feat: 게시물 답글 버튼 권한 적용

This commit is contained in:
2025-05-13 17:03:22 +09:00
parent 8bebd0c2c3
commit 2352a395fb
8 changed files with 30 additions and 12 deletions
@@ -1,7 +1,7 @@
import { useRouter, usePathname } from "next/navigation";
import { useConfirm } from "@frontend-opensource/use-react-hooks";
import { Button } from "@common/components";
import { useMenuStore } from "@/shared/lib";
import { useMenuStore, useUserStore } from "@/shared/lib";
type PostActionProps = {
bbsId: string;
@@ -15,11 +15,25 @@ function PostAction({ children, handleDelete }: PostActionProps) {
const pathname = usePathname();
const { confirm } = useConfirm();
const { bbsInfo } = useMenuStore((state) => state);
const { userInfo } = useUserStore((state) => state);
const onDelete = async () => {
if (await confirm("삭제하시겠습니까?")) handleDelete();
};
const checkAnsUseAuthrt = () => {
// 관리자
if (bbsInfo?.ansUseAuthrt === "A") {
return userInfo?.adminRoleYn === "Y";
}
// 회원
if (bbsInfo?.ansUseAuthrt === "M") {
return !!userInfo;
}
// 비회원
return true;
};
return (
<div>
{children}
@@ -45,6 +59,7 @@ function PostAction({ children, handleDelete }: PostActionProps) {
type="button"
color="gray"
onClick={() => router.push(`${pathname}/answer`)}
disabled={!checkAnsUseAuthrt()}
>
답글
</Button>