From 25ba795d25c7e98a50840093524798ef73a58d8a Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 12 Apr 2024 21:45:22 +0200 Subject: [PATCH] fix --- src/utils/getCountryId.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/getCountryId.ts b/src/utils/getCountryId.ts index 39c8f848f..e6458fc91 100644 --- a/src/utils/getCountryId.ts +++ b/src/utils/getCountryId.ts @@ -3,18 +3,18 @@ import countries from "../assets/countries.json"; /** * Get the country id base on the two letter id */ -export function getCountryId(country: string) { - if (country.length !== 2) { +export function getCountryId(country: string | null) { + if (!country || country.length !== 2) { return country; } const upperCountry = country.toUpperCase(); - const countryId = Object.keys(countries).find( - (id) => countries[id].countryCode === upperCountry, + const countryObject = countries.find( + ({ countryCode }) => countryCode === upperCountry, ); - if (countryId === undefined) { + if (!countryObject || !countryObject.id) { return country; } - return countryId; + return countryObject.id; }