@@ -4,54 +4,82 @@ import LoginSignupInputBox from "../layout/input/LoginSignupInputBox";
4
4
import IsModal from "../modal/Modal" ;
5
5
import { useRef } from "react" ;
6
6
import { LoginApi } from "../../api/LoginApi" ;
7
+ import { useNavigate } from "react-router" ;
7
8
8
9
const InputEmail = ( ) => {
10
+ const navigator = useNavigate ( ) ;
9
11
const emailRef = useRef ( ) ;
10
12
const authenticationNumberRef = useRef ( ) ;
13
+ const emailRegulationExp =
14
+ / ^ [ a - z A - Z 0 - 9 + -\_ . ] + @ [ a - z A - Z 0 - 9 - ] + \. [ a - z A - Z 0 - 9 - .] + $ / ;
15
+
11
16
const [ style , setStyle ] = useState ( {
12
17
bgColorEmail : "bg-inputBox" ,
13
18
shadowEmail : "" ,
14
19
bgColorAuthenticationNumber : "bg-inputBox" ,
15
20
shadowAuthenticationNumber : "" ,
16
21
} ) ;
17
- const [ regulation , setRegulation ] = useState ( "" ) ;
22
+ const [ regulation , SetRegulation ] = useState ( {
23
+ emailError : "" ,
24
+ authenticationNumberError : "" ,
25
+ } ) ;
18
26
const [ isOpen , setOpen ] = useState ( false ) ;
19
27
const [ ModalStr , setModalStr ] = useState ( {
20
28
modalTitle : "" ,
21
29
modalMessage : "" ,
22
30
} ) ;
23
31
const [ isLoding , setIsLoding ] = useState ( false ) ;
24
- const [ InputCheck , setInputCheck ] = useState ( false ) ;
32
+ const [ InputCheck , setInputCheck ] = useState ( { input : false , modal : false } ) ;
33
+
25
34
const onModalOpen = ( ) => {
26
35
setOpen ( { isOpen : true } ) ;
27
36
} ;
28
37
const onMoalClose = ( ) => {
29
38
setOpen ( { isOpen : false } ) ;
39
+ if ( InputCheck . modal ) {
40
+ navigator ( "/ChangePassword" ) ;
41
+ }
30
42
} ;
31
43
32
44
const onInputColor = ( event ) => {
33
- const { id, value } = event . target ;
45
+ const { id } = event . target ;
46
+ const emailRefCurrent = emailRef . current ;
47
+ const authenticationNumberRefCurrent = authenticationNumberRef . current ;
34
48
if ( id === "email" ) {
35
49
console . log ( "email입니다" ) ;
36
50
setStyle ( ( ) => ( {
37
51
...style ,
38
52
bgColorEmail : "bg-inputBoxFocus" ,
39
53
shadowEmail : "drop-shadow-inputBoxShadow" ,
40
54
} ) ) ;
41
- if ( value . trim ( ) === "" ) {
55
+ if ( emailRefCurrent . value . trim ( ) === "" ) {
42
56
setStyle ( ( ) => ( {
43
57
...style ,
44
58
bgColorEmail : "bg-inputBox" ,
45
59
shadowEmail : "" ,
46
60
} ) ) ;
47
61
}
62
+ if ( emailRegulationExp . test ( emailRefCurrent . value ) ) {
63
+ SetRegulation ( ( ) => ( {
64
+ ...regulation ,
65
+ emailError : "" ,
66
+ } ) ) ;
67
+ } else {
68
+ SetRegulation ( ( ) => ( {
69
+ ...regulation ,
70
+ emailError : "올바른 이메일 형식이 아닙니다." ,
71
+ } ) ) ;
72
+
73
+ emailRefCurrent . focus ( ) ;
74
+ return ;
75
+ }
48
76
} else {
49
77
setStyle ( ( ) => ( {
50
78
...style ,
51
79
bgColorAuthenticationNumber : "bg-inputBoxFocus" ,
52
80
shadowAuthenticationNumber : "drop-shadow-inputBoxShadow" ,
53
81
} ) ) ;
54
- if ( value . trim ( ) === "" ) {
82
+ if ( authenticationNumberRefCurrent . value . trim ( ) === "" ) {
55
83
setStyle ( ( ) => ( {
56
84
...style ,
57
85
bgColorAuthenticationNumber : "bg-inputBox" ,
@@ -64,10 +92,19 @@ const InputEmail = () => {
64
92
const onSendEmail = ( ) => {
65
93
const email = emailRef . current ;
66
94
if ( email . value . trim ( ) === "" ) {
67
- setRegulation ( ( ) => "이메일을 입력해주세요" ) ;
95
+ SetRegulation ( ( ) => ( {
96
+ ...regulation ,
97
+ emailError : "이메일을 입력해주세요" ,
98
+ } ) ) ;
99
+ email . focus ( ) ;
100
+ return ;
68
101
} else {
69
- setRegulation ( ( ) => "" ) ;
102
+ SetRegulation ( ( ) => ( {
103
+ ...regulation ,
104
+ emailError : "" ,
105
+ } ) ) ;
70
106
}
107
+
71
108
sendEmail ( { email : email . value } ) ;
72
109
} ;
73
110
@@ -77,11 +114,15 @@ const InputEmail = () => {
77
114
onModalOpen ( ) ;
78
115
const data = await LoginApi . SendEmailAuthenticationNumber ( payload ) ;
79
116
setIsLoding ( ( ) => false ) ;
80
- setModalStr ( {
81
- modalTitle : "이메일함을 확인해주세요" ,
82
- modalMessage : "인증번호를 입력해주세요" ,
83
- } ) ;
84
- setInputCheck ( ( ) => true ) ;
117
+ console . log ( data ) ;
118
+ if ( data . status === 200 ) {
119
+ sessionStorage . setItem ( "changePasswordEmail" , payload . email ) ;
120
+ setModalStr ( {
121
+ modalTitle : "이메일함을 확인해주세요" ,
122
+ modalMessage : "인증번호를 입력해주세요" ,
123
+ } ) ;
124
+ setInputCheck ( ( ) => ( { ...InputCheck , input : true } ) ) ;
125
+ }
85
126
} catch ( error ) {
86
127
console . log ( error . response ) ;
87
128
const { data } = error . response ;
@@ -100,16 +141,34 @@ const InputEmail = () => {
100
141
const authenticationNumber = authenticationNumberRef . current ;
101
142
102
143
if ( email . value . trim ( ) === "" ) {
103
- setRegulation ( ( ) => "이메일을 입력해주세요" ) ;
144
+ SetRegulation ( ( ) => ( {
145
+ ...regulation ,
146
+ emailError : "이메일을 입력해주세요" ,
147
+ } ) ) ;
104
148
email . focus ( ) ;
105
149
return ;
106
- } else if ( authenticationNumber . value . trim ( ) === "" ) {
107
- setRegulation ( ( ) => "인증번호를 입력해주세요" ) ;
150
+ } else {
151
+ SetRegulation ( ( ) => ( {
152
+ ...regulation ,
153
+ emailError : "" ,
154
+ } ) ) ;
155
+ }
156
+
157
+ if ( authenticationNumber . value . trim ( ) === "" ) {
158
+ SetRegulation ( ( ) => ( {
159
+ ...regulation ,
160
+ authenticationNumberError : "인증번호를 입력해주세요" ,
161
+ } ) ) ;
108
162
authenticationNumber . focus ( ) ;
109
163
return ;
164
+ } else {
165
+ SetRegulation ( ( ) => ( {
166
+ ...regulation ,
167
+ authenticationNumberError : "" ,
168
+ } ) ) ;
110
169
}
111
170
112
- if ( InputCheck ) {
171
+ if ( InputCheck . input ) {
113
172
onSubmitNextPageAxios ( {
114
173
email : email . value ,
115
174
code : authenticationNumber . value ,
@@ -121,18 +180,27 @@ const InputEmail = () => {
121
180
try {
122
181
setIsLoding ( ( ) => true ) ;
123
182
onModalOpen ( ) ;
124
- const data = await LoginApi . SendAuthenticationNumber ( payload ) ;
183
+ const { data } = await LoginApi . SendAuthenticationNumber ( payload ) ;
125
184
setIsLoding ( ( ) => false ) ;
126
185
console . log ( data ) ;
186
+ if ( data . status === 200 ) {
187
+ setModalStr ( {
188
+ ...ModalStr ,
189
+ modalTitle : data . message ,
190
+ modalMessage : "" ,
191
+ } ) ;
192
+ setInputCheck ( ( ) => ( { ...InputCheck , modal : true } ) ) ;
193
+ }
127
194
} catch ( error ) {
128
195
console . log ( error . response ) ;
129
196
const { data } = error . response ;
130
197
if ( data . status === 400 ) {
131
198
setIsLoding ( ( ) => false ) ;
132
- setModalStr ( {
199
+ setModalStr ( ( ) => ( {
200
+ ...ModalStr ,
133
201
modalTitle : "인증번호 실패" ,
134
202
modalMessage : `인증번호가 잘못 입력되었습니다. \n 인증요청을 재시도 해주세요.` ,
135
- } ) ;
203
+ } ) ) ;
136
204
}
137
205
}
138
206
} ;
@@ -157,14 +225,18 @@ const InputEmail = () => {
157
225
/>
158
226
< div
159
227
onClick = { onSendEmail }
228
+ << << << < Updated upstream
160
229
className = " bg-[#FFFFFF] flex items-center h-[50px] p-[5px] border-solid border-2 text-[16px] font-[600] border-[#002C51] rounded-[4px] leading-[28px] cursor-pointer"
230
+ = === ===
231
+ className = "bg-[#FFFFFF] h-[50px] flex items-center border-solid border-2 text-[16px] font-[600] border-[#002C51] p-[5px] rounded-[4px] cursor-pointer"
232
+ > >>> >>> Stashed changes
161
233
>
162
234
인증 요청
163
235
</ div >
164
236
</ div >
165
237
< div className = "flex items-center h-[20px]" >
166
238
< p className = " w-full font-[500] text-[16px] text-[#DE0D0D] flex items-center" >
167
- { regulation }
239
+ { regulation . emailError }
168
240
</ p >
169
241
</ div >
170
242
< div className = "h-[full]" >
@@ -178,6 +250,11 @@ const InputEmail = () => {
178
250
ref = { authenticationNumberRef }
179
251
/>
180
252
</ div >
253
+ < div className = "flex items-center h-[20px]" >
254
+ < p className = " w-full font-[500] text-[16px] text-[#DE0D0D] flex items-center" >
255
+ { regulation . authenticationNumberError }
256
+ </ p >
257
+ </ div >
181
258
</ div >
182
259
< div >
183
260
< button
0 commit comments