Compare commits
277
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2751232e1 | ||
|
|
48c1cced18 | ||
|
|
92b5341cd1 | ||
|
|
010ced20b5 | ||
|
|
c6cf493b51 | ||
|
|
623b1e985e | ||
|
|
84d4635a75 | ||
|
|
0a51ac3f79 | ||
|
|
4e4bd82009 | ||
|
|
a9739bdba5 | ||
|
|
1d132a86de | ||
|
|
6297d528fb | ||
|
|
3832adf3b0 | ||
|
|
60464b92b0 | ||
|
|
a912deeefb | ||
|
|
f2954e6ebd | ||
|
|
26854a8610 | ||
|
|
67d57e3060 | ||
|
|
ea319aa5ab | ||
|
|
8117ca5c2c | ||
|
|
c3fdf92f5c | ||
|
|
7216d6a74e | ||
|
|
0aee493d32 | ||
|
|
16511de37d | ||
|
|
e3fc4e4dbf | ||
|
|
0cfe98f4b7 | ||
|
|
7860345e89 | ||
|
|
84519658c1 | ||
|
|
8b9d493ccd | ||
|
|
ca1c0be47f | ||
|
|
cd455fa343 | ||
|
|
701d042d4f | ||
|
|
f59320d2ff | ||
|
|
572f18cc1a | ||
|
|
6a784cecf3 | ||
|
|
cb5e90c277 | ||
|
|
c221a4537e | ||
|
|
050ce81481 | ||
|
|
89f31c4c6b | ||
|
|
e32d0ba144 | ||
|
|
8b0939ff41 | ||
|
|
ae5597b1f3 | ||
|
|
0fa026e11b | ||
|
|
5c7ab94922 | ||
|
|
c5f1718441 | ||
|
|
73badb5ac5 | ||
|
|
e127180cb7 | ||
|
|
b26e7e3d10 | ||
|
|
f03b07738e | ||
|
|
d4f7cf140e | ||
|
|
131ceec61e | ||
|
|
e92f36f739 | ||
|
|
59c57d45d5 | ||
|
|
5b4e674214 | ||
|
|
f94b8a3f8e | ||
|
|
403bbe3647 | ||
|
|
752b5fa789 | ||
|
|
36c3bcb0b4 | ||
|
|
64d336c2a4 | ||
|
|
4cbead44db | ||
|
|
517ab0f272 | ||
|
|
5df4f6dd15 | ||
|
|
92f67ce1a3 | ||
|
|
2aee109912 | ||
|
|
8f4dc1bd34 | ||
|
|
ada14e0003 | ||
|
|
18e9708af1 | ||
|
|
8aa6d20c63 | ||
|
|
791098e0c0 | ||
|
|
89cec5291d | ||
|
|
539585f495 | ||
|
|
b459036a59 | ||
|
|
f749bee140 | ||
|
|
c4a9aabce7 | ||
|
|
d8d5c16d31 | ||
|
|
deeb670150 | ||
|
|
b1f3de08a7 | ||
|
|
699eadb399 | ||
|
|
580d449f3e | ||
|
|
b8e0a8a878 | ||
|
|
55ac57d73c | ||
|
|
fadb57242d | ||
|
|
dc01c897a9 | ||
|
|
b2141d9708 | ||
|
|
e49e3d3b36 | ||
|
|
915543628d | ||
|
|
6f0e1a6e40 | ||
|
|
4e0e05ea78 | ||
|
|
25a2ac5716 | ||
|
|
c31a6ea8bf | ||
|
|
a13ea5d6e9 | ||
|
|
8f484e8425 | ||
|
|
e7f2b3e3ee | ||
|
|
4933fc164a | ||
|
|
8aa713e285 | ||
|
|
daacb2cb25 | ||
|
|
d88afe7034 | ||
|
|
4a88315a99 | ||
|
|
f767d0a688 | ||
|
|
57e9daf772 | ||
|
|
4ed2a45486 | ||
|
|
08e9cb98e9 | ||
|
|
0b9b5bd22c | ||
|
|
e5265a10d0 | ||
|
|
4e869b2c70 | ||
|
|
d404de4afb | ||
|
|
c7039294c9 | ||
|
|
574286139c | ||
|
|
c81735b8b8 | ||
|
|
e2c80a9530 | ||
|
|
39bf03c4f5 | ||
|
|
e16ff92e72 | ||
|
|
cd03d6f42e | ||
|
|
4a8383da73 | ||
|
|
babf7055b4 | ||
|
|
05f3e48ed6 | ||
|
|
6e3b9aaa37 | ||
|
|
594dbd9fc7 | ||
|
|
daf9a52aec | ||
|
|
b8cf245cac | ||
|
|
e178fe370c | ||
|
|
ec5acf9291 | ||
|
|
5505838bc5 | ||
|
|
9277ffbde9 | ||
|
|
d4a2b5641d | ||
|
|
50ffc2d763 | ||
|
|
d5c376ca54 | ||
|
|
6542635391 | ||
|
|
2618fc7fbe | ||
|
|
8bd0bf3346 | ||
|
|
d80f649018 | ||
|
|
4c441a9c28 | ||
|
|
f541687c00 | ||
|
|
64a615258d | ||
|
|
b64ff7c081 | ||
|
|
00ba7de206 | ||
|
|
ffb15a7e3a | ||
|
|
59f35775b1 | ||
|
|
71e70c842b | ||
|
|
f026268aa8 | ||
|
|
ca78815ab5 | ||
|
|
0588bf0d7f | ||
|
|
396992fe1b | ||
|
|
25566be2c6 | ||
|
|
3507bb63c3 | ||
|
|
6528151aea | ||
|
|
49bcf4037f | ||
|
|
108e2a8746 | ||
|
|
42647d6ce3 | ||
|
|
afd8925792 | ||
|
|
104a7b0079 | ||
|
|
6e41c09157 | ||
|
|
4cb3e10686 | ||
|
|
b79629704a | ||
|
|
0d57bde4fd | ||
|
|
66fe8b3ef6 | ||
|
|
53bad41e53 | ||
|
|
43cbae0a7e | ||
|
|
6fc30dd4c6 | ||
|
|
23ccb53e8c | ||
|
|
b7e204f744 | ||
|
|
4126a6c3a8 | ||
|
|
0042f0b8c9 | ||
|
|
0900c469e2 | ||
|
|
6f3115f523 | ||
|
|
e2ae39c73c | ||
|
|
7807da99c6 | ||
|
|
c13ce271ff | ||
|
|
2f8f1b5ddc | ||
|
|
cddb5e0187 | ||
|
|
89eaefeb84 | ||
|
|
7262a03ec7 | ||
|
|
58a0c5f1de | ||
|
|
bc0dee3030 | ||
|
|
5c81e35bc4 | ||
|
|
a338afb36c | ||
|
|
d145eee662 | ||
|
|
2d341c1314 | ||
|
|
5785e57b40 | ||
|
|
8104ba825f | ||
|
|
8dfa052ea6 | ||
|
|
1b41ec5873 | ||
|
|
2f4745a65a | ||
|
|
1158b77ecb | ||
|
|
e0ef37e9d7 | ||
|
|
0ad1fdd253 | ||
|
|
718187a25d | ||
|
|
a2b0e9dfb3 | ||
|
|
19d765266f | ||
|
|
ad7c01eb4d | ||
|
|
2756b075d0 | ||
|
|
56ae9ec3c7 | ||
|
|
971c4a5615 | ||
|
|
e4d5e21b29 | ||
|
|
842461eb53 | ||
|
|
818fec3f75 | ||
|
|
fa0d220aab | ||
|
|
622b8bcf94 | ||
|
|
68ed0f6436 | ||
|
|
4775da6725 | ||
|
|
411a47a0b8 | ||
|
|
16b296e2fb | ||
|
|
6d4004fd86 | ||
|
|
d04a79d1cc | ||
|
|
1d8426224e | ||
|
|
fcf45107b1 | ||
|
|
021a282655 | ||
|
|
03abe7ae90 | ||
|
|
e7bff1579e | ||
|
|
d209213f02 | ||
|
|
811c6e62db | ||
|
|
87031def3c | ||
|
|
c0abd6d53f | ||
|
|
d9c77bcc5b | ||
|
|
24d7ed06fe | ||
|
|
7c03f04078 | ||
|
|
efa63f9c6a | ||
|
|
37c2901976 | ||
|
|
ff83a6c7dd | ||
|
|
584484bbd0 | ||
|
|
12f6f42b0e | ||
|
|
2a25f9b113 | ||
|
|
ab95b278cd | ||
|
|
48d55b0578 | ||
|
|
ff7bd16a6e | ||
|
|
e50799c726 | ||
|
|
dae9374b28 | ||
|
|
34a133b35c | ||
|
|
432579de83 | ||
|
|
ff3b2f18b5 | ||
|
|
c96b2600dd | ||
|
|
90c36533f4 | ||
|
|
6fe828d77f | ||
|
|
b4403ab687 | ||
|
|
2815110cb9 | ||
|
|
a244917de7 | ||
|
|
58d5175ee5 | ||
|
|
54e6ae3443 | ||
|
|
9f71e5527c | ||
|
|
bf8dbffd15 | ||
|
|
9b44458a12 | ||
|
|
77b779be6a | ||
|
|
0f1ff0ff68 | ||
|
|
4598bbb0ca | ||
|
|
3ef2795844 | ||
|
|
62d29d51f0 | ||
|
|
d31a2776a4 | ||
|
|
c6dea2e397 | ||
|
|
41c8c11ec0 | ||
|
|
fa5ef73261 | ||
|
|
7078f932ef | ||
|
|
7aa6f3449d | ||
|
|
c320a75cdd | ||
|
|
3704927378 | ||
|
|
e6f097355c | ||
|
|
624d5434db | ||
|
|
1ed87ab8fb | ||
|
|
c995f6a112 | ||
|
|
cea633c7b1 | ||
|
|
c51f2d977d | ||
|
|
b1ae5126f2 | ||
|
|
910eee4100 | ||
|
|
54ba841d6d | ||
|
|
86c29bc790 | ||
|
|
d51358a59a | ||
|
|
1ea71aa2ad | ||
|
|
8be4a7c086 | ||
|
|
c4e021f8b5 | ||
|
|
5a3e849e81 | ||
|
|
249f3fa883 | ||
|
|
73f1431087 | ||
|
|
ecb138a619 | ||
|
|
bbfc08e9de | ||
|
|
41a9deb098 | ||
|
|
0a4334dba2 | ||
|
|
e783084086 | ||
|
|
c45bccf9ce |
+14
-2
@@ -1,8 +1,20 @@
|
|||||||
# turbo
|
# turbo
|
||||||
.turbo
|
.turbo/
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
node_modules
|
node_modules/
|
||||||
|
|
||||||
|
# build
|
||||||
|
.next/
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# build
|
||||||
|
.next
|
||||||
|
dist
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# env
|
||||||
|
.env*
|
||||||
|
.qodo
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
## 새로운 프로젝트 설치 및 실행
|
## 새로운 프로젝트 설치 및 실행
|
||||||
|
|
||||||
### 1. 프로젝트 생성(Next.js)
|
### 1. 프로젝트 생성(Next.js 기준)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx create-next-app@latest ./apps/as --typescript --eslint --tailwind --app
|
npx create-next-app@latest ./apps/as --typescript --eslint --tailwind --app
|
||||||
@@ -44,6 +44,12 @@ npx create-next-app@latest ./apps/as --typescript --eslint --tailwind --app
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
// 기타 설정 ...
|
// 기타 설정 ...
|
||||||
|
"scripts": {
|
||||||
|
"dev": "next dev",
|
||||||
|
"build": "next build",
|
||||||
|
"start": "next start",
|
||||||
|
"lint": "next lint"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@common/components": "workspace:*", // 추가
|
"@common/components": "workspace:*", // 추가
|
||||||
"react": "^19.0.0", // 제거
|
"react": "^19.0.0", // 제거
|
||||||
@@ -62,7 +68,10 @@ npx create-next-app@latest ./apps/as --typescript --eslint --tailwind --app
|
|||||||
{
|
{
|
||||||
// 기타 설정 ...
|
// 기타 설정 ...
|
||||||
"paths": {
|
"paths": {
|
||||||
"@common/components": ["../../packages/common/components/src"], // 추가
|
"@common/components/*": ["../../../packages/common/components/src/*"],
|
||||||
|
"@common/components": ["../../../packages/common/components/src"],
|
||||||
|
"@common/network/*": ["../../../packages/common/network/*"],
|
||||||
|
"@common/network": ["../../../packages/common/network/"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -83,10 +92,66 @@ export default {
|
|||||||
} satisfies Config;
|
} satisfies Config;
|
||||||
```
|
```
|
||||||
|
|
||||||
### 5. globals.css(또는 전역 css) 수정
|
### 5. next.config.ts 수정
|
||||||
|
```json
|
||||||
|
import type { NextConfig } from "next";
|
||||||
|
import webpack from "webpack";
|
||||||
|
|
||||||
|
const serverApiUrl =
|
||||||
|
process.env.NEXT_PUBLIC_SERVER_API_URL || "http://localhost:3000";
|
||||||
|
|
||||||
|
const nextConfig: NextConfig = {
|
||||||
|
webpack: (config) => {
|
||||||
|
config.plugins.push(
|
||||||
|
// common/components의 vite 환경 변수를 next 환경 변수로 정의
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
"import.meta.env.VITE_PORT": JSON.stringify(
|
||||||
|
process.env.NEXT_PUBLIC_PORT,
|
||||||
|
),
|
||||||
|
"import.meta.env.VITE_PROXY_HOST": JSON.stringify(
|
||||||
|
process.env.NEXT_PUBLIC_PROXY_HOST,
|
||||||
|
),
|
||||||
|
"import.meta.env.VITE_SERVER_API_URL": JSON.stringify(
|
||||||
|
process.env.NEXT_PUBLIC_SERVER_API_URL,
|
||||||
|
),
|
||||||
|
"import.meta.env.VITE_SITE_ID": JSON.stringify(process.env.SITE_ID),
|
||||||
|
"import.meta.env.VITE_CLAIM_NAME": JSON.stringify(
|
||||||
|
process.env.NEXT_PUBLIC_CLAIM_NAME,
|
||||||
|
),
|
||||||
|
"import.meta.env.VITE_ACCESS_TOKEN": JSON.stringify(
|
||||||
|
process.env.NEXT_PUBLIC_ACCESS_TOKEN,
|
||||||
|
),
|
||||||
|
"import.meta.env.VITE_REFRESH_TOKEN": JSON.stringify(
|
||||||
|
process.env.NEXT_PUBLIC_REFRESH_TOKEN,
|
||||||
|
),
|
||||||
|
"import.meta.env.VITE_AUTH_USER_ID": JSON.stringify(
|
||||||
|
process.env.NEXT_PUBLIC_AUTH_USER_ID,
|
||||||
|
),
|
||||||
|
"process.env.SITE_ID": JSON.stringify(process.env.NEXT_PUBLIC_SITE_ID),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
async rewrites() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: "/server/:path*",
|
||||||
|
destination: `${serverApiUrl}/:path*`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default nextConfig;
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. globals.css(또는 전역 css) 수정
|
||||||
|
|
||||||
```css
|
```css
|
||||||
@import "@common/assets/index.css";
|
@import "@common/assets/styles/base.css";
|
||||||
|
@import "@common/assets/styles/diveicon.css";
|
||||||
|
@import "@common/assets/styles/components.css";
|
||||||
|
|
||||||
@tailwind base;
|
@tailwind base;
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@@ -95,7 +160,7 @@ export default {
|
|||||||
/* 기타 스타일 */
|
/* 기타 스타일 */
|
||||||
```
|
```
|
||||||
|
|
||||||
### 6. 패키지 의존성 재설치
|
### 7. 패키지 의존성 재설치
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
rm -rf node_modules pnpm-lock.yaml
|
rm -rf node_modules pnpm-lock.yaml
|
||||||
@@ -109,7 +174,7 @@ pnpm install
|
|||||||
- Next.js(^15)
|
- Next.js(^15)
|
||||||
- Tailwind CSS(^3)
|
- Tailwind CSS(^3)
|
||||||
- react-dnd-treeview(^3)
|
- react-dnd-treeview(^3)
|
||||||
- ~~TUI Grid(^4)~~ -> TanStack Table (v8)
|
- TanStack Table (v8)
|
||||||
- Chart.js(^4)
|
- Chart.js(^4)
|
||||||
- Storybook(^8)
|
- Storybook(^8)
|
||||||
- tus-js-client(^4)
|
- tus-js-client(^4)
|
||||||
@@ -120,3 +185,15 @@ pnpm install
|
|||||||
## 링크
|
## 링크
|
||||||
|
|
||||||
- 컴포넌트 가이드(스토리북): http://www.onasys.co.kr/design/template
|
- 컴포넌트 가이드(스토리북): http://www.onasys.co.kr/design/template
|
||||||
|
|
||||||
|
|
||||||
|
## API 서버
|
||||||
|
http://dev.onasys.co.kr:8000
|
||||||
|
|
||||||
|
## Swagger
|
||||||
|
http://dev.onasys.co.kr:8000/webjars/swagger-ui/index.html?urls.primaryName=attach-service
|
||||||
|
|
||||||
|
## 개발 가이드
|
||||||
|
- 사이드바 메뉴 클릭 시 "menuCd" 데이터 쿠키 저장 처리
|
||||||
|
- 쿠키명 : menu-code-key
|
||||||
|
- 해당 메뉴 쿠키 데이터 가져와 페이지 권한 및 상당 Breadcrumb 데이터 전달 처리
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
NEXT_PUBLIC_PORT=3000
|
||||||
|
NEXT_PUBLIC_SERVER_API_URL=http://192.168.0.102:8000
|
||||||
@@ -30,9 +30,6 @@ yarn-debug.log*
|
|||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
.pnpm-debug.log*
|
.pnpm-debug.log*
|
||||||
|
|
||||||
# env files (can opt-in for committing if needed)
|
|
||||||
.env*
|
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { ApimanPage } from "@/pages/apiman";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
return <ApimanPage />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { ModifyPage as VModifyPage } from "@/pages/apiman/ui/modify-page";
|
||||||
|
|
||||||
|
|
||||||
|
export default async function ModifyPage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ id: number}>;
|
||||||
|
}) {
|
||||||
|
const { id } = await params;
|
||||||
|
return <VModifyPage authorizationNo={id} />;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { CreatePage } from "@/pages/apiman/ui/create-page";
|
||||||
|
export default CreatePage;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
import { DashboardPage } from "@/pages/dashboard";
|
||||||
|
export default DashboardPage;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { GroupPage } from "@/pages/group";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
return <GroupPage />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { ModifyPage as VModifyPage } from "@/pages/group/ui/modify-page";
|
||||||
|
|
||||||
|
export default async function ModifyPage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ id: string }>;
|
||||||
|
}) {
|
||||||
|
const { id } = await params;
|
||||||
|
return <VModifyPage groupId={id} />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { CreatePage } from "@/pages/group/ui/create-page";
|
||||||
|
export default CreatePage;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
import { ImagePage } from "@/pages/image";
|
||||||
|
export default ImagePage;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { ModifyPage as VModifyPage } from "@/pages/image";
|
||||||
|
|
||||||
|
export default async function ModifyPage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ serial: string }>;
|
||||||
|
}) {
|
||||||
|
const { serial } = await params;
|
||||||
|
return <VModifyPage serial={serial} />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
import { CreatePage } from "@/pages/image";
|
||||||
|
export default CreatePage;
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
import type { MenuItem } from "@common/components/api";
|
||||||
|
import { BaseLayout } from "@common/components/ui";
|
||||||
|
import { useMenuStore } from "@/shared/lib";
|
||||||
|
import { PageLayout } from "@/shared/ui/page-layout";
|
||||||
|
|
||||||
|
export default function WithBaseLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const { setCurrentMenuInfo } = useMenuStore((state) => state);
|
||||||
|
|
||||||
|
const handleMenuClick = (item: MenuItem) => {
|
||||||
|
setCurrentMenuInfo(item);
|
||||||
|
router.push(item.urlPath);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BaseLayout
|
||||||
|
queryClient={queryClient}
|
||||||
|
currentPath={pathname ?? ""}
|
||||||
|
handleMenuClick={handleMenuClick}
|
||||||
|
>
|
||||||
|
<PageLayout>{children}</PageLayout>
|
||||||
|
</BaseLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
import { MenuPage } from "@/pages/menu";
|
||||||
|
export default MenuPage;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { ModifyPage as VModifyPage } from "@/pages/site";
|
||||||
|
|
||||||
|
export default async function ModifyPage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ id: string }>;
|
||||||
|
}) {
|
||||||
|
const { id } = await params;
|
||||||
|
return <VModifyPage siteId={id} />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
import { CreatePage } from "@/pages/site";
|
||||||
|
export default CreatePage;
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import {
|
||||||
|
ACCESS_TOKEN,
|
||||||
|
AUTH_USER_ID,
|
||||||
|
CLAIM_NAME,
|
||||||
|
REFRESH_TOKEN,
|
||||||
|
SERVER_API_URL,
|
||||||
|
SITE_ID,
|
||||||
|
} from "@/shared/config";
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
async function handler(
|
||||||
|
request: Request,
|
||||||
|
params: { url: string[] },
|
||||||
|
method: "GET" | "POST" | "PUT" | "DELETE",
|
||||||
|
) {
|
||||||
|
const cookieStore = await cookies();
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-Site-Id": SITE_ID,
|
||||||
|
};
|
||||||
|
let body = {};
|
||||||
|
const isRefreshHandler = params.url.includes("refresh");
|
||||||
|
|
||||||
|
// silent refresh
|
||||||
|
if (isRefreshHandler) {
|
||||||
|
const refreshToken = cookieStore.get(REFRESH_TOKEN);
|
||||||
|
headers[CLAIM_NAME] = refreshToken?.value ?? "";
|
||||||
|
|
||||||
|
if (!headers[CLAIM_NAME]) {
|
||||||
|
return NextResponse.json({ message: "Can't refresh" }, { status: 401 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!isRefreshHandler) {
|
||||||
|
body = await request.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await fetch(`${SERVER_API_URL}/${params.url.join("/")}`, {
|
||||||
|
method,
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.ok) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ message: "Invalid Credentials" },
|
||||||
|
{ status: 401 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const accessToken = result.headers.get(ACCESS_TOKEN);
|
||||||
|
const refreshToken = result.headers.get(REFRESH_TOKEN);
|
||||||
|
const userId = result.headers.get(AUTH_USER_ID);
|
||||||
|
|
||||||
|
if (accessToken && userId) {
|
||||||
|
const response = NextResponse.json({
|
||||||
|
[ACCESS_TOKEN]: accessToken,
|
||||||
|
[AUTH_USER_ID]: userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (refreshToken) {
|
||||||
|
cookieStore.set(REFRESH_TOKEN, refreshToken, {
|
||||||
|
httpOnly: true,
|
||||||
|
sameSite: "lax",
|
||||||
|
path: "/",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{ message: "Invalid Credentials" },
|
||||||
|
{ status: 401 },
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ message: "Server Error", error },
|
||||||
|
{ status: 500 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
request: Request,
|
||||||
|
props: { params: Promise<{ url: string[] }> },
|
||||||
|
) {
|
||||||
|
const params = await props.params;
|
||||||
|
return handler(request, params, "POST");
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PUT(
|
||||||
|
request: Request,
|
||||||
|
props: { params: Promise<{ url: string[] }> },
|
||||||
|
) {
|
||||||
|
const params = await props.params;
|
||||||
|
return handler(request, params, "PUT");
|
||||||
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
import { RegisterPage } from "@/pages/site";
|
|
||||||
export default RegisterPage;
|
|
||||||
Vendored
+16
@@ -0,0 +1,16 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
interface ImportMetaEnv {
|
||||||
|
readonly VITE_PORT: string;
|
||||||
|
readonly VITE_PROXY_HOST: string;
|
||||||
|
readonly VITE_SERVER_API_URL: string;
|
||||||
|
readonly VITE_SITE_ID: string;
|
||||||
|
readonly VITE_CLAIM_NAME: string;
|
||||||
|
readonly VITE_ACCESS_TOKEN: string;
|
||||||
|
readonly VITE_REFRESH_TOKEN: string;
|
||||||
|
readonly VITE_AUTH_USER_ID: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportMeta {
|
||||||
|
readonly env: ImportMetaEnv;
|
||||||
|
}
|
||||||
@@ -11,6 +11,11 @@ const compat = new FlatCompat({
|
|||||||
|
|
||||||
const eslintConfig = [
|
const eslintConfig = [
|
||||||
...compat.extends("next/core-web-vitals", "next/typescript"),
|
...compat.extends("next/core-web-vitals", "next/typescript"),
|
||||||
|
{
|
||||||
|
rules: {
|
||||||
|
"react-hooks/exhaustive-deps": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default eslintConfig;
|
export default eslintConfig;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
const serverApiUrl =
|
||||||
|
process.env.NEXT_PUBLIC_SERVER_API_URL ?? "http://localhost:3000";
|
||||||
|
|
||||||
|
export function middleware(req: NextRequest) {
|
||||||
|
const pathname = req.nextUrl.pathname;
|
||||||
|
const searchParams = req.nextUrl.searchParams;
|
||||||
|
|
||||||
|
if (pathname.startsWith("/server")) {
|
||||||
|
const queryParams = searchParams.toString();
|
||||||
|
const newUrl = `${serverApiUrl}${pathname.replace("/server", "")}${
|
||||||
|
queryParams ? `?${queryParams}` : ""
|
||||||
|
}`;
|
||||||
|
return NextResponse.rewrite(new URL(newUrl));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pathname.startsWith("/attach-service")) {
|
||||||
|
const newUrl = `${serverApiUrl}${pathname}`;
|
||||||
|
return NextResponse.rewrite(new URL(newUrl));
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: ["/server/:path*", "/attach-service/:path*"],
|
||||||
|
};
|
||||||
+1
-29
@@ -1,33 +1,5 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
import webpack from "webpack";
|
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {};
|
||||||
webpack: (config) => {
|
|
||||||
config.plugins.push(
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
"import.meta.env.VITE_SERVER_API_URL": JSON.stringify(
|
|
||||||
process.env.VITE_SERVER_API_URL,
|
|
||||||
),
|
|
||||||
"import.meta.env.VITE_SITE_ID": JSON.stringify(
|
|
||||||
process.env.VITE_SITE_ID,
|
|
||||||
),
|
|
||||||
"import.meta.env.VITE_CLAIM_NAME": JSON.stringify(
|
|
||||||
process.env.VITE_CLAIM_NAME,
|
|
||||||
),
|
|
||||||
"import.meta.env.VITE_ACCESS_TOKEN": JSON.stringify(
|
|
||||||
process.env.VITE_ACCESS_TOKEN,
|
|
||||||
),
|
|
||||||
"import.meta.env.VITE_REFRESH_TOKEN": JSON.stringify(
|
|
||||||
process.env.VITE_REFRESH_TOKEN,
|
|
||||||
),
|
|
||||||
"import.meta.env.VITE_TOKEN_ID": JSON.stringify(
|
|
||||||
process.env.VITE_TOKEN_ID,
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
return config;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|||||||
+14
-2
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "NODE_OPTIONS='--inspect' next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
@@ -11,13 +11,25 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@common/assets": "workspace:*",
|
"@common/assets": "workspace:*",
|
||||||
"@common/components": "workspace:*",
|
"@common/components": "workspace:*",
|
||||||
|
"@frontend-opensource/use-react-hooks": "^1.1.4",
|
||||||
|
"@hookform/resolvers": "^4.1.3",
|
||||||
|
"@minoru/react-dnd-treeview": "^3.5.0",
|
||||||
|
"@radix-ui/react-label": "^2.1.2",
|
||||||
|
"@radix-ui/react-slot": "^1.1.2",
|
||||||
|
"@tanstack/react-query": "^5.67.1",
|
||||||
"@tanstack/react-table": "^8.21.2",
|
"@tanstack/react-table": "^8.21.2",
|
||||||
"axios": "^1.8.1",
|
"axios": "^1.8.1",
|
||||||
"chart.js": "^4.4.8",
|
"chart.js": "^4.4.8",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"next": "15.1.7",
|
"next": "15.1.7",
|
||||||
"react-chartjs-2": "^5.3.0",
|
"react-chartjs-2": "^5.3.0",
|
||||||
"tailwindcss-animate": "^1.0.7"
|
"react-dnd": "^16.0.1",
|
||||||
|
"react-hook-form": "^7.54.2",
|
||||||
|
"tailwindcss-animate": "^1.0.7",
|
||||||
|
"tus-js-client": "^4.3.1",
|
||||||
|
"zod": "^3.24.2",
|
||||||
|
"zustand": "^5.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3",
|
"@eslint/eslintrc": "^3",
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import "./styles/base.css";
|
import "./styles/base.css";
|
||||||
import "./styles/components.css";
|
import "./styles/components.css";
|
||||||
|
import { AppProvider } from "./providers";
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
|
const App = async ({ children }: Readonly<{ children: React.ReactNode }>) => {
|
||||||
|
const theme = (await cookies()).get("site-theme-key");
|
||||||
|
|
||||||
const App = ({ children }: Readonly<{ children: React.ReactNode }>) => {
|
|
||||||
return (
|
return (
|
||||||
<html lang="ko">
|
<html lang="ko" data-theme={theme?.value}>
|
||||||
<body>{children}</body>
|
<body>
|
||||||
|
<AppProvider>{children}</AppProvider>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
import { ConfirmProvider } from "@frontend-opensource/use-react-hooks";
|
||||||
|
import { AuthWrapper } from "@/entities/auth";
|
||||||
|
import { MenuWrapper } from "@/entities/menu";
|
||||||
|
import { StoreProvider } from "@/shared/providers";
|
||||||
|
import { AlertDialog } from "@/shared/ui/alert-dialog";
|
||||||
|
|
||||||
|
const AppProvider = ({ children }: Readonly<{ children: React.ReactNode }>) => {
|
||||||
|
const queryClient = new QueryClient();
|
||||||
|
return (
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<StoreProvider>
|
||||||
|
<ConfirmProvider>
|
||||||
|
<AuthWrapper>
|
||||||
|
<MenuWrapper>{children}</MenuWrapper>
|
||||||
|
<AlertDialog />
|
||||||
|
</AuthWrapper>
|
||||||
|
</ConfirmProvider>
|
||||||
|
</StoreProvider>
|
||||||
|
</QueryClientProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { AppProvider };
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { AppProvider } from "./app-provider";
|
||||||
@@ -1,16 +1,129 @@
|
|||||||
@tailwind components;
|
.card {
|
||||||
|
position: relative;
|
||||||
|
margin: 0.6rem;
|
||||||
|
box-sizing: border-box;
|
||||||
|
min-height: 2rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
padding: 0.6rem;
|
||||||
|
font-size: 1.3rem;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
@layer components {
|
.card_width10 {
|
||||||
.card {
|
width: calc(10% - 12px);
|
||||||
@apply relative m-[0.6rem] box-border min-h-[2rem] rounded-[0.5rem] p-[0.6rem] text-[1.3rem] text-[#666];
|
}
|
||||||
}
|
|
||||||
|
.card_width20 {
|
||||||
|
width: calc(20% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width25 {
|
||||||
|
width: calc(25% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width30 {
|
||||||
|
width: calc(30% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width33 {
|
||||||
|
width: calc(33.333% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width40 {
|
||||||
|
width: calc(40% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width45 {
|
||||||
|
width: calc(45% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width50 {
|
||||||
|
width: calc(50% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width60 {
|
||||||
|
width: calc(60% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width66 {
|
||||||
|
width: calc(66.666% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width70 {
|
||||||
|
width: calc(70% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width75 {
|
||||||
|
width: calc(75% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width80 {
|
||||||
|
width: calc(80% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width90 {
|
||||||
|
width: calc(90% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_width100 {
|
||||||
|
width: calc(100% - 12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_nopadding {
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card_nomargin {
|
||||||
|
width: 100%;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topline {
|
||||||
|
border-top: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottomline {
|
||||||
|
border-bottom: 1px solid #e6eef3;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-border {
|
||||||
|
border: 1px solid #dbe2e6;
|
||||||
|
background-color: rgba(255, 255, 255, 0.6);
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
margin-top: -0.6rem;
|
||||||
|
margin-left: -0.6rem;
|
||||||
|
margin-right: -0.6rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
border-bottom: 1px solid #e1e7eb;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-footer {
|
||||||
|
margin-left: -0.6rem;
|
||||||
|
margin-right: -0.6rem;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border-top: 1px solid #e1e7eb;
|
||||||
|
padding-top: 1rem;
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 블랙 테마 */
|
||||||
|
[data-theme="black"] {
|
||||||
.card-border {
|
.card-border {
|
||||||
@apply shadow-blur border border-[#dbe2e6] bg-[rgba(255,255,255,0.6)];
|
background-color: rgba(255, 255, 255, 0.065);
|
||||||
|
border-color: #38383a;
|
||||||
}
|
}
|
||||||
.card-header {
|
.card-header {
|
||||||
@apply -mx-[0.6rem] flex items-center justify-between border-b border-b-[#e1e7eb] p-4;
|
border-bottom-color: #3f4042;
|
||||||
}
|
|
||||||
.card-footer {
|
|
||||||
@apply -mx-[0.6rem] mt-2 flex items-center justify-center border-t border-t-[#e1e7eb] py-4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import { AxiosError } from "axios";
|
||||||
|
import {
|
||||||
|
ENDPOINT,
|
||||||
|
JWT_EXPIRATION_TIME,
|
||||||
|
ACCESS_TOKEN,
|
||||||
|
AUTH_USER_ID,
|
||||||
|
CLAIM_NAME,
|
||||||
|
} from "@/shared/config";
|
||||||
|
import type { LoginService, ILogin } from "../model/login-interface";
|
||||||
|
import { tokenManager } from "../lib/token-manager";
|
||||||
|
|
||||||
|
export class LoginApiService implements LoginService {
|
||||||
|
private static instance: LoginApiService;
|
||||||
|
|
||||||
|
private constructor() {}
|
||||||
|
|
||||||
|
public static getInstance(): LoginApiService {
|
||||||
|
if (!LoginApiService.instance) {
|
||||||
|
LoginApiService.instance = new LoginApiService();
|
||||||
|
}
|
||||||
|
return LoginApiService.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async login(payload: ILogin): Promise<void> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/proxy${ENDPOINT.USER_SERVICE.LOGIN}`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({
|
||||||
|
userId: payload.userId,
|
||||||
|
password: payload.password,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
const accessToken = data[ACCESS_TOKEN];
|
||||||
|
const tokenId = data[AUTH_USER_ID];
|
||||||
|
|
||||||
|
if (!accessToken || !tokenId) {
|
||||||
|
throw new Error("Missing required authentication tokens");
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenManager.setToken(CLAIM_NAME, accessToken);
|
||||||
|
tokenManager.setToken(AUTH_USER_ID, tokenId);
|
||||||
|
tokenManager.setupRefreshTimer(
|
||||||
|
() => this.silentRefresh(),
|
||||||
|
JWT_EXPIRATION_TIME,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof AxiosError) {
|
||||||
|
throw new Error(`Login failed: ${error.response?.data?.message}`);
|
||||||
|
}
|
||||||
|
throw new Error(`Login failed: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async silentRefresh(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`/api/proxy${ENDPOINT.USER_SERVICE.SILENT_REFRESH}`,
|
||||||
|
{ method: "PUT" },
|
||||||
|
);
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
const accessToken = data[ACCESS_TOKEN];
|
||||||
|
const tokenId = data[AUTH_USER_ID];
|
||||||
|
|
||||||
|
if (!accessToken || !tokenId) {
|
||||||
|
throw new Error("Missing required authentication tokens");
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenManager.setToken(CLAIM_NAME, accessToken);
|
||||||
|
tokenManager.setToken(AUTH_USER_ID, tokenId);
|
||||||
|
} catch (error) {
|
||||||
|
tokenManager.clearAuthToken();
|
||||||
|
if (error instanceof AxiosError) {
|
||||||
|
throw new Error(
|
||||||
|
`Silent refresh failed: ${error.response?.data?.message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw new Error(`Silent refresh failed: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const LoginApi = LoginApiService.getInstance();
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { LoginApi } from "./api/login-service";
|
||||||
|
export { AuthWrapper } from "./lib/auth-wrapper";
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { client } from "@/shared/api";
|
||||||
|
import type { IUserInfo } from "@/shared/store";
|
||||||
|
import { getCookie, useUserStore } from "@/shared/lib";
|
||||||
|
import { ENDPOINT, AUTH_USER_ID } from "@/shared/config";
|
||||||
|
import { LoginApi } from "../api/login-service";
|
||||||
|
|
||||||
|
const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||||
|
const router = useRouter();
|
||||||
|
const { userInfo, setUserInfo } = useUserStore((state) => state);
|
||||||
|
|
||||||
|
async function authCheck() {
|
||||||
|
const userId = getCookie(AUTH_USER_ID);
|
||||||
|
if (!userId) {
|
||||||
|
throw new Error("Missing required authentication tokens");
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await client.get<IUserInfo>(
|
||||||
|
`${ENDPOINT.USER_SERVICE.USERS}/${userId}`,
|
||||||
|
);
|
||||||
|
if (!userInfo) setUserInfo(response.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await authCheck();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await LoginApi.silentRefresh();
|
||||||
|
await authCheck();
|
||||||
|
} catch (refreshError) {
|
||||||
|
console.error("Token refresh failed:", refreshError);
|
||||||
|
setUserInfo(null);
|
||||||
|
router.push("/auth/login");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return <>{children}</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export { AuthWrapper };
|
||||||
+14
-16
@@ -1,6 +1,5 @@
|
|||||||
import axios from "axios";
|
import { AUTH_USER_ID, CLAIM_NAME } from "@/shared/config";
|
||||||
import Cookies from "js-cookie";
|
import { getCookie, setCookie, removeCookie } from "@/shared/lib";
|
||||||
import { CLAIM_NAME, REFRESH_TOKEN, TOKEN_ID } from "@/shared/config";
|
|
||||||
|
|
||||||
export class TokenManager {
|
export class TokenManager {
|
||||||
private static instance: TokenManager;
|
private static instance: TokenManager;
|
||||||
@@ -15,20 +14,19 @@ export class TokenManager {
|
|||||||
return TokenManager.instance;
|
return TokenManager.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setToken(key: string, value: string): void {
|
public getToken(key: string): string | undefined {
|
||||||
axios.defaults.headers.common[key] = value;
|
return getCookie(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setRefreshToken(token: string): void {
|
public setToken(key: string, value: string): void {
|
||||||
Cookies.set(REFRESH_TOKEN, token, {
|
setCookie(key, value, {
|
||||||
httpOnly: true,
|
secure: window.location.protocol === "https:",
|
||||||
secure: true,
|
|
||||||
sameSite: "lax",
|
sameSite: "lax",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public getRefreshToken(): string | undefined {
|
public removeToken(key: string): void {
|
||||||
return Cookies.get(REFRESH_TOKEN);
|
removeCookie(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setupRefreshTimer(
|
public setupRefreshTimer(
|
||||||
@@ -42,19 +40,19 @@ export class TokenManager {
|
|||||||
this.refreshTimer = setTimeout(() => {
|
this.refreshTimer = setTimeout(() => {
|
||||||
callback().catch((error) => {
|
callback().catch((error) => {
|
||||||
console.error("Silent refresh failed:", error);
|
console.error("Silent refresh failed:", error);
|
||||||
this.clearAuth();
|
this.clearAuthToken();
|
||||||
});
|
});
|
||||||
}, expirationTime - 60000);
|
}, expirationTime - 60000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearAuth(): void {
|
public clearAuthToken(): void {
|
||||||
if (this.refreshTimer) {
|
if (this.refreshTimer) {
|
||||||
clearTimeout(this.refreshTimer);
|
clearTimeout(this.refreshTimer);
|
||||||
this.refreshTimer = null;
|
this.refreshTimer = null;
|
||||||
}
|
}
|
||||||
Cookies.remove(REFRESH_TOKEN);
|
|
||||||
delete axios.defaults.headers.common[CLAIM_NAME];
|
this.removeToken(CLAIM_NAME);
|
||||||
delete axios.defaults.headers.common[TOKEN_ID];
|
this.removeToken(AUTH_USER_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+1
@@ -5,4 +5,5 @@ export interface ILogin {
|
|||||||
|
|
||||||
export interface LoginService {
|
export interface LoginService {
|
||||||
login(payload: ILogin): Promise<void>;
|
login(payload: ILogin): Promise<void>;
|
||||||
|
silentRefresh(): Promise<void>;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import type {
|
||||||
|
BoardPopupList,
|
||||||
|
BoardPopupParams,
|
||||||
|
BoardService,
|
||||||
|
} from "../model/board-interface";
|
||||||
|
|
||||||
|
export class BoardApiService implements BoardService {
|
||||||
|
public async getBoardPopupList(
|
||||||
|
params: BoardPopupParams,
|
||||||
|
): Promise<BoardPopupList> {
|
||||||
|
const response = await client.get<BoardPopupList>(
|
||||||
|
`${ENDPOINT.BOARD_SERVICE.BBS}`,
|
||||||
|
{ params },
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const BoardApi = new BoardApiService();
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { BoardApi } from "./api/board-service";
|
||||||
|
export { type BoardPopup } from "./model/board-interface";
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import type { PageableList, PageableParams } from "@/shared/model";
|
||||||
|
|
||||||
|
export const BOARD_TYPE = {
|
||||||
|
BBSNORMAL: "BBSNORMAL",
|
||||||
|
BBSFAQ: "BBSFAQ",
|
||||||
|
BBSIMAGE: "BBSIMAGE",
|
||||||
|
BBSMOVIE: "BBSMOVIE",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type BoardType = (typeof BOARD_TYPE)[keyof typeof BOARD_TYPE];
|
||||||
|
|
||||||
|
export interface BoardPopupParams extends PageableParams {
|
||||||
|
bbsNm?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BoardPopup {
|
||||||
|
bbsId: number;
|
||||||
|
bbsTypeCd: BoardType;
|
||||||
|
bbsTypeNm: string;
|
||||||
|
bbsNm: string;
|
||||||
|
bbsExpln: string;
|
||||||
|
rfrncUseYn: string;
|
||||||
|
atflUseYn: string;
|
||||||
|
atflMaxCnt: number;
|
||||||
|
atflMaxFileSz: number;
|
||||||
|
ansUseYn: string;
|
||||||
|
cmntUseYn: string;
|
||||||
|
dgstfnEvlUseYn: string;
|
||||||
|
smsUseYn: string;
|
||||||
|
upndFixUseYn: string;
|
||||||
|
pstgPrdUseYn: string;
|
||||||
|
popupUseYn: string;
|
||||||
|
delYn: string;
|
||||||
|
regDt: string;
|
||||||
|
pstCnt: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BoardPopupList = PageableList<BoardPopup>;
|
||||||
|
|
||||||
|
export interface BoardService {
|
||||||
|
getBoardPopupList: (params: BoardPopupParams) => Promise<BoardPopupList>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import type { CodeService, ICode } from "../model/code-interface";
|
||||||
|
|
||||||
|
export class CodeApiService implements CodeService {
|
||||||
|
public async getCode(upCd: string): Promise<ICode[]> {
|
||||||
|
const response = await client.get<ICode[]>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.CODE}/${upCd}`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CodeApi = new CodeApiService();
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { CodeSelect } from "./ui/code-select";
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
export interface ICode {
|
||||||
|
lwpoCd: string;
|
||||||
|
upCd: string;
|
||||||
|
lwpoCdNm: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CodeService {
|
||||||
|
getCode(upCd: string): Promise<ICode[]>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@common/components";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { CodeApi } from "../api/code-service";
|
||||||
|
|
||||||
|
type CodeSelectProps = {
|
||||||
|
upCd: string;
|
||||||
|
} & React.ComponentPropsWithoutRef<typeof Select>;
|
||||||
|
|
||||||
|
function CodeSelect({ upCd, defaultValue, ...props }: CodeSelectProps) {
|
||||||
|
const { data: code } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.CODE, upCd],
|
||||||
|
queryFn: () => CodeApi.getCode(upCd),
|
||||||
|
enabled: !!upCd,
|
||||||
|
});
|
||||||
|
|
||||||
|
const defaultValueText =
|
||||||
|
code?.find((item) => item.lwpoCd === defaultValue)?.lwpoCdNm ?? "선택";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Select {...props}>
|
||||||
|
<SelectTrigger className="w-[12rem]">
|
||||||
|
<SelectValue placeholder={defaultValueText} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{code?.map((item) => (
|
||||||
|
<SelectItem key={item.lwpoCd} value={item.lwpoCd}>
|
||||||
|
{item.lwpoCdNm}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CodeSelect };
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export { GroupApi } from "./api/group-api";
|
||||||
|
export {
|
||||||
|
type GroupParams,
|
||||||
|
type Group,
|
||||||
|
type GroupFormData,
|
||||||
|
} from "./model/types";
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
export interface Group {
|
||||||
|
groupId: string;
|
||||||
|
groupNm: string;
|
||||||
|
groupSeCd: string;
|
||||||
|
groupExpln: string;
|
||||||
|
delYn: string;
|
||||||
|
regDt: string;
|
||||||
|
rgtr: string;
|
||||||
|
mdfcnDt: string | null;
|
||||||
|
mdfr: string | null;
|
||||||
|
authrtId: string;
|
||||||
|
siteId: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupParams {
|
||||||
|
groupNm?: string;
|
||||||
|
groupSeCd?: string;
|
||||||
|
siteId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupFormData {
|
||||||
|
groupId: string;
|
||||||
|
groupNm: string;
|
||||||
|
groupSeCd: string;
|
||||||
|
groupExpln: string;
|
||||||
|
delYn: string;
|
||||||
|
authrtId: string;
|
||||||
|
siteId: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { client } from "@common/components/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import type { MenuItem, MenuService } from "../model/menu-interface";
|
||||||
|
|
||||||
|
export class MenuApiService implements MenuService {
|
||||||
|
async getMenuRoles(siteId: string): Promise<MenuItem[]> {
|
||||||
|
const response = await client.get<MenuItem[]>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENU_ROLES}/${siteId}`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MenuApi = new MenuApiService();
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { MenuWrapper } from "./lib/menu-wrapper";
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
import { SITE_ID } from "@/shared/config";
|
||||||
|
import { useMenuStore } from "@/shared/lib";
|
||||||
|
import { MenuApi } from "../api/menu-service";
|
||||||
|
import { getCurrentMenu } from "./utils";
|
||||||
|
|
||||||
|
const MenuWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const { setCurrentMenuInfo } = useMenuStore((state) => state);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
const menuRoles = await MenuApi.getMenuRoles(SITE_ID);
|
||||||
|
if (!menuRoles) return;
|
||||||
|
|
||||||
|
const currentMenu = getCurrentMenu(menuRoles, pathname ?? "");
|
||||||
|
if (!currentMenu) return;
|
||||||
|
|
||||||
|
setCurrentMenuInfo(currentMenu);
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return <>{children}</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export { MenuWrapper };
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import type { MenuItem } from "../model/menu-interface";
|
||||||
|
|
||||||
|
export const getCurrentMenu = (
|
||||||
|
menus: MenuItem[],
|
||||||
|
pathname: string,
|
||||||
|
): MenuItem | null => {
|
||||||
|
for (const menu of menus) {
|
||||||
|
if (menu.children) {
|
||||||
|
return getCurrentMenu(menu.children, pathname);
|
||||||
|
}
|
||||||
|
if (menu.urlPath === pathname) return menu;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export interface MenuItem {
|
||||||
|
menuCd: number;
|
||||||
|
menuKornNm: string;
|
||||||
|
menuEngNm: string;
|
||||||
|
parentId: number | null;
|
||||||
|
sortSeq: number;
|
||||||
|
iconNm?: string;
|
||||||
|
children: MenuItem[] | null;
|
||||||
|
levelNo: number;
|
||||||
|
urlPath: string;
|
||||||
|
menuLnkgTypeCd: string;
|
||||||
|
menuLnkgSn: number;
|
||||||
|
menuPath: string;
|
||||||
|
qrcd: string;
|
||||||
|
useYn: string;
|
||||||
|
otptYn: string;
|
||||||
|
newWndwYn: string;
|
||||||
|
requiredUrlPath: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MenuService {
|
||||||
|
getMenuRoles(siteId: string): Promise<MenuItem[]>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import {
|
||||||
|
siteFormSchema,
|
||||||
|
type SiteService,
|
||||||
|
type SiteList,
|
||||||
|
type SiteDetail,
|
||||||
|
type SiteParams,
|
||||||
|
type SiteFormData,
|
||||||
|
} from "../model/site-interface";
|
||||||
|
|
||||||
|
export class SiteApiService implements SiteService {
|
||||||
|
public async getSiteList(params: SiteParams): Promise<SiteList> {
|
||||||
|
const response = await client.get<SiteList>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.SITES}`,
|
||||||
|
{ params },
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async siteDetail(siteId: string): Promise<SiteDetail> {
|
||||||
|
const response = await client.get<SiteDetail>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.SITES}/${siteId}`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createSite(data: SiteFormData): Promise<void> {
|
||||||
|
const validatedData = siteFormSchema.parse(data);
|
||||||
|
const response = await client.post<void>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.SITES}`,
|
||||||
|
validatedData,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateSite(siteId: string, data: SiteFormData): Promise<void> {
|
||||||
|
const validatedData = siteFormSchema.parse(data);
|
||||||
|
const response = await client.put<void>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.SITES}/${siteId}`,
|
||||||
|
validatedData,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteSite(siteId: string): Promise<void> {
|
||||||
|
const response = await client.delete<void>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.SITES}/${siteId}`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SiteApi = new SiteApiService();
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export { SiteApi } from "./api/site-service";
|
||||||
|
export {
|
||||||
|
siteFormSchema,
|
||||||
|
type SiteParams,
|
||||||
|
type Site,
|
||||||
|
type SiteFormData,
|
||||||
|
} from "./model/site-interface";
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
import type { PageableParams, PageableList } from "@/shared/model";
|
||||||
|
|
||||||
|
export interface SiteParams extends PageableParams {
|
||||||
|
siteNm?: string;
|
||||||
|
siteKndCd?: string;
|
||||||
|
useYn?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Site {
|
||||||
|
siteId: string;
|
||||||
|
siteNm: string;
|
||||||
|
siteKindCode: string;
|
||||||
|
bscSiteYn: string;
|
||||||
|
siteAddr: string;
|
||||||
|
useYn: string;
|
||||||
|
regDt: string;
|
||||||
|
rgTrNm: string;
|
||||||
|
dmnAddr: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SiteDetail extends SiteFormData {
|
||||||
|
siteId: string;
|
||||||
|
siteKindNm: string;
|
||||||
|
basicSiteYn: string;
|
||||||
|
faxNumber: string;
|
||||||
|
regDt: string;
|
||||||
|
rgTr: string;
|
||||||
|
mdfcnDt: string;
|
||||||
|
mdFr: string;
|
||||||
|
rgTrNm: string;
|
||||||
|
mdfrNm: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const siteFormSchema = z.object({
|
||||||
|
siteId: z.string().max(2).nonempty(),
|
||||||
|
siteNm: z.string().max(100).nonempty(),
|
||||||
|
siteExpln: z.string().max(1000).nullable(),
|
||||||
|
siteKndCd: z.string().max(10).nonempty(),
|
||||||
|
siteAddr: z.string().max(2000).nullable(),
|
||||||
|
faxNo: z.string().max(100).nullable(),
|
||||||
|
telNo: z.string().max(1000).nullable(),
|
||||||
|
lwndCn: z.string().max(2000).nullable(),
|
||||||
|
bscSiteYn: z.string(),
|
||||||
|
bkmkIcon: z.string().max(100).nullable(),
|
||||||
|
useYn: z.string(),
|
||||||
|
siteSkn: z.string().max(10).nullable(),
|
||||||
|
dmnAddr: z.string().nullable(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type SiteFormData = z.infer<typeof siteFormSchema>;
|
||||||
|
export type SiteList = PageableList<Site>;
|
||||||
|
|
||||||
|
export interface SiteService {
|
||||||
|
getSiteList(params: SiteParams): Promise<SiteList>;
|
||||||
|
siteDetail(siteId: string): Promise<SiteDetail>;
|
||||||
|
updateSite(siteId: string, data: SiteFormData): Promise<void>;
|
||||||
|
createSite(data: SiteFormData): Promise<void>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import type { Page } from "@/shared/types";
|
||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
|
||||||
|
export interface Api {
|
||||||
|
authorizationNo: number; // API 일련번호
|
||||||
|
authorizationName: string; // API 명
|
||||||
|
urlPatternValue: string; // URL 패턴
|
||||||
|
httpMethodCode: string; // 하이퍼텍스트 전송 프로토콜 메쏘드 값 (예: GET, POST)
|
||||||
|
sortSeq: number; // 정렬 순서
|
||||||
|
useYn: string; // 사용 여부 (Y/N)
|
||||||
|
regDt: string; // 등록 일시
|
||||||
|
rgtr: string; // 등록자 UUID
|
||||||
|
mdfcnDt: string | null; // 갱신 일시
|
||||||
|
mdfr: string | null; // 갱신자 UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiParams {
|
||||||
|
authorizationName?: string; // API 명 검색
|
||||||
|
httpMethodCode?: string; // HTTP 메소드 검색
|
||||||
|
useYn?: string; // 사용 여부 검색
|
||||||
|
page?: number; // 페이지 번호
|
||||||
|
size?: number; // 페이지 크기
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiFormData {
|
||||||
|
authorizationNo: number | null; // API 일련번호 (신규 등록 시 null)
|
||||||
|
authorizationName: string; // API 명
|
||||||
|
urlPatternValue: string; // URL 패턴
|
||||||
|
httpMethodCode: string; // HTTP 메소드
|
||||||
|
sortSeq: number; // 정렬 순서
|
||||||
|
useYn: string; // 사용 여부
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ApimanApi = {
|
||||||
|
getApiList: async (params: ApiParams) => {
|
||||||
|
const { data } = await client.get<Page<Api>>(
|
||||||
|
`${ENDPOINT.USER_SERVICE.AUTHRTS}`,
|
||||||
|
{ params }
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
getApi: async (authorizationNo: number) => {
|
||||||
|
const { data } = await client.get<Api>(`${ENDPOINT.USER_SERVICE.AUTHRTS}/${authorizationNo}`);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
createApi: async (apiData: ApiFormData) => {
|
||||||
|
const { data } = await client.post<Api>(ENDPOINT.USER_SERVICE.AUTHRTS, apiData);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
updateApi: async (authorizationNo: number, apiData: ApiFormData) => {
|
||||||
|
const { data } = await client.put<Api>(`${ENDPOINT.USER_SERVICE.AUTHRTS}/${authorizationNo}`, apiData);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteApi: async (authorizationNo: number) => {
|
||||||
|
const { data } = await client.delete<void>(`${ENDPOINT.USER_SERVICE.AUTHRTS}/${authorizationNo}`);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export { ApimanPage } from "./ui/apiman-page";
|
||||||
|
export { ApimanForm } from "./ui/apiman-form";
|
||||||
|
export { CreatePage } from "./ui/create-page";
|
||||||
|
export { ModifyPage } from "./ui/modify-page";
|
||||||
|
export { ApimanApi } from "./api/apiman-api";
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
|
import { Badge, Button } from "@common/components";
|
||||||
|
import type { Api } from "../api/apiman-api";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
// API 권한 관리를 위한 타입 정의
|
||||||
|
type ApiTableMeta = {
|
||||||
|
openRoleDialog: (api: Api) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const columns: ColumnDef<Api>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: "authorizationNo",
|
||||||
|
header: "번호",
|
||||||
|
cell: ({ row }) => <div>{row.original.authorizationNo}</div>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "authorizationName",
|
||||||
|
header: "API 명",
|
||||||
|
cell: ({ row }) => <div>{row.original.authorizationName}</div>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "urlPatternValue",
|
||||||
|
header: "URL 패턴",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="max-w-md truncate text-left" title={row.original.urlPatternValue}>
|
||||||
|
{row.original.urlPatternValue}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "httpMethodCode",
|
||||||
|
header: "HTTP 메소드",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const method = row.original.httpMethodCode;
|
||||||
|
let color = "bg-gray-500";
|
||||||
|
|
||||||
|
switch (method) {
|
||||||
|
case "GET":
|
||||||
|
color = "bg-blue-500";
|
||||||
|
break;
|
||||||
|
case "POST":
|
||||||
|
color = "bg-green-500";
|
||||||
|
break;
|
||||||
|
case "PUT":
|
||||||
|
color = "bg-orange-500";
|
||||||
|
break;
|
||||||
|
case "DELETE":
|
||||||
|
color = "bg-red-500";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Badge className={`${color} text-white`}>
|
||||||
|
{method}
|
||||||
|
</Badge>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "sortSeq",
|
||||||
|
header: "정렬 순서",
|
||||||
|
cell: ({ row }) => <div className="text-center">{row.original.sortSeq}</div>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "useYn",
|
||||||
|
header: "사용 여부",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const useYn = row.original.useYn;
|
||||||
|
return (
|
||||||
|
<Badge className={useYn === "Y" ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"}>
|
||||||
|
{useYn === "Y" ? "사용" : "미사용"}
|
||||||
|
</Badge>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "mdfrNm",
|
||||||
|
header: "수정자",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "mdfcnDt",
|
||||||
|
header: "수정일시",
|
||||||
|
cell: ({ row }) => dayjs(row.original.mdfcnDt).format("YYYY-MM-DD"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "권한",
|
||||||
|
cell: ({ row, table }) => {
|
||||||
|
// 메타 데이터에서 권한 다이얼로그 열기 함수 가져오기
|
||||||
|
const meta = table.options.meta as ApiTableMeta | undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="h-8 w-16 bg-blue-500 text-white hover:bg-blue-600"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation(); // 행 클릭 이벤트 전파 방지
|
||||||
|
if (meta?.openRoleDialog) {
|
||||||
|
// console.log(row.original);
|
||||||
|
meta.openRoleDialog(row.original);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
권한
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogTrigger,
|
||||||
|
Button,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
Input,
|
||||||
|
RadioGroup,
|
||||||
|
RadioGroupItem,
|
||||||
|
DialogFooter,
|
||||||
|
DialogClose,
|
||||||
|
Checkbox,
|
||||||
|
Label,
|
||||||
|
} from "@common/components";
|
||||||
|
import { ApiRoleApi, type ApiRoleByApi } from "../../apirole/api/apirole-api";
|
||||||
|
|
||||||
|
// 페이지네이션 응답을 위한 인터페이스
|
||||||
|
interface Page<T> {
|
||||||
|
content: T[];
|
||||||
|
pageable: {
|
||||||
|
pageNumber: number;
|
||||||
|
pageSize: number;
|
||||||
|
};
|
||||||
|
totalElements: number;
|
||||||
|
totalPages: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// API 역할 인터페이스 정의
|
||||||
|
interface Role extends ApiRoleByApi {
|
||||||
|
selected?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiRoleDialogProps {
|
||||||
|
api: ApiRoleByApi | null;
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onSave: (roleIds: string[]) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ApiRoleDialog({ api, isOpen, onClose, onSave }: ApiRoleDialogProps): JSX.Element {
|
||||||
|
const [roles, setRoles] = useState<Role[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
// API에서 역할 데이터 가져오기
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen && api && api.authorizationNo) {
|
||||||
|
// 실제 API 호출로 데이터 가져오기
|
||||||
|
ApiRoleApi.getApiRoleByApiList({ authorizationNo: api.authorizationNo })
|
||||||
|
.then((data: Page<ApiRoleByApi>) => {
|
||||||
|
// 데이터를 Role 인터페이스에 맞게 변환
|
||||||
|
const rolesWithSelected = data.content.map(role => ({
|
||||||
|
...role,
|
||||||
|
mode: role.useYn ==null?"C":"R",
|
||||||
|
selected: role.useYn === "Y"
|
||||||
|
}));
|
||||||
|
setRoles(rolesWithSelected);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("역할 데이터 가져오기 오류:", error);
|
||||||
|
// 오류 발생 시 빈 배열 설정
|
||||||
|
setRoles([]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [isOpen, api]);
|
||||||
|
|
||||||
|
const handleToggleRole = (roleId: string) => {
|
||||||
|
setRoles(
|
||||||
|
roles.map((role) =>
|
||||||
|
role.roleId === roleId ? { ...role, useYn: role.useYn === "Y" ? "N" : "Y", mode: role.mode === "R" ? "U" : "C" } : role
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
//const selectedRoleIds = roles.filter((role) => role.useYn === "Y").map((role) => role.roleId ?? "");
|
||||||
|
await onSave(roles);
|
||||||
|
onClose();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("권한 저장 중 오류 발생:", error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Dialog가 닫힐 때 호출되는 함수
|
||||||
|
const handleOpenChange = (open: boolean) => {
|
||||||
|
if (!open) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={isOpen} onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[600px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="text-xl font-bold">
|
||||||
|
API 권한 설정 - {api?.authorizationName}
|
||||||
|
</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="card mb-4">
|
||||||
|
<Table>
|
||||||
|
<colgroup>
|
||||||
|
<col style={{ width: "20%" }} />
|
||||||
|
<col style={{ width: "30%" }} />
|
||||||
|
<col style={{ width: "20%" }} />
|
||||||
|
<col style={{ width: "30%" }} />
|
||||||
|
</colgroup>
|
||||||
|
<TableBody>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell as="th">API 명</TableCell>
|
||||||
|
<TableCell className="border">
|
||||||
|
{api?.authorizationName || ""}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell as="th">HTTP 메소드</TableCell>
|
||||||
|
<TableCell className="border">
|
||||||
|
{api?.httpMethodCode || ""}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell as="th">URL 패턴</TableCell>
|
||||||
|
<TableCell colSpan={3} className="border">
|
||||||
|
{api?.urlPatternValue || ""}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="max-h-[400px] overflow-auto">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead className="w-[50px]">허용</TableHead>
|
||||||
|
<TableHead className="w-[150px]">권한 ID</TableHead>
|
||||||
|
<TableHead>권한명</TableHead>
|
||||||
|
<TableHead>권한내용</TableHead>
|
||||||
|
<TableHead className="w-[80px]">사용여부</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{roles.map((role) => (
|
||||||
|
<TableRow key={role.roleId}>
|
||||||
|
<TableCell className="text-center">
|
||||||
|
<Checkbox
|
||||||
|
checked={role.useYn === "Y"}
|
||||||
|
onCheckedChange={() => handleToggleRole(role.roleId)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{role.roleId}</TableCell>
|
||||||
|
<TableCell>{role.roleName}</TableCell>
|
||||||
|
<TableCell>{role.roleContent}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<span className={role.useYn === "Y" ? "text-green-600" : "text-red-600"}>
|
||||||
|
{role.useYn === "Y" ? "사용" : "미사용"}
|
||||||
|
</span>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
{roles.length === 0 && (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={5} className="text-center py-4">
|
||||||
|
권한 정보가 없습니다.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter className="flex justify-end gap-2 mt-4">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={onClose}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
취소
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleSave}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{loading ? "저장 중..." : "저장"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,256 @@
|
|||||||
|
// apps/cs/src/pages/apiman/ui/apiman-form.tsx
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||||
|
import { type UseFormReturn } from "react-hook-form";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
RadioGroup,
|
||||||
|
RadioGroupItem,
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableRow,
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@common/components";
|
||||||
|
import { FormItem, FormControl, FormField, Form } from "@/shared/ui/form";
|
||||||
|
import type { ApiFormData } from "../api/apiman-api";
|
||||||
|
import { ConfirmDialog } from "@/shared/ui/confirm-dialog";
|
||||||
|
|
||||||
|
interface ApimanFormProps {
|
||||||
|
form: UseFormReturn<ApiFormData>;
|
||||||
|
authorizationNo?: number;
|
||||||
|
handleSave: (data: ApiFormData) => Promise<void>;
|
||||||
|
handleDelete?: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ApimanForm({ form, authorizationNo, handleSave, handleDelete }: ApimanFormProps) {
|
||||||
|
const isModifyMode = !!authorizationNo;
|
||||||
|
const router = useRouter();
|
||||||
|
const { confirm } = useConfirm();
|
||||||
|
const [onConfirm, setOnConfirm] = useState(false);
|
||||||
|
|
||||||
|
const handleConfirm = async (callback: () => Promise<void>) => {
|
||||||
|
setOnConfirm(true);
|
||||||
|
await callback();
|
||||||
|
setOnConfirm(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmit = async (data: ApiFormData) => {
|
||||||
|
const confirmMessage = isModifyMode
|
||||||
|
? "수정하시겠습니까?"
|
||||||
|
: "저장하시겠습니까?";
|
||||||
|
|
||||||
|
await handleConfirm(async () => {
|
||||||
|
if (await confirm(confirmMessage)) {
|
||||||
|
await handleSave(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDelete = async () => {
|
||||||
|
await handleConfirm(async () => {
|
||||||
|
if (await confirm("삭제하시겠습니까?")) {
|
||||||
|
handleDelete?.();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
|
<div className="card">
|
||||||
|
<Table variant="secondary">
|
||||||
|
<colgroup>
|
||||||
|
<col width="20%" />
|
||||||
|
<col width="80%" />
|
||||||
|
</colgroup>
|
||||||
|
<TableBody>
|
||||||
|
{isModifyMode && (
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>API 일련번호</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="authorizationNo"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value?.toString() ?? ""}
|
||||||
|
className="w-[12rem] !text-[1.3rem]"
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>API 명</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="authorizationName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="API 명을 입력하세요"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>URL 패턴</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="urlPatternValue"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="URL 패턴을 입력하세요 (예: /api/users/{id})"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>요청 메소드</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="httpMethodCode"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Select
|
||||||
|
value={field.value || undefined}
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="!text-[1.3rem]">
|
||||||
|
<SelectValue placeholder="요청 메소드를 선택하세요" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="GET">GET</SelectItem>
|
||||||
|
<SelectItem value="POST">POST</SelectItem>
|
||||||
|
<SelectItem value="PUT">PUT</SelectItem>
|
||||||
|
<SelectItem value="DELETE">DELETE</SelectItem>
|
||||||
|
<SelectItem value="PATCH">PATCH</SelectItem>
|
||||||
|
<SelectItem value="OPTIONS">OPTIONS</SelectItem>
|
||||||
|
<SelectItem value="HEAD">TRACE</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>정렬 순서</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="sortSeq"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
{...field}
|
||||||
|
value={field.value?.toString() ?? ""}
|
||||||
|
className="w-[12rem] !text-[1.3rem]"
|
||||||
|
onChange={(e) => field.onChange(parseInt(e.target.value) || 0)}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>사용 여부</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="useYn"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<RadioGroup
|
||||||
|
{...field}
|
||||||
|
name="useYn"
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
value={field.value}
|
||||||
|
>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<RadioGroupItem value="Y" id="useY" />
|
||||||
|
<Label htmlFor="useY">예</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<RadioGroupItem value="N" id="useN" />
|
||||||
|
<Label htmlFor="useN">아니오</Label>
|
||||||
|
</div>
|
||||||
|
</RadioGroup>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-center gap-4 pb-12 pt-10">
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
variant="outline"
|
||||||
|
type="button"
|
||||||
|
onClick={() => router.back()}
|
||||||
|
>
|
||||||
|
목록
|
||||||
|
</Button>
|
||||||
|
<Button size="lg" type="submit">
|
||||||
|
저장
|
||||||
|
</Button>
|
||||||
|
{isModifyMode && (
|
||||||
|
<Button size="lg" variant="destructive" type="button" onClick={onDelete}>
|
||||||
|
삭제
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
<ConfirmDialog open={onConfirm} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ApimanForm };
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
"use client";
|
||||||
|
import "@common/assets/styles/grid.css";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
getCoreRowModel,
|
||||||
|
getPaginationRowModel,
|
||||||
|
useReactTable
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DataTable,
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
Pagination
|
||||||
|
} from "@common/components";
|
||||||
|
|
||||||
|
import { ApimanApi, type Api, type ApiParams } from "../api/apiman-api";
|
||||||
|
import { type ApiRoleByApi } from "../../apirole/api/apirole-api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { columns } from "../model/apiman-table-columns";
|
||||||
|
import { ApiRoleDialog } from "./api-role-dialog";
|
||||||
|
|
||||||
|
function ApimanPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [apiQuery, setApiQuery] = useState<ApiParams>({
|
||||||
|
authorizationName: "",
|
||||||
|
httpMethodCode: "",
|
||||||
|
useYn: "",
|
||||||
|
page: 0,
|
||||||
|
size: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
// API 역할 다이얼로그 상태 관리
|
||||||
|
const [apiRoleDialog, setApiRoleDialog] = useState<{
|
||||||
|
isOpen: boolean;
|
||||||
|
api: ApiRoleByApi | null;
|
||||||
|
}>({
|
||||||
|
isOpen: false,
|
||||||
|
api: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: apiList, refetch, isLoading } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.USER_SERVICE.AUTHRTS, apiQuery],
|
||||||
|
queryFn: () => ApimanApi.getApiList(apiQuery),
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data: apiList?.content ?? [],
|
||||||
|
columns,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
pageCount: apiList?.totalPages ?? -1,
|
||||||
|
state: {
|
||||||
|
pagination: {
|
||||||
|
pageIndex: apiQuery.page ?? 0,
|
||||||
|
pageSize: apiQuery.size ?? 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
meta: {
|
||||||
|
openRoleDialog: (api: ApiRoleByApi) => {
|
||||||
|
setApiRoleDialog({
|
||||||
|
isOpen: true,
|
||||||
|
api,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
onPaginationChange: (updater) => {
|
||||||
|
const newPagination =
|
||||||
|
typeof updater === "function"
|
||||||
|
? updater({ pageIndex: apiQuery.page ?? 0, pageSize: apiQuery.size ?? 10 })
|
||||||
|
: updater;
|
||||||
|
|
||||||
|
setApiQuery((prev) => ({
|
||||||
|
...prev,
|
||||||
|
page: newPagination.pageIndex,
|
||||||
|
size: newPagination.pageSize,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
manualPagination: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refetch();
|
||||||
|
}, [apiQuery, refetch]);
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setApiQuery(prev => ({ ...prev, page: 0 }));
|
||||||
|
refetch();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const handleRowClick = (api: Api) => {
|
||||||
|
router.push(`/apiman/register/${api.authorizationNo}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
// API 역할 저장 핸들러
|
||||||
|
const handleSaveRoles = async (roles: ApiRoleByApi[]) => {
|
||||||
|
try {
|
||||||
|
// 실제 구현에서는 API 호출로 대체
|
||||||
|
console.log(`API ${apiRoleDialog.api?.authorizationNo}에 권한 저장:`, roles);
|
||||||
|
// 성공 시 다이얼로그 닫기
|
||||||
|
setApiRoleDialog({ isOpen: false, api: null });
|
||||||
|
// 목록 새로고침
|
||||||
|
refetch();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("권한 저장 중 오류 발생:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card card-border !mt-6">
|
||||||
|
{/* API 역할 다이얼로그 */}
|
||||||
|
<ApiRoleDialog
|
||||||
|
api={apiRoleDialog.api}
|
||||||
|
isOpen={apiRoleDialog.isOpen}
|
||||||
|
onClose={() => setApiRoleDialog({ isOpen: false, api: null })}
|
||||||
|
onSave={handleSaveRoles}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="card card-border">
|
||||||
|
<form onSubmit={handleSubmit} className="flex items-center gap-2 p-2">
|
||||||
|
|
||||||
|
<Label htmlFor="httpMethodCode" className="mr-2 text-label">요청 메소드</Label>
|
||||||
|
<Select
|
||||||
|
value={apiQuery.httpMethodCode || undefined}
|
||||||
|
onValueChange={(value) => setApiQuery( prev => ({ ...prev, httpMethodCode: value === "ALL" ? "" : value }))}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="httpMethodCode" className="h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]">
|
||||||
|
<SelectValue placeholder="요청 메소드 선택" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="ALL">전체</SelectItem>
|
||||||
|
<SelectItem value="GET">GET</SelectItem>
|
||||||
|
<SelectItem value="POST">POST</SelectItem>
|
||||||
|
<SelectItem value="PUT">PUT</SelectItem>
|
||||||
|
<SelectItem value="DELETE">DELETE</SelectItem>
|
||||||
|
<SelectItem value="OPTIONS">OPTIONS</SelectItem>
|
||||||
|
<SelectItem value="PATCH">PATCH</SelectItem>
|
||||||
|
<SelectItem value="HEAD">HEAD</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<Label htmlFor="authorizationName" className="mr-2 text-label">API 명</Label>
|
||||||
|
<Input
|
||||||
|
className="h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]"
|
||||||
|
id="authorizationName"
|
||||||
|
value={apiQuery.authorizationName || ""}
|
||||||
|
onChange={(e) => setApiQuery( prev => ({ ...prev, authorizationName: e.target.value }))}
|
||||||
|
placeholder="API 명 입력"
|
||||||
|
/>
|
||||||
|
<Button className="h-[3.2rem]" type="submit">
|
||||||
|
조회
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div className="bg-white rounded-lg shadow">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">모듈API 목록</h3>
|
||||||
|
<Button onClick={() => router.push("/apiman/register")}>+등록</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
table={table}
|
||||||
|
isLoading={isLoading}
|
||||||
|
onRowClick={handleRowClick}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
|
<div className="flex-1 text-lm text-muted-foreground">
|
||||||
|
총 {apiList?.totalElements ?? 0} 건
|
||||||
|
</div>
|
||||||
|
<Pagination
|
||||||
|
currentPage={apiQuery.page + 1}
|
||||||
|
totalPages={apiList?.totalPages ?? 0}
|
||||||
|
onPageChange={(page) =>
|
||||||
|
setApiQuery(prev => ({ ...prev, page: page - 1 }))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
value={String(apiQuery.size)}
|
||||||
|
onValueChange={(value) =>
|
||||||
|
setApiQuery(prev => ({ ...prev, page: 0, size: Number(value) }))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="h-8 w-[70px]">
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{[2,10, 20, 30, 40, 50].map((pageSize) => (
|
||||||
|
<SelectItem key={pageSize} value={String(pageSize)}>
|
||||||
|
{pageSize}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ApimanPage };
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { ApimanApi, type ApiFormData } from "../api/apiman-api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { useAlertStore } from "@/shared/lib/use-alert-store";
|
||||||
|
import { ApimanForm } from "./apiman-form";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { AxiosError } from "axios";
|
||||||
|
|
||||||
|
// API 스키마 정의
|
||||||
|
const apiFormSchema = z.object({
|
||||||
|
authorizationNo: z.number().nullable(),
|
||||||
|
authorizationName: z.string().min(1, "API 명을 입력해주세요"),
|
||||||
|
urlPatternValue: z.string().min(1, "URL 패턴을 입력해주세요"),
|
||||||
|
httpMethodCode: z.string().min(1, "HTTP 메소드를 선택해주세요"),
|
||||||
|
sortSeq: z.number().min(0, "정렬 순서는 0 이상이어야 합니다"),
|
||||||
|
useYn: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
function CreatePage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const { setMessage: alert } = useAlertStore((state) => state);
|
||||||
|
|
||||||
|
const { mutateAsync: createApi } = useMutation({
|
||||||
|
mutationFn: (data: ApiFormData) => ApimanApi.createApi(data),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("등록되었습니다.", () => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.USER_SERVICE.AUTHRTS],
|
||||||
|
});
|
||||||
|
router.push("/apiman");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (error: unknown) => {
|
||||||
|
const axiosError = error as AxiosError<{ message: string }>;
|
||||||
|
if (axiosError.response?.data) {
|
||||||
|
alert(axiosError.response.data.message);
|
||||||
|
} else if (error instanceof Error) {
|
||||||
|
alert(error.message);
|
||||||
|
} else {
|
||||||
|
alert("알 수 없는 오류가 발생했습니다.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = useForm<ApiFormData>({
|
||||||
|
resolver: zodResolver(apiFormSchema),
|
||||||
|
defaultValues: {
|
||||||
|
authorizationNo: null,
|
||||||
|
authorizationName: "",
|
||||||
|
urlPatternValue: "",
|
||||||
|
httpMethodCode: "",
|
||||||
|
sortSeq: 0,
|
||||||
|
useYn: "Y"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card card-border !mb-0 !mt-6">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">API 등록</h3>
|
||||||
|
</div>
|
||||||
|
<ApimanForm
|
||||||
|
form={form}
|
||||||
|
handleSave={createApi}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CreatePage };
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { ApimanApi, type ApiFormData } from "../api/apiman-api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { useAlertStore } from "@/shared/lib/use-alert-store";
|
||||||
|
import { ApimanForm } from "./apiman-form";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { AxiosError } from "axios";
|
||||||
|
|
||||||
|
// API 스키마 정의
|
||||||
|
const apiFormSchema = z.object({
|
||||||
|
authorizationNo: z.number().nullable(),
|
||||||
|
authorizationName: z.string().min(1, "API 명을 입력해주세요"),
|
||||||
|
urlPatternValue: z.string().min(1, "URL 패턴을 입력해주세요"),
|
||||||
|
httpMethodCode: z.string().min(1, "HTTP 메소드를 선택해주세요"),
|
||||||
|
sortSeq: z.number(),
|
||||||
|
useYn: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
function ModifyPage({ authorizationNo }: { authorizationNo: number }) {
|
||||||
|
const router = useRouter();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const { setMessage: alert } = useAlertStore((state) => state);
|
||||||
|
|
||||||
|
const { data: apiDetail } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.USER_SERVICE.AUTHRTS, authorizationNo],
|
||||||
|
queryFn: () => ApimanApi.getApi(authorizationNo),
|
||||||
|
select: (data) => {
|
||||||
|
const keys = Object.keys(apiFormSchema.shape);
|
||||||
|
const filteredData = Object.fromEntries(
|
||||||
|
Object.entries(data).filter(([key]) => keys.includes(key)),
|
||||||
|
);
|
||||||
|
return filteredData;
|
||||||
|
},
|
||||||
|
enabled: !!authorizationNo,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutateAsync: updateApi } = useMutation({
|
||||||
|
mutationFn: (data: ApiFormData) => ApimanApi.updateApi(authorizationNo, data),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("수정되었습니다.", () => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.USER_SERVICE.AUTHRTS],
|
||||||
|
});
|
||||||
|
router.back();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (error: unknown) => {
|
||||||
|
const axiosError = error as AxiosError<{ message: string }>;
|
||||||
|
if (axiosError.response?.data) {
|
||||||
|
alert(axiosError.response.data.message);
|
||||||
|
} else if (error instanceof Error) {
|
||||||
|
alert(error.message);
|
||||||
|
} else {
|
||||||
|
alert("알 수 없는 오류가 발생했습니다.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutateAsync: deleteApi } = useMutation({
|
||||||
|
mutationFn: () => ApimanApi.deleteApi(authorizationNo),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("삭제되었습니다.", router.back);
|
||||||
|
},
|
||||||
|
onError: (error: unknown) => {
|
||||||
|
const axiosError = error as AxiosError<{ message: string }>;
|
||||||
|
if (axiosError.response?.data) {
|
||||||
|
alert(axiosError.response.data.message);
|
||||||
|
} else if (error instanceof Error) {
|
||||||
|
alert(error.message);
|
||||||
|
} else {
|
||||||
|
alert("알 수 없는 오류가 발생했습니다.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = useForm<ApiFormData>({
|
||||||
|
resolver: zodResolver(apiFormSchema),
|
||||||
|
values: apiDetail as ApiFormData,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card card-border !mb-0 !mt-6">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">API 수정</h3>
|
||||||
|
</div>
|
||||||
|
<ApimanForm
|
||||||
|
form={form}
|
||||||
|
authorizationNo={authorizationNo}
|
||||||
|
handleSave={async (data) => {
|
||||||
|
await updateApi(data);
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
handleDelete={deleteApi}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ModifyPage };
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import type { Page } from "@/shared/types";
|
||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
|
||||||
|
export interface ApiRole {
|
||||||
|
roleId?: string;
|
||||||
|
/** @format int64 */
|
||||||
|
authorizationNo?: number;
|
||||||
|
authorizationName?: string;
|
||||||
|
urlPatternValue?: string;
|
||||||
|
httpMethodCode?: string;
|
||||||
|
/** @format int32 */
|
||||||
|
sortSeq?: number;
|
||||||
|
createdAt?: boolean;
|
||||||
|
}
|
||||||
|
/** API 에서 역할 추가 (API에 대한 역할) */
|
||||||
|
export interface ApiRoleByApi {
|
||||||
|
roleId?: string;
|
||||||
|
roleName?: string;
|
||||||
|
roleContent?: string;
|
||||||
|
useYn?: string;
|
||||||
|
/** @format int64 */
|
||||||
|
authorizationNo?: number;
|
||||||
|
mode?:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiRoleParams {
|
||||||
|
authorizationNo?: number; // API 일련번호 검색
|
||||||
|
roleId?: string; // API 역할 검색
|
||||||
|
page?: number; // 페이지 번호
|
||||||
|
size?: number; // 페이지 크기
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiRoleFormData {
|
||||||
|
authorizationNo: number | null; // API 일련번호 (신규 등록 시 null)
|
||||||
|
authorizationName: string; // API 명
|
||||||
|
urlPatternValue: string; // URL 패턴
|
||||||
|
httpMethodCode: string; // HTTP 메소드
|
||||||
|
sortSeq: number; // 정렬 순서
|
||||||
|
useYn: string; // 사용 여부
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ApiRoleApi = {
|
||||||
|
getApiRoleList: async (params: ApiRoleParams) => {
|
||||||
|
const { data } = await client.get<Page<ApiRole>>(
|
||||||
|
`${ENDPOINT.USER_SERVICE.ROLES_AUTHRTS}`,
|
||||||
|
{ params }
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
getApiRoleByApiList: async (params: ApiRoleParams) => {
|
||||||
|
const { data } = await client.get<Page<ApiRoleByApi>>(
|
||||||
|
`${ENDPOINT.USER_SERVICE.ROLES_AUTHRTS}/api`,
|
||||||
|
{ params }
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
getApiRole: async (authorizationNo: number) => {
|
||||||
|
const { data } = await client.get<ApiRole>(`${ENDPOINT.USER_SERVICE.ROLES_AUTHRTS}/${authorizationNo}`);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
createApiRole: async (apiData: ApiRoleFormData) => {
|
||||||
|
const { data } = await client.post<ApiRole>(ENDPOINT.USER_SERVICE.ROLES_AUTHRTS, apiData);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
updateApiRole: async (authorizationNo: number, apiData: ApiRoleFormData) => {
|
||||||
|
const { data } = await client.put<ApiRole>(`${ENDPOINT.USER_SERVICE.ROLES_AUTHRTS}/${authorizationNo}`, apiData);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteApiRole: async (authorizationNo: number) => {
|
||||||
|
const { data } = await client.delete<void>(`${ENDPOINT.USER_SERVICE.ROLES_AUTHRTS}/${authorizationNo}`);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
import { AxiosError } from "axios";
|
|
||||||
import { client } from "@/shared/api";
|
|
||||||
import {
|
|
||||||
ACCESS_TOKEN,
|
|
||||||
CLAIM_NAME,
|
|
||||||
ENDPOINT,
|
|
||||||
JWT_EXPIRATION_TIME,
|
|
||||||
REFRESH_TOKEN,
|
|
||||||
TOKEN_ID,
|
|
||||||
} from "@/shared/config";
|
|
||||||
import { tokenManager } from "../lib/token-manager";
|
|
||||||
import type { LoginService, ILogin } from "../model/login";
|
|
||||||
|
|
||||||
export class LoginApiService implements LoginService {
|
|
||||||
private static instance: LoginApiService;
|
|
||||||
|
|
||||||
private constructor() {}
|
|
||||||
|
|
||||||
public static getInstance(): LoginApiService {
|
|
||||||
if (!LoginApiService.instance) {
|
|
||||||
LoginApiService.instance = new LoginApiService();
|
|
||||||
}
|
|
||||||
return LoginApiService.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async login(payload: ILogin): Promise<void> {
|
|
||||||
try {
|
|
||||||
const response = await client.post(ENDPOINT.USER_SERVICE.LOGIN, {
|
|
||||||
userId: payload.userId,
|
|
||||||
password: payload.password,
|
|
||||||
});
|
|
||||||
|
|
||||||
const accessToken = response.headers[ACCESS_TOKEN];
|
|
||||||
const refreshToken = response.headers[REFRESH_TOKEN];
|
|
||||||
const tokenId = response.headers[TOKEN_ID];
|
|
||||||
|
|
||||||
if (!refreshToken || !accessToken || !tokenId) {
|
|
||||||
throw new Error("Missing required authentication tokens");
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenManager.setToken(ACCESS_TOKEN, accessToken);
|
|
||||||
tokenManager.setToken(TOKEN_ID, tokenId);
|
|
||||||
tokenManager.setRefreshToken(refreshToken);
|
|
||||||
tokenManager.setupRefreshTimer(
|
|
||||||
() => this.silentRefresh(),
|
|
||||||
JWT_EXPIRATION_TIME,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof AxiosError) {
|
|
||||||
throw new Error(
|
|
||||||
`Login failed: ${error.response?.data?.message || error.message}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async silentRefresh(): Promise<void> {
|
|
||||||
try {
|
|
||||||
const refreshToken = tokenManager.getRefreshToken();
|
|
||||||
if (!refreshToken) {
|
|
||||||
throw new Error("No refresh token available");
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenManager.setToken(CLAIM_NAME, refreshToken);
|
|
||||||
|
|
||||||
const response = await client.put(ENDPOINT.USER_SERVICE.SILENT_REFRESH);
|
|
||||||
|
|
||||||
const accessToken = response.headers[ACCESS_TOKEN];
|
|
||||||
const tokenId = response.headers[TOKEN_ID];
|
|
||||||
|
|
||||||
if (!accessToken || !tokenId) {
|
|
||||||
throw new Error("Missing required authentication tokens");
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenManager.setToken(ACCESS_TOKEN, accessToken);
|
|
||||||
tokenManager.setToken(TOKEN_ID, tokenId);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof AxiosError) {
|
|
||||||
throw new Error(
|
|
||||||
`Silent refresh failed: ${error.response?.data?.message || error.message}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const LoginApi = LoginApiService.getInstance();
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { images } from "@common/assets";
|
import { images } from "@common/assets";
|
||||||
import { LoginApi } from "../api/login";
|
import { LoginApi } from "@/entities/auth";
|
||||||
import "./login.css";
|
import "./login.css";
|
||||||
|
|
||||||
function LoginPage() {
|
function LoginPage() {
|
||||||
@@ -13,7 +13,8 @@ function LoginPage() {
|
|||||||
const userId = formData.get("id") as string;
|
const userId = formData.get("id") as string;
|
||||||
const password = formData.get("password") as string;
|
const password = formData.get("password") as string;
|
||||||
|
|
||||||
LoginApi.login({ userId, password });
|
await LoginApi.login({ userId, password });
|
||||||
|
window.location.href = "/dashboard";
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export { DashboardPage } from "./ui/dashboard-page";
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
function DashboardPage() {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DashboardPage };
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
//import { http } from "@/libs/axios";
|
||||||
|
import type { Page } from "@/shared/types";
|
||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
|
||||||
|
export interface Group {
|
||||||
|
groupId: string;
|
||||||
|
groupNm: string;
|
||||||
|
groupSeCd: string;
|
||||||
|
groupExpln: string;
|
||||||
|
delYn: string;
|
||||||
|
regDt: string;
|
||||||
|
rgtr: string;
|
||||||
|
mdfcnDt: string | null;
|
||||||
|
mdfr: string | null;
|
||||||
|
authrtId: string;
|
||||||
|
siteId: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupParams {
|
||||||
|
groupNm?: string;
|
||||||
|
groupSeCd?: string;
|
||||||
|
siteId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupFormData {
|
||||||
|
groupId: string;
|
||||||
|
groupNm: string;
|
||||||
|
groupSeCd: string;
|
||||||
|
groupExpln: string;
|
||||||
|
delYn: string;
|
||||||
|
authrtId: string;
|
||||||
|
siteId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const GroupApi = {
|
||||||
|
getGroupList: async (params: GroupParams) => {
|
||||||
|
const { data } = await client.get<Page<Group>>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.GROUP}`
|
||||||
|
, { params });
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
getGroup: async (groupId: string) => {
|
||||||
|
const { data } = await client.get<Group>(`${ENDPOINT.CMS_SERVICE.GROUP}/${groupId}`);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
createGroup: async (groupData: GroupFormData) => {
|
||||||
|
const { data } = await client.post<Group>(ENDPOINT.CMS_SERVICE.GROUP, groupData);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
updateGroup: async (groupId: string, groupData: GroupFormData) => {
|
||||||
|
const { data } = await client.put<Group>(`${ENDPOINT.CMS_SERVICE.GROUP}/${groupId}`, groupData);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteGroup: async (groupId: string) => {
|
||||||
|
const { data } = await client.delete<void>(`${ENDPOINT.CMS_SERVICE.GROUP}/${groupId}`);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { GroupPage } from "./ui/group-page";
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import { type ColumnDef } from "@tanstack/react-table";
|
||||||
|
import { Checkbox } from "@common/components/ui";
|
||||||
|
import { type Group } from "../api/group-api";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
export const columns: ColumnDef<Group>[] = [
|
||||||
|
/* {
|
||||||
|
id: "select",
|
||||||
|
header: ({ table }) => (
|
||||||
|
<Checkbox
|
||||||
|
checked={table.getIsAllPageRowsSelected()}
|
||||||
|
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
||||||
|
aria-label="전체 선택"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<Checkbox
|
||||||
|
checked={row.getIsSelected()}
|
||||||
|
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
||||||
|
aria-label="행 선택"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
enableSorting: false,
|
||||||
|
enableHiding: false,
|
||||||
|
}, */
|
||||||
|
{
|
||||||
|
id: "no",
|
||||||
|
header: "NO",
|
||||||
|
accessorFn: (_, index) => index + 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "groupId",
|
||||||
|
header: "그룹 ID",
|
||||||
|
enableSorting: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "groupNm",
|
||||||
|
header: "그룹명",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "groupSeNm",
|
||||||
|
header: "그룹구분",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "delYn",
|
||||||
|
header: "삭제여부",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<Checkbox
|
||||||
|
checked={row.original.delYn === "Y"}
|
||||||
|
disabled
|
||||||
|
aria-label="삭제여부"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "siteId",
|
||||||
|
header: "사이트 ID",
|
||||||
|
enableSorting: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "roleNm",
|
||||||
|
header: "권한",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "mdfrNm",
|
||||||
|
header: "수정자",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "mdfcnDt",
|
||||||
|
header: "수정일시",
|
||||||
|
cell: ({ row }) => dayjs(row.original.mdfcnDt).format("YYYY-MM-DD"),
|
||||||
|
}
|
||||||
|
];
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
// apps/cs/src/pages/group/ui/create-page.tsx
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { GroupApi, type GroupFormData } from "../api/group-api";
|
||||||
|
import { useAlertStore } from "@/shared/lib/use-alert-store";
|
||||||
|
import { GroupForm } from "./group-form";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const groupFormSchema = z.object({
|
||||||
|
groupId: z.string(),
|
||||||
|
groupNm: z.string().min(1, "그룹명을 입력해주세요"),
|
||||||
|
groupSeCd: z.string().min(1, "그룹구분을 선택해주세요"),
|
||||||
|
groupExpln: z.string(),
|
||||||
|
delYn: z.string(),
|
||||||
|
authrtId: z.string(),
|
||||||
|
siteId: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
function CreatePage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const { setMessage: alert } = useAlertStore((state) => state);
|
||||||
|
|
||||||
|
const { mutateAsync: createGroup } = useMutation({
|
||||||
|
mutationFn: (data: GroupFormData) => GroupApi.createGroup(data),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("등록되었습니다.", router.back);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
/*{
|
||||||
|
"timestamp": "2025-04-07T14:30:15.471581",
|
||||||
|
"message": "해당 권한이 존재하지 않습니다. ID = sd",
|
||||||
|
"status": 400,
|
||||||
|
"code": "B001",
|
||||||
|
"errors": []
|
||||||
|
}*/
|
||||||
|
if(error.response.data){
|
||||||
|
alert(error.response.data.message);
|
||||||
|
}else{
|
||||||
|
alert(error.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = useForm<GroupFormData>({
|
||||||
|
resolver: zodResolver(groupFormSchema),
|
||||||
|
defaultValues: {
|
||||||
|
groupId: "",
|
||||||
|
groupNm: "",
|
||||||
|
groupSeCd: "",
|
||||||
|
groupExpln: "",
|
||||||
|
delYn: "N",
|
||||||
|
authrtId: "",
|
||||||
|
siteId: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card card-border !mb-0 !mt-6">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">그룹 등록</h3>
|
||||||
|
</div>
|
||||||
|
<GroupForm form={form} handleSave={createGroup} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CreatePage };
|
||||||
@@ -0,0 +1,258 @@
|
|||||||
|
// apps/cs/src/pages/group/ui/group-form.tsx
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||||
|
import { type UseFormReturn } from "react-hook-form";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
RadioGroup,
|
||||||
|
RadioGroupItem,
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableRow,
|
||||||
|
} from "@common/components";
|
||||||
|
import { CodeSelect } from "@/entities/code";
|
||||||
|
import { FormItem, FormControl, FormField, Form } from "@/shared/ui/form";
|
||||||
|
import type { GroupFormData } from "../api/group-api";
|
||||||
|
import { ConfirmDialog } from "@/shared/ui/confirm-dialog";
|
||||||
|
|
||||||
|
interface GroupFormProps {
|
||||||
|
form: UseFormReturn<GroupFormData>;
|
||||||
|
groupId?: string;
|
||||||
|
handleSave: (data: GroupFormData) => Promise<void>;
|
||||||
|
handleDelete?: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function GroupForm({ form, groupId, handleSave, handleDelete }: GroupFormProps) {
|
||||||
|
const isModifyMode = !!groupId;
|
||||||
|
const router = useRouter();
|
||||||
|
const { confirm } = useConfirm();
|
||||||
|
const [onConfirm, setOnConfirm] = useState(false);
|
||||||
|
|
||||||
|
const handleConfirm = async (callback: () => Promise<void>) => {
|
||||||
|
setOnConfirm(true);
|
||||||
|
await callback();
|
||||||
|
setOnConfirm(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmit = async (data: GroupFormData) => {
|
||||||
|
const confirmMessage = isModifyMode
|
||||||
|
? "수정하시겠습니까?"
|
||||||
|
: "저장하시겠습니까?";
|
||||||
|
|
||||||
|
await handleConfirm(async () => {
|
||||||
|
if (await confirm(confirmMessage)) {
|
||||||
|
handleSave(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDelete = async () => {
|
||||||
|
await handleConfirm(async () => {
|
||||||
|
if (await confirm("삭제하시겠습니까?")) {
|
||||||
|
handleDelete?.();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
|
<div className="card">
|
||||||
|
<Table variant="secondary">
|
||||||
|
<colgroup>
|
||||||
|
<col width="20%" />
|
||||||
|
<col width="80%" />
|
||||||
|
</colgroup>
|
||||||
|
<TableBody>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>그룹 ID</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="groupId"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="w-[12rem] !text-[1.3rem]"
|
||||||
|
disabled={isModifyMode}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>그룹명</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="groupNm"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="그룹명을 입력하세요"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>그룹구분</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="groupSeCd"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<CodeSelect
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
upCd="GROUPSECD"
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>그룹설명</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="groupExpln"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="그룹설명을 입력하세요"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>사이트 ID</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="siteId"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="사이트 ID를 입력하세요"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>권한 ID</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="authrtId"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="권한 ID를 입력하세요"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>삭제여부</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="delYn"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<RadioGroup
|
||||||
|
{...field}
|
||||||
|
name="delYn"
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<RadioGroupItem value="Y" id="delY" />
|
||||||
|
<Label htmlFor="delY">예</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<RadioGroupItem value="N" id="delN" />
|
||||||
|
<Label htmlFor="delN">아니오</Label>
|
||||||
|
</div>
|
||||||
|
</RadioGroup>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
<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="submit">
|
||||||
|
저장
|
||||||
|
</Button>
|
||||||
|
{isModifyMode && (
|
||||||
|
<Button size="lg" color="red" type="button" onClick={onDelete}>
|
||||||
|
삭제
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
<ConfirmDialog open={onConfirm} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { GroupForm };
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
"use client";
|
||||||
|
import "@common/assets/styles/grid.css";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
getCoreRowModel,
|
||||||
|
getPaginationRowModel,
|
||||||
|
useReactTable
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DataTable,
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
Pagination
|
||||||
|
} from "@common/components";
|
||||||
|
|
||||||
|
import { GroupApi, type Group, type GroupParams } from "../api/group-api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { columns } from "../model/group-table-columns";
|
||||||
|
|
||||||
|
function GroupPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [groupQuery, setGroupQuery] = useState<GroupParams>({
|
||||||
|
groupNm: "",
|
||||||
|
groupSeCd: "",
|
||||||
|
page: 0,
|
||||||
|
size: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: groupList, refetch } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.GROUP, groupQuery],
|
||||||
|
queryFn: () => GroupApi.getGroupList(groupQuery),
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data: groupList?.content ?? [],
|
||||||
|
columns,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
pageCount: groupList?.totalPages ?? -1,
|
||||||
|
state: {
|
||||||
|
pagination: {
|
||||||
|
pageIndex: groupQuery.page,
|
||||||
|
pageSize: groupQuery.size,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
onPaginationChange: (updater) => {
|
||||||
|
if (typeof updater === 'function') {
|
||||||
|
const newPagination = updater({
|
||||||
|
pageIndex: groupQuery.page,
|
||||||
|
pageSize: groupQuery.size,
|
||||||
|
});
|
||||||
|
setGroupQuery(prev => ({
|
||||||
|
...prev,
|
||||||
|
page: newPagination.pageIndex,
|
||||||
|
size: newPagination.pageSize,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
manualPagination: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setGroupQuery(prev => ({ ...prev, page: 0 })); // 검색 시 첫 페이지로 이동
|
||||||
|
refetch();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRowClick = (row: Group) => {
|
||||||
|
router.push(`/group/register/${row.groupId}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refetch();
|
||||||
|
}, [groupQuery, refetch]); //[groupQuery.page, groupQuery.size]); // 페이지나 사이즈 변경 시 자동 조회
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card card-border !mt-6">
|
||||||
|
<div className="card card-border">
|
||||||
|
<form onSubmit={handleSubmit} className="flex items-center gap-2 p-2">
|
||||||
|
<Label htmlFor="" className="mr-2 text-label">
|
||||||
|
그룹명
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
className="h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]"
|
||||||
|
value={groupQuery.groupNm}
|
||||||
|
onChange={(e) => setGroupQuery(prev => ({ ...prev, groupNm: e.target.value }))}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button className="h-[3.2rem]" type="submit">
|
||||||
|
조회
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div className="card card-border">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">그룹 목록</h3>
|
||||||
|
<Button onClick={() => router.push("/group/register")}>+등록</Button>
|
||||||
|
</div>
|
||||||
|
<div className="card !m-[1.2rem] h-[49rem] overflow-auto !p-0">
|
||||||
|
<DataTable table={table} onRowClick={handleRowClick} />
|
||||||
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
|
<div className="flex-1 text-lm text-muted-foreground">
|
||||||
|
총 {groupList?.totalElements ?? 0} 건
|
||||||
|
</div>
|
||||||
|
<Pagination
|
||||||
|
currentPage={groupQuery.page + 1}
|
||||||
|
totalPages={groupList?.totalPages ?? 0}
|
||||||
|
onPageChange={(page) =>
|
||||||
|
setGroupQuery(prev => ({ ...prev, page: page - 1 }))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
value={String(groupQuery.size)}
|
||||||
|
onValueChange={(value) =>
|
||||||
|
setGroupQuery(prev => ({ ...prev, page: 0, size: Number(value) }))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="h-8 w-[70px]">
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{[2,10, 20, 30, 40, 50].map((pageSize) => (
|
||||||
|
<SelectItem key={pageSize} value={String(pageSize)}>
|
||||||
|
{pageSize}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { GroupPage };
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
// apps/cs/src/pages/group/ui/modify-page.tsx
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { GroupApi, type GroupFormData } from "../api/group-api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { useAlertStore } from "@/shared/lib/use-alert-store";
|
||||||
|
import { GroupForm } from "./group-form";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
// Group 스키마 정의
|
||||||
|
const groupFormSchema = z.object({
|
||||||
|
groupId: z.string(),
|
||||||
|
groupNm: z.string().min(1, "그룹명을 입력해주세요"),
|
||||||
|
groupSeCd: z.string().min(1, "그룹구분을 선택해주세요"),
|
||||||
|
groupExpln: z.string(),
|
||||||
|
delYn: z.string(),
|
||||||
|
authrtId: z.string(),
|
||||||
|
siteId: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
function ModifyPage({ groupId }: { groupId: string }) {
|
||||||
|
const router = useRouter();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const { setMessage: alert } = useAlertStore((state) => state);
|
||||||
|
|
||||||
|
const { data: groupDetail } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.GROUP, groupId],
|
||||||
|
queryFn: () => GroupApi.getGroup(groupId),
|
||||||
|
select: (data) => {
|
||||||
|
const keys = Object.keys(groupFormSchema.shape);
|
||||||
|
const filteredData = Object.fromEntries(
|
||||||
|
Object.entries(data).filter(([key]) => keys.includes(key)),
|
||||||
|
);
|
||||||
|
return filteredData;
|
||||||
|
},
|
||||||
|
enabled: !!groupId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutateAsync: updateGroup } = useMutation({
|
||||||
|
mutationFn: (data: GroupFormData) => GroupApi.updateGroup(groupId, data),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("수정되었습니다.", () => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.GROUP],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
if(error.response.data){
|
||||||
|
alert(error.response.data.message);
|
||||||
|
}else{
|
||||||
|
alert(error.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutateAsync: deleteGroup } = useMutation({
|
||||||
|
mutationFn: () => GroupApi.deleteGroup(groupId),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("삭제되었습니다.", router.back);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
if(error.response.data){
|
||||||
|
alert(error.response.data.message);
|
||||||
|
}else{
|
||||||
|
alert(error.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = useForm<GroupFormData>({
|
||||||
|
resolver: zodResolver(groupFormSchema),
|
||||||
|
values: groupDetail as GroupFormData,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card card-border !mb-0 !mt-6">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">그룹 수정</h3>
|
||||||
|
</div>
|
||||||
|
<GroupForm
|
||||||
|
form={form}
|
||||||
|
groupId={groupId}
|
||||||
|
handleSave={updateGroup}
|
||||||
|
handleDelete={deleteGroup}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ModifyPage };
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import type {
|
||||||
|
Image,
|
||||||
|
ImageFormData,
|
||||||
|
ImageList,
|
||||||
|
ImageParams,
|
||||||
|
ImageService,
|
||||||
|
} from "../model/image-interface";
|
||||||
|
|
||||||
|
export class ImageApiService implements ImageService {
|
||||||
|
public async getImageList(params: ImageParams): Promise<ImageList> {
|
||||||
|
const response = await client.get<ImageList>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.IMAGES}`,
|
||||||
|
{
|
||||||
|
params,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getImageInfo(imgSn: string): Promise<Image> {
|
||||||
|
const response = await client.get<Image>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.IMAGES}/${imgSn}`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createImage(data: ImageFormData): Promise<void> {
|
||||||
|
const response = await client.post<void>(ENDPOINT.CMS_SERVICE.IMAGES, data);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateImage(imgSn: string, data: ImageFormData): Promise<void> {
|
||||||
|
const response = await client.put<void>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.IMAGES}/${imgSn}`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteImage(imgSn: string): Promise<void> {
|
||||||
|
await client.delete(`${ENDPOINT.CMS_SERVICE.IMAGES}/${imgSn}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ImageApi = new ImageApiService();
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export { CreatePage } from "./ui/create-page";
|
||||||
|
export { ModifyPage } from "./ui/modify-page";
|
||||||
|
export { ImagePage } from "./ui/image-page";
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { Upload, type HttpResponse } from "tus-js-client";
|
||||||
|
import { getCookie, setCookie } from "@/shared/lib";
|
||||||
|
import { AUTH_USER_ID, CLAIM_NAME, ENDPOINT } from "@/shared/config";
|
||||||
|
|
||||||
|
type UploadOptions = {
|
||||||
|
handleUploadStart?: (upload: Upload) => void;
|
||||||
|
handleProgress?: (percentage: string) => void;
|
||||||
|
handleSuccess?: (upload: Upload) => void;
|
||||||
|
handleResponse?: (res: HttpResponse) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleUpload = (files: FileList, options?: UploadOptions) => {
|
||||||
|
let metadata = {};
|
||||||
|
|
||||||
|
const file = files.item(0);
|
||||||
|
if (!file) return;
|
||||||
|
metadata = {
|
||||||
|
filename: file.name,
|
||||||
|
filetype: file.type,
|
||||||
|
};
|
||||||
|
|
||||||
|
const atflCd = getCookie("atfl-cd-key");
|
||||||
|
if (atflCd) {
|
||||||
|
metadata = {
|
||||||
|
...metadata,
|
||||||
|
atflCd,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const upload = new Upload(file, {
|
||||||
|
endpoint: `${ENDPOINT.ATTACH_SERVICE.TUS_UPLOAD}`,
|
||||||
|
chunkSize: 10 * 1024 * 1024,
|
||||||
|
headers: {
|
||||||
|
[CLAIM_NAME]: getCookie(CLAIM_NAME) ?? "",
|
||||||
|
[AUTH_USER_ID]: getCookie(AUTH_USER_ID) ?? "",
|
||||||
|
},
|
||||||
|
metadata,
|
||||||
|
onError(error) {
|
||||||
|
console.error(`Failed because: ${error}`);
|
||||||
|
},
|
||||||
|
onProgress(bytesUploaded, bytesTotal) {
|
||||||
|
const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2);
|
||||||
|
options?.handleProgress?.(percentage);
|
||||||
|
},
|
||||||
|
onAfterResponse(req, res) {
|
||||||
|
const fileInfo = res.getHeader("X-File-Info");
|
||||||
|
if (fileInfo === undefined || fileInfo === null) return;
|
||||||
|
|
||||||
|
setCookie("atfl-cd-key", JSON.parse(fileInfo)?.atflCd ?? "");
|
||||||
|
options?.handleResponse?.(res);
|
||||||
|
},
|
||||||
|
onSuccess() {
|
||||||
|
options?.handleSuccess?.(upload);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
upload.start();
|
||||||
|
options?.handleUploadStart?.(upload);
|
||||||
|
|
||||||
|
console.log("upload start >>>>>", upload);
|
||||||
|
};
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
import type { PageableList, PageableParams } from "@/shared/model";
|
||||||
|
|
||||||
|
export const IMAGE_TYPE = {
|
||||||
|
IMGSUB: "IMGSUB",
|
||||||
|
IMGMAIN: "IMGMAIN",
|
||||||
|
IMGLOGIN: "IMGLOGIN",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type ImageType = (typeof IMAGE_TYPE)[keyof typeof IMAGE_TYPE];
|
||||||
|
|
||||||
|
export interface ImageParams extends PageableParams {
|
||||||
|
keyword: string;
|
||||||
|
imgTypeCd: string;
|
||||||
|
useYn: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Image {
|
||||||
|
imgSn: number;
|
||||||
|
imgTypeCd: string;
|
||||||
|
imgTypeNm: string;
|
||||||
|
imgTtl: string;
|
||||||
|
lnkgUrlAddr: string;
|
||||||
|
atflYn: string;
|
||||||
|
sortSeq: number;
|
||||||
|
atflCd: string;
|
||||||
|
useYn: string;
|
||||||
|
mdfcnDt: string;
|
||||||
|
mdFr: string;
|
||||||
|
mdfrNm: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const imageFormSchema = z.object({
|
||||||
|
imgTtl: z.string(),
|
||||||
|
sortSeq: z.number(),
|
||||||
|
imgTypeCd: z.string(),
|
||||||
|
atflYn: z.string(),
|
||||||
|
atflCd: z.string().nullish(),
|
||||||
|
lnkgUrlAddr: z.string().nullish(),
|
||||||
|
useYn: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ImageFormData = z.infer<typeof imageFormSchema>;
|
||||||
|
export type ImageList = PageableList<Image>;
|
||||||
|
|
||||||
|
export interface ImageService {
|
||||||
|
getImageList: (params: ImageParams) => Promise<ImageList>;
|
||||||
|
getImageInfo: (imgSn: string) => Promise<Image>;
|
||||||
|
createImage: (data: ImageFormData) => Promise<void>;
|
||||||
|
updateImage: (imgSn: string, data: ImageFormData) => Promise<void>;
|
||||||
|
deleteImage: (imgSn: string) => Promise<void>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import { type ColumnDef } from "@tanstack/react-table";
|
||||||
|
import { Checkbox } from "@common/components/ui";
|
||||||
|
import { type Image } from "./image-interface";
|
||||||
|
import { IMAGE_TYPE } from "./image-interface";
|
||||||
|
|
||||||
|
export const columns: ColumnDef<Image>[] = [
|
||||||
|
{
|
||||||
|
id: "select",
|
||||||
|
header: ({ table }) => (
|
||||||
|
<Checkbox
|
||||||
|
checked={table.getIsAllPageRowsSelected()}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
table.toggleAllPageRowsSelected(!!checked)
|
||||||
|
}
|
||||||
|
className="h-4 w-4 rounded border-gray-300"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<Checkbox
|
||||||
|
checked={row.getIsSelected()}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
onCheckedChange={(checked) => row.toggleSelected(!!checked)}
|
||||||
|
className="h-4 w-4 rounded border-gray-300"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "imgSn",
|
||||||
|
header: "NO",
|
||||||
|
cell: ({ row }) => row.index + 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "imgTypeCd",
|
||||||
|
header: "이미지구분",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const type = row.getValue("imgTypeCd") as string;
|
||||||
|
switch (type) {
|
||||||
|
case IMAGE_TYPE.IMGSUB:
|
||||||
|
return "서브이미지";
|
||||||
|
case IMAGE_TYPE.IMGMAIN:
|
||||||
|
return "메인이미지";
|
||||||
|
case IMAGE_TYPE.IMGLOGIN:
|
||||||
|
return "로그인이미지";
|
||||||
|
default:
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "imgTtl",
|
||||||
|
header: "이미지명",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "useYn",
|
||||||
|
header: "사용여부",
|
||||||
|
cell: ({ row }) => (row.getValue("useYn") === "Y" ? "사용" : "미사용"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "mdfrNm",
|
||||||
|
header: "최종수정자",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "mdfcnDt",
|
||||||
|
header: "최종수정일",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const date = row.getValue("mdfcnDt") as string;
|
||||||
|
return date ? dayjs(date).format("YYYY-MM-DD") : "";
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import { useAlertStore } from "@/shared/lib/use-alert-store";
|
||||||
|
import { imageFormSchema, type ImageFormData } from "../model/image-interface";
|
||||||
|
import { ImageApi } from "../api/image-service";
|
||||||
|
import { ImageForm } from "./image-form";
|
||||||
|
|
||||||
|
function CreatePage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const { setMessage: alert } = useAlertStore((state) => state);
|
||||||
|
|
||||||
|
const { mutateAsync: createImage } = useMutation({
|
||||||
|
mutationFn: (data: ImageFormData) => ImageApi.createImage(data),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("등록되었습니다.", router.back);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = useForm<ImageFormData>({
|
||||||
|
resolver: zodResolver(imageFormSchema),
|
||||||
|
defaultValues: {
|
||||||
|
atflYn: "Y",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card card-border !mt-6">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">이미지 등록</h3>
|
||||||
|
</div>
|
||||||
|
<ImageForm form={form} handleSave={createImage} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CreatePage };
|
||||||
@@ -0,0 +1,317 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import type { UseFormReturn } from "react-hook-form";
|
||||||
|
import type { HttpResponse, Upload } from "tus-js-client";
|
||||||
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
FileUploader,
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
Progress,
|
||||||
|
RadioGroup,
|
||||||
|
RadioGroupItem,
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableRow,
|
||||||
|
} from "@common/components";
|
||||||
|
import { CodeSelect } from "@/entities/code";
|
||||||
|
import { ConfirmDialog } from "@/shared/ui/confirm-dialog";
|
||||||
|
import { Form, FormControl, FormField, FormItem } from "@/shared/ui/form";
|
||||||
|
import { handleUpload } from "../lib/utils";
|
||||||
|
import type { ImageFormData } from "../model/image-interface";
|
||||||
|
|
||||||
|
type ImageFormProps = {
|
||||||
|
form: UseFormReturn<ImageFormData>;
|
||||||
|
imgSn?: string;
|
||||||
|
handleSave: (data: ImageFormData) => Promise<void>;
|
||||||
|
handleDelete?: () => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
function ImageForm({ form, imgSn, handleSave, handleDelete }: ImageFormProps) {
|
||||||
|
const isModifyMode = !!imgSn;
|
||||||
|
const atflYn = form.watch("atflYn");
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const { confirm } = useConfirm();
|
||||||
|
const [onConfirm, setOnConfirm] = useState(false);
|
||||||
|
const [upload, setUpload] = useState<Upload | null>(null);
|
||||||
|
const [progress, setProgress] = useState(0);
|
||||||
|
|
||||||
|
const handleConfirm = async (callback: () => Promise<void>) => {
|
||||||
|
setOnConfirm(true);
|
||||||
|
await callback();
|
||||||
|
setOnConfirm(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmit = async (data: ImageFormData) => {
|
||||||
|
const confirmMessage = isModifyMode
|
||||||
|
? "수정하시겠습니까?"
|
||||||
|
: "저장하시겠습니까?";
|
||||||
|
|
||||||
|
await handleConfirm(async () => {
|
||||||
|
if (await confirm(confirmMessage)) {
|
||||||
|
await handleSave(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDelete = async () => {
|
||||||
|
await handleConfirm(async () => {
|
||||||
|
if (await confirm("삭제하시겠습니까?")) {
|
||||||
|
await handleDelete?.();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleProgress = (percentage: string) => {
|
||||||
|
setProgress(Number(percentage));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUploadResponse = (res: HttpResponse) => {
|
||||||
|
const fileInfo = res.getHeader("X-File-Info");
|
||||||
|
if (fileInfo === undefined || fileInfo === null) return;
|
||||||
|
|
||||||
|
form.setValue("atflCd", JSON.parse(fileInfo)?.atflCd);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
|
<div className="card">
|
||||||
|
<Table variant="secondary">
|
||||||
|
<colgroup>
|
||||||
|
<col width="20%" />
|
||||||
|
<col width="80%" />
|
||||||
|
</colgroup>
|
||||||
|
<TableBody>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>이미지명</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="imgTtl"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="이미지명을 입력해주세요"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>정렬순서</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="sortSeq"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
if (isNaN(Number(value))) return;
|
||||||
|
field.onChange(Number(value));
|
||||||
|
}}
|
||||||
|
className="w-[12rem] !text-[1.3rem]"
|
||||||
|
placeholder="정렬순서를 입력해주세요"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>이미지유형</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="imgTypeCd"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<CodeSelect
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
upCd="IMGTYPE"
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>첨부파일</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="atflYn"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<RadioGroup
|
||||||
|
{...field}
|
||||||
|
name="atflYn"
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<RadioGroupItem value="Y" id="atflY" />
|
||||||
|
<Label htmlFor="atflY">이미지파일</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<RadioGroupItem value="N" id="atflN" />
|
||||||
|
<Label htmlFor="atflN">외부링크</Label>
|
||||||
|
</div>
|
||||||
|
</RadioGroup>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
{atflYn === "Y" && (
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>이미지파일</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="atflCd"
|
||||||
|
render={() => (
|
||||||
|
<FormItem className="flex flex-col">
|
||||||
|
<FormControl>
|
||||||
|
<FileUploader
|
||||||
|
id="atflCd"
|
||||||
|
className="!h-auto !max-w-none flex-col !items-start"
|
||||||
|
onUpload={(e) => {
|
||||||
|
const files = e.target.files;
|
||||||
|
if (!files) return;
|
||||||
|
handleUpload(files, {
|
||||||
|
handleUploadStart: setUpload,
|
||||||
|
handleProgress,
|
||||||
|
handleSuccess: setUpload,
|
||||||
|
handleResponse: handleUploadResponse,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
customPreview={
|
||||||
|
<Label htmlFor="atflCd">
|
||||||
|
<div className="relative h-[27rem] w-[48rem] rounded-sm border border-border">
|
||||||
|
<p className="absolute left-0 top-0 p-2 text-base leading-none">
|
||||||
|
{(upload?.file as File)?.name}
|
||||||
|
</p>
|
||||||
|
<div></div>
|
||||||
|
<Progress
|
||||||
|
value={progress}
|
||||||
|
className="absolute bottom-0 left-0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Label>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
{atflYn === "N" && (
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>외부링크</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="lnkgUrlAddr"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="외부링크를 입력해주세요"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>사용여부</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="useYn"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<RadioGroup
|
||||||
|
{...field}
|
||||||
|
name="useYn"
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<RadioGroupItem value="Y" id="useY" />
|
||||||
|
<Label htmlFor="useY">사용</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<RadioGroupItem value="N" id="useN" />
|
||||||
|
<Label htmlFor="useN">미사용</Label>
|
||||||
|
</div>
|
||||||
|
</RadioGroup>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
<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="submit">
|
||||||
|
저장
|
||||||
|
</Button>
|
||||||
|
{isModifyMode && (
|
||||||
|
<Button size="lg" color="red" type="button" onClick={onDelete}>
|
||||||
|
삭제
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
<ConfirmDialog open={onConfirm} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ImageForm };
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
getCoreRowModel,
|
||||||
|
useReactTable,
|
||||||
|
type RowSelectionState,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
import { Button, DataTable, Input, Label } from "@common/components";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { ImageApi } from "../api/image-service";
|
||||||
|
import { columns } from "../model/table-columns";
|
||||||
|
import { type Image, type ImageParams } from "../model/image-interface";
|
||||||
|
|
||||||
|
function ImagePage() {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
||||||
|
const [imageQuery, setImageQuery] = useState<ImageParams>({
|
||||||
|
keyword: "",
|
||||||
|
imgTypeCd: "",
|
||||||
|
useYn: "",
|
||||||
|
page: 0,
|
||||||
|
size: 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: imageList, refetch } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.IMAGES],
|
||||||
|
queryFn: () => ImageApi.getImageList(imageQuery),
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data: imageList?.content ?? [],
|
||||||
|
columns,
|
||||||
|
state: {
|
||||||
|
rowSelection,
|
||||||
|
},
|
||||||
|
enableMultiRowSelection: true,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
refetch();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRowClick = (row: Image) => {
|
||||||
|
router.push(`/image/register/${row.imgSn}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refetch();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card card-border !mt-6">
|
||||||
|
<div className="card card-border">
|
||||||
|
<form onSubmit={handleSubmit} className="flex items-center gap-2 p-2">
|
||||||
|
<Label htmlFor="" className="mr-2 text-label">
|
||||||
|
이미지명
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
className="h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]"
|
||||||
|
value={imageQuery.keyword}
|
||||||
|
onChange={(e) =>
|
||||||
|
setImageQuery({ ...imageQuery, keyword: e.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Button className="h-[3.2rem]" type="submit">
|
||||||
|
조회
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div className="card card-border">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">이미지 목록</h3>
|
||||||
|
<Button onClick={() => router.push("/image/register")}>등록</Button>
|
||||||
|
</div>
|
||||||
|
<div className="card !m-[1.2rem] h-[49rem] overflow-auto !p-0">
|
||||||
|
<DataTable table={table} onRowClick={handleRowClick} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ImagePage };
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { imageFormSchema, type ImageFormData } from "../model/image-interface";
|
||||||
|
import { ImageApi } from "../api/image-service";
|
||||||
|
import { ImageForm } from "./image-form";
|
||||||
|
import { useAlertStore } from "@/shared/lib/use-alert-store";
|
||||||
|
|
||||||
|
function ModifyPage({ serial }: { serial: string }) {
|
||||||
|
const router = useRouter();
|
||||||
|
const { setMessage: alert } = useAlertStore((state) => state);
|
||||||
|
|
||||||
|
const { data: imageDetail } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.IMAGES, serial],
|
||||||
|
queryFn: () => ImageApi.getImageInfo(serial),
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutateAsync: updateImage } = useMutation({
|
||||||
|
mutationFn: (data: ImageFormData) => ImageApi.updateImage(serial, data),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("수정되었습니다.");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutateAsync: deleteImage } = useMutation({
|
||||||
|
mutationFn: () => ImageApi.deleteImage(serial),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("삭제되었습니다.", router.back);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = useForm<ImageFormData>({
|
||||||
|
resolver: zodResolver(imageFormSchema),
|
||||||
|
values: imageDetail,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card card-border !mt-6">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">이미지 수정</h3>
|
||||||
|
</div>
|
||||||
|
<ImageForm
|
||||||
|
form={form}
|
||||||
|
imgSn={serial}
|
||||||
|
handleSave={updateImage}
|
||||||
|
handleDelete={deleteImage}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ModifyPage };
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import type {
|
||||||
|
ContentService,
|
||||||
|
ContentParams,
|
||||||
|
ContentList,
|
||||||
|
} from "../model/content-interface";
|
||||||
|
|
||||||
|
export class ContentApiService implements ContentService {
|
||||||
|
public async getContentList(params: ContentParams): Promise<ContentList> {
|
||||||
|
const response = await client.get<ContentList>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.CONTENTS}`,
|
||||||
|
{ params },
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ContentApi = new ContentApiService();
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import type {
|
||||||
|
Menu,
|
||||||
|
MenuFormData,
|
||||||
|
MenuService,
|
||||||
|
TreeMenu,
|
||||||
|
TreeNode,
|
||||||
|
} from "../model/menu-interface";
|
||||||
|
|
||||||
|
export class MenuApiService implements MenuService {
|
||||||
|
public async getMenuInfo(menuCd: number): Promise<Menu> {
|
||||||
|
const response = await client.get<Menu>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENUS}/${menuCd}`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createMenu(data: MenuFormData): Promise<void> {
|
||||||
|
const response = await client.post<void>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENUS}`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateMenu(
|
||||||
|
menuCd: number,
|
||||||
|
data: Omit<MenuFormData, "siteId">,
|
||||||
|
): Promise<void> {
|
||||||
|
const response = await client.put<void>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENUS}/${menuCd}`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteMenu(menuCd: number): Promise<void> {
|
||||||
|
const response = await client.delete<void>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENUS}/${menuCd}`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getTreeMenuList(siteId: string): Promise<TreeMenu[]> {
|
||||||
|
const response = await client.get<TreeMenu[]>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENUS}/${siteId}/tree`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateTreeMenu(siteId: string, data: TreeNode[]): Promise<void> {
|
||||||
|
const response = await client.put<void>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENUS}/${siteId}/tree`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateMenuName(menuCd: number, name: string): Promise<void> {
|
||||||
|
const response = await client.put<void>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENUS}/${menuCd}/${name}`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MenuApi = new MenuApiService();
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { client } from "@/shared/api";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import type {
|
||||||
|
Organization,
|
||||||
|
OrganizationService,
|
||||||
|
} from "../model/organization-interface";
|
||||||
|
|
||||||
|
export class OrganizationApiService implements OrganizationService {
|
||||||
|
public async getOrganizationUserTreeList(): Promise<Organization[]> {
|
||||||
|
const response = await client.get<Organization[]>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.USER_OGNZ}/treeuser`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const OrganizationApi = new OrganizationApiService();
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { MenuPage } from "./ui/menu-page";
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
import type { DropOptions, NodeModel } from "@minoru/react-dnd-treeview";
|
||||||
|
import type { TreeMenu, TreeNode } from "../model/menu-interface";
|
||||||
|
import type { Organization, User } from "../model/organization-interface";
|
||||||
|
|
||||||
|
export const generateMenuTreeData = (
|
||||||
|
data: TreeMenu[],
|
||||||
|
): NodeModel<TreeMenu>[] => {
|
||||||
|
return data.reduce<NodeModel<TreeMenu>[]>((acc, menu) => {
|
||||||
|
const node: NodeModel<TreeMenu> = {
|
||||||
|
id: menu.menuCd ?? 0,
|
||||||
|
parent: menu.parentId ?? 0,
|
||||||
|
text: menu.menuKornNm,
|
||||||
|
droppable: true,
|
||||||
|
data: menu,
|
||||||
|
};
|
||||||
|
|
||||||
|
acc.push(node);
|
||||||
|
|
||||||
|
if (menu.children?.length) {
|
||||||
|
acc.push(...generateMenuTreeData(menu.children));
|
||||||
|
}
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const generateNewMenuTreeData = (
|
||||||
|
treeData: NodeModel<TreeMenu>[],
|
||||||
|
options: DropOptions<TreeMenu>,
|
||||||
|
): TreeNode | null => {
|
||||||
|
const { dragSourceId, dragSource, dropTargetId, dropTarget } = options;
|
||||||
|
|
||||||
|
if (!dragSource?.data) return null;
|
||||||
|
|
||||||
|
const siblings = treeData.filter((node) => node.parent === dropTargetId);
|
||||||
|
|
||||||
|
const dragSourceIndex = siblings.findIndex(
|
||||||
|
(node) => node.id === dragSourceId,
|
||||||
|
);
|
||||||
|
|
||||||
|
const prevSibling = siblings[dragSourceIndex - 1];
|
||||||
|
|
||||||
|
const newSortSeq =
|
||||||
|
dragSourceIndex === 0 ? 1 : (prevSibling?.data?.sortSeq ?? 0) + 1;
|
||||||
|
|
||||||
|
const childNodes = treeData.filter(
|
||||||
|
(node) => node.parent === dragSourceId && node.data,
|
||||||
|
);
|
||||||
|
|
||||||
|
const baseNode = (node: NodeModel<TreeMenu>): TreeNode => {
|
||||||
|
if (!node.data) return {};
|
||||||
|
return {
|
||||||
|
menuCd: node.data?.menuCd,
|
||||||
|
name: node.data?.menuKornNm,
|
||||||
|
icon: node.data?.iconNm,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const treeNode: TreeNode = {
|
||||||
|
...baseNode(dragSource),
|
||||||
|
parentId: dropTargetId === 0 ? null : (dropTargetId as number),
|
||||||
|
sortSeq: newSortSeq,
|
||||||
|
levelNo: (dropTarget?.data?.levelNo ?? 0) + 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const result: TreeNode = {
|
||||||
|
...treeNode,
|
||||||
|
children: childNodes.map((child) => ({
|
||||||
|
...baseNode(child),
|
||||||
|
parentId: child.data?.parentId === 0 ? null : (dropTargetId as number),
|
||||||
|
sortSeq: child.data?.sortSeq,
|
||||||
|
levelNo: (treeNode?.levelNo ?? 0) + 1,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleSelectNode =
|
||||||
|
(callback: (node: NodeModel<TreeMenu>) => void) =>
|
||||||
|
(node: NodeModel<TreeMenu>) => {
|
||||||
|
callback(node);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleDropNode =
|
||||||
|
(callback: (newTree: TreeNode) => void) =>
|
||||||
|
(newTree: NodeModel<TreeMenu>[], options: DropOptions<TreeMenu>) => {
|
||||||
|
const newTreeData = generateNewMenuTreeData(newTree, options);
|
||||||
|
if (!newTreeData) return;
|
||||||
|
callback(newTreeData);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleNodeTextChange =
|
||||||
|
(treeData: NodeModel<TreeMenu>[]) =>
|
||||||
|
(callback: (newTree: NodeModel<TreeMenu>[]) => void) =>
|
||||||
|
(id: NodeModel["id"], value: string) => {
|
||||||
|
const newTree = treeData.map((node) => {
|
||||||
|
if (node.id === id) {
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
text: value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
});
|
||||||
|
callback(newTree);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const generateOrganizationTreeData = (
|
||||||
|
organizations: Organization[],
|
||||||
|
): NodeModel<Organization | User>[] => {
|
||||||
|
return organizations.reduce<NodeModel<Organization | User>[]>((acc, org) => {
|
||||||
|
const orgNode: NodeModel<Organization> = {
|
||||||
|
id: org.ognzId,
|
||||||
|
parent: org.upOgnzId ?? 0,
|
||||||
|
text: org.ognzNm,
|
||||||
|
data: org,
|
||||||
|
droppable: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
acc.push(orgNode);
|
||||||
|
|
||||||
|
if (org.children?.length) {
|
||||||
|
acc.push(...generateOrganizationTreeData(org.children));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (org.users?.length) {
|
||||||
|
acc.push(
|
||||||
|
...org.users.map((user) => ({
|
||||||
|
id: user.userUnqId,
|
||||||
|
parent: org.ognzId,
|
||||||
|
text: user.userNm,
|
||||||
|
data: user,
|
||||||
|
droppable: false,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const filterOrganizationTreeDataByKeyword = (
|
||||||
|
treeData: NodeModel<Organization | User>[],
|
||||||
|
keyword: string,
|
||||||
|
): NodeModel<Organization | User>[] => {
|
||||||
|
return Array.from(
|
||||||
|
treeData.reduce((matchedNodes, node) => {
|
||||||
|
if (!node.text.includes(keyword)) return matchedNodes;
|
||||||
|
|
||||||
|
matchedNodes.add(node);
|
||||||
|
|
||||||
|
let parentId = node.parent;
|
||||||
|
while (parentId) {
|
||||||
|
const parentNode = treeData.find((n) => n.id === parentId);
|
||||||
|
if (!parentNode) break;
|
||||||
|
matchedNodes.add(parentNode);
|
||||||
|
parentId = parentNode.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchedNodes;
|
||||||
|
}, new Set<NodeModel<Organization | User>>()),
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { createColumnHelper } from "@tanstack/react-table";
|
||||||
|
import { Checkbox } from "@common/components/ui";
|
||||||
|
import type { BoardPopup } from "@/entities/board";
|
||||||
|
|
||||||
|
const columnHelper = createColumnHelper<BoardPopup>();
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
columnHelper.accessor((_, index) => index + 1, {
|
||||||
|
id: "no",
|
||||||
|
header: "NO",
|
||||||
|
}),
|
||||||
|
columnHelper.accessor("bbsNm", {
|
||||||
|
id: "bbsNm",
|
||||||
|
header: "게시판명",
|
||||||
|
}),
|
||||||
|
columnHelper.accessor("bbsTypeNm", {
|
||||||
|
id: "bbsTypeNm",
|
||||||
|
header: "게시판유형",
|
||||||
|
}),
|
||||||
|
columnHelper.accessor("regDt", {
|
||||||
|
id: "regDt",
|
||||||
|
header: "최초생성일",
|
||||||
|
}),
|
||||||
|
columnHelper.accessor("pstCnt", {
|
||||||
|
id: "pstCnt",
|
||||||
|
header: "게시물건수",
|
||||||
|
}),
|
||||||
|
columnHelper.display({
|
||||||
|
id: "select",
|
||||||
|
header: "선택",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<Checkbox
|
||||||
|
checked={row.getIsSelected()}
|
||||||
|
onCheckedChange={row.getToggleSelectedHandler()}
|
||||||
|
className="mx-4 flex justify-center"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
export { columns };
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import type { PageableList, PageableParams } from "@/shared/model";
|
||||||
|
|
||||||
|
export interface ContentParams extends PageableParams {
|
||||||
|
contsTtl?: string;
|
||||||
|
aprvContsVer?: number;
|
||||||
|
useYn?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Content {
|
||||||
|
contsSn: number;
|
||||||
|
contsTtl: string;
|
||||||
|
aprvContsVer: number;
|
||||||
|
useYn: string;
|
||||||
|
rgtr: string;
|
||||||
|
regDt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ContentList = PageableList<Content>;
|
||||||
|
|
||||||
|
export interface ContentService {
|
||||||
|
getContentList(params: ContentParams): Promise<ContentList>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { createColumnHelper } from "@tanstack/react-table";
|
||||||
|
import { Checkbox } from "@common/components/ui";
|
||||||
|
import type { Content } from "./content-interface";
|
||||||
|
|
||||||
|
const columnHelper = createColumnHelper<Content>();
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
columnHelper.accessor((_, index) => index + 1, {
|
||||||
|
id: "no",
|
||||||
|
header: "NO",
|
||||||
|
}),
|
||||||
|
columnHelper.accessor("contsTtl", {
|
||||||
|
id: "contsTtl",
|
||||||
|
header: "콘텐츠명",
|
||||||
|
}),
|
||||||
|
// TODO: 최종수정자, 최종수정일, 승인일시 추가
|
||||||
|
columnHelper.display({
|
||||||
|
id: "select",
|
||||||
|
header: "선택",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<Checkbox
|
||||||
|
checked={row.getIsSelected()}
|
||||||
|
onCheckedChange={row.getToggleSelectedHandler()}
|
||||||
|
className="mx-4 flex justify-center"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
export { columns };
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const MENU_TYPE = {
|
||||||
|
EMPTY: "EMPTY",
|
||||||
|
CONTENTS: "CONTENTS",
|
||||||
|
BOARD: "BOARD",
|
||||||
|
INSIDE: "INSIDE",
|
||||||
|
OUTSIDE: "OUTSIDE",
|
||||||
|
BOTTOM: "BOTTOM",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type MenuType = (typeof MENU_TYPE)[keyof typeof MENU_TYPE];
|
||||||
|
|
||||||
|
export interface TreeNode {
|
||||||
|
menuCd?: number;
|
||||||
|
name?: string;
|
||||||
|
sortSeq?: number;
|
||||||
|
parentId?: number | null;
|
||||||
|
levelNo?: number;
|
||||||
|
icon?: string;
|
||||||
|
children?: TreeNode[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TreeMenu extends Omit<TreeNode, "name" | "icon" | "children"> {
|
||||||
|
menuKornNm: string;
|
||||||
|
menuEngNm?: string;
|
||||||
|
iconNm?: string;
|
||||||
|
children?: TreeMenu[];
|
||||||
|
urlPath?: string;
|
||||||
|
menuLnkgTypeCd: string;
|
||||||
|
menuLnkgSn?: number;
|
||||||
|
qrcd?: string;
|
||||||
|
useYn: string;
|
||||||
|
otptYn: string;
|
||||||
|
requiredUrlPath?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const menuFormSchema = z.object({
|
||||||
|
siteId: z.string(),
|
||||||
|
menuKornNm: z.string(),
|
||||||
|
menuSubKornNm: z.string().nullish(),
|
||||||
|
menuEngNm: z.string().nullish(),
|
||||||
|
menuSubEngNm: z.string().nullish(),
|
||||||
|
levelNo: z.number(),
|
||||||
|
urlPath: z.string().nullish(),
|
||||||
|
iconNm: z.string().nullish(),
|
||||||
|
menuLnkgTypeCd: z.enum([
|
||||||
|
MENU_TYPE.EMPTY,
|
||||||
|
MENU_TYPE.CONTENTS,
|
||||||
|
MENU_TYPE.BOARD,
|
||||||
|
MENU_TYPE.INSIDE,
|
||||||
|
MENU_TYPE.OUTSIDE,
|
||||||
|
MENU_TYPE.BOTTOM,
|
||||||
|
]),
|
||||||
|
menuLnkgSn: z.number().nullish(),
|
||||||
|
otptYn: z.string().default("Y"),
|
||||||
|
prntMenuCd: z.number().nullish(),
|
||||||
|
sortSeq: z.number(),
|
||||||
|
evlUseYn: z.string().default("Y"),
|
||||||
|
qrcd: z.string().nullish(),
|
||||||
|
useYn: z.string().default("Y"),
|
||||||
|
newWndwYn: z.string().nullish(),
|
||||||
|
menuLnkgSnNm: z.string().nullish(),
|
||||||
|
menuPicUserUnqId: z.string().nullish(),
|
||||||
|
menuPicUserUnqIdNm: z.string().nullish(),
|
||||||
|
menuPicDsgnYmd: z.string().nullish(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type MenuFormData = z.infer<typeof menuFormSchema>;
|
||||||
|
export type Menu = Omit<MenuFormData, "iconNm"> & {
|
||||||
|
menuCd: number;
|
||||||
|
iconName?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface MenuService {
|
||||||
|
getMenuInfo: (menuCd: number) => Promise<Menu>;
|
||||||
|
createMenu: (data: MenuFormData) => Promise<void>;
|
||||||
|
updateMenu: (
|
||||||
|
menuCd: number,
|
||||||
|
data: Omit<MenuFormData, "siteId">,
|
||||||
|
) => Promise<void>;
|
||||||
|
deleteMenu: (menuCd: number) => Promise<void>;
|
||||||
|
getTreeMenuList: (siteId: string) => Promise<TreeMenu[]>;
|
||||||
|
updateTreeMenu: (siteId: string, data: TreeNode[]) => Promise<void>;
|
||||||
|
updateMenuName: (menuCd: number, name: string) => Promise<void>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
export interface User {
|
||||||
|
userUnqId: string;
|
||||||
|
userNm: string;
|
||||||
|
jbpsSeCd: string;
|
||||||
|
jbgdSeCd: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Organization {
|
||||||
|
ognzId: string;
|
||||||
|
upOgnzId: string;
|
||||||
|
ognzNm: string;
|
||||||
|
users: User[];
|
||||||
|
children: Organization[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OrganizationService {
|
||||||
|
getOrganizationUserTreeList(): Promise<Organization[]>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
import { type UseFormReturn } from "react-hook-form";
|
||||||
|
import {
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
RadioGroup,
|
||||||
|
RadioGroupItem,
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableRow,
|
||||||
|
} from "@common/components";
|
||||||
|
import { FormItem, FormControl, FormField } from "@/shared/ui/form";
|
||||||
|
import { MENU_TYPE, type MenuFormData } from "../model/menu-interface";
|
||||||
|
|
||||||
|
interface BaseMenuFormProps {
|
||||||
|
form: UseFormReturn<MenuFormData>;
|
||||||
|
menuCd?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function BaseMenuForm({ form, menuCd }: BaseMenuFormProps) {
|
||||||
|
return (
|
||||||
|
<Table variant="secondary">
|
||||||
|
<colgroup>
|
||||||
|
<col width="20%" />
|
||||||
|
<col width="80%" />
|
||||||
|
</colgroup>
|
||||||
|
<TableBody>
|
||||||
|
{menuCd && (
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>메뉴ID</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<div className="h-[3.2rem] w-[21.5rem] cursor-not-allowed rounded-md border border-input bg-form px-3 py-2 text-[1.3rem] opacity-50">
|
||||||
|
{menuCd}
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>메뉴명</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="menuKornNm"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="메뉴명을 입력하십시오."
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>메뉴 영문명</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="menuEngNm"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
placeholder="메뉴 영문명을 입력하십시오."
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>메뉴 유형</TableHead>
|
||||||
|
<TableCell className="border">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="menuLnkgTypeCd"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<RadioGroup
|
||||||
|
value={field.value}
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
>
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
{Object.entries(MENU_TYPE).map(([key, value]) => (
|
||||||
|
<div
|
||||||
|
key={key}
|
||||||
|
className="flex items-center space-x-2"
|
||||||
|
>
|
||||||
|
<RadioGroupItem value={value} id={key} />
|
||||||
|
<Label htmlFor={key}>
|
||||||
|
{key === "EMPTY" && "빈메뉴"}
|
||||||
|
{key === "CONTENTS" && "콘텐츠"}
|
||||||
|
{key === "BOARD" && "게시판"}
|
||||||
|
{key === "INSIDE" && "내부링크"}
|
||||||
|
{key === "OUTSIDE" && "외부링크"}
|
||||||
|
{key === "BOTTOM" && "하단메뉴"}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</RadioGroup>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { BaseMenuForm };
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
getCoreRowModel,
|
||||||
|
useReactTable,
|
||||||
|
type RowSelectionState,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DataTable,
|
||||||
|
Dialog,
|
||||||
|
DialogTrigger,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
Input,
|
||||||
|
} from "@common/components/ui";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { BoardApi, type BoardPopup } from "@/entities/board";
|
||||||
|
import { columns } from "../model/board-table-columns";
|
||||||
|
|
||||||
|
type BoardSearchDialogProps = {
|
||||||
|
handleBoardSelect: (board: BoardPopup) => void;
|
||||||
|
} & React.ComponentProps<typeof Dialog>;
|
||||||
|
|
||||||
|
function BoardSearchDialog({
|
||||||
|
handleBoardSelect,
|
||||||
|
...props
|
||||||
|
}: BoardSearchDialogProps) {
|
||||||
|
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
||||||
|
const [bbsNm, setBbsNm] = useState("");
|
||||||
|
|
||||||
|
const { data: boardList, refetch } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.BOARD_SERVICE.BBS],
|
||||||
|
queryFn: () => BoardApi.getBoardPopupList({ bbsNm }),
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data: boardList?.content ?? [],
|
||||||
|
columns,
|
||||||
|
state: {
|
||||||
|
rowSelection,
|
||||||
|
},
|
||||||
|
enableMultiRowSelection: false,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const boardData = table.getSelectedRowModel().rows[0]
|
||||||
|
?.original as BoardPopup;
|
||||||
|
if (!boardData) return;
|
||||||
|
handleBoardSelect(boardData);
|
||||||
|
}, [table.getSelectedRowModel().rows]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refetch();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog {...props}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button className="gap-3">
|
||||||
|
<i className="diveicon di-search" />
|
||||||
|
조회
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent className="max-w-[60rem]" aria-describedby={undefined}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>게시판 조회</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<div className="card card-border !m-0 flex w-full items-center gap-2">
|
||||||
|
<Input
|
||||||
|
placeholder="검색어를 입력하세요."
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
value={bbsNm}
|
||||||
|
onChange={(e) => setBbsNm(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button onClick={() => refetch()}>
|
||||||
|
<i className="diveicon di-search" />
|
||||||
|
조회
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="h-[40rem] w-full overflow-y-auto">
|
||||||
|
<DataTable table={table} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { BoardSearchDialog };
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
getCoreRowModel,
|
||||||
|
useReactTable,
|
||||||
|
type RowSelectionState,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DataTable,
|
||||||
|
Dialog,
|
||||||
|
DialogTrigger,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
Input,
|
||||||
|
} from "@common/components/ui";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { ContentApi } from "../api/content-service";
|
||||||
|
import type { Content } from "../model/content-interface";
|
||||||
|
import { columns } from "../model/content-table-colums";
|
||||||
|
|
||||||
|
type ContentSearchDialogProps = {
|
||||||
|
handleContentSelect: (content: Content) => void;
|
||||||
|
} & React.ComponentProps<typeof Dialog>;
|
||||||
|
|
||||||
|
function ContentSearchDialog({
|
||||||
|
handleContentSelect,
|
||||||
|
...props
|
||||||
|
}: ContentSearchDialogProps) {
|
||||||
|
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
||||||
|
const [contsTtl, setContsTtl] = useState("");
|
||||||
|
|
||||||
|
const { data: contentList, refetch } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS],
|
||||||
|
queryFn: () =>
|
||||||
|
ContentApi.getContentList({ contsTtl, useYn: "Y", page: 0, size: 100 }),
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data: contentList?.content ?? [],
|
||||||
|
columns,
|
||||||
|
state: {
|
||||||
|
rowSelection,
|
||||||
|
},
|
||||||
|
enableMultiRowSelection: false,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const contentData = table.getSelectedRowModel().rows[0]
|
||||||
|
?.original as Content;
|
||||||
|
if (!contentData) return;
|
||||||
|
handleContentSelect(contentData);
|
||||||
|
}, [table.getSelectedRowModel().rows]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refetch();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog {...props}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button className="gap-3">
|
||||||
|
<i className="diveicon di-search" />
|
||||||
|
조회
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent className="max-w-[60rem]" aria-describedby={undefined}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>콘텐츠 조회</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<div className="card card-border !m-0 flex w-full items-center gap-2">
|
||||||
|
<Input
|
||||||
|
placeholder="검색어를 입력하세요."
|
||||||
|
className="!text-[1.3rem]"
|
||||||
|
value={contsTtl}
|
||||||
|
onChange={(e) => setContsTtl(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button onClick={() => refetch()}>
|
||||||
|
<i className="diveicon di-search" />
|
||||||
|
조회
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="h-[40rem] w-full overflow-y-auto">
|
||||||
|
<DataTable table={table} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ContentSearchDialog };
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import type { ComponentProps } from "react";
|
||||||
|
import { Button, Input } from "@common/components/ui";
|
||||||
|
|
||||||
|
type EditableNodeProps = {
|
||||||
|
depth?: number;
|
||||||
|
onSave: () => void;
|
||||||
|
onCancel: () => void;
|
||||||
|
} & ComponentProps<typeof Input>;
|
||||||
|
|
||||||
|
function EditableNode({
|
||||||
|
depth,
|
||||||
|
onSave,
|
||||||
|
onCancel,
|
||||||
|
...props
|
||||||
|
}: EditableNodeProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="flex items-center gap-2 rounded-sm bg-accent p-2"
|
||||||
|
style={{ marginInlineStart: !depth ? 0 : depth * 5 + 5 }}
|
||||||
|
>
|
||||||
|
<Input {...props} className="h-[2.5rem] !text-[1.3rem] text-foreground" />
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="size-8 !bg-transparent"
|
||||||
|
onClick={onSave}
|
||||||
|
>
|
||||||
|
<i className="diveicon di-check text-2xl" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="size-8 !bg-transparent"
|
||||||
|
onClick={onCancel}
|
||||||
|
>
|
||||||
|
<i className="diveicon di-x" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { EditableNode };
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import type { UseFormReturn } from "react-hook-form";
|
||||||
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||||
|
import { Button } from "@common/components";
|
||||||
|
import { Form } from "@/shared/ui/form";
|
||||||
|
import { ConfirmDialog } from "@/shared/ui/confirm-dialog";
|
||||||
|
import type { MenuFormData } from "../model/menu-interface";
|
||||||
|
import { BaseMenuForm } from "./base-menu-form";
|
||||||
|
import { TypeMenuForm } from "./type-menu-form";
|
||||||
|
import { PermissionsManagementDialog } from "./permissions-management-dialog";
|
||||||
|
|
||||||
|
interface MenuFormProps {
|
||||||
|
form: UseFormReturn<MenuFormData>;
|
||||||
|
menuCd?: number;
|
||||||
|
handleCreate: (data: MenuFormData) => void;
|
||||||
|
handleUpdate: ({
|
||||||
|
menuCd,
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
menuCd: number;
|
||||||
|
data: Omit<MenuFormData, "siteId">;
|
||||||
|
}) => void;
|
||||||
|
handleDelete?: (menuCd: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function MenuForm({
|
||||||
|
form,
|
||||||
|
menuCd,
|
||||||
|
handleCreate,
|
||||||
|
handleUpdate,
|
||||||
|
handleDelete,
|
||||||
|
}: MenuFormProps) {
|
||||||
|
const isModifyMode = !!menuCd;
|
||||||
|
|
||||||
|
const { confirm } = useConfirm();
|
||||||
|
const [onConfirm, setOnConfirm] = useState(false);
|
||||||
|
|
||||||
|
const handleConfirm = async (callback: () => Promise<void>) => {
|
||||||
|
setOnConfirm(true);
|
||||||
|
await callback();
|
||||||
|
setOnConfirm(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmit = async (data: MenuFormData) => {
|
||||||
|
if (isModifyMode) {
|
||||||
|
await onUpdate(data);
|
||||||
|
} else {
|
||||||
|
await onCreate(data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onCreate = async (data: MenuFormData) => {
|
||||||
|
await handleConfirm(async () => {
|
||||||
|
if (await confirm("저장하시겠습니까?")) {
|
||||||
|
handleCreate(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onUpdate = async (data: MenuFormData) => {
|
||||||
|
await handleConfirm(async () => {
|
||||||
|
if (await confirm("수정하시겠습니까?")) {
|
||||||
|
handleUpdate({ menuCd: menuCd!, data });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDelete = () => {
|
||||||
|
handleConfirm(async () => {
|
||||||
|
if (await confirm("삭제하시겠습니까?")) {
|
||||||
|
handleDelete?.(menuCd!);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const menuType = form.watch("menuLnkgTypeCd");
|
||||||
|
const isSubmitDisabled = !form.watch("siteId");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
|
<div className="card card-border">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="text-2xl font-medium text-label">
|
||||||
|
{isModifyMode ? "메뉴 수정" : "메뉴 등록"}
|
||||||
|
</h3>
|
||||||
|
<PermissionsManagementDialog menuCd={menuCd} />
|
||||||
|
</div>
|
||||||
|
<div className="card">
|
||||||
|
<BaseMenuForm form={form} menuCd={menuCd} />
|
||||||
|
<TypeMenuForm form={form} menuType={menuType} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-center gap-4 pb-12 pt-10">
|
||||||
|
<Button size="lg" type="submit" disabled={isSubmitDisabled}>
|
||||||
|
저장
|
||||||
|
</Button>
|
||||||
|
{isModifyMode && (
|
||||||
|
<Button size="lg" color="red" type="button" onClick={onDelete}>
|
||||||
|
삭제
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
<ConfirmDialog open={onConfirm} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { MenuForm };
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import type { NodeModel, TreeMethods } from "@minoru/react-dnd-treeview";
|
||||||
|
import { Button } from "@common/components/ui";
|
||||||
|
import { cn } from "@common/components/lib";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { MenuApi } from "../api/menu-service";
|
||||||
|
import type { TreeMenu } from "../model/menu-interface";
|
||||||
|
import { EditableNode } from "./editable-node";
|
||||||
|
|
||||||
|
type MenuNodeProps = {
|
||||||
|
node: NodeModel<TreeMenu>;
|
||||||
|
depth: number;
|
||||||
|
isOpen: boolean;
|
||||||
|
isSelected: boolean;
|
||||||
|
isAdditionalParent: boolean;
|
||||||
|
treeMethods: TreeMethods | null;
|
||||||
|
onToggle: (id: NodeModel["id"]) => void;
|
||||||
|
onSelect: (node: NodeModel<TreeMenu>) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
function MenuNode({
|
||||||
|
node,
|
||||||
|
depth,
|
||||||
|
isOpen,
|
||||||
|
isSelected,
|
||||||
|
isAdditionalParent,
|
||||||
|
treeMethods,
|
||||||
|
onToggle,
|
||||||
|
onSelect,
|
||||||
|
}: MenuNodeProps) {
|
||||||
|
const { id, text, data } = node;
|
||||||
|
const indent = depth * 10 + 5;
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const { mutateAsync: updateMenuName } = useMutation({
|
||||||
|
mutationFn: (nodeName: string) => {
|
||||||
|
const encodedName = encodeURIComponent(nodeName);
|
||||||
|
return MenuApi.updateMenuName(id as number, encodedName);
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const [editMode, setEditMode] = useState(false);
|
||||||
|
const [nodeName, setNodeName] = useState(text);
|
||||||
|
|
||||||
|
const handleToggle = () => onToggle(id);
|
||||||
|
const handleSelect = () => onSelect(node);
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
await updateMenuName(nodeName);
|
||||||
|
setEditMode(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancel = () => {
|
||||||
|
setEditMode(false);
|
||||||
|
setNodeName(text);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isAdditionalParent) treeMethods?.open(id);
|
||||||
|
}, [isAdditionalParent]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{ paddingInlineStart: indent }}
|
||||||
|
className={cn(
|
||||||
|
"group flex cursor-pointer items-center justify-between gap-2 rounded-sm p-2 hover:bg-accent",
|
||||||
|
isSelected && "!bg-[rgba(32,148,250,0.2)]",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{editMode ? (
|
||||||
|
<EditableNode
|
||||||
|
value={nodeName}
|
||||||
|
onChange={(e) => setNodeName(e.target.value)}
|
||||||
|
onSave={handleSave}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="flex items-center" onClick={handleSelect}>
|
||||||
|
{data?.children?.length && (
|
||||||
|
<i
|
||||||
|
className={cn(
|
||||||
|
"diveicon di-arrow-forward mr-2 text-base text-label",
|
||||||
|
isOpen && "rotate-90",
|
||||||
|
)}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
handleToggle();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<span className="text-[1.4rem] font-medium text-label">{text}</span>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="invisible !bg-transparent group-hover:visible"
|
||||||
|
onClick={() => setEditMode(true)}
|
||||||
|
>
|
||||||
|
<i className="diveicon di-pencil" />
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { MenuNode };
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import type { NodeModel } from "@minoru/react-dnd-treeview";
|
||||||
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@common/components/ui";
|
||||||
|
import { SiteApi } from "@/entities/site";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { ConfirmDialog } from "@/shared/ui/confirm-dialog";
|
||||||
|
import { useAlertStore } from "@/shared/lib/use-alert-store";
|
||||||
|
import type { TreeMenu } from "../model/menu-interface";
|
||||||
|
import { MenuApi } from "../api/menu-service";
|
||||||
|
import {
|
||||||
|
MENU_TYPE,
|
||||||
|
menuFormSchema,
|
||||||
|
type MenuFormData,
|
||||||
|
} from "../model/menu-interface";
|
||||||
|
import { MenuTree } from "./menu-tree";
|
||||||
|
import { MenuForm } from "./menu-form";
|
||||||
|
import { generateMenuTreeData } from "../lib/utils";
|
||||||
|
|
||||||
|
function MenuPage() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const { setMessage: alert } = useAlertStore((state) => state);
|
||||||
|
const { confirm } = useConfirm();
|
||||||
|
|
||||||
|
const [siteId, setSiteId] = useState("");
|
||||||
|
const [onConfirm, setOnConfirm] = useState(false);
|
||||||
|
const [selectedMenu, setSelectedMenu] = useState<TreeMenu | null>(null);
|
||||||
|
const [additionalNode, setAdditionalNode] =
|
||||||
|
useState<NodeModel<TreeMenu> | null>(null);
|
||||||
|
|
||||||
|
const { data: menuInfo } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS, selectedMenu?.menuCd],
|
||||||
|
queryFn: () => MenuApi.getMenuInfo(selectedMenu?.menuCd ?? 0),
|
||||||
|
enabled: !!selectedMenu?.menuCd,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: treeData } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS, siteId],
|
||||||
|
queryFn: () => MenuApi.getTreeMenuList(siteId),
|
||||||
|
select: (data) => {
|
||||||
|
const treeData = generateMenuTreeData(data);
|
||||||
|
const defaultSortSeq =
|
||||||
|
treeData.filter((node) => node.data?.levelNo === 1).length + 1;
|
||||||
|
form.setValue("sortSeq", defaultSortSeq);
|
||||||
|
|
||||||
|
return treeData;
|
||||||
|
},
|
||||||
|
enabled: !!siteId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: options } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.SITES],
|
||||||
|
queryFn: () => SiteApi.getSiteList({}),
|
||||||
|
select: (data) =>
|
||||||
|
data.content.map((site) => ({
|
||||||
|
label: site.siteNm,
|
||||||
|
value: site.siteId,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutateAsync: createMenu } = useMutation({
|
||||||
|
mutationFn: (data: MenuFormData) => MenuApi.createMenu(data),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("저장되었습니다.");
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS, siteId],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutate: updateMenu } = useMutation({
|
||||||
|
mutationFn: ({
|
||||||
|
menuCd,
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
menuCd: number;
|
||||||
|
data: Omit<MenuFormData, "siteId">;
|
||||||
|
}) => MenuApi.updateMenu(menuCd, data),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("수정되었습니다.");
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS, siteId],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutate: deleteMenu } = useMutation({
|
||||||
|
mutationFn: (menuCd: number) => MenuApi.deleteMenu(menuCd),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("삭제되었습니다.");
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS, siteId],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = useForm<MenuFormData>({
|
||||||
|
resolver: zodResolver(menuFormSchema),
|
||||||
|
defaultValues: {
|
||||||
|
menuLnkgTypeCd: MENU_TYPE.EMPTY,
|
||||||
|
},
|
||||||
|
values: {
|
||||||
|
...menuInfo,
|
||||||
|
siteId,
|
||||||
|
levelNo: menuInfo?.levelNo ?? 1,
|
||||||
|
sortSeq: menuInfo?.sortSeq ?? 1,
|
||||||
|
menuKornNm: menuInfo?.menuKornNm ?? "",
|
||||||
|
menuLnkgTypeCd: menuInfo?.menuLnkgTypeCd ?? MENU_TYPE.EMPTY,
|
||||||
|
iconNm: menuInfo?.iconName,
|
||||||
|
otptYn: menuInfo?.otptYn ?? "Y",
|
||||||
|
evlUseYn: menuInfo?.evlUseYn ?? "Y",
|
||||||
|
useYn: menuInfo?.useYn ?? "Y",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const additionalNodeForm = useForm<MenuFormData>({
|
||||||
|
resolver: zodResolver(menuFormSchema),
|
||||||
|
defaultValues: {
|
||||||
|
menuLnkgTypeCd: MENU_TYPE.EMPTY,
|
||||||
|
levelNo: 1,
|
||||||
|
sortSeq: 1,
|
||||||
|
otptYn: "Y",
|
||||||
|
evlUseYn: "Y",
|
||||||
|
useYn: "Y",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleAdditionalNodeSave = async () => {
|
||||||
|
const prntMenuCd = !additionalNode?.parent
|
||||||
|
? null
|
||||||
|
: (additionalNode?.parent as number);
|
||||||
|
|
||||||
|
await createMenu({
|
||||||
|
...additionalNodeForm.getValues(),
|
||||||
|
prntMenuCd,
|
||||||
|
});
|
||||||
|
resetAdditionalNode();
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetAdditionalNode = () => {
|
||||||
|
additionalNodeForm.setValue("menuKornNm", "");
|
||||||
|
setAdditionalNode(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSiteIdChange = (value: string) => {
|
||||||
|
form.setValue("siteId", value);
|
||||||
|
additionalNodeForm.setValue("siteId", value);
|
||||||
|
|
||||||
|
setSiteId(value);
|
||||||
|
setSelectedMenu(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNodeSelect = (node: NodeModel<TreeMenu>) => {
|
||||||
|
if (!node.data) return;
|
||||||
|
if (node.data.menuCd === selectedMenu?.menuCd) {
|
||||||
|
setSelectedMenu(null);
|
||||||
|
additionalNodeForm.setValue("levelNo", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSelectedMenu(node.data);
|
||||||
|
additionalNodeForm.setValue("levelNo", (node.data.levelNo ?? 0) + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNodeDelete = async () => {
|
||||||
|
setOnConfirm(true);
|
||||||
|
if (await confirm("삭제하시겠습니까?")) {
|
||||||
|
setOnConfirm(false);
|
||||||
|
deleteMenu(selectedMenu!.menuCd!);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAddMenu = () => {
|
||||||
|
if (additionalNode) return;
|
||||||
|
setAdditionalNode({
|
||||||
|
id: -1,
|
||||||
|
parent: selectedMenu?.menuCd ?? 0,
|
||||||
|
text: "",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const tree = additionalNode
|
||||||
|
? [...(additionalNode ? [additionalNode] : []), ...(treeData ?? [])]
|
||||||
|
: (treeData ?? []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="card !mb-0 flex !min-h-[calc(100vh-16.8rem)] gap-2">
|
||||||
|
<div className="card card-border w-[24rem]">
|
||||||
|
<Select value={siteId} onValueChange={handleSiteIdChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="선택하세요" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{options?.map((option) => (
|
||||||
|
<SelectItem key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
{siteId && (
|
||||||
|
<>
|
||||||
|
<div className="my-4 flex gap-2">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
className="flex-1"
|
||||||
|
onClick={handleAddMenu}
|
||||||
|
>
|
||||||
|
메뉴 추가
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="red"
|
||||||
|
className="flex-1"
|
||||||
|
onClick={handleNodeDelete}
|
||||||
|
disabled={!selectedMenu}
|
||||||
|
>
|
||||||
|
메뉴 삭제
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="card card-border !mx-0">
|
||||||
|
<MenuTree
|
||||||
|
tree={tree}
|
||||||
|
siteId={siteId}
|
||||||
|
selectedMenu={selectedMenu}
|
||||||
|
additionalNodeForm={additionalNodeForm}
|
||||||
|
onSelectNode={handleNodeSelect}
|
||||||
|
onAdditionalNodeSave={handleAdditionalNodeSave}
|
||||||
|
onAdditionalNodeCancel={resetAdditionalNode}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="card card-border flex-1">
|
||||||
|
<MenuForm
|
||||||
|
form={form}
|
||||||
|
menuCd={selectedMenu?.menuCd}
|
||||||
|
handleCreate={createMenu}
|
||||||
|
handleUpdate={updateMenu}
|
||||||
|
handleDelete={deleteMenu}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<ConfirmDialog open={onConfirm} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { MenuPage };
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRef } from "react";
|
||||||
|
import { DndProvider } from "react-dnd";
|
||||||
|
import type { UseFormReturn } from "react-hook-form";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
Tree,
|
||||||
|
MultiBackend,
|
||||||
|
getBackendOptions,
|
||||||
|
type NodeModel,
|
||||||
|
type TreeMethods,
|
||||||
|
} from "@minoru/react-dnd-treeview";
|
||||||
|
import { Button } from "@common/components/ui";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { MenuApi } from "../api/menu-service";
|
||||||
|
import type { MenuFormData, TreeMenu, TreeNode } from "../model/menu-interface";
|
||||||
|
import { handleDropNode, handleSelectNode } from "../lib/utils";
|
||||||
|
import { MenuNode } from "./menu-node";
|
||||||
|
import { EditableNode } from "./editable-node";
|
||||||
|
|
||||||
|
type MenuTreeProps = {
|
||||||
|
tree: NodeModel<TreeMenu>[];
|
||||||
|
siteId: string;
|
||||||
|
selectedMenu: TreeMenu | null;
|
||||||
|
additionalNodeForm: UseFormReturn<MenuFormData>;
|
||||||
|
onSelectNode: (node: NodeModel<TreeMenu>) => void;
|
||||||
|
onAdditionalNodeSave: () => void;
|
||||||
|
onAdditionalNodeCancel: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
function MenuTree({
|
||||||
|
tree,
|
||||||
|
siteId,
|
||||||
|
selectedMenu,
|
||||||
|
additionalNodeForm,
|
||||||
|
onSelectNode,
|
||||||
|
onAdditionalNodeSave,
|
||||||
|
onAdditionalNodeCancel,
|
||||||
|
}: MenuTreeProps) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const treeMethods = useRef<TreeMethods>(null);
|
||||||
|
|
||||||
|
const { mutate: updateTreeMenu } = useMutation({
|
||||||
|
mutationFn: (newTree: TreeNode) =>
|
||||||
|
MenuApi.updateTreeMenu(siteId, [newTree]),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const additionalNode = tree.find((n) => n.id === -1);
|
||||||
|
|
||||||
|
const isAdditionalParent = (node: NodeModel<TreeMenu>): boolean => {
|
||||||
|
if (!additionalNode) return false;
|
||||||
|
return additionalNode?.parent === node.id;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="max-h-[calc(100vh-33.5rem)] overflow-auto">
|
||||||
|
<DndProvider backend={MultiBackend} options={getBackendOptions()}>
|
||||||
|
<Tree
|
||||||
|
tree={tree}
|
||||||
|
rootId={0}
|
||||||
|
ref={treeMethods}
|
||||||
|
render={(
|
||||||
|
node: NodeModel<TreeMenu>,
|
||||||
|
{ depth, isOpen, onToggle },
|
||||||
|
) => {
|
||||||
|
if (node.id === -1) {
|
||||||
|
return (
|
||||||
|
<EditableNode
|
||||||
|
value={additionalNodeForm.watch("menuKornNm") ?? ""}
|
||||||
|
onChange={(e) =>
|
||||||
|
additionalNodeForm.setValue("menuKornNm", e.target.value)
|
||||||
|
}
|
||||||
|
depth={depth}
|
||||||
|
onSave={onAdditionalNodeSave}
|
||||||
|
onCancel={onAdditionalNodeCancel}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<MenuNode
|
||||||
|
node={node}
|
||||||
|
depth={depth}
|
||||||
|
treeMethods={treeMethods.current}
|
||||||
|
isOpen={isOpen}
|
||||||
|
isSelected={selectedMenu?.menuCd === node.id}
|
||||||
|
isAdditionalParent={isAdditionalParent(node)}
|
||||||
|
onToggle={onToggle}
|
||||||
|
onSelect={handleSelectNode(onSelectNode)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
onDrop={handleDropNode(updateTreeMenu)}
|
||||||
|
classes={{
|
||||||
|
root: "p-4",
|
||||||
|
container: "flex flex-col",
|
||||||
|
dropTarget: "!bg-[rgba(32,148,250,0.5)] rounded-sm",
|
||||||
|
placeholder: "relative",
|
||||||
|
}}
|
||||||
|
sort={false}
|
||||||
|
dropTargetOffset={5}
|
||||||
|
insertDroppableFirst={false}
|
||||||
|
canDrop={(_, { dragSource, dropTargetId }) => {
|
||||||
|
if (dragSource?.parent === dropTargetId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
placeholderRender={(_, { depth }) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="absolute right-0 top-0 h-[0.2rem] bg-primary"
|
||||||
|
style={{ left: depth * 10 + 5 }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</DndProvider>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button
|
||||||
|
color="lightGray"
|
||||||
|
className="flex-1 items-center px-0"
|
||||||
|
onClick={() => {
|
||||||
|
treeMethods.current?.openAll();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<i className="diveicon di-arrows-angle-expand" />
|
||||||
|
전체펼침
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="lightGray"
|
||||||
|
className="flex-1 items-center px-0"
|
||||||
|
onClick={() => {
|
||||||
|
treeMethods.current?.closeAll();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<i className="diveicon di-arrows-angle-contract" />
|
||||||
|
전체접기
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { MenuTree };
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { DndProvider } from "react-dnd";
|
||||||
|
import {
|
||||||
|
Tree,
|
||||||
|
MultiBackend,
|
||||||
|
getBackendOptions,
|
||||||
|
type NodeModel,
|
||||||
|
} from "@minoru/react-dnd-treeview";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
Input,
|
||||||
|
} from "@common/components/ui";
|
||||||
|
import { cn } from "@common/components/lib";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { OrganizationApi } from "../api/organization-service";
|
||||||
|
import type { Organization, User } from "../model/organization-interface";
|
||||||
|
import {
|
||||||
|
filterOrganizationTreeDataByKeyword,
|
||||||
|
generateOrganizationTreeData,
|
||||||
|
} from "../lib/utils";
|
||||||
|
|
||||||
|
type TreeModel = Organization | User;
|
||||||
|
|
||||||
|
interface OrganizationSearchDialogProps {
|
||||||
|
handleUserSelect: (user: User) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function OrganizationSearchDialog({
|
||||||
|
handleUserSelect,
|
||||||
|
}: OrganizationSearchDialogProps) {
|
||||||
|
const [keyword, setKeyword] = useState("");
|
||||||
|
const [tree, setTree] = useState<NodeModel<TreeModel>[]>([]);
|
||||||
|
const [selectedNode, setSelectedNode] = useState<NodeModel<TreeModel> | null>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
const { data: treeData } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.USER_OGNZ],
|
||||||
|
queryFn: () => OrganizationApi.getOrganizationUserTreeList(),
|
||||||
|
select: (data) => generateOrganizationTreeData(data),
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSelectNode = (node: NodeModel<TreeModel>) => {
|
||||||
|
setSelectedNode(node);
|
||||||
|
handleUserSelect(node.data as User);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTree(treeData ?? []);
|
||||||
|
}, [treeData]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button className="gap-3">
|
||||||
|
<i className="diveicon di-search" />
|
||||||
|
조회
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent className="max-w-[30rem]" aria-describedby={undefined}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>담당자 조회</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<div className="card card-border !m-0 flex w-full items-center gap-2">
|
||||||
|
<Input
|
||||||
|
className="h-[2.5rem] !text-[1.3rem]"
|
||||||
|
value={keyword}
|
||||||
|
onChange={(e) => setKeyword(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() =>
|
||||||
|
setTree(filterOrganizationTreeDataByKeyword(tree, keyword))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<i className="diveicon di-search text-base" />
|
||||||
|
조회
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="h-[36rem] overflow-auto">
|
||||||
|
<DndProvider backend={MultiBackend} options={getBackendOptions()}>
|
||||||
|
<Tree
|
||||||
|
tree={tree}
|
||||||
|
rootId={0}
|
||||||
|
render={(
|
||||||
|
node: NodeModel<TreeModel>,
|
||||||
|
{ depth, isOpen, onToggle },
|
||||||
|
) => (
|
||||||
|
<TreeNode
|
||||||
|
node={node}
|
||||||
|
depth={depth}
|
||||||
|
isOpen={isOpen}
|
||||||
|
selectedNode={selectedNode}
|
||||||
|
onToggle={onToggle}
|
||||||
|
onSelect={handleSelectNode}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
classes={{
|
||||||
|
container: "flex flex-col",
|
||||||
|
}}
|
||||||
|
sort={false}
|
||||||
|
onDrop={() => {}}
|
||||||
|
/>
|
||||||
|
</DndProvider>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TreeNodeProps {
|
||||||
|
node: NodeModel<TreeModel>;
|
||||||
|
depth: number;
|
||||||
|
isOpen: boolean;
|
||||||
|
selectedNode: NodeModel<TreeModel> | null;
|
||||||
|
onToggle: (id: NodeModel["id"]) => void;
|
||||||
|
onSelect: (node: NodeModel<TreeModel>) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ORGANIZATION_PREFIX = "OGNZ";
|
||||||
|
|
||||||
|
function TreeNode({
|
||||||
|
node,
|
||||||
|
depth,
|
||||||
|
isOpen,
|
||||||
|
selectedNode,
|
||||||
|
onToggle,
|
||||||
|
onSelect,
|
||||||
|
}: TreeNodeProps) {
|
||||||
|
const { id, text, data } = node;
|
||||||
|
const indent = depth * 15 + 5;
|
||||||
|
|
||||||
|
const handleToggle = () => onToggle(id);
|
||||||
|
const handleSelect = () => {
|
||||||
|
if (id.toString().startsWith(ORGANIZATION_PREFIX)) return;
|
||||||
|
onSelect(node);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isSelected = selectedNode?.id === id;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{ paddingInlineStart: indent }}
|
||||||
|
className="group flex cursor-pointer items-center justify-between gap-2 rounded-sm p-2 hover:bg-accent"
|
||||||
|
onClick={handleSelect}
|
||||||
|
>
|
||||||
|
<div className="flex w-full items-center justify-between">
|
||||||
|
<div>
|
||||||
|
{data && ("children" in data || "users" in data) && (
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
className="h-6 w-6 !bg-transparent"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
handleToggle();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
className={cn(
|
||||||
|
"diveicon di-arrow-forward mr-2 text-base text-label",
|
||||||
|
isOpen && "rotate-90",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<span className="text-[1.4rem] font-medium text-label">{text}</span>
|
||||||
|
</div>
|
||||||
|
{isSelected && <i className="diveicon di-check text-xl text-primary" />}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { OrganizationSearchDialog };
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user