From 162111cc181a58c2bdf39df8ae566b8ab1f34426 Mon Sep 17 00:00:00 2001 From: Stefan Kairinos Date: Fri, 10 Jan 2025 16:39:37 +0000 Subject: [PATCH] fix: country iso code mapping (#73) --- src/components/form/CountryField.tsx | 10 +- src/utils/general.ts | 788 ++++++++++++++++++++++----- 2 files changed, 655 insertions(+), 143 deletions(-) diff --git a/src/components/form/CountryField.tsx b/src/components/form/CountryField.tsx index 2980ba3..fcac2e6 100644 --- a/src/components/form/CountryField.tsx +++ b/src/components/form/CountryField.tsx @@ -1,6 +1,10 @@ import { type ChipTypeMap } from "@mui/material" import { type ElementType } from "react" -import { COUNTRY_ISO_CODES } from "../../utils/general" +import { + COUNTRY_ISO_CODES, + COUNTRY_ISO_CODE_MAPPING, + type CountryIsoCodes, +} from "../../utils/general" import AutocompleteField, { type AutocompleteFieldProps, } from "./AutocompleteField" @@ -58,7 +62,9 @@ const CountryField = < return ( isoCode} // TODO: return country name + getOptionLabel={isoCode => + COUNTRY_ISO_CODE_MAPPING[isoCode as CountryIsoCodes] + } textFieldProps={{ name, label, placeholder, ...otherTextFieldProps }} {...otherAutocompleteFieldProps} /> diff --git a/src/utils/general.ts b/src/utils/general.ts index c9ed3a8..80e2556 100644 --- a/src/utils/general.ts +++ b/src/utils/general.ts @@ -59,259 +59,765 @@ export function camelCaseToSnakeCase(obj: Record): void { export const MIN_DATE = new Date(0, 0, 0) export const COUNTRY_ISO_CODES = [ + "AD", + "AE", "AF", - "AX", + "AG", + "AI", "AL", - "DZ", - "AS", - "AD", + "AM", "AO", - "AI", "AQ", - "AG", "AR", - "AM", - "AW", - "AU", + "AS", "AT", + "AU", + "AW", + "AX", "AZ", - "BS", - "BH", - "BD", + "BA", "BB", - "BY", + "BD", "BE", - "BZ", + "BF", + "BG", + "BH", + "BI", "BJ", + "BL", "BM", - "BT", + "BN", "BO", "BQ", - "BA", - "BW", - "BV", "BR", - "IO", - "BN", - "BG", - "BF", - "BI", - "KH", - "CM", + "BS", + "BT", + "BV", + "BW", + "BY", + "BZ", "CA", - "CV", - "KY", + "CC", + "CD", "CF", - "TD", + "CG", + "CH", + "CI", + "CK", "CL", + "CM", "CN", - "CX", - "CC", "CO", - "KM", - "CG", - "CD", - "CK", "CR", - "CI", - "HR", "CU", + "CV", "CW", + "CX", "CY", "CZ", - "DK", + "DE", "DJ", + "DK", "DM", "DO", + "DZ", "EC", + "EE", "EG", - "SV", - "GQ", + "EH", "ER", - "EE", + "ES", "ET", + "FI", + "FJ", "FK", + "FM", "FO", - "FJ", - "FI", "FR", - "GF", - "PF", - "TF", "GA", - "GM", + "GB", + "GD", "GE", - "DE", + "GF", + "GG", "GH", "GI", - "GR", "GL", - "GD", + "GM", + "GN", "GP", - "GU", + "GQ", + "GR", + "GS", "GT", - "GG", - "GN", + "GU", "GW", "GY", - "HT", + "HK", "HM", - "VA", "HN", - "HK", + "HR", + "HT", "HU", - "IS", - "IN", "ID", - "IR", - "IQ", "IE", - "IM", "IL", + "IM", + "IN", + "IO", + "IQ", + "IR", + "IS", "IT", - "JM", - "JP", "JE", + "JM", "JO", - "KZ", + "JP", "KE", + "KG", + "KH", "KI", + "KM", + "KN", "KP", "KR", "KW", - "KG", + "KY", + "KZ", "LA", - "LV", "LB", - "LS", - "LR", - "LY", + "LC", "LI", + "LK", + "LR", + "LS", "LT", "LU", - "MO", - "MK", + "LV", + "LY", + "MA", + "MC", + "MD", + "ME", + "MF", "MG", - "MW", - "MY", - "MV", - "ML", - "MT", "MH", + "MK", + "ML", + "MM", + "MN", + "MO", + "MP", "MQ", "MR", + "MS", + "MT", "MU", - "YT", + "MV", + "MW", "MX", - "FM", - "MD", - "MC", - "MN", - "ME", - "MS", - "MA", + "MY", "MZ", - "MM", "NA", - "NR", - "NP", - "NL", "NC", - "NZ", - "NI", "NE", - "NG", - "NU", "NF", - "MP", + "NG", + "NI", + "NL", "NO", + "NP", + "NR", + "NU", + "NZ", "OM", - "PK", - "PW", - "PS", "PA", - "PG", - "PY", "PE", + "PF", + "PG", "PH", - "PN", + "PK", "PL", - "PT", + "PM", + "PN", "PR", + "PS", + "PT", + "PW", + "PY", "QA", "RE", "RO", + "RS", "RU", "RW", - "BL", - "SH", - "KN", - "LC", - "MF", - "PM", - "VC", - "WS", - "SM", - "ST", "SA", - "SN", - "RS", + "SB", "SC", - "SL", + "SD", + "SE", "SG", - "SX", - "SK", + "SH", "SI", - "SB", + "SJ", + "SK", + "SL", + "SM", + "SN", "SO", - "ZA", - "GS", - "SS", - "ES", - "LK", - "SD", "SR", - "SJ", - "SZ", - "SE", - "CH", + "SS", + "ST", + "SV", + "SX", "SY", - "TW", - "TJ", - "TZ", - "TH", - "TL", + "SZ", + "TC", + "TD", + "TF", "TG", + "TH", + "TJ", "TK", - "TO", - "TT", + "TL", + "TM", "TN", + "TO", "TR", - "TM", - "TC", + "TT", "TV", - "UG", + "TW", + "TZ", "UA", - "AE", - "GB", - "US", + "UG", "UM", + "US", "UY", "UZ", - "VU", + "VA", + "VC", "VE", - "VN", "VG", "VI", + "VN", + "VU", "WF", - "EH", + "WS", "YE", + "YT", + "ZA", "ZM", "ZW", ] as const export type CountryIsoCodes = (typeof COUNTRY_ISO_CODES)[number] +export const COUNTRIES = [ + "Andorra", + "United Arab Emirates (the)", + "Afghanistan", + "Antigua and Barbuda", + "Anguilla", + "Albania", + "Armenia", + "Angola", + "Antarctica", + "Argentina", + "American Samoa", + "Austria", + "Australia", + "Aruba", + "Åland Islands", + "Azerbaijan", + "Bosnia and Herzegovina", + "Barbados", + "Bangladesh", + "Belgium", + "Burkina Faso", + "Bulgaria", + "Bahrain", + "Burundi", + "Benin", + "Saint Barthélemy", + "Bermuda", + "Brunei Darussalam", + "Bolivia (Plurinational State of)", + "Bonaire, Sint Eustatius and Saba", + "Brazil", + "Bahamas (the)", + "Bhutan", + "Bouvet Island", + "Botswana", + "Belarus", + "Belize", + "Canada", + "Cocos (Keeling) Islands (the)", + "Congo (the Democratic Republic of the)", + "Central African Republic (the)", + "Congo (the)", + "Switzerland", + "Côte d'Ivoire", + "Cook Islands (the)", + "Chile", + "Cameroon", + "China", + "Colombia", + "Costa Rica", + "Cuba", + "Cabo Verde", + "Curaçao", + "Christmas Island", + "Cyprus", + "Czechia", + "Germany", + "Djibouti", + "Denmark", + "Dominica", + "Dominican Republic (the", + "Algeria", + "Ecuador", + "Estonia", + "Egypt", + "Western Sahara", + "Eritrea", + "Spain", + "Ethiopia", + "Finland", + "Fiji", + "Falkland Islands (the) [Malvinas]", + "Micronesia (Federated States of)", + "Faroe Islands (the)", + "France", + "Gabon", + "United Kingdom of Great Britain and Northern Ireland (the)", + "Grenada", + "Georgia", + "French Guiana", + "Guernsey", + "Ghana", + "Gibraltar", + "Greenland", + "Gambia (the)", + "Guinea", + "Guadeloupe", + "Equatorial Guinea", + "Greece", + "South Georgia and the South Sandwich Islands", + "Guatemala", + "Guam", + "Guinea-Bissau", + "Guyana", + "Hong Kong", + "Heard Island and McDonald Islands", + "Honduras", + "Croatia", + "Haiti", + "Hungary", + "Indonesia", + "Ireland", + "Israel", + "Isle of Man", + "India", + "British Indian Ocean Territory (the)", + "Iraq", + "Iran (Islamic Republic of)", + "Iceland", + "Italy", + "Jersey", + "Jamaica", + "Jordan", + "Japan", + "Kenya", + "Kyrgyzstan", + "Cambodia", + "Kiribati", + "Comoros (the)", + "Saint Kitts and Nevis", + "Korea (the Democratic People's Republic of)", + "Korea (the Republic of)", + "Kuwait", + "Cayman Islands (the)", + "Kazakhstan", + "Lao People's Democratic Republic (the)", + "Lebanon", + "Saint Lucia", + "Liechtenstein", + "Sri Lanka", + "Liberia", + "Lesotho", + "Lithuania", + "Luxembourg", + "Latvia", + "Libya", + "Morocco", + "Monaco", + "Moldova (the Republic of)", + "Montenegro", + "Saint Martin (French part)", + "Madagascar", + "Marshall Islands (the)", + "Republic of North Macedonia", + "Mali", + "Myanmar", + "Mongolia", + "Macao", + "Northern Mariana Islands (the)", + "Martinique", + "Mauritania", + "Montserrat", + "Malta", + "Mauritius", + "Maldives", + "Malawi", + "Mexico", + "Malaysia", + "Mozambique", + "Namibia", + "New Caledonia", + "Niger (the)", + "Norfolk Island", + "Nigeria", + "Nicaragua", + "Netherlands (the)", + "Norway", + "Nepal", + "Nauru", + "Niue", + "New Zealand", + "Oman", + "Panama", + "Peru", + "French Polynesia", + "Papua New Guinea", + "Philippines (the)", + "Pakistan", + "Poland", + "Saint Pierre and Miquelon", + "Pitcairn", + "Puerto Rico", + "Palestine, State of", + "Portugal", + "Palau", + "Paraguay", + "Qatar", + "Réunion", + "Romania", + "Serbia", + "Russian Federation (the)", + "Rwanda", + "Saudi Arabia", + "Solomon Islands", + "Seychelles", + "Sudan (the)", + "Sweden", + "Singapore", + "Saint Helena, Ascension and Tristan da Cunha", + "Slovenia", + "Svalbard and Jan Mayen", + "Slovakia", + "Sierra Leone", + "San Marino", + "Senegal", + "Somalia", + "Suriname", + "South Sudan", + "Sao Tome and Principe", + "El Salvador", + "Sint Maarten (Dutch part)", + "Syrian Arab Republic", + "Eswatini", + "Turks and Caicos Islands (the)", + "Chad", + "French Southern Territories (the)", + "Togo", + "Thailand", + "Tajikistan", + "Tokelau", + "Timor-Leste", + "Turkmenistan", + "Tunisia", + "Tonga", + "Turkey", + "Trinidad and Tobago", + "Tuvalu", + "Taiwan (Province of China)", + "Tanzania, United Republic of", + "Ukraine", + "Uganda", + "United States Minor Outlying Islands (the)", + "United States of America (the)", + "Uruguay", + "Uzbekistan", + "Holy See (the)", + "Saint Vincent and the Grenadines", + "Venezuela (Bolivarian Republic of)", + "Virgin Islands (British)", + "Virgin Islands (U.S.)", + "Viet Nam", + "Vanuatu", + "Wallis and Futuna", + "Samoa", + "Yemen", + "Mayotte", + "South Africa", + "Zambia", + "Zimbabwe", +] as const + +export type Countries = (typeof COUNTRIES)[number] + +export const COUNTRY_ISO_CODE_MAPPING: Record = { + AD: "Andorra", + AE: "United Arab Emirates (the)", + AF: "Afghanistan", + AG: "Antigua and Barbuda", + AI: "Anguilla", + AL: "Albania", + AM: "Armenia", + AO: "Angola", + AQ: "Antarctica", + AR: "Argentina", + AS: "American Samoa", + AT: "Austria", + AU: "Australia", + AW: "Aruba", + AX: "Åland Islands", + AZ: "Azerbaijan", + BA: "Bosnia and Herzegovina", + BB: "Barbados", + BD: "Bangladesh", + BE: "Belgium", + BF: "Burkina Faso", + BG: "Bulgaria", + BH: "Bahrain", + BI: "Burundi", + BJ: "Benin", + BL: "Saint Barthélemy", + BM: "Bermuda", + BN: "Brunei Darussalam", + BO: "Bolivia (Plurinational State of)", + BQ: "Bonaire, Sint Eustatius and Saba", + BR: "Brazil", + BS: "Bahamas (the)", + BT: "Bhutan", + BV: "Bouvet Island", + BW: "Botswana", + BY: "Belarus", + BZ: "Belize", + CA: "Canada", + CC: "Cocos (Keeling) Islands (the)", + CD: "Congo (the Democratic Republic of the)", + CF: "Central African Republic (the)", + CG: "Congo (the)", + CH: "Switzerland", + CI: "Côte d'Ivoire", + CK: "Cook Islands (the)", + CL: "Chile", + CM: "Cameroon", + CN: "China", + CO: "Colombia", + CR: "Costa Rica", + CU: "Cuba", + CV: "Cabo Verde", + CW: "Curaçao", + CX: "Christmas Island", + CY: "Cyprus", + CZ: "Czechia", + DE: "Germany", + DJ: "Djibouti", + DK: "Denmark", + DM: "Dominica", + DO: "Dominican Republic (the", + DZ: "Algeria", + EC: "Ecuador", + EE: "Estonia", + EG: "Egypt", + EH: "Western Sahara", + ER: "Eritrea", + ES: "Spain", + ET: "Ethiopia", + FI: "Finland", + FJ: "Fiji", + FK: "Falkland Islands (the) [Malvinas]", + FM: "Micronesia (Federated States of)", + FO: "Faroe Islands (the)", + FR: "France", + GA: "Gabon", + GB: "United Kingdom of Great Britain and Northern Ireland (the)", + GD: "Grenada", + GE: "Georgia", + GF: "French Guiana", + GG: "Guernsey", + GH: "Ghana", + GI: "Gibraltar", + GL: "Greenland", + GM: "Gambia (the)", + GN: "Guinea", + GP: "Guadeloupe", + GQ: "Equatorial Guinea", + GR: "Greece", + GS: "South Georgia and the South Sandwich Islands", + GT: "Guatemala", + GU: "Guam", + GW: "Guinea-Bissau", + GY: "Guyana", + HK: "Hong Kong", + HM: "Heard Island and McDonald Islands", + HN: "Honduras", + HR: "Croatia", + HT: "Haiti", + HU: "Hungary", + ID: "Indonesia", + IE: "Ireland", + IL: "Israel", + IM: "Isle of Man", + IN: "India", + IO: "British Indian Ocean Territory (the)", + IQ: "Iraq", + IR: "Iran (Islamic Republic of)", + IS: "Iceland", + IT: "Italy", + JE: "Jersey", + JM: "Jamaica", + JO: "Jordan", + JP: "Japan", + KE: "Kenya", + KG: "Kyrgyzstan", + KH: "Cambodia", + KI: "Kiribati", + KM: "Comoros (the)", + KN: "Saint Kitts and Nevis", + KP: "Korea (the Democratic People's Republic of)", + KR: "Korea (the Republic of)", + KW: "Kuwait", + KY: "Cayman Islands (the)", + KZ: "Kazakhstan", + LA: "Lao People's Democratic Republic (the)", + LB: "Lebanon", + LC: "Saint Lucia", + LI: "Liechtenstein", + LK: "Sri Lanka", + LR: "Liberia", + LS: "Lesotho", + LT: "Lithuania", + LU: "Luxembourg", + LV: "Latvia", + LY: "Libya", + MA: "Morocco", + MC: "Monaco", + MD: "Moldova (the Republic of)", + ME: "Montenegro", + MF: "Saint Martin (French part)", + MG: "Madagascar", + MH: "Marshall Islands (the)", + MK: "Republic of North Macedonia", + ML: "Mali", + MM: "Myanmar", + MN: "Mongolia", + MO: "Macao", + MP: "Northern Mariana Islands (the)", + MQ: "Martinique", + MR: "Mauritania", + MS: "Montserrat", + MT: "Malta", + MU: "Mauritius", + MV: "Maldives", + MW: "Malawi", + MX: "Mexico", + MY: "Malaysia", + MZ: "Mozambique", + NA: "Namibia", + NC: "New Caledonia", + NE: "Niger (the)", + NF: "Norfolk Island", + NG: "Nigeria", + NI: "Nicaragua", + NL: "Netherlands (the)", + NO: "Norway", + NP: "Nepal", + NR: "Nauru", + NU: "Niue", + NZ: "New Zealand", + OM: "Oman", + PA: "Panama", + PE: "Peru", + PF: "French Polynesia", + PG: "Papua New Guinea", + PH: "Philippines (the)", + PK: "Pakistan", + PL: "Poland", + PM: "Saint Pierre and Miquelon", + PN: "Pitcairn", + PR: "Puerto Rico", + PS: "Palestine, State of", + PT: "Portugal", + PW: "Palau", + PY: "Paraguay", + QA: "Qatar", + RE: "Réunion", + RO: "Romania", + RS: "Serbia", + RU: "Russian Federation (the)", + RW: "Rwanda", + SA: "Saudi Arabia", + SB: "Solomon Islands", + SC: "Seychelles", + SD: "Sudan (the)", + SE: "Sweden", + SG: "Singapore", + SH: "Saint Helena, Ascension and Tristan da Cunha", + SI: "Slovenia", + SJ: "Svalbard and Jan Mayen", + SK: "Slovakia", + SL: "Sierra Leone", + SM: "San Marino", + SN: "Senegal", + SO: "Somalia", + SR: "Suriname", + SS: "South Sudan", + ST: "Sao Tome and Principe", + SV: "El Salvador", + SX: "Sint Maarten (Dutch part)", + SY: "Syrian Arab Republic", + SZ: "Eswatini", + TC: "Turks and Caicos Islands (the)", + TD: "Chad", + TF: "French Southern Territories (the)", + TG: "Togo", + TH: "Thailand", + TJ: "Tajikistan", + TK: "Tokelau", + TL: "Timor-Leste", + TM: "Turkmenistan", + TN: "Tunisia", + TO: "Tonga", + TR: "Turkey", + TT: "Trinidad and Tobago", + TV: "Tuvalu", + TW: "Taiwan (Province of China)", + TZ: "Tanzania, United Republic of", + UA: "Ukraine", + UG: "Uganda", + UM: "United States Minor Outlying Islands (the)", + US: "United States of America (the)", + UY: "Uruguay", + UZ: "Uzbekistan", + VA: "Holy See (the)", + VC: "Saint Vincent and the Grenadines", + VE: "Venezuela (Bolivarian Republic of)", + VG: "Virgin Islands (British)", + VI: "Virgin Islands (U.S.)", + VN: "Viet Nam", + VU: "Vanuatu", + WF: "Wallis and Futuna", + WS: "Samoa", + YE: "Yemen", + YT: "Mayotte", + ZA: "South Africa", + ZM: "Zambia", + ZW: "Zimbabwe", +} + export const UK_COUNTIES = [ "Aberdeen City", "Aberdeenshire",