Skip to content

Commit d9bb37f

Browse files
committed
fix duplicate error toast
Signed-off-by: d.phan <d.phan@salesforce.com>
1 parent b010a1c commit d9bb37f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-shipping-options.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default function ShippingOptions() {
5252
const showToast = useToast()
5353
const [noMethodsToastShown, setNoMethodsToastShown] = useState(false)
5454
const [shipmentIdsWithNoMethods, setShipmentIdsWithNoMethods] = useState(() => new Set())
55+
const [resolvedShipmentIds, setResolvedShipmentIds] = useState(() => new Set())
5556

5657
const productItems = basket?.productItems || []
5758
const deliveryShipments =
@@ -93,13 +94,15 @@ export default function ShippingOptions() {
9394
prevHasMultipleRef.current = hasMultipleDeliveryShipments
9495

9596
if (wasMulti && !hasMultipleDeliveryShipments) return
97+
if (step === STEPS.SHIPPING_OPTIONS) return
9698

9799
setNoMethodsToastShown(false)
98-
}, [deliveryAddressStateKey, hasMultipleDeliveryShipments])
100+
}, [deliveryAddressStateKey, hasMultipleDeliveryShipments, step, STEPS.SHIPPING_OPTIONS])
99101

100102
useEffect(() => {
101103
if (!hasMultipleDeliveryShipments) {
102104
setShipmentIdsWithNoMethods(() => new Set())
105+
setResolvedShipmentIds(() => new Set())
103106
}
104107
}, [hasMultipleDeliveryShipments])
105108

@@ -120,17 +123,24 @@ export default function ShippingOptions() {
120123
)
121124

122125
const handleShipmentMethodsResolved = useCallback((shipmentId, hasNoApplicableMethods) => {
126+
setResolvedShipmentIds((prev) => {
127+
const next = new Set(prev)
128+
next.add(shipmentId)
129+
return next
130+
})
123131
setShipmentIdsWithNoMethods((prev) => {
124132
const next = new Set(prev)
125133
if (hasNoApplicableMethods) next.add(shipmentId)
126134
else next.delete(shipmentId)
127135
return next
128136
})
129137
}, [])
138+
const allShipmentsResolved = resolvedShipmentIds.size >= deliveryShipments.length
130139
const hasAnyShipmentWithNoMethods = shipmentIdsWithNoMethods.size > 0
131140

132141
useEffect(() => {
133142
if (
143+
allShipmentsResolved &&
134144
hasAnyShipmentWithNoMethods &&
135145
!noMethodsToastShown &&
136146
step === STEPS.SHIPPING_OPTIONS &&
@@ -140,6 +150,7 @@ export default function ShippingOptions() {
140150
setNoMethodsToastShown(true)
141151
}
142152
}, [
153+
allShipmentsResolved,
143154
hasAnyShipmentWithNoMethods,
144155
noMethodsToastShown,
145156
step,

0 commit comments

Comments
 (0)