diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-07-11 17:05:43 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-07-11 17:05:43 +0700 |
| commit | b3855694c2723168d1c7ad949d892649fff220b8 (patch) | |
| tree | 5e3dedc710528470f761cadea66e4264a4113b81 /src/lib | |
| parent | dc334fa49ad13959b6a0d572fd56a4cde38176fa (diff) | |
find voucher
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 40 |
1 files changed, 35 insertions, 5 deletions
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 = () => { </button> </div> </div> - {codeVoucher && activeVoucher == codeVoucher ? ( + {findCodeVoucher === 3 && activeVoucher === codeVoucher && ( <div className='mt-2'> <span className='text-caption-1 mt-2 text-green-600'> Voucher berhasil ditambahkan{' '} </span> </div> - ) : ( + )} + {findCodeVoucher === 1 && ( <div className='mt-2'> - <span className='text-caption-1 mt-2 text-green-600'> + <span className='text-caption-1 mt-2 text-red-600'> Kode voucher salah / sudah tidak berlaku lagi. Coba voucher lainnya, ya. </span> </div> )} + {findCodeVoucher === 2 && ( + <div className='mt-2'> + <span className='text-caption-1 mt-2 text-red-600'> + {'Tambah ' + selisihHargaCode + ' untuk pakai promo ini'} + </span> + </div> + )} <hr className='mt-14 my-4 border-gray_r-10' /> <div className=''> @@ -374,7 +404,7 @@ const Checkout = () => { <button className='btn-solid-red w-[102px] md:flex-none rounded-md' type='button' - onClick={() => SetActiveVoucher(item.code)} + onClick={() => handleUseVoucher(item.code)} disabled={activeVoucher === item.code} > {activeVoucher === item.code ? 'Terpakai' : 'Pakai'} |
