summaryrefslogtreecommitdiff
path: root/src-migrate/modules/register/components/Form.tsx
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-09-18 14:39:16 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-09-18 14:39:16 +0700
commitb8b3b1df835d429920975e023d956b7c6ca33f43 (patch)
treed2488bf9c67d03ec5e9c686b17b0f994f3da6c77 /src-migrate/modules/register/components/Form.tsx
parentab0782b5cf7b65930b0b40528b9205f3f0dfc3a0 (diff)
parentbaa9b1e32c0afabf074f6c181274312d757a7099 (diff)
Merge branch 'Feature/new-register' into Feature/switch-account
Diffstat (limited to 'src-migrate/modules/register/components/Form.tsx')
-rw-r--r--src-migrate/modules/register/components/Form.tsx56
1 files changed, 49 insertions, 7 deletions
diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx
index 118d9d69..cd0b4343 100644
--- a/src-migrate/modules/register/components/Form.tsx
+++ b/src-migrate/modules/register/components/Form.tsx
@@ -1,4 +1,4 @@
-import { ChangeEvent, useMemo } from 'react';
+import { ChangeEvent, useMemo, useEffect, useRef, useState } from 'react';
import { useMutation } from 'react-query';
import { useRegisterStore } from '../stores/useRegisterStore';
import { RegisterProps } from '~/types/auth';
@@ -14,22 +14,28 @@ interface FormProps {
required: boolean;
isBisnisRegist: boolean;
chekValid: boolean;
+ buttonSubmitClick: boolean;
}
const Form: React.FC<FormProps> = ({
type,
required,
isBisnisRegist = false,
- chekValid = false,
+ chekValid,
+ buttonSubmitClick,
}) => {
const { form, isCheckedTNC, isValidCaptcha, errors, updateForm, validate } =
useRegisterStore();
-
const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]);
const router = useRouter();
const toast = useToast();
+ const emailRef = useRef<HTMLInputElement>(null);
+ const nameRef = useRef<HTMLInputElement>(null);
+ const passwordRef = useRef<HTMLInputElement>(null);
+ const phoneRef = useRef<HTMLInputElement>(null);
+
const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
const { name, value } = event.target;
updateForm(name, value);
@@ -40,6 +46,38 @@ const Form: React.FC<FormProps> = ({
mutationFn: (data: RegisterProps) => registerUser(data),
});
+ useEffect(() => {
+ const loadIndustries = async () => {
+ const response = await mutation.mutateAsync(form);
+ if (!response?.register) {
+ const options: ScrollIntoViewOptions = {
+ behavior: 'smooth',
+ block: 'center',
+ };
+
+ if (errors.email_partner && emailRef.current) {
+ emailRef.current.scrollIntoView(options);
+ return;
+ }
+ if (errors.name && nameRef.current) {
+ nameRef.current.scrollIntoView(options);
+ return;
+ }
+
+ if (errors.password && passwordRef.current) {
+ passwordRef.current.scrollIntoView(options);
+ return;
+ }
+
+ if (errors.phone && phoneRef.current) {
+ phoneRef.current.scrollIntoView(options);
+ return;
+ }
+ }
+ };
+ loadIndustries();
+ }, [buttonSubmitClick, chekValid]);
+
const handleSubmit = async (e: ChangeEvent<HTMLFormElement>) => {
e.preventDefault();
@@ -98,9 +136,10 @@ const Form: React.FC<FormProps> = ({
type='text'
id='name'
name='name'
- className='form-input mt-3'
+ className='form-input mt-3 transition-all duration-700'
placeholder='Masukan nama lengkap anda'
value={form.name}
+ ref={nameRef}
onChange={handleInputChange}
aria-invalid={chekValid && !!errors.name}
/>
@@ -119,9 +158,10 @@ const Form: React.FC<FormProps> = ({
type='text'
id='email'
name='email'
- className='form-input mt-3'
+ className='form-input mt-3 transition-all duration-500'
placeholder='Masukan alamat email anda'
value={form.email}
+ ref={emailRef}
onChange={handleInputChange}
autoComplete='username'
aria-invalid={chekValid && !!errors.email}
@@ -140,9 +180,10 @@ const Form: React.FC<FormProps> = ({
type='password'
name='password'
id='password'
- className='form-input mt-3'
+ className='form-input mt-3 transition-all duration-500'
placeholder='••••••••••••'
value={form.password}
+ ref={passwordRef}
onChange={handleInputChange}
autoComplete='current-password'
aria-invalid={chekValid && !!errors.password}
@@ -162,9 +203,10 @@ const Form: React.FC<FormProps> = ({
type='tel'
id='phone'
name='phone'
- className='form-input mt-3'
+ className='form-input mt-3 transition-all duration-500'
placeholder='08xxxxxxxx'
value={form.phone}
+ ref={phoneRef}
onChange={handleInputChange}
aria-invalid={chekValid && !!errors.phone}
/>