@fctc/widget-logic 1.10.0 → 1.10.2

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