From e91818e130d7d4c5ac52e1d421e7df01e377955c Mon Sep 17 00:00:00 2001 From: bicochan Date: Mon, 2 Jun 2025 13:34:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EA=B0=80=EB=93=9C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/entities/menu/lib/menu-wrapper.tsx | 16 +- .../features/src/entities/post/index.ts | 1 + .../src/entities/post/lib/post-page-guard.tsx | 39 ++++ .../src/widgets/post/ui/post-page.tsx | 177 ++++++++--------- apps/cs/src/entities/post/index.ts | 1 + .../src/entities/post/lib/post-page-guard.tsx | 39 ++++ apps/cs/src/pages/bbs/model/table-columns.tsx | 9 +- apps/cs/src/widgets/post/ui/post-page.tsx | 184 +++++++++--------- 8 files changed, 262 insertions(+), 204 deletions(-) create mode 100644 apps/common/features/src/entities/post/lib/post-page-guard.tsx create mode 100644 apps/cs/src/entities/post/lib/post-page-guard.tsx diff --git a/apps/common/features/src/entities/menu/lib/menu-wrapper.tsx b/apps/common/features/src/entities/menu/lib/menu-wrapper.tsx index 1615dd572..2855e5ef0 100644 --- a/apps/common/features/src/entities/menu/lib/menu-wrapper.tsx +++ b/apps/common/features/src/entities/menu/lib/menu-wrapper.tsx @@ -2,7 +2,6 @@ import { useEffect } from "react"; import { usePathname, useRouter } from "next/navigation"; -import { useLocalStorage } from "@frontend-opensource/use-react-hooks"; import { MenuAuthorityApi } from "@/entities/menu-authority/@x/menu"; import { getCookie, useAlertStore, useMenuStore } from "@/shared/lib"; import { SITE_ID } from "@/shared/config"; @@ -14,14 +13,8 @@ const MenuWrapper = ({ children }: { children: React.ReactNode }) => { const pathname = usePathname(); const alert = useAlertStore((state) => state.setMessage); - const { - pageMenuAuthority, - setBbsInfo, - setCurrentMenuInfo, - setPageMenuAuthority, - } = useMenuStore((state) => state); - - const [storedBbsInfo] = useLocalStorage("bbs-info", ""); + const { pageMenuAuthority, setCurrentMenuInfo, setPageMenuAuthority } = + useMenuStore((state) => state); const getCurrentMenuInfo = async () => { const menuRoles = await MenuApi.getMenuRoles(SITE_ID); @@ -60,11 +53,6 @@ const MenuWrapper = ({ children }: { children: React.ReactNode }) => { alert("페이지에 대한 조회 권한이 없습니다.", () => router.push("/")); }, [pageMenuAuthority]); - useEffect(() => { - if (!storedBbsInfo) return; - setBbsInfo(JSON.parse(storedBbsInfo)); - }, [storedBbsInfo]); - return <>{children}; }; diff --git a/apps/common/features/src/entities/post/index.ts b/apps/common/features/src/entities/post/index.ts index d2b94ba84..cdc99b102 100644 --- a/apps/common/features/src/entities/post/index.ts +++ b/apps/common/features/src/entities/post/index.ts @@ -9,3 +9,4 @@ export { type PostFormData, type PostUpdateFormData, } from "./model/post-interface"; +export { PostPageGuard } from "./lib/post-page-guard"; diff --git a/apps/common/features/src/entities/post/lib/post-page-guard.tsx b/apps/common/features/src/entities/post/lib/post-page-guard.tsx new file mode 100644 index 000000000..c72f1be85 --- /dev/null +++ b/apps/common/features/src/entities/post/lib/post-page-guard.tsx @@ -0,0 +1,39 @@ +import { useEffect } from "react"; +import { useQuery } from "@tanstack/react-query"; +import { usePathname, useRouter } from "next/navigation"; +import { BoardApi } from "@/entities/board"; +import { useAlertStore, useMenuStore } from "@/shared/lib"; + +function PostPageGuard({ + bbsId, + children, +}: { + bbsId: string; + children: React.ReactNode; +}) { + const router = useRouter(); + const pathname = usePathname(); + const alert = useAlertStore((state) => state.setMessage); + const setBbsInfo = useMenuStore((state) => state.setBbsInfo); + + const { data: boardInfo, isLoading } = useQuery({ + queryKey: [bbsId], + queryFn: () => BoardApi.getBoardInfo(bbsId), + }); + + useEffect(() => { + if (!boardInfo) return; + setBbsInfo(boardInfo); + }, [boardInfo]); + + if (!isLoading && pathname && boardInfo) { + if (!pathname.includes(boardInfo.bbsTypeCd.toLowerCase())) { + alert("잘못된 경로로 접속하였습니다.", router.back); + return null; + } + } + + return children; +} + +export { PostPageGuard }; diff --git a/apps/common/features/src/widgets/post/ui/post-page.tsx b/apps/common/features/src/widgets/post/ui/post-page.tsx index 41d8584cf..8c4c8c998 100644 --- a/apps/common/features/src/widgets/post/ui/post-page.tsx +++ b/apps/common/features/src/widgets/post/ui/post-page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect, useRef, useState } from "react"; +import { useRef, useState } from "react"; import { usePathname, useRouter } from "next/navigation"; import { useConfirm } from "@frontend-opensource/use-react-hooks"; import { useQuery } from "@tanstack/react-query"; @@ -22,7 +22,12 @@ import { SelectValue, Skeleton, } from "@common/components"; -import { PostApi, type Post, type PostParams } from "@/entities/post"; +import { + PostApi, + PostPageGuard, + type Post, + type PostParams, +} from "@/entities/post"; import { ENDPOINT } from "@/shared/config"; import { useMenuStore, useUserStore } from "@/shared/lib"; import { GridViewDataTable } from "@/shared/ui/grid-view-data-table"; @@ -35,6 +40,7 @@ function PostPage({ bbsId }: { bbsId: string }) { const { confirm } = useConfirm(); const userInfo = useUserStore((state) => state.userInfo); const { bbsInfo, pageMenuAuthority } = useMenuStore((state) => state); + const thumbRefs = useRef>(new Map()); const [postParams, setPostParams] = useState({ keywordType: "title", @@ -46,8 +52,6 @@ function PostPage({ bbsId }: { bbsId: string }) { }); const [rowSelection, setRowSelection] = useState({}); - const thumbRefs = useRef>(new Map()); - const { data: upndFixPostList } = useQuery({ queryKey: [ENDPOINT.BOARD_SERVICE.POSTS_USER, bbsId, bbsInfo], queryFn: () => @@ -70,7 +74,7 @@ function PostPage({ bbsId }: { bbsId: string }) { const { data: postList, - isFetched, + isLoading, refetch, } = useQuery({ queryKey: [ENDPOINT.BOARD_SERVICE.POSTS_USER, bbsId], @@ -80,7 +84,6 @@ function PostPage({ bbsId }: { bbsId: string }) { page: pagination.pageIndex, size: pagination.pageSize, }), - enabled: false, }); const isGridViewPage = @@ -128,94 +131,92 @@ function PostPage({ bbsId }: { bbsId: string }) { router.push(`${pathname}/${row.pstNo}`); }; - useEffect(() => { - refetch(); - }, [pagination]); - return ( -
-
-
- - - - setPostParams({ ...postParams, keyword: e.target.value }) - } - className="h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]" - /> - -
-
-
-
-
-

콘텐츠 목록

-
- {pageMenuAuthority?.regAuthrtYn === "Y" && ( - - )} - {pageMenuAuthority?.delAuthrtYn === "Y" && ( - + +
+
+
+
+

콘텐츠 목록

+
+ {pageMenuAuthority?.regAuthrtYn === "Y" && ( + + )} + {pageMenuAuthority?.delAuthrtYn === "Y" && ( + + )} + { - table.setPageSize(parseInt(value)); - }} - > - - - - - {[10, 20, 30, 40, 50].map((pageSize) => ( - - {pageSize}개씩 보기 - - ))} - - + + + + + {[10, 20, 30, 40, 50].map((pageSize) => ( + + {pageSize}개씩 보기 + + ))} + + +
-
-
- {isFetched ? ( - - ) : ( - - )} +
+ {isLoading ? ( + + ) : ( + + )} +
-
+ ); } diff --git a/apps/cs/src/entities/post/index.ts b/apps/cs/src/entities/post/index.ts index 0e19b54e2..0f8d14e32 100644 --- a/apps/cs/src/entities/post/index.ts +++ b/apps/cs/src/entities/post/index.ts @@ -13,3 +13,4 @@ export { type PostUpdateFormData, type PostService, } from "./model/post-interface"; +export { PostPageGuard } from "./lib/post-page-guard"; diff --git a/apps/cs/src/entities/post/lib/post-page-guard.tsx b/apps/cs/src/entities/post/lib/post-page-guard.tsx new file mode 100644 index 000000000..c72f1be85 --- /dev/null +++ b/apps/cs/src/entities/post/lib/post-page-guard.tsx @@ -0,0 +1,39 @@ +import { useEffect } from "react"; +import { useQuery } from "@tanstack/react-query"; +import { usePathname, useRouter } from "next/navigation"; +import { BoardApi } from "@/entities/board"; +import { useAlertStore, useMenuStore } from "@/shared/lib"; + +function PostPageGuard({ + bbsId, + children, +}: { + bbsId: string; + children: React.ReactNode; +}) { + const router = useRouter(); + const pathname = usePathname(); + const alert = useAlertStore((state) => state.setMessage); + const setBbsInfo = useMenuStore((state) => state.setBbsInfo); + + const { data: boardInfo, isLoading } = useQuery({ + queryKey: [bbsId], + queryFn: () => BoardApi.getBoardInfo(bbsId), + }); + + useEffect(() => { + if (!boardInfo) return; + setBbsInfo(boardInfo); + }, [boardInfo]); + + if (!isLoading && pathname && boardInfo) { + if (!pathname.includes(boardInfo.bbsTypeCd.toLowerCase())) { + alert("잘못된 경로로 접속하였습니다.", router.back); + return null; + } + } + + return children; +} + +export { PostPageGuard }; diff --git a/apps/cs/src/pages/bbs/model/table-columns.tsx b/apps/cs/src/pages/bbs/model/table-columns.tsx index 27082424d..e47562fe3 100644 --- a/apps/cs/src/pages/bbs/model/table-columns.tsx +++ b/apps/cs/src/pages/bbs/model/table-columns.tsx @@ -2,9 +2,7 @@ import dayjs from "dayjs"; import { usePathname, useRouter } from "next/navigation"; import type { ColumnDef, Row } from "@tanstack/react-table"; -import { useLocalStorage } from "@frontend-opensource/use-react-hooks"; import type { Board } from "@/entities/board/model/board-interface"; -import { useMenuStore } from "@/shared/lib"; import { Button } from "@common/components"; export const columns: ColumnDef[] = [ @@ -52,19 +50,14 @@ export const columns: ColumnDef[] = [ const ManageButton = ({ row }: { row: Row }) => { const router = useRouter(); const pathname = usePathname(); - const [, setBbsInfo] = useLocalStorage("bbs-info", ""); - const setStoreBbsInfo = useMenuStore((state) => state.setBbsInfo); - const { bbsTypeCd, bbsId } = row.original; + return ( - -
-
-
-
-

콘텐츠 목록

-
- router.push(`${pathname}/register`)} - > - 등록 - - - 선택삭제 - - + +
+
+
+ + + + setPostParams({ ...postParams, keyword: e.target.value }) + } + className="h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]" + /> + +
+
+
+
+
+

콘텐츠 목록

+
+ router.push(`${pathname}/register`)} + > + 등록 + + + 선택삭제 + + +
-
-
- {isFetched ? ( - - ) : ( - - )} +
+ {isLoading ? ( + + ) : ( + + )} +
-
+ ); }