From 50425ea134852897bf125aae0f68a1642eb3b3b8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 3 Apr 2024 10:31:14 +0700 Subject: Add voucher shipping feature --- src/lib/checkout/components/Checkout.jsx | 224 ++++++++++++++++++++++++++----- 1 file changed, 191 insertions(+), 33 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 52edbd05..042fc258 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -43,9 +43,16 @@ const Checkout = () => { const auth = useAuth(); const [activeVoucher, SetActiveVoucher] = useState(null); - - const { data: cartCheckout } = useQuery('cartCheckout-' + activeVoucher, () => - getProductsCheckout(activeVoucher, query) + const [activeVoucherShipping, setActiveVoucherShipping] = useState(null); + + const { data: cartCheckout } = useQuery( + ['cartCheckout', activeVoucher, activeVoucherShipping], + () => + getProductsCheckout({ + source: query, + voucher: activeVoucher, + voucher_shipping: activeVoucherShipping, + }) ); const [selectedAddress, setSelectedAddress] = useState({ @@ -103,6 +110,7 @@ const Checkout = () => { const [bottomPopupTnC, SetBottomPopupTnC] = useState(null); const [itemTnC, setItemTnC] = useState(null); const [listVouchers, SetListVoucher] = useState(null); + const [listVoucherShippings, SetListVoucherShipping] = useState(null); const [discountVoucher, SetDiscountVoucher] = useState(0); const [codeVoucher, SetCodeVoucher] = useState(null); const [findCodeVoucher, SetFindVoucher] = useState(null); @@ -117,13 +125,23 @@ const Checkout = () => { const voucher = async () => { if (!listVouchers) { try { - let dataVoucher = await getVoucher(auth?.id, query); + setLoadingVoucher(true); + let dataVoucher = await getVoucher(auth?.id, { + source: query, + }); SetListVoucher(dataVoucher); + + let dataVoucherShipping = await getVoucher(auth?.id, { + source: query, + type: 'shipping', + }); + SetListVoucherShipping(dataVoucherShipping); } finally { setLoadingVoucher(false); } } }; + const VoucherCode = async (code) => { let dataVoucher = await findVoucher(code, auth.id, query); if (dataVoucher.length <= 0) { @@ -333,6 +351,7 @@ const Checkout = () => { estimated_arrival_days: splitDuration(etd), delivery_service_type: selectedExpedisiService, voucher: activeVoucher, + voucher_shipping: activeVoucherShipping, type: 'sale_order', }; @@ -419,6 +438,11 @@ const Checkout = () => { return false; }, [products]); + const voucherShippingAmt = cartCheckout?.discountVoucherShipping || 0; + const discShippingAmt = Math.min(biayaKirim, voucherShippingAmt); + + const finalShippingAmt = biayaKirim - discShippingAmt; + return ( <> { )} -
-
+
+ + {listVoucherShippings && listVoucherShippings?.length > 0 && ( +
+

Promo Gratis Ongkir

+ {listVoucherShippings?.map((item) => ( +
+
+ {item.canApply && ( + + )} + {!item.canApply && ( + + )} + +
+ {item.canApply === false && ( +
+ )} +
+ {item.name} +
+
+
+
+

{item.name}

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

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

+

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

+
+
+ +
+
+ Berakhir dalam{' '} + + {item.remainingTime} + {' '} + lagi,{' '} +
+
handlingTnC(item)} + > + Baca S&K +
+
+
+
+
+
+

+
+
+
+ ))} +
+ )} + +
+ +
{!loadingVoucher && listVouchers?.length === 0 ? (
@@ -714,14 +875,7 @@ const Checkout = () => {
-

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

+

@@ -887,14 +1041,18 @@ const Checkout = () => {
- Biaya Kirim

{etdFix}

-
-
- {currencyFormat( - Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 - )} + Biaya Kirim

{etdFix}

+
{currencyFormat(biayaKirim)}
+ {activeVoucherShipping && voucherShippingAmt && ( +
+
Diskon Kirim
+
+ - {currencyFormat(discShippingAmt)} +
+
+ )} )} @@ -913,10 +1071,7 @@ const Checkout = () => {
Grand Total
- {currencyFormat( - cartCheckout?.grandTotal + - Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 - )} + {currencyFormat(cartCheckout?.grandTotal + finalShippingAmt)}
)} @@ -926,7 +1081,7 @@ const Checkout = () => {
)} @@ -1209,8 +1368,7 @@ const Checkout = () => {
Grand Total
{currencyFormat( - cartCheckout?.grandTotal + - Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 + cartCheckout?.grandTotal + finalShippingAmt )}
-- cgit v1.2.3 From 1bb3f91f27db4db6a16a1ed3fe59016268ba3d44 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 8 May 2024 13:23:10 +0700 Subject: change wa number --- src/lib/checkout/components/Checkout.jsx | 2 +- src/lib/checkout/components/CheckoutOld.jsx | 2 +- src/lib/checkout/components/CheckoutSection.jsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 7a456d70..0090acee 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -1454,7 +1454,7 @@ const SectionExpedisi = ({ dengan menghubungi admin melalui{' '} tautan ini diff --git a/src/lib/checkout/components/CheckoutOld.jsx b/src/lib/checkout/components/CheckoutOld.jsx index d57fbd66..e2c45ce6 100644 --- a/src/lib/checkout/components/CheckoutOld.jsx +++ b/src/lib/checkout/components/CheckoutOld.jsx @@ -696,7 +696,7 @@ const SectionExpedisi = ({ address, listExpedisi, setSelectedExpedisi, checkWeig diatur beratnya. Mohon atur berat barang dengan menghubungi admin melalui{' '} tautan ini diff --git a/src/lib/checkout/components/CheckoutSection.jsx b/src/lib/checkout/components/CheckoutSection.jsx index 7f9ea08a..affe6138 100644 --- a/src/lib/checkout/components/CheckoutSection.jsx +++ b/src/lib/checkout/components/CheckoutSection.jsx @@ -120,7 +120,7 @@ export const SectionExpedisi = ({ dengan menghubungi admin melalui{' '} tautan ini -- cgit v1.2.3 From da80b7e00e2ee6aaa3a81902cd51ff556d4d7ef0 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 5 Jun 2024 15:01:12 +0700 Subject: fixing shipping address and invoice address --- src/lib/checkout/components/Checkout.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 0090acee..5ca3611f 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -333,8 +333,10 @@ const Checkout = () => { quantity: product.quantity, })); let data = { - partner_shipping_id: auth.partnerId, - partner_invoice_id: auth.partnerId, + // partner_shipping_id: auth.partnerId, + // partner_invoice_id: auth.partnerId, + partner_shipping_id: selectedAddress?.shipping?.id || auth.partnerId, + partner_invoice_id: selectedAddress?.invoicing?.id || auth.partnerId, user_id: auth.id, order_line: JSON.stringify(productOrder), delivery_amount: biayaKirim, -- cgit v1.2.3 From b992edcc7f1b7395dea0c8562ddf272df9fc6b7f Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 29 Jun 2024 10:08:16 +0700 Subject: add parameter flag flash sale --- src/lib/checkout/components/Checkout.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 5ca3611f..df1768fb 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -112,6 +112,7 @@ const Checkout = () => { const [loadingVoucher, setLoadingVoucher] = useState(true); const [loadingRajaOngkir, setLoadingRajaOngkir] = useState(false); const [grandTotal, setGrandTotal] = useState(0); + const [hasFlashSale, setHasFlashSale] = useState(false); const expedisiValidation = useRef(null); @@ -224,6 +225,7 @@ const Checkout = () => { setProducts(cartCheckout?.products); setCheckWeight(cartCheckout?.hasProductWithoutWeight); setTotalWeight(cartCheckout?.totalWeight.g); + setHasFlashSale(cartCheckout?.products[0]?.hasFlashsale ? cartCheckout.products[0].hasFlashsale : false); }, [cartCheckout]); useEffect(() => { @@ -343,6 +345,7 @@ const Checkout = () => { carrier_id: selectedCarrierId, estimated_arrival_days: splitDuration(etd), delivery_service_type: selectedExpedisiService, + flash_sale : !hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false voucher: activeVoucher, type: 'sale_order', }; @@ -358,7 +361,7 @@ const Checkout = () => { toast.error('Gagal melakukan transaksi, terjadi kesalahan internal'); return; } - + console.log("isCheckouted",isCheckouted) gtagPurchase(products, biayaKirim, isCheckouted.name); const midtrans = async () => { -- cgit v1.2.3 From 703136862dc3d41d0a276c17fa7f4ecebd471527 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 1 Jul 2024 09:07:59 +0700 Subject: add flash sales to sales order --- src/lib/checkout/components/Checkout.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index df1768fb..4aafdece 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -227,6 +227,7 @@ const Checkout = () => { setTotalWeight(cartCheckout?.totalWeight.g); setHasFlashSale(cartCheckout?.products[0]?.hasFlashsale ? cartCheckout.products[0].hasFlashsale : false); }, [cartCheckout]); + useEffect(() => { setCheckoutValidation(false); @@ -345,7 +346,7 @@ const Checkout = () => { carrier_id: selectedCarrierId, estimated_arrival_days: splitDuration(etd), delivery_service_type: selectedExpedisiService, - flash_sale : !hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false + flash_sale : hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false voucher: activeVoucher, type: 'sale_order', }; @@ -361,7 +362,7 @@ const Checkout = () => { toast.error('Gagal melakukan transaksi, terjadi kesalahan internal'); return; } - console.log("isCheckouted",isCheckouted) + gtagPurchase(products, biayaKirim, isCheckouted.name); const midtrans = async () => { -- cgit v1.2.3 From 44895db5a27a87e6f6f91d4d3fda33ff444f82f0 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 11 Jul 2024 15:21:10 +0700 Subject: marge conflik --- src/lib/checkout/components/Checkout.jsx | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 4355c7bd..3c2b8a09 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -1391,13 +1391,10 @@ const Checkout = () => {
Grand Total
-<<<<<<< HEAD {currencyFormat(grandTotal)} -======= {currencyFormat( cartCheckout?.grandTotal + finalShippingAmt )} ->>>>>>> dev/voucher-shipment
)} -- cgit v1.2.3 From 8625a9ddf959c131c293254015b59d5cb3b00f55 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 12 Jul 2024 13:28:15 +0700 Subject: { setProducts(cartCheckout?.products); setCheckWeight(cartCheckout?.hasProductWithoutWeight); setTotalWeight(cartCheckout?.totalWeight.g); - setHasFlashSale(cartCheckout?.products[0]?.hasFlashsale ? cartCheckout.products[0].hasFlashsale : false); + const hasFlashSale = cartCheckout?.products.some(product => product.hasFlashsale); + setHasFlashSale(hasFlashSale); }, [cartCheckout]); -- cgit v1.2.3 From ccb5ea650de36e537802893d0abb351739b480b8 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Fri, 12 Jul 2024 13:31:24 +0700 Subject: bug --- src/lib/checkout/components/Checkout.jsx | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 3c2b8a09..73040425 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -245,7 +245,6 @@ const Checkout = () => { setTotalWeight(cartCheckout?.totalWeight.g); setHasFlashSale(cartCheckout?.products[0]?.hasFlashsale ? cartCheckout.products[0].hasFlashsale : false); }, [cartCheckout]); - useEffect(() => { setCheckoutValidation(false); @@ -1392,9 +1391,6 @@ const Checkout = () => {
Grand Total
{currencyFormat(grandTotal)} - {currencyFormat( - cartCheckout?.grandTotal + finalShippingAmt - )}
)} -- cgit v1.2.3 From 19f6ce87e9f6e0a5c2cfbae2cf8eabee777f011a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 12 Jul 2024 13:34:56 +0700 Subject: update flash sale --- src/lib/checkout/components/Checkout.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 4aafdece..77c3590b 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -225,7 +225,8 @@ const Checkout = () => { setProducts(cartCheckout?.products); setCheckWeight(cartCheckout?.hasProductWithoutWeight); setTotalWeight(cartCheckout?.totalWeight.g); - setHasFlashSale(cartCheckout?.products[0]?.hasFlashsale ? cartCheckout.products[0].hasFlashsale : false); + const hasFlashSale = cartCheckout?.products.some(product => product.hasFlashsale); + setHasFlashSale(hasFlashSale); }, [cartCheckout]); -- cgit v1.2.3 From f4eba44dbacf13be894744e48d4248714daee223 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 17 Jul 2024 15:22:34 +0700 Subject: update nomor wa di keranjang --- src/lib/checkout/components/Checkout.jsx | 4 +++- src/lib/checkout/components/CheckoutOld.jsx | 4 +++- src/lib/checkout/components/CheckoutSection.jsx | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 77c3590b..3d7d47b1 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -1589,7 +1589,9 @@ const PickupAddress = ({ label }) => ( Kodepos : 14440

Telp : 021-2933 8828/29

-

Mobile : 0813 9000 7430

+

+ Mobile : 0817-1718-1922 +

); diff --git a/src/lib/checkout/components/CheckoutOld.jsx b/src/lib/checkout/components/CheckoutOld.jsx index e2c45ce6..3c4229aa 100644 --- a/src/lib/checkout/components/CheckoutOld.jsx +++ b/src/lib/checkout/components/CheckoutOld.jsx @@ -802,7 +802,9 @@ const PickupAddress = ({ label }) => ( Daerah Khusus Ibukota Jakarta, Indonesia Kodepos : 14440

Telp : 021-2933 8828/29

-

Mobile : 0813 9000 7430

+

+ Mobile : 0817-1718-1922 +

) diff --git a/src/lib/checkout/components/CheckoutSection.jsx b/src/lib/checkout/components/CheckoutSection.jsx index affe6138..3ed4b115 100644 --- a/src/lib/checkout/components/CheckoutSection.jsx +++ b/src/lib/checkout/components/CheckoutSection.jsx @@ -2,6 +2,7 @@ import Link from 'next/link'; import BottomPopup from '@/core/components/elements/Popup/BottomPopup'; import { AnimatePresence, motion } from 'framer-motion'; import { Divider, Spinner } from '@chakra-ui/react'; +import whatsappUrl from '@/core/utils/whatsappUrl'; export const SectionAddress = ({ address, label, url }) => { return ( @@ -185,7 +186,9 @@ export const PickupAddress = ({ label }) => ( Kodepos : 14440

Telp : 021-2933 8828/29

-

Mobile : 0813 9000 7430

+

+ Mobile : 0817-1718-1922 +

); -- cgit v1.2.3 From d0f97021c611d07944f3cbc7e2610b1d495d897f Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 17 Jul 2024 15:41:02 +0700 Subject: update hover wa link --- src/lib/checkout/components/Checkout.jsx | 2 +- src/lib/checkout/components/CheckoutOld.jsx | 2 +- src/lib/checkout/components/CheckoutSection.jsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 3d7d47b1..92e14db6 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -1589,7 +1589,7 @@ const PickupAddress = ({ label }) => ( Kodepos : 14440

Telp : 021-2933 8828/29

-

+

Mobile : 0817-1718-1922

diff --git a/src/lib/checkout/components/CheckoutOld.jsx b/src/lib/checkout/components/CheckoutOld.jsx index 3c4229aa..5b479a73 100644 --- a/src/lib/checkout/components/CheckoutOld.jsx +++ b/src/lib/checkout/components/CheckoutOld.jsx @@ -802,7 +802,7 @@ const PickupAddress = ({ label }) => ( Daerah Khusus Ibukota Jakarta, Indonesia Kodepos : 14440

Telp : 021-2933 8828/29

-

+

Mobile : 0817-1718-1922

diff --git a/src/lib/checkout/components/CheckoutSection.jsx b/src/lib/checkout/components/CheckoutSection.jsx index 3ed4b115..623152c6 100644 --- a/src/lib/checkout/components/CheckoutSection.jsx +++ b/src/lib/checkout/components/CheckoutSection.jsx @@ -186,7 +186,7 @@ export const PickupAddress = ({ label }) => ( Kodepos : 14440

Telp : 021-2933 8828/29

-

+

Mobile : 0817-1718-1922

-- cgit v1.2.3 From 0433d92034937c76135ceb83ef88402464006866 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Mon, 22 Jul 2024 15:08:07 +0700 Subject: get new voucher --- src/lib/checkout/components/Checkout.jsx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 92e14db6..61410bdf 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -30,7 +30,7 @@ import whatsappUrl from '@/core/utils/whatsappUrl'; import addressesApi from '@/lib/address/api/addressesApi'; import CartItem from '~/modules/cart/components/Item.tsx'; import ExpedisiList from '../api/ExpedisiList'; -import { findVoucher, getVoucher } from '../api/getVoucher'; +import { findVoucher, getVoucher, getVoucherNew } from '../api/getVoucher'; const SELF_PICKUP_ID = 32; @@ -40,6 +40,7 @@ const { getProductsCheckout } = require('../api/checkoutApi'); const Checkout = () => { const router = useRouter(); const query = router.query.source ?? null; + const qVoucher = router.query.voucher ?? null; const auth = useAuth(); const [activeVoucher, SetActiveVoucher] = useState(null); @@ -119,7 +120,8 @@ const Checkout = () => { const voucher = async () => { if (!listVouchers) { try { - let dataVoucher = await getVoucher(auth?.id, query); + let source = 'source=' + query; + let dataVoucher = await getVoucherNew(source); SetListVoucher(dataVoucher); } finally { setLoadingVoucher(false); @@ -127,14 +129,16 @@ const Checkout = () => { } }; const VoucherCode = async (code) => { - let dataVoucher = await findVoucher(code, auth.id, query); + const source = 'code=' + code+'&source='+query; + // let dataVoucher = await findVoucher(code, auth.id, query); + let dataVoucher = await getVoucherNew(source); if (dataVoucher.length <= 0) { SetFindVoucher(1); return; } let addNewLine = dataVoucher[0]; - let checkList = listVouchers.findIndex( + let checkList = listVouchers?.findIndex( (voucher) => voucher.code == addNewLine.code ); if (checkList >= 0) { @@ -166,6 +170,8 @@ const Checkout = () => { }, [bottomPopup]); useEffect(() => { + + // voucher() const loadExpedisi = async () => { let dataExpedisi = await ExpedisiList(); dataExpedisi = dataExpedisi.map((expedisi) => ({ @@ -176,6 +182,10 @@ const Checkout = () => { setExpedisi(dataExpedisi); }; loadExpedisi(); + if(qVoucher === 'PASTIHEMAT'){ + let code = qVoucher; + handleUseVoucher(code, !isChecked); + } const handlePopState = () => { router.push('/shop/cart'); @@ -186,7 +196,7 @@ const Checkout = () => { return () => { window.onpopstate = null; }; - // voucher() + }, []); const hitungDiscountVoucher = (code) => { @@ -407,13 +417,13 @@ const Checkout = () => { } else { SetActiveVoucher(code); SetFindVoucher(null); - document.getElementById('uniqCode').value = ''; + document.getElementById('uniqCode') ? document.getElementById('uniqCode').value = '' : ''; SetButtonTerapkan(false); } } else { SetActiveVoucher(code); SetFindVoucher(null); - document.getElementById('uniqCode').value = ''; + document.getElementById('uniqCode') ? document.getElementById('uniqCode').value = '' : ''; SetButtonTerapkan(false); } }; -- cgit v1.2.3 From 95081416190d09bbbe4f3d745e69ff81258bde7a Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Mon, 22 Jul 2024 15:38:48 +0700 Subject: add params voucher --- src/lib/checkout/components/Checkout.jsx | 40 +++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 61410bdf..9bc0257e 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -129,7 +129,7 @@ const Checkout = () => { } }; const VoucherCode = async (code) => { - const source = 'code=' + code+'&source='+query; + const source = 'code=' + code + '&source=' + query; // let dataVoucher = await findVoucher(code, auth.id, query); let dataVoucher = await getVoucherNew(source); if (dataVoucher.length <= 0) { @@ -170,8 +170,7 @@ const Checkout = () => { }, [bottomPopup]); useEffect(() => { - - // voucher() + voucher(); const loadExpedisi = async () => { let dataExpedisi = await ExpedisiList(); dataExpedisi = dataExpedisi.map((expedisi) => ({ @@ -182,10 +181,6 @@ const Checkout = () => { setExpedisi(dataExpedisi); }; loadExpedisi(); - if(qVoucher === 'PASTIHEMAT'){ - let code = qVoucher; - handleUseVoucher(code, !isChecked); - } const handlePopState = () => { router.push('/shop/cart'); @@ -196,7 +191,6 @@ const Checkout = () => { return () => { window.onpopstate = null; }; - }, []); const hitungDiscountVoucher = (code) => { @@ -231,14 +225,22 @@ const Checkout = () => { SetDiscountVoucher(countDiscount); }, [activeVoucher, listVouchers]); + useEffect(() => { + if (qVoucher === 'PASTIHEMAT' && listVouchers) { + let code = qVoucher; + VoucherCode(code); + } + }, [listVouchers]); + useEffect(() => { setProducts(cartCheckout?.products); setCheckWeight(cartCheckout?.hasProductWithoutWeight); setTotalWeight(cartCheckout?.totalWeight.g); - const hasFlashSale = cartCheckout?.products.some(product => product.hasFlashsale); + const hasFlashSale = cartCheckout?.products.some( + (product) => product.hasFlashsale + ); setHasFlashSale(hasFlashSale); }, [cartCheckout]); - useEffect(() => { setCheckoutValidation(false); @@ -357,7 +359,7 @@ const Checkout = () => { carrier_id: selectedCarrierId, estimated_arrival_days: splitDuration(etd), delivery_service_type: selectedExpedisiService, - flash_sale : hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false + flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false voucher: activeVoucher, type: 'sale_order', }; @@ -373,7 +375,7 @@ const Checkout = () => { toast.error('Gagal melakukan transaksi, terjadi kesalahan internal'); return; } - + gtagPurchase(products, biayaKirim, isCheckouted.name); const midtrans = async () => { @@ -417,13 +419,17 @@ const Checkout = () => { } else { SetActiveVoucher(code); SetFindVoucher(null); - document.getElementById('uniqCode') ? document.getElementById('uniqCode').value = '' : ''; + document.getElementById('uniqCode') + ? (document.getElementById('uniqCode').value = '') + : ''; SetButtonTerapkan(false); } } else { SetActiveVoucher(code); SetFindVoucher(null); - document.getElementById('uniqCode') ? document.getElementById('uniqCode').value = '' : ''; + document.getElementById('uniqCode') + ? (document.getElementById('uniqCode').value = '') + : ''; SetButtonTerapkan(false); } }; @@ -1599,9 +1605,11 @@ const PickupAddress = ({ label }) => ( Kodepos : 14440

Telp : 021-2933 8828/29

-

+

+ Mobile : 0817-1718-1922 -

+ +

); -- cgit v1.2.3