diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-08-02 13:23:30 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-08-02 13:23:30 +0700 |
| commit | 30a686e4140a503d88142e71c25bc517092b4bd5 (patch) | |
| tree | 0fdd51e8f8609d5965463fb5eb6f61870b60fab4 /src-migrate/pages | |
| parent | e4bbb9cf1b1918ce33e6c2ee22acf17b49d0fcd1 (diff) | |
<iman> update delete button
Diffstat (limited to 'src-migrate/pages')
| -rw-r--r-- | src-migrate/pages/shop/cart/index.tsx | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index cb0156f1..4586c65c 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -15,7 +15,8 @@ import useDevice from '@/core/hooks/useDevice'; import CartSummaryMobile from '~/modules/cart/components/CartSummaryMobile'; import Image from '~/components/ui/image'; import { CartItem } from '~/types/cart' -import { upsertUserCart } from '~/services/cart' +import { deleteUserCart ,upsertUserCart } from '~/services/cart' +import { Trash2Icon } from 'lucide-react'; const CartPage = () => { const router = useRouter(); @@ -25,7 +26,7 @@ const CartPage = () => { const [isButtonChek, setIsButtonChek] = useState(false); const [buttonSelectNow, setButtonSelectNow] = useState(true); const [isLoad, setIsLoad] = useState<boolean>(false) - + const [isLoadDelete, setIsLoadDelete] = useState<boolean>(false) const { loadCart, cart, summary } = useCartStore(); const useDivvice = useDevice(); @@ -87,8 +88,17 @@ const CartPage = () => { setIsLoad(false) } - const handleDelete = () => { - console.log("delete data"); + const handleDelete = async () => { + if (typeof auth !== 'object' || !cart) return; + + setIsLoadDelete(true) + for (const item of cart.products) { + if(item.selected === true){ + await deleteUserCart(auth.id, [item.cart_id]) + await loadCart(auth.id) + } + } + setIsLoadDelete(false) } return ( @@ -128,7 +138,11 @@ const CartPage = () => { isDisabled={!hasSelected || hasSelectNoPrice} onClick={handleDelete} > - Hapus Barang + {isLoadDelete && <Spinner size='xs' />} + {!isLoadDelete && <Trash2Icon size={16} />} + <p className='text-sm ml-2'> + Hapus Barang + </p> </Button> </Tooltip> </div> |
