| @@ -41,13 +41,20 @@ | ||
| 41 | 41 | * Return the canonical `{CODE: 'Name'}` map. Reads from the localized |
| 42 | 42 | * payload first; falls back to the minimal set when missing. |
| 43 | 43 | */ |
| 44 | 44 | export function getCountryMap(): CountryMap { |
| 45 | - const raw = (window as any)?.yatraAdmin?.countries; | |
| 46 | - if (raw && typeof raw === "object" && !Array.isArray(raw)) { | |
| 47 | - const map = raw as CountryMap; | |
| 48 | - // Guard against an accidentally-empty object from the server. | |
| 49 | - if (Object.keys(map).length > 0) return map; | |
| 45 | + // Admin app localizes onto `yatraAdmin`; the front-end account page localizes | |
| 46 | + // onto `yatraAccountPage`. Read whichever is present so the same helper works | |
| 47 | + // in both contexts (otherwise the account page silently fell back to a tiny | |
| 48 | + // 6-country list and rendered ISO codes like "BH" instead of "Bahrain"). | |
| 49 | + const w = window as any; | |
| 50 | + const sources = [w?.yatraAdmin?.countries, w?.yatraAccountPage?.countries]; | |
| 51 | + for (const raw of sources) { | |
| 52 | + if (raw && typeof raw === "object" && !Array.isArray(raw)) { | |
| 53 | + const map = raw as CountryMap; | |
| 54 | + // Guard against an accidentally-empty object from the server. | |
| 55 | + if (Object.keys(map).length > 0) return map; | |
| 56 | + } | |
| 50 | 57 | } |
| 51 | 58 | return FALLBACK_COUNTRIES; |
| 52 | 59 | } |
| 53 | 60 | |
| @@ -61,8 +68,30 @@ | ||
| 61 | 68 | */ |
| 62 | 69 | export function getCountryOptions(): CountryOption[] { |
| 63 | 70 | const map = getCountryMap(); |
| 64 | 71 | return Object.entries(map).map(([code, name]) => ({ code, name })); |
| 72 | +} | |
| 73 | + | |
| 74 | +/** | |
| 75 | + * Country options shaped for SearchableSelect, each carrying its national flag. | |
| 76 | + * | |
| 77 | + * The flag base URL is localized by AdminAssetsProvider (`flagBase`), pointing at | |
| 78 | + * the SVG set the plugin already ships and the phone widget already uses — one | |
| 79 | + * source of flag assets for the whole product. Without that global the options | |
| 80 | + * are returned flagless rather than with broken images. | |
| 81 | + */ | |
| 82 | +export function getCountrySelectOptions(): Array<{ | |
| 83 | + value: string; | |
| 84 | + label: string; | |
| 85 | + icon?: string; | |
| 86 | +}> { | |
| 87 | + const base = (window as any).yatraAdmin?.flagBase || ""; | |
| 88 | + | |
| 89 | + return getCountryOptions().map((c) => ({ | |
| 90 | + value: c.code, | |
| 91 | + label: c.name, | |
| 92 | + icon: base ? base + c.code.toLowerCase() + ".svg" : undefined, | |
| 93 | + })); | |
| 65 | 94 | } |
| 66 | 95 | |
| 67 | 96 | /** |
| 68 | 97 | * Look up a single country's display name by ISO-3166 code. |