Skip to content

Commit fb82328

Browse files
authored
Feat. authenticationNumber #78 비밀번호 변경 완료
Feat. authenticationNumber #78 비밀번호 변경 완료
2 parents 1cc0a14 + 6ae018d commit fb82328

File tree

8 files changed

+451
-98
lines changed

8 files changed

+451
-98
lines changed

src/api/LoginApi.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const LoginApi = {
1111
},
1212

1313
SendEmailAuthenticationNumber: async (payload) => {
14-
return await instance.post("/auth/password", payload);
14+
console.log(payload);
15+
return await instance.post("/auth/password", { email: payload });
1516
},
1617

1718
SendAuthenticationNumber: async (payload) => {

src/components/login/EmailLogin.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import { KAKAO_AUTH_URL } from "../../shared/OAuth";
66
import KakaoLogin from "./KakaoLogin";
77
import "../style/login.css";
88
import { __emailLogin } from "../../redux/modules/LoginSlice";
9-
import { useDispatch, useSelector } from "react-redux";
9+
import { useDispatch } from "react-redux";
1010
import NaverLogin from "../../page/NaverLoginPage";
1111
import Label from "../layout/Label";
1212
import LoginSignupInputBox from "../layout/input/LoginSignupInputBox";
1313
import gnimsLogo from "../../img/gnimslogo1.png";
14-
import { EventSourcePolyfill } from "event-source-polyfill";
1514
import { __closeModal } from "../../redux/modules/SingupSlice";
1615

1716
const EmailLogin = () => {
@@ -200,7 +199,7 @@ const EmailLogin = () => {
200199
<div className="border-black border-solid border-r-[1px]">
201200
<button
202201
className="text-textBlack text-[16px] font-[400] px-[30px] pr-[37px]"
203-
onClick={() => navigate("/developing")}
202+
onClick={() => navigate("/login/auth/InputEmail")}
204203
>
205204
비밀번호 재설정
206205
</button>

src/components/login/InputEmail.jsx

+66-87
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@ import Label from "../layout/Label";
33
import LoginSignupInputBox from "../layout/input/LoginSignupInputBox";
44
import IsModal from "../modal/Modal";
55
import { useRef } from "react";
6-
import { LoginApi } from "../../api/LoginApi";
76
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";
815

916
const InputEmail = () => {
1017
const navigator = useNavigate();
18+
const dispatch = useDispatch();
19+
1120
const emailRef = useRef();
1221
const authenticationNumberRef = useRef();
13-
const emailRegulationExp =
14-
/^[a-zA-Z0-9+-\_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
22+
23+
const { isLoading } = useSelector((state) => state.LoginSlice);
1524

1625
const [style, setStyle] = useState({
1726
bgColorEmail: "bg-inputBox",
@@ -21,40 +30,38 @@ const InputEmail = () => {
2130
emailError: "",
2231
authenticationNumberError: "",
2332
});
24-
const [isOpen, setOpen] = useState(false);
2533
const [ModalStr, setModalStr] = useState({
2634
modalTitle: "",
2735
modalMessage: "",
2836
});
29-
const [isLoding, setIsLoding] = useState(false);
30-
const [InputCheck, setInputCheck] = useState({ input: false, modal: false });
3137

32-
const onModalOpen = () => {
33-
setOpen({ isOpen: true });
34-
};
38+
const { emailCheck, authenticationNumberCheck } = useSelector(
39+
(state) => state.LoginSlice.check
40+
);
3541
const onMoalClose = () => {
36-
setOpen({ isOpen: false });
37-
if (InputCheck.modal) {
42+
dispatch(__closeModal());
43+
if (authenticationNumberCheck) {
3844
navigator("/ChangePassword");
3945
}
4046
};
4147

4248
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-zA-Z0-9+-\_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
52+
4653
if (id === "email") {
4754
setStyle(() => ({
4855
...style,
4956
bgColorEmail: "bg-inputBoxFocus",
5057
}));
51-
if (emailRefCurrent.value.trim() === "") {
58+
if (value === "") {
5259
setStyle(() => ({
5360
...style,
5461
bgColorEmail: "bg-inputBox",
5562
}));
5663
}
57-
if (emailRegulationExp.test(emailRefCurrent.value)) {
64+
if (emailRegulationExp.test(value)) {
5865
SetRegulation(() => ({
5966
...regulation,
6067
emailError: "",
@@ -64,20 +71,20 @@ const InputEmail = () => {
6471
...regulation,
6572
emailError: "올바른 이메일 형식이 아닙니다.",
6673
}));
67-
68-
emailRefCurrent.focus();
74+
event.target.focus();
6975
return;
7076
}
7177
} else {
72-
setStyle(() => ({
73-
...style,
74-
bgColorAuthenticationNumber: "bg-inputBoxFocus",
75-
}));
76-
if (authenticationNumberRefCurrent.value.trim() === "") {
78+
if (value.trim() === "") {
7779
setStyle(() => ({
7880
...style,
7981
bgColorAuthenticationNumber: "bg-inputBox",
8082
}));
83+
} else {
84+
setStyle(() => ({
85+
...style,
86+
bgColorAuthenticationNumber: "bg-inputBoxFocus",
87+
}));
8188
}
8289
}
8390
};
@@ -98,33 +105,14 @@ const InputEmail = () => {
98105
}));
99106
}
100107

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));
128116
};
129117

130118
const onSubmitNextPage = () => {
@@ -138,14 +126,17 @@ const InputEmail = () => {
138126
}));
139127
email.focus();
140128
return;
129+
} else if (regulation.emailError) {
130+
email.focus();
131+
return;
141132
} else {
142133
SetRegulation(() => ({
143134
...regulation,
144135
emailError: "",
145136
}));
146137
}
147138

148-
if (authenticationNumber.value.trim() === "") {
139+
if (authenticationNumber.value === "") {
149140
SetRegulation(() => ({
150141
...regulation,
151142
authenticationNumberError: "인증번호를 입력해주세요",
@@ -158,43 +149,32 @@ const InputEmail = () => {
158149
authenticationNumberError: "",
159150
}));
160151
}
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();
195169
}
196170
};
197171

172+
useEffect(() => {
173+
return () => {
174+
dispatch(resetCheck());
175+
console.log(emailCheck);
176+
};
177+
}, []);
198178
return (
199179
<div className="container ">
200180
<div className=" grid grid-flow-row ml-[20px] mr-[20px] mt-[55px]">
@@ -251,10 +231,9 @@ const InputEmail = () => {
251231
</div>
252232
</div>
253233
<IsModal
254-
isModalOpen={isOpen.isOpen}
255234
onMoalClose={onMoalClose}
256235
message={{ ModalStr }}
257-
isLoding={isLoding}
236+
isLoding={isLoading}
258237
/>
259238
</div>
260239
</div>

src/components/modal/Modal.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import Modal from "react-modal";
33
import MoonLoader from "react-spinners/MoonLoader";
44
import { useSelector } from "react-redux";
5+
import { useLayoutEffect } from "react";
56
const IsModal = ({ onMoalClose, message, isLoding }) => {
67
const modalStr = message.ModalStr;
78
const modalState = useSelector((state) => state.SingupSlice.modal);
@@ -16,7 +17,6 @@ const IsModal = ({ onMoalClose, message, isLoding }) => {
1617
alignItems: "center",
1718
backgroundColor: "#53535339",
1819
zIndex: 10,
19-
// width: "375px",
2020
},
2121
content: {
2222
justifyContent: "center",
@@ -33,6 +33,7 @@ const IsModal = ({ onMoalClose, message, isLoding }) => {
3333
padding: "16px",
3434
},
3535
};
36+
3637
return (
3738
<Modal
3839
isOpen={modalState.isOpen}
@@ -42,7 +43,7 @@ const IsModal = ({ onMoalClose, message, isLoding }) => {
4243
labelledby: "heading",
4344
describedby: "full_description",
4445
}}
45-
shouldCloseOnEsc={false}
46+
shouldCloseOnEsc={true}
4647
>
4748
<div className="grid grid-flow-row gap-[20px] text-center">
4849
{isLoding ? (

0 commit comments

Comments
 (0)