diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2024-01-05 09:30:08 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2024-01-05 09:30:08 +0700 |
| commit | ee0b5893ac039ab05fe8247647364a923d707da3 (patch) | |
| tree | 3f89409e3a1701cd129b1b031084bc236edbf0f4 /src-migrate/pages | |
| parent | 6b8f9cda775b6c4701bcbcf30b0fbe1434107d06 (diff) | |
Fixing UI cart page
Diffstat (limited to 'src-migrate/pages')
| -rw-r--r-- | src-migrate/pages/shop/cart.module.css | 31 | ||||
| -rw-r--r-- | src-migrate/pages/shop/cart.tsx | 91 |
2 files changed, 122 insertions, 0 deletions
diff --git a/src-migrate/pages/shop/cart.module.css b/src-migrate/pages/shop/cart.module.css new file mode 100644 index 00000000..d523a55a --- /dev/null +++ b/src-migrate/pages/shop/cart.module.css @@ -0,0 +1,31 @@ +.title { + @apply text-h-lg font-semibold; +} + +.content { + @apply flex flex-wrap; +} + +.item-wrapper { + @apply w-full md:w-3/4; +} + +.item-skeleton { + @apply grid grid-cols-1 gap-y-4; +} + +.items { + @apply flex flex-col gap-y-6 border-t border-gray-300 pt-6; +} + +.summary-wrapper { + @apply w-full md:w-1/4 md:pl-6 mt-6 md:mt-0; +} + +.summary { + @apply border border-gray-300 p-4 rounded-md sticky top-[180px]; +} + +.summary-buttons { + @apply grid grid-cols-2 gap-x-3 mt-6; +} diff --git a/src-migrate/pages/shop/cart.tsx b/src-migrate/pages/shop/cart.tsx new file mode 100644 index 00000000..5016c9b5 --- /dev/null +++ b/src-migrate/pages/shop/cart.tsx @@ -0,0 +1,91 @@ +import style from './cart.module.css' + +import React, { useEffect, useMemo } from 'react' +import Link from 'next/link' +import { Button, Tooltip } from '@chakra-ui/react' + +import { getAuth } from '~/common/libs/auth' +import { useCartStore } from '~/modules/cart/stores/useCartStore' + +import CartItem from '~/modules/cart/components/Item' +import CartSummary from '~/modules/cart/components/Summary' + +const CartPage = () => { + const auth = getAuth() + + const { loadCart, cart, summary } = useCartStore() + + useEffect(() => { + if (typeof auth === 'object' && !cart) loadCart(auth.id) + }, [auth, loadCart, cart]) + + const hasSelectedPromo = useMemo(() => { + if (!cart) return false + for (const item of cart.products) { + if (item.cart_type === 'promotion' && item.selected) return true + } + return false + }, [cart]) + + const hasSelected = useMemo(() => { + if (!cart) return false + for (const item of cart.products) { + if (item.selected) return true + } + return false + }, [cart]) + + return ( + <> + <div className={style['title']}> + Keranjang Belanja + </div> + + <div className='h-6' /> + + <div className={style['content']}> + <div className={style['item-wrapper']}> + <div className={style['item-skeleton']}> + {!cart && <CartItem.Skeleton count={5} height='120px' />} + </div> + + <div className={style['items']}> + {cart?.products.map((item) => <CartItem key={item.id} item={item} />)} + </div> + </div> + + <div className={style['summary-wrapper']}> + <div className={style['summary']}> + <CartSummary {...summary} isLoaded={!!cart} /> + + <div className={style['summary-buttons']}> + <Tooltip label={hasSelectedPromo && 'Barang promo tidak dapat dibuat quotation'}> + <Button + colorScheme='yellow' + w='full' + isDisabled={hasSelectedPromo || !hasSelected} + > + Quotation + </Button> + </Tooltip> + + <Tooltip label={!hasSelected && 'Tidak ada item yang dipilih'}> + <Button + colorScheme='red' + w='full' + isDisabled={!hasSelected} + as={Link} + href='/shop/checkout' + > + Checkout + </Button> + </Tooltip> + </div> + </div> + </div> + </div> + </> + ) +} + +export default CartPage
\ No newline at end of file |
