From ff965aa38741cc88dae7436384fed571003d70a3 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 28 Oct 2025 10:12:44 +0700 Subject: ntar --- .../components/Product/ProductDesktopVariant.jsx | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) 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 (
@@ -593,6 +627,13 @@ const ProductDesktopVariant = ({ /> Penawaran Harga Instan +
+
+ + Pakai Voucher {currencyFormat(discount)} + +
+