diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-08-02 11:19:10 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-08-02 11:19:10 +0700 |
| commit | e4bbb9cf1b1918ce33e6c2ee22acf17b49d0fcd1 (patch) | |
| tree | f3dbf27e4712059b19f42faccb88ad042c610496 | |
| parent | 8c848cf35811ee95e88ce03745ee25315172d758 (diff) | |
<iman> add delete all cart button
| -rw-r--r-- | src-migrate/pages/shop/cart/index.tsx | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 0eb9c554..cb0156f1 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -2,7 +2,7 @@ import style from './cart.module.css'; import React, { useEffect, useMemo, useState } from 'react'; import Link from 'next/link'; -import { Button, Checkbox, Tooltip } from '@chakra-ui/react'; +import { Button, Checkbox, Spinner, Tooltip } from '@chakra-ui/react'; import { toast } from 'react-hot-toast'; import { useRouter } from 'next/router'; import { getAuth } from '~/libs/auth'; @@ -24,6 +24,7 @@ const CartPage = () => { const [isSelectedAll, setIsSelectedAll] = useState(false); const [isButtonChek, setIsButtonChek] = useState(false); const [buttonSelectNow, setButtonSelectNow] = useState(true); + const [isLoad, setIsLoad] = useState<boolean>(false) const { loadCart, cart, summary } = useCartStore(); const useDivvice = useDevice(); @@ -69,7 +70,7 @@ const CartPage = () => { const handleChange = async (e: React.ChangeEvent<HTMLInputElement>) => { if (typeof auth !== 'object' || !cart) return; - + setIsLoad(true) const newSelected = e.target.checked; setIsSelectedAll(newSelected); @@ -83,23 +84,54 @@ const CartPage = () => { }); } await loadCart(auth.id); + setIsLoad(false) + } + + const handleDelete = () => { + console.log("delete data"); } return ( <> <div className={style['title']}>Keranjang Belanja</div> <div className='h-2' /> - <div className='flex items-center object-center mt-2'> - <Checkbox - borderColor='gray.600' - colorScheme='red' - size='lg' - isChecked={hasSelectedAll} - onChange={handleChange} - /> - <p className='p-2 text-caption-2'> - {hasSelectedAll ? "Unchek all" : "Select all"} - </p> + <div className='flex items-center object-center justify-between mt-2 mb-2 w-3/4'> + <div className='flex items-center object-center'> + {isLoad && ( + <Spinner className='my-auto' size='sm' /> + )} + {!isLoad && ( + <Checkbox + borderColor='gray.600' + colorScheme='red' + size='lg' + isChecked={hasSelectedAll} + onChange={handleChange} + /> + )} + <p className='p-2 text-caption-2'> + {hasSelectedAll ? "Unchek all" : "Select all"} + </p> + </div> + <div className='delate all flex items-center object-center'> + <Tooltip + label={clsxm({ + 'Tidak ada item yang dipilih': !hasSelected, + 'Terdapat item yang tidak ada harga': hasSelectNoPrice, + })} + > + <Button + bg='#fadede' + variant='outline' + colorScheme='red' + w='full' + isDisabled={!hasSelected || hasSelectNoPrice} + onClick={handleDelete} + > + Hapus Barang + </Button> + </Tooltip> + </div> </div> <div className={style['content']}> |
