diff options
| -rw-r--r-- | src/lib/product/components/Product/ProductDesktopVariant.jsx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx index 59fa2032..5e6d7d7f 100644 --- a/src/lib/product/components/Product/ProductDesktopVariant.jsx +++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx @@ -1,3 +1,4 @@ +import { TicketIcon } from '@heroicons/react/24/solid'; import { Box, Button, Skeleton, Tooltip } from '@chakra-ui/react'; import { HeartIcon } from '@heroicons/react/24/outline'; import { Info, MessageCircleIcon, Share2Icon } from 'lucide-react'; @@ -46,6 +47,7 @@ const ProductDesktopVariant = ({ const [isLoadingSLA, setIsLoadingSLA] = useState(true); const [selectedVariant, setSelectedVariant] = useState(product.id); const { setRefreshCart } = useProductCartContext(); + const [discount, setDiscount] = useState(0); const [quantityInput, setQuantityInput] = useState(1); @@ -307,6 +309,38 @@ const ProductDesktopVariant = ({ fetchData(); }, [product]); + let voucherPastiHemat = 0; + voucherPastiHemat = product?.newVoucherPastiHemat[0] + ? product?.newVoucherPastiHemat[0] + : product?.newVoucherPastiHemat; + + const hitungDiscountVoucher = () => { + let countDiscount = 0; + if (voucherPastiHemat.discountType === 'percentage') { + countDiscount = + product?.lowestPrice.priceDiscount * + (voucherPastiHemat.discountAmount / 100); + // console.log('count disc', countDiscount); + if ( + voucherPastiHemat.maxDiscount > 0 && + countDiscount > voucherPastiHemat.maxDiscount + ) { + countDiscount = voucherPastiHemat.maxDiscount; + } + } else { + countDiscount = voucherPastiHemat.discountAmount; + } + + setDiscount(countDiscount); + console.log('count disc', countDiscount); + }; + + useEffect(() => { + hitungDiscountVoucher(); + }, []); + + console.log('product', product); + return ( <DesktopView> <div className='container mx-auto pt-10'> @@ -593,6 +627,13 @@ const ProductDesktopVariant = ({ /> Penawaran Harga Instan </Button> + <div className='mt-3'> + <div className='inline-flex items-center'> + <span className='text-sm font-semibold'> + Pakai Voucher {currencyFormat(discount)} + </span> + </div> + </div> <div className='flex py-5'> <div className='flex gap-x-5 items-center justify-center'> <Button |
