Skip to content

Commit c6cedfb

Browse files
authored
Merge pull request #30 from KWcapstone/24-feat-메인페이지-모달-api-연결
24 feat 메인페이지 모달 api 연결
2 parents f3da552 + 45d437e commit c6cedfb

File tree

10 files changed

+257
-31
lines changed

10 files changed

+257
-31
lines changed

src/api/main/profile.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Send from "@/api/send.ts";
2+
import { profileData } from "@/types/profileData";
23

34
export const getProfile = () => {
45
return Send({
@@ -13,3 +14,11 @@ export const Withdraw = () => {
1314
url: "auth/withdraw",
1415
});
1516
};
17+
18+
export const patchProfile = (data: profileData) => {
19+
return Send({
20+
method: "patch",
21+
url: "main/profile",
22+
data: data,
23+
});
24+
};

src/api/main/project.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Send from "@/api/send.ts";
22
import { selectParams } from "@/types/selectParams";
3+
import { projects } from "@/types/deleteProject";
34

45
export const getProject = (params: selectParams) => {
56
return Send({
@@ -8,3 +9,11 @@ export const getProject = (params: selectParams) => {
89
params: params,
910
});
1011
};
12+
13+
export const deleteProject = (data: projects[]) => {
14+
return Send({
15+
method: "delete",
16+
url: "main/project/delete",
17+
data: data,
18+
});
19+
};

src/api/splash/resetPW.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Send from "@/api/send.ts";
2+
import { ResetPWData } from "@/types/loginData";
3+
4+
export const postResetPW = (data: ResetPWData) => {
5+
return Send({
6+
method: "post",
7+
url: "auth/reset_pw",
8+
data: data,
9+
});
10+
};

src/types/deleteProject.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface projects {
2+
projectId: Array<string>;
3+
type: string;
4+
}

src/types/loginData.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ export interface LoginData {
22
email: string;
33
password: string;
44
}
5+
6+
export interface ResetPWData {
7+
name: string;
8+
email: string;
9+
}

src/views/main/components/UserModal.tsx

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Modal from "@/views/components/modal";
33
import test from "@/assets/imgs/common/user.svg";
44

55
// api
6-
import { getProfile, Withdraw } from "@/api/main/profile";
6+
import { getProfile, Withdraw, patchProfile } from "@/api/main/profile";
77
import { logout } from "@/api/splash/login";
88

99
// import
@@ -19,52 +19,88 @@ interface UserModalProps {
1919
onCloseModal: () => void;
2020
}
2121

22-
const UserModal = ({
23-
onCloseModal,
24-
}: UserModalProps) => {
25-
22+
const UserModal = ({ onCloseModal }: UserModalProps) => {
2623
const [profile, setProfile] = useState<profileData>();
27-
24+
const [isEdit, setIsEdit] = useState(false);
25+
const [editName, setEditName] = useState("");
26+
const clickEdit = () => {
27+
setEditName(profile?.name ?? "");
28+
setIsEdit(true);
29+
};
2830
const clickLogout = () => {
29-
logout().then(()=>{
30-
alert('로그아웃 되었습니다.')
31+
logout().then(() => {
32+
alert("로그아웃 되었습니다.");
3133
clearTokens();
32-
window.location.href = '/'
34+
window.location.href = "/";
3335
});
34-
}
36+
};
3537

3638
const clickWithdraw = () => {
37-
if(confirm("정말 계정을 삭제하시겠습니까?")) {
39+
if (confirm("정말 계정을 삭제하시겠습니까?")) {
3840
Withdraw().then(() => {
39-
alert('계정이 정상적으로 삭제되었습니다.')
41+
alert("계정이 정상적으로 삭제되었습니다.");
4042
clearTokens();
41-
window.location.href = '/'
42-
})
43+
window.location.href = "/";
44+
});
4345
}
44-
}
46+
};
4547

4648
useEffect(() => {
4749
getProfile().then((res: any) => {
4850
setProfile(res.data.data);
4951
});
50-
},[]);
52+
}, []);
53+
54+
useEffect(() => {
55+
if (profile?.name) setEditName(profile.name);
56+
}, [profile]);
5157

5258
return (
5359
<Modal onCloseModal={onCloseModal}>
5460
<div className="modal-wrap">
5561
<div className="info-wrap">
5662
<div className="user-img">
5763
<img src={profile?.imageUrl ?? test} alt="" />
64+
<div className="edit-div" onClick={clickEdit}></div>
5865
</div>
59-
<div className="user-name">{profile?.name}</div>
66+
{isEdit ? (
67+
<input
68+
type="text"
69+
value={editName}
70+
className="title-rename-input"
71+
onChange={(e) => setEditName(e.target.value)}
72+
onBlur={() => setIsEdit(false)}
73+
onKeyDown={(e) => {
74+
if (e.key === "Enter") {
75+
const newName = e.currentTarget.value;
76+
setIsEdit(false);
77+
setEditName(newName);
78+
patchProfile({
79+
name: newName,
80+
imageUrl: profile?.imageUrl ?? "",
81+
} as profileData).then(() => {
82+
console.log("프로필 변경 성공");
83+
setProfile((prev) => prev && { ...prev, name: newName });
84+
window.location.reload();
85+
});
86+
}
87+
}}
88+
/>
89+
) : (
90+
<div className="user-name">{profile?.name}</div>
91+
)}
6092
<div className="user-email">{profile?.email}</div>
6193
</div>
6294
<ul className="edit-wrap">
6395
{/* <li className="mode-wrap"></li> */}
64-
<li className="log-out" onClick={clickLogout}>로그아웃</li>
96+
<li className="log-out" onClick={clickLogout}>
97+
로그아웃
98+
</li>
6599
<li className="pwd-edit">비밀번호 변경</li>
66100
</ul>
67-
<button className="remove" onClick={clickWithdraw}>계정 삭제</button>
101+
<button className="remove" onClick={clickWithdraw}>
102+
계정 삭제
103+
</button>
68104
<p>개인 정보 처리 방침・이용약관</p>
69105
</div>
70106
</Modal>

src/views/main/page/ProjectPage.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import test from "@/assets/imgs/common/user.svg";
66

77
// api
88
import { getSearch, patchProjectName } from "@/api/common/common";
9-
import { getProject } from "@/api/main/project";
9+
import { getProject, deleteProject } from "@/api/main/project";
1010

1111
// component
1212
import SideBar from "@/views/main/components/SideBar";
@@ -19,6 +19,7 @@ import { Link } from "react-router-dom";
1919

2020
// type
2121
import { projectData } from "@/types/projectData";
22+
import { projects } from "@/types/deleteProject";
2223

2324
const ProjectPage = () => {
2425
// value
@@ -32,6 +33,7 @@ const ProjectPage = () => {
3233
const [editedTitle, setEditedTitle] = useState<string>("");
3334
const menuRef = useRef<HTMLUListElement | null>(null);
3435
const orderRef = useRef<HTMLDivElement | null>(null);
36+
const [deleteProjectList, setDeleteProjectList] = useState<projects[]>([]);
3537

3638
// modal
3739
type ModalType = "dwn" | "share" | null;
@@ -44,6 +46,17 @@ const ProjectPage = () => {
4446
setOpenMenuId((prev) => (prev === id ? null : id));
4547
};
4648

49+
const clickProjectDelete = (projectID: Array<string>) => {
50+
if (confirm("정말 프로젝트를 삭제하시겠습니까?")) {
51+
setDeleteProjectList([{ projectId: projectID, type: "project" }]);
52+
53+
deleteProject(deleteProjectList).then(() => {
54+
alert("프로젝트가 정상적으로 삭제되었습니다.");
55+
window.location.reload();
56+
});
57+
}
58+
};
59+
4760
const getSearchList = () => {
4861
setTap("all");
4962
setOrder("latest");
@@ -229,7 +242,18 @@ const ProjectPage = () => {
229242
>
230243
공유하기
231244
</li>
232-
<li className="del">삭제하기</li>
245+
<li
246+
className="del"
247+
onClick={(e) => {
248+
e.preventDefault();
249+
e.stopPropagation();
250+
clickProjectDelete(list.projectId);
251+
setOpenMenuId(null);
252+
setProjectId(list.projectId);
253+
}}
254+
>
255+
삭제하기
256+
</li>
233257
</ul>
234258
)}
235259
<div className="info-wrap">
@@ -258,9 +282,6 @@ const ProjectPage = () => {
258282
.catch(() => {
259283
console.log("이름 변경 실패");
260284
});
261-
262-
// 여기서 API 호출도 함께 하면 좋음
263-
// await updateProjectName(list.projectId, editedTitle);
264285
}
265286
}}
266287
/>

src/views/main/style/user-modal.sass

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
+padding(bottom 32px)
1616
+flex-box(center, center)
1717
flex-direction: column
18+
.title-rename-input
19+
+margin(top 8px)
20+
+border(1px solid $gray-200)
21+
+size(100px, 30px)
22+
+border-radius(4px)
23+
+box-sizing(border-box)
24+
+padding(6px 4px)
25+
font-weight: 500
26+
line-height: 21px
27+
background-color: $gray-50
1828

1929
.user-img
2030
position: relative
@@ -25,7 +35,7 @@
2535
border-radius: 50px
2636
background: #B3C4DE
2737

28-
&:after
38+
.edit-div
2939
content: ""
3040
+size(24px, 24px)
3141
+box-sizing(border-box)

0 commit comments

Comments
 (0)