From ecaa66653e57e369b97674ff239177244f8f83ff Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Mon, 22 Jul 2024 11:13:59 +0700 Subject: voucher in product card --- src/lib/product/components/ProductCard.jsx | 152 +++++++++++++++++------------ 1 file changed, 92 insertions(+), 60 deletions(-) (limited to 'src/lib') diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index 98732407..818dbbcf 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -14,7 +14,15 @@ import useUtmSource from '~/hooks/useUtmSource'; const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { const router = useRouter(); const utmSource = useUtmSource(); + const [discount, setDiscount] = useState(0); + let voucherPastiHemat = 0; + + if (product?.voucherPastiHemat.length > 0) { + const stringVoucher = product?.voucherPastiHemat[0]; + const validJsonString = stringVoucher.replace(/'/g, '"'); + voucherPastiHemat = JSON.parse(validJsonString); + } const callForPriceWhatsapp = whatsappUrl('product', { name: product.name, @@ -38,42 +46,59 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { ), }; + const hitungDiscountVoucher = () => { + let countDiscount = 0; + if (voucherPastiHemat.discount_type === 'percentage') { + countDiscount = product?.lowestPrice.priceDiscount * (voucherPastiHemat.discount_amount / 100); + if (voucherPastiHemat.max_discount > 0 && countDiscount > voucherPastiHemat.max_discount) { + countDiscount = voucherPastiHemat.max_discount; + } + } else { + countDiscount = voucherPastiHemat.discount_amount; + } + + setDiscount(countDiscount); + }; + + useEffect(() => { + hitungDiscountVoucher(); + }, []); + if (variant == 'vertical') { return ( -
+
-
- {product?.name} -
-
- {product?.isSni && ( - - )} -
-
- {product?.isTkdn && ( - - )} +
+ {product?.name} +
+
+ {product?.isSni && ( + + )} +
+
+ {product?.isTkdn && ( + + )} +
-
- {router.pathname != '/' && product?.flashSale?.id > 0 && (
@@ -178,6 +203,13 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { )}
)} + {discount > 0 && ( +
+
+ Hemat : {currencyFormat(discount)} +
+
+ )}
{product?.stockTotal > 0 && ( @@ -200,37 +232,37 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => {
-
- {product?.name} -
-
- {product?.isSni && ( - - )} -
-
- {product?.isTkdn && ( - - )} +
+ {product?.name} +
+
+ {product?.isSni && ( + + )} +
+
+ {product?.isTkdn && ( + + )} +
-
{product.variantTotal > 1 && (
{product.variantTotal} Varian -- cgit v1.2.3 From 6be3ec5948932671013aba249fbc5c44ecf9e95b Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Thu, 25 Jul 2024 13:51:46 +0700 Subject: feedback review --- src/lib/product/components/ProductCard.jsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/lib') diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index 818dbbcf..283a10c6 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -49,8 +49,13 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { const hitungDiscountVoucher = () => { let countDiscount = 0; if (voucherPastiHemat.discount_type === 'percentage') { - countDiscount = product?.lowestPrice.priceDiscount * (voucherPastiHemat.discount_amount / 100); - if (voucherPastiHemat.max_discount > 0 && countDiscount > voucherPastiHemat.max_discount) { + countDiscount = + product?.lowestPrice.priceDiscount * + (voucherPastiHemat.discount_amount / 100); + if ( + voucherPastiHemat.max_discount > 0 && + countDiscount > voucherPastiHemat.max_discount + ) { countDiscount = voucherPastiHemat.max_discount; } } else { @@ -203,10 +208,10 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { )}
)} - {discount > 0 && ( + {discount > 0 && product?.flashSale?.id < 1 && (
- Hemat : {currencyFormat(discount)} + Voucher : {currencyFormat(discount)}
)} @@ -351,6 +356,14 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => {
)} + {discount > 0 && product?.flashSale?.id < 1 && ( +
+
+ Voucher : {currencyFormat(discount)} +
+
+ )} +
{product?.stockTotal > 0 && (
Ready Stock
-- cgit v1.2.3