76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import { useRouter, usePathname } from "next/navigation";
|
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
|
import { Button } from "@common/components";
|
|
import { useMenuStore, useUserStore } from "@/shared/lib";
|
|
|
|
type PostActionProps = {
|
|
bbsId: string;
|
|
pstNo: string;
|
|
children: React.ReactNode;
|
|
handleDelete: () => Promise<void>;
|
|
};
|
|
|
|
function PostAction({ children, handleDelete }: PostActionProps) {
|
|
const router = useRouter();
|
|
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 (
|
|
<>
|
|
{children}
|
|
<div className="flex justify-center gap-4 pb-12 pt-10">
|
|
<Button
|
|
size="lg"
|
|
color="white"
|
|
type="button"
|
|
onClick={() => router.back()}
|
|
>
|
|
목록
|
|
</Button>
|
|
<Button
|
|
size="lg"
|
|
type="button"
|
|
onClick={() => router.push(`${pathname}/modify`)}
|
|
>
|
|
수정
|
|
</Button>
|
|
{bbsInfo?.ansUseYn === "Y" && (
|
|
<Button
|
|
size="lg"
|
|
type="button"
|
|
color="gray"
|
|
onClick={() => router.push(`${pathname}/answer`)}
|
|
disabled={!checkAnsUseAuthrt()}
|
|
>
|
|
답글
|
|
</Button>
|
|
)}
|
|
<Button size="lg" color="red" type="button" onClick={onDelete}>
|
|
삭제
|
|
</Button>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export { PostAction };
|