Skip to content

Commit e3d2452

Browse files
authored
feat: 댓글 전체 공개 상태 조회 구현 (#323)
2 parents 64df133 + 4b26960 commit e3d2452

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"use client";
2+
3+
import {
4+
getCommentsDisclosure,
5+
postCommentsDisclosure,
6+
} from "@/src/apis/comment";
7+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
8+
9+
const QUERY_KEY = ["comments-disclosure"];
10+
11+
export default function CommentsDisclosurePage() {
12+
const queryClient = useQueryClient();
13+
const { data, isLoading, isError } = useQuery(
14+
QUERY_KEY,
15+
getCommentsDisclosure
16+
);
17+
18+
const { mutate: updateDisclosure, isLoading: isUpdating } = useMutation(
19+
postCommentsDisclosure,
20+
{
21+
onSuccess: () => {
22+
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
23+
},
24+
onError: () => {
25+
alert("댓글 공개 상태 변경에 실패했습니다. 잠시 후 다시 시도해주세요.");
26+
},
27+
}
28+
);
29+
30+
if (isLoading) {
31+
return <div className="mt-10">로딩중...</div>;
32+
}
33+
34+
if (isError || data === undefined) {
35+
return <div className="mt-10">에러 발생</div>;
36+
}
37+
38+
const nextDisclosure = !data;
39+
40+
return (
41+
<section className="mt-10 flex flex-col gap-4 max-w-xl">
42+
<h2 className="text-xl font-semibold">댓글 전체 공개 상태 관리</h2>
43+
<div className="rounded-lg border p-6 flex items-center justify-between">
44+
<div className="text-lg font-medium">
45+
현재 상태:{" "}
46+
<span className={data ? "text-primary" : "text-gray-500"}>
47+
{data ? "활성화" : "비활성화"}
48+
</span>
49+
</div>
50+
<button
51+
type="button"
52+
className={`rounded-md text-white px-4 py-2 disabled:bg-gray-300 ${
53+
nextDisclosure
54+
? "bg-blue-500 hover:bg-blue-600"
55+
: "bg-gray-500 hover:bg-gray-600"
56+
}`}
57+
onClick={() => updateDisclosure(nextDisclosure)}
58+
disabled={isUpdating}
59+
>
60+
{nextDisclosure ? "활성화" : "비활성화"}
61+
</button>
62+
</div>
63+
</section>
64+
);
65+
}

frontend/components/admin/AdminTabs.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default function AdminTabs() {
1414
const tabs = [
1515
{ name: "멤버 권한 변경", href: `/admin/${generation}` },
1616
{ name: "지원서 on/off", href: `/admin/${generation}/on-off` },
17+
{ name: "댓글 전체 공개 on/off", href: `/admin/${generation}/comments-disclosure` },
1718
];
1819

1920
return (

frontend/src/apis/comment/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,16 @@ export const getCommentsIsLike = async (commentId: string) => {
107107

108108
return data;
109109
};
110+
111+
export const getCommentsDisclosure = async () => {
112+
const { data } = await https.get<boolean | string>(`/comments/disclosure`);
113+
return data === true || data === "true";
114+
};
115+
116+
export const postCommentsDisclosure = async (isDisclosure: boolean) => {
117+
const { data } = await https.post<boolean | string>(
118+
`/comments/disclosure`,
119+
`${isDisclosure}`
120+
);
121+
return data === true || data === "true";
122+
};

0 commit comments

Comments
 (0)