11import { FC , useState } from 'react' ;
22import { Button } from "@/components/@Shared/Buttons/Button" ;
33import { useForm } from 'react-hook-form' ;
4- import { axiosInstance } from '@/apis/instance/axiosInstance' ;
54import AuthInput from './AuthInput' ;
65import clsx from 'clsx' ;
7-
86import createValidations from './Validations' ;
97import { LoginFormData } from './AuthDtos' ;
108import Modal from './Modal' ;
119import useModalClose from './modalClose' ;
1210import axios from 'axios' ;
11+ import { useRoot } from '@/hook/useRoot' ;
1312
1413
1514const LoginForm : FC = ( ) => {
1615 const { register, handleSubmit, watch, trigger, formState : { errors } } = useForm < LoginFormData > ( { mode : 'onBlur' } ) ;
17- const [ isButtonValid , setIsButtonValid ] = useState < boolean > ( false ) ;
16+ const [ isButtonValid , setIsButtonValid ] = useState < boolean > ( false ) ;
1817 const [ modalOpen , setModalOpen ] = useState < boolean > ( false ) ;
1918 const [ modalMessage , setModalMessage ] = useState < string > ( '' ) ;
2019 const [ isLoginSuccess , setIsLoginSuccess ] = useState < boolean > ( true ) ;
20+ const { useLogin } = useRoot ( ) ;
2121 const Validations = createValidations ( watch ( 'password' ) ) ;
2222 const modalClose = useModalClose ( ) ;
2323 const handleBlur = async ( name : keyof LoginFormData ) => {
@@ -28,14 +28,7 @@ const LoginForm: FC = () => {
2828
2929 const onSubmit = async ( data : LoginFormData ) => {
3030 try {
31- const response = await axiosInstance . post ( '/auth/login' , data ) ;
32- console . log ( response . data ) ;
33- const { accessToken, refreshToken } = response . data ;
34-
35- console . log ( `엑세스토큰, 리프레시토큰 로컬스토리지에 저장` ) ;
36- localStorage . setItem ( 'accessToken' , accessToken ) ;
37- localStorage . setItem ( 'refreshToken' , refreshToken ) ;
38-
31+ await useLogin ( data ) ;
3932 setIsLoginSuccess ( true ) ;
4033 setModalMessage ( `로그인 성공` ) ;
4134 setModalOpen ( true ) ;
@@ -63,7 +56,6 @@ const LoginForm: FC = () => {
6356 < AuthInput label = "이메일" register = { register } name = "email" validation = { Validations . email } onBlur = { ( ) => handleBlur ( 'email' ) } errors = { errors } type = 'email' />
6457 < AuthInput label = "비밀번호" register = { register } name = "password" validation = { Validations . password } onBlur = { ( ) => handleBlur ( 'password' ) } errors = { errors } type = "password" />
6558 < Button variant = "solid" label = "로그인 하기" type = "submit" disabled = { ! isButtonValid } className = 'h-[48px]' />
66-
6759 </ form >
6860 ) ;
6961} ;
0 commit comments