summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-migrate/pages/shop/cart/index.tsx58
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']}>