From 87ffd2fa7edc240693ddd81401ef23c5cd1bbb3e Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 18 Oct 2024 16:11:17 +0700
Subject: <iman> update fix kontak person

---
 .../pengajuan-tempo/component/PengajuanTempo.jsx   | 29 ++++++++++++++--------
 1 file changed, 19 insertions(+), 10 deletions(-)

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

diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
index 2c10b1d6..14ea1805 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -9,11 +9,11 @@ import {
   usePengajuanTempoStoreKontakPerson,
 } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore';
 import { ChevronRightIcon, ChevronLeftIcon } from '@heroicons/react/24/outline';
-import { chakra } from '@chakra-ui/react';
 const PengajuanTempo = () => {
   const [currentStep, setCurrentStep] = React.useState(0);
   const NUMBER_OF_STEPS = 6;
   const { form, errors, validate, updateForm } = usePengajuanTempoStore();
+  const { control, watch, setValue } = useForm();
   const {
     formKontakPerson,
     errorsKontakPerson,
@@ -55,6 +55,15 @@ const PengajuanTempo = () => {
     <div>Dokumen</div>,
     <div>Konfirmasi</div>,
   ];
+  const stepDivsUpdateForm = [
+    updateForm,
+    updateFormKontakPerson,
+    <div>Kontak Person</div>,
+    <div>Pengiriman</div>,
+    <div>Referensi</div>,
+    <div>Dokumen</div>,
+    <div>Konfirmasi</div>,
+  ];
   const stepLabels = [
     'informasi_perusahaan',
     'kontak_person',
@@ -69,16 +78,21 @@ const PengajuanTempo = () => {
     [stepDivsError[currentStep]]
   );
   useEffect(() => {
-    validate();
     validateKontakPerson();
-  }, []);
+    validate();
+
+    window.scrollTo({
+      top: 0,
+      behavior: 'smooth',
+    });
+  }, [currentStep]);
+
   useEffect(() => {
     const cachedData = getFromLocalStorage(stepLabels[currentStep]);
-    console.log('cachedData prev button', cachedData);
     if (cachedData) {
       // const formData = JSON.parse(cachedData);
       Object.keys(cachedData).forEach((key) => {
-        updateForm(key, cachedData[key]);
+        stepDivsUpdateForm[currentStep](key, cachedData[key]);
       });
     }
   }, [currentStep]);
@@ -86,15 +100,10 @@ const PengajuanTempo = () => {
     if (!isFormValid) {
       setNotValid(true);
       setButtonSubmitClick(!buttonSubmitClick);
-      console.log('form', stepDivsForm[currentStep]);
-      console.log('error', stepDivsError[currentStep]);
       return;
     } else {
       saveToLocalStorage(stepLabels[currentStep], stepDivsForm[currentStep]);
       const cachedData = getFromLocalStorage(stepLabels[currentStep]);
-      console.log('cachedData', cachedData);
-      console.log('form', stepDivsForm[currentStep]);
-      console.log('error', stepDivsError[currentStep]);
       setButtonSubmitClick(!buttonSubmitClick);
       setNotValid(false);
     }
-- 
cgit v1.2.3

