licence_categories->categories;frontend: fixed category handling
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
issued_date: '',
|
||||
expiration_date: '',
|
||||
country: '',
|
||||
licence_categories: []
|
||||
categories: []
|
||||
},
|
||||
bank_account: {
|
||||
id: 0,
|
||||
@@ -374,11 +374,11 @@
|
||||
<div class="checkbox-label-container">
|
||||
<InputField
|
||||
type="checkbox"
|
||||
name="user[licence][categories[]]"
|
||||
name="user[licence][categories][]"
|
||||
value={JSON.stringify(category)}
|
||||
label={category.category}
|
||||
checked={localUser.licence.licence_categories != null &&
|
||||
localUser.licence.licence_categories.some(
|
||||
checked={localUser.licence.categories != null &&
|
||||
localUser.licence.categories.some(
|
||||
(cat) => cat.category === category.category
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user