@@ -5,27 +5,30 @@ import { FormEvent, useEffect, useState } from 'react';
5
5
import { login } from 'service/auth' ;
6
6
import useAuthStore from 'store/useAuthStore.ts' ;
7
7
import Overay from '../ModalOveray.tsx' ;
8
+ import Toast from 'components/Toast.tsx' ;
8
9
9
10
export default function Login ( ) {
10
11
const { isOpen, toggleModal } = useLoginModalStore ( ) ;
11
12
const [ email , setEmail ] = useState ( '' ) ;
12
13
const [ password , setPassword ] = useState ( '' ) ;
13
14
const { setIsLogin } = useAuthStore ( ) ;
14
- const [ errorCode , setErrorCode ] = useState < number > ( 200 ) ;
15
15
16
16
useEffect ( ( ) => {
17
- setEmail ( '' ) ;
18
- setPassword ( '' ) ;
17
+ setEmail ( 'jindding ' ) ;
18
+ setPassword ( '1234 ' ) ;
19
19
} , [ isOpen ] ) ;
20
20
21
21
if ( ! isOpen ) return ;
22
22
23
23
const handleSubmit = async ( e : FormEvent < HTMLFormElement > ) => {
24
24
e . preventDefault ( ) ;
25
25
const res = await login ( email , password ) ;
26
+ if ( 'message' in res ) {
27
+ let message = '' ;
28
+ if ( res . statusCode === 401 ) message = '존재하지 않는 사용자입니다.' ;
29
+ else if ( res . statusCode === 400 ) message = '잘못된 입력형식입니다.' ;
26
30
27
- if ( 'error' in res ) {
28
- setErrorCode ( res . statusCode ) ;
31
+ Toast ( { message, type : 'error' } ) ;
29
32
return ;
30
33
}
31
34
@@ -40,8 +43,12 @@ export default function Login() {
40
43
import . meta. env . VITE_TEST_PW ,
41
44
) ;
42
45
43
- if ( 'error' in res ) {
44
- setErrorCode ( res . statusCode ) ;
46
+ if ( 'message' in res ) {
47
+ let message = '' ;
48
+ if ( res . statusCode === 401 ) message = '존재하지 않는 사용자입니다.' ;
49
+ else if ( res . statusCode === 400 ) message = '잘못된 입력형식입니다.' ;
50
+
51
+ Toast ( { message, type : 'error' } ) ;
45
52
return ;
46
53
}
47
54
@@ -58,17 +65,9 @@ export default function Login() {
58
65
< >
59
66
< Overay onClick = { ( ) => toggleModal ( ) } />
60
67
< section className = 'fixed left-1/2 top-1/2 flex w-[500px] -translate-x-1/2 -translate-y-1/2 flex-col rounded-2xl bg-white p-20 shadow-lg' >
61
- < h2 className = 'text-3xl font-bold' > JuGa</ h2 >
62
- < p className = 'my-3 h-5 text-sm font-semibold text-juga-red-60' >
63
- {
64
- {
65
- '401' : '존재하지 않는 사용자입니다.' ,
66
- '400' : '잘못된 입력형식입니다.' ,
67
- } [ errorCode ]
68
- }
69
- </ p >
70
- < form className = 'mb-2 flex flex-col' onSubmit = { handleSubmit } >
71
- < div className = 'my-10 flex flex-col gap-2' >
68
+ < h2 className = 'mb-5 text-3xl font-bold' > JuGa</ h2 >
69
+ < form className = 'flex flex-col mb-2' onSubmit = { handleSubmit } >
70
+ < div className = 'flex flex-col gap-2 my-10' >
72
71
< Input
73
72
type = 'text'
74
73
placeholder = '아이디'
@@ -84,7 +83,7 @@ export default function Login() {
84
83
autoComplete = 'current-password'
85
84
/>
86
85
</ div >
87
- < button className = 'rounded-3xl bg-juga-blue-40 py-2 text-white transition hover:bg-juga-blue-50' >
86
+ < button className = 'py-2 text-white transition rounded-3xl bg-juga-blue-40 hover:bg-juga-blue-50' >
88
87
로그인
89
88
</ button >
90
89
</ form >
0 commit comments