From 8b8560742a16b46a114a86966e13ba59c1c248f6 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 21 Jul 2023 16:24:06 +0700 Subject: voucher brand --- src/lib/checkout/components/Checkout.jsx | 393 +++++++++++++++++++++---------- 1 file changed, 275 insertions(+), 118 deletions(-) (limited to 'src/lib') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 3686ced9..23a471aa 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -26,7 +26,6 @@ import BottomPopup from '@/core/components/elements/Popup/BottomPopup' import { useQuery } from 'react-query' import { gtagPurchase } from '@/core/utils/googleTag' import { findVoucher, getVoucher } from '../api/getVoucher' -import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner' const SELF_PICKUP_ID = 32 @@ -100,12 +99,17 @@ const Checkout = () => { const [selisihHargaCode, SetSelisihHargaCode] = useState(null) const [buttonTerapkan, SetButtonTerapkan] = useState(false) const [checkoutValidation, setCheckoutValidation] = useState(false) + const [loadingVoucher, setLoadingVoucher] = useState(true) const expedisiValidation = useRef(null) const voucher = async () => { - let dataVoucher = await getVoucher(auth?.id) - SetListVoucher(dataVoucher) + try { + let dataVoucher = await getVoucher(auth?.id) + SetListVoucher(dataVoucher) + } finally { + setLoadingVoucher(false) + } } const VoucherCode = async (code) => { let dataVoucher = await findVoucher(code, auth.id) @@ -417,7 +421,7 @@ const Checkout = () => {
- {!listVouchers ? ( + {!loadingVoucher && !listVouchers ? (

Tidak ada voucher tersedia

@@ -425,88 +429,174 @@ const Checkout = () => {
) : ( -

Promo Khusus Untuk {auth.name}

+

Promo Khusus Untuk {auth?.name}

)} - {listVouchers?.map((item) => ( -
- {item.canApply === false && ( -
- )} - -
-
-
- {item.name} + {loadingVoucher && ( + <> +
+
+
+
-
-
-
-

{item.name}

-
- {item.description} -
-
-
- -
-
-
-
-

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

-

- {activeVoucher === item.code && ( - Voucher digunakan - )} -

-
+
+
+
+
-
-

- {item.canApply === false - ? 'Tambah ' + - currencyFormat(item.differenceToApply) + - ' untuk pakai promo ini' - : 'Potensi potongan sebesar ' + - currencyFormat(hitungDiscountVoucher(item.code))} -

-
-
+
+
+
+
- - Berakhir dalam {item.remainingTime}{' '} - lagi{' '} - +
+
+
+
+
-
- ))} + + )} + {!loadingVoucher && + listVouchers?.map((item) => ( +
+ {item.canApply === false && ( +
+ )} + +
+
+
+ {item.name} +
+
+
+
+

{item.name}

+
+ {item.description} +
+
+
+ +
+
+
+
+

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

+

+ {activeVoucher === item.code && ( + Voucher digunakan + )} +

+
+
+
+
+

+ {!item.canApply && + item.applyStatus === 'MPA' && + item.manufactureNames != '' && ( +

+ Tambah produk{' '} + {item.manufactureNames} senilai{' '} + + {currencyFormat(item.differenceToApply)} + {' '} + untuk pakai promo ini +

+ )} + {!item.canApply && + item.applyStatus === 'MPA' && + item.manufactureNames === '' && ( +

+ Tambah{' '} + + {currencyFormat(item.differenceToApply)} + {' '} + untuk pakai promo ini{' '} +

+ )} + {!item.canApply && item.applyStatus === 'UM' && ( +

+ Tambah produk{' '} + {item.manufactureNames} senilai{' '} + + {currencyFormat(item.minPurchaseAmount)} + {' '} + untuk pakai promo ini +

+ )} + {item.canApply && ( +

+ Potensi potongan sebesar{' '} + {item.discountVoucher} +

+ )} + {/* {item.canApply === false + ? 'Tambah ' + + currencyFormat(item.differenceToApply) + + ' untuk pakai promo ini' + : 'Potensi potongan sebesar ' + + currencyFormat(hitungDiscountVoucher(item.code))} */} +

+
+
+ + + Berakhir dalam {item.remainingTime}{' '} + lagi{' '} + +
+
+
+
+ ))}
@@ -569,52 +659,108 @@ const Checkout = () => {
{products?.length} Barang

-
-
-
Total Belanja
-
{currencyFormat(cartCheckout?.totalPurchase)}
-
-
-
Diskon Produk
-
- {currencyFormat(cartCheckout?.totalDiscount)}
+ {!cartCheckout ? ( +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- {activeVoucher && ( + ) : ( +
-
Diskon Voucher
-
- {currencyFormat(discountVoucher)}
+
Total Belanja
+
{currencyFormat(cartCheckout?.totalPurchase)}
- )} -
-
Subtotal
-
{currencyFormat(cartCheckout?.subtotal)}
-
-
-
PPN 11%
-
{currencyFormat(cartCheckout?.tax)}
-
-
-
- Biaya Kirim

{etdFix}

+
+
Diskon Produk
+
+ - {currencyFormat(cartCheckout?.totalDiscount)} +
+
+ {activeVoucher && ( +
+
Diskon Voucher
+
- {currencyFormat(discountVoucher)}
+
+ )} +
+
Subtotal
+
{currencyFormat(cartCheckout?.subtotal)}
+
+
+
PPN 11%
+
{currencyFormat(cartCheckout?.tax)}
+
+
+
+ Biaya Kirim

{etdFix}

+
+
{currencyFormat(Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000)}
-
{currencyFormat(Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000)}
-
+ )} +
-
-
Grand Total
-
- {currencyFormat( - cartCheckout?.grandTotal + Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 - )} + {!cartCheckout ? ( +
+
+ {' '} +
+
+
+
+
-
+ ) : ( +
+
Grand Total
+
+ {currencyFormat( + cartCheckout?.grandTotal + Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 + )} +
+
+ )}
- Loading...
) : (
@@ -979,15 +1124,27 @@ const Checkout = () => { )}
- -
-
Grand Total
-
- {currencyFormat( - cartCheckout?.grandTotal + Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 - )} + {!cartCheckout ? ( +
+
+ {' '} +
+
+
+
+
-
+ ) : ( +
+
Grand Total
+
+ {currencyFormat( + cartCheckout?.grandTotal + + Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 + )} +
+
+ )}
@@ -1159,7 +1316,7 @@ const SectionExpedisi = ({ ))} {checkoutValidation && ( - * Silahkan pilih expedisi + *silahkan pilih expedisi )}