mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 12:18:11 +00:00
fix
This commit is contained in:
@@ -45,6 +45,24 @@ export interface FleetFormDialogProps {
|
||||
verifyWithFayda?: boolean;
|
||||
}
|
||||
|
||||
// Fayda returns gender as "Male"/"Female"; snap it onto the form's uppercase
|
||||
// option values (MALE/FEMALE/OTHER) so the Select prefills instead of rendering
|
||||
// blank. Unknown/empty values fall through to undefined (field left untouched).
|
||||
const normalizeGender = (raw?: string): string | undefined => {
|
||||
const up = (raw ?? "").trim().toUpperCase();
|
||||
if (up === "MALE" || up === "M") return "MALE";
|
||||
if (up === "FEMALE" || up === "F") return "FEMALE";
|
||||
return up ? "OTHER" : undefined;
|
||||
};
|
||||
|
||||
// Fayda may return the birthdate as "2001/12/01" (slashes), but the date input
|
||||
// and validator expect ISO "2001-12-01". Normalize separators + trim to 10 chars
|
||||
// so the DOB field prefills instead of silently staying blank.
|
||||
const normalizeBirthdate = (raw?: string): string | undefined => {
|
||||
const iso = (raw ?? "").trim().replace(/\//g, "-").slice(0, 10);
|
||||
return /^\d{4}-\d{2}-\d{2}$/.test(iso) ? iso : undefined;
|
||||
};
|
||||
|
||||
const buildInitialValues = (
|
||||
fields: FleetFormFieldDef[],
|
||||
emptyValues: Record<string, unknown>,
|
||||
@@ -131,13 +149,16 @@ const FleetFormDialog = ({
|
||||
}
|
||||
const nameParts = (result.fullName ?? "").trim().split(/\s+/).filter(Boolean);
|
||||
const [firstName, ...rest] = nameParts;
|
||||
const gender = normalizeGender(result.gender);
|
||||
const dateOfBirth = normalizeBirthdate(result.birthdate);
|
||||
setValues((current) => ({
|
||||
...current,
|
||||
...(firstName ? { firstName } : {}),
|
||||
...(rest.length ? { lastName: rest.join(" ") } : {}),
|
||||
...(result.email ? { email: result.email } : {}),
|
||||
...(result.phoneNumber ? { phoneNumber: result.phoneNumber } : {}),
|
||||
...(result.birthdate ? { dateOfBirth: result.birthdate } : {}),
|
||||
...(dateOfBirth ? { dateOfBirth } : {}),
|
||||
...(gender ? { gender } : {}),
|
||||
faydaVerified: true,
|
||||
...(result.iamUserId ? { faydaSub: result.iamUserId } : {}),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user