Skip to content

Commit ec45c9a

Browse files
authored
Merge pull request #81 from codeit9-temporary/feature/modalAction
Fix : 모달 백드롭 스타일 수정 / Feat: 폴더 삭제 모달 기능 추가
2 parents b804a55 + f616b48 commit ec45c9a

File tree

10 files changed

+94
-19
lines changed

10 files changed

+94
-19
lines changed

components/modal/AddModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const AddModal = ({ list, link }: { list: FolderItemType[]; link: string }) => {
4343
type="button"
4444
onClick={handleSubmit}
4545
width="w-full"
46-
height="h-[51px] "
46+
height="h-[51px]"
4747
color="positive"
4848
>
4949
추가하기

components/modal/DeleteFolderModal.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1+
import useModalStore from "@/store/useModalStore";
12
import SubmitButton from "../SubMitButton";
23
import ModalContainer from "./modalComponents/ModalContainer";
4+
import { deleteFolder } from "@/lib/api/folder";
5+
6+
const DeleteFolderModal = ({
7+
folderName,
8+
folderId,
9+
}: {
10+
folderName: string;
11+
folderId: number;
12+
}) => {
13+
const { closeModal } = useModalStore();
14+
const handleSubmit = async () => {
15+
try {
16+
await deleteFolder(folderId);
17+
} catch (error) {
18+
console.log(error, "폴더 삭제 에러");
19+
} finally {
20+
closeModal();
21+
}
22+
};
323

4-
const DeleteFolderModal = ({ folderName }: { folderName: string }) => {
5-
console.log("folderName", folderName);
624
return (
725
<ModalContainer title="폴더 삭제" subtitle={folderName}>
826
<SubmitButton
927
type="button"
10-
// onClick={handleSubmit}
28+
onClick={handleSubmit}
1129
width="w-full"
12-
height="h-[51px] "
30+
height="h-[51px]"
1331
color="negative"
1432
>
1533
삭제하기

components/modal/EditLink.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const EditLink = ({
2121
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
2222
setValue(e.target.value);
2323
};
24-
2524
const handleSubmit = async () => {
2625
const body = {
2726
url: value,

components/modal/EditModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const EditModal = ({ folderName }: { folderName: string }) => {
4141
type="button"
4242
// onClick={handleSubmit}
4343
width="w-full"
44-
height="h-[51px] "
44+
height="h-[51px]"
4545
color="positive"
4646
>
4747
변경하기

components/modal/modalComponents/ModalContainer.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import { IoIosClose } from "react-icons/io";
2-
import SubmitButton from "../../SubMitButton";
32
import { ModalPropType } from "@/types/modalTypes";
43
import useModalStore from "@/store/useModalStore";
54
import { MouseEvent, useRef } from "react";
65

76
const ModalContainer = ({ title, subtitle, children }: ModalPropType) => {
8-
const { closeModal } = useModalStore();
7+
const { isOpen, closeModal } = useModalStore();
98
const modalRef = useRef<HTMLDivElement | null>(null);
109
const onClickBackDrop = (e: MouseEvent<HTMLDivElement>) => {
1110
if (modalRef.current && !modalRef.current.contains(e.target as Node))
1211
closeModal();
1312
};
14-
13+
if (isOpen) {
14+
document.body.style.overflow = "hidden";
15+
} else {
16+
document.body.style.overflow = "auto";
17+
}
1518
return (
1619
<div
1720
onClick={onClickBackDrop}
18-
className="z-30 absolute top-0 left-0 flex justify-center items-center bg-black/40 h-screen w-screen"
21+
className=" z-30 fixed top-0 left-0 flex justify-center items-center bg-black/40 h-screen w-screen"
1922
>
2023
<div
2124
ref={modalRef}

components/modal/modalManager/ModalManager.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export const Modal = () => {
4242
/>
4343
);
4444
case "DeleteFolderModal":
45-
return <DeleteFolderModal folderName={props.folderName || "폴더이름"} />;
45+
return (
46+
<DeleteFolderModal
47+
folderName={props.folderName || "폴더이름"}
48+
folderId={props.folderId || 1}
49+
/>
50+
);
4651
case "DeleteLinkModal":
4752
return (
4853
<DeleteLinkModal

lib/api/folder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@ export const postFolders = async (body: folderApiProps) => {
2525
};
2626

2727
// 폴더 조회
28-
export const getFolder = async (forderId: number) => {
28+
export const getFolder = async (folderId: number) => {
2929
try {
30-
const res = await axiosInstance.get(`/folders/${forderId}`);
30+
const res = await axiosInstance.get(`/folders/${folderId}`);
3131
if (res.status >= 200 && res.status < 300) return res.data;
3232
} catch (err) {
3333
console.error("에러 메시지: ", err instanceof Error ? err.message : err);
3434
}
3535
};
3636

3737
// 폴더 삭제(auth)
38-
export const deleteFolder = async (forderId: number) => {
38+
export const deleteFolder = async (folderId: number) => {
3939
try {
40-
const res = await proxy.delete(`/api/folders/${forderId}`);
40+
const res = await proxy.delete(`/api/folders/${folderId}`);
4141
if (res.status >= 200 && res.status < 300) return res.data;
4242
} catch (err) {
4343
console.error("에러 메시지: ", err instanceof Error ? err.message : err);
4444
}
4545
};
4646

4747
// 폴더 이름 수정(auth)
48-
export const putFolder = async (forderId: number, body: folderApiProps) => {
48+
export const putFolder = async (folderId: number, body: folderApiProps) => {
4949
try {
50-
const res = await proxy.put(`/api/folders/${forderId}`, body);
50+
const res = await proxy.put(`/api/folders/${folderId}`, body);
5151
if (res.status >= 200 && res.status < 300) return res.data;
5252
} catch (err) {
5353
console.error("에러 메시지: ", err instanceof Error ? err.message : err);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import axiosInstance from "@/lib/api/axiosInstanceApi";
2+
import axios from "axios";
3+
import { NextApiRequest, NextApiResponse } from "next";
4+
5+
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
6+
const token = req.cookies.accessToken;
7+
const { folderId } = req.query;
8+
const id = Number(folderId);
9+
10+
console.log("Token:", token);
11+
console.log("folderId:", folderId);
12+
13+
if (!token) {
14+
return res.status(401).json({ error: "사용자 정보를 찾을 수 없습니다." });
15+
}
16+
17+
if (isNaN(id)) {
18+
return res.status(400).json({ error: "Invalid folderId" });
19+
}
20+
21+
if (req.method === "DELETE") {
22+
try {
23+
const response = await axiosInstance.delete(`/folders/${id}`, {
24+
headers: {
25+
Authorization: `Bearer ${token}`,
26+
},
27+
});
28+
29+
return res.status(204).json({ message: "폴더 삭제 성공" });
30+
} catch (error) {
31+
if (axios.isAxiosError(error) && error.response) {
32+
const status = error.response.status;
33+
const message = error.response.data?.message || "알 수 없는 오류 발생";
34+
return res.status(status).json({ message });
35+
}
36+
}
37+
} else {
38+
return res.status(500).json({ error: "서버 오류 발생" });
39+
}
40+
};
41+
export default handler;

pages/test/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ export default function Test() {
3939
>
4040
폴더에 추가 버튼
4141
</button>
42-
<button type="button" onClick={() => openModal("DeleteFolderModal")}>
42+
<button
43+
type="button"
44+
onClick={() =>
45+
openModal("DeleteFolderModal", {
46+
folderName: "NAME",
47+
folderId: 700,
48+
})
49+
}
50+
>
4351
폴더 삭제 버튼
4452
</button>
4553
<button type="button" onClick={() => openModal("DeleteLinkModal")}>

types/modalTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface ModalPropType {
55
subtitle?: string;
66
children?: ReactNode;
77
folderName?: string;
8+
folderId?: number;
89
list?: FolderItemType[];
910
link?: string;
1011
linkId?: number | null;

0 commit comments

Comments
 (0)