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