@uniai-fe/uds-templates 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/cctv/apis/client.ts +4 -13
- package/src/cctv/apis/server.ts +13 -23
- package/src/cctv/hooks/useCompanyData.tsx +16 -15
- package/src/cctv/types/api.ts +30 -12
- package/src/cctv/types/hook.ts +1 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniai-fe/uds-templates",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "UNIAI Design System; UI Templates Package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
|
-
"packageManager": "pnpm@10.33.
|
|
15
|
+
"packageManager": "pnpm@10.33.2",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=24",
|
|
18
18
|
"pnpm": ">=10"
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@svgr/webpack": "^8.1.0",
|
|
73
|
-
"@tanstack/react-query": "^5.
|
|
73
|
+
"@tanstack/react-query": "^5.100.1",
|
|
74
74
|
"@types/node": "^24.10.2",
|
|
75
75
|
"@types/react": "^19.2.14",
|
|
76
76
|
"@types/react-dom": "^19.2.3",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"jotai": "^2.19.1",
|
|
90
90
|
"next": "^15.5.11",
|
|
91
91
|
"prettier": "^3.8.3",
|
|
92
|
-
"react-hook-form": "^7.
|
|
92
|
+
"react-hook-form": "^7.73.1",
|
|
93
93
|
"sass": "^1.99.0",
|
|
94
94
|
"typescript": "5.9.3"
|
|
95
95
|
}
|
package/src/cctv/apis/client.ts
CHANGED
|
@@ -6,31 +6,22 @@ import type {
|
|
|
6
6
|
API_Res_CctvCompany,
|
|
7
7
|
API_Res_CctvRtcToken,
|
|
8
8
|
} from "../types";
|
|
9
|
-
import { getQueryString } from "@uniai-fe/util-functions";
|
|
10
9
|
|
|
11
10
|
export const getClientCctvCompanyList = async ({
|
|
12
|
-
username,
|
|
13
11
|
url,
|
|
14
12
|
}: {
|
|
15
|
-
username: string;
|
|
16
13
|
url?: string;
|
|
17
|
-
}) =>
|
|
18
|
-
await (
|
|
19
|
-
await fetch(
|
|
20
|
-
`${url ?? "/api/cctv/company-list"}${getQueryString({ username })}`,
|
|
21
|
-
)
|
|
22
|
-
).json();
|
|
14
|
+
}): Promise<API_Res_CctvCompany> =>
|
|
15
|
+
await (await fetch(url ?? "/api/cctv/company-list")).json();
|
|
23
16
|
|
|
24
17
|
export const useQueryCctvCompanyList = ({
|
|
25
|
-
username,
|
|
26
18
|
url,
|
|
27
19
|
}: {
|
|
28
|
-
username: string;
|
|
29
20
|
url?: string;
|
|
30
21
|
}): UseQueryResult<API_Res_CctvCompany> =>
|
|
31
22
|
useQuery({
|
|
32
|
-
queryKey: ["cctv_company_list",
|
|
33
|
-
queryFn: () => getClientCctvCompanyList({
|
|
23
|
+
queryKey: ["cctv_company_list", url],
|
|
24
|
+
queryFn: () => getClientCctvCompanyList({ url }),
|
|
34
25
|
});
|
|
35
26
|
|
|
36
27
|
export const postCctvRtcToken = async ({
|
package/src/cctv/apis/server.ts
CHANGED
|
@@ -132,46 +132,39 @@ export function classifyGroups(
|
|
|
132
132
|
/**
|
|
133
133
|
* CCTV; company-list API route.ts 로직
|
|
134
134
|
* @api
|
|
135
|
-
* @route /
|
|
135
|
+
* @route /common/cctvs/{me|all}
|
|
136
136
|
* @param {API_Req_GetCompanyListParams} params
|
|
137
137
|
* @property {string} domain API 요청 도메인(서버)
|
|
138
138
|
* @property {string} routeUrl Next.js app/api 이하 경로 url
|
|
139
139
|
* @property {string} [queryUrl] 백엔드 요청 url
|
|
140
|
-
* @property {
|
|
140
|
+
* @property {"me" | "all"} [scope] common/cctvs 조회 범위
|
|
141
141
|
*/
|
|
142
142
|
export async function getServerCompanyList({
|
|
143
143
|
domain,
|
|
144
144
|
routeUrl,
|
|
145
145
|
queryUrl,
|
|
146
|
-
|
|
146
|
+
scope = "me",
|
|
147
147
|
}: API_Req_GetCompanyListParams): Promise<{
|
|
148
148
|
res: API_Res_CctvCompany;
|
|
149
149
|
domain: string;
|
|
150
150
|
queryUrl: string;
|
|
151
151
|
options?: ResponseInit;
|
|
152
152
|
}> {
|
|
153
|
-
const
|
|
154
|
-
const query_url = queryUrl || `/v1/users/${username}/cctvs`;
|
|
153
|
+
const query_url = queryUrl || `/common/cctvs/${scope}`;
|
|
155
154
|
|
|
156
|
-
const alternateResponse = {
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
const alternateResponse: API_Res_CctvCompany = {
|
|
156
|
+
status: "error",
|
|
157
|
+
data: {
|
|
158
|
+
items: [],
|
|
159
|
+
total_count: 0,
|
|
160
|
+
},
|
|
161
|
+
errors: [],
|
|
159
162
|
};
|
|
160
163
|
const API_OPTION = {
|
|
161
164
|
domain,
|
|
162
165
|
queryUrl: query_url,
|
|
163
|
-
// searchParams,
|
|
164
166
|
};
|
|
165
167
|
|
|
166
|
-
if (!queryUrl && !username) {
|
|
167
|
-
nextAPILog("GET", routeUrl, query_url, { searchParams });
|
|
168
|
-
return {
|
|
169
|
-
res: alternateResponse,
|
|
170
|
-
...API_OPTION,
|
|
171
|
-
options: { status: 400, statusText: "유저 아이디를 확인할 수 없습니다." },
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
168
|
// 요청 URL 구성
|
|
176
169
|
const url = generateQueryUrl({
|
|
177
170
|
routeUrl,
|
|
@@ -181,12 +174,9 @@ export async function getServerCompanyList({
|
|
|
181
174
|
try {
|
|
182
175
|
const originRes: API_Res_CctvCompany = await (await fetch(url)).json();
|
|
183
176
|
|
|
184
|
-
//
|
|
185
|
-
const originGroups = originRes?.data || [];
|
|
186
|
-
const resGourps = classifyGroups(originGroups);
|
|
187
|
-
|
|
177
|
+
// 변경: server helper는 common/cctvs raw 응답을 유지하고 template 변환은 hook에서 처리한다.
|
|
188
178
|
return {
|
|
189
|
-
res:
|
|
179
|
+
res: originRes,
|
|
190
180
|
...API_OPTION,
|
|
191
181
|
};
|
|
192
182
|
} catch (err) {
|
|
@@ -1,47 +1,48 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useEffect, useMemo } from "react";
|
|
4
|
-
import { useQueryCctvCompanyList } from "../apis";
|
|
4
|
+
import { classifyGroups, useQueryCctvCompanyList } from "../apis";
|
|
5
5
|
import { useCctvApiUrl } from "../components/Provider";
|
|
6
6
|
import useCctvContext from "./useContext";
|
|
7
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
UseCctvCompanyDataParams,
|
|
9
|
+
UseCctvCompanyDataReturn,
|
|
10
|
+
} from "../types";
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* CCTV 회사 리스트 API를 호출해 데이터를 가져오는 훅.
|
|
11
14
|
* @hook
|
|
12
15
|
* @param {UseCctvCompanyDataParams} [params] 훅 파라미터
|
|
13
|
-
* @property {string} [username] 사용자 계정 아이디 (Provider에서 주입된 기본값 대신 사용)
|
|
14
16
|
* @property {string} [url] 회사 리스트 API URL (Provider에서 주입된 기본값 대신 사용)
|
|
15
17
|
* @return {UseCctvCompanyDataReturn} 회사 리스트 쿼리 반환값
|
|
16
18
|
* @desc
|
|
17
19
|
* return {
|
|
18
|
-
* data, //
|
|
20
|
+
* data, // common/cctvs 원본 API 응답 데이터
|
|
19
21
|
* isFetching, // 데이터 로딩 중 상태
|
|
20
22
|
* isError, // 데이터 로딩 에러 상태
|
|
21
23
|
* ...rest, // react-query useQuery 반환값
|
|
22
24
|
* }
|
|
23
25
|
*/
|
|
24
|
-
export default function useCctvCompanyData(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const { username, url } = params || {};
|
|
26
|
+
export default function useCctvCompanyData(
|
|
27
|
+
params?: UseCctvCompanyDataParams,
|
|
28
|
+
): UseCctvCompanyDataReturn {
|
|
29
|
+
// 변경: list 조회 계약은 URL만 override 대상으로 유지한다.
|
|
30
|
+
const { url } = params || {};
|
|
30
31
|
|
|
31
32
|
const { listUrl } = useCctvApiUrl();
|
|
32
33
|
const resolvedUrl = useMemo(() => url ?? listUrl, [url, listUrl]);
|
|
33
|
-
const {
|
|
34
|
+
const { setValue } = useCctvContext();
|
|
34
35
|
|
|
35
|
-
//
|
|
36
|
+
// URL에 맞춰 회사 리스트 API를 호출한다.
|
|
36
37
|
const { data, isFetching, isError, ...rest } = useQueryCctvCompanyList({
|
|
37
|
-
username: username ?? contextUsername,
|
|
38
38
|
url: resolvedUrl,
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
// 응답 데이터를 react-hook-form rawData 필드로 반영한다.
|
|
42
42
|
useEffect(() => {
|
|
43
|
-
if (data?.data) {
|
|
44
|
-
|
|
43
|
+
if (data?.data?.items) {
|
|
44
|
+
// 변경: common/cctvs raw items를 template form data 계약에 맞게 재분류한다.
|
|
45
|
+
setValue("rawData", classifyGroups(data.data.items));
|
|
45
46
|
}
|
|
46
47
|
}, [data, setValue]);
|
|
47
48
|
|
package/src/cctv/types/api.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { API_Res_Base } from "@uniai-fe/util-api";
|
|
1
2
|
import type { UtilQueryBaseParams } from "@uniai-fe/util-functions";
|
|
2
3
|
import type { NextRequest } from "next/server";
|
|
3
4
|
|
|
@@ -6,20 +7,25 @@ import type { NextRequest } from "next/server";
|
|
|
6
7
|
* @property {string} domain API 요청 도메인(서버)
|
|
7
8
|
* @property {string} routeUrl Next.js app/api 이하 경로 url
|
|
8
9
|
* @property {string} [queryUrl] 백엔드 요청 url
|
|
9
|
-
* @property {
|
|
10
|
+
* @property {"me" | "all"} [scope] common/cctvs 조회 범위
|
|
10
11
|
*/
|
|
11
|
-
export interface API_Req_GetCompanyListParams
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export interface API_Req_GetCompanyListParams {
|
|
13
|
+
/**
|
|
14
|
+
* API 도메인
|
|
15
|
+
*/
|
|
16
|
+
domain: string;
|
|
17
|
+
/**
|
|
18
|
+
* Next.js app/api 이하 경로 url
|
|
19
|
+
*/
|
|
20
|
+
routeUrl: string;
|
|
15
21
|
/**
|
|
16
22
|
* 백엔드 요청 url
|
|
17
23
|
*/
|
|
18
24
|
queryUrl?: string;
|
|
19
25
|
/**
|
|
20
|
-
*
|
|
26
|
+
* common/cctvs 조회 범위
|
|
21
27
|
*/
|
|
22
|
-
|
|
28
|
+
scope?: "me" | "all";
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
/**
|
|
@@ -115,15 +121,27 @@ export interface API_Res_CctvCompanyGroup {
|
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
/**
|
|
118
|
-
* CCTV;
|
|
119
|
-
* @property {API_Res_CctvCompanyGroup[]}
|
|
120
|
-
* @property {number} total_count
|
|
124
|
+
* CCTV; common/cctvs 원본 응답 데이터
|
|
125
|
+
* @property {API_Res_CctvCompanyGroup[]} items 백엔드 원본 업체 그룹 목록
|
|
126
|
+
* @property {number} total_count 전체 업체 그룹 수
|
|
121
127
|
*/
|
|
122
|
-
export interface
|
|
123
|
-
|
|
128
|
+
export interface API_Res_CctvCompanyData {
|
|
129
|
+
/**
|
|
130
|
+
* 백엔드 원본 업체 그룹 목록
|
|
131
|
+
*/
|
|
132
|
+
items: API_Res_CctvCompanyGroup[];
|
|
133
|
+
/**
|
|
134
|
+
* 전체 업체 그룹 수
|
|
135
|
+
*/
|
|
124
136
|
total_count: number;
|
|
125
137
|
}
|
|
126
138
|
|
|
139
|
+
/**
|
|
140
|
+
* CCTV; common/cctvs 원본 응답
|
|
141
|
+
* @typedef {API_Res_Base<API_Res_CctvCompanyData>} API_Res_CctvCompany
|
|
142
|
+
*/
|
|
143
|
+
export type API_Res_CctvCompany = API_Res_Base<API_Res_CctvCompanyData>;
|
|
144
|
+
|
|
127
145
|
/**
|
|
128
146
|
* CCTV; 실시간 스트리밍 토큰 요청 (Next.js API 요청)
|
|
129
147
|
* @property {string} company_id 업체 id코드
|
package/src/cctv/types/hook.ts
CHANGED
|
@@ -92,14 +92,9 @@ export interface UseCctvRtcStreamReturn extends UseCctvRtcStreamState {
|
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* CCTV; useCctvCompanyData params
|
|
95
|
-
* @property {string} [username] 사용자 계정 아이디
|
|
96
95
|
* @property {string} [url] 업체 리스트 API URL
|
|
97
96
|
*/
|
|
98
97
|
export interface UseCctvCompanyDataParams {
|
|
99
|
-
/**
|
|
100
|
-
* 사용자 계정 아이디
|
|
101
|
-
*/
|
|
102
|
-
username?: string;
|
|
103
98
|
/**
|
|
104
99
|
* 업체 리스트 API URL
|
|
105
100
|
*/
|
|
@@ -108,7 +103,7 @@ export interface UseCctvCompanyDataParams {
|
|
|
108
103
|
|
|
109
104
|
/**
|
|
110
105
|
* CCTV; useCctvCompanyData return
|
|
111
|
-
* @property {API_Res_CctvCompany | undefined} data
|
|
106
|
+
* @property {API_Res_CctvCompany | undefined} data common/cctvs 원본 API 응답 데이터
|
|
112
107
|
* @property {boolean} isFetching 데이터 로딩 중 상태
|
|
113
108
|
* @property {boolean} isError 데이터 로딩 에러 상태
|
|
114
109
|
*/
|