From e9cd13307f0095dc4edc5048752675d80c551564 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 6 Dec 2024 17:06:26 +0700
Subject: <iman> pengajuan tempo

---
 src/lib/address/components/EditAddress.jsx | 53 ++++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 6 deletions(-)

(limited to 'src/lib/address/components/EditAddress.jsx')

diff --git a/src/lib/address/components/EditAddress.jsx b/src/lib/address/components/EditAddress.jsx
index 23cf72a9..dd5c27fd 100644
--- a/src/lib/address/components/EditAddress.jsx
+++ b/src/lib/address/components/EditAddress.jsx
@@ -34,7 +34,8 @@ const EditAddress = ({ id, defaultValues }) => {
   const [states, setStates] = useState([]);
   const [cities, setCities] = useState([]);
   const [districts, setDistricts] = useState([]);
-  const [subDistricts, setSubDistricts] = useState([]); 
+  const [subDistricts, setSubDistricts] = useState([]);
+  const [isZipTrue, setIsZipTrue] = useState(false);
 
   useEffect(() => {
     const loadProfile = async () => {
@@ -60,12 +61,12 @@ const EditAddress = ({ id, defaultValues }) => {
       setStates(dataStates);
     };
     loadStates();
-  },[])
+  }, []);
 
   const watchState = watch('state');
   useEffect(() => {
     setValue('city', '');
-    if(watchState) {
+    if (watchState) {
       const loadCities = async () => {
         let dataCities = await cityApi({ stateId: watchState });
         dataCities = dataCities.map((city) => ({
@@ -81,7 +82,6 @@ const EditAddress = ({ id, defaultValues }) => {
       };
       loadCities();
     }
-    
   }, [watchState, setValue, getValues]);
 
   const watchCity = watch('city');
@@ -128,7 +128,44 @@ const EditAddress = ({ id, defaultValues }) => {
       loadSubDistricts();
     }
   }, [watchDistrict, setValue, getValues]);
+
+  const watchZip = watch('zip');
   const onSubmitHandler = async (values) => {
+    if (watchZip) {
+      const loadZip = async () => {
+        try {
+          const response = await fetch(
+            `https://alamat.thecloudalert.com/api/cari/index/?keyword=${watchZip}`
+          );
+
+          if (!response.ok) {
+            toast.error('Gagal memuat data alamat pos.');
+            setValue('zip', '');
+            return false;
+          }
+
+          const result = await response.json();
+          console.log('result', result);
+
+          if (result.length === 0) {
+            toast.error('Alamat pos salah');
+            setValue('zip', '');
+            return false;
+          }
+
+          return true; // Jika valid
+        } catch (error) {
+          toast.error('Terjadi kesalahan saat memeriksa alamat pos.');
+          console.error('Error:', error);
+          return false;
+        }
+      };
+
+      const isValidZip = await loadZip();
+      if (!isValidZip) {
+        return; // Menghentikan eksekusi jika alamat salah
+      }
+    }
     const data = {
       ...values,
       phone: values.mobile,
@@ -287,7 +324,11 @@ const EditAddress = ({ id, defaultValues }) => {
                   name='city'
                   control={control}
                   render={(props) => (
-                    <HookFormSelect {...props} options={cities} disabled={!watchState} />
+                    <HookFormSelect
+                      {...props}
+                      options={cities}
+                      disabled={!watchState}
+                    />
                   )}
                 />
                 <div className='text-caption-2 text-danger-500 mt-1'>
@@ -348,7 +389,7 @@ const validationSchema = Yup.object().shape({
   mobile: Yup.string().required('Harus di-isi'),
   street: Yup.string().required('Harus di-isi'),
   zip: Yup.string().required('Harus di-isi'),
-  state : Yup.string().required('Harus di-pilih'),
+  state: Yup.string().required('Harus di-pilih'),
   city: Yup.string().required('Harus di-pilih'),
   district: Yup.string().required('Harus di-pilih'),
 });
-- 
cgit v1.2.3


From 0f84963214ee6dc5b5a44d945540826a66bec9e0 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 11 Dec 2024 11:51:45 +0700
Subject: <iman> update pengajuan tempo

---
 src/lib/address/components/EditAddress.jsx | 40 +-----------------------------
 1 file changed, 1 insertion(+), 39 deletions(-)

(limited to 'src/lib/address/components/EditAddress.jsx')

diff --git a/src/lib/address/components/EditAddress.jsx b/src/lib/address/components/EditAddress.jsx
index dd5c27fd..b98ab7b4 100644
--- a/src/lib/address/components/EditAddress.jsx
+++ b/src/lib/address/components/EditAddress.jsx
@@ -35,7 +35,6 @@ const EditAddress = ({ id, defaultValues }) => {
   const [cities, setCities] = useState([]);
   const [districts, setDistricts] = useState([]);
   const [subDistricts, setSubDistricts] = useState([]);
-  const [isZipTrue, setIsZipTrue] = useState(false);
 
   useEffect(() => {
     const loadProfile = async () => {
@@ -53,7 +52,7 @@ const EditAddress = ({ id, defaultValues }) => {
 
   useEffect(() => {
     const loadStates = async () => {
-      let dataStates = await stateApi();
+      let dataStates = await stateApi({ tempo: false });
       dataStates = dataStates.map((state) => ({
         value: state.id,
         label: state.name,
@@ -128,44 +127,7 @@ const EditAddress = ({ id, defaultValues }) => {
       loadSubDistricts();
     }
   }, [watchDistrict, setValue, getValues]);
-
-  const watchZip = watch('zip');
   const onSubmitHandler = async (values) => {
-    if (watchZip) {
-      const loadZip = async () => {
-        try {
-          const response = await fetch(
-            `https://alamat.thecloudalert.com/api/cari/index/?keyword=${watchZip}`
-          );
-
-          if (!response.ok) {
-            toast.error('Gagal memuat data alamat pos.');
-            setValue('zip', '');
-            return false;
-          }
-
-          const result = await response.json();
-          console.log('result', result);
-
-          if (result.length === 0) {
-            toast.error('Alamat pos salah');
-            setValue('zip', '');
-            return false;
-          }
-
-          return true; // Jika valid
-        } catch (error) {
-          toast.error('Terjadi kesalahan saat memeriksa alamat pos.');
-          console.error('Error:', error);
-          return false;
-        }
-      };
-
-      const isValidZip = await loadZip();
-      if (!isValidZip) {
-        return; // Menghentikan eksekusi jika alamat salah
-      }
-    }
     const data = {
       ...values,
       phone: values.mobile,
-- 
cgit v1.2.3


From 4711fff3bf3b07c50f353a7c5956055a37a5e4d2 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Sat, 14 Dec 2024 08:55:39 +0700
Subject: <iman> update alamat

---
 src/lib/address/components/EditAddress.jsx | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

(limited to 'src/lib/address/components/EditAddress.jsx')

diff --git a/src/lib/address/components/EditAddress.jsx b/src/lib/address/components/EditAddress.jsx
index b98ab7b4..e12aba13 100644
--- a/src/lib/address/components/EditAddress.jsx
+++ b/src/lib/address/components/EditAddress.jsx
@@ -39,6 +39,7 @@ const EditAddress = ({ id, defaultValues }) => {
   useEffect(() => {
     const loadProfile = async () => {
       const dataProfile = await addressApi({ id: auth.parentId });
+      console.log('dataProfile', dataProfile);
       setValue('industry', dataProfile.industryId);
       setValue('companyType', dataProfile.companyTypeId);
       setValue('taxName', dataProfile.taxName);
@@ -46,6 +47,9 @@ const EditAddress = ({ id, defaultValues }) => {
       setValue('alamat_wajib_pajak', dataProfile.alamatWajibPajak);
       setValue('alamat_bisnis', dataProfile.alamatBisnis);
       setValue('business_name', dataProfile.name);
+      setValue('city', dataProfile.city.id);
+      setValue('district', dataProfile.district.id);
+      setValue('subDistrict', dataProfile.subDistrict.id);
     };
     if (auth) loadProfile();
   }, [auth?.parentId]);
@@ -64,8 +68,8 @@ const EditAddress = ({ id, defaultValues }) => {
 
   const watchState = watch('state');
   useEffect(() => {
-    setValue('city', '');
     if (watchState) {
+      setValue('city', '');
       const loadCities = async () => {
         let dataCities = await cityApi({ stateId: watchState });
         dataCities = dataCities.map((city) => ({
@@ -85,8 +89,8 @@ const EditAddress = ({ id, defaultValues }) => {
 
   const watchCity = watch('city');
   useEffect(() => {
-    setValue('district', '');
     if (watchCity) {
+      // setValue('district', '');
       const loadDistricts = async () => {
         let dataDistricts = await districtApi({ cityId: watchCity });
         dataDistricts = dataDistricts.map((district) => ({
@@ -96,7 +100,7 @@ const EditAddress = ({ id, defaultValues }) => {
         setDistricts(dataDistricts);
         let oldDistrict = getValues('oldDistrict');
         if (oldDistrict) {
-          setValue('district', oldDistrict);
+          // setValue('district', oldDistrict);
           setValue('oldDistrict', '');
         }
       };
@@ -106,8 +110,8 @@ const EditAddress = ({ id, defaultValues }) => {
 
   const watchDistrict = watch('district');
   useEffect(() => {
-    setValue('subDistrict', '');
     if (watchDistrict) {
+      // setValue('subDistrict', '');
       const loadSubDistricts = async () => {
         let dataSubDistricts = await subDistrictApi({
           districtId: watchDistrict,
-- 
cgit v1.2.3


From daa0b872601789815513508d48a14cbd8e1f6518 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 23 Dec 2024 13:39:47 +0700
Subject: <iman> update pengajuan tempo

---
 src/lib/address/components/EditAddress.jsx | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

(limited to 'src/lib/address/components/EditAddress.jsx')

diff --git a/src/lib/address/components/EditAddress.jsx b/src/lib/address/components/EditAddress.jsx
index e12aba13..62858465 100644
--- a/src/lib/address/components/EditAddress.jsx
+++ b/src/lib/address/components/EditAddress.jsx
@@ -39,7 +39,6 @@ const EditAddress = ({ id, defaultValues }) => {
   useEffect(() => {
     const loadProfile = async () => {
       const dataProfile = await addressApi({ id: auth.parentId });
-      console.log('dataProfile', dataProfile);
       setValue('industry', dataProfile.industryId);
       setValue('companyType', dataProfile.companyTypeId);
       setValue('taxName', dataProfile.taxName);
@@ -47,9 +46,9 @@ const EditAddress = ({ id, defaultValues }) => {
       setValue('alamat_wajib_pajak', dataProfile.alamatWajibPajak);
       setValue('alamat_bisnis', dataProfile.alamatBisnis);
       setValue('business_name', dataProfile.name);
-      setValue('city', dataProfile.city.id);
-      setValue('district', dataProfile.district.id);
-      setValue('subDistrict', dataProfile.subDistrict.id);
+      setValue('city', dataProfile.city?.id);
+      setValue('district', dataProfile.district?.id);
+      setValue('subDistrict', dataProfile.subDistrict?.id);
     };
     if (auth) loadProfile();
   }, [auth?.parentId]);
-- 
cgit v1.2.3

