diff options
Diffstat (limited to 'src-migrate/pages')
| -rw-r--r-- | src-migrate/pages/shop/cart/cart.module.css | 4 | ||||
| -rw-r--r-- | src-migrate/pages/shop/cart/index.tsx | 94 | ||||
| -rw-r--r-- | src-migrate/pages/shop/promo/index.tsx | 38 |
3 files changed, 108 insertions, 28 deletions
diff --git a/src-migrate/pages/shop/cart/cart.module.css b/src-migrate/pages/shop/cart/cart.module.css index 98a6ac86..806104be 100644 --- a/src-migrate/pages/shop/cart/cart.module.css +++ b/src-migrate/pages/shop/cart/cart.module.css @@ -29,3 +29,7 @@ .summary-buttons { @apply grid grid-cols-2 gap-x-3 mt-6; } + +.summary-buttons-step-approval { + @apply grid grid-cols-1 gap-y-3 mt-6; +} diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 4b4de92b..2ecf1c03 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -1,9 +1,10 @@ import style from './cart.module.css'; -import React, { useEffect, useMemo } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import Link from 'next/link'; -import { Button, Tooltip } from '@chakra-ui/react'; - +import { Button, Checkbox, Toast, Tooltip } from '@chakra-ui/react'; +import { toast } from 'react-hot-toast'; +import { useRouter } from 'next/router'; import { getAuth } from '~/libs/auth'; import { useCartStore } from '~/modules/cart/stores/useCartStore'; @@ -15,16 +16,25 @@ import CartSummaryMobile from '~/modules/cart/components/CartSummaryMobile'; import Image from '~/components/ui/image'; const CartPage = () => { + const router = useRouter(); const auth = getAuth(); + const [isStepApproval, setIsStepApproval] = React.useState(false); + const [isSelectedAll, setIsSelectedAll] = useState<boolean>(false); + const [isButtonChek, setIsButtonChek] = useState<boolean>(false); + const [buttonSelectNow, setButtonSelectNow] = useState<boolean>(true); const { loadCart, cart, summary } = useCartStore(); const useDivvice = useDevice(); useEffect(() => { - if (typeof auth === 'object' && !cart) loadCart(auth.id); - }, [auth, loadCart, cart]); - + if (typeof auth === 'object' && !cart) { + loadCart(auth.id); + setIsStepApproval(auth?.feature?.soApproval); + } + }, [auth, loadCart, cart, isButtonChek, ]); + + const hasSelectedPromo = useMemo(() => { if (!cart) return false; for (const item of cart.products) { @@ -48,12 +58,40 @@ const CartPage = () => { } return false; }, [cart]); + + const handleCheckout = (()=>{ + router.push('/shop/checkout'); + }) + + const handleQuotation = (()=>{ + if(hasSelectedPromo || !hasSelected){ + toast.error('Maaf, Barang promo tidak dapat dibuat quotation'); + }else{ + router.push('/shop/quotation'); + } + }) + + const handleChange = (()=>{ + setButtonSelectNow(!buttonSelectNow) + setIsSelectedAll(!isSelectedAll) + setIsButtonChek(!isButtonChek) + }) return ( <> <div className={style['title']}>Keranjang Belanja</div> - - <div className='h-6' /> + <div className='h-2' /> + <div className='flex items-center object-center mt-2'> + <Checkbox + borderColor='gray.600' + colorScheme='red' + size='lg' + isChecked={isButtonChek} + onChange={handleChange} + /> <p className='p-2 text-caption-2'> + {buttonSelectNow? "Select all" : "Unchek all" } + </p> + </div> <div className={style['content']}> <div className={style['item-wrapper']}> @@ -63,8 +101,9 @@ const CartPage = () => { <div className={style['items']}> {cart?.products.map((item) => ( - <CartItem key={item.id} item={item} /> + <CartItem key={item.id} item={item} pilihSemuaCart={isSelectedAll} /> ))} + {cart?.products?.length === 0 && ( <div className='flex flex-col items-center'> @@ -106,7 +145,7 @@ const CartPage = () => { <CartSummary {...summary} isLoaded={!!cart} /> )} - <div className={style['summary-buttons']}> + <div className={isStepApproval ? style['summary-buttons-step-approval'] : style['summary-buttons'] }> <Tooltip label={ hasSelectedPromo && @@ -117,29 +156,28 @@ const CartPage = () => { colorScheme='yellow' w='full' isDisabled={hasSelectedPromo || !hasSelected} - as={Link} - href='/shop/quotation' + onClick={handleQuotation} > Quotation </Button> </Tooltip> - - <Tooltip - label={clsxm({ - 'Tidak ada item yang dipilih': !hasSelected, - 'Terdapat item yang tidak ada harga': hasSelectNoPrice, - })} - > - <Button - colorScheme='red' - w='full' - isDisabled={!hasSelected || hasSelectNoPrice} - as={Link} - href='/shop/checkout' + {!isStepApproval && ( + <Tooltip + label={clsxm({ + 'Tidak ada item yang dipilih': !hasSelected, + 'Terdapat item yang tidak ada harga': hasSelectNoPrice, + })} > - Checkout - </Button> - </Tooltip> + <Button + colorScheme='red' + w='full' + isDisabled={!hasSelected || hasSelectNoPrice} + onClick={handleCheckout} + > + Checkout + </Button> + </Tooltip> + )} </div> </div> </div> diff --git a/src-migrate/pages/shop/promo/index.tsx b/src-migrate/pages/shop/promo/index.tsx new file mode 100644 index 00000000..febe31a4 --- /dev/null +++ b/src-migrate/pages/shop/promo/index.tsx @@ -0,0 +1,38 @@ +import dynamic from 'next/dynamic' +import React, { useState } from 'react' +import { LazyLoadComponent } from 'react-lazy-load-image-component' +import Hero from '~/modules/promo/components/Hero' +import PromotionProgram from '~/modules/promo/components/PromotinProgram' +import Voucher from '~/modules/promo/components/Voucher' +import FlashSale from '../../../modules/promo/components/FlashSale' +const PromoList = dynamic(() => import('../../../modules/promo/components/PromoList')); + + + +const PromoPage = () => { + const [selectedPromo, setSelectedPromo] = useState('Bundling'); + return ( + <> + <LazyLoadComponent> + <Hero /> + </LazyLoadComponent> + <LazyLoadComponent> + <PromotionProgram + selectedPromo={selectedPromo} + onSelectPromo={setSelectedPromo} + /> + <PromoList selectedPromo={selectedPromo} /> + </LazyLoadComponent> + + <LazyLoadComponent> + <FlashSale /> + </LazyLoadComponent> + <h1 className='h-1'></h1> + <LazyLoadComponent> + <Voucher /> + </LazyLoadComponent> + </> + ) +} + +export default PromoPage
\ No newline at end of file |
