feat: add NATIONALITY and NATION field types with dedicated country-picker logic and storage conversion

This commit is contained in:
estifanos
2026-09-08 06:45:34 +00:00
parent d5d77cbc30
commit e1150cab63
7 changed files with 126 additions and 15 deletions

View File

@@ -5,6 +5,7 @@ import { registerLocale, getNames, getName, getAlpha2Code } from 'i18n-iso-count
import {
registerLocale as registerNationalityLocale,
getName as getNationalityNameRaw,
getAlpha2Code as getNationalityAlpha2Code,
} from 'i18n-nationality';
import * as Flags from 'country-flag-icons/react/3x2';
import en from 'i18n-iso-countries/langs/en.json';
@@ -44,6 +45,17 @@ export function getNationalityName(code: string | null | undefined, lang: Countr
return getCountryName(code, lang);
}
/**
* Alpha-2 code for a stored demonym (e.g. "Ethiopian" -> "ET"), the reverse of
* `getNationalityName`. Falls back to the country-name lookup so a field that
* happens to hold "Ethiopia" still resolves.
*/
export function getNationalityCode(name: string | null | undefined, lang: CountryLang = 'en'): string | undefined {
if (!name) return undefined;
const demonymCode = lang === 'en' ? getNationalityAlpha2Code(name, 'en') : undefined;
return demonymCode || getCountryCode(name, lang);
}
export function CountryFlag({ code }: { code: string }) {
const Flag = Flags[code as keyof typeof Flags];
return Flag ? <Flag style={{ width: 22, borderRadius: 2, display: 'block' }} /> : null;