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

