11import styles from './SigninForm.module.css' ;
2- import { ChangeEvent , FocusEvent , FormEvent , useEffect , useState } from 'react' ;
2+ import { ChangeEvent , FocusEvent , FormEvent , useState } from 'react' ;
33import { useRouter } from 'next/router' ;
44import { useDispatch } from 'react-redux' ;
55import { setUserInfo } from '@/redux/settingSlice' ;
@@ -32,36 +32,18 @@ function SignupForm() {
3232 const [ passwordValid , setPasswordValid ] = useState ( false ) ;
3333 const [ nicknameValid , setNicknameValid ] = useState ( false ) ;
3434 const [ passwordCheckValid , setPasswordCheckValid ] = useState ( false ) ;
35- const [ disabled , setDisabled ] = useState ( true ) ;
3635 const [ isModalVisible , setIsModalVisible ] = useState ( false ) ;
3736 const [ responseMessage , setResponseMessage ] = useState ( '' ) ;
3837 const router = useRouter ( ) ;
3938 const dispatch = useDispatch < AppDispatch > ( ) ;
4039
41- useEffect ( ( ) => {
42- const isEmailValid = emailValidation ( values . email ) ;
43- const isPasswordValid = passwordValidation ( values . password ) ;
44- const isNicknameValid = nicknameValidation ( values . nickname ) ;
45- const isPasswordCheckValid = passwordCheckValidation (
46- values . password ,
47- values . passwordCheck ,
48- ) ;
49- setDisabled (
50- ! (
51- isEmailValid &&
52- isPasswordValid &&
53- ! isNicknameValid &&
54- ! isPasswordCheckValid &&
55- values . checkbox
56- ) ,
57- ) ;
58- } , [ values ] ) ;
59-
60- useEffect ( ( ) => {
61- if ( sessionStorage . getItem ( 'accessToken' ) ) {
62- router . push ( '/mydashboard' ) ;
63- }
64- } , [ ] ) ;
40+ const isEmailValid = emailValidation ( values . email ) ;
41+ const isPasswordValid = passwordValidation ( values . password ) ;
42+ const isNicknameValid = nicknameValidation ( values . nickname ) ;
43+ const isPasswordCheckValid = passwordCheckValidation (
44+ values . password ,
45+ values . passwordCheck ,
46+ ) ;
6547
6648 const handleChange = ( e : ChangeEvent < HTMLInputElement > ) => {
6749 const { name, type, value, checked } = e . target ;
@@ -102,19 +84,14 @@ function SignupForm() {
10284 user : response . user ,
10385 } ) ,
10486 ) ;
105-
87+ alert ( ` ${ values . nickname } 님 가입이 완료되었습니다.` ) ;
10688 router . push ( '/mydashboard' ) ;
10789 } catch ( error ) {
10890 setResponseMessage ( error . message ) ;
10991 setIsModalVisible ( true ) ;
11092 }
11193 } ;
11294
113- const handleCancelClick = ( ) => {
114- setIsModalVisible ( false ) ;
115- setResponseMessage ( null ) ;
116- } ;
117-
11895 return (
11996 < >
12097 < form onSubmit = { onSubmit } >
@@ -187,7 +164,19 @@ function SignupForm() {
187164 />
188165
189166 < div className = { styles [ 'login-button' ] } >
190- < CDSButton btnType = "auth" type = "submit" disabled = { disabled } >
167+ < CDSButton
168+ btnType = "auth"
169+ type = "submit"
170+ disabled = {
171+ ! (
172+ isEmailValid &&
173+ isPasswordValid &&
174+ ! isNicknameValid &&
175+ ! isPasswordCheckValid &&
176+ values . checkbox
177+ )
178+ }
179+ >
191180 가입하기
192181 </ CDSButton >
193182 </ div >
@@ -196,7 +185,10 @@ function SignupForm() {
196185 { isModalVisible && (
197186 < AuthModal
198187 message = { responseMessage }
199- handleCancelClick = { handleCancelClick }
188+ handleCancelClick = { ( ) => {
189+ setIsModalVisible ( false ) ;
190+ setResponseMessage ( null ) ;
191+ } }
200192 />
201193 ) }
202194 </ >
0 commit comments