From 321e0c09be4b26d72b470407217262d10c88089d Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Wed, 22 Feb 2023 22:57:48 +0700
Subject: fix

---
 src/lib/auth/components/CompanyProfile.jsx | 97 ++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 src/lib/auth/components/CompanyProfile.jsx

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

diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
new file mode 100644
index 00000000..d66a0209
--- /dev/null
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -0,0 +1,97 @@
+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 { useForm } from 'react-hook-form'
+
+const PersonalProfile = () => {
+  const auth = useAuth()
+  const [isOpen, setIsOpen] = useState(false)
+  const toggle = () => setIsOpen(!isOpen)
+  const { register, setValue } = useForm({
+    defaultValues: {
+      email: '',
+      name: '',
+      mobile: '',
+      password: ''
+    }
+  })
+
+  useEffect(() => {
+    const loadProfile = async () => {
+      const dataProfile = await addressApi({ id: auth.partnerId })
+      setValue('email', dataProfile?.email)
+      setValue('name', dataProfile?.name)
+      setValue('mobile', dataProfile?.mobile)
+    }
+    if (auth) loadProfile()
+  }, [auth, setValue])
+
+  return (
+    <>
+      <button
+        type='button'
+        onClick={toggle}
+        className='p-4 flex items-center text-left'
+      >
+        <div>
+          <div className='font-semibold mb-2'>Informasi Akun</div>
+          <div className='text-gray_r-11'>
+            Dibawah ini adalah data diri yang anda masukkan, periksa kembali data diri anda
+          </div>
+        </div>
+        <div className='p-2 bg-gray_r-3 rounded'>
+          {!isOpen && <ChevronDownIcon className='w-6' />}
+          {isOpen && <ChevronUpIcon className='w-6' />}
+        </div>
+      </button>
+
+      {isOpen && (
+        <form className='p-4 border-t border-gray_r-6 flex flex-col gap-y-4'>
+          <div>
+            <label>Email</label>
+            <input
+              {...register('email')}
+              type='text'
+              disabled
+              className='form-input mt-3'
+            />
+          </div>
+          <div>
+            <label>Nama Lengkap</label>
+            <input
+              {...register('name')}
+              type='text'
+              className='form-input mt-3'
+            />
+          </div>
+          <div>
+            <label>No. Handphone</label>
+            <input
+              {...register('mobile')}
+              type='text'
+              className='form-input mt-3'
+            />
+          </div>
+          <div>
+            <label>Kata Sandi</label>
+            <input
+              {...register('password')}
+              type='password'
+              className='form-input mt-3'
+              placeholder='Isi jika ingin mengubah kata sandi'
+            />
+          </div>
+          <button
+            type='submit'
+            className='btn-yellow w-full'
+          >
+            Simpan
+          </button>
+        </form>
+      )}
+    </>
+  )
+}
+
+export default PersonalProfile
-- 
cgit v1.2.3


From 0de0fda98dc35bd6503f1a45a52878b154a94c75 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Thu, 23 Feb 2023 10:52:40 +0700
Subject: fox

---
 src/lib/auth/components/CompanyProfile.jsx | 120 +++++++++++++++++++++--------
 1 file changed, 86 insertions(+), 34 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 d66a0209..95575c87 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -1,32 +1,66 @@
+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 { useForm } from 'react-hook-form'
+import { Controller, useForm } from 'react-hook-form'
 
-const PersonalProfile = () => {
+const CompanyProfile = () => {
   const auth = useAuth()
   const [isOpen, setIsOpen] = useState(false)
   const toggle = () => setIsOpen(!isOpen)
-  const { register, setValue } = useForm({
+  const { register, setValue, control, handleSubmit } = useForm({
     defaultValues: {
-      email: '',
+      industry: '',
+      companyType: '',
       name: '',
-      mobile: '',
-      password: ''
+      taxName: '',
+      npwp: ''
     }
   })
 
+  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 [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()
+  }, [])
+
   useEffect(() => {
     const loadProfile = async () => {
-      const dataProfile = await addressApi({ id: auth.partnerId })
-      setValue('email', dataProfile?.email)
-      setValue('name', dataProfile?.name)
-      setValue('mobile', dataProfile?.mobile)
+      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)
     }
     if (auth) loadProfile()
   }, [auth, setValue])
 
+  const onSubmitHandler = async (values) => {
+    const data = {
+      ...values,
+      company_type_id: values.companyType,
+      industry_id: values.industry,
+      tax_name: values.taxName
+    };
+    const isUpdated = await odooApi('PUT', `/api/v1/partner/${auth.parentId}`, data)
+    console.log(isUpdated);
+  }
+
   return (
     <>
       <button
@@ -35,9 +69,9 @@ const PersonalProfile = () => {
         className='p-4 flex items-center text-left'
       >
         <div>
-          <div className='font-semibold mb-2'>Informasi Akun</div>
+          <div className='font-semibold mb-2'>Informasi Usaha</div>
           <div className='text-gray_r-11'>
-            Dibawah ini adalah data diri yang anda masukkan, periksa kembali data diri anda
+            Dibawah ini adalah data usaha yang anda masukkan, periksa kembali data usaha anda.
           </div>
         </div>
         <div className='p-2 bg-gray_r-3 rounded'>
@@ -47,44 +81,62 @@ const PersonalProfile = () => {
       </button>
 
       {isOpen && (
-        <form className='p-4 border-t border-gray_r-6 flex flex-col gap-y-4'>
+        <form className='p-4 border-t border-gray_r-6 flex flex-col gap-y-4' onSubmit={handleSubmit(onSubmitHandler)}>
           <div>
-            <label>Email</label>
-            <input
-              {...register('email')}
-              type='text'
-              disabled
-              className='form-input mt-3'
+            <label className='block mb-3'>Klasifikasi Jenis Usaha</label>
+            <Controller
+              name='industry'
+              control={control}
+              render={(props) => (
+                <HookFormSelect
+                  {...props}
+                  options={industries}
+                />
+              )}
             />
           </div>
-          <div>
-            <label>Nama Lengkap</label>
-            <input
-              {...register('name')}
-              type='text'
-              className='form-input mt-3'
-            />
+          <div className='flex flex-wrap'>
+            <div className='w-full mb-3'>Nama Usaha</div>
+            <div className='w-3/12 pr-1'>
+              <Controller
+                name='companyType'
+                control={control}
+                render={(props) => (
+                  <HookFormSelect
+                    {...props}
+                    options={companyTypes}
+                  />
+                )}
+              />
+            </div>
+            <div className='w-9/12 pl-1'>
+              <input
+                {...register('name')}
+                type='text'
+                className='form-input'
+                placeholder='Cth: Indoteknik Dotcom Gemilang'
+              />
+            </div>
           </div>
           <div>
-            <label>No. Handphone</label>
+            <label>Nama Wajib Pajak</label>
             <input
-              {...register('mobile')}
+              {...register('taxName')}
               type='text'
               className='form-input mt-3'
             />
           </div>
           <div>
-            <label>Kata Sandi</label>
+            <label>Nomor NPWP</label>
             <input
-              {...register('password')}
-              type='password'
+              {...register('npwp')}
+              type='text'
               className='form-input mt-3'
-              placeholder='Isi jika ingin mengubah kata sandi'
             />
           </div>
           <button
             type='submit'
-            className='btn-yellow w-full'
+            className='btn-yellow w-full mt-2'
           >
             Simpan
           </button>
@@ -94,4 +146,4 @@ const PersonalProfile = () => {
   )
 }
 
-export default PersonalProfile
+export default CompanyProfile
-- 
cgit v1.2.3


From 649f1a39cef2bf0d44dacd981747df29798d46d2 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Thu, 23 Feb 2023 11:19:25 +0700
Subject: fix

---
 src/lib/auth/components/CompanyProfile.jsx | 8 +++++++-
 1 file changed, 7 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 95575c87..f9f7fe13 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -5,6 +5,7 @@ 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'
 
 const CompanyProfile = () => {
   const auth = useAuth()
@@ -58,7 +59,12 @@ const CompanyProfile = () => {
       tax_name: values.taxName
     };
     const isUpdated = await odooApi('PUT', `/api/v1/partner/${auth.parentId}`, data)
-    console.log(isUpdated);
+    if (isUpdated?.id) {
+      setIsOpen(false)
+      toast.success('Berhasil mengubah profil', { duration: 1500 })
+      return
+    }
+    toast.error('Terjadi kesalahan internal')
   }
 
   return (
-- 
cgit v1.2.3


From ccf4174e7e2e8a3f4cc35f243695f900f2172bb4 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Thu, 23 Feb 2023 13:19:17 +0700
Subject: fixc

---
 src/lib/auth/components/CompanyProfile.jsx | 7 +++++--
 1 file changed, 5 insertions(+), 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 f9f7fe13..1b25551e 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -57,7 +57,7 @@ const CompanyProfile = () => {
       company_type_id: values.companyType,
       industry_id: values.industry,
       tax_name: values.taxName
-    };
+    }
     const isUpdated = await odooApi('PUT', `/api/v1/partner/${auth.parentId}`, data)
     if (isUpdated?.id) {
       setIsOpen(false)
@@ -87,7 +87,10 @@ const CompanyProfile = () => {
       </button>
 
       {isOpen && (
-        <form className='p-4 border-t border-gray_r-6 flex flex-col gap-y-4' onSubmit={handleSubmit(onSubmitHandler)}>
+        <form
+          className='p-4 border-t border-gray_r-6 flex flex-col gap-y-4'
+          onSubmit={handleSubmit(onSubmitHandler)}
+        >
           <div>
             <label className='block mb-3'>Klasifikasi Jenis Usaha</label>
             <Controller
-- 
cgit v1.2.3

