clear cart

This commit is contained in:
hamid zarghami
2025-12-16 16:50:37 +03:30
parent 806c0c3c48
commit f49e635c51
2 changed files with 35 additions and 2 deletions
+29 -1
View File
@@ -7,12 +7,27 @@ import { ArrowLeft, Trash } from 'iconsax-react';
import { useCart } from './hook/useCart';
import CartItemsList from './components/CartItemsList';
import CartSummary from './components/CartSummary';
import Prompt from '@/components/utils/Prompt';
const CartIndex = () => {
const { t } = useTranslation('parallels', { keyPrefix: 'Cart' });
const router = useRouter();
const { clearCart } = useCart();
const [description, setDescription] = React.useState('');
const [showClearConfirm, setShowClearConfirm] = React.useState(false);
const handleClearCart = (e: React.MouseEvent) => {
e?.preventDefault();
e?.stopPropagation();
clearCart();
setShowClearConfirm(false);
};
const toggleClearConfirm = (e: React.MouseEvent) => {
e?.preventDefault();
e?.stopPropagation();
setShowClearConfirm(false);
};
return (
<div className='bg-inherit flex flex-col h-full'>
@@ -21,7 +36,7 @@ const CartIndex = () => {
className='cursor-pointer place-self-start'
size='24'
color='currentColor'
onClick={clearCart}
onClick={() => setShowClearConfirm(true)}
/>
<h1 className='text-sm2 place-self-center font-medium'>{t('Heading')}</h1>
<ArrowLeft
@@ -36,6 +51,19 @@ const CartIndex = () => {
<CartItemsList />
<CartSummary description={description} onDescriptionChange={setDescription} />
</div>
<div className={showClearConfirm ? 'fixed inset-0 z-1001' : 'pointer-events-none fixed inset-0 z-1001'}>
<Prompt
title='پاک کردن سبد خرید'
description='آیا از پاک کردن تمامی آیتم‌های سبد خرید اطمینان دارید؟'
textConfirm='بله'
textCancel='خیر'
onConfirm={handleClearCart}
onCancel={toggleClearConfirm}
visible={showClearConfirm}
onClick={toggleClearConfirm}
/>
</div>
</div>
);
};
@@ -17,7 +17,7 @@ export const decrement = async (id: string | number) => {
};
export const clear = async () => {
const { data } = await api.delete("/public/cart/items");
const { data } = await api.delete("/public/cart");
return data;
};
@@ -25,3 +25,8 @@ export const getCartItems = async (): Promise<CartResponse> => {
const { data } = await api.get<CartResponse>("/public/cart");
return data;
};
export const getCartSummary = async () => {
const { data } = await api.get("/public/cart/summary");
return data;
};