From 39b5e05a5fcc7ca26342f37e85c6585d1dacb3a5 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 5 Mar 2024 14:37:44 +0700
Subject: add address & expedisi di page quotation - template stepper approval

---
 src/lib/checkout/components/CheckoutSection.jsx | 174 +++++++++++++++---------
 1 file changed, 112 insertions(+), 62 deletions(-)

(limited to 'src/lib/checkout/components/CheckoutSection.jsx')

diff --git a/src/lib/checkout/components/CheckoutSection.jsx b/src/lib/checkout/components/CheckoutSection.jsx
index 34fe19f7..7f9ea08a 100644
--- a/src/lib/checkout/components/CheckoutSection.jsx
+++ b/src/lib/checkout/components/CheckoutSection.jsx
@@ -1,35 +1,35 @@
-import Link from "next/link";
+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 { AnimatePresence, motion } from 'framer-motion';
+import { Divider, Spinner } from '@chakra-ui/react';
 
 export const SectionAddress = ({ address, label, url }) => {
-    return (
-        <div className='p-4'>
-        <div className='flex justify-between items-center'>
-          <div className='font-medium'>{label}</div>
-          <Link className='text-caption-1' href={url}>
-            Pilih Alamat Lain
-          </Link>
-        </div>
-    
-        {address && (
-          <div className='mt-4 text-caption-1'>
-            <div className='badge-red mb-2'>
-              {address.type.charAt(0).toUpperCase() +
-                address.type.slice(1) +
-                ' Address'}
-            </div>
-            <p className='font-medium'>{address.name}</p>
-            <p className='mt-2 text-gray_r-11'>{address.mobile}</p>
-            <p className='mt-1 text-gray_r-11'>
-              {address.street}, {address?.city?.name}
-            </p>
-          </div>
-        )}
+  return (
+    <div className='p-4'>
+      <div className='flex justify-between items-center'>
+        <div className='font-medium'>{label}</div>
+        <Link className='text-caption-1' href={url}>
+          Pilih Alamat Lain
+        </Link>
       </div>
-    )
-}
+
+      {address && (
+        <div className='mt-4 text-caption-1'>
+          <div className='badge-red mb-2'>
+            {address.type.charAt(0).toUpperCase() +
+              address.type.slice(1) +
+              ' Address'}
+          </div>
+          <p className='font-medium'>{address.name}</p>
+          <p className='mt-2 text-gray_r-11'>{address.mobile}</p>
+          <p className='mt-1 text-gray_r-11'>
+            {address.street}, {address?.city?.name}
+          </p>
+        </div>
+      )}
+    </div>
+  );
+};
 
 export const SectionValidation = ({ address }) =>
   address?.rajaongkirCityId == 0 && (
@@ -129,7 +129,10 @@ export const SectionExpedisi = ({
     </div>
   );
 
-export const SectionListService = ({ listserviceExpedisi, setSelectedServiceType }) =>
+export const SectionListService = ({
+  listserviceExpedisi,
+  setSelectedServiceType,
+}) =>
   listserviceExpedisi?.length > 0 && (
     <>
       <div className='p-4'>
@@ -169,39 +172,86 @@ export const SectionListService = ({ listserviceExpedisi, setSelectedServiceType
     </>
   );
 
-  export const PickupAddress = ({ label }) => (
-    <div className='p-4'>
-      <div className='flex justify-between items-center'>
-        <div className='font-medium'>{label}</div>
-      </div>
-      <div className='mt-4 text-caption-1'>
-        <p className='font-medium'>Indoteknik</p>
-        <p className='mt-2 mb-2 text-gray_r-11 leading-6'>
-          Jl. Bandengan Utara Raya No.85, RT.3/RW.16, Penjaringan, Kec.
-          Penjaringan, Kota Jkt Utara, Daerah Khusus Ibukota Jakarta, Indonesia
-          Kodepos : 14440
-        </p>
-        <p className='mt-1 text-gray_r-11'>Telp : 021-2933 8828/29</p>
-        <p className='mt-1 text-gray_r-11'>Mobile : 0813 9000 7430</p>
-      </div>
+export const PickupAddress = ({ label }) => (
+  <div className='p-4'>
+    <div className='flex justify-between items-center'>
+      <div className='font-medium'>{label}</div>
     </div>
-  );
+    <div className='mt-4 text-caption-1'>
+      <p className='font-medium'>Indoteknik</p>
+      <p className='mt-2 mb-2 text-gray_r-11 leading-6'>
+        Jl. Bandengan Utara Raya No.85, RT.3/RW.16, Penjaringan, Kec.
+        Penjaringan, Kota Jkt Utara, Daerah Khusus Ibukota Jakarta, Indonesia
+        Kodepos : 14440
+      </p>
+      <p className='mt-1 text-gray_r-11'>Telp : 021-2933 8828/29</p>
+      <p className='mt-1 text-gray_r-11'>Mobile : 0813 9000 7430</p>
+    </div>
+  </div>
+);
+
+const extractDuration = (text) => {
+  const matches = text.match(/\d+(?:-\d+)?/g);
 
-  const extractDuration = (text) => {
-    const matches = text.match(/\d+(?:-\d+)?/g);
-  
-    if (matches && matches.length === 1) {
-      const parts = matches[0].split('-');
-      const min = parseInt(parts[0]);
-      const max = parseInt(parts[1]);
-  
-      if (min === max) {
-        return min.toString();
-      }
-  
-      return matches[0];
+  if (matches && matches.length === 1) {
+    const parts = matches[0].split('-');
+    const min = parseInt(parts[0]);
+    const max = parseInt(parts[1]);
+
+    if (min === max) {
+      return min.toString();
     }
-  
-    return '';
-  };
-  
\ No newline at end of file
+
+    return matches[0];
+  }
+
+  return '';
+};
+
+export function calculateEstimatedArrival(duration) {
+  if (duration) {
+    let estimationDate = duration.split('-');
+    estimationDate[0] = parseInt(estimationDate[0]);
+    estimationDate[1] = parseInt(estimationDate[1]);
+    const from = addDays(new Date(), estimationDate[0] + 3);
+    const to = addDays(new Date(), estimationDate[1] + 3);
+
+    let etdText = `*Estimasi tiba ${formatDate(from)}`;
+
+    if (estimationDate[1] > estimationDate[0]) {
+      etdText += ` - ${formatDate(to)}`;
+    }
+
+    return etdText;
+  }
+
+  return '';
+}
+
+function addDays(date, days) {
+  const result = new Date(date);
+  result.setDate(result.getDate() + days);
+  return result;
+}
+
+function formatDate(date) {
+  const day = date.getDate();
+  const month = date.toLocaleString('default', { month: 'short' });
+  return `${day} ${month}`;
+}
+
+export function splitDuration(duration) {
+  if (duration) {
+    let estimationDate = null;
+    if (duration.includes('-')) {
+      estimationDate = duration.split('-');
+      estimationDate = parseInt(estimationDate[1]);
+    } else {
+      estimationDate = parseInt(duration);
+    }
+
+    return estimationDate;
+  }
+
+  return '';
+}
\ No newline at end of file
-- 
cgit v1.2.3

