diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/auth/components/CompanyProfile.jsx | 69 |
1 files changed, 52 insertions, 17 deletions
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> |
