From 555de668c83b44679af9ef34f3624a55b372cfce Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 4 Sep 2024 16:07:38 +0700
Subject: <iman> update new register edit data

---
 src/lib/auth/components/CompanyProfile.jsx | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index 2faede9b..a4c25e40 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -20,6 +20,7 @@ const CompanyProfile = () => {
       npwp: ''
     }
   })
+  console.log("auth",auth)
 
   const [industries, setIndustries] = useState([])
   useEffect(() => {
@@ -42,11 +43,13 @@ const CompanyProfile = () => {
   useEffect(() => {
     const loadProfile = async () => {
       const dataProfile = await addressApi({ id: auth.parentId })
+      console.log("dataProfile",dataProfile)
       setValue('name', dataProfile.name)
       setValue('industry', dataProfile.industryId)
       setValue('companyType', dataProfile.companyTypeId)
       setValue('taxName', dataProfile.taxName)
       setValue('npwp', dataProfile.npwp)
+      setValue('alamat_wajib_pajak', dataProfile.alamatWajibPajak)
     }
     if (auth) loadProfile()
   }, [auth, setValue])
@@ -54,9 +57,11 @@ const CompanyProfile = () => {
   const onSubmitHandler = async (values) => {
     const data = {
       ...values,
+      id_user:auth.partnerId,
       company_type_id: values.companyType,
       industry_id: values.industry,
-      tax_name: values.taxName
+      tax_name: values.taxName,
+      alamat_lengkap_text:values.alamat_wajib_pajak
     }
     const isUpdated = await odooApi('PUT', `/api/v1/partner/${auth.parentId}`, data)
     if (isUpdated?.id) {
@@ -117,6 +122,9 @@ const CompanyProfile = () => {
             <div>
               <label>Nomor NPWP</label>
               <input {...register('npwp')} type='text' className='form-input mt-3' />
+            </div><div>
+              <label>Alamat Wajib Pajak</label>
+              <input {...register('alamat_wajib_pajak')} type='text' className='form-input mt-3' />
             </div>
           </div>
           <button type='submit' className='btn-yellow w-full mt-6'>
-- 
cgit v1.2.3


From d3e867689b9b171efb8f5a85c7a4cb39b7e7b8fd Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 5 Sep 2024 09:40:32 +0700
Subject: <iman> update new register

---
 src/lib/auth/components/CompanyProfile.jsx | 69 ++++++++++++++++++++++--------
 1 file changed, 52 insertions(+), 17 deletions(-)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index a4c25e40..581c32b0 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -6,8 +6,10 @@ import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'
 import { useEffect, useState } from 'react'
 import { Controller, useForm } from 'react-hook-form'
 import { toast } from 'react-hot-toast'
+import BottomPopup from '@/core/components/elements/Popup/BottomPopup'
 
 const CompanyProfile = () => {
+  const [changeConfirmation, setChangeConfirmation] = useState(false)
   const auth = useAuth()
   const [isOpen, setIsOpen] = useState(false)
   const toggle = () => setIsOpen(!isOpen)
@@ -17,10 +19,10 @@ const CompanyProfile = () => {
       companyType: '',
       name: '',
       taxName: '',
-      npwp: ''
+      npwp: '',
+      alamat_wajib_pajak:'',
     }
   })
-  console.log("auth",auth)
 
   const [industries, setIndustries] = useState([])
   useEffect(() => {
@@ -43,7 +45,6 @@ const CompanyProfile = () => {
   useEffect(() => {
     const loadProfile = async () => {
       const dataProfile = await addressApi({ id: auth.parentId })
-      console.log("dataProfile",dataProfile)
       setValue('name', dataProfile.name)
       setValue('industry', dataProfile.industryId)
       setValue('companyType', dataProfile.companyTypeId)
@@ -55,24 +56,55 @@ const CompanyProfile = () => {
   }, [auth, setValue])
 
   const onSubmitHandler = async (values) => {
-    const data = {
-      ...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
+    if(changeConfirmation){
+      const data = {
+        ...values,
+        company_type_id: values.companyType,
+        industry_id: values.industry,
+        tax_name: values.taxName,
+        alamat_lengkap_text:values.alamat_wajib_pajak
+      }
+      const isUpdated = await odooApi('PUT', `/api/v1/partner/${auth.parentId}`, data)
+      if (isUpdated?.id) {
+        toast.success('Berhasil mengubah profil', { duration: 1500 })
+        return
+      }
+      toast.error('Terjadi kesalahan internal')
     }
-    const isUpdated = await odooApi('PUT', `/api/v1/partner/${auth.parentId}`, data)
-    if (isUpdated?.id) {
-      toast.success('Berhasil mengubah profil', { duration: 1500 })
-      return
-    }
-    toast.error('Terjadi kesalahan internal')
+  }
+
+  const handleConfirmSubmit = () => {
+    setChangeConfirmation(false)
+    handleSubmit(onSubmitHandler)()
   }
 
   return (
     <>
+      <BottomPopup
+        active={changeConfirmation}
+        close={() => setChangeConfirmation(true)}
+        title='Ubah profil Bisnis'
+      >
+        <div className='leading-7 text-gray_r-12/80'>
+          Apakah anda yakin mengubah data bisnis?
+        </div>
+        <div className='flex mt-6 gap-x-4 md:justify-end'>
+          <button
+            className='btn-solid-red flex-1 md:flex-none'
+            type='button'
+            onClick={handleConfirmSubmit}
+          >
+            Ya, Ubah
+          </button>
+          <button
+            className='btn-light flex-1 md:flex-none'
+            type='button'
+            onClick={() => setChangeConfirmation(false)}
+          >
+            Batal
+          </button>
+        </div>
+      </BottomPopup>
       <button type='button' onClick={toggle} className='p-4 flex items-center text-left w-full'>
         <div>
           <div className='font-semibold mb-2'>Informasi Usaha</div>
@@ -87,7 +119,10 @@ const CompanyProfile = () => {
       </button>
 
       {isOpen && (
-        <form className='p-4 border-t border-gray_r-6' onSubmit={handleSubmit(onSubmitHandler)}>
+        <form className='p-4 border-t border-gray_r-6' onSubmit={(e) => {
+          e.preventDefault()
+          setChangeConfirmation(true) 
+        }}>
           <div className='grid grid-cols-1 sm:grid-cols-2 gap-4'>
             <div>
               <label className='block mb-3'>Klasifikasi Jenis Usaha</label>
-- 
cgit v1.2.3


From 4d9200650d232e4302f7e01df96751c3f9412693 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 6 Sep 2024 16:20:51 +0700
Subject: <iman> update data api

---
 src/lib/auth/components/CompanyProfile.jsx | 1 +
 1 file changed, 1 insertion(+)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index 581c32b0..e37decc9 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -59,6 +59,7 @@ const CompanyProfile = () => {
     if(changeConfirmation){
       const data = {
         ...values,
+        id_user:auth.partnerId,
         company_type_id: values.companyType,
         industry_id: values.industry,
         tax_name: values.taxName,
-- 
cgit v1.2.3


From 499954a8be814850103eece2dbd0306d6246989d Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 12 Sep 2024 15:12:42 +0700
Subject: <iman> update new register

---
 src/lib/auth/components/CompanyProfile.jsx | 179 ++++++++++++++++++-----------
 1 file changed, 113 insertions(+), 66 deletions(-)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index e37decc9..fc3d149b 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -1,18 +1,18 @@
-import odooApi from '@/core/api/odooApi'
-import HookFormSelect from '@/core/components/elements/Select/HookFormSelect'
-import useAuth from '@/core/hooks/useAuth'
-import addressApi from '@/lib/address/api/addressApi'
-import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'
-import { useEffect, useState } from 'react'
-import { Controller, useForm } from 'react-hook-form'
-import { toast } from 'react-hot-toast'
-import BottomPopup from '@/core/components/elements/Popup/BottomPopup'
+import odooApi from '@/core/api/odooApi';
+import HookFormSelect from '@/core/components/elements/Select/HookFormSelect';
+import useAuth from '@/core/hooks/useAuth';
+import addressApi from '@/lib/address/api/addressApi';
+import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline';
+import { useEffect, useState } from 'react';
+import { Controller, useForm } from 'react-hook-form';
+import { toast } from 'react-hot-toast';
+import BottomPopup from '@/core/components/elements/Popup/BottomPopup';
 
 const CompanyProfile = () => {
-  const [changeConfirmation, setChangeConfirmation] = useState(false)
-  const auth = useAuth()
-  const [isOpen, setIsOpen] = useState(false)
-  const toggle = () => setIsOpen(!isOpen)
+  const [changeConfirmation, setChangeConfirmation] = useState(false);
+  const auth = useAuth();
+  const [isOpen, setIsOpen] = useState(false);
+  const toggle = () => setIsOpen(!isOpen);
   const { register, setValue, control, handleSubmit } = useForm({
     defaultValues: {
       industry: '',
@@ -20,64 +20,78 @@ const CompanyProfile = () => {
       name: '',
       taxName: '',
       npwp: '',
-      alamat_wajib_pajak:'',
-    }
-  })
+      alamat_wajib_pajak: '',
+    },
+  });
 
-  const [industries, setIndustries] = useState([])
+  const [industries, setIndustries] = useState([]);
   useEffect(() => {
     const loadIndustries = async () => {
-      const dataIndustries = await odooApi('GET', '/api/v1/partner/industry')
-      setIndustries(dataIndustries?.map((o) => ({ value: o.id, label: o.name })))
-    }
-    loadIndustries()
-  }, [])
+      const dataIndustries = await odooApi('GET', '/api/v1/partner/industry');
+      setIndustries(
+        dataIndustries?.map((o) => ({ value: o.id, label: o.name }))
+      );
+    };
+    loadIndustries();
+  }, []);
 
-  const [companyTypes, setCompanyTypes] = useState([])
+  const [companyTypes, setCompanyTypes] = useState([]);
   useEffect(() => {
     const loadCompanyTypes = async () => {
-      const dataCompanyTypes = await odooApi('GET', '/api/v1/partner/company_type')
-      setCompanyTypes(dataCompanyTypes?.map((o) => ({ value: o.id, label: o.name })))
-    }
-    loadCompanyTypes()
-  }, [])
+      const dataCompanyTypes = await odooApi(
+        'GET',
+        '/api/v1/partner/company_type'
+      );
+      setCompanyTypes(
+        dataCompanyTypes?.map((o) => ({ value: o.id, label: o.name }))
+      );
+    };
+    loadCompanyTypes();
+  }, []);
 
   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)
-      setValue('npwp', dataProfile.npwp)
-      setValue('alamat_wajib_pajak', dataProfile.alamatWajibPajak)
-    }
-    if (auth) loadProfile()
-  }, [auth, setValue])
+      const dataProfile = await addressApi({ id: auth.parentId });
+      console.log('dataProfile', dataProfile);
+      setValue('name', dataProfile.name);
+      setValue('industry', dataProfile.industryId);
+      setValue('companyType', dataProfile.companyTypeId);
+      setValue('taxName', dataProfile.taxName);
+      setValue('npwp', dataProfile.npwp);
+      setValue('alamat_wajib_pajak', dataProfile.alamatWajibPajak);
+      setValue('alamat_bisnis', dataProfile.alamatBisnis);
+    };
+    if (auth) loadProfile();
+  }, [auth, setValue]);
 
   const onSubmitHandler = async (values) => {
-    if(changeConfirmation){
+    if (changeConfirmation) {
       const data = {
         ...values,
-        id_user:auth.partnerId,
+        id_user: auth.partnerId,
         company_type_id: values.companyType,
         industry_id: values.industry,
         tax_name: values.taxName,
-        alamat_lengkap_text:values.alamat_wajib_pajak
-      }
-      const isUpdated = await odooApi('PUT', `/api/v1/partner/${auth.parentId}`, data)
+        alamat_lengkap_text: values.alamat_wajib_pajak,
+        street: values.alamat_bisnis,
+      };
+      const isUpdated = await odooApi(
+        'PUT',
+        `/api/v1/partner/${auth.parentId}`,
+        data
+      );
       if (isUpdated?.id) {
-        toast.success('Berhasil mengubah profil', { duration: 1500 })
-        return
+        toast.success('Berhasil mengubah profil', { duration: 1500 });
+        return;
       }
-      toast.error('Terjadi kesalahan internal')
+      toast.error('Terjadi kesalahan internal');
     }
-  }
+  };
 
   const handleConfirmSubmit = () => {
-    setChangeConfirmation(false)
-    handleSubmit(onSubmitHandler)()
-  }
+    setChangeConfirmation(false);
+    handleSubmit(onSubmitHandler)();
+  };
 
   return (
     <>
@@ -106,11 +120,16 @@ const CompanyProfile = () => {
           </button>
         </div>
       </BottomPopup>
-      <button type='button' onClick={toggle} className='p-4 flex items-center text-left w-full'>
+      <button
+        type='button'
+        onClick={toggle}
+        className='p-4 flex items-center text-left w-full'
+      >
         <div>
           <div className='font-semibold mb-2'>Informasi Usaha</div>
           <div className='text-gray_r-11'>
-            Dibawah ini adalah data usaha yang anda masukkan, periksa kembali data usaha anda.
+            Dibawah ini adalah data usaha yang anda masukkan, periksa kembali
+            data usaha anda.
           </div>
         </div>
         <div className='ml-auto p-2 bg-gray_r-3 rounded'>
@@ -120,17 +139,22 @@ const CompanyProfile = () => {
       </button>
 
       {isOpen && (
-        <form className='p-4 border-t border-gray_r-6' onSubmit={(e) => {
-          e.preventDefault()
-          setChangeConfirmation(true) 
-        }}>
+        <form
+          className='p-4 border-t border-gray_r-6'
+          onSubmit={(e) => {
+            e.preventDefault();
+            setChangeConfirmation(true);
+          }}
+        >
           <div className='grid grid-cols-1 sm:grid-cols-2 gap-4'>
             <div>
               <label className='block mb-3'>Klasifikasi Jenis Usaha</label>
               <Controller
                 name='industry'
                 control={control}
-                render={(props) => <HookFormSelect {...props} options={industries} />}
+                render={(props) => (
+                  <HookFormSelect {...props} options={industries} />
+                )}
               />
             </div>
             <div className='flex flex-wrap'>
@@ -139,7 +163,9 @@ const CompanyProfile = () => {
                 <Controller
                   name='companyType'
                   control={control}
-                  render={(props) => <HookFormSelect {...props} options={companyTypes} />}
+                  render={(props) => (
+                    <HookFormSelect {...props} options={companyTypes} />
+                  )}
                 />
               </div>
               <div className='w-9/12 pl-1'>
@@ -153,14 +179,35 @@ const CompanyProfile = () => {
             </div>
             <div>
               <label>Nama Wajib Pajak</label>
-              <input {...register('taxName')} type='text' className='form-input mt-3' />
+              <input
+                {...register('taxName')}
+                type='text'
+                className='form-input mt-3'
+              />
             </div>
             <div>
-              <label>Nomor NPWP</label>
-              <input {...register('npwp')} type='text' className='form-input mt-3' />
-            </div><div>
               <label>Alamat Wajib Pajak</label>
-              <input {...register('alamat_wajib_pajak')} type='text' className='form-input mt-3' />
+              <input
+                {...register('alamat_wajib_pajak')}
+                type='text'
+                className='form-input mt-3'
+              />
+            </div>
+            <div>
+              <label>Alamat Bisnis</label>
+              <input
+                {...register('alamat_bisnis')}
+                type='text'
+                className='form-input mt-3'
+              />
+            </div>
+            <div>
+              <label>Nomor NPWP</label>
+              <input
+                {...register('npwp')}
+                type='text'
+                className='form-input mt-3'
+              />
             </div>
           </div>
           <button type='submit' className='btn-yellow w-full mt-6'>
@@ -169,7 +216,7 @@ const CompanyProfile = () => {
         </form>
       )}
     </>
-  )
-}
+  );
+};
 
-export default CompanyProfile
+export default CompanyProfile;
-- 
cgit v1.2.3


From aaf907c834343970e1d30b3ef49c13ed5f9d34ed Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 17 Sep 2024 09:01:04 +0700
Subject: <iman> add focus error when button submit click

---
 src/lib/auth/components/CompanyProfile.jsx | 1 -
 1 file changed, 1 deletion(-)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index fc3d149b..70713bdf 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -52,7 +52,6 @@ const CompanyProfile = () => {
   useEffect(() => {
     const loadProfile = async () => {
       const dataProfile = await addressApi({ id: auth.parentId });
-      console.log('dataProfile', dataProfile);
       setValue('name', dataProfile.name);
       setValue('industry', dataProfile.industryId);
       setValue('companyType', dataProfile.companyTypeId);
-- 
cgit v1.2.3


From aa44cff228f73d2546466abb6344f249881f94be Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 17 Sep 2024 13:53:52 +0700
Subject: <iman< update new register

---
 src/lib/auth/components/CompanyProfile.jsx | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index 70713bdf..f1577ca1 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -21,9 +21,10 @@ const CompanyProfile = () => {
       taxName: '',
       npwp: '',
       alamat_wajib_pajak: '',
+      alamat_bisnis: '',
     },
   });
-
+  console.log('auth', auth);
   const [industries, setIndustries] = useState([]);
   useEffect(() => {
     const loadIndustries = async () => {
@@ -74,6 +75,7 @@ const CompanyProfile = () => {
         alamat_lengkap_text: values.alamat_wajib_pajak,
         street: values.alamat_bisnis,
       };
+      console.log('data', data);
       const isUpdated = await odooApi(
         'PUT',
         `/api/v1/partner/${auth.parentId}`,
-- 
cgit v1.2.3


From 7d5f7d239231cdfc439a57930e315586b206a0e5 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 17 Sep 2024 15:53:06 +0700
Subject: <iman> update new register

---
 src/lib/auth/components/CompanyProfile.jsx | 2 --
 1 file changed, 2 deletions(-)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index f1577ca1..d4cf8657 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -24,7 +24,6 @@ const CompanyProfile = () => {
       alamat_bisnis: '',
     },
   });
-  console.log('auth', auth);
   const [industries, setIndustries] = useState([]);
   useEffect(() => {
     const loadIndustries = async () => {
@@ -75,7 +74,6 @@ const CompanyProfile = () => {
         alamat_lengkap_text: values.alamat_wajib_pajak,
         street: values.alamat_bisnis,
       };
-      console.log('data', data);
       const isUpdated = await odooApi(
         'PUT',
         `/api/v1/partner/${auth.parentId}`,
-- 
cgit v1.2.3


From fad165af76bb008076e96199f173fbe27b7835a8 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 18 Sep 2024 17:18:47 +0700
Subject: <iman> update alamat yang sama

---
 src/lib/auth/components/CompanyProfile.jsx | 40 ++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index d4cf8657..ee9c1f58 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -24,6 +24,45 @@ const CompanyProfile = () => {
       alamat_bisnis: '',
     },
   });
+
+  const formatNpwp = (value) => {
+    try {
+      const cleaned = ('' + value).replace(/\D/g, '');
+      let match;
+      if (cleaned.length <= 15) {
+        match = cleaned.match(
+          /(\d{0,2})?(\d{0,3})?(\d{0,3})?(\d{0,1})?(\d{0,3})?(\d{0,3})$/
+        );
+      } else {
+        match = cleaned.match(
+          /(\d{0,3})?(\d{0,3})?(\d{0,3})?(\d{0,1})?(\d{0,3})?(\d{0,3})$/
+        );
+      }
+
+      if (match) {
+        return [
+          match[1],
+          match[2] ? '.' : '',
+          match[2],
+          match[3] ? '.' : '',
+          match[3],
+          match[4] ? '.' : '',
+          match[4],
+          match[5] ? '-' : '',
+          match[5],
+          match[6] ? '.' : '',
+          match[6],
+        ].join('');
+      }
+
+      // If match is null, return the original cleaned string or handle as needed
+      return cleaned;
+    } catch (error) {
+      // Handle error or return a default value
+      console.error('Error formatting NPWP:', error);
+      return value;
+    }
+  };
   const [industries, setIndustries] = useState([]);
   useEffect(() => {
     const loadIndustries = async () => {
@@ -206,6 +245,7 @@ const CompanyProfile = () => {
                 {...register('npwp')}
                 type='text'
                 className='form-input mt-3'
+                maxLength={16}
               />
             </div>
           </div>
-- 
cgit v1.2.3


From ee88c2f776f5dbacfacb78d3a2f04155e0d93a15 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 20 Sep 2024 14:37:00 +0700
Subject: <iman> add error handling

---
 src/lib/auth/components/CompanyProfile.jsx | 86 +++++++++++++-----------------
 1 file changed, 38 insertions(+), 48 deletions(-)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index ee9c1f58..6d5790b4 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -7,62 +7,25 @@ import { useEffect, useState } from 'react';
 import { Controller, useForm } from 'react-hook-form';
 import { toast } from 'react-hot-toast';
 import BottomPopup from '@/core/components/elements/Popup/BottomPopup';
+import { yupResolver } from '@hookform/resolvers/yup';
+import * as Yup from 'yup';
 
 const CompanyProfile = () => {
   const [changeConfirmation, setChangeConfirmation] = useState(false);
   const auth = useAuth();
   const [isOpen, setIsOpen] = useState(false);
   const toggle = () => setIsOpen(!isOpen);
-  const { register, setValue, control, handleSubmit } = useForm({
-    defaultValues: {
-      industry: '',
-      companyType: '',
-      name: '',
-      taxName: '',
-      npwp: '',
-      alamat_wajib_pajak: '',
-      alamat_bisnis: '',
-    },
+  const {
+    register,
+    formState: { errors },
+    setValue,
+    control,
+    handleSubmit,
+  } = useForm({
+    resolver: yupResolver(validationSchema),
+    defaultValues,
   });
 
-  const formatNpwp = (value) => {
-    try {
-      const cleaned = ('' + value).replace(/\D/g, '');
-      let match;
-      if (cleaned.length <= 15) {
-        match = cleaned.match(
-          /(\d{0,2})?(\d{0,3})?(\d{0,3})?(\d{0,1})?(\d{0,3})?(\d{0,3})$/
-        );
-      } else {
-        match = cleaned.match(
-          /(\d{0,3})?(\d{0,3})?(\d{0,3})?(\d{0,1})?(\d{0,3})?(\d{0,3})$/
-        );
-      }
-
-      if (match) {
-        return [
-          match[1],
-          match[2] ? '.' : '',
-          match[2],
-          match[3] ? '.' : '',
-          match[3],
-          match[4] ? '.' : '',
-          match[4],
-          match[5] ? '-' : '',
-          match[5],
-          match[6] ? '.' : '',
-          match[6],
-        ].join('');
-      }
-
-      // If match is null, return the original cleaned string or handle as needed
-      return cleaned;
-    } catch (error) {
-      // Handle error or return a default value
-      console.error('Error formatting NPWP:', error);
-      return value;
-    }
-  };
   const [industries, setIndustries] = useState([]);
   useEffect(() => {
     const loadIndustries = async () => {
@@ -91,6 +54,7 @@ const CompanyProfile = () => {
   useEffect(() => {
     const loadProfile = async () => {
       const dataProfile = await addressApi({ id: auth.parentId });
+      console.log('dataProfile', dataProfile);
       setValue('name', dataProfile.name);
       setValue('industry', dataProfile.industryId);
       setValue('companyType', dataProfile.companyTypeId);
@@ -103,6 +67,7 @@ const CompanyProfile = () => {
   }, [auth, setValue]);
 
   const onSubmitHandler = async (values) => {
+    console.log('values', values);
     if (changeConfirmation) {
       const data = {
         ...values,
@@ -222,6 +187,9 @@ const CompanyProfile = () => {
                 type='text'
                 className='form-input mt-3'
               />
+              <div className='text-caption-2 text-danger-500 mt-1'>
+                {errors.taxName?.message}
+              </div>
             </div>
             <div>
               <label>Alamat Wajib Pajak</label>
@@ -230,6 +198,9 @@ const CompanyProfile = () => {
                 type='text'
                 className='form-input mt-3'
               />
+              <div className='text-caption-2 text-danger-500 mt-1'>
+                {errors.alamat_wajib_pajak?.message}
+              </div>
             </div>
             <div>
               <label>Alamat Bisnis</label>
@@ -238,6 +209,9 @@ const CompanyProfile = () => {
                 type='text'
                 className='form-input mt-3'
               />
+              <div className='text-caption-2 text-danger-500 mt-1'>
+                {errors.alamat_bisnis?.message}
+              </div>
             </div>
             <div>
               <label>Nomor NPWP</label>
@@ -259,3 +233,19 @@ const CompanyProfile = () => {
 };
 
 export default CompanyProfile;
+
+const validationSchema = Yup.object().shape({
+  alamat_bisnis: Yup.string().required('Harus di-isi'),
+  alamat_wajib_pajak: Yup.string().required('Harus di-isi'),
+  taxName: Yup.string().required('Harus di-isi'),
+});
+
+const defaultValues = {
+  industry: '',
+  companyType: '',
+  name: '',
+  taxName: '',
+  npwp: '',
+  alamat_wajib_pajak: '',
+  alamat_bisnis: '',
+};
-- 
cgit v1.2.3


From 5b0a6e9c8660c5cc427a66bd2540206513225075 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 20 Sep 2024 14:41:18 +0700
Subject: <iman> delete console log

---
 src/lib/auth/components/CompanyProfile.jsx | 2 --
 1 file changed, 2 deletions(-)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index 6d5790b4..80b424dc 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -54,7 +54,6 @@ const CompanyProfile = () => {
   useEffect(() => {
     const loadProfile = async () => {
       const dataProfile = await addressApi({ id: auth.parentId });
-      console.log('dataProfile', dataProfile);
       setValue('name', dataProfile.name);
       setValue('industry', dataProfile.industryId);
       setValue('companyType', dataProfile.companyTypeId);
@@ -67,7 +66,6 @@ const CompanyProfile = () => {
   }, [auth, setValue]);
 
   const onSubmitHandler = async (values) => {
-    console.log('values', values);
     if (changeConfirmation) {
       const data = {
         ...values,
-- 
cgit v1.2.3


From 09378e8389ad7dcca805e9dde10e26cf097ad97c Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 20 Sep 2024 14:50:01 +0700
Subject: <iman> update new register

---
 src/lib/auth/components/CompanyProfile.jsx | 3 +++
 1 file changed, 3 insertions(+)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index 80b424dc..9e1dd1f9 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -236,6 +236,9 @@ const validationSchema = Yup.object().shape({
   alamat_bisnis: Yup.string().required('Harus di-isi'),
   alamat_wajib_pajak: Yup.string().required('Harus di-isi'),
   taxName: Yup.string().required('Harus di-isi'),
+  npwp: Yup.string().required('Harus di-isi'),
+  industry: Yup.string().required('Harus di-pilih'),
+  companyType: Yup.string().required('Harus di-pilih'),
 });
 
 const defaultValues = {
-- 
cgit v1.2.3


From e7082aec2592932c8f27e4d191476b69aac7475b Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 20 Sep 2024 14:53:52 +0700
Subject: <iman> update

---
 src/lib/auth/components/CompanyProfile.jsx | 7 +++++++
 1 file changed, 7 insertions(+)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index 9e1dd1f9..606f56ea 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -176,6 +176,9 @@ const CompanyProfile = () => {
                   className='form-input'
                   placeholder='Cth: Indoteknik Dotcom Gemilang'
                 />
+                <div className='text-caption-2 text-danger-500 mt-1'>
+                  {errors.name?.message}
+                </div>
               </div>
             </div>
             <div>
@@ -219,6 +222,9 @@ const CompanyProfile = () => {
                 className='form-input mt-3'
                 maxLength={16}
               />
+              <div className='text-caption-2 text-danger-500 mt-1'>
+                {errors.npwp?.message}
+              </div>
             </div>
           </div>
           <button type='submit' className='btn-yellow w-full mt-6'>
@@ -237,6 +243,7 @@ const validationSchema = Yup.object().shape({
   alamat_wajib_pajak: Yup.string().required('Harus di-isi'),
   taxName: Yup.string().required('Harus di-isi'),
   npwp: Yup.string().required('Harus di-isi'),
+  name: Yup.string().required('Harus di-isi'),
   industry: Yup.string().required('Harus di-pilih'),
   companyType: Yup.string().required('Harus di-pilih'),
 });
-- 
cgit v1.2.3


From 1db54e16f970b4e09df89d432efd5a66ac775eb6 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 20 Sep 2024 14:55:40 +0700
Subject: <iman> update new register

---
 src/lib/auth/components/CompanyProfile.jsx | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'src/lib/auth/components/CompanyProfile.jsx')

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index 606f56ea..7bda992f 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -157,6 +157,9 @@ const CompanyProfile = () => {
                   <HookFormSelect {...props} options={industries} />
                 )}
               />
+              <div className='text-caption-2 text-danger-500 mt-1'>
+                {errors.industry?.message}
+              </div>
             </div>
             <div className='flex flex-wrap'>
               <div className='w-full mb-3'>Badan Usaha</div>
@@ -168,6 +171,9 @@ const CompanyProfile = () => {
                     <HookFormSelect {...props} options={companyTypes} />
                   )}
                 />
+                <div className='text-caption-2 text-danger-500 mt-1'>
+                  {errors.companyType?.message}
+                </div>
               </div>
               <div className='w-9/12 pl-1'>
                 <input
-- 
cgit v1.2.3

