1
1
"use client" ;
2
2
3
- import { useEffect , useCallback } from "react" ;
4
- import { useSignInCtx } from "@/app/signin/hooks/use-sign-in" ;
5
- import { useSignInDispatch } from "@/app/signin/hooks/use-sign-in-dispatch" ;
6
- import { useRouter } from "next/navigation" ;
7
- import { useForm } from "react-hook-form" ;
8
- import { SignInSchema } from "@/app/signin/schemas/sign-in-schema" ;
9
- import { zodResolver } from "@hookform/resolvers/zod" ;
10
- import { getObjectErrors } from "@/app/utils/get-object-errors" ;
11
- import { SignInFormSchema } from "@/app/signin/interfaces/sign-in-form-schema" ;
3
+ import { useEffect } from "react" ;
12
4
import { SignIn } from "@/app/signin/components/index" ;
5
+ import { useSignInForm } from "@/app/signin/hooks/use-sign-in-form" ;
13
6
14
7
export function SignInForm ( ) {
15
- const router = useRouter ( ) ;
16
-
17
- const { error, success, showLoading, shouldOpenForgetPasswordModal } =
18
- useSignInCtx ( ) ;
19
-
20
- const { signInUser, setOpenForgetPasswordModal } = useSignInDispatch ( ) ;
21
-
22
8
const {
23
9
register,
24
10
handleSubmit,
25
- formState : { errors } ,
26
- } = useForm < SignInFormSchema > ( {
27
- resolver : zodResolver ( SignInSchema ) ,
28
- } ) ;
29
-
30
- const handleFormSubmit = ( data : SignInFormSchema ) => {
31
- const { success } = SignInSchema . safeParse ( data ) ;
32
-
33
- if ( success ) signInUser ( data ) ;
34
- } ;
35
-
36
- const handleSignUp = ( ) => {
37
- router . push ( "/signup" ) ;
38
- } ;
39
-
40
- const memoizedHandleSignIn = useCallback ( ( ) => {
41
- router . push ( "/about" ) ;
42
- } , [ router ] ) ;
11
+ errors,
12
+ handleFormSubmit,
13
+ memoizedHandleSignIn,
14
+ handleSignUp,
15
+ setOpenForgetPasswordModal,
16
+ getObjectErrors,
17
+ error,
18
+ success,
19
+ showLoading,
20
+ shouldOpenForgetPasswordModal,
21
+ } = useSignInForm ( ) ;
43
22
44
23
useEffect ( ( ) => {
45
24
if ( success !== null && success === true && error === null ) {
@@ -51,7 +30,7 @@ export function SignInForm() {
51
30
if ( errors ) {
52
31
getObjectErrors ( errors ) ;
53
32
}
54
- } , [ errors ] ) ;
33
+ } , [ errors , getObjectErrors ] ) ;
55
34
56
35
return (
57
36
< SignIn . Root >
0 commit comments