summaryrefslogtreecommitdiff
path: root/src/lib/auth
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/auth')
-rw-r--r--src/lib/auth/components/CompanyProfile.jsx77
-rw-r--r--src/lib/auth/components/PersonalProfile.jsx2
-rw-r--r--src/lib/auth/components/SwitchAccount.jsx32
3 files changed, 96 insertions, 15 deletions
diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
index 2daec766..e1a604c2 100644
--- a/src/lib/auth/components/CompanyProfile.jsx
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -9,10 +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 [company_type, setCompany_type] = useState();
+ const [changeType, setChangeType] = useState(false);
+ const [isChecked, setIsChecked] = useState(false);
+ const [company_type, setCompany_type] = useState('Non PKP');
const auth = useAuth();
const [isOpen, setIsOpen] = useState(false);
const toggle = () => setIsOpen(!isOpen);
@@ -98,10 +102,47 @@ const CompanyProfile = () => {
setChangeConfirmation(false);
handleSubmit(onSubmitHandler)();
};
+ const handleConfirmSubmitType = () => {
+ setChangeType(false);
+ setIsChecked(true);
+ setIsOpen(!isOpen);
+ };
+ const handleChange = async () => {
+ if (isChecked) {
+ setIsChecked(!isChecked);
+ } else {
+ 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'
@@ -126,11 +167,19 @@ 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 === 'Non PKP' && (
+ <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 flex flex-row gap-x-2'>
<h2>Informasi Usaha</h2>
@@ -141,13 +190,14 @@ const CompanyProfile = () => {
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) => {
@@ -246,6 +296,7 @@ const CompanyProfile = () => {
</button>
</form>
)}
+ {isOpen && <SwitchAccount />}
</>
);
};
diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx
index 727785bf..ce27c650 100644
--- a/src/lib/auth/components/PersonalProfile.jsx
+++ b/src/lib/auth/components/PersonalProfile.jsx
@@ -109,7 +109,7 @@ const PersonalProfile = () => {
</div>
<button
type='submit'
- className='btn-yellow w-full sm:w-fit sm:ml-auto mt-6'
+ className='btn-yellow w-full sm:w-fit sm:ml-auto mt-6 max-w-28'
>
Simpan
</button>
diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx
index 18c6076f..ad22da0f 100644
--- a/src/lib/auth/components/SwitchAccount.jsx
+++ b/src/lib/auth/components/SwitchAccount.jsx
@@ -69,7 +69,26 @@ const SwitchAccount = () => {
validate();
}
}, [isTerdaftar]);
-
+ useEffect(() => {
+ const loadProfile = async () => {
+ const dataProfile = await addressApi({
+ id: auth.parentId ? auth.parentId : auth.parent_id,
+ });
+ if (dataProfile.companyType === 'Non PKP') {
+ setSelectedValue('PKP');
+ }
+ updateForm('email_partner', dataProfile.email_partner);
+ updateForm('business_name', dataProfile.name);
+ updateForm('industry_id', dataProfile.industryId);
+ updateForm('company_type_id', dataProfile.companyTypeId);
+ updateForm('nama_wajib_pajak', dataProfile.taxName);
+ updateForm('npwp', dataProfile.npwp);
+ updateForm('alamat_wajib_pajak', dataProfile.alamatWajibPajak);
+ updateForm('alamat_bisnis', dataProfile.alamatBisnis);
+ validate();
+ };
+ if (auth) loadProfile();
+ }, [auth, setValue]);
useEffect(() => {
updateForm('name', '-');
updateForm('email', 'example@mail.com');
@@ -125,6 +144,10 @@ const SwitchAccount = () => {
toast.error('Terjadi kesalahan internal');
};
+ const onSubmitHandlerCancel = async (values) => {
+ window.location.reload();
+ };
+
return (
<>
<button
@@ -191,6 +214,13 @@ const SwitchAccount = () => {
<div className='flex justify-end mb-4 mr-4'>
<button
type='submit'
+ onClick={onSubmitHandlerCancel}
+ className='btn-red w-full sm:w-fit sm:ml-auto mt-6'
+ >
+ {mutation.isLoading ? 'Loading...' : 'Batal'}
+ </button>
+ <button
+ type='submit'
onClick={onSubmitHandler}
className='btn-yellow w-full sm:w-fit sm:ml-auto mt-6'
>