From 09e45bafb7d4a0522643ee3b188ae18b82fb27bb Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 1 Oct 2024 13:31:45 +0700 Subject: update switch account --- src/lib/auth/components/SwitchAccount.jsx | 37 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/lib/auth/components') diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index 12d00890..9adcc726 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -39,8 +39,15 @@ const SwitchAccount = ({ company_type }) => { mutationFn: (data) => registerUser(data), }); const [notValid, setNotValid] = useState(false); - const { form, isCheckedTNC, isValidCaptcha, errors, validate, updateForm } = - useRegisterStore(); + const { + form, + isCheckedTNC, + isValidCaptcha, + errors, + validate, + updateForm, + resetForm, + } = useRegisterStore(); const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); useEffect(() => { const loadProfile = async () => { @@ -79,15 +86,17 @@ const SwitchAccount = ({ company_type }) => { if (dataProfile?.companyType === 'nonpkp') { 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?.company) { + 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]); @@ -97,9 +106,10 @@ const SwitchAccount = ({ company_type }) => { updateForm('password', 'example@mail.com'); updateForm('phone', '081234567890'); validate(); - }, []); + }, [buttonSubmitClick, changeConfirmation]); const handleChangeBisnis = (value) => { + resetForm(); setSelectedValueBisnis(value); if (value === 'true') { validate(); @@ -121,9 +131,12 @@ const SwitchAccount = ({ company_type }) => { } }; const onSubmitHandler = async (values) => { + console.log('error', errors); + console.log('form', form); setChangeConfirmation(false); // let data = { ...form, id: `${auth.partnerId}` }; const data = form; + console.log('data', data); if (!isFormValid) { setNotValid(true); setButtonSubmitClick(!buttonSubmitClick); -- cgit v1.2.3