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

Commit

Permalink
Revert "feat: Use country-state-city to populate state dropdown in St…
Browse files Browse the repository at this point in the history
…ateProvi…" (#855)

This reverts commit 58cde5d.
  • Loading branch information
julianajlk authored Feb 27, 2024
1 parent 58cde5d commit 9dc662f
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 49 deletions.
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"bootstrap": "4.6.1",
"classnames": "^2.3.1",
"core-js": "^3.23.5",
"country-state-city": "^3.2.1",
"form-urlencoded": "^6.0.6",
"lodash.camelcase": "^4.3.0",
"lodash.snakecase": "^4.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/payment/checkout/payment-form/StateProvinceFormInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import PropTypes from 'prop-types';
import { Field } from 'redux-form';
import { injectIntl, intlShape, FormattedMessage } from '@edx/frontend-platform/i18n';

import { getCountryStatesMap } from './utils/form-validators';
import FormInput from './FormInput';
import FormSelect from './FormSelect';
import getStates from './utils/countryStatesMap';
import messages from './StateProvinceFormInput.messages';

class StateProvinceFormInput extends React.Component {
getOptions() {
const options = [];
const { country } = this.props;
const states = getCountryStatesMap(country);
const states = getStates(country);

if (states) {
options.push([(
Expand Down
25 changes: 3 additions & 22 deletions src/payment/checkout/payment-form/StripePaymentForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,16 @@ describe('<StripePaymentForm />', () => {
lastName: '',
address: '',
city: '',
country: 'AQ', // Antarctica does not have states, postal code not required
optionalField: '',
},
{
firstName: '',
lastName: '',
address: '',
city: '',
country: 'GB', // United Kingdom has states, state becomes required, postal code is required
country: 'GB',
postalCode: '',
state: '',
optionalField: '',
},
{
firstName: '',
lastName: '',
address: '',
city: '',
country: 'CA', // Canada state and postal code are required
postalCode: '',
state: '',
optionalField: '',
},
{
firstName: '',
lastName: '',
address: '',
city: '',
country: 'US', // United States state and postal code are required
country: 'US',
postalCode: '',
state: '',
optionalField: '',
Expand All @@ -166,7 +147,7 @@ describe('<StripePaymentForm />', () => {
lastName: '',
address: '',
city: '',
country: 'IN', // India state is required
country: 'IN',
state: '',
optionalField: '',
},
Expand Down
115 changes: 115 additions & 0 deletions src/payment/checkout/payment-form/utils/countryStatesMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
const COUNTRY_STATES_MAP = {
CA: {
AB: 'Alberta',
BC: 'British Columbia',
MB: 'Manitoba',
NB: 'New Brunswick',
NL: 'Newfoundland and Labrador',
NS: 'Nova Scotia',
NT: 'Northwest Territories',
NU: 'Nunavut',
ON: 'Ontario',
PE: 'Prince Edward Island',
QC: 'Québec',
SK: 'Saskatchewan',
YT: 'Yukon',
},
IN: {
AN: 'Andaman and Nicobar Islands',
AP: 'Andhra Pradesh',
AR: 'Arunachal Pradesh',
AS: 'Assam',
BR: 'Bihar',
CH: 'Chandigarh',
CT: 'Chhattisgarh',
DN: 'Dadra and Nagar Haveli',
DD: 'Daman and Diu',
DL: 'Delhi',
GA: 'Goa',
GJ: 'Gujarat',
HR: 'Haryana',
HP: 'Himachal Pradesh',
JK: 'Jammu and Kashmir',
JH: 'Jharkhand',
KA: 'Karnataka',
KL: 'Kerala',
LD: 'Lakshadweep',
MP: 'Madhya Pradesh',
MH: 'Maharashtra',
MN: 'Manipur',
ML: 'Meghalaya',
MZ: 'Mizoram',
NL: 'Nagaland',
OR: 'Odisha',
PY: 'Puducherry',
PB: 'Punjab',
RJ: 'Rajasthan',
SK: 'Sikkim',
TN: 'Tamil Nadu',
TG: 'Telangana',
TR: 'Tripura',
UP: 'Uttar Pradesh',
UT: 'Uttarakhand',
WB: 'West Bengal',
},
US: {
AL: 'Alabama',
AK: 'Alaska',
AZ: 'Arizona',
AR: 'Arkansas',
AA: 'Armed Forces Americas',
AE: 'Armed Forces Europe',
AP: 'Armed Forces Pacific',
CA: 'California',
CO: 'Colorado',
CT: 'Connecticut',
DE: 'Delaware',
DC: 'District Of Columbia',
FL: 'Florida',
GA: 'Georgia',
HI: 'Hawaii',
ID: 'Idaho',
IL: 'Illinois',
IN: 'Indiana',
IA: 'Iowa',
KS: 'Kansas',
KY: 'Kentucky',
LA: 'Louisiana',
ME: 'Maine',
MD: 'Maryland',
MA: 'Massachusetts',
MI: 'Michigan',
MN: 'Minnesota',
MS: 'Mississippi',
MO: 'Missouri',
MT: 'Montana',
NE: 'Nebraska',
NV: 'Nevada',
NH: 'New Hampshire',
NJ: 'New Jersey',
NM: 'New Mexico',
NY: 'New York',
NC: 'North Carolina',
ND: 'North Dakota',
OH: 'Ohio',
OK: 'Oklahoma',
OR: 'Oregon',
PA: 'Pennsylvania',
RI: 'Rhode Island',
SC: 'South Carolina',
SD: 'South Dakota',
TN: 'Tennessee',
TX: 'Texas',
UT: 'Utah',
VT: 'Vermont',
VA: 'Virginia',
WA: 'Washington',
WV: 'West Virginia',
WI: 'Wisconsin',
WY: 'Wyoming',
},
};

export default function getStates(country) {
return country && COUNTRY_STATES_MAP[country.toUpperCase()];
}
20 changes: 2 additions & 18 deletions src/payment/checkout/payment-form/utils/form-validators.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { State } from 'country-state-city';

export const getCountryStatesMap = (country) => {
const states = State.getStatesOfCountry(country);

if (!states.length) {
return null;
}
const statesMap = {};
states.forEach((state) => {
statesMap[state.isoCode] = state.name;
});
return country && statesMap;
};
import getStates from './countryStatesMap';

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

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

Expand Down

0 comments on commit 9dc662f

Please sign in to comment.