From 5d668ea0bba9968cc23bf34cf658b73827b175b3 Mon Sep 17 00:00:00 2001 From: Frank <48450599+Fbasham@users.noreply.github.com> Date: Wed, 26 Feb 2025 08:45:13 -0500 Subject: [PATCH] update getLocalizedCountries to return a sorted array (#279) --- frontend/app/.server/services/locale-data-service.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/app/.server/services/locale-data-service.ts b/frontend/app/.server/services/locale-data-service.ts index e76c5287..ff685578 100644 --- a/frontend/app/.server/services/locale-data-service.ts +++ b/frontend/app/.server/services/locale-data-service.ts @@ -24,10 +24,18 @@ type LocalizedCountry = Readonly<{ }>; export function getLocalizedCountries(locale: Language = 'en'): readonly LocalizedCountry[] { - return getCountries().map((country) => ({ + const { PP_CANADA_COUNTRY_CODE } = serverEnvironment; + const countries = getCountries().map((country) => ({ id: country.id, name: country[locale === 'en' ? 'nameEn' : 'nameFr'], })); + return countries + .filter((country) => country.id === PP_CANADA_COUNTRY_CODE) + .concat( + countries + .filter((country) => country.id !== PP_CANADA_COUNTRY_CODE) + .sort((a, b) => a.name.localeCompare(b.name, locale, { sensitivity: 'base' })), + ); } type ProvinceTerritory = Readonly<{