From 578456cacf1ec5106854277222a6f7a9f4790bd5 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 12 Jul 2023 10:48:19 +0700 Subject: checout mobile --- src/lib/checkout/components/Checkout.jsx | 113 ++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 31 deletions(-) (limited to 'src/lib') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index f19b6054..1763ae5b 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -85,10 +85,11 @@ const Checkout = () => { const [bottomPopup, SetBottomPopup] = useState(null) const [listVouchers, SetListVoucher] = useState(null) const [activeVoucher, SetActiveVoucher] = useState(null) - const [discountVoucher, SetDiscountVoucher] = useState(null) + const [discountVoucher, SetDiscountVoucher] = useState(0) const [codeVoucher, SetCodeVoucher] = useState(null) const [findCodeVoucher, SetFindVoucher] = useState(null) const [selisihHargaCode, SetSelisihHargaCode] = useState(null) + const [buttonTerapkan, SetButtonTerapkan] = useState(false) const voucher = async () => { let dataVoucher = await getVoucher() @@ -102,6 +103,8 @@ const Checkout = () => { } let addNewLine = dataVoucher[0] + let checkList = listVouchers.findIndex((voucher) => voucher.code == addNewLine.code) + if(checkList > 0) return if (totalAmount - totalDiscountAmount < addNewLine.minPurchaseAmount) { SetSelisihHargaCode( currencyFormat(addNewLine.minPurchaseAmount - (totalAmount - totalDiscountAmount)) @@ -110,6 +113,7 @@ const Checkout = () => { return } else { SetFindVoucher(3) + SetButtonTerapkan(true) } SetListVoucher((prevList) => [addNewLine, ...prevList]) SetActiveVoucher(addNewLine.code) @@ -132,7 +136,7 @@ const Checkout = () => { if (!listVouchers) return if (!activeVoucher) return - let dataVoucherIndex = listVouchers.findIndex((vocuher) => vocuher.code == activeVoucher) + let dataVoucherIndex = listVouchers.findIndex((voucher) => voucher.code == activeVoucher) let dataActiveVocuher = listVouchers[dataVoucherIndex] let countDiscount = 0 @@ -277,6 +281,7 @@ const Checkout = () => { delivery_amount: biayaKirim, carrier_id: selectedCarrierId, delivery_service_type: selectedExpedisiService, + voucher: activeVoucher, type: 'sale_order' } if (poNumber.current.value) data.po_number = poNumber.current.value @@ -319,16 +324,21 @@ const Checkout = () => { const handleUseVoucher = async (code) => { SetActiveVoucher(code) SetFindVoucher(null) - // document.getElementById('uniqCode').val('') + document.getElementById('uniqCode').value = '' + SetButtonTerapkan(false) } - - console.log('ini find voucher', findCodeVoucher) - const taxTotal = (totalAmount - totalDiscountAmount) * 0.11 + + const onChangeCodeVoucher = async (e) => { + SetCodeVoucher(e.target.value) + SetButtonTerapkan(false) + } + + const taxTotal = (totalAmount - totalDiscountAmount - discountVoucher) * 0.11 return ( <> SetBottomPopup(false)} title='Gunakan Promo' @@ -343,7 +353,7 @@ const Checkout = () => { className='form-input w-full rounded-md' placeholder='Kode Voucher' autoCapitalize='true' - onChange={(e) => SetCodeVoucher(e.target.value)} + onChange={(e) => onChangeCodeVoucher(e)} />
@@ -351,6 +361,7 @@ const Checkout = () => { className='btn-solid-red flex-1 md:flex-none rounded-md' type='button' onClick={() => handlingActivateCode()} + disabled={buttonTerapkan} > Terapkan @@ -380,7 +391,16 @@ const Checkout = () => {
-

Promo yang tersedia

+ {!listVouchers ? ( +
+
+

Tidak ada voucher tersedia

+

Maaf, saat ini tidak ada voucher yang tersedia.

+
+
+ ) : ( +

Promo yang tersedia

+ )} {listVouchers?.map((item) => (
{totalAmount - totalDiscountAmount < item.minPurchaseAmount && ( @@ -389,7 +409,7 @@ const Checkout = () => {
-
+
{item.name}
@@ -528,9 +548,15 @@ const Checkout = () => {
{currencyFormat(totalAmount)}
-
Total Diskon
+
Diskon Produk
- {currencyFormat(totalDiscountAmount)}
+ {activeVoucher && ( +
+
Diskon Voucher
+
- {currencyFormat(discountVoucher)}
+
+ )}
Subtotal
{currencyFormat(totalAmount - totalDiscountAmount)}
@@ -552,7 +578,8 @@ const Checkout = () => {
{currencyFormat( totalAmount - - totalDiscountAmount + + totalDiscountAmount - + discountVoucher + taxTotal + Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 )} @@ -565,22 +592,33 @@ const Checkout = () => {
{/*

*) Belum termasuk biaya pengiriman

*/} @@ -778,9 +816,15 @@ const Checkout = () => {
Total Diskon
- {currencyFormat(totalDiscountAmount)}
+ {activeVoucher && ( +
+
Diskon Voucher
+
- {currencyFormat(discountVoucher)}
+
+ )}
Subtotal
-
{currencyFormat(totalAmount - totalDiscountAmount)}
+
{currencyFormat(totalAmount - totalDiscountAmount - discountVoucher)}
PPN 11%
@@ -802,7 +846,8 @@ const Checkout = () => {
{currencyFormat( totalAmount - - totalDiscountAmount + + totalDiscountAmount - + discountVoucher + taxTotal + Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 )} @@ -815,9 +860,15 @@ const Checkout = () => {
-- cgit v1.2.3