@fctc/widget-logic 1.5.0 → 1.5.1

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.
Files changed (65) hide show
  1. package/dist/config.d.mts +6 -0
  2. package/dist/config.d.ts +6 -0
  3. package/dist/config.js +24 -0
  4. package/dist/config.mjs +2 -0
  5. package/dist/constants.d.mts +1 -0
  6. package/dist/constants.d.ts +1 -0
  7. package/dist/constants.js +24 -0
  8. package/dist/constants.mjs +2 -0
  9. package/dist/environment.d.mts +1 -0
  10. package/dist/environment.d.ts +1 -0
  11. package/dist/environment.js +24 -0
  12. package/dist/environment.mjs +2 -0
  13. package/dist/hooks.d.mts +969 -0
  14. package/dist/hooks.d.ts +969 -0
  15. package/dist/hooks.js +743 -0
  16. package/dist/hooks.mjs +717 -0
  17. package/dist/icons.d.mts +9 -0
  18. package/dist/icons.d.ts +9 -0
  19. package/dist/icons.js +139 -0
  20. package/dist/icons.mjs +110 -0
  21. package/dist/index.d.mts +17 -4
  22. package/dist/index.d.ts +17 -4
  23. package/dist/index.js +7233 -229
  24. package/dist/index.mjs +7320 -218
  25. package/dist/provider.d.mts +1 -0
  26. package/dist/provider.d.ts +1 -0
  27. package/dist/provider.js +24 -0
  28. package/dist/provider.mjs +2 -0
  29. package/dist/services.d.mts +1 -0
  30. package/dist/services.d.ts +1 -0
  31. package/dist/services.js +24 -0
  32. package/dist/services.mjs +2 -0
  33. package/dist/store.d.mts +1 -0
  34. package/dist/store.d.ts +1 -0
  35. package/dist/store.js +24 -0
  36. package/dist/store.mjs +2 -0
  37. package/dist/types.d.mts +31 -0
  38. package/dist/types.d.ts +31 -0
  39. package/dist/types.js +24 -0
  40. package/dist/types.mjs +2 -0
  41. package/dist/utils.d.mts +38 -0
  42. package/dist/utils.d.ts +38 -0
  43. package/dist/utils.js +282 -0
  44. package/dist/utils.mjs +242 -0
  45. package/dist/widget.d.mts +299 -0
  46. package/dist/widget.d.ts +299 -0
  47. package/dist/widget.js +7079 -0
  48. package/dist/widget.mjs +7111 -0
  49. package/package.json +69 -23
  50. package/dist/action.d.mts +0 -68
  51. package/dist/action.d.ts +0 -68
  52. package/dist/action.js +0 -152
  53. package/dist/action.mjs +0 -122
  54. package/dist/common.d.mts +0 -13
  55. package/dist/common.d.ts +0 -13
  56. package/dist/common.js +0 -60
  57. package/dist/common.mjs +0 -33
  58. package/dist/form.d.mts +0 -42
  59. package/dist/form.d.ts +0 -42
  60. package/dist/form.js +0 -116
  61. package/dist/form.mjs +0 -87
  62. package/dist/table.d.mts +0 -22
  63. package/dist/table.d.ts +0 -22
  64. package/dist/table.js +0 -118
  65. package/dist/table.mjs +0 -91
package/dist/hooks.js ADDED
@@ -0,0 +1,743 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/hooks.ts
22
+ var hooks_exports = {};
23
+ __export(hooks_exports, {
24
+ AppProvider: () => AppProvider,
25
+ useAppProvider: () => useAppProvider,
26
+ useAuth: () => useAuth,
27
+ useCallAction: () => useCallAction,
28
+ useClickOutside: () => useClickOutside,
29
+ useConfig: () => useConfig,
30
+ useDebounce: () => useDebounce,
31
+ useDetail: () => useDetail,
32
+ useListData: () => useListData,
33
+ useMenu: () => useMenu,
34
+ useProfile: () => useProfile,
35
+ useUser: () => useUser,
36
+ useViewV2: () => useViewV2
37
+ });
38
+ module.exports = __toCommonJS(hooks_exports);
39
+
40
+ // src/hooks/core/use-call-action.ts
41
+ var import_react = require("react");
42
+ var import_environment = require("@fctc/interface-logic/environment");
43
+ var import_hooks = require("@fctc/interface-logic/hooks");
44
+ var useCallAction = () => {
45
+ const queryLoadAction = (0, import_hooks.useLoadAction)();
46
+ const queryRunAction = (0, import_hooks.useRunAction)();
47
+ const [data, setData] = (0, import_react.useState)(void 0);
48
+ const callAction = async ({
49
+ aid,
50
+ actionType = "ir.actions.act_window"
51
+ }) => {
52
+ const context = (0, import_environment.getEnv)().context;
53
+ let res = void 0;
54
+ if (actionType === "ir.actions.act_window") {
55
+ res = await queryLoadAction.mutateAsync({
56
+ idAction: aid,
57
+ context
58
+ });
59
+ } else if (actionType === "ir.actions.server") {
60
+ res = await queryRunAction.mutateAsync({
61
+ idAction: aid,
62
+ context
63
+ });
64
+ }
65
+ setData(res);
66
+ return res;
67
+ };
68
+ return [data, callAction];
69
+ };
70
+
71
+ // src/hooks/core/use-config.ts
72
+ var import_react2 = require("react");
73
+ var import_environment2 = require("@fctc/interface-logic/environment");
74
+ var import_store = require("@fctc/interface-logic/store");
75
+ var useConfig = ({ localStorageUtils, sessionStorageUtils }) => {
76
+ const dispatch = (0, import_store.useAppDispatch)();
77
+ const envConfig = (0, import_react2.useMemo)(() => {
78
+ return {
79
+ mode: "development",
80
+ baseUrl: "https://api.vitrust.app/c2/api/v2",
81
+ config: {
82
+ grantType: "password",
83
+ clientId: "C52foVQSMpnNOcAP2CBIIkupOSfxUarF8nlOPfXM",
84
+ clientSecret: "rColINr4a9QBFQPqQB8YU1XfBjqzwerDMJGBxsFK"
85
+ }
86
+ };
87
+ }, []);
88
+ const config = (0, import_react2.useMemo)(() => {
89
+ return {
90
+ VITE_SIDEBAR_TYPE: "grid/sidebar",
91
+ VITE_APP_DOMAIN: "https://api.vitrust.app/c2/",
92
+ VITE_IS_EDU: true,
93
+ VITE_LOGO_WHITE_LOGIN: "https://static.vitrust.app/vitrust/3a/3a1301f614dea6ee19ebf99b68f57e3fd46011d2.png",
94
+ VITE_LOGO_BLACK_LOGIN: "https://static.vitrust.app/vitrust/32/3223918780da7a439f916faac9abf0bfe98dfa07.png",
95
+ VITE_BACKGROUND_SIDEBAR: "linear-gradient(178deg, rgb(1, 106, 13) -0.89%, rgb(4, 179, 66) 99.46%",
96
+ VITE_BANNER: "https://static.vitrust.app/vitrust/5d/5d20cab0627182b4ed5cba4ee42c58b98b663e5b.svg",
97
+ VITE_BG_BUTTON: "#008F3C",
98
+ VITE_BACKGROUND_PAGE: "#F9FAFB"
99
+ };
100
+ }, []);
101
+ (0, import_react2.useEffect)(() => {
102
+ try {
103
+ const env = (0, import_environment2.getEnv)();
104
+ env.setupEnv({
105
+ baseUrl: envConfig.baseUrl,
106
+ port: 3e3,
107
+ config: {
108
+ grantType: envConfig.config.grantType,
109
+ clientId: envConfig.config.clientId,
110
+ clientSecret: envConfig.config.clientSecret
111
+ },
112
+ db: "preschool",
113
+ localStorageUtils: localStorageUtils(),
114
+ sessionStorageUtils: sessionStorageUtils()
115
+ });
116
+ dispatch((0, import_store.setEnvFile)(config));
117
+ } catch (error) {
118
+ console.error("Error loading env or config:", error);
119
+ }
120
+ }, [dispatch, envConfig, config]);
121
+ return { envConfig, config };
122
+ };
123
+
124
+ // src/hooks/core/use-detail.ts
125
+ var import_store2 = require("@fctc/interface-logic/store");
126
+ var import_react_query = require("@tanstack/react-query");
127
+ var import_react3 = require("react");
128
+ var import_hooks2 = require("@fctc/interface-logic/hooks");
129
+ var useDetail = (accessToken, sub) => {
130
+ const dispatch = (0, import_store2.useAppDispatch)();
131
+ const fetchGetDetail = (0, import_hooks2.useGetDetail)();
132
+ const userDetailQuery = (0, import_react_query.useQuery)({
133
+ queryKey: ["userDetailQuery", sub && accessToken],
134
+ queryFn: () => {
135
+ return fetchGetDetail.mutateAsync({
136
+ model: "res.users",
137
+ ids: [sub],
138
+ specification: { image_256: {} }
139
+ });
140
+ },
141
+ enabled: !!sub && !!accessToken
142
+ });
143
+ (0, import_react3.useEffect)(() => {
144
+ if (userDetailQuery.data) {
145
+ const userPicture = userDetailQuery.data;
146
+ dispatch(
147
+ (0, import_store2.setProfile)({ ...userPicture, image: userPicture?.[0]?.image_256 })
148
+ );
149
+ }
150
+ }, [userDetailQuery.data, dispatch]);
151
+ return userDetailQuery;
152
+ };
153
+
154
+ // src/hooks/core/use-list-data.ts
155
+ var import_react5 = require("react");
156
+
157
+ // src/utils/function.ts
158
+ var import_react4 = require("react");
159
+ var getDateRange = (currentDate, unit) => {
160
+ const date = new Date(currentDate);
161
+ let dateStart, dateEnd;
162
+ function formatDate(d) {
163
+ return d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0") + " " + String(d.getHours()).padStart(2, "0") + ":" + String(d.getMinutes()).padStart(2, "0") + ":" + String(d.getSeconds()).padStart(2, "0");
164
+ }
165
+ switch (unit) {
166
+ case "month":
167
+ dateStart = new Date(
168
+ date.getFullYear(),
169
+ date.getMonth() + 1,
170
+ date.getDate(),
171
+ 23,
172
+ 59,
173
+ 59
174
+ );
175
+ dateStart.setHours(dateStart.getHours() - 7);
176
+ dateEnd = new Date(date.getFullYear(), date.getMonth(), 0, 0, 0, 0);
177
+ dateEnd.setHours(dateEnd.getHours() - 7);
178
+ break;
179
+ case "day":
180
+ dateStart = new Date(
181
+ date.getFullYear(),
182
+ date.getMonth(),
183
+ date.getDate(),
184
+ 23,
185
+ 59,
186
+ 59
187
+ );
188
+ dateStart.setHours(dateStart.getHours() - 7);
189
+ dateEnd = new Date(
190
+ date.getFullYear(),
191
+ date.getMonth(),
192
+ date.getDate(),
193
+ 0,
194
+ 0,
195
+ 0
196
+ );
197
+ dateEnd.setHours(dateEnd.getHours() - 7);
198
+ break;
199
+ case "week":
200
+ const dayOfWeek = date.getDay();
201
+ const daysToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
202
+ const daysToSunday = dayOfWeek === 0 ? 0 : 7 - dayOfWeek;
203
+ dateStart = new Date(
204
+ date.getFullYear(),
205
+ date.getMonth(),
206
+ date.getDate() + daysToSunday,
207
+ 23,
208
+ 59,
209
+ 59
210
+ );
211
+ dateStart.setHours(dateStart.getHours() - 7);
212
+ dateEnd = new Date(
213
+ date.getFullYear(),
214
+ date.getMonth(),
215
+ date.getDate() + daysToMonday,
216
+ 0,
217
+ 0,
218
+ 0
219
+ );
220
+ dateEnd.setHours(dateEnd.getHours() - 7);
221
+ break;
222
+ case "year":
223
+ dateStart = new Date(date.getFullYear(), 11, 31, 23, 59, 59);
224
+ dateStart.setHours(dateStart.getHours() - 7);
225
+ dateEnd = new Date(date.getFullYear() - 1, 11, 31, 0, 0, 0);
226
+ dateEnd.setHours(dateEnd.getHours() - 7);
227
+ break;
228
+ default:
229
+ throw new Error(
230
+ "\u0110\u01A1n v\u1ECB kh\xF4ng h\u1EE3p l\u1EC7. Ch\u1EC9 ch\u1EA5p nh\u1EADn: week, day, month, year"
231
+ );
232
+ }
233
+ return [
234
+ ["date_start", "<=", formatDate(dateStart)],
235
+ ["date_end", ">=", formatDate(dateEnd)]
236
+ ];
237
+ };
238
+ var convertFieldsToArray = (fields) => {
239
+ const defaultFields = ["display_name", "date_start", "date_end"];
240
+ if (!fields || !Array.isArray(fields)) {
241
+ return defaultFields;
242
+ }
243
+ const inputFields = fields.filter((field) => field && field.type_co === "field").map((field) => field.name);
244
+ return [...defaultFields, ...inputFields];
245
+ };
246
+ function combineContexts(contexts) {
247
+ if (contexts.some((context) => !context)) {
248
+ return void 0;
249
+ } else {
250
+ const res = contexts.reduce((acc, context) => {
251
+ return { ...acc, ...context };
252
+ }, {});
253
+ return res;
254
+ }
255
+ }
256
+ function useAsyncState(initialValue = [true, null]) {
257
+ return (0, import_react4.useReducer)(
258
+ (_state, action = null) => [false, action],
259
+ initialValue
260
+ );
261
+ }
262
+ async function setStorageItemAsync(key, value) {
263
+ try {
264
+ if (value === null) {
265
+ localStorage.removeItem(key);
266
+ } else {
267
+ localStorage.setItem(key, value);
268
+ }
269
+ } catch (e) {
270
+ console.error("Local storage is unavailable:", e);
271
+ }
272
+ }
273
+ function useStorageState(key) {
274
+ const [state, setState] = useAsyncState();
275
+ (0, import_react4.useEffect)(() => {
276
+ try {
277
+ const storedValue = localStorage.getItem(key);
278
+ setState(storedValue);
279
+ } catch (e) {
280
+ console.error("Local storage is unavailable:", e);
281
+ }
282
+ }, [key]);
283
+ const setValue = (0, import_react4.useCallback)(
284
+ (value) => {
285
+ setState(value);
286
+ setStorageItemAsync(key, value);
287
+ },
288
+ [key]
289
+ );
290
+ return [state, setValue];
291
+ }
292
+
293
+ // src/hooks/core/use-list-data.ts
294
+ var import_hooks3 = require("@fctc/interface-logic/hooks");
295
+ var import_store3 = require("@fctc/interface-logic/store");
296
+ var import_utils = require("@fctc/interface-logic/utils");
297
+ var useListData = ({
298
+ action,
299
+ context,
300
+ viewResponse
301
+ }) => {
302
+ const { groupByDomain } = (0, import_store3.useAppSelector)(import_store3.selectSearch);
303
+ const initModel = (0, import_hooks3.useModel)();
304
+ const [type, setType] = (0, import_react5.useState)("list");
305
+ const [mode, setMode] = (0, import_react5.useState)("month");
306
+ const [currentDate, setCurrentDate] = (0, import_react5.useState)(/* @__PURE__ */ new Date());
307
+ const { pageLimit, page, order } = (0, import_store3.useAppSelector)(import_store3.selectList);
308
+ const listDataProps = (0, import_react5.useMemo)(() => {
309
+ const actData = action?.result;
310
+ if (!viewResponse || !actData || !context) {
311
+ return null;
312
+ }
313
+ const specification = initModel.initModel({
314
+ name: String(actData.res_model),
315
+ view: viewResponse || {},
316
+ actContext: context,
317
+ fields: type === "kanban" ? viewResponse?.views?.kanban?.fields : type === "calendar" ? viewResponse?.views?.calendar?.fields : viewResponse?.views?.list?.fields
318
+ }).getSpecification();
319
+ const domain = type === "calendar" ? getDateRange(currentDate, mode) : actData?.domain ? Array.isArray(actData?.domain) ? [...actData?.domain] : (0, import_utils.evalJSONDomain)(actData?.domain, context) : [];
320
+ const limit = type === "calendar" ? 2500 : pageLimit;
321
+ const offset = page * pageLimit;
322
+ const fields = type === "calendar" ? convertFieldsToArray(viewResponse?.views?.calendar?.fields) || [] : typeof groupByDomain === "object" ? groupByDomain?.fields : void 0;
323
+ const groupby = typeof groupByDomain === "object" ? [groupByDomain?.contexts?.[0]?.group_by] : [];
324
+ const sort = order ? order : viewResponse?.views?.list?.default_order ? (0, import_utils.formatSortingString)(viewResponse?.views?.list?.default_order) : "";
325
+ return {
326
+ model: actData.res_model,
327
+ specification,
328
+ domain,
329
+ limit,
330
+ offset,
331
+ fields,
332
+ groupby,
333
+ context,
334
+ sort,
335
+ type
336
+ };
337
+ }, [
338
+ action?.result,
339
+ context,
340
+ currentDate,
341
+ groupByDomain,
342
+ initModel,
343
+ mode,
344
+ order,
345
+ page,
346
+ pageLimit,
347
+ type,
348
+ viewResponse
349
+ ]);
350
+ const list = (0, import_hooks3.useGetListData)(
351
+ listDataProps,
352
+ [listDataProps],
353
+ !!listDataProps
354
+ );
355
+ return {
356
+ ...list,
357
+ state: {
358
+ type,
359
+ setType,
360
+ mode,
361
+ setMode,
362
+ currentDate,
363
+ setCurrentDate
364
+ }
365
+ };
366
+ };
367
+
368
+ // src/hooks/core/use-menu.ts
369
+ var import_react6 = require("react");
370
+
371
+ // src/utils/constants.ts
372
+ var languages = [
373
+ { id: "vi_VN", name: "VIE" },
374
+ { id: "en_US", name: "ENG" }
375
+ ];
376
+ var API_APP_URL = {
377
+ baseUrl: "https://api.vitrust.app",
378
+ c2: "https://api.vitrust.app/c2",
379
+ apiV2: "https://api.vitrust.app/c2/api/v2"
380
+ };
381
+
382
+ // src/hooks/core/use-menu.ts
383
+ var import_hooks4 = require("@fctc/interface-logic/hooks");
384
+ var useMenu = ({ context }) => {
385
+ const menuData = (0, import_hooks4.useGetMenu)(context, !!context);
386
+ const [menuid, setMenuId] = (0, import_react6.useState)(void 0);
387
+ const [action, setAction] = useCallAction();
388
+ const configedIconData = (0, import_react6.useMemo)(() => {
389
+ const data = menuData.data;
390
+ return data?.map((item) => {
391
+ return {
392
+ ...item,
393
+ child_id: item?.child_id?.map((child) => {
394
+ return {
395
+ ...child,
396
+ url_icon: API_APP_URL.c2 + "/" + child.url_icon
397
+ };
398
+ }) ?? [],
399
+ url_icon: API_APP_URL.c2 + "/" + item.url_icon
400
+ };
401
+ });
402
+ }, [menuData.data]);
403
+ const handleChangeMenu = async ({
404
+ menu,
405
+ subMenu
406
+ }) => {
407
+ const aid = subMenu?.action?.id?.id;
408
+ const actionType = subMenu?.action?.type;
409
+ await setAction({
410
+ aid: Number(aid),
411
+ actionType
412
+ });
413
+ if (menu) {
414
+ setMenuId(menu.id?.toString() ?? "");
415
+ }
416
+ };
417
+ (0, import_react6.useEffect)(() => {
418
+ const firstRecord = configedIconData?.[0];
419
+ const firstChild = firstRecord?.child_id?.[0];
420
+ if (firstChild && firstRecord) {
421
+ handleChangeMenu({ menu: firstRecord, subMenu: firstChild });
422
+ }
423
+ }, [configedIconData]);
424
+ return {
425
+ ...menuData,
426
+ data: configedIconData,
427
+ action: { handleChangeMenu },
428
+ state: { menuid, action },
429
+ context
430
+ };
431
+ };
432
+
433
+ // src/hooks/core/use-profile.ts
434
+ var import_react_query2 = require("@tanstack/react-query");
435
+ var import_react7 = require("react");
436
+ var import_react_i18next = require("react-i18next");
437
+ var import_environment3 = require("@fctc/interface-logic/environment");
438
+ var import_hooks5 = require("@fctc/interface-logic/hooks");
439
+ var import_store4 = require("@fctc/interface-logic/store");
440
+ var useProfile = (accessToken) => {
441
+ const getProfile = (0, import_hooks5.useGetProfile)();
442
+ const dispatch = (0, import_store4.useAppDispatch)();
443
+ const { i18n } = (0, import_react_i18next.useTranslation)();
444
+ const fetchUserProfile = async () => {
445
+ return await getProfile.mutateAsync();
446
+ };
447
+ const userInfoQuery = (0, import_react_query2.useQuery)({
448
+ queryKey: ["userInfo", accessToken],
449
+ queryFn: fetchUserProfile,
450
+ enabled: !!accessToken
451
+ });
452
+ (0, import_react7.useEffect)(() => {
453
+ if (userInfoQuery.data) {
454
+ const userInfo = userInfoQuery.data;
455
+ const env = (0, import_environment3.getEnv)();
456
+ env.setUid(userInfo?.sub);
457
+ dispatch((0, import_store4.setDataUser)(userInfo));
458
+ const userLocale = languages.find((lang) => lang?.id === userInfo?.locale);
459
+ env.setLang(userLocale?.id);
460
+ i18n.changeLanguage(userLocale?.id.split("_")[0]);
461
+ }
462
+ }, [dispatch, userInfoQuery.data]);
463
+ const context = (0, import_react7.useMemo)(() => {
464
+ if (userInfoQuery.data?.sub && userInfoQuery.data?.locale) {
465
+ return {
466
+ uid: Number(userInfoQuery.data.sub),
467
+ allowed_company_ids: [],
468
+ lang: String(userInfoQuery.data.locale),
469
+ tz: "Asia/Saigon"
470
+ };
471
+ }
472
+ return void 0;
473
+ }, [userInfoQuery.data]);
474
+ return { ...userInfoQuery, context };
475
+ };
476
+
477
+ // src/hooks/core/use-user.ts
478
+ var useUser = (accessToken) => {
479
+ const userProfile = useProfile(accessToken);
480
+ const userDetail = useDetail(accessToken, userProfile.data?.sub);
481
+ return { userProfile, userDetail, context: userProfile.context };
482
+ };
483
+
484
+ // src/hooks/core/use-view-v2.ts
485
+ var import_react8 = require("react");
486
+ var import_hooks6 = require("@fctc/interface-logic/hooks");
487
+ var useViewV2 = ({
488
+ action,
489
+ context
490
+ }) => {
491
+ const viewParams = (0, import_react8.useMemo)(() => {
492
+ if (!action?.result) {
493
+ return void 0;
494
+ }
495
+ const actionResult = action?.result;
496
+ return {
497
+ model: String(actionResult?.res_model),
498
+ views: [
499
+ ...Array.isArray(actionResult?.views) ? actionResult?.views.map(
500
+ (view2) => view2[1] === "list" ? [view2[0], "list"] : view2
501
+ ) : [],
502
+ [
503
+ Array.isArray(actionResult?.search_view_id) ? actionResult?.search_view_id[0] : actionResult?.search_view_id,
504
+ "search"
505
+ ]
506
+ ],
507
+ context
508
+ };
509
+ }, [action, context]);
510
+ const view = (0, import_hooks6.useGetView)(
511
+ viewParams || {},
512
+ !!viewParams
513
+ );
514
+ return {
515
+ ...view,
516
+ context
517
+ };
518
+ };
519
+
520
+ // src/hooks/core/use-auth.ts
521
+ var import_hooks7 = require("@fctc/interface-logic/hooks");
522
+ var import_store5 = require("@fctc/interface-logic/store");
523
+ var useAuth = () => {
524
+ const [[isLoading, accessToken], setAccessToken] = useStorageState("TOKEN");
525
+ const loginMutate = (0, import_hooks7.useLoginCredential)();
526
+ const dispatch = (0, import_store5.useAppDispatch)();
527
+ const signIn = async (email, password) => {
528
+ try {
529
+ loginMutate.mutate(
530
+ {
531
+ email,
532
+ password,
533
+ path: "/authentication/oauth2/token"
534
+ },
535
+ {
536
+ onSuccess: (res) => {
537
+ setAccessToken(res.access_token);
538
+ },
539
+ onError: (err) => {
540
+ }
541
+ }
542
+ );
543
+ } catch (error) {
544
+ throw new Error("Login failed");
545
+ }
546
+ };
547
+ const signOut = async () => {
548
+ dispatch((0, import_store5.setMenuList)([]));
549
+ dispatch((0, import_store5.setDataUser)({}));
550
+ dispatch((0, import_store5.setProfile)({}));
551
+ setAccessToken(null);
552
+ };
553
+ return {
554
+ signIn,
555
+ signOut,
556
+ accessToken,
557
+ isLoading
558
+ };
559
+ };
560
+
561
+ // src/hooks/core/use-app-provider.tsx
562
+ var import_react10 = require("react");
563
+
564
+ // src/hooks/core/use-company.ts
565
+ var import_react_query3 = require("@tanstack/react-query");
566
+ var import_react9 = require("react");
567
+ var import_environment4 = require("@fctc/interface-logic/environment");
568
+ var import_hooks8 = require("@fctc/interface-logic/hooks");
569
+ var useCompany = (accessToken) => {
570
+ const getCurrentCompany = (0, import_hooks8.useGetCurrentCompany)();
571
+ const fetchCurrentCompany = async () => {
572
+ return await getCurrentCompany.mutateAsync();
573
+ };
574
+ const currentCompany = (0, import_react_query3.useQuery)({
575
+ queryKey: ["currentCompany", accessToken],
576
+ queryFn: fetchCurrentCompany,
577
+ enabled: !!accessToken
578
+ });
579
+ const current_company_id = (0, import_react9.useMemo)(() => {
580
+ return currentCompany.data?.current_company_id;
581
+ }, [currentCompany.data]);
582
+ (0, import_react9.useEffect)(() => {
583
+ if (current_company_id) {
584
+ const companyIDs = [current_company_id];
585
+ const env = (0, import_environment4.getEnv)();
586
+ env.setAllowCompanies([...companyIDs]);
587
+ env.setCompanies(companyIDs);
588
+ }
589
+ }, [current_company_id]);
590
+ const getCompanyInfo = (0, import_hooks8.useGetCompanyInfo)();
591
+ const companyInfo = (0, import_react_query3.useQuery)({
592
+ queryKey: ["companyInfoQuery", current_company_id, accessToken],
593
+ queryFn: () => getCompanyInfo.mutateAsync(Number(current_company_id)),
594
+ enabled: !!current_company_id && !!accessToken
595
+ });
596
+ (0, import_react9.useEffect)(() => {
597
+ if (companyInfo.data) {
598
+ const companyInfoData = companyInfo.data;
599
+ if (companyInfoData?.length) {
600
+ const env = (0, import_environment4.getEnv)();
601
+ env.setDefaultCompany(companyInfoData[0]);
602
+ }
603
+ }
604
+ }, [companyInfo.data]);
605
+ return {
606
+ currentCompany,
607
+ companyInfo,
608
+ context: { allowed_company_ids: [current_company_id] }
609
+ };
610
+ };
611
+ var use_company_default = useCompany;
612
+
613
+ // src/hooks/core/use-app-provider.tsx
614
+ var import_utils2 = require("@fctc/interface-logic/utils");
615
+ var import_jsx_runtime = require("react/jsx-runtime");
616
+ var AppProviderInitialValue = {
617
+ config: {},
618
+ user: {},
619
+ auth: {},
620
+ company: {},
621
+ action: {},
622
+ menu: {},
623
+ view: {},
624
+ list: {}
625
+ };
626
+ var ReactContext = (0, import_react10.createContext)(AppProviderInitialValue);
627
+ var AppProvider = ({ children }) => {
628
+ const config = useConfig({});
629
+ const auth = useAuth();
630
+ const user = useUser(auth.accessToken);
631
+ const company = use_company_default(auth.accessToken);
632
+ const menuContext = (0, import_react10.useMemo)(() => {
633
+ return combineContexts([user.context, company.context]);
634
+ }, [user.context, company.context]);
635
+ const menu = useMenu({ context: menuContext });
636
+ const action = (0, import_react10.useMemo)(() => {
637
+ return menu.state.action;
638
+ }, [menu.state.action]);
639
+ const viewContext = (0, import_react10.useMemo)(() => {
640
+ return combineContexts([
641
+ menuContext,
642
+ { ...(0, import_utils2.evalJSONContext)(action?.result?.context) }
643
+ ]);
644
+ }, [menuContext, action?.result?.context]);
645
+ const view = useViewV2({
646
+ action,
647
+ context: viewContext
648
+ });
649
+ const list = useListData({
650
+ action,
651
+ viewResponse: view.data,
652
+ context: viewContext
653
+ });
654
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
655
+ ReactContext.Provider,
656
+ {
657
+ value: {
658
+ config,
659
+ auth,
660
+ user,
661
+ company,
662
+ menu,
663
+ list,
664
+ action,
665
+ view
666
+ },
667
+ children
668
+ }
669
+ );
670
+ };
671
+ var useAppProvider = () => {
672
+ const context = (0, import_react10.useContext)(ReactContext);
673
+ if (!context) {
674
+ return AppProviderInitialValue;
675
+ }
676
+ return context;
677
+ };
678
+
679
+ // src/hooks/utils/use-click-outside.ts
680
+ var import_react11 = require("react");
681
+ var DEFAULT_EVENTS = ["mousedown", "touchstart"];
682
+ var useClickOutside = ({
683
+ handler,
684
+ events = DEFAULT_EVENTS,
685
+ nodes = [],
686
+ refs
687
+ }) => {
688
+ const ref = (0, import_react11.useRef)(null);
689
+ (0, import_react11.useEffect)(() => {
690
+ const listener = (event) => {
691
+ const { target } = event;
692
+ if (refs && refs?.length > 0 && refs?.some((r) => r.current?.contains(target))) {
693
+ return;
694
+ }
695
+ if (!(target instanceof HTMLElement)) return;
696
+ const shouldIgnore = target.hasAttribute("data-ignore-outside-clicks") || !document.body.contains(target) && target.tagName !== "HTML";
697
+ const shouldTrigger = nodes.length > 0 ? nodes.every((node) => node && !event.composedPath().includes(node)) : ref.current && !ref.current.contains(target);
698
+ if (shouldTrigger && !shouldIgnore) {
699
+ handler(event);
700
+ }
701
+ };
702
+ events.forEach((event) => document.addEventListener(event, listener));
703
+ return () => {
704
+ events.forEach((event) => document.removeEventListener(event, listener));
705
+ };
706
+ }, [handler, nodes, events]);
707
+ return ref;
708
+ };
709
+
710
+ // src/hooks/utils/use-debounce.ts
711
+ var import_react12 = require("react");
712
+ function useDebounce(value, delay) {
713
+ const [debouncedValue, setDebouncedValue] = (0, import_react12.useState)(value);
714
+ (0, import_react12.useEffect)(() => {
715
+ const handler = setTimeout(() => {
716
+ setDebouncedValue(value);
717
+ }, delay);
718
+ return () => {
719
+ clearTimeout(handler);
720
+ };
721
+ }, [value, delay]);
722
+ return [debouncedValue];
723
+ }
724
+
725
+ // src/hooks.ts
726
+ __reExport(hooks_exports, require("@fctc/interface-logic/hooks"), module.exports);
727
+ // Annotate the CommonJS export names for ESM import in node:
728
+ 0 && (module.exports = {
729
+ AppProvider,
730
+ useAppProvider,
731
+ useAuth,
732
+ useCallAction,
733
+ useClickOutside,
734
+ useConfig,
735
+ useDebounce,
736
+ useDetail,
737
+ useListData,
738
+ useMenu,
739
+ useProfile,
740
+ useUser,
741
+ useViewV2,
742
+ ...require("@fctc/interface-logic/hooks")
743
+ });