Skip to content

Commit 28be0f6

Browse files
authored
Merge pull request #55 from codeit9-temporary/feature/modalAction
Feat: 폴더 추가 기능 (모달)
2 parents 56b89d5 + b392df1 commit 28be0f6

File tree

10 files changed

+145
-24
lines changed

10 files changed

+145
-24
lines changed

components/modal/AddFolderModal.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
1+
import { ChangeEvent, useState } from "react";
12
import ModalContainer from "./modalComponents/ModalContainer";
23
import ModalInput from "./modalComponents/ModalInput";
4+
import { postFolders } from "@/lib/api/folder";
5+
import useModalStore from "@/store/useModalStore";
36

47
const AddFolderModal = ({ folderName }: { folderName: string }) => {
8+
const [value, setValue] = useState("");
9+
10+
const { closeModal } = useModalStore();
11+
12+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
13+
setValue(e.target.value);
14+
};
15+
const handleSubmit = async () => {
16+
const body = {
17+
name: value,
18+
};
19+
if (value !== "") {
20+
try {
21+
const res = await postFolders(body);
22+
console.log(res);
23+
} catch (error) {
24+
console.log(error);
25+
}
26+
}
27+
closeModal();
28+
};
529
return (
6-
<ModalContainer title="폴더 추가" buttonText="추가하기">
7-
<ModalInput placeholder="내용 입력" name={folderName} />
30+
<ModalContainer
31+
title="폴더 추가"
32+
buttonText="추가하기"
33+
onClick={handleSubmit}
34+
>
35+
<ModalInput
36+
placeholder="내용 입력"
37+
name={folderName}
38+
value={value}
39+
onChange={handleChange}
40+
/>
841
</ModalContainer>
942
);
1043
};

components/modal/EditModal.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
1+
import { ChangeEvent, useState } from "react";
12
import ModalContainer from "./modalComponents/ModalContainer";
23
import ModalInput from "./modalComponents/ModalInput";
4+
import useModalStore from "@/store/useModalStore";
5+
import { putFolder } from "@/lib/api/folder";
36

47
const EditModal = ({ folderName }: { folderName: string }) => {
8+
const [value, setValue] = useState("");
9+
10+
const { closeModal } = useModalStore();
11+
12+
// 폴더 정보를 먼저 가져와야함
13+
14+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
15+
setValue(e.target.value);
16+
};
17+
const handleSubmit = async () => {
18+
const body = {
19+
name: value,
20+
};
21+
// if (value !== "") {
22+
// try {
23+
// const res = await putFolder(folderId, body);
24+
// console.log(res);
25+
// } catch (error) {
26+
// console.log(error);
27+
// }
28+
// }
29+
closeModal();
30+
};
531
return (
6-
<ModalContainer title="폴더 이름 변경" buttonText="변경하기">
7-
<ModalInput placeholder="내용 입력" name={folderName} />
32+
<ModalContainer
33+
title="폴더 이름 변경"
34+
buttonText="변경하기"
35+
onClick={handleSubmit}
36+
>
37+
<ModalInput
38+
placeholder="내용 입력"
39+
name={folderName}
40+
value={value}
41+
onChange={handleChange}
42+
/>
843
</ModalContainer>
944
);
1045
};

components/modal/modalComponents/FolderItem.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const FolderItem = ({ item }: { item: FolderItemType }) => {
88

99
const bgColor = selected ? "bg-gray100" : "bg-white";
1010

11-
const { title, totalCount } = item;
11+
const { name, linkCount } = item;
1212

1313
const onClickFolder = () => {
1414
setSelected(!selected);
@@ -17,7 +17,7 @@ const FolderItem = ({ item }: { item: FolderItemType }) => {
1717
<li
1818
className={bindCls(
1919
bgColor,
20-
"w-full p-2 flex h-10 rounded-lg items-center justify-between"
20+
"w-full p-2 flex h-10 rounded-lg items-center justify-between cursor-pointer"
2121
)}
2222
onClick={onClickFolder}
2323
>
@@ -28,9 +28,9 @@ const FolderItem = ({ item }: { item: FolderItemType }) => {
2828
selected ? "text-purple100" : "text-black300"
2929
)}
3030
>
31-
{title}
31+
{name}
3232
</div>
33-
<div className="text-gray400 text-sm">{totalCount}개 링크</div>
33+
<div className="text-gray400 text-sm">{linkCount}개 링크</div>
3434
</div>
3535
{selected && (
3636
<div>

components/modal/modalComponents/ModalContainer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const ModalContainer = ({
1010
children,
1111
buttonText,
1212
buttonColor,
13+
onClick,
1314
}: ModalPropType) => {
1415
const { closeModal } = useModalStore();
1516
const modalRef = useRef<HTMLDivElement | null>(null);
@@ -48,6 +49,7 @@ const ModalContainer = ({
4849
{buttonText && (
4950
<SubmitButton
5051
type="button"
52+
onClick={onClick}
5153
width="w-full"
5254
height="h-[51px] "
5355
color={buttonColor}

components/modal/modalComponents/ModalInput.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { bindCls } from "@/lib/utils";
2+
import { ChangeEvent } from "react";
23

34
const ModalInput = ({
45
placeholder,
56
name,
7+
value,
8+
onChange,
69
}: {
710
placeholder: string;
811
name: string;
12+
value: string;
13+
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
914
}) => {
1015
return (
1116
<input
1217
type="text"
1318
name={name}
1419
id={name}
20+
value={value}
21+
onChange={onChange}
1522
className={bindCls(
1623
"w-full rounded-lg border border-gray300 py-[18px] px-[15px] mb-6 text-black300",
1724
"placeholder:text-base placeholder:text-gray400",

components/modal/modalComponents/ModalShare.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@ import ModalShareItem from "./ModalShareItem";
33
const ModalShare = () => {
44
return (
55
<div className="flex gap-8">
6-
<ModalShareItem src="/icons/Kakao.svg" text="카카오톡" bg="#FEE500" />
7-
<ModalShareItem src="/icons/Facebook.svg" text="페이스북" bg="#1877F2" />
8-
<ModalShareItem
9-
src="/icons/link.svg"
10-
text="링크 복사"
11-
bg="rgba(157, 157, 157, 0.04)"
12-
color="#6D6AFE"
13-
/>
6+
<div>
7+
<ModalShareItem src="/icons/Kakao.svg" text="카카오톡" bg="#FEE500" />
8+
</div>
9+
<div>
10+
<ModalShareItem
11+
src="/icons/Facebook.svg"
12+
text="페이스북"
13+
bg="#1877F2"
14+
/>
15+
</div>
16+
<div>
17+
<ModalShareItem
18+
src="/icons/link.svg"
19+
text="링크 복사"
20+
bg="rgba(157, 157, 157, 0.04)"
21+
color="#6D6AFE"
22+
/>
23+
</div>
1424
</div>
1525
);
1626
};

components/modal/modalManager/ModalManager.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export const Modal = () => {
3030
<AddModal
3131
list={
3232
props.list || [
33-
{ id: 1, title: "코딩팁", totalCount: 7 },
34-
{ id: 2, title: "채용 사이트", totalCount: 7 },
35-
{ id: 3, title: "유용한 글", totalCount: 7 },
36-
{ id: 4, title: "나만의 장소", totalCount: 7 },
33+
{ id: 1, name: "코딩팁", linkCount: 7, createAt: "" },
34+
{ id: 2, name: "채용 사이트", linkCount: 7, createAt: "" },
35+
{ id: 3, name: "유용한 글", linkCount: 7, createAt: "" },
36+
{ id: 4, name: "나만의 장소", linkCount: 7, createAt: "" },
3737
]
3838
}
3939
/>

lib/api/axiosInstanceApi.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const axiosInstance = axios.create({
88

99
export const proxy = axios.create({
1010
// 배포 이후에는 배포된 URL로 변경해야 함.
11-
// baseURL: "http://localhost:3000", -> baseURL을 안쓰면 로컬에서는 로컬3000, 배포했을때는 배포된 도메인으로 감
1211
baseURL: "http://localhost:3000",
1312
timeout: 5000,
1413
withCredentials: true,

pages/api/folders/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
console.log("Token:", token); // 쿠키 확인
8+
9+
if (!token) {
10+
return res.status(401).json({ error: "사용자 정보를 찾을 수 없습니다." });
11+
}
12+
13+
if (req.method === "POST") {
14+
try {
15+
const response = await axiosInstance.post("/folders", req.body, {
16+
headers: {
17+
Authorization: `Bearer ${token}`,
18+
},
19+
});
20+
console.log(response);
21+
return res.status(200).json({ message: "폴더 생성 성공" });
22+
} catch (error) {
23+
if (axios.isAxiosError(error) && error.response) {
24+
const status = error.response.status;
25+
const message = error.response.data?.message || "알 수 없는 오류 발생";
26+
return res.status(status).json({ message });
27+
}
28+
}
29+
} else {
30+
res.status(405).json({ message: "허용되지 않은 접근 방법" });
31+
}
32+
};
33+
34+
export default handler;

types/modalTypes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ export interface ModalPropType {
66
children?: ReactNode;
77
buttonText?: string;
88
buttonColor?: "positive" | "negative";
9+
onClick?: () => void;
910
folderName?: string;
1011
list?: FolderItemType[];
1112
link?: string;
1213
}
1314

14-
// 폴더 데이터 임시 타입 (실제 스웨거와 일치하지 않음)
1515
export interface FolderItemType {
1616
id: number;
17-
title: string;
18-
totalCount: number;
17+
createAt: string;
18+
name: string;
19+
linkCount: number;
1920
}

0 commit comments

Comments
 (0)