Skip to content

Commit

Permalink
fix: use title-case country/region only in render
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiayee Lim committed Feb 21, 2023
1 parent d1f6a36 commit 589af79
Show file tree
Hide file tree
Showing 2 changed files with 270 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useMemo } from 'react'
import { Controller, useFormContext } from 'react-hook-form'

import { CountryRegion } from '~shared/constants/countryRegion'
import {
CountryRegion,
CountryRegionTitleCase,
} from '~shared/constants/countryRegion'
import { FormColorTheme } from '~shared/types'
import { CountryRegionFieldBase, FormFieldWithId } from '~shared/types/field'

Expand All @@ -25,6 +28,14 @@ export const SORTED_COUNTRY_OPTIONS = (() => {
return countryOptions
})()

const SORTED_COUNTRY_OPTIONS_TO_RENDER = (() => {
const countryOptions = Object.values(CountryRegionTitleCase)
.filter((country) => country !== CountryRegionTitleCase.Singapore)
.sort((a, b) => a.localeCompare(b))
countryOptions.unshift(CountryRegionTitleCase.Singapore)
return countryOptions
})()

export const CountryRegionField = ({
schema,
colorTheme = FormColorTheme.Blue,
Expand Down Expand Up @@ -53,7 +64,7 @@ export const CountryRegionField = ({
render={({ field }) => (
<SingleSelect
colorScheme={`theme-${colorTheme}`}
items={schemaWithFieldOptions.fieldOptions}
items={SORTED_COUNTRY_OPTIONS_TO_RENDER}
{...field}
/>
)}
Expand Down
257 changes: 257 additions & 0 deletions shared/constants/countryRegion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,261 @@
export enum CountryRegion {
Afghanistan = 'AFGHANISTAN',
Albania = 'ALBANIA',
Algeria = 'ALGERIA',
American_Samoa = 'AMERICAN SAMOA',
Andorra = 'ANDORRA',
Angola = 'ANGOLA',
Anguilla = 'ANGUILLA',
Antigua = 'ANTIGUA',
Argentina = 'ARGENTINA',
Armenia = 'ARMENIA',
Aruba = 'ARUBA',
Australia = 'AUSTRALIA',
Austria = 'AUSTRIA',
Azerbaijan = 'AZERBAIJAN',
Bahamas = 'BAHAMAS',
Bahrain = 'BAHRAIN',
Bangladesh = 'BANGLADESH',
Barbados = 'BARBADOS',
Belarus = 'BELARUS',
Belgium = 'BELGIUM',
Belize = 'BELIZE',
Benin = 'BENIN',
Bermuda = 'BERMUDA',
Bhutan = 'BHUTAN',
Bolivia = 'BOLIVIA',
Bosnia_Herzegovina = 'BOSNIA-HERZEGOVINA',
Botswana = 'BOTSWANA',
Brazil = 'BRAZIL',
British_Antarctic_Territory = 'BRITISH ANTARCTIC TERRITORY',
British_Indian_Ocean_Territory = 'BRITISH INDIAN OCEAN TERRITORY',
British_Virgin_Islands = 'BRITISH VIRGIN ISLANDS',
Brunei = 'BRUNEI',
Bulgaria = 'BULGARIA',
Burkina_Faso = 'BURKINA FASO',
Burundi = 'BURUNDI',
Cambodia = 'CAMBODIA',
Cameroon = 'CAMEROON',
Canada = 'CANADA',
Canton_and_Enderbury_Islands = 'CANTON & ENDERBURY ISLANDS',
Cape_Verde = 'CAPE VERDE',
Cayman_Islands = 'CAYMAN ISLANDS',
Central_African_Republic = 'CENTRAL AFRICAN REPUBLIC',
Chad = 'CHAD',
Channel_Islands = 'CHANNEL ISLANDS',
Chile = 'CHILE',
China = 'CHINA',
Christmas_Island = 'CHRISTMAS ISLAND',
Cocos_Keeling_Island = 'COCOS KEELING ISLAND',
Colombia = 'COLOMBIA',
Comoros = 'COMOROS',
Congo = 'CONGO',
Cook_Islands = 'COOK ISLANDS',
Costa_Rica = 'COSTA RICA',
Croatia = 'CROATIA',
Cuba = 'CUBA',
Cyprus = 'CYPRUS',
Czech_Republic = 'CZECH REPUBLIC',
Denmark = 'DENMARK',
Djibouti = 'DJIBOUTI',
Dominica = 'DOMINICA',
Dominican_Republic = 'DOMINICAN REPUBLIC',
East_Timor = 'EAST TIMOR',
Ecuador = 'ECUADOR',
Egypt = 'EGYPT',
El_Salvador = 'EL SALVADOR',
Equatorial_Guinea = 'EQUATORIAL GUINEA',
Eritrea = 'ERITREA',
Estonia = 'ESTONIA',
Ethiopia = 'ETHIOPIA',
Faeroe_Islands = 'FAEROE ISLANDS',
Falkland_Islands = 'FALKLAND ISLANDS',
Fiji = 'FIJI',
Finland = 'FINLAND',
France = 'FRANCE',
French_Guiana = 'FRENCH GUIANA',
French_Polynesia = 'FRENCH POLYNESIA',
French_Southern_and_Antarctic_Territories = 'FRENCH SOUTHERN & ANTARCTIC TERRITORIES',
Gabon = 'GABON',
Gambia = 'GAMBIA',
Gaza = 'GAZA',
Georgia = 'GEORGIA',
Germany = 'GERMANY',
Ghana = 'GHANA',
Gibraltar = 'GIBRALTAR',
Greece = 'GREECE',
Greenland = 'GREENLAND',
Grenada = 'GRENADA',
Guadeloupe = 'GUADELOUPE',
Guam = 'GUAM',
Guatemala = 'GUATEMALA',
Guernsey = 'GUERNSEY',
Guinea = 'GUINEA',
Guinea_Bissau = 'GUINEA-BISSAU',
Guyana = 'GUYANA',
Haiti = 'HAITI',
Heard_and_McDonald_Island = 'HEARD & MCDONALD ISLAND',
Honduras = 'HONDURAS',
Hong_Kong = 'HONG KONG',
Hong_Kong_SAR = 'HONG KONG SAR',
Hungary = 'HUNGARY',
Iceland = 'ICELAND',
India = 'INDIA',
Indonesia = 'INDONESIA',
Iran = 'IRAN',
Iraq = 'IRAQ',
Ireland = 'IRELAND',
Isle_Of_Man = 'ISLE OF MAN',
Israel = 'ISRAEL',
Italy = 'ITALY',
Ivory_Coast = 'IVORY COAST',
Jamaica = 'JAMAICA',
Japan = 'JAPAN',
Johnston_Island = 'JOHNSTON ISLAND',
Jordan = 'JORDAN',
Kazakhstan = 'KAZAKHSTAN',
Kenya = 'KENYA',
Kirghizia = 'KIRGHIZIA',
Kiribati = 'KIRIBATI',
Korea_North = 'KOREA, NORTH',
Korea_South = 'KOREA, SOUTH',
Kosovo = 'KOSOVO',
Kuwait = 'KUWAIT',
Kyrgyzstan = 'KYRGYZSTAN',
Laos = 'LAOS',
Latvia = 'LATVIA',
Lebanon = 'LEBANON',
Lesotho = 'LESOTHO',
Liberia = 'LIBERIA',
Libya = 'LIBYA',
Liechtenstein = 'LIECHTENSTEIN',
Lithuania = 'LITHUANIA',
Luxembourg = 'LUXEMBOURG',
Macao = 'MACAO',
Macau_SAR = 'MACAU SAR',
Macedonia = 'MACEDONIA',
Madagascar = 'MADAGASCAR',
Malawi = 'MALAWI',
Malaysia = 'MALAYSIA',
Maldives = 'MALDIVES',
Mali = 'MALI',
Malta = 'MALTA',
Marshall_Islands = 'MARSHALL ISLANDS',
Martinique = 'MARTINIQUE',
Mauritania = 'MAURITANIA',
Mauritius = 'MAURITIUS',
Mayotte = 'MAYOTTE',
Mexico = 'MEXICO',
Midway_Islands = 'MIDWAY ISLANDS',
Moldova = 'MOLDOVA',
Monaco = 'MONACO',
Mongolia = 'MONGOLIA',
Montenegro = 'MONTENEGRO',
Montserrat = 'MONTSERRAT',
Morocco = 'MOROCCO',
Mozambique = 'MOZAMBIQUE',
Myanmar = 'MYANMAR',
Namibia = 'NAMIBIA',
Nauru = 'NAURU',
Nepal = 'NEPAL',
Netherlands = 'NETHERLANDS',
Netherlands_Antililles = 'NETHERLANDS ANTILILLES',
New_Caledonia = 'NEW CALEDONIA',
New_Zealand = 'NEW ZEALAND',
Nicaragua = 'NICARAGUA',
Niger = 'NIGER',
Nigeria = 'NIGERIA',
Niue_Island = 'NIUE ISLAND',
Norfolk_Island = 'NORFOLK ISLAND',
Norway = 'NORWAY',
Oman = 'OMAN',
Others = 'OTHERS',
Pacific_Island_Trust_Territory = 'PACIFIC ISLAND TRUST TERRITORY',
Pakistan = 'PAKISTAN',
Palau = 'PALAU',
Palestine = 'PALESTINE',
Panama = 'PANAMA',
Panama_Canal_Zone = 'PANAMA CANAL ZONE',
Papua_New_Guinea = 'PAPUA NEW GUINEA',
Paraguay = 'PARAGUAY',
Peru = 'PERU',
Philippines = 'PHILIPPINES',
Pitcairn_Island = 'PITCAIRN ISLAND',
Poland = 'POLAND',
Portugal = 'PORTUGAL',
Puerto_Rico = 'PUERTO RICO',
Qatar = 'QATAR',
Reunion = 'REUNION',
Romania = 'ROMANIA',
Russia = 'RUSSIA',
Rwanda = 'RWANDA',
Samoa = 'SAMOA',
San_Marino = 'SAN MARINO',
Sao_Tome_and_Principe = 'SAO TOME & PRINCIPE',
Saudi_Arabia = 'SAUDI ARABIA',
Senegal = 'SENEGAL',
Serbia = 'SERBIA',
Serbia_Montenegro = 'SERBIA/MONTENEGRO',
Seychelles = 'SEYCHELLES',
Sierra_Leone = 'SIERRA LEONE',
Singapore = 'SINGAPORE',
Slovak_Republic = 'SLOVAK REPUBLIC',
Slovenia = 'SLOVENIA',
Solomon_Islands = 'SOLOMON ISLANDS',
Somalia = 'SOMALIA',
South_Africa = 'SOUTH AFRICA',
Spain = 'SPAIN',
Sri_Lanka = 'SRI LANKA',
St_Helena = 'ST. HELENA',
St_Kitts_Nevis = 'ST. KITTS-NEVIS',
St_Lucia = 'ST. LUCIA',
St_Pierre_and_Miquelon = 'ST. PIERRE & MIQUELON',
St_Vincent = 'ST. VINCENT',
Sudan = 'SUDAN',
Suriname = 'SURINAME',
Swaziland = 'SWAZILAND',
Sweden = 'SWEDEN',
Switzerland = 'SWITZERLAND',
Syria = 'SYRIA',
Taiwan = 'TAIWAN',
Tajikistan = 'TAJIKISTAN',
Tanzania = 'TANZANIA',
Thailand = 'THAILAND',
Timor = 'TIMOR',
Togo = 'TOGO',
Tokelau_Islands = 'TOKELAU ISLANDS',
Tonga = 'TONGA',
Trinidad_and_Tobago = 'TRINIDAD & TOBAGO',
Tunisia = 'TUNISIA',
Turkey = 'TURKEY',
Turkmenistan = 'TURKMENISTAN',
Turks_and_Caicos_Islands = 'TURKS & CAICOS ISLANDS',
Tuvalu = 'TUVALU',
Uganda = 'UGANDA',
Ukraine = 'UKRAINE',
United_Arab_Emirates = 'UNITED ARAB EMIRATES',
United_Kingdom = 'UNITED KINGDOM',
United_States = 'UNITED STATES',
Unknown = 'UNKNOWN',
Upper_Volta = 'UPPER VOLTA',
Uruguay = 'URUGUAY',
US_Virgin_Islands = 'US VIRGIN ISLANDS',
Uzbekistan = 'UZBEKISTAN',
Vanuatu = 'VANUATU',
Vatican_City_State = 'VATICAN CITY STATE',
Venezuela = 'VENEZUELA',
Vietnam = 'VIETNAM',
Wake_Island = 'WAKE ISLAND',
Wallis_and_Futuna = 'WALLIS AND FUTUNA',
Western_Sahara = 'WESTERN SAHARA',
Yemen = 'YEMEN',
Yugoslavia = 'YUGOSLAVIA',
Zaire = 'ZAIRE',
Zambia = 'ZAMBIA',
Zimbabwe = 'ZIMBABWE',
}

export enum CountryRegionTitleCase {
Afghanistan = 'Afghanistan',
Albania = 'Albania',
Algeria = 'Algeria',
Expand Down

0 comments on commit 589af79

Please sign in to comment.