Skip to content

Commit

Permalink
feat: 히스토리 삭제, 이름변경, 회원탈퇴 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
gogumalatte committed Dec 4, 2024
1 parent f7a642f commit 8d7394e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/pages/MainPage/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ isOpen, toggleSidebar }) => {
title: "히스토리 이름이 성공적으로 변경되었습니다.",
status: "success",
duration: 3000,
position: "top",
isClosable: true,
});
fetchHistories(); // 히스토리 목록 새로고침
Expand All @@ -109,6 +110,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ isOpen, toggleSidebar }) => {
title: "히스토리 이름 변경에 실패했습니다.",
status: "error",
duration: 3000,
position: "top",
isClosable: true,
});
}
Expand All @@ -118,6 +120,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ isOpen, toggleSidebar }) => {
title: "히스토리 이름 변경 중 오류가 발생했습니다.",
status: "error",
duration: 3000,
position: "top",
isClosable: true,
});
}
Expand Down Expand Up @@ -166,6 +169,55 @@ export const Sidebar: React.FC<SidebarProps> = ({ isOpen, toggleSidebar }) => {
}
};

const handleUserDelete = async () => {
const confirmation = window.confirm(
"정말로 회원탈퇴를 하시겠습니까? 모든 데이터가 삭제됩니다."
);
if (!confirmation) return;

try {
const token = localStorage.getItem("accessToken");
const response = await fetch(`${baseURL}/api/member/delete`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
});

if (response.ok) {
toast({
title: "회원탈퇴가 완료되었습니다.",
status: "success",
duration: 3000,
position: "top",
isClosable: true,
});
localStorage.removeItem("accessToken");
navigate("/");
window.location.reload();
} else {
const errorData = await response.json();
toast({
title: `회원탈퇴 실패: ${errorData.error || "알 수 없는 오류"}`,
status: "error",
duration: 3000,
position: "top",
isClosable: true,
});
}
} catch (error) {
console.error("회원탈퇴 중 오류 발생:", error);
toast({
title: "회원탈퇴 중 오류가 발생했습니다.",
status: "error",
duration: 3000,
position: "top",
isClosable: true,
});
}
};

useEffect(() => {
const fetchUserInfo = async () => {
const baseURL = import.meta.env.VITE_BASE_URL; // 환경변수에서 baseURL 가져오기
Expand Down Expand Up @@ -539,6 +591,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ isOpen, toggleSidebar }) => {
bg="#EFA9A4"
color="black"
_hover={{ bg: "#D17C74" }}
onClick={handleUserDelete} // 회원탈퇴 버튼
boxShadow={
"0px 2px 3px rgba(0, 0, 0, 0.1), 0px 1px 2px rgba(0, 0, 0, 0.06)"
} // 사용자 정의 그림자
Expand Down

0 comments on commit 8d7394e

Please sign in to comment.