diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-09-23 09:22:29 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-09-23 09:22:29 +0700 |
| commit | c13bb5c6f78032695b24cf8a6c23942eb465c6d5 (patch) | |
| tree | e48c1ab39a61fd5702f578fbfdb7a7375cc1ce43 /src-migrate/modules/register/components | |
| parent | 870bede9df9920b23f2e5cb771ff5ae6448e3ac7 (diff) | |
| parent | 4bd29979c34c1ec3b31dd384829b008eb726769c (diff) | |
Merge branch 'Feature/new-register' into Feature/switch-account
Diffstat (limited to 'src-migrate/modules/register/components')
| -rw-r--r-- | src-migrate/modules/register/components/Form.tsx | 57 | ||||
| -rw-r--r-- | src-migrate/modules/register/components/FormBisnis.tsx | 73 |
2 files changed, 20 insertions, 110 deletions
diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx index cd0b4343..38e9c810 100644 --- a/src-migrate/modules/register/components/Form.tsx +++ b/src-migrate/modules/register/components/Form.tsx @@ -41,15 +41,9 @@ const Form: React.FC<FormProps> = ({ updateForm(name, value); validate(); }; - - const mutation = useMutation({ - mutationFn: (data: RegisterProps) => registerUser(data), - }); - useEffect(() => { const loadIndustries = async () => { - const response = await mutation.mutateAsync(form); - if (!response?.register) { + if (!isFormValid) { const options: ScrollIntoViewOptions = { behavior: 'smooth', block: 'center', @@ -78,55 +72,8 @@ const Form: React.FC<FormProps> = ({ loadIndustries(); }, [buttonSubmitClick, chekValid]); - const handleSubmit = async (e: ChangeEvent<HTMLFormElement>) => { - e.preventDefault(); - - const response = await mutation.mutateAsync(form); - - if (response?.register === true) { - const urlParams = new URLSearchParams({ - activation: 'otp', - email: form.email, - redirect: (router.query?.next || '/') as string, - }); - router.push(`${router.route}?${urlParams}`); - } - - const toastProps: UseToastOptions = { - duration: 5000, - isClosable: true, - position: 'top', - }; - - switch (response?.reason) { - case 'EMAIL_USED': - toast({ - ...toastProps, - title: 'Email sudah digunakan', - status: 'warning', - }); - break; - case 'NOT_ACTIVE': - const activationUrl = `${router.route}?activation=email`; - toast({ - ...toastProps, - title: 'Akun belum aktif', - description: ( - <> - Akun sudah terdaftar namun belum aktif.{' '} - <Link href={activationUrl} className='underline'> - Klik untuk aktivasi akun - </Link> - </> - ), - status: 'warning', - }); - break; - } - }; - return ( - <form className='mt-6 grid grid-cols-1 gap-y-4' onSubmit={handleSubmit}> + <form className='mt-6 grid grid-cols-1 gap-y-4'> <div> <label htmlFor='name' className='text-black font-bold'> Nama Lengkap diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx index b81ca601..88a2f0b0 100644 --- a/src-migrate/modules/register/components/FormBisnis.tsx +++ b/src-migrate/modules/register/components/FormBisnis.tsx @@ -128,9 +128,23 @@ const form: React.FC<FormProps> = ({ const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => { const { name, value } = event.target; - updateForm('type_acc', `business`); + + updateForm('type_acc', 'business'); updateForm('is_pkp', `${isPKP}`); + + // Update form dengan nilai terbaru dari input yang berubah updateForm(name, value); + + // Jika checkbox aktif, sinkronisasi alamat_wajib_pajak dengan alamat_bisnis + if (isChekBox) { + if (name === 'alamat_wajib_pajak') { + updateForm('alamat_bisnis', value); + } else if (name === 'alamat_bisnis') { + updateForm('alamat_wajib_pajak', value); + } + } + + // Validasi setelah perubahan dilakukan validate(); }; @@ -188,6 +202,7 @@ const form: React.FC<FormProps> = ({ useEffect(() => { if (isChekBox) { updateForm('isChekBox', 'true'); + updateForm('alamat_wajib_pajak', `${form.alamat_bisnis}`); validate(); } else { updateForm('isChekBox', 'false'); @@ -241,15 +256,11 @@ const form: React.FC<FormProps> = ({ validate(); // Perform form validation } }; - - const mutation = useMutation({ - mutationFn: (data: RegisterProps) => registerUser(data), - }); + const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); useEffect(() => { const loadIndustries = async () => { - const response = await mutation.mutateAsync(form); - if (!response?.register) { + if (!isFormValid) { const options: ScrollIntoViewOptions = { behavior: 'smooth', block: 'center', @@ -299,53 +310,6 @@ const form: React.FC<FormProps> = ({ }; loadIndustries(); }, [buttonSubmitClick, chekValid]); - - const handleSubmit = async (e: ChangeEvent<HTMLFormElement>) => { - e.preventDefault(); - - const response = await mutation.mutateAsync(form); - - if (response?.register === true) { - const urlParams = new URLSearchParams({ - activation: 'otp', - email: form.email, - redirect: (router.query?.next || '/') as string, - }); - router.push(`${router.route}?${urlParams}`); - } - - const toastProps: UseToastOptions = { - duration: 5000, - isClosable: true, - position: 'top', - }; - - switch (response?.reason) { - case 'EMAIL_USED': - toast({ - ...toastProps, - title: 'Email sudah digunakan', - status: 'warning', - }); - break; - case 'NOT_ACTIVE': - const activationUrl = `${router.route}?activation=email`; - toast({ - ...toastProps, - title: 'Akun belum aktif', - description: ( - <> - Akun sudah terdaftar namun belum aktif.{' '} - <Link href={activationUrl} className='underline'> - Klik untuk aktivasi akun - </Link> - </> - ), - status: 'warning', - }); - break; - } - }; return ( <> <BottomPopup @@ -371,7 +335,6 @@ const form: React.FC<FormProps> = ({ ? 'mt-6 grid grid-cols-1 gap-y-4' : 'mt-6 grid grid-cols-2 gap-x-4 gap-y-6 auto-rows-min' }`} - onSubmit={handleSubmit} > <div> <label htmlFor='email' className='font-bold'> |
