[common/features] feat: 게시글 내 수정 및 삭제 버튼 권한 적용
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export { MenuAuthorityApi } from "./api/menu-authority-service";
|
||||
export { type PageMenuAuthority } from "./model/menu-authority-interface";
|
||||
export { AuthorityButton } from "./ui/authority-button";
|
||||
export { ManagementAuthorityDialog } from "./ui/management-authority-dialog";
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useMenuStore } from "@/shared/lib";
|
||||
import { Button, cn, type ButtonProps } from "@common/components";
|
||||
import type { PageMenuAuthority } from "../model/menu-authority-interface";
|
||||
|
||||
type AuthorityButtonProps = {
|
||||
authority: keyof PageMenuAuthority;
|
||||
} & ButtonProps;
|
||||
|
||||
function AuthorityButton({
|
||||
authority,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: AuthorityButtonProps) {
|
||||
const pageMenuAuthority = useMenuStore((state) => state.pageMenuAuthority);
|
||||
|
||||
const isAuthority = pageMenuAuthority?.[authority] === "Y";
|
||||
|
||||
return (
|
||||
<Button className={cn(className, !isAuthority && "hidden")} {...props}>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export { AuthorityButton };
|
||||
@@ -2,21 +2,24 @@ 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";
|
||||
import { AuthorityButton } from "@/entities/menu-authority";
|
||||
|
||||
type PostActionProps = {
|
||||
bbsId: string;
|
||||
pstNo: string;
|
||||
registerId?: string;
|
||||
children: React.ReactNode;
|
||||
handleDelete: () => Promise<void>;
|
||||
};
|
||||
|
||||
function PostAction({ children, handleDelete }: PostActionProps) {
|
||||
function PostAction({ registerId, children, handleDelete }: PostActionProps) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const { confirm } = useConfirm();
|
||||
const bbsInfo = useMenuStore((state) => state.bbsInfo);
|
||||
const userInfo = useUserStore((state) => state.userInfo);
|
||||
|
||||
const actionButtonAuthrt =
|
||||
userInfo?.adminRoleYn === "Y" || userInfo?.userUnqId === registerId;
|
||||
|
||||
const onDelete = async () => {
|
||||
if (await confirm("삭제하시겠습니까?")) handleDelete();
|
||||
};
|
||||
@@ -46,15 +49,19 @@ function PostAction({ children, handleDelete }: PostActionProps) {
|
||||
>
|
||||
목록
|
||||
</Button>
|
||||
<Button
|
||||
size="lg"
|
||||
type="button"
|
||||
onClick={() => router.push(`${pathname}/modify`)}
|
||||
>
|
||||
수정
|
||||
</Button>
|
||||
{actionButtonAuthrt && (
|
||||
<AuthorityButton
|
||||
authority="mdfcnAuthrtYn"
|
||||
size="lg"
|
||||
type="button"
|
||||
onClick={() => router.push(`${pathname}/modify`)}
|
||||
>
|
||||
수정
|
||||
</AuthorityButton>
|
||||
)}
|
||||
{bbsInfo?.ansUseYn === "Y" && (
|
||||
<Button
|
||||
<AuthorityButton
|
||||
authority="regAuthrtYn"
|
||||
size="lg"
|
||||
type="button"
|
||||
color="gray"
|
||||
@@ -62,11 +69,19 @@ function PostAction({ children, handleDelete }: PostActionProps) {
|
||||
disabled={!checkAnsUseAuthrt()}
|
||||
>
|
||||
답글
|
||||
</Button>
|
||||
</AuthorityButton>
|
||||
)}
|
||||
{actionButtonAuthrt && (
|
||||
<AuthorityButton
|
||||
authority="delAuthrtYn"
|
||||
size="lg"
|
||||
color="red"
|
||||
type="button"
|
||||
onClick={onDelete}
|
||||
>
|
||||
삭제
|
||||
</AuthorityButton>
|
||||
)}
|
||||
<Button size="lg" color="red" type="button" onClick={onDelete}>
|
||||
삭제
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -125,7 +125,7 @@ function Post({ bbsId, pstNo }: { bbsId: string; pstNo: string }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<PostAction bbsId={bbsId} pstNo={pstNo} handleDelete={handleDelete}>
|
||||
<PostAction registerId={postData?.rgtr} handleDelete={handleDelete}>
|
||||
<div className="card card-border !p-8">
|
||||
<h3 className="text-[2rem] font-bold text-foreground">
|
||||
{postData?.pstTtl}
|
||||
|
||||
Reference in New Issue
Block a user