summaryrefslogtreecommitdiff
path: root/src/lib/checkout/components/Checkout.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/checkout/components/Checkout.jsx')
-rw-r--r--src/lib/checkout/components/Checkout.jsx107
1 files changed, 58 insertions, 49 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index d8ede118..6cda069c 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -55,7 +55,9 @@ 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;
@@ -172,7 +174,7 @@ const Checkout = () => {
selectedService,
listExpedisi,
setExpedisi,
- productSla
+ productSla,
} = useCheckout();
const expedisiValidation = useRef(null);
@@ -184,7 +186,7 @@ const Checkout = () => {
let dataVoucher = await getVoucher(auth?.id, {
source: query,
type: 'all,brand',
- partner_id : auth?.partnerId,
+ partner_id: auth?.partnerId,
});
SetListVoucher(dataVoucher);
@@ -210,7 +212,6 @@ const Checkout = () => {
return;
}
-
dataVoucher.forEach((addNewLine) => {
if (addNewLine.applyType !== 'shipping') {
// Mencari voucher dalam listVouchers
@@ -374,17 +375,21 @@ const Checkout = () => {
}
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;
- }
+ 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) => ({
@@ -415,7 +420,8 @@ 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_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
@@ -430,8 +436,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;
@@ -1019,10 +1025,10 @@ const Checkout = () => {
</div>
)}
- {selectedCarrierId == SELF_PICKUP_ID && (
+ {selectedCourierId == SELF_PICKUP_ID && (
<PickupAddress label='Alamat Pickup' />
)}
- {selectedCarrierId != SELF_PICKUP_ID && (
+ {selectedCourierId != SELF_PICKUP_ID && (
<Skeleton
isLoaded={!!selectedAddress.invoicing && !!selectedAddress.shipping}
minHeight={320}
@@ -1137,7 +1143,9 @@ const Checkout = () => {
<div>{currencyFormat(cartCheckout?.subtotal)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
- <div className='text-gray_r-11'>PPN {((PPN - 1) * 100).toFixed(0)}%</div>
+ <div className='text-gray_r-11'>
+ PPN {((PPN - 1) * 100).toFixed(0)}%
+ </div>
<div>{currencyFormat(cartCheckout?.tax)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
@@ -1269,10 +1277,7 @@ const Checkout = () => {
className='flex-1 btn-yellow'
onClick={checkout}
disabled={
- !products ||
- products?.length == 0 ||
- priceCheck ||
- hasNoPrice
+ !products || products?.length == 0 || priceCheck || hasNoPrice || isLoading
}
>
{isLoading ? 'Loading...' : 'Lanjut Pembayaran'}
@@ -1317,16 +1322,11 @@ const Checkout = () => {
<div className='flex'>
{' '}
<div className='w-3/4 border border-gray_r-6 rounded bg-white'>
- {selectedCarrierId == SELF_PICKUP_ID && (
+ {selectedCourierId == SELF_PICKUP_ID && (
<PickupAddress label='Alamat Pickup' />
)}
- {selectedCarrierId != SELF_PICKUP_ID && (
- <Skeleton
- isLoaded={
- !!selectedAddress.invoicing && !!selectedAddress.shipping
- }
- minHeight={290}
- >
+ {selectedCourierId != SELF_PICKUP_ID && (
+ <Skeleton isLoaded minHeight={290}>
<SectionAddress
address={selectedAddress.shipping}
label='Alamat Pengiriman'
@@ -1444,7 +1444,9 @@ const Checkout = () => {
<div>{currencyFormat(cartCheckout?.subtotal)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
- <div className='text-gray_r-11'>PPN {((PPN - 1) * 100).toFixed(0)}%</div>
+ <div className='text-gray_r-11'>
+ PPN {((PPN - 1) * 100).toFixed(0)}%
+ </div>
<div>{currencyFormat(cartCheckout?.tax)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
@@ -1577,7 +1579,8 @@ const Checkout = () => {
!products ||
products?.length == 0 ||
priceCheck ||
- hasNoPrice
+ hasNoPrice ||
+ isLoading
}
>
{isLoading ? 'Loading...' : 'Lanjut Pembayaran'}
@@ -1633,8 +1636,14 @@ const SectionAddress = ({ address, label, url }) => (
{address.addressMap ? (
<label>Sudah Pinpoint</label>
) : (
- <Link href={'/my/address/' + address.id + '/edit'} target='_blank' className='cursor-pointer'>
- <label className='text-red-500 cursor-pointer '>Belum Pinpoint</label>
+ <Link
+ href={'/my/address/' + address.id + '/edit'}
+ target='_blank'
+ className='cursor-pointer'
+ >
+ <label className='text-red-500 cursor-pointer '>
+ Belum Pinpoint
+ </label>
</Link>
)}
</div>
@@ -1644,7 +1653,7 @@ const SectionAddress = ({ address, label, url }) => (
);
const SectionValidation = ({ address }) =>
- address?.stateId == 0 && (
+ address?.stateId === 0 && (
<BottomPopup active={true} title='Update Alamat'>
<div className='leading-7 text-gray_r-12/80'>
Mohon untuk memperbarui alamat Anda dengan mengklik tombol di bawah ini.{' '}
@@ -1661,14 +1670,14 @@ const SectionValidation = ({ address }) =>
);
const SectionExpedisi = ({
- address,
- listExpedisi,
- setSelectedExpedisi,
- checkWeigth,
- checkoutValidation,
- expedisiValidation,
- loadingRajaOngkir,
- }) =>
+ address,
+ listExpedisi,
+ setSelectedExpedisi,
+ checkWeigth,
+ checkoutValidation,
+ expedisiValidation,
+ loadingRajaOngkir,
+}) =>
address?.rajaongkirCityId > 0 && (
<div className='p-4' ref={expedisiValidation}>
<div className='flex justify-between items-center'>
@@ -1720,9 +1729,9 @@ const SectionExpedisi = ({
)}
</div>
<style jsx>{`
- .shake {
- animation: shake 0.4s ease-in-out;
- }
+ .shake {
+ animation: shake 0.4s ease-in-out;
+ }
`}</style>
</div>
{checkWeigth == true && (