@uniai-fe/uds-templates 0.1.20 → 0.1.21
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/dist/styles.css +2 -2
- package/package.json +7 -3
- package/src/auth/login/jotai/user.ts +13 -0
- package/src/auth/login/types/api.ts +229 -0
- package/src/auth/login/types/form.ts +1 -0
- package/src/auth/login/types/index.ts +4 -0
- package/src/auth/signup/markup/VerificationForm.tsx +3 -2
- package/src/cctv/apis/client.ts +61 -0
- package/src/cctv/apis/index.ts +2 -0
- package/src/cctv/apis/server.ts +188 -0
- package/src/cctv/components/Provider.tsx +47 -0
- package/src/cctv/components/__viewer.tsx +99 -0
- package/src/cctv/components/cam-list/Container.tsx +36 -0
- package/src/cctv/components/cam-list/Item.tsx +71 -0
- package/src/cctv/components/cam-list/index.tsx +7 -0
- package/src/cctv/components/index.tsx +13 -0
- package/src/cctv/components/pagination/Container.tsx +26 -0
- package/src/cctv/components/pagination/Control.tsx +29 -0
- package/src/cctv/components/pagination/Provider.tsx +204 -0
- package/src/cctv/components/pagination/buttons/Base.tsx +56 -0
- package/src/cctv/components/pagination/buttons/Next.tsx +34 -0
- package/src/cctv/components/pagination/buttons/Prev.tsx +34 -0
- package/src/cctv/components/pagination/index.tsx +25 -0
- package/src/cctv/components/pagination/list/Carousel.tsx +26 -0
- package/src/cctv/components/pagination/list/Container.tsx +30 -0
- package/src/cctv/components/pagination/list/Item.tsx +81 -0
- package/src/cctv/components/video/Container.tsx +13 -0
- package/src/cctv/components/video/Video.tsx +34 -0
- package/src/cctv/components/video/index.tsx +9 -0
- package/src/cctv/components/video/overlay/Container.tsx +15 -0
- package/src/cctv/components/video/overlay/Title.tsx +28 -0
- package/src/cctv/components/video/overlay/body/Container.tsx +13 -0
- package/src/cctv/components/video/overlay/body/Error.tsx +16 -0
- package/src/cctv/components/video/overlay/footer/Container.tsx +30 -0
- package/src/cctv/components/video/overlay/footer/OpenButton.tsx +19 -0
- package/src/cctv/components/video/overlay/header/CloseButton.tsx +14 -0
- package/src/cctv/components/video/overlay/header/Container.tsx +50 -0
- package/src/cctv/components/video/overlay/header/LiveState.tsx +21 -0
- package/src/cctv/components/video/overlay/index.tsx +24 -0
- package/src/cctv/components/viewer/Container.tsx +13 -0
- package/src/cctv/components/viewer/desktop/Container.tsx +38 -0
- package/src/cctv/components/viewer/desktop/Pagination.tsx +20 -0
- package/src/cctv/components/viewer/desktop/Placeholder.tsx +18 -0
- package/src/cctv/components/viewer/desktop/Video.tsx +83 -0
- package/src/cctv/components/viewer/index.tsx +12 -0
- package/src/cctv/components/viewer/mobile/Container.tsx +13 -0
- package/src/cctv/data/context.ts +22 -0
- package/src/cctv/data/index.ts +1 -0
- package/src/cctv/hooks/index.tsx +5 -0
- package/src/cctv/hooks/useCompanyData.tsx +39 -0
- package/src/cctv/hooks/useContext.ts +150 -0
- package/src/cctv/hooks/useRtcStream.ts +94 -0
- package/src/cctv/img/chevron-left.svg +3 -0
- package/src/cctv/img/chevron-right.svg +3 -0
- package/src/cctv/img/error.svg +4 -0
- package/src/cctv/img/viewer-close.svg +3 -0
- package/src/cctv/img/viewer-open.svg +6 -0
- package/src/cctv/index.scss +1 -0
- package/src/cctv/index.tsx +9 -0
- package/src/cctv/jotai/context.ts +9 -0
- package/src/cctv/jotai/index.ts +1 -0
- package/src/cctv/styles/cam-list.scss +32 -0
- package/src/cctv/styles/index.scss +5 -0
- package/src/cctv/styles/pagination.scss +77 -0
- package/src/cctv/styles/variables.scss +38 -0
- package/src/cctv/styles/video.scss +142 -0
- package/src/cctv/styles/viewer.scss +7 -0
- package/src/cctv/types/api.ts +166 -0
- package/src/cctv/types/carousel.ts +24 -0
- package/src/cctv/types/context.ts +68 -0
- package/src/cctv/types/index.ts +4 -0
- package/src/cctv/types/list.ts +94 -0
- package/src/cctv/utils/data.ts +40 -0
- package/src/cctv/utils/select.ts +62 -0
- package/src/index.tsx +3 -0
- package/src/modal/styles/base.scss +2 -2
- package/src/types/api.ts +43 -0
- package/src/types/index.ts +1 -0
- package/src/auth/login/types.ts +0 -2
package/dist/styles.css
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
--modal-panel-width: 360px;
|
|
20
20
|
--modal-panel-max-width: calc(100vw - var(--spacing-padding-10, 32px) * 2);
|
|
21
21
|
--modal-panel-max-height: calc(100vh - var(--spacing-padding-10, 32px) * 2);
|
|
22
|
-
--modal-panel-bg: var(--color-
|
|
22
|
+
--modal-panel-bg: var(--color-surface-static-white);
|
|
23
23
|
--modal-panel-radius: var(--theme-radius-large-1);
|
|
24
24
|
--modal-panel-shadow: 0px 18px 40px rgba(8, 11, 30, 0.18);
|
|
25
25
|
--modal-border-color: var(--color-border-standard-cool-gray, #e4e5e7);
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
width: 100%;
|
|
170
170
|
max-width: min(var(--modal-panel-width, 360px), var(--modal-panel-max-width, calc(100vw - var(--spacing-padding-10, 32px) * 2)));
|
|
171
171
|
max-height: var(--modal-panel-max-height, calc(100vh - var(--spacing-padding-10, 32px) * 2));
|
|
172
|
-
background-color: var(--modal-panel-bg, var(--color-
|
|
172
|
+
background-color: var(--modal-panel-bg, var(--color-surface-static-white));
|
|
173
173
|
border-radius: var(--modal-panel-radius, var(--theme-radius-large-1));
|
|
174
174
|
box-shadow: var(--modal-panel-shadow, 0px 18px 40px rgba(8, 11, 30, 0.18));
|
|
175
175
|
pointer-events: auto;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniai-fe/uds-templates",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "UNIAI Design System; UI Templates Package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -48,11 +48,13 @@
|
|
|
48
48
|
"design-templates:dev": "pnpm run dev"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
+
"@tanstack/react-query": "^5",
|
|
51
52
|
"@uniai-fe/uds-foundation": "^0.1.0",
|
|
52
53
|
"@uniai-fe/uds-primitives": "^0.1.0",
|
|
53
54
|
"@uniai-fe/util-functions": "^0.2.0",
|
|
55
|
+
"@uniai-fe/util-jotai": "^0.1.5",
|
|
54
56
|
"@uniai-fe/util-next": "^0.2.0",
|
|
55
|
-
"@
|
|
57
|
+
"@uniai-fe/util-rtc": "^0.1.0",
|
|
56
58
|
"jotai": "^2",
|
|
57
59
|
"next": "^15",
|
|
58
60
|
"react": "^19",
|
|
@@ -65,6 +67,7 @@
|
|
|
65
67
|
},
|
|
66
68
|
"devDependencies": {
|
|
67
69
|
"@svgr/webpack": "^8.1.0",
|
|
70
|
+
"@tanstack/react-query": "^5.90.16",
|
|
68
71
|
"@types/node": "^24.10.2",
|
|
69
72
|
"@types/react": "^19.2.8",
|
|
70
73
|
"@types/react-dom": "^19.2.3",
|
|
@@ -75,8 +78,9 @@
|
|
|
75
78
|
"@uniai-fe/uds-foundation": "workspace:*",
|
|
76
79
|
"@uniai-fe/uds-primitives": "workspace:*",
|
|
77
80
|
"@uniai-fe/util-functions": "workspace:*",
|
|
81
|
+
"@uniai-fe/util-jotai": "workspace:*",
|
|
78
82
|
"@uniai-fe/util-next": "workspace:*",
|
|
79
|
-
"@
|
|
83
|
+
"@uniai-fe/util-rtc": "workspace:*",
|
|
80
84
|
"eslint": "^9.39.2",
|
|
81
85
|
"jotai": "^2.16.1",
|
|
82
86
|
"next": "^15.5.9",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jotaiStorage } from "@uniai-fe/util-jotai";
|
|
2
|
+
import { atomWithStorage } from "jotai/utils";
|
|
3
|
+
import type { API_Res_LoginData } from "../types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 로그인 사용자 정보 세션스토리지로 관리
|
|
7
|
+
* @state
|
|
8
|
+
*/
|
|
9
|
+
export const userDataAtom = atomWithStorage<API_Res_LoginData | null>(
|
|
10
|
+
"userData",
|
|
11
|
+
null,
|
|
12
|
+
jotaiStorage.session<API_Res_LoginData | null>(),
|
|
13
|
+
);
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { API_Res_Base } from "../../../types/api";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 로그인 API; 요청
|
|
5
|
+
* @route /auth/user/login
|
|
6
|
+
* @property {string} username - 사용자 ID
|
|
7
|
+
* @property {string} password - 비밀번호
|
|
8
|
+
*/
|
|
9
|
+
export interface API_Req_Login {
|
|
10
|
+
/**
|
|
11
|
+
* 사용자 ID
|
|
12
|
+
*/
|
|
13
|
+
username: string;
|
|
14
|
+
/**
|
|
15
|
+
* 비밀번호
|
|
16
|
+
*/
|
|
17
|
+
password: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 로그인 API; 응답 - 유저 정보
|
|
22
|
+
* @route /auth/user/login
|
|
23
|
+
* @property {number} id - 사용자 인덱스
|
|
24
|
+
* @property {string} username - 사용자 아이디
|
|
25
|
+
* @property {string} full_name - 사용자 이름
|
|
26
|
+
* @property {number} gender - 사용자 성별
|
|
27
|
+
* - 0: 남
|
|
28
|
+
* - 1: 여
|
|
29
|
+
* @property {string} birth_date - 사용자 생년월일
|
|
30
|
+
* - yyyy-MM-dd
|
|
31
|
+
* @property {string} email - 사용자 이메일
|
|
32
|
+
* @property {number | string} phone_number - 사용자 전화번호
|
|
33
|
+
* @property {string} joined_at - 가입일
|
|
34
|
+
* - yyyy-MM-ddTHH:mm:ss
|
|
35
|
+
* @property {string | null} closed_at - 사용자 탈퇴일
|
|
36
|
+
* @property {number} use_sms - SMS 수신 여부
|
|
37
|
+
* - 0: 수신 안함
|
|
38
|
+
* - 1: 수신
|
|
39
|
+
* @property {number} user_type - 사용자 유형
|
|
40
|
+
* - 0: 일반 사용자
|
|
41
|
+
* ...
|
|
42
|
+
* - 99: 관리자
|
|
43
|
+
*/
|
|
44
|
+
export interface API_Res_LoginUserInfo {
|
|
45
|
+
/**
|
|
46
|
+
* 사용자 인덱스
|
|
47
|
+
*/
|
|
48
|
+
id: number;
|
|
49
|
+
/**
|
|
50
|
+
* 사용자 아이디
|
|
51
|
+
*/
|
|
52
|
+
username: string;
|
|
53
|
+
/**
|
|
54
|
+
* 사용자 이름
|
|
55
|
+
*/
|
|
56
|
+
full_name: string;
|
|
57
|
+
/**
|
|
58
|
+
* 사용자 성별
|
|
59
|
+
* - 0: 남
|
|
60
|
+
* - 1: 여
|
|
61
|
+
*/
|
|
62
|
+
gender: number;
|
|
63
|
+
/**
|
|
64
|
+
* 사용자 생년월일
|
|
65
|
+
* - yyyy-MM-dd
|
|
66
|
+
*/
|
|
67
|
+
birth_date: string;
|
|
68
|
+
/**
|
|
69
|
+
* 사용자 이메일
|
|
70
|
+
*/
|
|
71
|
+
email: string;
|
|
72
|
+
/**
|
|
73
|
+
* 사용자 전화번호
|
|
74
|
+
*/
|
|
75
|
+
phone_number: number | string;
|
|
76
|
+
/**
|
|
77
|
+
* 가입일
|
|
78
|
+
* - yyyy-MM-ddTHH:mm:ss
|
|
79
|
+
*/
|
|
80
|
+
joined_at: string;
|
|
81
|
+
/**
|
|
82
|
+
* 사용자 탈퇴일
|
|
83
|
+
*/
|
|
84
|
+
closed_at: string | null;
|
|
85
|
+
/**
|
|
86
|
+
* SMS 수신 여부
|
|
87
|
+
* - 0: 수신 안함
|
|
88
|
+
* - 1: 수신
|
|
89
|
+
*/
|
|
90
|
+
use_sms: number;
|
|
91
|
+
/**
|
|
92
|
+
* 사용자 유형
|
|
93
|
+
* - 0: 일반 사용자
|
|
94
|
+
* ...
|
|
95
|
+
* - 99: 관리자
|
|
96
|
+
*/
|
|
97
|
+
user_type: number;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 로그인 API; 응답 - 소속 그룹
|
|
102
|
+
* @route /auth/user/login
|
|
103
|
+
* @property {number} id - 그룹 인덱스
|
|
104
|
+
* @property {number} parent_id - 상위 그룹 인덱스
|
|
105
|
+
* @property {string} name - 그룹명
|
|
106
|
+
* @property {number} group_type - 그룹 유형
|
|
107
|
+
* - 0: 일반 그룹 (유니아이, 유통사 포함)
|
|
108
|
+
* - 1: 농장 그룹
|
|
109
|
+
* - 2: 기타 그룹
|
|
110
|
+
* @property {string} description - 그룹 설명
|
|
111
|
+
* @property {string} created_at - 그룹 생성일
|
|
112
|
+
* - yyyy-MM-ddTHH:mm:ss
|
|
113
|
+
*/
|
|
114
|
+
export interface API_Res_LoginGroup {
|
|
115
|
+
/**
|
|
116
|
+
* 그룹 인덱스
|
|
117
|
+
*/
|
|
118
|
+
id: number;
|
|
119
|
+
/**
|
|
120
|
+
* 상위 그룹 인덱스
|
|
121
|
+
*/
|
|
122
|
+
parent_id: number;
|
|
123
|
+
/**
|
|
124
|
+
* 그룹명
|
|
125
|
+
*/
|
|
126
|
+
name: string;
|
|
127
|
+
/**
|
|
128
|
+
* 그룹 유형
|
|
129
|
+
* - 0: 일반 그룹 (유니아이, 유통사 포함)
|
|
130
|
+
* - 1: 농장 그룹
|
|
131
|
+
* - 2: 기타 그룹
|
|
132
|
+
*/
|
|
133
|
+
group_type: number;
|
|
134
|
+
/**
|
|
135
|
+
* 그룹 설명
|
|
136
|
+
*/
|
|
137
|
+
description: string;
|
|
138
|
+
/**
|
|
139
|
+
* 그룹 생성일
|
|
140
|
+
* - yyyy-MM-ddTHH:mm:ss
|
|
141
|
+
*/
|
|
142
|
+
created_at: string;
|
|
143
|
+
flag: number;
|
|
144
|
+
status: number;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 로그인 API; 응답 - 역할 정보
|
|
149
|
+
* @route /auth/user/login
|
|
150
|
+
* @property {number} id - 역할 인덱스
|
|
151
|
+
* @property {string} name - 역할 이름
|
|
152
|
+
* @property {string} description - 역할 설명
|
|
153
|
+
* @property {number} create_userid - 역할을 생성한 사용자 ID
|
|
154
|
+
* @property {number} group_id - 역할이 속한 그룹 ID
|
|
155
|
+
* @property {string} created_at - 역할 생성일
|
|
156
|
+
* - yyyy-MM-ddTHH:mm:ss
|
|
157
|
+
* @property {Array<unknown>} rules - 역할 권한 목록
|
|
158
|
+
*/
|
|
159
|
+
export interface API_Res_LoginRole {
|
|
160
|
+
/**
|
|
161
|
+
* 역할 인덱스
|
|
162
|
+
*/
|
|
163
|
+
id: number;
|
|
164
|
+
/**
|
|
165
|
+
* 역할 이름
|
|
166
|
+
*/
|
|
167
|
+
name: string;
|
|
168
|
+
/**
|
|
169
|
+
* 역할 설명
|
|
170
|
+
*/
|
|
171
|
+
description: string;
|
|
172
|
+
/**
|
|
173
|
+
* 역할을 생성한 사용자 ID
|
|
174
|
+
*/
|
|
175
|
+
create_userid: number;
|
|
176
|
+
/**
|
|
177
|
+
* 역할이 속한 그룹 ID
|
|
178
|
+
*/
|
|
179
|
+
group_id: number;
|
|
180
|
+
/**
|
|
181
|
+
* 역할 생성일
|
|
182
|
+
* - yyyy-MM-ddTHH:mm:ss
|
|
183
|
+
*/
|
|
184
|
+
created_at: string;
|
|
185
|
+
rules: [];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 로그인 API; 응답 성공 데이터
|
|
190
|
+
* @route /auth/user/login
|
|
191
|
+
* @property {string} access_token - 엑세스 토큰
|
|
192
|
+
* @property {string} token_type - 엑세스 토큰 타입
|
|
193
|
+
* - bearer
|
|
194
|
+
* @property {number} expires_in - 토큰 유효기간
|
|
195
|
+
* - 초 단위
|
|
196
|
+
* @property {API_Res_LoginUserInfo} user_info - 로그인 유저 정보
|
|
197
|
+
* @property {API_Res_LoginGroup[]} groups - 소속 그룹 목록
|
|
198
|
+
* @property {API_Res_LoginGroup[]} ancestor_groups - 상위 그룹 목록
|
|
199
|
+
* @property {API_Res_LoginRole[]} roles - 역할 목록
|
|
200
|
+
*/
|
|
201
|
+
export interface API_Res_LoginData {
|
|
202
|
+
/**
|
|
203
|
+
* 엑세스 토큰
|
|
204
|
+
*/
|
|
205
|
+
access_token: string;
|
|
206
|
+
/**
|
|
207
|
+
* 엑세스 토큰 타입
|
|
208
|
+
* - bearer
|
|
209
|
+
*/
|
|
210
|
+
token_type: string;
|
|
211
|
+
/**
|
|
212
|
+
* 토큰 유효기간
|
|
213
|
+
* - 초 단위
|
|
214
|
+
*/
|
|
215
|
+
expires_in: number;
|
|
216
|
+
/**
|
|
217
|
+
* 로그인 유저 정보
|
|
218
|
+
*/
|
|
219
|
+
user_info: API_Res_LoginUserInfo;
|
|
220
|
+
groups: API_Res_LoginGroup[];
|
|
221
|
+
ancestor_groups: API_Res_LoginGroup[];
|
|
222
|
+
roles: API_Res_LoginRole[];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 로그인 API; 응답
|
|
227
|
+
* @route /auth/user/login
|
|
228
|
+
*/
|
|
229
|
+
export type API_Res_Login = API_Res_LoginData | API_Res_Base<null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type {};
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
EmailInput,
|
|
17
17
|
type EmailInputProps,
|
|
18
18
|
} from "@uniai-fe/uds-primitives";
|
|
19
|
-
import type {
|
|
19
|
+
import type { SubmitEvent } from "react";
|
|
20
20
|
import type {
|
|
21
21
|
AuthSignupAgreementOption,
|
|
22
22
|
AuthSignupVerificationProps,
|
|
@@ -234,7 +234,8 @@ export function AuthSignupVerificationForm({
|
|
|
234
234
|
const ctaDisabled =
|
|
235
235
|
disabled || Boolean(submitDisabled) || !resolvedVerificationReady;
|
|
236
236
|
|
|
237
|
-
|
|
237
|
+
// React 19에서는 onSubmit이 SubmitEvent를 요구하므로 이벤트 타입을 맞춰준다.
|
|
238
|
+
const handleFormSubmit = (event: SubmitEvent<HTMLFormElement>) => {
|
|
238
239
|
formAttr?.onSubmit?.(event);
|
|
239
240
|
if (event.defaultPrevented) {
|
|
240
241
|
return;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
import type {
|
|
3
|
+
API_Req_CctvRtcToken,
|
|
4
|
+
API_Res_CctvCompanyGroup,
|
|
5
|
+
API_Res_CctvRtcToken,
|
|
6
|
+
} from "../types";
|
|
7
|
+
import { getQueryString } from "@uniai-fe/util-functions";
|
|
8
|
+
|
|
9
|
+
export const getCctvCompanyList = async ({
|
|
10
|
+
username,
|
|
11
|
+
url,
|
|
12
|
+
}: {
|
|
13
|
+
username: string;
|
|
14
|
+
url?: string;
|
|
15
|
+
}) =>
|
|
16
|
+
await (
|
|
17
|
+
await fetch(url ?? `/api/cctv/company-list${getQueryString(username)}`)
|
|
18
|
+
).json();
|
|
19
|
+
|
|
20
|
+
export const useQueryCctvCompanyList = ({
|
|
21
|
+
username,
|
|
22
|
+
url,
|
|
23
|
+
}: {
|
|
24
|
+
username: string;
|
|
25
|
+
url?: string;
|
|
26
|
+
}): UseQueryResult<{ data: API_Res_CctvCompanyGroup[]; total_count: number }> =>
|
|
27
|
+
useQuery({
|
|
28
|
+
queryKey: ["cctv_company_list", username, url],
|
|
29
|
+
queryFn: () => getCctvCompanyList({ username, url }),
|
|
30
|
+
enabled: Boolean(username),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const postCctvRtcToken = async ({
|
|
34
|
+
company_id,
|
|
35
|
+
cam_id,
|
|
36
|
+
username,
|
|
37
|
+
url,
|
|
38
|
+
}: API_Req_CctvRtcToken & { url?: string }): Promise<API_Res_CctvRtcToken> =>
|
|
39
|
+
await (
|
|
40
|
+
await fetch(url ?? `/api/cctv/token`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
},
|
|
45
|
+
body: JSON.stringify({ companyId: company_id, camId: cam_id, username }),
|
|
46
|
+
})
|
|
47
|
+
).json();
|
|
48
|
+
|
|
49
|
+
export const useQueryCctvRtcToken = ({
|
|
50
|
+
company_id,
|
|
51
|
+
cam_id,
|
|
52
|
+
username,
|
|
53
|
+
url,
|
|
54
|
+
}: API_Req_CctvRtcToken & {
|
|
55
|
+
url?: string;
|
|
56
|
+
}): UseQueryResult<API_Res_CctvRtcToken> =>
|
|
57
|
+
useQuery({
|
|
58
|
+
queryKey: ["cctv_rtc_token", username, company_id, cam_id, url],
|
|
59
|
+
queryFn: () => postCctvRtcToken({ company_id, cam_id, username, url }),
|
|
60
|
+
enabled: Boolean(company_id && cam_id && username),
|
|
61
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateBackendQueryUrl_GET,
|
|
3
|
+
nextAPILog,
|
|
4
|
+
} from "@uniai-fe/util-functions";
|
|
5
|
+
import type {
|
|
6
|
+
API_Req_GetCompanyListParams,
|
|
7
|
+
API_Res_CctvCompanyGroup,
|
|
8
|
+
} from "../types";
|
|
9
|
+
|
|
10
|
+
export const GROUP_PRESET: API_Res_CctvCompanyGroup[] = [
|
|
11
|
+
{
|
|
12
|
+
group_code: "C",
|
|
13
|
+
group_name: "사육",
|
|
14
|
+
list: [], //meat,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
group_code: "PS-Growing",
|
|
18
|
+
group_name: "종계(육성)",
|
|
19
|
+
list: [], //breeder,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
group_code: "PS-Laying",
|
|
23
|
+
group_name: "종계(산란)",
|
|
24
|
+
list: [], //laying,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
group_code: "GPS-Growing",
|
|
28
|
+
group_name: "원종계(육성)",
|
|
29
|
+
list: [], //breeder,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
group_code: "GPS-Laying",
|
|
33
|
+
group_name: "원종계(산란)",
|
|
34
|
+
list: [], //laying,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
group_code: "PS-Hatching",
|
|
38
|
+
group_name: "부화",
|
|
39
|
+
list: [], //hatchery,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
group_code: "FeedFactory",
|
|
43
|
+
group_name: "사료공장",
|
|
44
|
+
list: [], //feedFactory,
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export function getMatchedGroupList(
|
|
49
|
+
data: API_Res_CctvCompanyGroup[] = [],
|
|
50
|
+
{ code, method }: { code: string; method: string },
|
|
51
|
+
) {
|
|
52
|
+
if (typeof data === "undefined" || !Array.isArray(data)) return [];
|
|
53
|
+
return data
|
|
54
|
+
.filter(g => {
|
|
55
|
+
const groupCode = g.group_code;
|
|
56
|
+
if (!method || method === "includes") return groupCode.includes(code);
|
|
57
|
+
if (method === "startsWith") return groupCode.startsWith(code);
|
|
58
|
+
if (method === "endsWith") return groupCode.endsWith(code);
|
|
59
|
+
return groupCode === code;
|
|
60
|
+
})
|
|
61
|
+
.flatMap(g => g.list);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function classifyGroups(
|
|
65
|
+
data: API_Res_CctvCompanyGroup[] = [],
|
|
66
|
+
): API_Res_CctvCompanyGroup[] {
|
|
67
|
+
// 사육(육계)
|
|
68
|
+
const meatGroupList = getMatchedGroupList(data, {
|
|
69
|
+
code: "C-Growing",
|
|
70
|
+
method: "startsWith",
|
|
71
|
+
});
|
|
72
|
+
// 종계 - 육성
|
|
73
|
+
const PS_breederGroupList = getMatchedGroupList(data, {
|
|
74
|
+
code: "PS-Growing",
|
|
75
|
+
method: "startsWith",
|
|
76
|
+
});
|
|
77
|
+
// 종계 - 산란
|
|
78
|
+
const PS_layingGroupList = getMatchedGroupList(data, {
|
|
79
|
+
code: "PS-Laying",
|
|
80
|
+
method: "startsWith",
|
|
81
|
+
});
|
|
82
|
+
// 원종계 - 육성
|
|
83
|
+
const GPS_breederGroupList = getMatchedGroupList(data, {
|
|
84
|
+
code: "GPS-Growing",
|
|
85
|
+
method: "startsWith",
|
|
86
|
+
});
|
|
87
|
+
// 원종계 - 산란
|
|
88
|
+
const GPS_layingGroupList = getMatchedGroupList(data, {
|
|
89
|
+
code: "GPS-Laying",
|
|
90
|
+
method: "startsWith",
|
|
91
|
+
});
|
|
92
|
+
// 부화
|
|
93
|
+
const hatcheryGroupList = getMatchedGroupList(data, {
|
|
94
|
+
code: "Hatching",
|
|
95
|
+
method: "includes",
|
|
96
|
+
});
|
|
97
|
+
// 사료공장
|
|
98
|
+
const feedFactoryGroupList = getMatchedGroupList(data, {
|
|
99
|
+
code: "FeedFactory",
|
|
100
|
+
method: "includes",
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const res = GROUP_PRESET.map(g => {
|
|
104
|
+
switch (g.group_code) {
|
|
105
|
+
case "C":
|
|
106
|
+
return { ...g, list: meatGroupList };
|
|
107
|
+
case "PS-Growing":
|
|
108
|
+
return { ...g, list: PS_breederGroupList };
|
|
109
|
+
case "PS-Laying":
|
|
110
|
+
return { ...g, list: PS_layingGroupList };
|
|
111
|
+
case "GPS-Growing":
|
|
112
|
+
return { ...g, list: GPS_breederGroupList };
|
|
113
|
+
case "GPS-Laying":
|
|
114
|
+
return { ...g, list: GPS_layingGroupList };
|
|
115
|
+
case "PS-Hatching":
|
|
116
|
+
return { ...g, list: hatcheryGroupList };
|
|
117
|
+
case "FeedFactory":
|
|
118
|
+
return { ...g, list: feedFactoryGroupList };
|
|
119
|
+
default:
|
|
120
|
+
return { ...g, list: [] };
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return res;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* CCTV; API route.ts 로직
|
|
129
|
+
* @api
|
|
130
|
+
* @route /v1/users/{username}/cctvs
|
|
131
|
+
* @param {API_Req_GetCompanyListParams} params
|
|
132
|
+
* @property {string} domain API 요청 도메인(서버)
|
|
133
|
+
* @property {string} routeUrl Next.js app/api 이하 경로 url
|
|
134
|
+
* @property {string} [queryUrl] 백엔드 요청 url
|
|
135
|
+
* @property {URLSearchParams | object} searchParams 요청 searchParams
|
|
136
|
+
*/
|
|
137
|
+
export async function getCompanyList({
|
|
138
|
+
domain,
|
|
139
|
+
routeUrl,
|
|
140
|
+
queryUrl,
|
|
141
|
+
searchParams,
|
|
142
|
+
}: API_Req_GetCompanyListParams): Promise<{
|
|
143
|
+
res: API_Res_CctvCompanyGroup[];
|
|
144
|
+
domain: string;
|
|
145
|
+
queryUrl: string;
|
|
146
|
+
options?: ResponseInit;
|
|
147
|
+
}> {
|
|
148
|
+
const username = searchParams.get("username") || "";
|
|
149
|
+
const query_url = queryUrl || `/v1/users/${username}/cctvs`;
|
|
150
|
+
|
|
151
|
+
const API_OPTION = {
|
|
152
|
+
domain,
|
|
153
|
+
queryUrl: query_url,
|
|
154
|
+
// searchParams,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
if (!queryUrl && !username)
|
|
158
|
+
return {
|
|
159
|
+
res: [],
|
|
160
|
+
...API_OPTION,
|
|
161
|
+
options: { status: 400, statusText: "유저 아이디를 확인할 수 없습니다." },
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// 요청 URL 구성
|
|
165
|
+
const url = generateBackendQueryUrl_GET({
|
|
166
|
+
routeUrl,
|
|
167
|
+
...API_OPTION,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const originRes: { data: API_Res_CctvCompanyGroup[] } = await (
|
|
172
|
+
await fetch(url)
|
|
173
|
+
).json();
|
|
174
|
+
|
|
175
|
+
// 응답 그룹/농장
|
|
176
|
+
const resGroups = originRes?.data || [];
|
|
177
|
+
const res = classifyGroups(resGroups);
|
|
178
|
+
|
|
179
|
+
return { res, ...API_OPTION };
|
|
180
|
+
} catch (err) {
|
|
181
|
+
nextAPILog("GET", routeUrl, url, { err });
|
|
182
|
+
return {
|
|
183
|
+
res: [],
|
|
184
|
+
...API_OPTION,
|
|
185
|
+
options: { status: 500 },
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
import { Form } from "@uniai-fe/uds-primitives";
|
|
5
|
+
|
|
6
|
+
import type { CctvContext, CctvSelectedContext } from "../types";
|
|
7
|
+
import { CCTV_CONTEXT_DEFAULT_VALUES } from "../data";
|
|
8
|
+
|
|
9
|
+
const EndpointContext = createContext<{ listUrl?: string; tokenUrl?: string }>({
|
|
10
|
+
listUrl: undefined,
|
|
11
|
+
tokenUrl: undefined,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export function useCctvEndpoints() {
|
|
15
|
+
return useContext(EndpointContext);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function CCTVProvider({
|
|
19
|
+
username,
|
|
20
|
+
company_id,
|
|
21
|
+
cam_id,
|
|
22
|
+
listUrl,
|
|
23
|
+
tokenUrl,
|
|
24
|
+
children,
|
|
25
|
+
}: {
|
|
26
|
+
username: string;
|
|
27
|
+
children: React.ReactNode;
|
|
28
|
+
listUrl?: string;
|
|
29
|
+
tokenUrl?: string;
|
|
30
|
+
} & CctvSelectedContext) {
|
|
31
|
+
return (
|
|
32
|
+
<EndpointContext.Provider value={{ listUrl, tokenUrl }}>
|
|
33
|
+
<Form.Provider<CctvContext>
|
|
34
|
+
options={{
|
|
35
|
+
defaultValues: {
|
|
36
|
+
...CCTV_CONTEXT_DEFAULT_VALUES,
|
|
37
|
+
username,
|
|
38
|
+
company_id,
|
|
39
|
+
cam_id,
|
|
40
|
+
},
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
{children}
|
|
44
|
+
</Form.Provider>
|
|
45
|
+
</EndpointContext.Provider>
|
|
46
|
+
);
|
|
47
|
+
}
|