diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-01-20 10:39:35 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-01-20 10:39:35 +0700 |
| commit | 00afe24409bf3cd517597e7c59cf1c12535c54c0 (patch) | |
| tree | 2e3e573ead141c8381e9b962b442de3a80f17529 /src/lib/auth/components/CompanyProfile.jsx | |
| parent | bd4cdf2125f717875ba90e03893b319dd962f753 (diff) | |
| parent | 389382046d804053d8e5c6de13d7d0b197175022 (diff) | |
Merge branch 'new-release' into feature/integrasi_biteship
# Conflicts:
# src/lib/address/components/CreateAddress.jsx
# src/lib/address/components/EditAddress.jsx
Diffstat (limited to 'src/lib/auth/components/CompanyProfile.jsx')
| -rw-r--r-- | src/lib/auth/components/CompanyProfile.jsx | 155 |
1 files changed, 131 insertions, 24 deletions
diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx index 7bda992f..410d6a23 100644 --- a/src/lib/auth/components/CompanyProfile.jsx +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -9,9 +9,14 @@ 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'; +import SwitchAccount from '@/lib/auth/components/SwitchAccount'; +import { Checkbox } from '@chakra-ui/react'; const CompanyProfile = () => { const [changeConfirmation, setChangeConfirmation] = useState(false); + const [changeType, setChangeType] = useState(false); + const [isChecked, setIsChecked] = useState(false); + const [company_type, setCompany_type] = useState('nonpkp'); const auth = useAuth(); const [isOpen, setIsOpen] = useState(false); const toggle = () => setIsOpen(!isOpen); @@ -53,14 +58,20 @@ const CompanyProfile = () => { 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); - setValue('alamat_bisnis', dataProfile.alamatBisnis); + const dataProfile = await addressApi({ + id: auth.parentId ? auth.parentId : auth.parent_id, + }); + setCompany_type(dataProfile?.companyType); + 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); + setValue('company_type', dataProfile?.companyType); + setValue('email_bisnis', dataProfile.email); + setValue('mobile_bisnis', dataProfile.mobile); }; if (auth) loadProfile(); }, [auth, setValue]); @@ -75,6 +86,8 @@ const CompanyProfile = () => { tax_name: values.taxName, alamat_lengkap_text: values.alamat_wajib_pajak, street: values.alamat_bisnis, + email: values.email_bisnis, + mobile: values.mobile_bisnis, }; const isUpdated = await odooApi( 'PUT', @@ -93,10 +106,49 @@ const CompanyProfile = () => { setChangeConfirmation(false); handleSubmit(onSubmitHandler)(); }; + const handleConfirmSubmitType = () => { + setChangeType(false); + setIsChecked(true); + setIsOpen(!isOpen); + }; + const handleChange = async () => { + if (isChecked) { + setIsChecked(!isChecked); + setIsOpen(!isOpen); + } else { + setIsChecked(!isChecked); + setChangeType(true); + } + }; return ( <> <BottomPopup + active={changeType} + close={() => setChangeType(false)} // Menutup popup + title='Ubah type akun' + > + <div className='leading-7 text-gray_r-12/80'> + Anda akan mengubah type akun anda? + </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={handleConfirmSubmitType} + > + Yakin + </button> + <button + className='btn-light flex-1 md:flex-none' + type='button' + onClick={() => setChangeType(false)} + > + Batal + </button> + </div> + </BottomPopup> + <BottomPopup active={changeConfirmation} close={() => setChangeConfirmation(true)} title='Ubah profil Bisnis' @@ -121,25 +173,37 @@ const CompanyProfile = () => { </button> </div> </BottomPopup> - <button - type='button' - onClick={toggle} - className='p-4 flex items-center text-left w-full' - > + <div className='p-4 flex-row items-center text-left w-full'> + {company_type === 'nonpkp' && ( + <div className='text-sm mb-2 flex items-center'> + <Checkbox + borderColor='gray.600' + colorScheme='red' + size='lg' + isChecked={isChecked} + onChange={handleChange} + /> + <p className='ml-2'>Ubah ke akun PKP</p> + </div> + )} <div> - <div className='font-semibold mb-2'>Informasi Usaha</div> + <div className='font-semibold mb-2 flex flex-row gap-x-2'> + <h2>Informasi Usaha</h2> + <div className='badge-red'>{company_type.toUpperCase()}</div> + </div> <div className='text-gray_r-11'> 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'> - {!isOpen && <ChevronDownIcon className='w-6' />} - {isOpen && <ChevronUpIcon className='w-6' />} - </div> - </button> - - {isOpen && ( + {/* <button + onClick={toggle} + className='btn-yellow w-full sm:w-fit sm:ml-auto min-w-[92px]' + > + Ubah + </button> */} + </div> + {!isOpen && ( <form className='p-4 border-t border-gray_r-6' onSubmit={(e) => { @@ -199,6 +263,28 @@ const CompanyProfile = () => { </div> </div> <div> + <label>Email Bisnis</label> + <input + {...register('email_bisnis')} + type='email' + className='form-input mt-3' + /> + <div className='text-caption-2 text-danger-500 mt-1'> + {errors.email_bisnis?.message} + </div> + </div> + <div> + <label>No. Handphone Bisnis</label> + <input + {...register('mobile_bisnis')} + type='tel' + className='form-input mt-3' + /> + <div className='text-caption-2 text-danger-500 mt-1'> + {errors.mobile_bisnis?.message} + </div> + </div> + <div> <label>Alamat Wajib Pajak</label> <input {...register('alamat_wajib_pajak')} @@ -238,6 +324,7 @@ const CompanyProfile = () => { </button> </form> )} + {isOpen && <SwitchAccount company_type={company_type} />} </> ); }; @@ -246,18 +333,38 @@ 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'), - npwp: Yup.string().required('Harus di-isi'), name: Yup.string().required('Harus di-isi'), + email_bisnis: Yup.string().required('Harus di-isi'), + mobile_bisnis: Yup.string().required('Harus di-isi'), industry: Yup.string().required('Harus di-pilih'), companyType: Yup.string().required('Harus di-pilih'), + taxName: Yup.string(), + npwp: Yup.string(), + alamat_wajib_pajak: Yup.string(), + company_type: Yup.string(), + taxName: Yup.string().when('company_type', { + is: (company_type) => company_type !== 'Non PKP', + then: Yup.string().required('Harus di-isi'), + otherwise: Yup.string().notRequired(), + }), + npwp: Yup.string().when('company_type', { + is: (company_type) => company_type !== 'Non PKP', + then: Yup.string().required('Harus di-isi'), + otherwise: Yup.string().notRequired(), + }), + alamat_wajib_pajak: Yup.string().when('company_type', { + is: (company_type) => company_type !== 'Non PKP', + then: Yup.string().required('Harus di-isi'), + otherwise: Yup.string().notRequired(), + }), }); const defaultValues = { industry: '', companyType: '', name: '', + email_bisnis: '', + mobile_bisnis: '', taxName: '', npwp: '', alamat_wajib_pajak: '', |
