From 7f92d22feb841e1405e56505c742f90cbd365ffc Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 30 Dec 2024 15:49:18 +0700
Subject: <iman> update pengajuan tempo

---
 .../component/informasiPerusahaan.jsx              | 34 ++++++++++++----------
 1 file changed, 19 insertions(+), 15 deletions(-)

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

diff --git a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx
index fc0f1c28..d385bc3b 100644
--- a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx
+++ b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx
@@ -73,9 +73,6 @@ const InformasiPerusahaan = ({
 
   const watchState = watch('state');
   useEffect(() => {
-    // setValue('city', '');
-    // setValue('district', '');
-    // setValue('subDistrict', '');
     if (watchState) {
       updateForm('state', `${watchState}`);
       validate();
@@ -93,6 +90,15 @@ const InformasiPerusahaan = ({
 
   const watchCity = watch('city');
 
+  // Untuk memperbarui form.city
+  useEffect(() => {
+    if (watchCity && form.city !== `${watchCity}`) {
+      updateForm('city', `${watchCity}`);
+      validate();
+    }
+  }, [watchCity]);
+
+  // Untuk memuat distrik
   useEffect(() => {
     if (watchCity) {
       const loadDistricts = async () => {
@@ -103,10 +109,6 @@ const InformasiPerusahaan = ({
         }));
         setDistricts(dataDistricts);
       };
-      if (form.city !== `${watchCity}`) {
-        updateForm('city', `${watchCity}`);
-      }
-      validate();
       loadDistricts();
     }
   }, [watchCity]);
@@ -429,9 +431,7 @@ const InformasiPerusahaan = ({
     if (form.state) {
       setValue('state', parseInt(form.state));
     }
-    if (form.city) {
-      setValue('city', parseInt(form.city));
-    }
+
     if (form.district) {
       setValue('district', parseInt(form.district));
     }
@@ -462,6 +462,11 @@ const InformasiPerusahaan = ({
       }
     }
   }, [form]);
+  useEffect(() => {
+    if (form.city) {
+      setValue('city', parseInt(form.city));
+    }
+  }, [form.city]);
   useEffect(() => {
     const loadProfile = async () => {
       try {
@@ -469,6 +474,9 @@ const InformasiPerusahaan = ({
         if (dataProfile.name) {
           updateForm('name', dataProfile.name);
         }
+        if (dataProfile.street) {
+          updateForm('street', dataProfile.street);
+        }
         if (dataProfile.stateId.id) {
           updateForm('state', `${dataProfile.stateId.id}`);
         }
@@ -481,9 +489,6 @@ const InformasiPerusahaan = ({
         if (dataProfile.subDistrict.id) {
           updateForm('subDistrict', `${dataProfile.subDistrict.id}`);
         }
-        if (dataProfile.alamatBisnis) {
-          updateForm('street', dataProfile.alamatBisnis);
-        }
         if (dataProfile.zip) {
           updateForm('zip', dataProfile.zip);
         }
@@ -509,7 +514,7 @@ const InformasiPerusahaan = ({
   useEffect(() => {
     const loadProfile = async () => {
       try {
-        const dataProfile = await addressApi({ id: auth.partnerId });
+        const dataProfile = await addressApi({ id: auth.parentId });
         setValue('industryId', parseInt(dataProfile.industryId));
         setValue('state', parseInt(dataProfile.stateId.id));
         setValue('city', parseInt(dataProfile.city.id));
@@ -528,7 +533,6 @@ const InformasiPerusahaan = ({
   const handleLengkapiData = () => {
     router.push('/my/profile');
   };
-
   return (
     <>
       <BottomPopup
-- 
cgit v1.2.3

