From 7966f67569d01c25f7a337962d7d0bb1a0c57808 Mon Sep 17 00:00:00 2001
From: trisusilo48 <tri.susilo@altama.co.id>
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 = () => {
                   />
                 </Skeleton>
               )}
+              {products && <SectionExpedition products={products} />}
               <Divider />
               <SectionValidation address={selectedAddress.invoicing} />
               <SectionExpedisi
@@ -1621,12 +1638,22 @@ const SectionAddress = ({ address, label, url }) => (
           {address.street}, {address?.city?.name}
         </p>
         <div className='flex gap-x-2 items-center mt-4'>
-          <MapPinIcon className={address.addressMap ? `h-6 w-6 text-gray-500` : `h-6 w-6 text-red-500`} />
-          {address.addressMap ?  <label>Sudah Pinpoint</label> : <label className='text-red-500 '>Belum Pinpoint</label>}
+          <MapPinIcon
+            className={
+              address.addressMap
+                ? `h-6 w-6 text-gray-500`
+                : `h-6 w-6 text-red-500`
+            }
+          />
+          {address.addressMap ? (
+            <label>Sudah Pinpoint</label>
+          ) : (
+            <label className='text-red-500 '>Belum Pinpoint</label>
+          )}
         </div>
       </div>
     )}
-  </div>  
+  </div>
 );
 
 const SectionValidation = ({ address }) =>
@@ -1647,11 +1674,9 @@ const SectionValidation = ({ address }) =>
   );
 
 const SectionExpedisiBiteship = ({ listExpedisi, setSelectedExpedisi }) => (
-  <>
-  </>
+  <></>
 );
 
-
 const SectionExpedisi = ({
   address,
   listExpedisi,
-- 
cgit v1.2.3

