licence_categories->categories;frontend: fixed category handling
This commit is contained in:
2
frontend/src/app.d.ts
vendored
2
frontend/src/app.d.ts
vendored
@@ -37,7 +37,7 @@ interface Licence {
|
|||||||
issued_date: string | '';
|
issued_date: string | '';
|
||||||
expiration_date: string | '';
|
expiration_date: string | '';
|
||||||
country: string | '';
|
country: string | '';
|
||||||
licence_categories: LicenceCategory[];
|
categories: LicenceCategory[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LicenceCategory {
|
interface LicenceCategory {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
issued_date: '',
|
issued_date: '',
|
||||||
expiration_date: '',
|
expiration_date: '',
|
||||||
country: '',
|
country: '',
|
||||||
licence_categories: []
|
categories: []
|
||||||
},
|
},
|
||||||
bank_account: {
|
bank_account: {
|
||||||
id: 0,
|
id: 0,
|
||||||
@@ -374,11 +374,11 @@
|
|||||||
<div class="checkbox-label-container">
|
<div class="checkbox-label-container">
|
||||||
<InputField
|
<InputField
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="user[licence][categories[]]"
|
name="user[licence][categories][]"
|
||||||
value={JSON.stringify(category)}
|
value={JSON.stringify(category)}
|
||||||
label={category.category}
|
label={category.category}
|
||||||
checked={localUser.licence.licence_categories != null &&
|
checked={localUser.licence.categories != null &&
|
||||||
localUser.licence.licence_categories.some(
|
localUser.licence.categories.some(
|
||||||
(cat) => cat.category === category.category
|
(cat) => cat.category === category.category
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ export function formDataToObject(formData) {
|
|||||||
/** @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);
|
||||||
|
console.dir(value);
|
||||||
/** @type {Record<string, any>} */
|
/** @type {Record<string, any>} */
|
||||||
let current = object;
|
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++) {
|
for (let i = 0; i < keys.length - 1; i++) {
|
||||||
/**
|
/**
|
||||||
* Create nested object if it doesn't exist
|
* Create nested object if it doesn't exist
|
||||||
@@ -42,13 +43,14 @@ export function formDataToObject(formData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lastKey = keys[keys.length - 1];
|
const lastKey = keys[keys.length - 1];
|
||||||
if (lastKey.endsWith('[]')) {
|
if (key.endsWith('[]')) {
|
||||||
/**
|
current[lastKey] = current[lastKey] || [];
|
||||||
* Handle array fields (licence categories)
|
try {
|
||||||
*/
|
/** @type {{id: number, category: string}} */
|
||||||
const arrayKey = lastKey.slice(0, -2);
|
current[lastKey].push(JSON.parse(value.toString()));
|
||||||
current[arrayKey] = current[arrayKey] || [];
|
} catch {
|
||||||
current[arrayKey].push(value);
|
current[lastKey].push(value);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
current[lastKey] = value;
|
current[lastKey] = value;
|
||||||
}
|
}
|
||||||
@@ -100,7 +102,7 @@ export function processFormData(rawData) {
|
|||||||
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 || ''),
|
||||||
licence_categories: rawData.user.licence?.licence_categories || []
|
categories: rawData.user.licence?.categories || []
|
||||||
},
|
},
|
||||||
|
|
||||||
bank_account: {
|
bank_account: {
|
||||||
@@ -114,7 +116,8 @@ export function processFormData(rawData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
console.log('Categories: --------');
|
||||||
|
console.dir(rawData.user.licence);
|
||||||
if (
|
if (
|
||||||
rawData.user.password &&
|
rawData.user.password &&
|
||||||
rawData.password2 &&
|
rawData.password2 &&
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ func (u *User) Safe() map[string]interface{} {
|
|||||||
"issued_date": u.Licence.IssuedDate,
|
"issued_date": u.Licence.IssuedDate,
|
||||||
"expiration_date": u.Licence.ExpirationDate,
|
"expiration_date": u.Licence.ExpirationDate,
|
||||||
"country": u.Licence.IssuingCountry,
|
"country": u.Licence.IssuingCountry,
|
||||||
"licence_categories": u.Licence.Categories,
|
"categories": u.Licence.Categories,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user