From b3855694c2723168d1c7ad949d892649fff220b8 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 11 Jul 2023 17:05:43 +0700 Subject: find voucher --- src/lib/checkout/components/Checkout.jsx | 40 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'src/lib') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index dcc00eb8..f19b6054 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -87,6 +87,8 @@ const Checkout = () => { const [activeVoucher, SetActiveVoucher] = useState(null) const [discountVoucher, SetDiscountVoucher] = useState(null) const [codeVoucher, SetCodeVoucher] = useState(null) + const [findCodeVoucher, SetFindVoucher] = useState(null) + const [selisihHargaCode, SetSelisihHargaCode] = useState(null) const voucher = async () => { let dataVoucher = await getVoucher() @@ -94,9 +96,21 @@ const Checkout = () => { } const VoucherCode = async (code) => { let dataVoucher = await findVoucher(code) - if (!dataVoucher) return + if (dataVoucher.length <= 0) { + SetFindVoucher(1) + return + } let addNewLine = dataVoucher[0] + if (totalAmount - totalDiscountAmount < addNewLine.minPurchaseAmount) { + SetSelisihHargaCode( + currencyFormat(addNewLine.minPurchaseAmount - (totalAmount - totalDiscountAmount)) + ) + SetFindVoucher(2) + return + } else { + SetFindVoucher(3) + } SetListVoucher((prevList) => [addNewLine, ...prevList]) SetActiveVoucher(addNewLine.code) } @@ -301,6 +315,14 @@ const Checkout = () => { const handlingActivateCode = async () => { VoucherCode(codeVoucher) } + + const handleUseVoucher = async (code) => { + SetActiveVoucher(code) + SetFindVoucher(null) + // document.getElementById('uniqCode').val('') + } + + console.log('ini find voucher', findCodeVoucher) const taxTotal = (totalAmount - totalDiscountAmount) * 0.11 return ( @@ -334,19 +356,27 @@ const Checkout = () => { - {codeVoucher && activeVoucher == codeVoucher ? ( + {findCodeVoucher === 3 && activeVoucher === codeVoucher && (
Voucher berhasil ditambahkan{' '}
- ) : ( + )} + {findCodeVoucher === 1 && (
- + Kode voucher salah / sudah tidak berlaku lagi. Coba voucher lainnya, ya.
)} + {findCodeVoucher === 2 && ( +
+ + {'Tambah ' + selisihHargaCode + ' untuk pakai promo ini'} + +
+ )}
@@ -374,7 +404,7 @@ const Checkout = () => {