@@ -3,15 +3,24 @@ import Label from "../layout/Label";
3
3
import LoginSignupInputBox from "../layout/input/LoginSignupInputBox" ;
4
4
import IsModal from "../modal/Modal" ;
5
5
import { useRef } from "react" ;
6
- import { LoginApi } from "../../api/LoginApi" ;
7
6
import { useNavigate } from "react-router" ;
7
+ import { useDispatch , useSelector } from "react-redux" ;
8
+ import {
9
+ __sendEmail ,
10
+ __NextPage ,
11
+ resetCheck ,
12
+ } from "../../redux/modules/LoginSlice" ;
13
+ import { __openModal , __closeModal } from "../../redux/modules/SingupSlice" ;
14
+ import { useEffect } from "react" ;
8
15
9
16
const InputEmail = ( ) => {
10
17
const navigator = useNavigate ( ) ;
18
+ const dispatch = useDispatch ( ) ;
19
+
11
20
const emailRef = useRef ( ) ;
12
21
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 - . ] + $ / ;
22
+
23
+ const { isLoading } = useSelector ( ( state ) => state . LoginSlice ) ;
15
24
16
25
const [ style , setStyle ] = useState ( {
17
26
bgColorEmail : "bg-inputBox" ,
@@ -21,40 +30,38 @@ const InputEmail = () => {
21
30
emailError : "" ,
22
31
authenticationNumberError : "" ,
23
32
} ) ;
24
- const [ isOpen , setOpen ] = useState ( false ) ;
25
33
const [ ModalStr , setModalStr ] = useState ( {
26
34
modalTitle : "" ,
27
35
modalMessage : "" ,
28
36
} ) ;
29
- const [ isLoding , setIsLoding ] = useState ( false ) ;
30
- const [ InputCheck , setInputCheck ] = useState ( { input : false , modal : false } ) ;
31
37
32
- const onModalOpen = ( ) => {
33
- setOpen ( { isOpen : true } ) ;
34
- } ;
38
+ const { emailCheck , authenticationNumberCheck } = useSelector (
39
+ ( state ) => state . LoginSlice . check
40
+ ) ;
35
41
const onMoalClose = ( ) => {
36
- setOpen ( { isOpen : false } ) ;
37
- if ( InputCheck . modal ) {
42
+ dispatch ( __closeModal ( ) ) ;
43
+ if ( authenticationNumberCheck ) {
38
44
navigator ( "/ChangePassword" ) ;
39
45
}
40
46
} ;
41
47
42
48
const onInputColor = ( event ) => {
43
- const { id } = event . target ;
44
- const emailRefCurrent = emailRef . current ;
45
- const authenticationNumberRefCurrent = authenticationNumberRef . current ;
49
+ const { id, value } = event . target ;
50
+ const emailRegulationExp =
51
+ / ^ [ a - z A - Z 0 - 9 + -\_ . ] + @ [ a - z A - Z 0 - 9 - ] + \. [ a - z A - Z 0 - 9 - .] + $ / ;
52
+
46
53
if ( id === "email" ) {
47
54
setStyle ( ( ) => ( {
48
55
...style ,
49
56
bgColorEmail : "bg-inputBoxFocus" ,
50
57
} ) ) ;
51
- if ( emailRefCurrent . value . trim ( ) === "" ) {
58
+ if ( value === "" ) {
52
59
setStyle ( ( ) => ( {
53
60
...style ,
54
61
bgColorEmail : "bg-inputBox" ,
55
62
} ) ) ;
56
63
}
57
- if ( emailRegulationExp . test ( emailRefCurrent . value ) ) {
64
+ if ( emailRegulationExp . test ( value ) ) {
58
65
SetRegulation ( ( ) => ( {
59
66
...regulation ,
60
67
emailError : "" ,
@@ -64,20 +71,20 @@ const InputEmail = () => {
64
71
...regulation ,
65
72
emailError : "올바른 이메일 형식이 아닙니다." ,
66
73
} ) ) ;
67
-
68
- emailRefCurrent . focus ( ) ;
74
+ event . target . focus ( ) ;
69
75
return ;
70
76
}
71
77
} else {
72
- setStyle ( ( ) => ( {
73
- ...style ,
74
- bgColorAuthenticationNumber : "bg-inputBoxFocus" ,
75
- } ) ) ;
76
- if ( authenticationNumberRefCurrent . value . trim ( ) === "" ) {
78
+ if ( value . trim ( ) === "" ) {
77
79
setStyle ( ( ) => ( {
78
80
...style ,
79
81
bgColorAuthenticationNumber : "bg-inputBox" ,
80
82
} ) ) ;
83
+ } else {
84
+ setStyle ( ( ) => ( {
85
+ ...style ,
86
+ bgColorAuthenticationNumber : "bg-inputBoxFocus" ,
87
+ } ) ) ;
81
88
}
82
89
}
83
90
} ;
@@ -98,33 +105,14 @@ const InputEmail = () => {
98
105
} ) ) ;
99
106
}
100
107
101
- sendEmail ( { email : email . value } ) ;
102
- } ;
103
-
104
- const sendEmail = async ( payload ) => {
105
- try {
106
- setIsLoding ( ( ) => true ) ;
107
- onModalOpen ( ) ;
108
- const data = await LoginApi . SendEmailAuthenticationNumber ( payload ) ;
109
- setIsLoding ( ( ) => false ) ;
110
- if ( data . status === 200 ) {
111
- sessionStorage . setItem ( "changePasswordEmail" , payload . email ) ;
112
- setModalStr ( {
113
- modalTitle : "이메일함을 확인해주세요" ,
114
- modalMessage : "인증번호를 입력해주세요" ,
115
- } ) ;
116
- setInputCheck ( ( ) => ( { ...InputCheck , input : true } ) ) ;
117
- }
118
- } catch ( error ) {
119
- const { data } = error . response ;
120
- if ( data . status === 400 ) {
121
- setIsLoding ( ( ) => false ) ;
122
- setModalStr ( {
123
- modalTitle : data . message ,
124
- modalMessage : "이메일을 확인해주세요." ,
125
- } ) ;
126
- }
127
- }
108
+ dispatch (
109
+ __sendEmail ( {
110
+ email : email . value ,
111
+ dispatch : dispatch ,
112
+ setModalStr : setModalStr ,
113
+ } )
114
+ ) ;
115
+ dispatch ( __openModal ( dispatch ) ) ;
128
116
} ;
129
117
130
118
const onSubmitNextPage = ( ) => {
@@ -138,14 +126,17 @@ const InputEmail = () => {
138
126
} ) ) ;
139
127
email . focus ( ) ;
140
128
return ;
129
+ } else if ( regulation . emailError ) {
130
+ email . focus ( ) ;
131
+ return ;
141
132
} else {
142
133
SetRegulation ( ( ) => ( {
143
134
...regulation ,
144
135
emailError : "" ,
145
136
} ) ) ;
146
137
}
147
138
148
- if ( authenticationNumber . value . trim ( ) === "" ) {
139
+ if ( authenticationNumber . value === "" ) {
149
140
SetRegulation ( ( ) => ( {
150
141
...regulation ,
151
142
authenticationNumberError : "인증번호를 입력해주세요" ,
@@ -158,43 +149,32 @@ const InputEmail = () => {
158
149
authenticationNumberError : "" ,
159
150
} ) ) ;
160
151
}
161
-
162
- if ( InputCheck . input ) {
163
- onSubmitNextPageAxios ( {
164
- email : email . value ,
165
- code : authenticationNumber . value ,
166
- } ) ;
167
- }
168
- } ;
169
-
170
- const onSubmitNextPageAxios = async ( payload ) => {
171
- try {
172
- setIsLoding ( ( ) => true ) ;
173
- onModalOpen ( ) ;
174
- const { data } = await LoginApi . SendAuthenticationNumber ( payload ) ;
175
- setIsLoding ( ( ) => false ) ;
176
-
177
- if ( data . status === 200 ) {
178
- setModalStr ( {
179
- ...ModalStr ,
180
- modalTitle : data . message ,
181
- modalMessage : "" ,
182
- } ) ;
183
- setInputCheck ( ( ) => ( { ...InputCheck , modal : true } ) ) ;
184
- }
185
- } catch ( error ) {
186
- const { data } = error . response ;
187
- if ( data . status === 400 ) {
188
- setIsLoding ( ( ) => false ) ;
189
- setModalStr ( ( ) => ( {
190
- ...ModalStr ,
191
- modalTitle : "인증번호 실패" ,
192
- modalMessage : `인증번호가 잘못 입력되었습니다. \n 인증요청을 재시도 해주세요.` ,
193
- } ) ) ;
194
- }
152
+ console . log ( authenticationNumberCheck ) ;
153
+ if ( emailCheck && ! authenticationNumberCheck ) {
154
+ console . log ( "안녕" ) ;
155
+ dispatch (
156
+ __NextPage ( {
157
+ email : email . value ,
158
+ code : authenticationNumber . value ,
159
+ dispatch : dispatch ,
160
+ setModalStr : setModalStr ,
161
+ } )
162
+ ) ;
163
+ } else if ( ! emailCheck ) {
164
+ SetRegulation ( ( ) => ( {
165
+ ...regulation ,
166
+ emailError : "이메일 중복확인을 해주세요." ,
167
+ } ) ) ;
168
+ email . focus ( ) ;
195
169
}
196
170
} ;
197
171
172
+ useEffect ( ( ) => {
173
+ return ( ) => {
174
+ dispatch ( resetCheck ( ) ) ;
175
+ console . log ( emailCheck ) ;
176
+ } ;
177
+ } , [ ] ) ;
198
178
return (
199
179
< div className = "container " >
200
180
< div className = " grid grid-flow-row ml-[20px] mr-[20px] mt-[55px]" >
@@ -251,10 +231,9 @@ const InputEmail = () => {
251
231
</ div >
252
232
</ div >
253
233
< IsModal
254
- isModalOpen = { isOpen . isOpen }
255
234
onMoalClose = { onMoalClose }
256
235
message = { { ModalStr } }
257
- isLoding = { isLoding }
236
+ isLoding = { isLoading }
258
237
/>
259
238
</ div >
260
239
</ div >
0 commit comments