Frontend: licence_number>number, password update enabled
This commit is contained in:
3
frontend/src/app.d.ts
vendored
3
frontend/src/app.d.ts
vendored
@@ -33,7 +33,7 @@ interface BankAccount {
|
|||||||
interface Licence {
|
interface Licence {
|
||||||
id: number | -1;
|
id: number | -1;
|
||||||
status: number | -1;
|
status: number | -1;
|
||||||
licence_number: string | '';
|
number: string | '';
|
||||||
issued_date: string | '';
|
issued_date: string | '';
|
||||||
expiration_date: string | '';
|
expiration_date: string | '';
|
||||||
country: string | '';
|
country: string | '';
|
||||||
@@ -49,6 +49,7 @@ interface User {
|
|||||||
email: string | '';
|
email: string | '';
|
||||||
first_name: string | '';
|
first_name: string | '';
|
||||||
last_name: string | '';
|
last_name: string | '';
|
||||||
|
password: string | '';
|
||||||
phone: string | '';
|
phone: string | '';
|
||||||
notes: string | '';
|
notes: string | '';
|
||||||
address: string | '';
|
address: string | '';
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
email: '',
|
email: '',
|
||||||
first_name: '',
|
first_name: '',
|
||||||
last_name: '',
|
last_name: '',
|
||||||
|
password: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
address: '',
|
address: '',
|
||||||
zip_code: '',
|
zip_code: '',
|
||||||
@@ -43,7 +44,7 @@
|
|||||||
licence: {
|
licence: {
|
||||||
id: 0,
|
id: 0,
|
||||||
status: 1,
|
status: 1,
|
||||||
licence_number: '',
|
number: '',
|
||||||
issued_date: '',
|
issued_date: '',
|
||||||
expiration_date: '',
|
expiration_date: '',
|
||||||
country: '',
|
country: '',
|
||||||
@@ -83,14 +84,6 @@
|
|||||||
// $: isNewUser = user === null;
|
// $: isNewUser = user === null;
|
||||||
$: isLoading = user === undefined;
|
$: isLoading = user === undefined;
|
||||||
|
|
||||||
$: {
|
|
||||||
console.log('incomingUser:', user);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add debug logging for user
|
|
||||||
$: {
|
|
||||||
console.log('processed user:', user);
|
|
||||||
}
|
|
||||||
/** @type {App.Locals['licence_categories']} */
|
/** @type {App.Locals['licence_categories']} */
|
||||||
export let licence_categories;
|
export let licence_categories;
|
||||||
|
|
||||||
@@ -345,7 +338,7 @@
|
|||||||
name="user[licence][number]"
|
name="user[licence][number]"
|
||||||
type="text"
|
type="text"
|
||||||
label={$t('licence_number')}
|
label={$t('licence_number')}
|
||||||
bind:value={localUser.licence.licence_number}
|
bind:value={localUser.licence.number}
|
||||||
placeholder={$t('placeholder.licence_number')}
|
placeholder={$t('placeholder.licence_number')}
|
||||||
toUpperCase={true}
|
toUpperCase={true}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -3,17 +3,20 @@ import { toRFC3339 } from './helpers';
|
|||||||
/**
|
/**
|
||||||
* Converts FormData to a nested object structure
|
* Converts FormData to a nested object structure
|
||||||
* @param {FormData} formData - The FormData object to convert
|
* @param {FormData} formData - The FormData object to convert
|
||||||
* @returns {{ user: Partial<App.Locals['user']> }} Nested object representation of the form data
|
* @returns {{ user: Partial<App.Locals['user']>,password2: string }} Nested object representation of the form data
|
||||||
*/
|
*/
|
||||||
export function formDataToObject(formData) {
|
export function formDataToObject(formData) {
|
||||||
/** @type { Partial<App.Locals['user']> } */
|
/** @type { Partial<App.Locals['user']> } */
|
||||||
const object = {};
|
const object = {};
|
||||||
|
let password2 = '';
|
||||||
|
|
||||||
console.log('Form data entries:');
|
console.log('Form data entries:');
|
||||||
for (const [key, value] of formData.entries()) {
|
for (const [key, value] of formData.entries()) {
|
||||||
console.log('Key:', key, 'Value:', value);
|
console.log('Key:', key, 'Value:', value);
|
||||||
}
|
if (key == 'password2') {
|
||||||
for (const [key, value] of formData.entries()) {
|
password2 = String(value);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
const keys = key.match(/\[([^\]]+)\]/g)?.map((k) => k.slice(1, -1)) || [key];
|
const keys = key.match(/\[([^\]]+)\]/g)?.map((k) => k.slice(1, -1)) || [key];
|
||||||
console.log('Processed keys:', keys);
|
console.log('Processed keys:', keys);
|
||||||
@@ -51,17 +54,17 @@ export function formDataToObject(formData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { user: object };
|
return { user: object, password2: password2 };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the raw form data into the expected user data structure
|
* Processes the raw form data into the expected user data structure
|
||||||
* @param {{ user: Partial<App.Locals['user']> } } rawData - The raw form data object
|
* @param {{ user: Partial<App.Locals['user']>, password2: string} } rawData - The raw form data object
|
||||||
* @returns {{ user: Partial<App.Locals['user']> }} Processed user data
|
* @returns {{ user: Partial<App.Locals['user']> }} Processed user data
|
||||||
*/
|
*/
|
||||||
export function processFormData(rawData) {
|
export function processFormData(rawData) {
|
||||||
/** @type {{ user: Partial<App.Locals['user']> }} */
|
/** @type {{ user: Partial<App.Locals['user']> }} */
|
||||||
const processedData = {
|
let processedData = {
|
||||||
user: {
|
user: {
|
||||||
id: Number(rawData.user.id) || 0,
|
id: Number(rawData.user.id) || 0,
|
||||||
status: Number(rawData.user.status),
|
status: Number(rawData.user.status),
|
||||||
@@ -93,7 +96,7 @@ export function processFormData(rawData) {
|
|||||||
licence: {
|
licence: {
|
||||||
id: Number(rawData.user.licence?.id) || 0,
|
id: Number(rawData.user.licence?.id) || 0,
|
||||||
status: Number(rawData.user.licence?.status),
|
status: Number(rawData.user.licence?.status),
|
||||||
licence_number: String(rawData.user.licence?.licence_number || ''),
|
number: String(rawData.user.licence?.number || ''),
|
||||||
issued_date: toRFC3339(rawData.user.licence?.issued_date),
|
issued_date: toRFC3339(rawData.user.licence?.issued_date),
|
||||||
expiration_date: toRFC3339(rawData.user.licence?.expiration_date),
|
expiration_date: toRFC3339(rawData.user.licence?.expiration_date),
|
||||||
country: String(rawData.user.licence?.country || ''),
|
country: String(rawData.user.licence?.country || ''),
|
||||||
@@ -112,6 +115,15 @@ export function processFormData(rawData) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (
|
||||||
|
rawData.user.password &&
|
||||||
|
rawData.password2 &&
|
||||||
|
rawData.user.password === rawData.password2 &&
|
||||||
|
rawData.user.password.trim() !== ''
|
||||||
|
) {
|
||||||
|
processedData.user.password = rawData.user.password;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove undefined or null properties
|
// Remove undefined or null properties
|
||||||
const cleanUpdateData = JSON.parse(JSON.stringify(processedData), (key, value) =>
|
const cleanUpdateData = JSON.parse(JSON.stringify(processedData), (key, value) =>
|
||||||
value !== null && value !== '' ? value : undefined
|
value !== null && value !== '' ? value : undefined
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export const actions = {
|
|||||||
console.log('Is creating: ', isCreating);
|
console.log('Is creating: ', isCreating);
|
||||||
// console.dir(formData);
|
// console.dir(formData);
|
||||||
console.dir(processedData.user.membership);
|
console.dir(processedData.user.membership);
|
||||||
const apiURL = `${BASE_API_URI}/backend/users/update/`;
|
const apiURL = `${BASE_API_URI}/backend/users/upsert/`;
|
||||||
|
|
||||||
/** @type {RequestInit} */
|
/** @type {RequestInit} */
|
||||||
const requestUpdateOptions = {
|
const requestUpdateOptions = {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export const actions = {
|
|||||||
console.dir(processedData.user.membership);
|
console.dir(processedData.user.membership);
|
||||||
const isCreating = !processedData.user.id || processedData.user.id === 0;
|
const isCreating = !processedData.user.id || processedData.user.id === 0;
|
||||||
console.log('Is creating: ', isCreating);
|
console.log('Is creating: ', isCreating);
|
||||||
const apiURL = `${BASE_API_URI}/backend/users/update`;
|
const apiURL = `${BASE_API_URI}/backend/users/upsert`;
|
||||||
|
|
||||||
/** @type {RequestInit} */
|
/** @type {RequestInit} */
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
@@ -59,6 +59,6 @@ export const actions = {
|
|||||||
console.log('Server success response:', response);
|
console.log('Server success response:', response);
|
||||||
locals.user = response;
|
locals.user = response;
|
||||||
userDatesFromRFC3339(locals.user);
|
userDatesFromRFC3339(locals.user);
|
||||||
throw redirect(303, `/auth/about/${response.id}`);
|
throw redirect(303, `/auth/admin/users`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -223,6 +223,7 @@
|
|||||||
{subscriptions}
|
{subscriptions}
|
||||||
{licence_categories}
|
{licence_categories}
|
||||||
on:cancel={close}
|
on:cancel={close}
|
||||||
|
on:close={close}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user