diff --git a/src/app/cart/components/DiscountCard.tsx b/src/app/cart/components/DiscountCard.tsx index 1edf1bd..a8ab716 100644 --- a/src/app/cart/components/DiscountCard.tsx +++ b/src/app/cart/components/DiscountCard.tsx @@ -1,32 +1,50 @@ import { Button } from '@/components/ui/button' import Input from '@/components/Input' import { FC, useState } from 'react' +import { useAddCoupon, useGetCart } from '../hooks/useCartData' +import { toast } from '@/components/Toast' +import { extractErrorMessage } from '@/helpers/errorUtils' -type DiscountCardProps = { - discountCode: string - setDiscountCode: (code: string) => void - onSubmit: () => void - isLoading?: boolean -} -const DiscountCard: FC = ({ - discountCode, - setDiscountCode, - onSubmit, - isLoading = false -}) => { + +const DiscountCard: FC = () => { const [isExpanded, setIsExpanded] = useState(false) + const [couponCode, setCouponCode] = useState('') + const addCouponMutation = useAddCoupon() + const { data: cartData, refetch } = useGetCart() - const handleSubmit = (e: React.FormEvent) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() - onSubmit() + + if (!couponCode.trim()) { + toast('لطفاً کد کوپن را وارد کنید', 'error') + return + } + + await addCouponMutation.mutateAsync({ + code: couponCode, + cartShipmentItemId: cartData?.results?.cart?.cartShipmentItems?.[0]._id as string + }, { + onSuccess: () => { + toast('کوپن با موفقیت اعمال شد', 'success') + refetch() + setCouponCode('') + setIsExpanded(false) + }, + onError: (error) => { + toast(extractErrorMessage(error), 'error') + } + }) + + } + if (!isExpanded) { return (
- کد تخفیف دارید؟ + کد کوپن دارید؟
+ +
+ + + ) + } + + // صفحه پرداخت موفق + if (status === 'success') { + return ( +
+
+ {/* آیکون موفقیت */} +
+
+ +
+
+ + {/* پیام اصلی */} +

+ پرداخت با موفقیت انجام شد +

+

+ سفارش شما ثبت شد و به زودی ارسال می‌شود +

+ + {/* اطلاعات سفارش */} +
+
+
+ شماره سفارش: + {orderId} +
+
+ کد پیگیری: + {paymentId} +
+
+
+ + {/* دکمه‌های اکشن */} +
+ + +
+
+
+ ) + } + + // در صورتی که status معتبر نباشد + return ( +
+
+
+ اطلاعات پرداخت نامعتبر است +
+ +
+
+ ) +} + +const ThankYouPage = () => { + return ( + + +
+ + } + > + +
+
+ ) +} + +export default ThankYouPage \ No newline at end of file diff --git a/src/share/components/Cart.tsx b/src/share/components/Cart.tsx index 88f09d6..2b2677b 100644 --- a/src/share/components/Cart.tsx +++ b/src/share/components/Cart.tsx @@ -145,7 +145,7 @@ const Cart = () => { {/* View Cart Button */} - {itemsCount > 0 && ( + {itemsCount > 0 && isLogin && (