Skip to content

Commit a6ce904

Browse files
committed
fix(core): use state abbreviation instead of entityId for shipping form
1 parent 74dee6e commit a6ce904

2 files changed

Lines changed: 68 additions & 4 deletions

File tree

.changeset/legal-adults-look.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
```

core/app/[locale]/(default)/cart/page.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,23 @@ export default async function Cart({ params }: Props) {
192192
label: country.name,
193193
}));
194194

195+
// These US states share the same abbreviation (AE), which causes issues:
196+
// 1. The shipping API uses abbreviations, so it can't distinguish between them
197+
// 2. React select dropdowns require unique keys, causing duplicate key warnings
198+
const blacklistedUSStates = new Set([
199+
'Armed Forces Africa',
200+
'Armed Forces Canada',
201+
'Armed Forces Middle East',
202+
]);
203+
195204
const statesOrProvinces = shippingCountries.map((country) => ({
196205
country: country.code,
197-
states: country.statesOrProvinces.map((state) => ({
198-
value: state.entityId.toString(),
199-
label: state.name,
200-
})),
206+
states: country.statesOrProvinces
207+
.filter((state) => country.code !== 'US' || !blacklistedUSStates.has(state.name))
208+
.map((state) => ({
209+
value: state.abbreviation,
210+
label: state.name,
211+
})),
201212
}));
202213

203214
const showShippingForm =

0 commit comments

Comments
 (0)