From b886fcf2dbc9114bc2e2347e3d4bf5299ed43d3b Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 14 Jul 2023 09:26:08 +0700 Subject: toggle on off --- src/lib/checkout/components/Checkout.jsx | 62 ++++++++++++++-------- .../product/components/Product/ProductDesktop.jsx | 2 +- 2 files changed, 42 insertions(+), 22 deletions(-) (limited to 'src/lib') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 27cdda76..78d61770 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -105,7 +105,7 @@ const Checkout = () => { let addNewLine = dataVoucher[0] let checkList = listVouchers.findIndex((voucher) => voucher.code == addNewLine.code) - if (checkList > 0) return + if (checkList >= 0) return if (totalAmount - totalDiscountAmount < addNewLine.minPurchaseAmount) { SetSelisihHargaCode( currencyFormat(addNewLine.minPurchaseAmount - (totalAmount - totalDiscountAmount)) @@ -140,8 +140,11 @@ const Checkout = () => { let countDiscount = 0 if (dataActiveVoucher.discountType === 'percentage') { - countDiscount = (totalAmount - totalDiscountAmount) * (dataActiveVoucher.discountAmount/100) - if (dataActiveVoucher.maxDiscountAmount > 0 && countDiscount > dataActiveVoucher.maxDiscountAmount) { + countDiscount = (totalAmount - totalDiscountAmount) * (dataActiveVoucher.discountAmount / 100) + if ( + dataActiveVoucher.maxDiscountAmount > 0 && + countDiscount > dataActiveVoucher.maxDiscountAmount + ) { countDiscount = dataActiveVoucher.maxDiscountAmount } } else { @@ -327,10 +330,17 @@ const Checkout = () => { VoucherCode(codeVoucher) } - const handleUseVoucher = async (code) => { - if(code === activeVoucher){ - SetActiveVoucher(null) - }else{ + const handleUseVoucher = async (code, isCheck) => { + if (isCheck) { + if (code === activeVoucher) { + SetActiveVoucher(null) + } else { + SetActiveVoucher(code) + SetFindVoucher(null) + document.getElementById('uniqCode').value = '' + SetButtonTerapkan(false) + } + } else { SetActiveVoucher(code) SetFindVoucher(null) document.getElementById('uniqCode').value = '' @@ -343,6 +353,13 @@ const Checkout = () => { SetButtonTerapkan(false) } + const [isChecked, setIsChecked] = useState(false) + + const ToggleSwitch = (code) => { + setIsChecked(!isChecked) + handleUseVoucher(code, !isChecked) + } + const taxTotal = (totalAmount - totalDiscountAmount - discountVoucher) * 0.11 return ( @@ -409,21 +426,21 @@ const Checkout = () => { ) : ( -

Promo yang tersedia

+

Promo Khusus Untuk {auth.name}

)} {listVouchers?.map((item) => (
{totalAmount - totalDiscountAmount < item.minPurchaseAmount && ( -
+
)}
-
+
{item.name}
-
+

{item.name}

@@ -431,24 +448,27 @@ const Checkout = () => {
- +

-

+

Kode Voucher :{' '} {item.code}

-

+

{activeVoucher === item.code && ( - + Voucher digunakan{' '} )} diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index cafab721..037b8c66 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -256,7 +256,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {