Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 9dc662f

Browse files
authored
Revert "feat: Use country-state-city to populate state dropdown in StateProvi…" (#855)
This reverts commit 58cde5d.
1 parent 58cde5d commit 9dc662f

File tree

6 files changed

+122
-49
lines changed

6 files changed

+122
-49
lines changed

package-lock.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"bootstrap": "4.6.1",
4848
"classnames": "^2.3.1",
4949
"core-js": "^3.23.5",
50-
"country-state-city": "^3.2.1",
5150
"form-urlencoded": "^6.0.6",
5251
"lodash.camelcase": "^4.3.0",
5352
"lodash.snakecase": "^4.1.1",

src/payment/checkout/payment-form/StateProvinceFormInput.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import PropTypes from 'prop-types';
33
import { Field } from 'redux-form';
44
import { injectIntl, intlShape, FormattedMessage } from '@edx/frontend-platform/i18n';
55

6-
import { getCountryStatesMap } from './utils/form-validators';
76
import FormInput from './FormInput';
87
import FormSelect from './FormSelect';
8+
import getStates from './utils/countryStatesMap';
99
import messages from './StateProvinceFormInput.messages';
1010

1111
class StateProvinceFormInput extends React.Component {
1212
getOptions() {
1313
const options = [];
1414
const { country } = this.props;
15-
const states = getCountryStatesMap(country);
15+
const states = getStates(country);
1616

1717
if (states) {
1818
options.push([(

src/payment/checkout/payment-form/StripePaymentForm.test.jsx

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,35 +128,16 @@ describe('<StripePaymentForm />', () => {
128128
lastName: '',
129129
address: '',
130130
city: '',
131-
country: 'AQ', // Antarctica does not have states, postal code not required
132-
optionalField: '',
133-
},
134-
{
135-
firstName: '',
136-
lastName: '',
137-
address: '',
138-
city: '',
139-
country: 'GB', // United Kingdom has states, state becomes required, postal code is required
131+
country: 'GB',
140132
postalCode: '',
141-
state: '',
142-
optionalField: '',
143-
},
144-
{
145-
firstName: '',
146-
lastName: '',
147-
address: '',
148-
city: '',
149-
country: 'CA', // Canada state and postal code are required
150-
postalCode: '',
151-
state: '',
152133
optionalField: '',
153134
},
154135
{
155136
firstName: '',
156137
lastName: '',
157138
address: '',
158139
city: '',
159-
country: 'US', // United States state and postal code are required
140+
country: 'US',
160141
postalCode: '',
161142
state: '',
162143
optionalField: '',
@@ -166,7 +147,7 @@ describe('<StripePaymentForm />', () => {
166147
lastName: '',
167148
address: '',
168149
city: '',
169-
country: 'IN', // India state is required
150+
country: 'IN',
170151
state: '',
171152
optionalField: '',
172153
},
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
const COUNTRY_STATES_MAP = {
2+
CA: {
3+
AB: 'Alberta',
4+
BC: 'British Columbia',
5+
MB: 'Manitoba',
6+
NB: 'New Brunswick',
7+
NL: 'Newfoundland and Labrador',
8+
NS: 'Nova Scotia',
9+
NT: 'Northwest Territories',
10+
NU: 'Nunavut',
11+
ON: 'Ontario',
12+
PE: 'Prince Edward Island',
13+
QC: 'Québec',
14+
SK: 'Saskatchewan',
15+
YT: 'Yukon',
16+
},
17+
IN: {
18+
AN: 'Andaman and Nicobar Islands',
19+
AP: 'Andhra Pradesh',
20+
AR: 'Arunachal Pradesh',
21+
AS: 'Assam',
22+
BR: 'Bihar',
23+
CH: 'Chandigarh',
24+
CT: 'Chhattisgarh',
25+
DN: 'Dadra and Nagar Haveli',
26+
DD: 'Daman and Diu',
27+
DL: 'Delhi',
28+
GA: 'Goa',
29+
GJ: 'Gujarat',
30+
HR: 'Haryana',
31+
HP: 'Himachal Pradesh',
32+
JK: 'Jammu and Kashmir',
33+
JH: 'Jharkhand',
34+
KA: 'Karnataka',
35+
KL: 'Kerala',
36+
LD: 'Lakshadweep',
37+
MP: 'Madhya Pradesh',
38+
MH: 'Maharashtra',
39+
MN: 'Manipur',
40+
ML: 'Meghalaya',
41+
MZ: 'Mizoram',
42+
NL: 'Nagaland',
43+
OR: 'Odisha',
44+
PY: 'Puducherry',
45+
PB: 'Punjab',
46+
RJ: 'Rajasthan',
47+
SK: 'Sikkim',
48+
TN: 'Tamil Nadu',
49+
TG: 'Telangana',
50+
TR: 'Tripura',
51+
UP: 'Uttar Pradesh',
52+
UT: 'Uttarakhand',
53+
WB: 'West Bengal',
54+
},
55+
US: {
56+
AL: 'Alabama',
57+
AK: 'Alaska',
58+
AZ: 'Arizona',
59+
AR: 'Arkansas',
60+
AA: 'Armed Forces Americas',
61+
AE: 'Armed Forces Europe',
62+
AP: 'Armed Forces Pacific',
63+
CA: 'California',
64+
CO: 'Colorado',
65+
CT: 'Connecticut',
66+
DE: 'Delaware',
67+
DC: 'District Of Columbia',
68+
FL: 'Florida',
69+
GA: 'Georgia',
70+
HI: 'Hawaii',
71+
ID: 'Idaho',
72+
IL: 'Illinois',
73+
IN: 'Indiana',
74+
IA: 'Iowa',
75+
KS: 'Kansas',
76+
KY: 'Kentucky',
77+
LA: 'Louisiana',
78+
ME: 'Maine',
79+
MD: 'Maryland',
80+
MA: 'Massachusetts',
81+
MI: 'Michigan',
82+
MN: 'Minnesota',
83+
MS: 'Mississippi',
84+
MO: 'Missouri',
85+
MT: 'Montana',
86+
NE: 'Nebraska',
87+
NV: 'Nevada',
88+
NH: 'New Hampshire',
89+
NJ: 'New Jersey',
90+
NM: 'New Mexico',
91+
NY: 'New York',
92+
NC: 'North Carolina',
93+
ND: 'North Dakota',
94+
OH: 'Ohio',
95+
OK: 'Oklahoma',
96+
OR: 'Oregon',
97+
PA: 'Pennsylvania',
98+
RI: 'Rhode Island',
99+
SC: 'South Carolina',
100+
SD: 'South Dakota',
101+
TN: 'Tennessee',
102+
TX: 'Texas',
103+
UT: 'Utah',
104+
VT: 'Vermont',
105+
VA: 'Virginia',
106+
WA: 'Washington',
107+
WV: 'West Virginia',
108+
WI: 'Wisconsin',
109+
WY: 'Wyoming',
110+
},
111+
};
112+
113+
export default function getStates(country) {
114+
return country && COUNTRY_STATES_MAP[country.toUpperCase()];
115+
}

src/payment/checkout/payment-form/utils/form-validators.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
// eslint-disable-next-line import/no-extraneous-dependencies
2-
import { State } from 'country-state-city';
3-
4-
export const getCountryStatesMap = (country) => {
5-
const states = State.getStatesOfCountry(country);
6-
7-
if (!states.length) {
8-
return null;
9-
}
10-
const statesMap = {};
11-
states.forEach((state) => {
12-
statesMap[state.isoCode] = state.name;
13-
});
14-
return country && statesMap;
15-
};
1+
import getStates from './countryStatesMap';
162

173
// eslint-disable-next-line import/prefer-default-export
184
export function isPostalCodeRequired(selectedCountry) {
@@ -53,9 +39,7 @@ export function getRequiredFields(fieldValues, isBulkOrder = false, enableStripe
5339
requiredFields.postalCode = postalCode;
5440
}
5541

56-
// By using the country-state-city library to populate states, every country that
57-
// has states from the ISO 3166-2 list will have states as a required field
58-
if (getCountryStatesMap(country)) {
42+
if (getStates(country)) {
5943
requiredFields.state = state;
6044
}
6145

0 commit comments

Comments
 (0)