diff --git a/app/home/(user)/_components/cart/discount-code.tsx b/app/home/(user)/_components/cart/discount-code.tsx index 0a5cbaf..eea8ef4 100644 --- a/app/home/(user)/_components/cart/discount-code.tsx +++ b/app/home/(user)/_components/cart/discount-code.tsx @@ -1,6 +1,7 @@ "use client" -import { Badge, Heading, Text } from "@medusajs/ui" +import { Badge, Text } from "@medusajs/ui" +import { toast } from '@kit/ui/sonner'; import React, { useActionState } from "react"; import { applyPromotions, submitPromotionForm } from "@lib/data/cart" @@ -31,11 +32,19 @@ export default function DiscountCode({ cart }: { const removePromotionCode = async (code: string) => { const validPromotions = promotions.filter( - (promotion) => promotion.code !== code + (promotion) => promotion.code !== code, ) await applyPromotions( - validPromotions.filter((p) => p.code === undefined).map((p) => p.code!) + validPromotions.filter((p) => p.code === undefined).map((p) => p.code!), + { + onSuccess: () => { + toast.success(t('cart:discountCode.removeSuccess')); + }, + onError: () => { + toast.error(t('cart:discountCode.removeError')); + }, + } ) } @@ -45,7 +54,14 @@ export default function DiscountCode({ cart }: { .map((p) => p.code!) codes.push(code.toString()) - await applyPromotions(codes) + await applyPromotions(codes, { + onSuccess: () => { + toast.success(t('cart:discountCode.addSuccess')); + }, + onError: () => { + toast.error(t('cart:discountCode.addError')); + }, + }); form.reset() } @@ -64,7 +80,7 @@ export default function DiscountCode({ cart }: {
-
-
+
+
-
+
+ {formatCurrency({ + value: cart.subtotal, + currencyCode: cart.currency_code, + locale: language, + })} +
+- {formatCurrency({ - value: cart.total, - currencyCode: cart.currency_code, - locale: language, - })} -
+
+
+ {formatCurrency({ + value: cart.discount_total, + currencyCode: cart.currency_code, + locale: language, + })} +
+
+
+ {formatCurrency({ + value: cart.total, + currencyCode: cart.currency_code, + locale: language, + })} +
+