Skip to content

Commit ce61f1b

Browse files
authored
Merge pull request #159 from Soohyuniii/feat/팝업-컴포넌트-공통-컴포넌트화-작업
Feat/팝업 컴포넌트 공통 컴포넌트화 작업
2 parents 74d098c + 45e02f5 commit ce61f1b

File tree

3 files changed

+96
-35
lines changed

3 files changed

+96
-35
lines changed

src/components/Alert.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import AlertButton from "@/components/button/AlertButton";
2+
3+
type AlertProps = {
4+
title: string;
5+
message: string[];
6+
cancelText: string;
7+
confirmText: string;
8+
onCancel?: () => void;
9+
onConfirm?: () => void;
10+
};
11+
12+
const ActionConfirmModal = ({
13+
title,
14+
message,
15+
cancelText,
16+
confirmText,
17+
onCancel,
18+
onConfirm
19+
}: AlertProps) => {
20+
return (
21+
<div className="absolute inset-0 z-50 flex items-center justify-center bg-[#00000080]">
22+
<div className="flex h-[200px] w-[294px] flex-col items-center justify-center rounded-2xl bg-white">
23+
<h3 className="text-2xl font-bold">{title}</h3>
24+
<p className="mt-[9px] text-center text-xl font-medium">
25+
{message.map((line, index) => (
26+
<span key={index} className="block">
27+
{line}
28+
</span>
29+
))}
30+
</p>
31+
<div className="mt-[19px] flex gap-3.5">
32+
<AlertButton onClick={onCancel}>{cancelText}</AlertButton>
33+
<AlertButton onClick={onConfirm}>{confirmText}</AlertButton>
34+
</div>
35+
</div>
36+
</div>
37+
);
38+
};
39+
40+
export default ActionConfirmModal;

src/pages/MyInfo.tsx

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
1+
import { useState } from "react";
12
import Header from "@/components/Header";
3+
import ActionConfirmModal from "@/components/modal/ActionConfirmModal";
4+
import useAuthStore from "@/store/useAuthStore";
5+
import { useNavigate } from "react-router-dom";
26

3-
interface MenuItem {
4-
label: string;
5-
onClick?: () => void;
6-
}
7+
type ModalType = "logout" | "withdraw" | "terms" | "privacy" | null;
78

8-
const menuItems: MenuItem[] = [
9-
{ label: "이용약관", onClick: () => console.log("이용약관 클릭") },
10-
{
11-
label: "개인정보처리방침",
12-
onClick: () => console.log("개인정보처리방침 클릭")
9+
const alertConfig = {
10+
logout: {
11+
title: "로그아웃",
12+
message: ["로그아웃 할까요?"],
13+
cancelText: "취소",
14+
confirmText: "확인"
1315
},
14-
{ label: "로그아웃", onClick: () => console.log("로그아웃 클릭") },
15-
{ label: "회원탈퇴", onClick: () => console.log("회원탈퇴 클릭") }
16-
];
16+
withdraw: {
17+
title: "회원탈퇴",
18+
message: ["정말 탈퇴하시겠습니까?"],
19+
cancelText: "취소",
20+
confirmText: "확인"
21+
}
22+
};
1723

1824
const MyInfo = () => {
25+
const [modalType, setModalType] = useState<ModalType>(null);
26+
const { logout } = useAuthStore();
27+
const navigate = useNavigate();
28+
29+
const handleCancel = () => {
30+
setModalType(null);
31+
};
32+
33+
const handleConfirm = () => {
34+
if (modalType === "logout") {
35+
logout();
36+
navigate("/login");
37+
} else if (modalType === "withdraw") {
38+
console.log("회원탈퇴 실행"); //TODO: 회원탈퇴 기능 구현 시 추가 필요
39+
}
40+
setModalType(null);
41+
};
42+
43+
const menuItems = [
44+
{ label: "이용약관", onClick: () => setModalType("terms") }, //TODO: 이용약관 팝업 구현 시 추가 필요
45+
{ label: "개인정보처리방침", onClick: () => setModalType("privacy") }, //TODO: 개인정보처리방침 팝업 구현 시 추가 필요
46+
{ label: "로그아웃", onClick: () => setModalType("logout") },
47+
{ label: "회원탈퇴", onClick: () => setModalType("withdraw") }
48+
];
49+
1950
return (
20-
<div className="flex w-[360px] flex-col bg-white md:w-[375px] lg:w-[500px]">
51+
<div className="relative flex w-[360px] flex-col bg-white md:w-[375px] lg:w-[500px]">
2152
<Header title="내 정보" showShareIcon={false} />
2253

2354
<ul className="mt-[10px] flex flex-col justify-between gap-[20px]">
@@ -27,7 +58,7 @@ const MyInfo = () => {
2758
className="flex h-[56px] cursor-pointer items-center justify-between px-5 py-4 hover:bg-gray-50"
2859
onClick={item.onClick}
2960
>
30-
<span className="text-base text-[16px] leading-6 font-medium tracking-normal text-gray-900 ">
61+
<span className="text-base font-medium text-gray-900">
3162
{item.label}
3263
</span>
3364
<img
@@ -38,6 +69,17 @@ const MyInfo = () => {
3869
</li>
3970
))}
4071
</ul>
72+
73+
{modalType && (modalType === "logout" || modalType === "withdraw") && (
74+
<ActionConfirmModal
75+
title={alertConfig[modalType].title}
76+
message={alertConfig[modalType].message}
77+
cancelText={alertConfig[modalType].cancelText}
78+
confirmText={alertConfig[modalType].confirmText}
79+
onCancel={handleCancel}
80+
onConfirm={handleConfirm}
81+
/>
82+
)}
4183
</div>
4284
);
4385
};

0 commit comments

Comments
 (0)