feat: 답글 버튼 노출 조건 분기 처리

This commit is contained in:
2025-05-12 11:34:18 +09:00
parent 0954e21b25
commit 1a8053910d
@@ -1,6 +1,11 @@
import { useEffect, useState } from "react";
import { useRouter, usePathname } from "next/navigation";
import { useConfirm } from "@frontend-opensource/use-react-hooks";
import {
useConfirm,
useLocalStorage,
} from "@frontend-opensource/use-react-hooks";
import { Button } from "@common/components";
import type { Board } from "@/entities/board";
type PostActionProps = {
bbsId: string;
@@ -12,13 +17,18 @@ type PostActionProps = {
function PostAction({ children, handleDelete }: PostActionProps) {
const router = useRouter();
const pathname = usePathname();
const { confirm } = useConfirm();
const [storedBbsInfo] = useLocalStorage("bbs-info", "");
const [bbsInfo, setBbsInfo] = useState<Board | null>(null);
const onDelete = async () => {
if (await confirm("삭제하시겠습니까?")) handleDelete();
};
useEffect(() => {
if (storedBbsInfo) setBbsInfo(JSON.parse(storedBbsInfo));
}, [storedBbsInfo]);
return (
<div>
{children}
@@ -38,14 +48,16 @@ function PostAction({ children, handleDelete }: PostActionProps) {
>
수정
</Button>
<Button
size="lg"
type="button"
color="gray"
onClick={() => router.push(`${pathname}/answer`)}
>
답글
</Button>
{bbsInfo?.ansUseYn === "Y" && (
<Button
size="lg"
type="button"
color="gray"
onClick={() => router.push(`${pathname}/answer`)}
>
답글
</Button>
)}
<Button size="lg" color="red" type="button" onClick={onDelete}>
삭제
</Button>