feat: add nationality support with demonym in CountrySelect and related components

This commit is contained in:
estifanos
2026-08-10 12:28:31 +00:00
parent 849915d5db
commit 19afcc3403
6 changed files with 58 additions and 5 deletions

View File

@@ -68,6 +68,7 @@ export function ConfigDrivenSection({
{isNationality ? (
<CountrySelect
{...common}
demonym
value={(value as string) ?? null}
onChange={(v) => onChange(field.key, v)}
/>

View File

@@ -50,7 +50,7 @@ import {
type FormFieldConfig,
type ValidationIssue,
} from '@ema-platform/api';
import { getCountryCode, ModalFooter } from '@ema-platform/ui';
import { getCountryCode, getCountryName, ModalFooter } from '@ema-platform/ui';
import { useCurrentProfile } from '@ema-platform/auth';
import { ConfigDrivenSection } from '../components/ConfigDrivenSection';
import { DocumentSlots } from '../components/DocumentSlots';
@@ -210,11 +210,20 @@ export function LicenseApplicationPage() {
// During an adjustment round only flagged sections are editable, so don't
// even attempt a write the server would reject.
if (isAdjusting && !flaggedSections[sectionKey]) return;
const values = { ...(draft[sectionKey] ?? {}) };
// The picker works in alpha-2 codes (CountrySelect); the backend, like
// the profile Address endpoint, stores the full country name.
const nationalityField = config?.licenseType.formSchema.sections
.find((s) => s.key === sectionKey)
?.fields.find((f) => f.key === 'nationality' || localized(f.label).toLowerCase().includes('nationality'));
if (nationalityField && values[nationalityField.key]) {
values[nationalityField.key] = getCountryName(values[nationalityField.key] as string) || values[nationalityField.key];
}
try {
await patchSection({
id: appId as string,
sectionKey,
values: draft[sectionKey] ?? {},
values,
}).unwrap();
} catch (err) {
notifications.show({

View File

@@ -132,6 +132,7 @@ export function AddressFormContent({
/>
<CountrySelect
label="Nationality"
demonym
required
value={watch('nationality') || null}
onChange={(val) => setValue('nationality', val || '', { shouldValidate: true })}