From 585e199424fb0898eddaac4399ddbbad9fc04a35 Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadmiqdad27@gmail.com>
Date: Mon, 8 Sep 2025 17:30:13 +0700
Subject: <Miqdad> fix eror

---
 src/lib/checkout/components/Checkout.jsx | 107 +++++++++++++++++--------------
 1 file changed, 60 insertions(+), 47 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 95916b22..e21ea266 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;
@@ -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 ? 'Loading...' : 'Lanjut Pembayaran'}
@@ -1322,28 +1327,28 @@ const Checkout = () => {
               )}
               {selectedCarrierId != SELF_PICKUP_ID && (
                 <>
-                  {(!selectedAddress?.shipping || !selectedAddress?.invoicing) ? (
-                    <div className="p-4 border rounded-xl text-center text-red-600 bg-red-50">
+                  {!selectedAddress?.shipping || !selectedAddress?.invoicing ? (
+                    <div className='p-4 border rounded-xl text-center text-red-600 bg-red-50'>
                       <p>⚠️ Anda belum memiliki alamat yang terdaftar.</p>
-                      <a
-                        href="/my/address?select=shipping"
-                        className="mt-2 inline-block px-4 py-2 bg-solid-red text-white rounded-lg"
+                      <Link
+                        href='/my/address?select=shipping'
+                        className='mt-2 inline-block px-4 py-2 bg-solid-red text-white rounded-lg'
                       >
                         Tambahkan Alamat
-                      </a>
+                      </Link>
                     </div>
                   ) : (
                     <Skeleton isLoaded minHeight={290}>
                       <SectionAddress
                         address={selectedAddress.shipping}
-                        label="Alamat Pengiriman"
-                        url="/my/address?select=shipping"
+                        label='Alamat Pengiriman'
+                        url='/my/address?select=shipping'
                       />
                       <Divider />
                       <SectionAddress
                         address={selectedAddress.invoicing}
-                        label="Alamat Penagihan"
-                        url="/my/address?select=invoice"
+                        label='Alamat Penagihan'
+                        url='/my/address?select=invoice'
                       />
                     </Skeleton>
                   )}
@@ -1453,7 +1458,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'>
@@ -1643,8 +1650,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>
@@ -1671,14 +1684,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'>
@@ -1730,9 +1743,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 && (
-- 
cgit v1.2.3

