From d1592286eef165533c21d52aec70dbb703cdcfd3 Mon Sep 17 00:00:00 2001
From: trisusilo48 <tri.susilo@altama.co.id>
Date: Wed, 18 Dec 2024 15:03:52 +0700
Subject: feedback uat

---
 src/lib/address/components/EditAddress.jsx | 71 ++++++++++++++++++++++++++++--
 1 file changed, 68 insertions(+), 3 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 0b3b0aa3..7675db9d 100644
--- a/src/lib/address/components/EditAddress.jsx
+++ b/src/lib/address/components/EditAddress.jsx
@@ -42,18 +42,33 @@ const EditAddress = ({ id, defaultValues }) => {
   const [districts, setDistricts] = useState([]);
   const [subDistricts, setSubDistricts] = useState([]);
   const [pinedMaps, setPinedMaps] = useState(false);
-  const [tempAddress, setTempAddress] = useState(getValues('address_maps'));
+  const [tempAddress, setTempAddress] = useState(getValues('addressMap'));
   const { addressMaps, selectedPosition, detailAddress } = useMaps();
 
+  console.log('ini adalah',);
+
   useEffect(() => {
     if (addressMaps) {
       setTempAddress(addressMaps);
-      setValue('address_map', addressMaps);
+      setValue('addressMap', addressMaps);
       setValue('longtitude', selectedPosition.lng);
       setValue('latitude', selectedPosition.lat);
     }
   }, [addressMaps, selectedPosition, setValue]);
 
+  useEffect(() => {
+    if (Object.keys(detailAddress).length > 0) {
+      setValue('zip', detailAddress.postalCode);
+      const selectedState = states.find(
+        (state) =>
+          detailAddress?.province.includes(state.label) ||
+          state.label.includes(detailAddress?.province)
+      );
+      setValue('state', selectedState?.value);  
+      setValue('street', detailAddress?.route);      
+    }
+  }, [detailAddress, setValue]);
+
   useEffect(() => {
     const loadProfile = async () => {
       const dataProfile = await addressApi({ id: auth.parentId });
@@ -101,6 +116,21 @@ const EditAddress = ({ id, defaultValues }) => {
     }
   }, [watchState, setValue, getValues]);
 
+  useEffect(() => {
+    if (Object.keys(detailAddress).length > 0) {
+      const selectedCities = cities.find(
+        (city) =>
+          detailAddress?.district
+            .toLowerCase()
+            .includes(city.label.toLowerCase()) ||
+          city.label
+            .toLowerCase()
+            .includes(detailAddress?.district.toLowerCase())
+      );
+      setValue('city', selectedCities?.value);
+    }
+  }, [cities, detailAddress, setValue]);
+
   const watchCity = watch('city');
   useEffect(() => {
     setValue('district', '');
@@ -122,6 +152,23 @@ const EditAddress = ({ id, defaultValues }) => {
     }
   }, [watchCity, setValue, getValues]);
 
+  useEffect(() => {
+    if (Object.keys(detailAddress).length > 0) {
+      const selectedDistrict = districts.find(
+        (district) =>
+          detailAddress.subDistrict
+            .toLowerCase()
+            .includes(district.label.toLowerCase()) ||
+          district.label
+            .toLowerCase()
+            .includes(detailAddress.subDistrict.toLowerCase())
+      );
+      setValue('district', selectedDistrict?.value);
+    }
+  }, [districts, detailAddress, setValue]);
+
+
+
   const watchDistrict = watch('district');
   useEffect(() => {
     setValue('subDistrict', '');
@@ -145,6 +192,24 @@ const EditAddress = ({ id, defaultValues }) => {
       loadSubDistricts();
     }
   }, [watchDistrict, setValue, getValues]);
+
+  
+  useEffect(() => {
+    if (Object.keys(detailAddress).length > 0) {
+      const selectedSubDistrict = subDistricts.find(
+        (district) =>
+          detailAddress.village
+            .toLowerCase()
+            .includes(district.label.toLowerCase()) ||
+          district.label
+            .toLowerCase()
+            .includes(detailAddress.village.toLowerCase())
+      );
+
+      setValue('subDistrict', selectedSubDistrict?.value);
+    }
+  }, [subDistricts, detailAddress, setValue]);
+
   const onSubmitHandler = async (values) => {
     const data = {
       ...values,
@@ -228,7 +293,7 @@ const EditAddress = ({ id, defaultValues }) => {
               <label className='form-label mb-2'>PinPoint</label>
               {tempAddress ? (
                 <div className='flex gap-x-2 items-center'>
-                  <MapPinIcon class='h-6 w-6 text-gray-500 mr-3' />{' '}
+                  <MapPinIcon class='h-6 w-6 text-gray-500 mr-3 cursor-pointer' onClick={() => setPinedMaps(true)} />{' '}
                   <span> {tempAddress} </span>
                 </div>
               ) : (
-- 
cgit v1.2.3

