Skip to content

Commit 4c61c2f

Browse files
committed
feat: 삭제 API 연결 로직 작성
1 parent 0153a87 commit 4c61c2f

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

frontend/src/components/setting/ProjectDeleteModal.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import { ChangeEvent, MouseEventHandler, useState } from "react";
2+
import useSettingProjectSocket from "../../hooks/pages/setting/useSettingProjectSocket";
23
import Closed from "../../assets/icons/closed.svg?react";
4+
import { Socket } from "socket.io-client";
35

46
interface ProjectDeleteModalProps {
57
projectTitle: string;
8+
socket: Socket;
69
close: () => void;
710
}
811

912
const ProjectDeleteModal = ({
1013
projectTitle,
14+
socket,
1115
close,
1216
}: ProjectDeleteModalProps) => {
1317
const [inputValue, setInputValue] = useState("");
1418
const [confirmed, setConfirmed] = useState(false);
1519

20+
const { emitProjectDeleteEvent } = useSettingProjectSocket(socket);
21+
1622
const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
1723
const { value } = event.target;
1824

@@ -34,6 +40,12 @@ const ProjectDeleteModal = ({
3440
close();
3541
};
3642

43+
const handleDeleteButtonClick = () => {
44+
if (confirmed) {
45+
emitProjectDeleteEvent();
46+
}
47+
};
48+
3749
return (
3850
<div
3951
className="fixed top-0 left-0 z-50 flex items-center justify-center w-full h-full bg-black bg-opacity-30"
@@ -63,12 +75,15 @@ const ProjectDeleteModal = ({
6375
} h-7 relative`}
6476
>
6577
{!confirmed && (
66-
<div className="absolute w-full h-full bg-black rounded opacity-20"></div>
78+
<div className="absolute w-full h-full bg-black rounded opacity-40"></div>
6779
)}
6880
<button
69-
className="w-full h-full text-sm text-center text-white rounded bg-error-red"
81+
className={`w-full h-full text-sm text-center text-white rounded ${
82+
!confirmed ? "bg-gray-300" : "bg-error-red"
83+
}`}
7084
type="button"
7185
disabled={!confirmed}
86+
onClick={handleDeleteButtonClick}
7287
>
7388
프로젝트 삭제
7489
</button>

frontend/src/components/setting/ProjectDeleteSection.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useOutletContext } from "react-router-dom";
2+
import { Socket } from "socket.io-client";
13
import { useModal } from "../../hooks/common/modal/useModal";
24
import ProjectDeleteModal from "./ProjectDeleteModal";
35

@@ -7,8 +9,9 @@ interface ProjectDeleteSectionProps {
79

810
const ProjectDeleteSection = ({ projectTitle }: ProjectDeleteSectionProps) => {
911
const { open, close } = useModal(true);
12+
const { socket }: { socket: Socket } = useOutletContext();
1013
const handleDeleteButtonClick = () => {
11-
open(<ProjectDeleteModal {...{ projectTitle, close }} />);
14+
open(<ProjectDeleteModal {...{ projectTitle, close, socket }} />);
1215
};
1316

1417
return (

frontend/src/hooks/common/socket/useSocket.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { io } from "socket.io-client";
2-
import { BASE_URL } from "../../../constants/path";
31
import { useEffect, useState } from "react";
2+
import { useNavigate } from "react-router-dom";
3+
import { io } from "socket.io-client";
4+
import { BASE_URL, ROUTER_URL } from "../../../constants/path";
45
import { getAccessToken } from "../../../apis/utils/authAPI";
6+
import { SettingSocketData } from "../../../types/common/setting";
57

68
const useSocket = (projectId: string) => {
79
const WS_URL = `${BASE_URL}/project-${projectId}`;
@@ -15,6 +17,16 @@ const useSocket = (projectId: string) => {
1517
})
1618
);
1719
const [connected, setConnected] = useState<boolean>(false);
20+
const navigate = useNavigate();
21+
22+
const handleProjectDeleted = ({ domain, action }: SettingSocketData) => {
23+
if (domain === "projectInfo" && action === "delete") {
24+
alert("프로젝트가 삭제되었습니다.");
25+
setTimeout(() => {
26+
navigate(ROUTER_URL.PROJECTS);
27+
}, 1000);
28+
}
29+
};
1830

1931
useEffect(() => {
2032
const handleOnConnect = () => {
@@ -27,11 +39,13 @@ const useSocket = (projectId: string) => {
2739
socket.connect();
2840
socket.on("connect", handleOnConnect);
2941
socket.on("disconnect", handleOnDisconnect);
42+
socket.on("main", handleProjectDeleted);
3043

3144
return () => {
3245
socket.disconnect();
3346
socket.off("connect", handleOnConnect);
3447
socket.off("disconnect", handleOnDisconnect);
48+
socket.off("main", handleProjectDeleted);
3549
};
3650
}, []);
3751

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Socket } from "socket.io-client";
2+
3+
const useSettingProjectSocket = (socket: Socket) => {
4+
const emitProjectDeleteEvent = () => {
5+
socket.emit("projectInfo", { action: "delete", content: {} });
6+
};
7+
8+
return { emitProjectDeleteEvent };
9+
};
10+
11+
export default useSettingProjectSocket;

frontend/src/pages/setting/SettingPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const SettingPage = () => {
3434
<div className="w-full h-full">
3535
<InformationSettingSection {...{ title, subject }} />
3636
<MemberSettingSection memberList={memberList} />
37-
<ProjectDeleteSection projectTitle="프로젝트 이름" />
37+
<ProjectDeleteSection projectTitle={title} />
3838
</div>
3939
);
4040
};

0 commit comments

Comments
 (0)