clear cart
This commit is contained in:
@@ -7,12 +7,27 @@ import { ArrowLeft, Trash } from 'iconsax-react';
|
|||||||
import { useCart } from './hook/useCart';
|
import { useCart } from './hook/useCart';
|
||||||
import CartItemsList from './components/CartItemsList';
|
import CartItemsList from './components/CartItemsList';
|
||||||
import CartSummary from './components/CartSummary';
|
import CartSummary from './components/CartSummary';
|
||||||
|
import Prompt from '@/components/utils/Prompt';
|
||||||
|
|
||||||
const CartIndex = () => {
|
const CartIndex = () => {
|
||||||
const { t } = useTranslation('parallels', { keyPrefix: 'Cart' });
|
const { t } = useTranslation('parallels', { keyPrefix: 'Cart' });
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { clearCart } = useCart();
|
const { clearCart } = useCart();
|
||||||
const [description, setDescription] = React.useState('');
|
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 (
|
return (
|
||||||
<div className='bg-inherit flex flex-col h-full'>
|
<div className='bg-inherit flex flex-col h-full'>
|
||||||
@@ -21,7 +36,7 @@ const CartIndex = () => {
|
|||||||
className='cursor-pointer place-self-start'
|
className='cursor-pointer place-self-start'
|
||||||
size='24'
|
size='24'
|
||||||
color='currentColor'
|
color='currentColor'
|
||||||
onClick={clearCart}
|
onClick={() => setShowClearConfirm(true)}
|
||||||
/>
|
/>
|
||||||
<h1 className='text-sm2 place-self-center font-medium'>{t('Heading')}</h1>
|
<h1 className='text-sm2 place-self-center font-medium'>{t('Heading')}</h1>
|
||||||
<ArrowLeft
|
<ArrowLeft
|
||||||
@@ -36,6 +51,19 @@ const CartIndex = () => {
|
|||||||
<CartItemsList />
|
<CartItemsList />
|
||||||
<CartSummary description={description} onDescriptionChange={setDescription} />
|
<CartSummary description={description} onDescriptionChange={setDescription} />
|
||||||
</div>
|
</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>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const decrement = async (id: string | number) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const clear = async () => {
|
export const clear = async () => {
|
||||||
const { data } = await api.delete("/public/cart/items");
|
const { data } = await api.delete("/public/cart");
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,3 +25,8 @@ export const getCartItems = async (): Promise<CartResponse> => {
|
|||||||
const { data } = await api.get<CartResponse>("/public/cart");
|
const { data } = await api.get<CartResponse>("/public/cart");
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getCartSummary = async () => {
|
||||||
|
const { data } = await api.get("/public/cart/summary");
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user