Skip to content

Commit 882c003

Browse files
authored
Merge pull request #85 from haruharuganda/passwordChange
Feat. authenticationNumber #78 이메일 인증 기능,CSS완성 3차
2 parents 5052eee + 554d893 commit 882c003

File tree

5 files changed

+108
-23
lines changed

5 files changed

+108
-23
lines changed

src/api/UserApi.jsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { async } from "q";
12
import { instance } from "../shared/AxiosInstance";
23

34
export const UserApi = {
@@ -9,7 +10,11 @@ export const UserApi = {
910
return data;
1011
},
1112
editProfile: async (payload) => {
12-
const data = instance.patch("users/profile", payload);
13+
const data = await instance.patch("users/profile", payload);
14+
return data;
15+
},
16+
passwordChange: async (payload) => {
17+
const { data } = await instance.patch("/auth/password", payload);
1318
return data;
1419
},
1520
};

src/components/login/EmailLogin.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ const EmailLogin = () => {
136136
window.location.href = KAKAO_AUTH_URL;
137137
};
138138

139-
console.log({ style });
140139
return (
141140
<div className="container h-full md ">
142141
<div className="ml-[20px] mr-[20px] ">

src/components/login/InputEmail.jsx

+97-20
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,82 @@ import LoginSignupInputBox from "../layout/input/LoginSignupInputBox";
44
import IsModal from "../modal/Modal";
55
import { useRef } from "react";
66
import { LoginApi } from "../../api/LoginApi";
7+
import { useNavigate } from "react-router";
78

89
const InputEmail = () => {
10+
const navigator = useNavigate();
911
const emailRef = useRef();
1012
const authenticationNumberRef = useRef();
13+
const emailRegulationExp =
14+
/^[a-zA-Z0-9+-\_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
15+
1116
const [style, setStyle] = useState({
1217
bgColorEmail: "bg-inputBox",
1318
shadowEmail: "",
1419
bgColorAuthenticationNumber: "bg-inputBox",
1520
shadowAuthenticationNumber: "",
1621
});
17-
const [regulation, setRegulation] = useState("");
22+
const [regulation, SetRegulation] = useState({
23+
emailError: "",
24+
authenticationNumberError: "",
25+
});
1826
const [isOpen, setOpen] = useState(false);
1927
const [ModalStr, setModalStr] = useState({
2028
modalTitle: "",
2129
modalMessage: "",
2230
});
2331
const [isLoding, setIsLoding] = useState(false);
24-
const [InputCheck, setInputCheck] = useState(false);
32+
const [InputCheck, setInputCheck] = useState({ input: false, modal: false });
33+
2534
const onModalOpen = () => {
2635
setOpen({ isOpen: true });
2736
};
2837
const onMoalClose = () => {
2938
setOpen({ isOpen: false });
39+
if (InputCheck.modal) {
40+
navigator("/ChangePassword");
41+
}
3042
};
3143

3244
const onInputColor = (event) => {
33-
const { id, value } = event.target;
45+
const { id } = event.target;
46+
const emailRefCurrent = emailRef.current;
47+
const authenticationNumberRefCurrent = authenticationNumberRef.current;
3448
if (id === "email") {
3549
console.log("email입니다");
3650
setStyle(() => ({
3751
...style,
3852
bgColorEmail: "bg-inputBoxFocus",
3953
shadowEmail: "drop-shadow-inputBoxShadow",
4054
}));
41-
if (value.trim() === "") {
55+
if (emailRefCurrent.value.trim() === "") {
4256
setStyle(() => ({
4357
...style,
4458
bgColorEmail: "bg-inputBox",
4559
shadowEmail: "",
4660
}));
4761
}
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+
}
4876
} else {
4977
setStyle(() => ({
5078
...style,
5179
bgColorAuthenticationNumber: "bg-inputBoxFocus",
5280
shadowAuthenticationNumber: "drop-shadow-inputBoxShadow",
5381
}));
54-
if (value.trim() === "") {
82+
if (authenticationNumberRefCurrent.value.trim() === "") {
5583
setStyle(() => ({
5684
...style,
5785
bgColorAuthenticationNumber: "bg-inputBox",
@@ -64,10 +92,19 @@ const InputEmail = () => {
6492
const onSendEmail = () => {
6593
const email = emailRef.current;
6694
if (email.value.trim() === "") {
67-
setRegulation(() => "이메일을 입력해주세요");
95+
SetRegulation(() => ({
96+
...regulation,
97+
emailError: "이메일을 입력해주세요",
98+
}));
99+
email.focus();
100+
return;
68101
} else {
69-
setRegulation(() => "");
102+
SetRegulation(() => ({
103+
...regulation,
104+
emailError: "",
105+
}));
70106
}
107+
71108
sendEmail({ email: email.value });
72109
};
73110

@@ -77,11 +114,15 @@ const InputEmail = () => {
77114
onModalOpen();
78115
const data = await LoginApi.SendEmailAuthenticationNumber(payload);
79116
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+
}
85126
} catch (error) {
86127
console.log(error.response);
87128
const { data } = error.response;
@@ -100,16 +141,34 @@ const InputEmail = () => {
100141
const authenticationNumber = authenticationNumberRef.current;
101142

102143
if (email.value.trim() === "") {
103-
setRegulation(() => "이메일을 입력해주세요");
144+
SetRegulation(() => ({
145+
...regulation,
146+
emailError: "이메일을 입력해주세요",
147+
}));
104148
email.focus();
105149
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+
}));
108162
authenticationNumber.focus();
109163
return;
164+
} else {
165+
SetRegulation(() => ({
166+
...regulation,
167+
authenticationNumberError: "",
168+
}));
110169
}
111170

112-
if (InputCheck) {
171+
if (InputCheck.input) {
113172
onSubmitNextPageAxios({
114173
email: email.value,
115174
code: authenticationNumber.value,
@@ -121,18 +180,27 @@ const InputEmail = () => {
121180
try {
122181
setIsLoding(() => true);
123182
onModalOpen();
124-
const data = await LoginApi.SendAuthenticationNumber(payload);
183+
const { data } = await LoginApi.SendAuthenticationNumber(payload);
125184
setIsLoding(() => false);
126185
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+
}
127194
} catch (error) {
128195
console.log(error.response);
129196
const { data } = error.response;
130197
if (data.status === 400) {
131198
setIsLoding(() => false);
132-
setModalStr({
199+
setModalStr(() => ({
200+
...ModalStr,
133201
modalTitle: "인증번호 실패",
134202
modalMessage: `인증번호가 잘못 입력되었습니다. \n 인증요청을 재시도 해주세요.`,
135-
});
203+
}));
136204
}
137205
}
138206
};
@@ -157,14 +225,18 @@ const InputEmail = () => {
157225
/>
158226
<div
159227
onClick={onSendEmail}
228+
<<<<<<< Updated upstream
160229
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
161233
>
162234
인증 요청
163235
</div>
164236
</div>
165237
<div className="flex items-center h-[20px]">
166238
<p className=" w-full font-[500] text-[16px] text-[#DE0D0D] flex items-center">
167-
{regulation}
239+
{regulation.emailError}
168240
</p>
169241
</div>
170242
<div className="h-[full]">
@@ -178,6 +250,11 @@ const InputEmail = () => {
178250
ref={authenticationNumberRef}
179251
/>
180252
</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>
181258
</div>
182259
<div>
183260
<button

src/redux/modules/LoginSlice.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ const LoginSlice = createSlice({
108108
setMessage: (state, action) => {
109109
state.message = action.payload;
110110
},
111+
setEmail: (state, action) => {
112+
state.email = action.payload;
113+
},
111114
},
112115
extraReducers: {
113116
//카카오 소셜로그인

src/shared/Router.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import ProfileEditPage from "../page/ProfileEditPage";
2222
import InfiniteScroll from "../components/main/InfiniteScroll";
2323
import PastEventsPage from "../page/PastEventsPage";
2424
import UserSearchPage from "../page/UserSearchPage";
25-
import ScheduleEditPage from "../page/ScheduleEditPage";
2625
import InputEmailPage from "../page/InputEmailPage";
2726
import FriendsMain from "../components/main/FriendsMain";
27+
import ChangePasswordPage from "../page/ChangePasswordPage";
2828

2929
const Router = () => {
3030
return (
@@ -69,6 +69,7 @@ const Router = () => {
6969
<Route path="/follow" element={<FollowPage />} />
7070
<Route path="/pastEvents" element={<PastEventsPage />} />
7171
<Route path="/editProfile" element={<ProfileEditPage />} />
72+
<Route path="/ChangePassword" element={<ChangePasswordPage />} />
7273
{/* 알람 */}
7374
<Route path="/notification" element={<NotificationsPage />} />
7475

0 commit comments

Comments
 (0)