From 803d93cd36abdf5de5882ba9e9cda24e9a32ab80 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 31 Oct 2024 16:07:18 +0700
Subject: update pengajuan tempo fix suplier ids

---
 src/lib/pengajuan-tempo/component/Pengiriman.jsx | 85 +++++++++++++-----------
 1 file changed, 48 insertions(+), 37 deletions(-)

(limited to 'src/lib/pengajuan-tempo/component/Pengiriman.jsx')

diff --git a/src/lib/pengajuan-tempo/component/Pengiriman.jsx b/src/lib/pengajuan-tempo/component/Pengiriman.jsx
index c2308aed..9817ab12 100644
--- a/src/lib/pengajuan-tempo/component/Pengiriman.jsx
+++ b/src/lib/pengajuan-tempo/component/Pengiriman.jsx
@@ -277,6 +277,16 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
       }
     }
   }, [buttonSubmitClick]);
+  useEffect(() => {
+    if (formPengiriman.isSameAddrees) {
+      const isSame = formPengiriman.isSameAddrees;
+      if (isSame == 'true') {
+        setSameAddress(true);
+      } else {
+        setSameAddress(false);
+      }
+    }
+  }, [formPengiriman.isSameAddrees]);
   useEffect(() => {
     if (sameAddress) {
       updateFormPengiriman('streetInvoice', formPengiriman.streetPengiriman);
@@ -297,67 +307,68 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
   const cachedData = getFromLocalStorage('Pengiriman');
   useEffect(() => {
     if (cachedData) {
-      setValue('cityPengiriman', parseInt(cachedData.cityPengiriman));
-      updateFormPengiriman('cityPengiriman', `${cachedData.cityPengiriman}`);
+      setValue('cityPengiriman', parseInt(cachedData?.cityPengiriman));
+      updateFormPengiriman('cityPengiriman', `${cachedData?.cityPengiriman}`);
     }
-    if (cachedData.statePengiriman) {
-      setValue('statePengiriman', parseInt(cachedData.statePengiriman));
+    if (cachedData?.statePengiriman) {
+      setValue('statePengiriman', parseInt(cachedData?.statePengiriman));
     }
-    if (cachedData.stateInvoice) {
-      setValue('stateInvoice', parseInt(cachedData.stateInvoice));
+    if (cachedData?.stateInvoice) {
+      setValue('stateInvoice', parseInt(cachedData?.stateInvoice));
     }
-    if (cachedData.cityInvoice) {
-      setValue('cityInvoice', parseInt(cachedData.cityInvoice));
+    if (cachedData?.cityInvoice) {
+      setValue('cityInvoice', parseInt(cachedData?.cityInvoice));
     }
-    if (cachedData.isSameAddrees) {
-      updateFormPengiriman('isSameAddrees', `${cachedData.isSameAddrees}`);
+    if (cachedData?.isSameAddrees) {
+      updateFormPengiriman('isSameAddrees', `${cachedData?.isSameAddrees}`);
     }
-  }, [cachedData.cityPengiriman]);
+  }, [cachedData?.cityPengiriman]);
   useEffect(() => {
-    if (cachedData.everyWeek) {
-      updateFormPengiriman('everyWeek', cachedData.everyWeek);
-      setEveryWeek(cachedData.everyWeek);
+    if (cachedData?.everyWeek) {
+      updateFormPengiriman('everyWeek', cachedData?.everyWeek);
+      setEveryWeek(cachedData?.everyWeek);
     }
-    if (cachedData.everyWeekday) {
-      updateFormPengiriman('everyWeekday', cachedData.everyWeekday);
-      setEveryWeekday(cachedData.everyWeekday);
+    if (cachedData?.everyWeekday) {
+      updateFormPengiriman('everyWeekday', cachedData?.everyWeekday);
+      setEveryWeekday(cachedData?.everyWeekday);
     }
-    if (cachedData.tukarInvoice) {
-      updateFormPengiriman('tukarInvoice', cachedData.tukarInvoice);
-      setTukarInvoice(cachedData.tukarInvoice);
+    if (cachedData?.tukarInvoice) {
+      updateFormPengiriman('tukarInvoice', cachedData?.tukarInvoice);
+      setTukarInvoice(cachedData?.tukarInvoice);
     }
-    if (cachedData.everyWeekPembayaran) {
+    if (cachedData?.everyWeekPembayaran) {
       updateFormPengiriman(
         'everyWeekPembayaran',
-        cachedData.everyWeekPembayaran
+        cachedData?.everyWeekPembayaran
       );
-      setEveryWeekPembayaran(cachedData.everyWeekPembayaran);
+      setEveryWeekPembayaran(cachedData?.everyWeekPembayaran);
     }
-    if (cachedData.everyWeekdayPembayaran) {
+    if (cachedData?.everyWeekdayPembayaran) {
       updateFormPengiriman(
         'everyWeekdayPembayaran',
-        cachedData.everyWeekdayPembayaran
+        cachedData?.everyWeekdayPembayaran
       );
-      setEveryWeekdayPembayaran(cachedData.everyWeekdayPembayaran);
+      setEveryWeekdayPembayaran(cachedData?.everyWeekdayPembayaran);
     }
-    if (cachedData.tukarInvoicePembayaran) {
+    if (cachedData?.tukarInvoicePembayaran) {
       updateFormPengiriman(
         'tukarInvoicePembayaran',
-        cachedData.tukarInvoicePembayaran
+        cachedData?.tukarInvoicePembayaran
       );
-      setTukarInvoicePembayaran(cachedData.tukarInvoicePembayaran);
+      setTukarInvoicePembayaran(cachedData?.tukarInvoicePembayaran);
     }
   }, [
-    cachedData.everyWeek,
-    cachedData.everyWeekday,
-    cachedData.tukarInvoice,
-    cachedData.everyWeekdayPembayaran,
-    cachedData.everyWeekPembayaran,
-    cachedData.tukarInvoicePembayaran,
+    cachedData?.everyWeek,
+    cachedData?.everyWeekday,
+    cachedData?.tukarInvoice,
+    cachedData?.everyWeekdayPembayaran,
+    cachedData?.everyWeekPembayaran,
+    cachedData?.tukarInvoicePembayaran,
   ]);
   const handleChangeSameAddress = () => {
     setSameAddress(!sameAddress);
   };
+  console.log('formPengiriman', formPengiriman);
   return (
     <>
       <h1 className={`font-bold ${isKonfirmasi ? 'text-xl' : ''}`}>
@@ -466,7 +477,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     ref={zipRef}
                     placeholder='Kode Pos'
                     type='number'
-                    value={formPengiriman.zip}
+                    value={formPengiriman.zipPengiriman}
                     className='form-input'
                     onChange={handleInputChange}
                   />
@@ -763,7 +774,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
               <Checkbox
                 colorScheme='red'
                 key='1'
-                isChecked={isChecked(2)}
+                isChecked={isChecked(1)}
                 onChange={() => handleCheckboxChange(1)}
               >
                 Good Receipt (GR)
-- 
cgit v1.2.3

