From ed0adaad2125b46a6c039ce89b38b3cbb8379342 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Fri, 1 Nov 2024 13:42:10 +0700
Subject: add label pinpoint di pagecheckout
---
src/lib/checkout/components/Checkout.jsx | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 0e180d9c..97254ec0 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -1,4 +1,4 @@
-import { Skeleton, Spinner } from '@chakra-ui/react';
+import { Button, Skeleton, Spinner } from '@chakra-ui/react';
import {
BanknotesIcon,
ChevronLeftIcon,
@@ -31,6 +31,7 @@ import addressesApi from '@/lib/address/api/addressesApi';
import CartItem from '~/modules/cart/components/Item.tsx';
import ExpedisiList from '../api/ExpedisiList';
import { findVoucher, getVoucher, getVoucherNew } from '../api/getVoucher';
+import { MapPinIcon } from 'lucide-react';
const SELF_PICKUP_ID = 32;
@@ -413,7 +414,12 @@ const Checkout = () => {
Math.round(parseInt(finalShippingAmt * 1.1) / 1000) * 1000;
const finalGT = GT < 0 ? 0 : GT;
setGrandTotal(finalGT);
- }, [biayaKirim, cartCheckout?.grandTotal, activeVoucher, activeVoucherShipping]);
+ }, [
+ biayaKirim,
+ cartCheckout?.grandTotal,
+ activeVoucher,
+ activeVoucherShipping,
+ ]);
const checkout = async () => {
const file = poFile.current.files[0];
@@ -500,7 +506,7 @@ const Checkout = () => {
}
}
- /* const midtrans = async () => {
+ /* const midtrans = async () => {
for (const product of products) deleteItemCart({ productId: product.id });
if (grandTotal > 0) {
const payment = await axios.post(
@@ -1192,7 +1198,11 @@ const Checkout = () => {
- {currencyFormat(Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000)}
+
+ {currencyFormat(
+ Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000
+ )}
+
{activeVoucherShipping && voucherShippingAmt && (
@@ -1493,7 +1503,11 @@ const Checkout = () => {
Biaya Kirim
{etdFix}
- {currencyFormat(Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000) }
+
+ {currencyFormat(
+ Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000
+ )}
+
{activeVoucherShipping && voucherShippingAmt && (
@@ -1658,9 +1672,13 @@ const SectionAddress = ({ address, label, url }) => (
{address.street}, {address?.city?.name}
+
+
+ {address.addressMap ? : }
+
)}
-
+
);
const SectionValidation = ({ address }) =>
--
cgit v1.2.3
From ebba81f144b860eaf3bd7a9ef2b1c63a2ff021e0 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Thu, 7 Nov 2024 12:59:56 +0700
Subject: get couries biteship
---
src/lib/checkout/components/Checkout.jsx | 58 ++++----------------------------
1 file changed, 6 insertions(+), 52 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 97254ec0..6da27745 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -269,58 +269,6 @@ const Checkout = () => {
};
}, []);
- const hitungDiscountVoucher = (code, source) => {
- let countDiscount = 0;
- if (source === 'voucher') {
- let dataVoucherIndex = listVouchers.findIndex(
- (voucher) => voucher.code == code
- );
- let dataActiveVoucher = listVouchers[dataVoucherIndex];
-
- countDiscount = dataActiveVoucher.discountVoucher;
- } else {
- let dataVoucherIndex = listVoucherShippings.findIndex(
- (voucher) => voucher.code == code
- );
- let dataActiveVoucher = listVoucherShippings[dataVoucherIndex];
-
- countDiscount = dataActiveVoucher.discountVoucher;
- }
-
- /*if (dataActiveVoucher.discountType === 'percentage') {
- countDiscount = cartCheckout?.subtotal * (dataActiveVoucher.discountAmount / 100)
- if (
- dataActiveVoucher.maxDiscountAmount > 0 &&
- countDiscount > dataActiveVoucher.maxDiscountAmount
- ) {
- countDiscount = dataActiveVoucher.maxDiscountAmount
- }
- } else {
- countDiscount = dataActiveVoucher.discountAmount
- }*/
-
- return countDiscount;
- };
-
- // useEffect(() => {
- // if (!listVouchers) return;
- // if (!activeVoucher) return;
-
- // console.log('voucher')
- // const countDiscount = hitungDiscountVoucher(activeVoucher, 'voucher');
-
- // SetDiscountVoucher(countDiscount);
- // }, [activeVoucher, listVouchers]);
-
- // useEffect(() => {
- // if (!listVoucherShippings) return;
- // if (!activeVoucherShipping) return;
-
- // const countDiscount = hitungDiscountVoucher(activeVoucherShipping, 'voucher_shipping');
-
- // SetDiscountVoucherOngkir(countDiscount);
- // }, [activeVoucherShipping, listVoucherShippings]);
-
useEffect(() => {
if (qVoucher === 'PASTIHEMAT' && listVouchers) {
let code = qVoucher;
@@ -1698,6 +1646,12 @@ const SectionValidation = ({ address }) =>
);
+const SectionExpedisiBiteship = ({ listExpedisi, setSelectedExpedisi }) => (
+ <>
+ >
+);
+
+
const SectionExpedisi = ({
address,
listExpedisi,
--
cgit v1.2.3
From 7966f67569d01c25f7a337962d7d0bb1a0c57808 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Wed, 13 Nov 2024 14:46:59 +0700
Subject: get couries, mapping couries and service
---
src/lib/checkout/components/Checkout.jsx | 53 +++++++++++++++++++++++---------
1 file changed, 39 insertions(+), 14 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 6da27745..b4c311a9 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -1,4 +1,4 @@
-import { Button, Skeleton, Spinner } from '@chakra-ui/react';
+import { Skeleton, Spinner } from '@chakra-ui/react';
import {
BanknotesIcon,
ChevronLeftIcon,
@@ -28,10 +28,12 @@ import getFileBase64 from '@/core/utils/getFileBase64';
import { gtagPurchase } from '@/core/utils/googleTag';
import whatsappUrl from '@/core/utils/whatsappUrl';
import addressesApi from '@/lib/address/api/addressesApi';
+import { MapPinIcon } from 'lucide-react';
import CartItem from '~/modules/cart/components/Item.tsx';
import ExpedisiList from '../api/ExpedisiList';
-import { findVoucher, getVoucher, getVoucherNew } from '../api/getVoucher';
-import { MapPinIcon } from 'lucide-react';
+import { getVoucher } from '../api/getVoucher';
+import { useAddress } from '../stores/useAdress';
+import SectionExpedition from './SectionExpedition';
const SELF_PICKUP_ID = 32;
@@ -57,11 +59,15 @@ const Checkout = () => {
})
);
- const [selectedAddress, setSelectedAddress] = useState({
- shipping: null,
- invoicing: null,
- });
- const [addresses, setAddresses] = useState(null);
+ const {
+ selectedAddress,
+ setSelectedAddress,
+ addresses,
+ setAddresses,
+ setAddressMaps,
+ setCoordinate,
+ setPostalCode,
+ } = useAddress();
useEffect(() => {
if (!auth) return;
@@ -91,10 +97,20 @@ const Checkout = () => {
return addresses[0];
};
+ let ship = matchAddress('shipping');
+
setSelectedAddress({
shipping: matchAddress('shipping'),
invoicing: matchAddress('invoicing'),
});
+ setPostalCode(ship?.zip);
+ if (ship?.addressMap) {
+ setAddressMaps(ship?.addressMap);
+ setCoordinate({
+ destination_latitude: ship?.latitude,
+ destination_longitude: ship?.longtitude,
+ });
+ }
}, [addresses]);
const [products, setProducts] = useState(null);
@@ -1340,6 +1356,7 @@ const Checkout = () => {
/>
)}
+ {products && }
(
{address.street}, {address?.city?.name}
-
- {address.addressMap ? : }
+
+ {address.addressMap ? (
+
+ ) : (
+
+ )}
)}
-
+
);
const SectionValidation = ({ address }) =>
@@ -1647,11 +1674,9 @@ const SectionValidation = ({ address }) =>
);
const SectionExpedisiBiteship = ({ listExpedisi, setSelectedExpedisi }) => (
- <>
- >
+ <>>
);
-
const SectionExpedisi = ({
address,
listExpedisi,
--
cgit v1.2.3
From b18d45c560d57c788d3646cf6be0beb6381ec0f7 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Thu, 14 Nov 2024 10:53:54 +0700
Subject: biteship
---
src/lib/checkout/components/Checkout.jsx | 4 ----
1 file changed, 4 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index b0f8f884..152b84ed 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -1674,10 +1674,6 @@ const SectionValidation = ({ address }) =>
);
-const SectionExpedisiBiteship = ({ listExpedisi, setSelectedExpedisi }) => (
- <>>
-);
-
const SectionExpedisi = ({
address,
listExpedisi,
--
cgit v1.2.3
From 0d4278bd482d2ec2563b29cb3597eb8c7227a2d7 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Fri, 15 Nov 2024 13:32:26 +0700
Subject: add hook state
---
src/lib/checkout/components/Checkout.jsx | 13 -------------
1 file changed, 13 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 152b84ed..4dd715d7 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -662,19 +662,6 @@ const Checkout = () => {
)}
- {/* {!loadingVoucher &&
- listVouchers?.length === 1 &&
- listVoucherShippings?.length === 1}
- {
-
-
-
Tidak ada voucher tersedia
-
- Maaf, saat ini tidak ada voucher yang tersedia.
-
-
-
- } */}
{listVoucherShippings && listVoucherShippings?.length > 0 && (
--
cgit v1.2.3
From d078c6adfd896b59f14e2a5116ecb977256674fa Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Tue, 19 Nov 2024 16:51:54 +0700
Subject: biteships
---
src/lib/checkout/components/Checkout.jsx | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 33cfaa87..92a94834 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -34,6 +34,7 @@ import ExpedisiList from '../api/ExpedisiList';
import { getVoucher } from '../api/getVoucher';
import { useAddress } from '../stores/useAdress';
import SectionExpedition from './SectionExpedition';
+import { useCheckout } from '../stores/stateCheckout';
const SELF_PICKUP_ID = 32;
@@ -125,7 +126,6 @@ const Checkout = () => {
}
}, [addresses]);
- const [products, setProducts] = useState(null);
const [totalWeight, setTotalWeight] = useState(0);
const [priceCheck, setPriceCheck] = useState(false);
const [listExpedisi, setExpedisi] = useState([]);
@@ -133,8 +133,6 @@ const Checkout = () => {
const [selectedExpedisi, setSelectedExpedisi] = useState(0);
const [selectedCarrierId, setselectedCarrierId] = useState(0);
const [selectedCarrier, setselectedCarrier] = useState(0);
- const [biayaKirim, setBiayaKirim] = useState(0);
- const [checkWeigth, setCheckWeight] = useState(false);
const [selectedServiceType, setSelectedServiceType] = useState(null);
const [selectedExpedisiService, setselectedExpedisiService] = useState(null);
const [etd, setEtd] = useState(null);
@@ -149,11 +147,11 @@ const Checkout = () => {
const [findCodeVoucher, SetFindVoucher] = useState(null);
const [selisihHargaCode, SetSelisihHargaCode] = useState(null);
const [buttonTerapkan, SetButtonTerapkan] = useState(false);
- const [checkoutValidation, setCheckoutValidation] = useState(false);
const [loadingVoucher, setLoadingVoucher] = useState(true);
const [loadingRajaOngkir, setLoadingRajaOngkir] = useState(false);
const [grandTotal, setGrandTotal] = useState(0);
- const [hasFlashSale, setHasFlashSale] = useState(false);
+
+ const {checkWeigth, setCheckWeight, hasFlashSale, setHasFlashSale, checkoutValidation, setCheckoutValidation, biayaKirim, setBiayaKirim, products, setProducts} = useCheckout();
const expedisiValidation = useRef(null);
@@ -571,6 +569,9 @@ const Checkout = () => {
cartCheckout?.discountVoucher +
(cartCheckout?.discountVoucherShipping || 0);
+
+ console.log('etd', etd, calculateEstimatedArrival(etd), splitDuration(etd));
+
return (
<>
Date: Tue, 26 Nov 2024 09:46:07 +0700
Subject: filter biteship courier sesuikan dengan courier dari odoo
---
src/lib/checkout/components/Checkout.jsx | 185 ++++++++++++++-----------------
1 file changed, 84 insertions(+), 101 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 92a94834..38e11038 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -35,6 +35,7 @@ import { getVoucher } from '../api/getVoucher';
import { useAddress } from '../stores/useAdress';
import SectionExpedition from './SectionExpedition';
import { useCheckout } from '../stores/stateCheckout';
+import { formatShipmentRange, getToDate } from '../utils/functionCheckouit';
const SELF_PICKUP_ID = 32;
@@ -128,15 +129,14 @@ const Checkout = () => {
const [totalWeight, setTotalWeight] = useState(0);
const [priceCheck, setPriceCheck] = useState(false);
- const [listExpedisi, setExpedisi] = useState([]);
const [listserviceExpedisi, setListServiceExpedisi] = useState([]);
const [selectedExpedisi, setSelectedExpedisi] = useState(0);
const [selectedCarrierId, setselectedCarrierId] = useState(0);
const [selectedCarrier, setselectedCarrier] = useState(0);
const [selectedServiceType, setSelectedServiceType] = useState(null);
const [selectedExpedisiService, setselectedExpedisiService] = useState(null);
- const [etd, setEtd] = useState(null);
- const [etdFix, setEtdFix] = useState(null);
+ // const [etd, setEtd] = useState(null);
+ // const [etdFix, setEtdFix] = useState(null);
const [bottomPopup, SetBottomPopup] = useState(null);
const [bottomPopupTnC, SetBottomPopupTnC] = useState(null);
const [itemTnC, setItemTnC] = useState(null);
@@ -151,7 +151,7 @@ const Checkout = () => {
const [loadingRajaOngkir, setLoadingRajaOngkir] = useState(false);
const [grandTotal, setGrandTotal] = useState(0);
- const {checkWeigth, setCheckWeight, hasFlashSale, setHasFlashSale, checkoutValidation, setCheckoutValidation, biayaKirim, setBiayaKirim, products, setProducts} = useCheckout();
+ const {checkWeigth, setCheckWeight, hasFlashSale, setHasFlashSale, checkoutValidation, setCheckoutValidation, biayaKirim, products, setProducts, etd, unit, selectedCourier, selectedService, listExpedisi, setExpedisi} = useCheckout();
const expedisiValidation = useRef(null);
@@ -290,6 +290,7 @@ const Checkout = () => {
window.onpopstate = handlePopState;
+
return () => {
window.onpopstate = null;
};
@@ -312,70 +313,70 @@ const Checkout = () => {
setHasFlashSale(hasFlashSale);
}, [cartCheckout]);
- useEffect(() => {
- setCheckoutValidation(false);
- const loadServiceRajaOngkir = async () => {
- setLoadingRajaOngkir(true);
- const body = {
- origin: 2127,
- destination: selectedAddress.shipping.rajaongkirCityId,
- weight: totalWeight,
- courier: selectedCarrier,
- originType: 'subdistrict',
- destinationType: 'subdistrict',
- };
- setBiayaKirim(0);
- const dataService = await axios(
- '/api/rajaongkir-service?body=' + JSON.stringify(body)
- );
- setLoadingRajaOngkir(false);
- setListServiceExpedisi(dataService.data[0].costs);
- if (dataService.data[0].costs[0]) {
- setBiayaKirim(dataService.data[0].costs[0]?.cost[0].value);
- setselectedExpedisiService(
- dataService.data[0].costs[0]?.description +
- '-' +
- dataService.data[0].costs[0]?.service
- );
- setEtd(dataService.data[0].costs[0]?.cost[0].etd);
- toast.success('Harap pilih tipe layanan pengiriman');
- } else {
- toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
- }
- };
- if (selectedCarrier != 0 && selectedCarrier != 1 && totalWeight > 0) {
- loadServiceRajaOngkir();
- } else {
- setListServiceExpedisi();
- setBiayaKirim(0);
- setselectedExpedisiService();
- setEtd();
- }
- }, [selectedCarrier, selectedAddress, totalWeight]);
-
- useEffect(() => {
- if (selectedServiceType) {
- let serviceType = selectedServiceType.split(',');
- setBiayaKirim(serviceType[0]);
- setselectedExpedisiService(serviceType[1]);
- setEtd(serviceType[2]);
- }
- }, [selectedServiceType]);
-
- useEffect(() => {
- if (etd) setEtdFix(calculateEstimatedArrival(etd));
- }, [etd]);
-
- useEffect(() => {
- if (selectedExpedisi) {
- let serviceType = selectedExpedisi.split(',');
- if (serviceType[0] === 0) return;
-
- setselectedCarrier(serviceType[0]);
- setselectedCarrierId(serviceType[1]);
- setListServiceExpedisi([]);
- }
- }, [selectedExpedisi]);
+ // useEffect(() => {
+ // setCheckoutValidation(false);
+ // const loadServiceRajaOngkir = async () => {
+ // setLoadingRajaOngkir(true);
+ // const body = {
+ // origin: 2127,
+ // destination: selectedAddress.shipping.rajaongkirCityId,
+ // weight: totalWeight,
+ // courier: selectedCarrier,
+ // originType: 'subdistrict',
+ // destinationType: 'subdistrict',
+ // };
+ // setBiayaKirim(0);
+ // const dataService = await axios(
+ // '/api/rajaongkir-service?body=' + JSON.stringify(body)
+ // );
+ // setLoadingRajaOngkir(false);
+ // setListServiceExpedisi(dataService.data[0].costs);
+ // if (dataService.data[0].costs[0]) {
+ // setBiayaKirim(dataService.data[0].costs[0]?.cost[0].value);
+ // setselectedExpedisiService(
+ // dataService.data[0].costs[0]?.description +
+ // '-' +
+ // dataService.data[0].costs[0]?.service
+ // );
+ // setEtd(dataService.data[0].costs[0]?.cost[0].etd);
+ // toast.success('Harap pilih tipe layanan pengiriman');
+ // } else {
+ // toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
+ // }
+ // };
+ // if (selectedCarrier != 0 && selectedCarrier != 1 && totalWeight > 0) {
+ // loadServiceRajaOngkir();
+ // } else {
+ // setListServiceExpedisi();
+ // setBiayaKirim(0);
+ // setselectedExpedisiService();
+ // setEtd();
+ // }
+ // }, [selectedCarrier, selectedAddress, totalWeight]);
+
+ // useEffect(() => {
+ // if (selectedServiceType) {
+ // let serviceType = selectedServiceType.split(',');
+ // setBiayaKirim(serviceType[0]);
+ // setselectedExpedisiService(serviceType[1]);
+ // setEtd(serviceType[2]);
+ // }
+ // }, [selectedServiceType]);
+
+ // useEffect(() => {
+ // if (etd) setEtdFix(calculateEstimatedArrival(etd));
+ // }, [etd]);
+
+ // useEffect(() => {
+ // if (selectedExpedisi) {
+ // let serviceType = selectedExpedisi.split(',');
+ // if (serviceType[0] === 0) return;
+
+ // setselectedCarrier(serviceType[0]);
+ // setselectedCarrierId(serviceType[1]);
+ // setListServiceExpedisi([]);
+ // }
+ // }, [selectedExpedisi]);
const poNumber = useRef(null);
const poFile = useRef(null);
@@ -403,7 +404,7 @@ const Checkout = () => {
});
return;
}
- if (selectedExpedisi === 0) {
+ if (selectedCourier === 0 || !selectedCourier) {
setCheckoutValidation(true);
if (expedisiValidation.current) {
const position = expedisiValidation.current.getBoundingClientRect();
@@ -414,7 +415,11 @@ const Checkout = () => {
}
return;
}
- if (selectedCarrier != 1 && biayaKirim == 0) {
+ if(!selectedService){
+ toast.error('Harap pilih tipe layanan pengiriman');
+ return;
+ }
+ if (selectedCourier != 1 && biayaKirim == 0) {
toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
return;
}
@@ -432,15 +437,14 @@ const Checkout = () => {
user_id: auth.id,
order_line: JSON.stringify(productOrder),
delivery_amount: biayaKirim,
- carrier_id: selectedCarrierId,
- estimated_arrival_days: splitDuration(etd),
- delivery_service_type: selectedExpedisiService,
+ carrier_id: selectedCourier,
+ estimated_arrival_days: getToDate(etd, unit),
+ delivery_service_type: selectedService?.service_type,
flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false
voucher: activeVoucher,
voucher_shipping: activeVoucherShipping,
type: 'sale_order',
};
-
if (query) {
data.source = 'buy';
}
@@ -487,24 +491,6 @@ const Checkout = () => {
)}`;
}
}
-
- /* const midtrans = async () => {
- for (const product of products) deleteItemCart({ productId: product.id });
- if (grandTotal > 0) {
- const payment = await axios.post(
- `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}`
- );
- setIsLoading(false);
- window.location.href = payment.data.redirectUrl;
- } else {
- window.location.href = `${
- process.env.NEXT_PUBLIC_SELF_HOST
- }/shop/checkout/success?order_id=${isCheckouted.name.replace(
- /\//g,
- '-'
- )}`;
- }
- };*/
};
const handlingActivateCode = async () => {
@@ -569,9 +555,6 @@ const Checkout = () => {
cartCheckout?.discountVoucher +
(cartCheckout?.discountVoucherShipping || 0);
-
- console.log('etd', etd, calculateEstimatedArrival(etd), splitDuration(etd));
-
return (
<>
{
)}
- {
+ /> */}
{!!products &&
@@ -1168,7 +1151,7 @@ const Checkout = () => {
- Biaya Kirim
{etdFix}
+ Biaya Kirim
{formatShipmentRange(etd, unit)}
{currencyFormat(
@@ -1367,7 +1350,7 @@ const Checkout = () => {
{products &&
}
-
{
+ /> */}
Detail Pesanan
@@ -1474,7 +1457,7 @@ const Checkout = () => {
Biaya Kirim
-
{etdFix}
+
{formatShipmentRange(etd, unit)}
{currencyFormat(
--
cgit v1.2.3
From d1592286eef165533c21d52aec70dbb703cdcfd3 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Wed, 18 Dec 2024 15:03:52 +0700
Subject: feedback uat
---
src/lib/checkout/components/Checkout.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 38e11038..0471dc6c 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -430,7 +430,7 @@ const Checkout = () => {
available_quantity: product?.availableQuantity,
}));
let data = {
- // partner_shipping_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,
--
cgit v1.2.3
From 5559770e0b0e94b68de1e31bf2be5c978362821d Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Tue, 31 Dec 2024 09:01:10 +0700
Subject: logo and mapping courier
---
src/lib/checkout/components/Checkout.jsx | 1 +
1 file changed, 1 insertion(+)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 0471dc6c..99c7b40a 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -279,6 +279,7 @@ const Checkout = () => {
value: expedisi.id,
label: expedisi.name,
carrierId: expedisi.deliveryCarrierId,
+ logo : expedisi.image,
}));
setExpedisi(dataExpedisi);
};
--
cgit v1.2.3
From bd4cdf2125f717875ba90e03893b319dd962f753 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Sat, 18 Jan 2025 10:37:49 +0700
Subject: bittesip
---
src/lib/checkout/components/Checkout.jsx | 48 ++++++++++++++++++++++++--------
1 file changed, 36 insertions(+), 12 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 99c7b40a..6479881d 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -44,11 +44,11 @@ const { getProductsCheckout } = require('../api/checkoutApi');
function convertToInternational(number) {
if (typeof number !== 'string') {
- throw new Error("Input harus berupa string");
+ throw new Error('Input harus berupa string');
}
if (number.startsWith('08')) {
- return '+62' + number.slice(2);
+ return '+62' + number.slice(2);
}
return number;
@@ -151,7 +151,23 @@ const Checkout = () => {
const [loadingRajaOngkir, setLoadingRajaOngkir] = useState(false);
const [grandTotal, setGrandTotal] = useState(0);
- const {checkWeigth, setCheckWeight, hasFlashSale, setHasFlashSale, checkoutValidation, setCheckoutValidation, biayaKirim, products, setProducts, etd, unit, selectedCourier, selectedService, listExpedisi, setExpedisi} = useCheckout();
+ const {
+ checkWeigth,
+ setCheckWeight,
+ hasFlashSale,
+ setHasFlashSale,
+ checkoutValidation,
+ setCheckoutValidation,
+ biayaKirim,
+ products,
+ setProducts,
+ etd,
+ unit,
+ selectedCourier,
+ selectedService,
+ listExpedisi,
+ setExpedisi,
+ } = useCheckout();
const expedisiValidation = useRef(null);
@@ -279,7 +295,7 @@ const Checkout = () => {
value: expedisi.id,
label: expedisi.name,
carrierId: expedisi.deliveryCarrierId,
- logo : expedisi.image,
+ logo: expedisi.image,
}));
setExpedisi(dataExpedisi);
};
@@ -291,7 +307,6 @@ const Checkout = () => {
window.onpopstate = handlePopState;
-
return () => {
window.onpopstate = null;
};
@@ -416,7 +431,7 @@ const Checkout = () => {
}
return;
}
- if(!selectedService){
+ if (!selectedService) {
toast.error('Harap pilih tipe layanan pengiriman');
return;
}
@@ -471,10 +486,12 @@ const Checkout = () => {
gtag('set', 'user_data', {
email: auth.email,
- phone_number: convertToInternational(auth.mobile) ?? convertToInternational(auth.phone),
+ phone_number:
+ convertToInternational(auth.mobile) ??
+ convertToInternational(auth.phone),
});
- gtag('config', 'AW-954540379', { ' allow_enhanced_conversions':true } ) ;
+ gtag('config', 'AW-954540379', { ' allow_enhanced_conversions': true });
for (const product of products) deleteItemCart({ productId: product.id });
if (grandTotal > 0) {
@@ -1152,7 +1169,10 @@ const Checkout = () => {
- Biaya Kirim
{formatShipmentRange(etd, unit)}
+ Biaya Kirim{' '}
+
+ {formatShipmentRange(etd, unit)}
+
{currencyFormat(
@@ -1458,7 +1478,9 @@ const Checkout = () => {
Biaya Kirim
-
{formatShipmentRange(etd, unit)}
+
+ {formatShipmentRange(etd, unit)}
+
{currencyFormat(
@@ -1629,7 +1651,7 @@ const SectionAddress = ({ address, label, url }) => (
{address.street}, {address?.city?.name}
-
+
(
{address.addressMap ? (
) : (
-
+
+
+
)}
--
cgit v1.2.3
From c26a0d026886e6f70ea3487b9d83a54d20b9c1e4 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Tue, 28 Jan 2025 09:46:11 +0700
Subject: biteship
---
src/lib/checkout/components/Checkout.jsx | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 5f630799..3ad833ec 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -168,6 +168,7 @@ const Checkout = () => {
selectedService,
listExpedisi,
setExpedisi,
+ productSla
} = useCheckout();
const expedisiValidation = useRef(null);
@@ -1171,7 +1172,7 @@ const Checkout = () => {
Biaya Kirim{' '}
- {formatShipmentRange(etd, unit)}
+ {formatShipmentRange(etd, unit, productSla)}
@@ -1479,7 +1480,7 @@ const Checkout = () => {
Biaya Kirim
- {formatShipmentRange(etd, unit)}
+ {formatShipmentRange(etd, unit, productSla)}
--
cgit v1.2.3
From 58601bc17b6f0516eee9c36aa36e39f1dea3ad77 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Wed, 26 Feb 2025 10:47:58 +0700
Subject: bitehsip
---
src/lib/checkout/components/Checkout.jsx | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 3ad833ec..1a7fdc03 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -165,6 +165,7 @@ const Checkout = () => {
etd,
unit,
selectedCourier,
+ selectedCourierId,
selectedService,
listExpedisi,
setExpedisi,
@@ -447,6 +448,10 @@ const Checkout = () => {
quantity: product.quantity,
available_quantity: product?.availableQuantity,
}));
+ let estimated_courier = etd.split('-').map(Number);
+ let eta_courier = Math.max(...estimated_courier);
+ let eta_courier_start = Math.min(...estimated_courier);
+
let data = {
// partner_shipping_id: auth.partnerId,,
// partner_invoice_id: auth.partnerId,
@@ -455,8 +460,9 @@ const Checkout = () => {
user_id: auth.id,
order_line: JSON.stringify(productOrder),
delivery_amount: biayaKirim,
- carrier_id: selectedCourier,
- estimated_arrival_days: getToDate(etd, unit),
+ carrier_id: selectedCourierId,
+ estimated_arrival_days_start : parseInt(eta_courier_start) + parseInt(productSla),
+ estimated_arrival_days: parseInt(eta_courier) + parseInt(productSla),
delivery_service_type: selectedService?.service_type,
flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false
voucher: activeVoucher,
@@ -469,6 +475,8 @@ const Checkout = () => {
if (poNumber.current.value) data.po_number = poNumber.current.value;
if (typeof file !== 'undefined') data.po_file = await getFileBase64(file);
+ console.log('ini data', data);
+
const isCheckouted = await checkoutApi({ data });
if (!isCheckouted?.id) {
@@ -1297,7 +1305,6 @@ const Checkout = () => {
className='flex-1 btn-yellow'
onClick={checkout}
disabled={
- isLoading ||
!products ||
products?.length == 0 ||
priceCheck ||
@@ -1603,7 +1610,6 @@ const Checkout = () => {
className='w-full btn-yellow mt-4'
onClick={checkout}
disabled={
- isLoading ||
!products ||
products?.length == 0 ||
priceCheck ||
--
cgit v1.2.3
From 00ba9833becbea5b25c6aafcb95b327d8adef4e3 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Mon, 3 Mar 2025 14:41:44 +0700
Subject: delete comment
---
src/lib/checkout/components/Checkout.jsx | 65 --------------------------------
1 file changed, 65 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 1a7fdc03..d5c370bf 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -332,71 +332,6 @@ const Checkout = () => {
setHasFlashSale(hasFlashSale);
}, [cartCheckout]);
- // useEffect(() => {
- // setCheckoutValidation(false);
- // const loadServiceRajaOngkir = async () => {
- // setLoadingRajaOngkir(true);
- // const body = {
- // origin: 2127,
- // destination: selectedAddress.shipping.rajaongkirCityId,
- // weight: totalWeight,
- // courier: selectedCarrier,
- // originType: 'subdistrict',
- // destinationType: 'subdistrict',
- // };
- // setBiayaKirim(0);
- // const dataService = await axios(
- // '/api/rajaongkir-service?body=' + JSON.stringify(body)
- // );
- // setLoadingRajaOngkir(false);
- // setListServiceExpedisi(dataService.data[0].costs);
- // if (dataService.data[0].costs[0]) {
- // setBiayaKirim(dataService.data[0].costs[0]?.cost[0].value);
- // setselectedExpedisiService(
- // dataService.data[0].costs[0]?.description +
- // '-' +
- // dataService.data[0].costs[0]?.service
- // );
- // setEtd(dataService.data[0].costs[0]?.cost[0].etd);
- // toast.success('Harap pilih tipe layanan pengiriman');
- // } else {
- // toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
- // }
- // };
- // if (selectedCarrier != 0 && selectedCarrier != 1 && totalWeight > 0) {
- // loadServiceRajaOngkir();
- // } else {
- // setListServiceExpedisi();
- // setBiayaKirim(0);
- // setselectedExpedisiService();
- // setEtd();
- // }
- // }, [selectedCarrier, selectedAddress, totalWeight]);
-
- // useEffect(() => {
- // if (selectedServiceType) {
- // let serviceType = selectedServiceType.split(',');
- // setBiayaKirim(serviceType[0]);
- // setselectedExpedisiService(serviceType[1]);
- // setEtd(serviceType[2]);
- // }
- // }, [selectedServiceType]);
-
- // useEffect(() => {
- // if (etd) setEtdFix(calculateEstimatedArrival(etd));
- // }, [etd]);
-
- // useEffect(() => {
- // if (selectedExpedisi) {
- // let serviceType = selectedExpedisi.split(',');
- // if (serviceType[0] === 0) return;
-
- // setselectedCarrier(serviceType[0]);
- // setselectedCarrierId(serviceType[1]);
- // setListServiceExpedisi([]);
- // }
- // }, [selectedExpedisi]);
-
const poNumber = useRef(null);
const poFile = useRef(null);
--
cgit v1.2.3
From f88f457fd1b91298ea8a7f9f396e49660a81e276 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Mon, 17 Mar 2025 09:06:47 +0700
Subject: handle bug service type kurir
---
src/lib/checkout/components/Checkout.jsx | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index d5c370bf..fa8d8aea 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -71,7 +71,10 @@ const Checkout = () => {
source: query,
voucher: activeVoucher,
voucher_shipping: activeVoucherShipping,
- })
+ }),
+ {
+ keepPreviousData: true, // Menjaga data sebelumnya sampai data baru tersedia
+ }
);
const {
@@ -205,6 +208,7 @@ const Checkout = () => {
SetFindVoucher(1);
return;
}
+
dataVoucher.forEach((addNewLine) => {
if (addNewLine.applyType !== 'shipping') {
@@ -410,8 +414,6 @@ const Checkout = () => {
if (poNumber.current.value) data.po_number = poNumber.current.value;
if (typeof file !== 'undefined') data.po_file = await getFileBase64(file);
- console.log('ini data', data);
-
const isCheckouted = await checkoutApi({ data });
if (!isCheckouted?.id) {
--
cgit v1.2.3
From 815ff154cde6da4a0dcf0831ad3521cfd67e0340 Mon Sep 17 00:00:00 2001
From: Miqdad
Date: Sun, 1 Jun 2025 19:31:50 +0700
Subject: fix hasflashsale error checkout page
---
src/lib/checkout/components/Checkout.jsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 0b386c30..8c80640a 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -174,8 +174,8 @@ const Checkout = () => {
const {
checkWeigth,
setCheckWeight,
- hasFlashSale,
- setHasFlashSale,
+ // hasFlashSale,
+ // setHasFlashSale,
checkoutValidation,
setCheckoutValidation,
biayaKirim,
--
cgit v1.2.3
From ffc18f479e3eef4c4e2608141238f83ca5fa79f4 Mon Sep 17 00:00:00 2001
From: Miqdad
Date: Sun, 1 Jun 2025 20:11:57 +0700
Subject: fix estimated arrival days start NaN
---
src/lib/checkout/components/Checkout.jsx | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 8c80640a..77053d1c 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -566,8 +566,15 @@ const Checkout = () => {
order_line: JSON.stringify(productOrder),
delivery_amount: biayaKirim,
carrier_id: selectedCourierId,
- estimated_arrival_days_start : parseInt(eta_courier_start) + parseInt(productSla),
- estimated_arrival_days: parseInt(eta_courier) + parseInt(productSla),
+ // estimated_arrival_days_start : parseInt(eta_courier_start) + parseInt(productSla),
+ // estimated_arrival_days: parseInt(eta_courier) + parseInt(productSla),
+ // If NaN conver to 0 (int)
+ estimated_arrival_days_start: (isNaN(parseInt(eta_courier_start)) ? 0 : parseInt(eta_courier_start)) +
+ (isNaN(parseInt(productSla)) ? 0 : parseInt(productSla)),
+
+ estimated_arrival_days: (isNaN(parseInt(eta_courier)) ? 0 : parseInt(eta_courier)) +
+ (isNaN(parseInt(productSla)) ? 0 : parseInt(productSla)),
+
delivery_service_type: selectedService?.service_type,
// New release
// carrier_id: selectedCarrierId,
--
cgit v1.2.3
From 43bed6bf9ebe559e32e7572ea17278b5f3b0897c Mon Sep 17 00:00:00 2001
From: Miqdad
Date: Wed, 11 Jun 2025 16:31:35 +0700
Subject: fix checkout
---
src/lib/checkout/components/Checkout.jsx | 416 ++++++++++++-------------------
1 file changed, 154 insertions(+), 262 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 0dc025f5..f6889558 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -28,15 +28,10 @@ import getFileBase64 from '@/core/utils/getFileBase64';
import { gtagPurchase } from '@/core/utils/googleTag';
import whatsappUrl from '@/core/utils/whatsappUrl';
import addressesApi from '@/lib/address/api/addressesApi';
-import { MapPinIcon } from 'lucide-react';
import CartItem from '~/modules/cart/components/Item.tsx';
import ExpedisiList from '../api/ExpedisiList';
import { findVoucher, getVoucher, getVoucherNew } from '../api/getVoucher';
-import { useAddress } from '../stores/useAdress';
-import SectionExpedition from './SectionExpedition';
-import { useCheckout } from '../stores/stateCheckout';
-import { formatShipmentRange, getToDate } from '../utils/functionCheckouit';
const SELF_PICKUP_ID = 32;
const { checkoutApi } = require('../api/checkoutApi');
@@ -73,28 +68,14 @@ const Checkout = () => {
source: query,
voucher: activeVoucher,
voucher_shipping: activeVoucherShipping,
- }),
- //biteship
- {
- keepPreviousData: true, // Menjaga data sebelumnya sampai data baru tersedia
- }
+ })
);
- // const [selectedAddress, setSelectedAddress] = useState({
- // shipping: null,
- // invoicing: null,
- // });
- // const [addresses, setAddresses] = useState(null);
-
- const {
- selectedAddress,
- setSelectedAddress,
- addresses,
- setAddresses,
- setAddressMaps,
- setCoordinate,
- setPostalCode,
- } = useAddress();
+ const [selectedAddress, setSelectedAddress] = useState({
+ shipping: null,
+ invoicing: null,
+ });
+ const [addresses, setAddresses] = useState(null);
useEffect(() => {
if (!auth) return;
@@ -124,37 +105,26 @@ const Checkout = () => {
return addresses[0];
};
- let ship = matchAddress('shipping');
-
setSelectedAddress({
shipping: matchAddress('shipping'),
invoicing: matchAddress('invoicing'),
});
- setPostalCode(ship?.zip);
- if (ship?.addressMap) {
- setAddressMaps(ship?.addressMap);
- setCoordinate({
- destination_latitude: ship?.latitude,
- destination_longitude: ship?.longtitude,
- });
- }
}, [addresses]);
- // const [products, setProducts] = useState(null);
+ const [products, setProducts] = useState(null);
const [totalWeight, setTotalWeight] = useState(0);
const [priceCheck, setPriceCheck] = useState(false);
- // const [listExpedisi, setExpedisi] = useState([]);
+ const [listExpedisi, setExpedisi] = useState([]);
const [listserviceExpedisi, setListServiceExpedisi] = useState([]);
const [selectedExpedisi, setSelectedExpedisi] = useState(0);
const [selectedCarrierId, setselectedCarrierId] = useState(0);
const [selectedCarrier, setselectedCarrier] = useState(0);
- //new release
- // const [biayaKirim, setBiayaKirim] = useState(0);
- // const [checkWeigth, setCheckWeight] = useState(false);
+ const [biayaKirim, setBiayaKirim] = useState(0);
+ const [checkWeigth, setCheckWeight] = useState(false);
const [selectedServiceType, setSelectedServiceType] = useState(null);
const [selectedExpedisiService, setselectedExpedisiService] = useState(null);
- // const [etd, setEtd] = useState(null);
- // const [etdFix, setEtdFix] = useState(null);
+ const [etd, setEtd] = useState(null);
+ const [etdFix, setEtdFix] = useState(null);
const [bottomPopup, SetBottomPopup] = useState(null);
const [bottomPopupTnC, SetBottomPopupTnC] = useState(null);
const [itemTnC, setItemTnC] = useState(null);
@@ -165,31 +135,12 @@ const Checkout = () => {
const [findCodeVoucher, SetFindVoucher] = useState(null);
const [selisihHargaCode, SetSelisihHargaCode] = useState(null);
const [buttonTerapkan, SetButtonTerapkan] = useState(false);
- // const [checkoutValidation, setCheckoutValidation] = useState(false);
+ const [checkoutValidation, setCheckoutValidation] = useState(false);
const [loadingVoucher, setLoadingVoucher] = useState(true);
const [loadingRajaOngkir, setLoadingRajaOngkir] = useState(false);
const [grandTotal, setGrandTotal] = useState(0);
const [hasFlashSale, setHasFlashSale] = useState(false);
- const {
- checkWeigth,
- setCheckWeight,
- // hasFlashSale,
- // setHasFlashSale,
- checkoutValidation,
- setCheckoutValidation,
- biayaKirim,
- products,
- setProducts,
- etd,
- unit,
- selectedCourier,
- selectedCourierId,
- selectedService,
- listExpedisi,
- setExpedisi,
- productSla
- } = useCheckout();
const expedisiValidation = useRef(null);
const voucher = async () => {
@@ -253,7 +204,6 @@ const Checkout = () => {
return;
}
-
dataVoucher.forEach((addNewLine) => {
if (addNewLine.applyType !== 'shipping') {
// Mencari voucher dalam listVouchers
@@ -346,7 +296,6 @@ const Checkout = () => {
value: expedisi.id,
label: expedisi.name,
carrierId: expedisi.deliveryCarrierId,
- logo: expedisi.image,
}));
setExpedisi(dataExpedisi);
};
@@ -363,38 +312,38 @@ const Checkout = () => {
};
}, []);
- // const hitungDiscountVoucher = (code, source) => {
- // let countDiscount = 0;
- // if (source === 'voucher') {
- // let dataVoucherIndex = listVouchers.findIndex(
- // (voucher) => voucher.code == code
- // );
- // let dataActiveVoucher = listVouchers[dataVoucherIndex];
- //
- // countDiscount = dataActiveVoucher.discountVoucher;
- // } else {
- // let dataVoucherIndex = listVoucherShippings.findIndex(
- // (voucher) => voucher.code == code
- // );
- // let dataActiveVoucher = listVoucherShippings[dataVoucherIndex];
- //
- // countDiscount = dataActiveVoucher.discountVoucher;
- // }
- //
- // /*if (dataActiveVoucher.discountType === 'percentage') {
- // countDiscount = cartCheckout?.subtotal * (dataActiveVoucher.discountAmount / 100)
- // if (
- // dataActiveVoucher.maxDiscountAmount > 0 &&
- // countDiscount > dataActiveVoucher.maxDiscountAmount
- // ) {
- // countDiscount = dataActiveVoucher.maxDiscountAmount
- // }
- // } else {
- // countDiscount = dataActiveVoucher.discountAmount
- // }*/
- //
- // return countDiscount;
- // };
+ const hitungDiscountVoucher = (code, source) => {
+ let countDiscount = 0;
+ if (source === 'voucher') {
+ let dataVoucherIndex = listVouchers.findIndex(
+ (voucher) => voucher.code == code
+ );
+ let dataActiveVoucher = listVouchers[dataVoucherIndex];
+
+ countDiscount = dataActiveVoucher.discountVoucher;
+ } else {
+ let dataVoucherIndex = listVoucherShippings.findIndex(
+ (voucher) => voucher.code == code
+ );
+ let dataActiveVoucher = listVoucherShippings[dataVoucherIndex];
+
+ countDiscount = dataActiveVoucher.discountVoucher;
+ }
+
+ /*if (dataActiveVoucher.discountType === 'percentage') {
+ countDiscount = cartCheckout?.subtotal * (dataActiveVoucher.discountAmount / 100)
+ if (
+ dataActiveVoucher.maxDiscountAmount > 0 &&
+ countDiscount > dataActiveVoucher.maxDiscountAmount
+ ) {
+ countDiscount = dataActiveVoucher.maxDiscountAmount
+ }
+ } else {
+ countDiscount = dataActiveVoucher.discountAmount
+ }*/
+
+ return countDiscount;
+ };
// useEffect(() => {
// if (!listVouchers) return;
@@ -432,71 +381,70 @@ const Checkout = () => {
setHasFlashSale(hasFlashSale);
}, [cartCheckout]);
- // useEffect(() => {
- // setCheckoutValidation(false);
- // const loadServiceRajaOngkir = async () => {
- // setLoadingRajaOngkir(true);
- // const body = {
- // origin: 2127,
- // destination: selectedAddress.shipping.rajaongkirCityId,
- // weight: totalWeight,
- // courier: selectedCarrier,
- // originType: 'subdistrict',
- // destinationType: 'subdistrict',
- // };
- // setBiayaKirim(0);
- // const dataService = await axios(
- // '/api/rajaongkir-service?body=' + JSON.stringify(body)
- // );
- // setLoadingRajaOngkir(false);
- // setListServiceExpedisi(dataService.data[0].costs);
- // if (dataService.data[0].costs[0]) {
- // setBiayaKirim(dataService.data[0].costs[0]?.cost[0].value);
- // setselectedExpedisiService(
- // dataService.data[0].costs[0]?.description +
- // '-' +
- // dataService.data[0].costs[0]?.service
- // );
- // setEtd(dataService.data[0].costs[0]?.cost[0].etd);
- // toast.success('Harap pilih tipe layanan pengiriman');
- // } else {
- // toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
- // }
- // };
- // if (selectedCarrier != 0 && selectedCarrier != 1 && totalWeight > 0) {
- // loadServiceRajaOngkir();
- // } else {
- // setListServiceExpedisi();
- // setBiayaKirim(0);
- // setselectedExpedisiService();
- // setEtd();
- // }
- // }, [selectedCarrier, selectedAddress, totalWeight]);
- //
- // useEffect(() => {
- // if (selectedServiceType) {
- // let serviceType = selectedServiceType.split(',');
- // setBiayaKirim(serviceType[0]);
- // setselectedExpedisiService(serviceType[1]);
- // setEtd(serviceType[2]);
- // }
- // }, [selectedServiceType]);
- //
- // useEffect(() => {
- // if (etd) setEtdFix(calculateEstimatedArrival(etd));
- // }, [etd]);
- //
- // useEffect(() => {
- // if (selectedExpedisi) {
- // let serviceType = selectedExpedisi.split(',');
- // if (serviceType[0] === 0) return;
- //
- // setselectedCarrier(serviceType[0]);
- // setselectedCarrierId(serviceType[1]);
- // setListServiceExpedisi([]);
- // }
- // }, [selectedExpedisi]);
- //
+ useEffect(() => {
+ setCheckoutValidation(false);
+ const loadServiceRajaOngkir = async () => {
+ setLoadingRajaOngkir(true);
+ const body = {
+ origin: 2127,
+ destination: selectedAddress.shipping.rajaongkirCityId,
+ weight: totalWeight,
+ courier: selectedCarrier,
+ originType: 'subdistrict',
+ destinationType: 'subdistrict',
+ };
+ setBiayaKirim(0);
+ const dataService = await axios(
+ '/api/rajaongkir-service?body=' + JSON.stringify(body)
+ );
+ setLoadingRajaOngkir(false);
+ setListServiceExpedisi(dataService.data[0].costs);
+ if (dataService.data[0].costs[0]) {
+ setBiayaKirim(dataService.data[0].costs[0]?.cost[0].value);
+ setselectedExpedisiService(
+ dataService.data[0].costs[0]?.description +
+ '-' +
+ dataService.data[0].costs[0]?.service
+ );
+ setEtd(dataService.data[0].costs[0]?.cost[0].etd);
+ toast.success('Harap pilih tipe layanan pengiriman');
+ } else {
+ toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
+ }
+ };
+ if (selectedCarrier != 0 && selectedCarrier != 1 && totalWeight > 0) {
+ loadServiceRajaOngkir();
+ } else {
+ setListServiceExpedisi();
+ setBiayaKirim(0);
+ setselectedExpedisiService();
+ setEtd();
+ }
+ }, [selectedCarrier, selectedAddress, totalWeight]);
+
+ useEffect(() => {
+ if (selectedServiceType) {
+ let serviceType = selectedServiceType.split(',');
+ setBiayaKirim(serviceType[0]);
+ setselectedExpedisiService(serviceType[1]);
+ setEtd(serviceType[2]);
+ }
+ }, [selectedServiceType]);
+
+ useEffect(() => {
+ if (etd) setEtdFix(calculateEstimatedArrival(etd));
+ }, [etd]);
+
+ useEffect(() => {
+ if (selectedExpedisi) {
+ let serviceType = selectedExpedisi.split(',');
+ if (serviceType[0] === 0) return;
+
+ setselectedCarrier(serviceType[0]);
+ setselectedCarrierId(serviceType[1]);
+ setListServiceExpedisi([]);
+ }
+ }, [selectedExpedisi]);
const poNumber = useRef(null);
const poFile = useRef(null);
@@ -524,7 +472,7 @@ const Checkout = () => {
});
return;
}
- if (selectedCourier === 0 || !selectedCourier) {
+ if (selectedExpedisi === 0) {
setCheckoutValidation(true);
if (expedisiValidation.current) {
const position = expedisiValidation.current.getBoundingClientRect();
@@ -535,20 +483,7 @@ const Checkout = () => {
}
return;
}
- //new release
- // if (!selectedService) {
- toast.error('Harap pilih tipe layanan pengiriman');
- return;
- }
- if (selectedCourier != 1 && biayaKirim == 0) {
- // toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
- // return;
- // }
- // if (!selectedService) {
- // toast.error('Harap pilih tipe layanan pengiriman');
- // return;
- // }
- if (selectedCourier != 1 && biayaKirim == 0) {
+ if (selectedCarrier != 1 && biayaKirim == 0) {
toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
return;
}
@@ -558,39 +493,23 @@ const Checkout = () => {
quantity: product.quantity,
available_quantity: product?.availableQuantity,
}));
- let estimated_courier = etd.split('-').map(Number);
- let eta_courier = Math.max(...estimated_courier);
- let eta_courier_start = Math.min(...estimated_courier);
-
let data = {
- // partner_shipping_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,
- carrier_id: selectedCourierId,
- // estimated_arrival_days_start : parseInt(eta_courier_start) + parseInt(productSla),
- // estimated_arrival_days: parseInt(eta_courier) + parseInt(productSla),
- // If NaN conver to 0 (int)
- estimated_arrival_days_start: (isNaN(parseInt(eta_courier_start)) ? 0 : parseInt(eta_courier_start)) +
- (isNaN(parseInt(productSla)) ? 0 : parseInt(productSla)),
-
- estimated_arrival_days: (isNaN(parseInt(eta_courier)) ? 0 : parseInt(eta_courier)) +
- (isNaN(parseInt(productSla)) ? 0 : parseInt(productSla)),
-
- delivery_service_type: selectedService?.service_type,
- // New release
- // carrier_id: selectedCourierId,
- estimated_arrival_days_start : parseInt(eta_courier_start) + parseInt(productSla),
- // estimated_arrival_days: parseInt(eta_courier) + parseInt(productSla),
- // delivery_service_type: selectedService?.service_type,
+ carrier_id: selectedCarrierId,
+ estimated_arrival_days: splitDuration(etd),
+ delivery_service_type: selectedExpedisiService,
flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false
voucher: activeVoucher,
voucher_shipping: activeVoucherShipping,
type: 'sale_order',
};
+
if (query) {
data.source = 'buy';
}
@@ -598,8 +517,8 @@ const Checkout = () => {
if (typeof file == 'undefined') {
toast.error(
'Nomor PO ' +
- poNumber.current.value +
- ' telah dimasukkan, Harap upload file PO yang dimaksud'
+ poNumber.current.value +
+ ' telah dimasukkan, Harap upload file PO yang dimaksud'
);
setIsLoading(false);
return;
@@ -1240,22 +1159,21 @@ const Checkout = () => {
)}
-
- {/*new-relase*/}
- {/**/}
- {/* */}
- {/* */}
+
+
+
+
{!!products &&
@@ -1344,10 +1262,7 @@ const Checkout = () => {
- Biaya Kirim{' '}
-
- {formatShipmentRange(etd, unit, productSla)}
-
+ Biaya Kirim
{etdFix}
{currencyFormat(
@@ -1471,8 +1386,7 @@ const Checkout = () => {
className='flex-1 btn-yellow'
onClick={checkout}
disabled={
- //new release
- // isLoading ||
+ isLoading ||
!products ||
products?.length == 0 ||
priceCheck ||
@@ -1544,10 +1458,9 @@ const Checkout = () => {
/>
)}
- {products &&
}
-
- {/*
+
{
*/}
+ />
Detail Pesanan
@@ -1656,9 +1569,7 @@ const Checkout = () => {
Biaya Kirim
-
- {formatShipmentRange(etd, unit, productSla)}
-
+
{etdFix}
{currencyFormat(
@@ -1780,8 +1691,7 @@ const Checkout = () => {
className='w-full btn-yellow mt-4'
onClick={checkout}
disabled={
- // new-relase
- // isLoading ||
+ isLoading ||
!products ||
products?.length == 0 ||
priceCheck ||
@@ -1830,32 +1740,14 @@ const SectionAddress = ({ address, label, url }) => (
{address.street}, {address?.city?.name}
-
-
- {address.addressMap ? (
-
- ) : (
-
-
-
- )}
-
)}
);
const SectionValidation = ({ address }) =>
- //new release
- // address?.stateId == 0 ||
- // (address?.rajaongkirCityId == 0 && (
- address?.stateId == 0 && (
+ address?.stateId == 0 ||
+ (address?.rajaongkirCityId == 0 && (
Mohon untuk memperbarui alamat Anda dengan mengklik tombol di bawah ini.{' '}
@@ -1869,17 +1761,17 @@ const SectionValidation = ({ address }) =>
- );
+ ));
const SectionExpedisi = ({
- address,
- listExpedisi,
- setSelectedExpedisi,
- checkWeigth,
- checkoutValidation,
- expedisiValidation,
- loadingRajaOngkir,
-}) =>
+ address,
+ listExpedisi,
+ setSelectedExpedisi,
+ checkWeigth,
+ checkoutValidation,
+ expedisiValidation,
+ loadingRajaOngkir,
+ }) =>
address?.rajaongkirCityId > 0 && (
@@ -1931,9 +1823,9 @@ const SectionExpedisi = ({
)}
{checkWeigth == true && (
--
cgit v1.2.3
From 337e7a189efacbe696f4512130278952977b2da2 Mon Sep 17 00:00:00 2001
From: Miqdad
Date: Wed, 11 Jun 2025 16:37:19 +0700
Subject: fix checkout
---
src/lib/checkout/components/Checkout.jsx | 327 ++++++++++---------------------
1 file changed, 105 insertions(+), 222 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index f6889558..668c7ac0 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -28,9 +28,14 @@ import getFileBase64 from '@/core/utils/getFileBase64';
import { gtagPurchase } from '@/core/utils/googleTag';
import whatsappUrl from '@/core/utils/whatsappUrl';
import addressesApi from '@/lib/address/api/addressesApi';
+import { MapPinIcon } from 'lucide-react';
import CartItem from '~/modules/cart/components/Item.tsx';
import ExpedisiList from '../api/ExpedisiList';
-import { findVoucher, getVoucher, getVoucherNew } from '../api/getVoucher';
+import { getVoucher } from '../api/getVoucher';
+import { useAddress } from '../stores/useAdress';
+import SectionExpedition from './SectionExpedition';
+import { useCheckout } from '../stores/stateCheckout';
+import { formatShipmentRange, getToDate } from '../utils/functionCheckouit';
const SELF_PICKUP_ID = 32;
@@ -50,9 +55,7 @@ function convertToInternational(number) {
}
const Checkout = () => {
- const PPN = process.env.NEXT_PUBLIC_PPN
- ? parseFloat(process.env.NEXT_PUBLIC_PPN)
- : 0;
+ const PPN = process.env.NEXT_PUBLIC_PPN ? parseFloat(process.env.NEXT_PUBLIC_PPN) : 0;
const router = useRouter();
const query = router.query.source ?? null;
const qVoucher = router.query.voucher ?? null;
@@ -68,14 +71,21 @@ const Checkout = () => {
source: query,
voucher: activeVoucher,
voucher_shipping: activeVoucherShipping,
- })
+ }),
+ {
+ keepPreviousData: true, // Menjaga data sebelumnya sampai data baru tersedia
+ }
);
- const [selectedAddress, setSelectedAddress] = useState({
- shipping: null,
- invoicing: null,
- });
- const [addresses, setAddresses] = useState(null);
+ const {
+ selectedAddress,
+ setSelectedAddress,
+ addresses,
+ setAddresses,
+ setAddressMaps,
+ setCoordinate,
+ setPostalCode,
+ } = useAddress();
useEffect(() => {
if (!auth) return;
@@ -105,26 +115,32 @@ const Checkout = () => {
return addresses[0];
};
+ let ship = matchAddress('shipping');
+
setSelectedAddress({
shipping: matchAddress('shipping'),
invoicing: matchAddress('invoicing'),
});
+ setPostalCode(ship?.zip);
+ if (ship?.addressMap) {
+ setAddressMaps(ship?.addressMap);
+ setCoordinate({
+ destination_latitude: ship?.latitude,
+ destination_longitude: ship?.longtitude,
+ });
+ }
}, [addresses]);
- const [products, setProducts] = useState(null);
const [totalWeight, setTotalWeight] = useState(0);
const [priceCheck, setPriceCheck] = useState(false);
- const [listExpedisi, setExpedisi] = useState([]);
const [listserviceExpedisi, setListServiceExpedisi] = useState([]);
const [selectedExpedisi, setSelectedExpedisi] = useState(0);
const [selectedCarrierId, setselectedCarrierId] = useState(0);
const [selectedCarrier, setselectedCarrier] = useState(0);
- const [biayaKirim, setBiayaKirim] = useState(0);
- const [checkWeigth, setCheckWeight] = useState(false);
const [selectedServiceType, setSelectedServiceType] = useState(null);
const [selectedExpedisiService, setselectedExpedisiService] = useState(null);
- const [etd, setEtd] = useState(null);
- const [etdFix, setEtdFix] = useState(null);
+ // const [etd, setEtd] = useState(null);
+ // const [etdFix, setEtdFix] = useState(null);
const [bottomPopup, SetBottomPopup] = useState(null);
const [bottomPopupTnC, SetBottomPopupTnC] = useState(null);
const [itemTnC, setItemTnC] = useState(null);
@@ -135,11 +151,29 @@ const Checkout = () => {
const [findCodeVoucher, SetFindVoucher] = useState(null);
const [selisihHargaCode, SetSelisihHargaCode] = useState(null);
const [buttonTerapkan, SetButtonTerapkan] = useState(false);
- const [checkoutValidation, setCheckoutValidation] = useState(false);
const [loadingVoucher, setLoadingVoucher] = useState(true);
const [loadingRajaOngkir, setLoadingRajaOngkir] = useState(false);
const [grandTotal, setGrandTotal] = useState(0);
- const [hasFlashSale, setHasFlashSale] = useState(false);
+
+ const {
+ checkWeigth,
+ setCheckWeight,
+ hasFlashSale,
+ setHasFlashSale,
+ checkoutValidation,
+ setCheckoutValidation,
+ biayaKirim,
+ products,
+ setProducts,
+ etd,
+ unit,
+ selectedCourier,
+ selectedCourierId,
+ selectedService,
+ listExpedisi,
+ setExpedisi,
+ productSla
+ } = useCheckout();
const expedisiValidation = useRef(null);
@@ -147,31 +181,16 @@ const Checkout = () => {
if (!listVouchers) {
try {
setLoadingVoucher(true);
- const productCategories = products
- ?.reduce((categories, product) => {
- if (product.categories && Array.isArray(product.categories)) {
- product.categories.forEach((category) => {
- if (category.id && !categories.includes(category.id)) {
- categories.push(category.id);
- }
- });
- }
- return categories;
- }, [])
- .join(',');
-
let dataVoucher = await getVoucher(auth?.id, {
source: query,
type: 'all,brand',
- partner_id: auth?.partnerId,
- voucher_category: productCategories, // Add the product categories
+ partner_id : auth?.partnerId,
});
SetListVoucher(dataVoucher);
let dataVoucherShipping = await getVoucher(auth?.id, {
source: query,
type: 'shipping',
- voucher_category: productCategories, // Add the product categories
});
SetListVoucherShipping(dataVoucherShipping);
} finally {
@@ -181,29 +200,17 @@ const Checkout = () => {
};
const VoucherCode = async (code) => {
- const productCategories = products
- ?.reduce((categories, product) => {
- if (product.categories && Array.isArray(product.categories)) {
- product.categories.forEach((category) => {
- if (category.id && !categories.includes(category.id)) {
- categories.push(category.id);
- }
- });
- }
- return categories;
- }, [])
- .join(',');
-
+ // let dataVoucher = await findVoucher(code, auth.id, query);
let dataVoucher = await getVoucher(auth?.id, {
source: query,
code: code,
- voucher_category: productCategories, // Add the product categories
});
if (dataVoucher.length <= 0) {
SetFindVoucher(1);
return;
}
+
dataVoucher.forEach((addNewLine) => {
if (addNewLine.applyType !== 'shipping') {
// Mencari voucher dalam listVouchers
@@ -296,6 +303,7 @@ const Checkout = () => {
value: expedisi.id,
label: expedisi.name,
carrierId: expedisi.deliveryCarrierId,
+ logo: expedisi.image,
}));
setExpedisi(dataExpedisi);
};
@@ -312,58 +320,6 @@ const Checkout = () => {
};
}, []);
- const hitungDiscountVoucher = (code, source) => {
- let countDiscount = 0;
- if (source === 'voucher') {
- let dataVoucherIndex = listVouchers.findIndex(
- (voucher) => voucher.code == code
- );
- let dataActiveVoucher = listVouchers[dataVoucherIndex];
-
- countDiscount = dataActiveVoucher.discountVoucher;
- } else {
- let dataVoucherIndex = listVoucherShippings.findIndex(
- (voucher) => voucher.code == code
- );
- let dataActiveVoucher = listVoucherShippings[dataVoucherIndex];
-
- countDiscount = dataActiveVoucher.discountVoucher;
- }
-
- /*if (dataActiveVoucher.discountType === 'percentage') {
- countDiscount = cartCheckout?.subtotal * (dataActiveVoucher.discountAmount / 100)
- if (
- dataActiveVoucher.maxDiscountAmount > 0 &&
- countDiscount > dataActiveVoucher.maxDiscountAmount
- ) {
- countDiscount = dataActiveVoucher.maxDiscountAmount
- }
- } else {
- countDiscount = dataActiveVoucher.discountAmount
- }*/
-
- return countDiscount;
- };
-
- // useEffect(() => {
- // if (!listVouchers) return;
- // if (!activeVoucher) return;
-
- // console.log('voucher')
- // const countDiscount = hitungDiscountVoucher(activeVoucher, 'voucher');
-
- // SetDiscountVoucher(countDiscount);
- // }, [activeVoucher, listVouchers]);
-
- // useEffect(() => {
- // if (!listVoucherShippings) return;
- // if (!activeVoucherShipping) return;
-
- // const countDiscount = hitungDiscountVoucher(activeVoucherShipping, 'voucher_shipping');
-
- // SetDiscountVoucherOngkir(countDiscount);
- // }, [activeVoucherShipping, listVoucherShippings]);
-
useEffect(() => {
if (qVoucher === 'PASTIHEMAT' && listVouchers) {
let code = qVoucher;
@@ -381,71 +337,6 @@ const Checkout = () => {
setHasFlashSale(hasFlashSale);
}, [cartCheckout]);
- useEffect(() => {
- setCheckoutValidation(false);
- const loadServiceRajaOngkir = async () => {
- setLoadingRajaOngkir(true);
- const body = {
- origin: 2127,
- destination: selectedAddress.shipping.rajaongkirCityId,
- weight: totalWeight,
- courier: selectedCarrier,
- originType: 'subdistrict',
- destinationType: 'subdistrict',
- };
- setBiayaKirim(0);
- const dataService = await axios(
- '/api/rajaongkir-service?body=' + JSON.stringify(body)
- );
- setLoadingRajaOngkir(false);
- setListServiceExpedisi(dataService.data[0].costs);
- if (dataService.data[0].costs[0]) {
- setBiayaKirim(dataService.data[0].costs[0]?.cost[0].value);
- setselectedExpedisiService(
- dataService.data[0].costs[0]?.description +
- '-' +
- dataService.data[0].costs[0]?.service
- );
- setEtd(dataService.data[0].costs[0]?.cost[0].etd);
- toast.success('Harap pilih tipe layanan pengiriman');
- } else {
- toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
- }
- };
- if (selectedCarrier != 0 && selectedCarrier != 1 && totalWeight > 0) {
- loadServiceRajaOngkir();
- } else {
- setListServiceExpedisi();
- setBiayaKirim(0);
- setselectedExpedisiService();
- setEtd();
- }
- }, [selectedCarrier, selectedAddress, totalWeight]);
-
- useEffect(() => {
- if (selectedServiceType) {
- let serviceType = selectedServiceType.split(',');
- setBiayaKirim(serviceType[0]);
- setselectedExpedisiService(serviceType[1]);
- setEtd(serviceType[2]);
- }
- }, [selectedServiceType]);
-
- useEffect(() => {
- if (etd) setEtdFix(calculateEstimatedArrival(etd));
- }, [etd]);
-
- useEffect(() => {
- if (selectedExpedisi) {
- let serviceType = selectedExpedisi.split(',');
- if (serviceType[0] === 0) return;
-
- setselectedCarrier(serviceType[0]);
- setselectedCarrierId(serviceType[1]);
- setListServiceExpedisi([]);
- }
- }, [selectedExpedisi]);
-
const poNumber = useRef(null);
const poFile = useRef(null);
@@ -472,7 +363,7 @@ const Checkout = () => {
});
return;
}
- if (selectedExpedisi === 0) {
+ if (selectedCourier === 0 || !selectedCourier) {
setCheckoutValidation(true);
if (expedisiValidation.current) {
const position = expedisiValidation.current.getBoundingClientRect();
@@ -483,7 +374,11 @@ const Checkout = () => {
}
return;
}
- if (selectedCarrier != 1 && biayaKirim == 0) {
+ if (!selectedService) {
+ toast.error('Harap pilih tipe layanan pengiriman');
+ return;
+ }
+ if (selectedCourier != 1 && biayaKirim == 0) {
toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
return;
}
@@ -493,23 +388,27 @@ const Checkout = () => {
quantity: product.quantity,
available_quantity: product?.availableQuantity,
}));
+ let estimated_courier = etd.split('-').map(Number);
+ let eta_courier = Math.max(...estimated_courier);
+ let eta_courier_start = Math.min(...estimated_courier);
+
let data = {
- // partner_shipping_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,
- carrier_id: selectedCarrierId,
- estimated_arrival_days: splitDuration(etd),
- delivery_service_type: selectedExpedisiService,
+ carrier_id: selectedCourierId,
+ estimated_arrival_days_start : parseInt(eta_courier_start) + parseInt(productSla),
+ estimated_arrival_days: parseInt(eta_courier) + parseInt(productSla),
+ delivery_service_type: selectedService?.service_type,
flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false
voucher: activeVoucher,
voucher_shipping: activeVoucherShipping,
type: 'sale_order',
};
-
if (query) {
data.source = 'buy';
}
@@ -570,24 +469,6 @@ const Checkout = () => {
)}`;
}
}
-
- /* const midtrans = async () => {
- for (const product of products) deleteItemCart({ productId: product.id });
- if (grandTotal > 0) {
- const payment = await axios.post(
- `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}`
- );
- setIsLoading(false);
- window.location.href = payment.data.redirectUrl;
- } else {
- window.location.href = `${
- process.env.NEXT_PUBLIC_SELF_HOST
- }/shop/checkout/success?order_id=${isCheckouted.name.replace(
- /\//g,
- '-'
- )}`;
- }
- };*/
};
const handlingActivateCode = async () => {
@@ -761,19 +642,6 @@ const Checkout = () => {
)}
- {/* {!loadingVoucher &&
- listVouchers?.length === 1 &&
- listVoucherShippings?.length === 1}
- {
-
-
-
Tidak ada voucher tersedia
-
- Maaf, saat ini tidak ada voucher yang tersedia.
-
-
-
- } */}
{listVoucherShippings && listVoucherShippings?.length > 0 && (
@@ -1159,8 +1027,8 @@ const Checkout = () => {
)}
-
-
+ {/*
{
+ /> */}
{!!products &&
@@ -1255,14 +1123,15 @@ const Checkout = () => {
{currencyFormat(cartCheckout?.subtotal)}
-
- PPN {((PPN - 1) * 100).toFixed(0)}%
-
+
PPN {((PPN - 1) * 100).toFixed(0)}%
{currencyFormat(cartCheckout?.tax)}
- Biaya Kirim
{etdFix}
+ Biaya Kirim{' '}
+
+ {formatShipmentRange(etd, unit, productSla)}
+
{currencyFormat(
@@ -1386,7 +1255,6 @@ const Checkout = () => {
className='flex-1 btn-yellow'
onClick={checkout}
disabled={
- isLoading ||
!products ||
products?.length == 0 ||
priceCheck ||
@@ -1458,9 +1326,10 @@ const Checkout = () => {
/>
)}
+ {products &&
}
-
-
+ {/*
{
+ /> */}
Detail Pesanan
@@ -1561,15 +1430,15 @@ const Checkout = () => {
{currencyFormat(cartCheckout?.subtotal)}
-
- PPN {((PPN - 1) * 100).toFixed(0)}%
-
+
PPN {((PPN - 1) * 100).toFixed(0)}%
{currencyFormat(cartCheckout?.tax)}
Biaya Kirim
-
{etdFix}
+
+ {formatShipmentRange(etd, unit, productSla)}
+
{currencyFormat(
@@ -1691,7 +1560,6 @@ const Checkout = () => {
className='w-full btn-yellow mt-4'
onClick={checkout}
disabled={
- isLoading ||
!products ||
products?.length == 0 ||
priceCheck ||
@@ -1740,14 +1608,29 @@ const SectionAddress = ({ address, label, url }) => (
{address.street}, {address?.city?.name}
+
+
+ {address.addressMap ? (
+
+ ) : (
+
+
+
+ )}
+
)}
);
const SectionValidation = ({ address }) =>
- address?.stateId == 0 ||
- (address?.rajaongkirCityId == 0 && (
+ address?.stateId == 0 && (
Mohon untuk memperbarui alamat Anda dengan mengklik tombol di bawah ini.{' '}
@@ -1761,7 +1644,7 @@ const SectionValidation = ({ address }) =>
- ));
+ );
const SectionExpedisi = ({
address,
--
cgit v1.2.3
From 5754fd0a95bc72f0e97e6af2d246f4d14a45bf9f Mon Sep 17 00:00:00 2001
From: "Indoteknik ."
Date: Mon, 16 Jun 2025 11:14:28 +0700
Subject: (andri) fix self pick up checkout
---
src/lib/checkout/components/Checkout.jsx | 34 ++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 668c7ac0..aad3d66d 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -374,13 +374,17 @@ const Checkout = () => {
}
return;
}
- if (!selectedService) {
- toast.error('Harap pilih tipe layanan pengiriman');
- return;
- }
- if (selectedCourier != 1 && biayaKirim == 0) {
- toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
- return;
+ if (selectedCourierId !== SELF_PICKUP_ID) { // Menggunakan selectedCourierId karena lebih spesifik dan numerik
+ if (!selectedService) { // Jika kurir bukan Self Pickup, maka harus ada layanan yang dipilih
+ toast.error('Harap pilih tipe layanan pengiriman');
+ return;
+ }
+ // Validasi biaya kirim hanya untuk kurir selain Self Pickup (dan ID kurir 1 jika itu kasus khusus)
+ // Jika selectedCourierId adalah 1 (misalnya kurir internal yang bisa gratis), lewati validasi biayaKirim 0
+ if (selectedCourierId !== 1 && biayaKirim === 0) {
+ toast.error('Maaf, layanan tidak tersedia untuk ekspedisi ini. Mohon pilih ekspedisi lain atau layanan lain.');
+ return;
+ }
}
setIsLoading(true);
const productOrder = products.map((product) => ({
@@ -388,9 +392,19 @@ const Checkout = () => {
quantity: product.quantity,
available_quantity: product?.availableQuantity,
}));
- let estimated_courier = etd.split('-').map(Number);
- let eta_courier = Math.max(...estimated_courier);
- let eta_courier_start = Math.min(...estimated_courier);
+
+ let eta_courier = 0;
+ let eta_courier_start = 0;
+
+ if (selectedCourierId !== SELF_PICKUP_ID && etd) {
+ const estimated_courier = etd.split('-').map(Number);
+ eta_courier = Math.max(...estimated_courier);
+ eta_courier_start = Math.min(...estimated_courier);
+ }
+
+ // let estimated_courier = etd.split('-').map(Number);
+ // let eta_courier = Math.max(...estimated_courier);
+ // let eta_courier_start = Math.min(...estimated_courier);
let data = {
// partner_shipping_id: auth.partnerId,,
--
cgit v1.2.3
From 59ae628913de8dc1040cd6fb94c2e9f389cdd7d1 Mon Sep 17 00:00:00 2001
From: it-fixcomart
Date: Fri, 4 Jul 2025 15:40:05 +0700
Subject: biteship mobile belum muncul
---
src/lib/checkout/components/Checkout.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/lib/checkout/components/Checkout.jsx')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index aad3d66d..d8ede118 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -1070,7 +1070,7 @@ const Checkout = () => {
-
+ {products &&
}
Ringkasan Pesanan
--
cgit v1.2.3