licence_categories->categories;frontend: fixed category handling

This commit is contained in:
Alex
2025-02-10 14:59:22 +01:00
parent a8bc049af7
commit 447f149423
4 changed files with 25 additions and 22 deletions

View File

@@ -20,10 +20,11 @@ export function formDataToObject(formData) {
/** @type {string[]} */
const keys = key.match(/\[([^\]]+)\]/g)?.map((k) => k.slice(1, -1)) || [key];
console.log('Processed keys:', keys);
console.dir(value);
/** @type {Record<string, any>} */
let current = object;
console.log('Current object state:', JSON.stringify(current));
// console.log('Current object state:', JSON.stringify(current));
for (let i = 0; i < keys.length - 1; i++) {
/**
* Create nested object if it doesn't exist
@@ -42,13 +43,14 @@ export function formDataToObject(formData) {
}
const lastKey = keys[keys.length - 1];
if (lastKey.endsWith('[]')) {
/**
* Handle array fields (licence categories)
*/
const arrayKey = lastKey.slice(0, -2);
current[arrayKey] = current[arrayKey] || [];
current[arrayKey].push(value);
if (key.endsWith('[]')) {
current[lastKey] = current[lastKey] || [];
try {
/** @type {{id: number, category: string}} */
current[lastKey].push(JSON.parse(value.toString()));
} catch {
current[lastKey].push(value);
}
} else {
current[lastKey] = value;
}
@@ -100,7 +102,7 @@ export function processFormData(rawData) {
issued_date: toRFC3339(rawData.user.licence?.issued_date),
expiration_date: toRFC3339(rawData.user.licence?.expiration_date),
country: String(rawData.user.licence?.country || ''),
licence_categories: rawData.user.licence?.licence_categories || []
categories: rawData.user.licence?.categories || []
},
bank_account: {
@@ -114,7 +116,8 @@ export function processFormData(rawData) {
}
}
};
console.log('Categories: --------');
console.dir(rawData.user.licence);
if (
rawData.user.password &&
rawData.password2 &&