Skip to content

Commit 326164b

Browse files
Merge pull request #220 from mercurjs/fix/mm2-1492
fix/mm2-1492
2 parents a8bdc09 + 3dd2976 commit 326164b

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/components/sections/CartShippingMethodsSection/CartShippingMethodRow.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
import { Button } from "@/components/atoms"
44
import { BinIcon } from "@/icons"
5-
import { removeShippingMethod } from "@/lib/data/cart"
5+
66
import { convertToLocale } from "@/lib/helpers/money"
77
import { HttpTypes } from "@medusajs/types"
88
import { Text } from "@medusajs/ui"
99

1010
export const CartShippingMethodRow = ({
1111
method,
1212
currency_code,
13+
onRemoveShippingMethod,
1314
}: {
1415
method: HttpTypes.StoreCartShippingMethod
1516
currency_code: string
17+
onRemoveShippingMethod: (methodId: string) => void
1618
}) => {
17-
const handleRemoveShippingMethod = async () => {
18-
await removeShippingMethod(method.id)
19-
}
20-
2119
return (
2220
<div className="mb-4 border rounded-md p-4 flex items-center justify-between">
2321
<div>
@@ -35,7 +33,7 @@ export const CartShippingMethodRow = ({
3533
variant="tonal"
3634
size="small"
3735
className="p-2"
38-
onClick={handleRemoveShippingMethod}
36+
onClick={() => onRemoveShippingMethod(method.id)}
3937
>
4038
<BinIcon size={16} />
4139
</Button>

src/components/sections/CartShippingMethodsSection/CartShippingMethodsSection.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client"
22

33
import ErrorMessage from "@/components/molecules/ErrorMessage/ErrorMessage"
4-
import { setShippingMethod } from "@/lib/data/cart"
4+
import { removeShippingMethod, setShippingMethod } from "@/lib/data/cart"
55
import { calculatePriceForShippingOption } from "@/lib/data/fulfillment"
66
import { convertToLocale } from "@/lib/helpers/money"
77
import { CheckCircleSolid, ChevronUpDown, Loader } from "@medusajs/icons"
@@ -58,6 +58,8 @@ const CartShippingMethodsSection: React.FC<ShippingProps> = ({
5858
availableShippingMethods,
5959
}) => {
6060
const [isLoadingPrices, setIsLoadingPrices] = useState(false)
61+
const [isRemovingShippingMethod, setIsRemovingShippingMethod] =
62+
useState(false)
6163
const [calculatedPricesMap, setCalculatedPricesMap] = useState<
6264
Record<string, number>
6365
>({})
@@ -149,6 +151,12 @@ const CartShippingMethodsSection: React.FC<ShippingProps> = ({
149151
}
150152
}
151153

154+
const handleRemoveShippingMethod = async (methodId: string) => {
155+
setIsRemovingShippingMethod(true)
156+
await removeShippingMethod(methodId)
157+
setIsRemovingShippingMethod(false)
158+
}
159+
152160
useEffect(() => {
153161
setError(null)
154162
}, [isOpen])
@@ -315,13 +323,14 @@ const CartShippingMethodsSection: React.FC<ShippingProps> = ({
315323
</div>
316324
)
317325
})}
318-
{cart && (cart.shipping_methods?.length ?? 0) > 0 && (
326+
{!!cart?.shipping_methods?.length && (
319327
<div className="flex flex-col">
320328
{cart.shipping_methods?.map((method) => (
321329
<CartShippingMethodRow
322330
key={method.id}
323331
method={method}
324332
currency_code={cart.currency_code}
333+
onRemoveShippingMethod={handleRemoveShippingMethod}
325334
/>
326335
))}
327336
</div>
@@ -337,7 +346,7 @@ const CartShippingMethodsSection: React.FC<ShippingProps> = ({
337346
<Button
338347
onClick={handleSubmit}
339348
variant="tonal"
340-
disabled={!cart.shipping_methods?.[0]}
349+
disabled={!cart.shipping_methods?.[0] || isRemovingShippingMethod}
341350
loading={isLoadingPrices}
342351
>
343352
Continue to payment

0 commit comments

Comments
 (0)