From dc3f5a3196a41c676f328aa0804af516d39e69f9 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 17 Sep 2024 16:23:41 +0700
Subject: <iman> update new register ubah alamat

---
 src/lib/address/components/EditAddress.jsx | 40 ++++++++++++++++--------------
 1 file changed, 21 insertions(+), 19 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 626709db..580aaeb8 100644
--- a/src/lib/address/components/EditAddress.jsx
+++ b/src/lib/address/components/EditAddress.jsx
@@ -37,7 +37,6 @@ const EditAddress = ({ id, defaultValues }) => {
   useEffect(() => {
     const loadProfile = async () => {
       const dataProfile = await addressApi({ id: auth.parentId });
-      setValue('name', dataProfile.name);
       setValue('industry', dataProfile.industryId);
       setValue('companyType', dataProfile.companyTypeId);
       setValue('taxName', dataProfile.taxName);
@@ -113,25 +112,28 @@ const EditAddress = ({ id, defaultValues }) => {
       district_id: values.district,
       sub_district_id: values.subDistrict,
     };
-    const dataAlamat = {
-      ...values,
-      id_user: auth.partnerId,
-      company_type_id: values.companyType,
-      industry_id: values.industry,
-      tax_name: values.taxName,
-      alamat_lengkap_text: values.alamat_wajib_pajak,
-      street: values.street,
-    };
-
-    // const address = await editAddressApi({ id, data });
-    const isUpdated = await odooApi(
-      'PUT',
-      `/api/v1/partner/${auth.parentId}`,
-      dataAlamat
-    );
+    const address = await editAddressApi({ id, data });
+    let dataAlamat;
+    let isUpdated = true;
+    if (auth?.partnerId == id) {
+      dataAlamat = {
+        ...values,
+        id_user: auth.partnerId,
+        company_type_id: values.companyType,
+        industry_id: values.industry,
+        tax_name: values.taxName,
+        alamat_lengkap_text: values.alamat_wajib_pajak,
+        street: values.street,
+      };
+      isUpdated = await odooApi(
+        'PUT',
+        `/api/v1/partner/${auth.parentId}`,
+        dataAlamat
+      );
+    }
 
-    if (isUpdated?.id) {
-      // if (address?.id && isUpdated?.id) {
+    // if (isUpdated?.id) {
+    if (address?.id) {
       toast.success('Berhasil mengubah alamat');
       router.back();
     } else {
-- 
cgit v1.2.3

