diff --git a/src/assets/countries.json b/src/assets/countries.json index b9576542a..639c2d973 100644 --- a/src/assets/countries.json +++ b/src/assets/countries.json @@ -1490,7 +1490,7 @@ "countryCode": "AE" }, { - "id": "en:united-kingdom", + "id": "en:uk", "label": "United Kingdom", "languageCode": "en", "countryCode": "UK" diff --git a/src/pages/eco-score/index.tsx b/src/pages/eco-score/index.tsx index bb5b27a95..3167b2111 100644 --- a/src/pages/eco-score/index.tsx +++ b/src/pages/eco-score/index.tsx @@ -11,7 +11,7 @@ import SmallQuestionCard from "../../components/SmallQuestionCard"; import Opportunities from "../../components/Opportunities"; import { DEFAULT_FILTER_STATE } from "../../components/QuestionFilter/const"; import { useTranslation } from "react-i18next"; -import { capitaliseName } from "../../utils"; +import { getCountryName } from "../../utils"; import Loader from "../loader"; const ecoScoreCards = [ @@ -161,12 +161,14 @@ export const countryNames = [ "en:united-states", "en:canada", "en:australia", - "en:united-kingdom", -]; + "en:uk", +].map((id) => ({ id, label: getCountryName(id) })); export default function EcoScore() { const { t } = useTranslation(); - const [selectedCountry, setSelectedCountry] = React.useState(countryNames[0]); + const [selectedCountry, setSelectedCountry] = React.useState( + countryNames[0].id + ); return ( }> @@ -202,8 +204,8 @@ export default function EcoScore() { sx={{ width: 200 }} > {countryNames.map((country) => ( - - {capitaliseName(country)} + + {country.label} ))} diff --git a/src/utils.ts b/src/utils.ts index f607f136d..1d586c534 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,5 @@ +import counties from "./assets/countries.json"; + const reformatTagMapping = { " ": "-", "'": "-", @@ -50,3 +52,14 @@ export const capitaliseName = (string: string | undefined) => { let name = string.slice(3); return name.charAt(0).toUpperCase() + name.slice(1); }; + +export const getCountryName = (countryId?: string) => { + if (!countryId) { + return ""; + } + const country = counties.find((item) => item.id === countryId); + if (!country) { + return ""; + } + return country.label; +};