@fctc/widget-logic 1.2.0 → 1.2.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.
package/dist/hooks.js ADDED
@@ -0,0 +1,860 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/hooks.ts
21
+ var hooks_exports = {};
22
+ __export(hooks_exports, {
23
+ AppProvider: () => AppProvider,
24
+ useAppProvider: () => useAppProvider,
25
+ useAuth: () => useAuth,
26
+ useCallAction: () => useCallAction,
27
+ useClickOutside: () => useClickOutside,
28
+ useConfig: () => useConfig,
29
+ useDebounce: () => useDebounce,
30
+ useDetail: () => useDetail,
31
+ useForgotPasswordHandler: () => useForgotPasswordHandler,
32
+ useListData: () => useListData,
33
+ useLoginHandler: () => useLoginHandler,
34
+ useMenu: () => useMenu,
35
+ useProfile: () => useProfile,
36
+ useResetPasswordHandler: () => useResetPasswordHandler,
37
+ useSwitchLocaleHandler: () => useSwitchLocaleHandler,
38
+ useUser: () => useUser,
39
+ useViewV2: () => useViewV2
40
+ });
41
+ module.exports = __toCommonJS(hooks_exports);
42
+
43
+ // src/hooks/core/use-call-action.ts
44
+ var import_interface_logic = require("@fctc/interface-logic");
45
+ var import_react = require("react");
46
+ var useCallAction = () => {
47
+ const queryLoadAction = (0, import_interface_logic.useLoadAction)();
48
+ const queryRunAction = (0, import_interface_logic.useRunAction)();
49
+ const [data, setData] = (0, import_react.useState)(void 0);
50
+ const callAction = async ({
51
+ aid,
52
+ actionType = "ir.actions.act_window"
53
+ }) => {
54
+ const context = (0, import_interface_logic.getEnv)().context;
55
+ let res = void 0;
56
+ if (actionType === "ir.actions.act_window") {
57
+ res = await queryLoadAction.mutateAsync({
58
+ idAction: aid,
59
+ context
60
+ });
61
+ } else if (actionType === "ir.actions.server") {
62
+ res = await queryRunAction.mutateAsync({
63
+ idAction: aid,
64
+ context
65
+ });
66
+ }
67
+ setData(res);
68
+ return res;
69
+ };
70
+ return [data, callAction];
71
+ };
72
+
73
+ // src/hooks/core/use-config.ts
74
+ var import_interface_logic2 = require("@fctc/interface-logic");
75
+ var import_react2 = require("react");
76
+ var useConfig = ({ localStorageUtils, sessionStorageUtils }) => {
77
+ const dispatch = (0, import_interface_logic2.useAppDispatch)();
78
+ const envConfig = (0, import_react2.useMemo)(() => {
79
+ return {
80
+ mode: "development",
81
+ baseUrl: "https://api.vitrust.app/c2/api/v2",
82
+ config: {
83
+ grantType: "password",
84
+ clientId: "C52foVQSMpnNOcAP2CBIIkupOSfxUarF8nlOPfXM",
85
+ clientSecret: "rColINr4a9QBFQPqQB8YU1XfBjqzwerDMJGBxsFK"
86
+ }
87
+ };
88
+ }, []);
89
+ const config = (0, import_react2.useMemo)(() => {
90
+ return {
91
+ VITE_SIDEBAR_TYPE: "grid/sidebar",
92
+ VITE_APP_DOMAIN: "https://api.vitrust.app/c2/",
93
+ VITE_IS_EDU: true,
94
+ VITE_LOGO_WHITE_LOGIN: "https://static.vitrust.app/vitrust/3a/3a1301f614dea6ee19ebf99b68f57e3fd46011d2.png",
95
+ VITE_LOGO_BLACK_LOGIN: "https://static.vitrust.app/vitrust/32/3223918780da7a439f916faac9abf0bfe98dfa07.png",
96
+ VITE_BACKGROUND_SIDEBAR: "linear-gradient(178deg, rgb(1, 106, 13) -0.89%, rgb(4, 179, 66) 99.46%",
97
+ VITE_BANNER: "https://static.vitrust.app/vitrust/5d/5d20cab0627182b4ed5cba4ee42c58b98b663e5b.svg",
98
+ VITE_BG_BUTTON: "#008F3C",
99
+ VITE_BACKGROUND_PAGE: "#F9FAFB"
100
+ };
101
+ }, []);
102
+ (0, import_react2.useEffect)(() => {
103
+ try {
104
+ const env = (0, import_interface_logic2.getEnv)();
105
+ env.setupEnv({
106
+ baseUrl: envConfig.baseUrl,
107
+ port: 3e3,
108
+ config: {
109
+ grantType: envConfig.config.grantType,
110
+ clientId: envConfig.config.clientId,
111
+ clientSecret: envConfig.config.clientSecret
112
+ },
113
+ db: "preschool",
114
+ localStorageUtils: localStorageUtils(),
115
+ sessionStorageUtils: sessionStorageUtils()
116
+ });
117
+ dispatch((0, import_interface_logic2.setEnvFile)(config));
118
+ } catch (error) {
119
+ console.error("Error loading env or config:", error);
120
+ }
121
+ }, [dispatch, envConfig, config]);
122
+ return { envConfig, config };
123
+ };
124
+
125
+ // src/hooks/core/use-detail.ts
126
+ var import_interface_logic3 = require("@fctc/interface-logic");
127
+ var import_react_query = require("@tanstack/react-query");
128
+ var import_react3 = require("react");
129
+ var useDetail = (accessToken, sub) => {
130
+ const dispatch = (0, import_interface_logic3.useAppDispatch)();
131
+ const fetchGetDetail = (0, import_interface_logic3.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_interface_logic3.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
+ var import_interface_logic4 = require("@fctc/interface-logic");
157
+
158
+ // src/utils/function.ts
159
+ var import_react4 = require("react");
160
+ var getDateRange = (currentDate, unit) => {
161
+ const date = new Date(currentDate);
162
+ let dateStart, dateEnd;
163
+ function formatDate(d) {
164
+ 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");
165
+ }
166
+ switch (unit) {
167
+ case "month":
168
+ dateStart = new Date(
169
+ date.getFullYear(),
170
+ date.getMonth() + 1,
171
+ date.getDate(),
172
+ 23,
173
+ 59,
174
+ 59
175
+ );
176
+ dateStart.setHours(dateStart.getHours() - 7);
177
+ dateEnd = new Date(date.getFullYear(), date.getMonth(), 0, 0, 0, 0);
178
+ dateEnd.setHours(dateEnd.getHours() - 7);
179
+ break;
180
+ case "day":
181
+ dateStart = new Date(
182
+ date.getFullYear(),
183
+ date.getMonth(),
184
+ date.getDate(),
185
+ 23,
186
+ 59,
187
+ 59
188
+ );
189
+ dateStart.setHours(dateStart.getHours() - 7);
190
+ dateEnd = new Date(
191
+ date.getFullYear(),
192
+ date.getMonth(),
193
+ date.getDate(),
194
+ 0,
195
+ 0,
196
+ 0
197
+ );
198
+ dateEnd.setHours(dateEnd.getHours() - 7);
199
+ break;
200
+ case "week":
201
+ const dayOfWeek = date.getDay();
202
+ const daysToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
203
+ const daysToSunday = dayOfWeek === 0 ? 0 : 7 - dayOfWeek;
204
+ dateStart = new Date(
205
+ date.getFullYear(),
206
+ date.getMonth(),
207
+ date.getDate() + daysToSunday,
208
+ 23,
209
+ 59,
210
+ 59
211
+ );
212
+ dateStart.setHours(dateStart.getHours() - 7);
213
+ dateEnd = new Date(
214
+ date.getFullYear(),
215
+ date.getMonth(),
216
+ date.getDate() + daysToMonday,
217
+ 0,
218
+ 0,
219
+ 0
220
+ );
221
+ dateEnd.setHours(dateEnd.getHours() - 7);
222
+ break;
223
+ case "year":
224
+ dateStart = new Date(date.getFullYear(), 11, 31, 23, 59, 59);
225
+ dateStart.setHours(dateStart.getHours() - 7);
226
+ dateEnd = new Date(date.getFullYear() - 1, 11, 31, 0, 0, 0);
227
+ dateEnd.setHours(dateEnd.getHours() - 7);
228
+ break;
229
+ default:
230
+ throw new Error(
231
+ "\u0110\u01A1n v\u1ECB kh\xF4ng h\u1EE3p l\u1EC7. Ch\u1EC9 ch\u1EA5p nh\u1EADn: week, day, month, year"
232
+ );
233
+ }
234
+ return [
235
+ ["date_start", "<=", formatDate(dateStart)],
236
+ ["date_end", ">=", formatDate(dateEnd)]
237
+ ];
238
+ };
239
+ var convertFieldsToArray = (fields) => {
240
+ const defaultFields = ["display_name", "date_start", "date_end"];
241
+ if (!fields || !Array.isArray(fields)) {
242
+ return defaultFields;
243
+ }
244
+ const inputFields = fields.filter((field) => field && field.type_co === "field").map((field) => field.name);
245
+ return [...defaultFields, ...inputFields];
246
+ };
247
+ function combineContexts(contexts) {
248
+ if (contexts.some((context) => !context)) {
249
+ return void 0;
250
+ } else {
251
+ const res = contexts.reduce((acc, context) => {
252
+ return { ...acc, ...context };
253
+ }, {});
254
+ return res;
255
+ }
256
+ }
257
+ function useAsyncState(initialValue = [true, null]) {
258
+ return (0, import_react4.useReducer)(
259
+ (_state, action = null) => [false, action],
260
+ initialValue
261
+ );
262
+ }
263
+ async function setStorageItemAsync(key, value) {
264
+ try {
265
+ if (value === null) {
266
+ localStorage.removeItem(key);
267
+ } else {
268
+ localStorage.setItem(key, value);
269
+ }
270
+ } catch (e) {
271
+ console.error("Local storage is unavailable:", e);
272
+ }
273
+ }
274
+ function useStorageState(key) {
275
+ const [state, setState] = useAsyncState();
276
+ (0, import_react4.useEffect)(() => {
277
+ try {
278
+ const storedValue = localStorage.getItem(key);
279
+ setState(storedValue);
280
+ } catch (e) {
281
+ console.error("Local storage is unavailable:", e);
282
+ }
283
+ }, [key]);
284
+ const setValue = (0, import_react4.useCallback)(
285
+ (value) => {
286
+ setState(value);
287
+ setStorageItemAsync(key, value);
288
+ },
289
+ [key]
290
+ );
291
+ return [state, setValue];
292
+ }
293
+
294
+ // src/hooks/core/use-list-data.ts
295
+ var useListData = ({
296
+ action,
297
+ context,
298
+ viewResponse
299
+ }) => {
300
+ const { groupByDomain } = (0, import_interface_logic4.useAppSelector)(import_interface_logic4.selectSearch);
301
+ const initModel = (0, import_interface_logic4.useModel)();
302
+ const [type, setType] = (0, import_react5.useState)("list");
303
+ const [mode, setMode] = (0, import_react5.useState)("month");
304
+ const [currentDate, setCurrentDate] = (0, import_react5.useState)(/* @__PURE__ */ new Date());
305
+ const { pageLimit, page, order } = (0, import_interface_logic4.useAppSelector)(import_interface_logic4.selectList);
306
+ const listDataProps = (0, import_react5.useMemo)(() => {
307
+ const actData = action?.result;
308
+ if (!viewResponse || !actData || !context) {
309
+ return null;
310
+ }
311
+ const specification = initModel.initModel({
312
+ name: String(actData.res_model),
313
+ view: viewResponse || {},
314
+ actContext: context,
315
+ fields: type === "kanban" ? viewResponse?.views?.kanban?.fields : type === "calendar" ? viewResponse?.views?.calendar?.fields : viewResponse?.views?.list?.fields
316
+ }).getSpecification();
317
+ const domain = type === "calendar" ? getDateRange(currentDate, mode) : actData?.domain ? Array.isArray(actData?.domain) ? [...actData?.domain] : (0, import_interface_logic4.evalJSONDomain)(actData?.domain, context) : [];
318
+ const limit = type === "calendar" ? 2500 : pageLimit;
319
+ const offset = page * pageLimit;
320
+ const fields = type === "calendar" ? convertFieldsToArray(viewResponse?.views?.calendar?.fields) || [] : typeof groupByDomain === "object" ? groupByDomain?.fields : void 0;
321
+ const groupby = typeof groupByDomain === "object" ? [groupByDomain?.contexts?.[0]?.group_by] : [];
322
+ const sort = order ? order : viewResponse?.views?.list?.default_order ? (0, import_interface_logic4.formatSortingString)(viewResponse?.views?.list?.default_order) : "";
323
+ return {
324
+ model: actData.res_model,
325
+ specification,
326
+ domain,
327
+ limit,
328
+ offset,
329
+ fields,
330
+ groupby,
331
+ context,
332
+ sort,
333
+ type
334
+ };
335
+ }, [
336
+ action?.result,
337
+ context,
338
+ currentDate,
339
+ groupByDomain,
340
+ initModel,
341
+ mode,
342
+ order,
343
+ page,
344
+ pageLimit,
345
+ type,
346
+ viewResponse
347
+ ]);
348
+ const list = (0, import_interface_logic4.useGetListData)(
349
+ listDataProps,
350
+ [listDataProps],
351
+ !!listDataProps
352
+ );
353
+ return {
354
+ ...list,
355
+ state: {
356
+ type,
357
+ setType,
358
+ mode,
359
+ setMode,
360
+ currentDate,
361
+ setCurrentDate
362
+ }
363
+ };
364
+ };
365
+
366
+ // src/hooks/core/use-menu.ts
367
+ var import_react6 = require("react");
368
+ var import_interface_logic5 = require("@fctc/interface-logic");
369
+
370
+ // src/utils/constants.ts
371
+ var languages = [
372
+ { id: "vi_VN", name: "VIE" },
373
+ { id: "en_US", name: "ENG" }
374
+ ];
375
+ var API_APP_URL = {
376
+ baseUrl: "https://api.vitrust.app",
377
+ c2: "https://api.vitrust.app/c2",
378
+ apiV2: "https://api.vitrust.app/c2/api/v2"
379
+ };
380
+
381
+ // src/hooks/core/use-menu.ts
382
+ var useMenu = ({ context }) => {
383
+ const menuData = (0, import_interface_logic5.useGetMenu)(context, !!context);
384
+ const [menuid, setMenuId] = (0, import_react6.useState)(void 0);
385
+ const [action, setAction] = useCallAction();
386
+ const configedIconData = (0, import_react6.useMemo)(() => {
387
+ const data = menuData.data;
388
+ return data?.map((item) => {
389
+ return {
390
+ ...item,
391
+ child_id: item?.child_id?.map((child) => {
392
+ return {
393
+ ...child,
394
+ url_icon: API_APP_URL.c2 + "/" + child.url_icon
395
+ };
396
+ }) ?? [],
397
+ url_icon: API_APP_URL.c2 + "/" + item.url_icon
398
+ };
399
+ });
400
+ }, [menuData.data]);
401
+ const handleChangeMenu = async ({
402
+ menu,
403
+ subMenu
404
+ }) => {
405
+ const aid = subMenu?.action?.id?.id;
406
+ const actionType = subMenu?.action?.type;
407
+ await setAction({
408
+ aid: Number(aid),
409
+ actionType
410
+ });
411
+ if (menu) {
412
+ setMenuId(menu.id?.toString() ?? "");
413
+ }
414
+ };
415
+ (0, import_react6.useEffect)(() => {
416
+ const firstRecord = configedIconData?.[0];
417
+ const firstChild = firstRecord?.child_id?.[0];
418
+ if (firstChild && firstRecord) {
419
+ handleChangeMenu({ menu: firstRecord, subMenu: firstChild });
420
+ }
421
+ }, [configedIconData]);
422
+ return {
423
+ ...menuData,
424
+ data: configedIconData,
425
+ action: { handleChangeMenu },
426
+ state: { menuid, action },
427
+ context
428
+ };
429
+ };
430
+
431
+ // src/hooks/core/use-profile.ts
432
+ var import_react_query2 = require("@tanstack/react-query");
433
+ var import_react7 = require("react");
434
+ var import_react_i18next = require("react-i18next");
435
+ var import_interface_logic6 = require("@fctc/interface-logic");
436
+ var useProfile = (accessToken) => {
437
+ const getProfile = (0, import_interface_logic6.useGetProfile)();
438
+ const dispatch = (0, import_interface_logic6.useAppDispatch)();
439
+ const { i18n } = (0, import_react_i18next.useTranslation)();
440
+ const fetchUserProfile = async () => {
441
+ return await getProfile.mutateAsync();
442
+ };
443
+ const userInfoQuery = (0, import_react_query2.useQuery)({
444
+ queryKey: ["userInfo", accessToken],
445
+ queryFn: fetchUserProfile,
446
+ enabled: !!accessToken
447
+ });
448
+ (0, import_react7.useEffect)(() => {
449
+ if (userInfoQuery.data) {
450
+ const userInfo = userInfoQuery.data;
451
+ const env = (0, import_interface_logic6.getEnv)();
452
+ env.setUid(userInfo?.sub);
453
+ dispatch((0, import_interface_logic6.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 = (0, import_react7.useMemo)(() => {
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
+ var import_react8 = require("react");
482
+ var import_interface_logic7 = require("@fctc/interface-logic");
483
+ var useViewV2 = ({
484
+ action,
485
+ context
486
+ }) => {
487
+ const viewParams = (0, import_react8.useMemo)(() => {
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 = (0, import_interface_logic7.useGetView)(
507
+ viewParams || {},
508
+ !!viewParams
509
+ );
510
+ return {
511
+ ...view,
512
+ context
513
+ };
514
+ };
515
+
516
+ // src/hooks/core/use-auth.ts
517
+ var import_interface_logic8 = require("@fctc/interface-logic");
518
+ var useAuth = () => {
519
+ const [[isLoading, accessToken], setAccessToken] = useStorageState("TOKEN");
520
+ const loginMutate = (0, import_interface_logic8.useLoginCredential)();
521
+ const dispatch = (0, import_interface_logic8.useAppDispatch)();
522
+ const signIn = async (email, password) => {
523
+ try {
524
+ loginMutate.mutate(
525
+ {
526
+ email,
527
+ password,
528
+ path: "/authentication/oauth2/token"
529
+ },
530
+ {
531
+ onSuccess: (res) => {
532
+ setAccessToken(res.access_token);
533
+ },
534
+ onError: (err) => {
535
+ }
536
+ }
537
+ );
538
+ } catch (error) {
539
+ throw new Error("Login failed");
540
+ }
541
+ };
542
+ const signOut = async () => {
543
+ dispatch((0, import_interface_logic8.setMenuList)([]));
544
+ dispatch((0, import_interface_logic8.setDataUser)({}));
545
+ dispatch((0, import_interface_logic8.setProfile)({}));
546
+ setAccessToken(null);
547
+ };
548
+ return {
549
+ signIn,
550
+ signOut,
551
+ accessToken,
552
+ isLoading
553
+ };
554
+ };
555
+
556
+ // src/hooks/core/use-app-provider.tsx
557
+ var import_react10 = require("react");
558
+
559
+ // src/hooks/core/use-company.ts
560
+ var import_interface_logic9 = require("@fctc/interface-logic");
561
+ var import_react_query3 = require("@tanstack/react-query");
562
+ var import_react9 = require("react");
563
+ var useCompany = (accessToken) => {
564
+ const getCurrentCompany = (0, import_interface_logic9.useGetCurrentCompany)();
565
+ const fetchCurrentCompany = async () => {
566
+ return await getCurrentCompany.mutateAsync();
567
+ };
568
+ const currentCompany = (0, import_react_query3.useQuery)({
569
+ queryKey: ["currentCompany", accessToken],
570
+ queryFn: fetchCurrentCompany,
571
+ enabled: !!accessToken
572
+ });
573
+ const current_company_id = (0, import_react9.useMemo)(() => {
574
+ return currentCompany.data?.current_company_id;
575
+ }, [currentCompany.data]);
576
+ (0, import_react9.useEffect)(() => {
577
+ if (current_company_id) {
578
+ const companyIDs = [current_company_id];
579
+ const env = (0, import_interface_logic9.getEnv)();
580
+ env.setAllowCompanies([...companyIDs]);
581
+ env.setCompanies(companyIDs);
582
+ }
583
+ }, [current_company_id]);
584
+ const getCompanyInfo = (0, import_interface_logic9.useGetCompanyInfo)();
585
+ const companyInfo = (0, import_react_query3.useQuery)({
586
+ queryKey: ["companyInfoQuery", current_company_id, accessToken],
587
+ queryFn: () => getCompanyInfo.mutateAsync(Number(current_company_id)),
588
+ enabled: !!current_company_id && !!accessToken
589
+ });
590
+ (0, import_react9.useEffect)(() => {
591
+ if (companyInfo.data) {
592
+ const companyInfoData = companyInfo.data;
593
+ if (companyInfoData?.length) {
594
+ const env = (0, import_interface_logic9.getEnv)();
595
+ env.setDefaultCompany(companyInfoData[0]);
596
+ }
597
+ }
598
+ }, [companyInfo.data]);
599
+ return {
600
+ currentCompany,
601
+ companyInfo,
602
+ context: { allowed_company_ids: [current_company_id] }
603
+ };
604
+ };
605
+ var use_company_default = useCompany;
606
+
607
+ // src/hooks/core/use-app-provider.tsx
608
+ var import_interface_logic10 = require("@fctc/interface-logic");
609
+ var import_jsx_runtime = require("react/jsx-runtime");
610
+ var AppProviderInitialValue = {
611
+ config: {},
612
+ user: {},
613
+ auth: {},
614
+ company: {},
615
+ action: {},
616
+ menu: {},
617
+ view: {},
618
+ list: {}
619
+ };
620
+ var ReactContext = (0, import_react10.createContext)(AppProviderInitialValue);
621
+ var AppProvider = ({ children }) => {
622
+ const config = useConfig({});
623
+ const auth = useAuth();
624
+ const user = useUser(auth.accessToken);
625
+ const company = use_company_default(auth.accessToken);
626
+ const menuContext = (0, import_react10.useMemo)(() => {
627
+ return combineContexts([user.context, company.context]);
628
+ }, [user.context, company.context]);
629
+ const menu = useMenu({ context: menuContext });
630
+ const action = (0, import_react10.useMemo)(() => {
631
+ return menu.state.action;
632
+ }, [menu.state.action]);
633
+ const viewContext = (0, import_react10.useMemo)(() => {
634
+ return combineContexts([
635
+ menuContext,
636
+ { ...(0, import_interface_logic10.evalJSONContext)(action?.result?.context) }
637
+ ]);
638
+ }, [menuContext, action?.result?.context]);
639
+ const view = useViewV2({
640
+ action,
641
+ context: viewContext
642
+ });
643
+ const list = useListData({
644
+ action,
645
+ viewResponse: view.data,
646
+ context: viewContext
647
+ });
648
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
649
+ ReactContext.Provider,
650
+ {
651
+ value: {
652
+ config,
653
+ auth,
654
+ user,
655
+ company,
656
+ menu,
657
+ list,
658
+ action,
659
+ view
660
+ },
661
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_interface_logic10.MainProvider, { children })
662
+ }
663
+ );
664
+ };
665
+ var useAppProvider = () => {
666
+ const context = (0, import_react10.useContext)(ReactContext);
667
+ if (!context) {
668
+ return AppProviderInitialValue;
669
+ }
670
+ return context;
671
+ };
672
+
673
+ // src/hooks/utils/use-click-outside.ts
674
+ var import_react11 = require("react");
675
+ var DEFAULT_EVENTS = ["mousedown", "touchstart"];
676
+ var useClickOutside = ({
677
+ handler,
678
+ events = DEFAULT_EVENTS,
679
+ nodes = [],
680
+ refs
681
+ }) => {
682
+ const ref = (0, import_react11.useRef)(null);
683
+ (0, import_react11.useEffect)(() => {
684
+ const listener = (event) => {
685
+ const { target } = event;
686
+ if (refs && refs?.length > 0 && refs?.some((r) => r.current?.contains(target))) {
687
+ return;
688
+ }
689
+ if (!(target instanceof HTMLElement)) return;
690
+ const shouldIgnore = target.hasAttribute("data-ignore-outside-clicks") || !document.body.contains(target) && target.tagName !== "HTML";
691
+ const shouldTrigger = nodes.length > 0 ? nodes.every((node) => node && !event.composedPath().includes(node)) : ref.current && !ref.current.contains(target);
692
+ if (shouldTrigger && !shouldIgnore) {
693
+ handler(event);
694
+ }
695
+ };
696
+ events.forEach((event) => document.addEventListener(event, listener));
697
+ return () => {
698
+ events.forEach((event) => document.removeEventListener(event, listener));
699
+ };
700
+ }, [handler, nodes, events]);
701
+ return ref;
702
+ };
703
+
704
+ // src/hooks/utils/use-debounce.ts
705
+ var import_react12 = require("react");
706
+ function useDebounce(value, delay) {
707
+ const [debouncedValue, setDebouncedValue] = (0, import_react12.useState)(value);
708
+ (0, import_react12.useEffect)(() => {
709
+ const handler = setTimeout(() => {
710
+ setDebouncedValue(value);
711
+ }, delay);
712
+ return () => {
713
+ clearTimeout(handler);
714
+ };
715
+ }, [value, delay]);
716
+ return [debouncedValue];
717
+ }
718
+
719
+ // src/hooks/api/use-switch-locale.ts
720
+ var import_interface_logic11 = require("@fctc/interface-logic");
721
+ var import_react13 = require("react");
722
+ var useSwitchLocaleHandler = () => {
723
+ const switchUserLocale = (0, import_interface_logic11.useSwitchLocale)();
724
+ const env = (0, import_interface_logic11.getEnv)();
725
+ const { context } = (0, import_interface_logic11.useAppSelector)(import_interface_logic11.selectEnv);
726
+ const switchLocale = (0, import_react13.useCallback)(
727
+ async (langId) => {
728
+ if (!langId) return;
729
+ await switchUserLocale.mutateAsync({
730
+ data: {
731
+ id: parseInt(context?.uid),
732
+ values: { lang: langId }
733
+ }
734
+ });
735
+ env.setLang(langId);
736
+ },
737
+ [switchUserLocale]
738
+ );
739
+ return {
740
+ switchLocale,
741
+ isLoading: switchUserLocale.isPending,
742
+ error: switchUserLocale.error
743
+ };
744
+ };
745
+
746
+ // src/hooks/api/use-login.ts
747
+ var import_interface_logic12 = require("@fctc/interface-logic");
748
+ var import_react14 = require("react");
749
+ var useLoginHandler = () => {
750
+ const loginMutate = (0, import_interface_logic12.useLoginCredential)();
751
+ const login = (0, import_react14.useCallback)(
752
+ ({
753
+ email,
754
+ password,
755
+ path
756
+ }, {
757
+ onSuccess,
758
+ onError
759
+ }) => {
760
+ loginMutate.mutate(
761
+ {
762
+ email,
763
+ password,
764
+ path
765
+ },
766
+ {
767
+ onSuccess,
768
+ onError
769
+ }
770
+ );
771
+ },
772
+ [loginMutate]
773
+ );
774
+ return {
775
+ login,
776
+ isLoading: loginMutate.isPending,
777
+ error: loginMutate.error
778
+ };
779
+ };
780
+
781
+ // src/hooks/api/use-forgot-password.ts
782
+ var import_interface_logic13 = require("@fctc/interface-logic");
783
+ var import_react15 = require("react");
784
+ var useForgotPasswordHandler = () => {
785
+ const forgotPasswordMutate = (0, import_interface_logic13.useForgotPassword)();
786
+ const sendForgotPassword = (0, import_react15.useCallback)(
787
+ (email, {
788
+ onSuccess,
789
+ onError
790
+ } = {}) => {
791
+ forgotPasswordMutate.mutate(email, {
792
+ onSuccess,
793
+ onError
794
+ });
795
+ },
796
+ [forgotPasswordMutate]
797
+ );
798
+ return {
799
+ sendForgotPassword,
800
+ isLoading: forgotPasswordMutate.isPending,
801
+ error: forgotPasswordMutate.error
802
+ };
803
+ };
804
+
805
+ // src/hooks/api/use-reset-password.ts
806
+ var import_interface_logic14 = require("@fctc/interface-logic");
807
+ var import_react16 = require("react");
808
+ var useResetPasswordHandler = () => {
809
+ const resetPasswordMutate = (0, import_interface_logic14.useResetPassword)();
810
+ const resetPassword = (0, import_react16.useCallback)(
811
+ ({
812
+ password,
813
+ confirmPassword,
814
+ token
815
+ }, {
816
+ onSuccess,
817
+ onError
818
+ }) => {
819
+ resetPasswordMutate.mutate(
820
+ {
821
+ data: {
822
+ password,
823
+ confirmPassword
824
+ },
825
+ token
826
+ },
827
+ {
828
+ onSuccess,
829
+ onError
830
+ }
831
+ );
832
+ },
833
+ [resetPasswordMutate]
834
+ );
835
+ return {
836
+ resetPassword,
837
+ isLoading: resetPasswordMutate.isPending,
838
+ error: resetPasswordMutate.error
839
+ };
840
+ };
841
+ // Annotate the CommonJS export names for ESM import in node:
842
+ 0 && (module.exports = {
843
+ AppProvider,
844
+ useAppProvider,
845
+ useAuth,
846
+ useCallAction,
847
+ useClickOutside,
848
+ useConfig,
849
+ useDebounce,
850
+ useDetail,
851
+ useForgotPasswordHandler,
852
+ useListData,
853
+ useLoginHandler,
854
+ useMenu,
855
+ useProfile,
856
+ useResetPasswordHandler,
857
+ useSwitchLocaleHandler,
858
+ useUser,
859
+ useViewV2
860
+ });