diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-09-19 10:11:47 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-09-19 10:11:47 +0700 |
| commit | c651d654c2c87d26aab184025b7d0e4d8e74e65f (patch) | |
| tree | 24dce1314d503a638bd7e793876746a23f7f3a89 /src-migrate | |
| parent | 6d5ace9505543bcfbc5c830b86613fef00101cbd (diff) | |
<iman> fix otp send 3 times
Diffstat (limited to 'src-migrate')
| -rw-r--r-- | src-migrate/modules/register/components/Form.tsx | 57 | ||||
| -rw-r--r-- | src-migrate/modules/register/components/FormBisnis.tsx | 56 |
2 files changed, 4 insertions, 109 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 042bf507..5ee19e58 100644 --- a/src-migrate/modules/register/components/FormBisnis.tsx +++ b/src-migrate/modules/register/components/FormBisnis.tsx @@ -256,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', @@ -314,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 @@ -386,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-2' }`} - onSubmit={handleSubmit} > <div> <label htmlFor='email' className='font-bold'> |
