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
@@ -17,7 +17,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
}
const response = await client.get<IUserInfo>(
`${ENDPOINT.USER_SERVICE.USERS}/${userId}`,
`${ENDPOINT.USER_SERVICE.USERS}/info/me`,
);
if (!userInfo) setUserInfo(response.data);
}
@@ -5,6 +5,7 @@ export interface IUserInfo {
mdfcnDt: string;
rgtr: string;
mdfr: string;
adminRoleYn: string;
userUnqId: string;
userId: string;
userName: string;
@@ -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>
@@ -19,7 +19,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
}
const response = await client.get<IUserInfo>(
`${ENDPOINT.USER_SERVICE.USERS}/${userId}`,
`${ENDPOINT.USER_SERVICE.USERS}/info/me`,
);
if (!userInfo) setUserInfo(response.data);
}
@@ -82,7 +82,9 @@ function ManagementAuthorityDialog({
<DialogHeader>
<DialogTitle>그룹별 메뉴 권한</DialogTitle>
</DialogHeader>
<DataTable table={table} />
<div className="max-h-[40rem] overflow-auto">
<DataTable table={table} />
</div>
<DialogFooter className="!justify-center">
<Button size="lg" onClick={handleSave}>
저장
@@ -128,7 +128,9 @@ function ManagementAuthorityDialog({
</TableRow>
</TableBody>
</Table>
<DataTable table={table} />
<div className="max-h-[40rem] overflow-auto">
<DataTable table={table} />
</div>
</div>
<DialogFooter className="!justify-center">
<Button size="lg" onClick={handleSave}>
+2 -2
View File
@@ -37,9 +37,9 @@ export interface IUser {
const client = getApiClient();
export const getUserInfo = async (userUniqId: string) => {
export const getUserInfo = async () => {
const response = await client.get<IUser>(
`${ENDPOINT.USER_SERVICE.USERS}/${userUniqId}`,
`${ENDPOINT.USER_SERVICE.USERS}/info/me`,
);
return response.data;
};
@@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";
import { images } from "@common/assets";
import { getConfig } from "@common/config";
import { ENDPOINT } from "../../config";
import { getCookie, setCookie } from "../../lib";
import { setCookie } from "../../lib";
import { getSiteInfo, getUserInfo } from "../../api";
import {
DropdownMenu,
@@ -12,14 +12,12 @@ import {
} from "../dropdown-menu";
import { Button } from "../button";
const { AUTH_USER_ID, SITE_ID } = getConfig();
const { SITE_ID } = getConfig();
export function Header({ viewOnly }: { viewOnly?: boolean }) {
const userUniqId = getCookie(AUTH_USER_ID ?? "") ?? "";
const { data: userInfo } = useQuery({
queryKey: [ENDPOINT.USER_SERVICE.USERS],
queryFn: () => getUserInfo(userUniqId),
queryFn: () => getUserInfo(),
enabled: !viewOnly,
});