|
| 1 | +--- |
| 2 | +"@bigcommerce/catalyst-core": patch |
| 3 | +--- |
| 4 | + |
| 5 | +Use state abbreviation instead of entityId for cart shipping form state values. The shipping API expects state abbreviations, and using entityId caused form submissions to fail. Additionally, certain US military states that share the same abbreviation (AE) are now filtered out to prevent duplicate key issues and ambiguous submissions. |
| 6 | + |
| 7 | +## Migration steps |
| 8 | + |
| 9 | +### Step 1: Add blacklist for states with duplicate abbreviations |
| 10 | + |
| 11 | +Certain US states share the same abbreviation (AE), which causes issues with the shipping API and React select dropdowns. Add a blacklist to filter these out. |
| 12 | + |
| 13 | +Update `core/app/[locale]/(default)/cart/page.tsx`: |
| 14 | + |
| 15 | +```diff |
| 16 | + const countries = shippingCountries.map((country) => ({ |
| 17 | + value: country.code, |
| 18 | + label: country.name, |
| 19 | + })); |
| 20 | + |
| 21 | ++ // These US states share the same abbreviation (AE), which causes issues: |
| 22 | ++ // 1. The shipping API uses abbreviations, so it can't distinguish between them |
| 23 | ++ // 2. React select dropdowns require unique keys, causing duplicate key warnings |
| 24 | ++ const blacklistedUSStates = new Set([ |
| 25 | ++ 'Armed Forces Africa', |
| 26 | ++ 'Armed Forces Canada', |
| 27 | ++ 'Armed Forces Middle East', |
| 28 | ++ ]); |
| 29 | + |
| 30 | + const statesOrProvinces = shippingCountries.map((country) => ({ |
| 31 | +``` |
| 32 | + |
| 33 | +### Step 2: Use state abbreviation instead of entityId |
| 34 | + |
| 35 | +Update the state mapping to use `abbreviation` instead of `entityId`, and apply the blacklist filter for US states. |
| 36 | + |
| 37 | +Update `core/app/[locale]/(default)/cart/page.tsx`: |
| 38 | + |
| 39 | +```diff |
| 40 | + const statesOrProvinces = shippingCountries.map((country) => ({ |
| 41 | + country: country.code, |
| 42 | +- states: country.statesOrProvinces.map((state) => ({ |
| 43 | +- value: state.entityId.toString(), |
| 44 | +- label: state.name, |
| 45 | +- })), |
| 46 | ++ states: country.statesOrProvinces |
| 47 | ++ .filter((state) => country.code !== 'US' || !blacklistedUSStates.has(state.name)) |
| 48 | ++ .map((state) => ({ |
| 49 | ++ value: state.abbreviation, |
| 50 | ++ label: state.name, |
| 51 | ++ })), |
| 52 | + })); |
| 53 | +``` |
0 commit comments