@fctc/widget-logic 1.1.6 → 1.1.8

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.mjs CHANGED
@@ -214,6 +214,16 @@ var convertFieldsToArray = (fields) => {
214
214
  const inputFields = fields.filter((field) => field && field.type_co === "field").map((field) => field.name);
215
215
  return [...defaultFields, ...inputFields];
216
216
  };
217
+ function combineContexts(contexts) {
218
+ if (contexts.some((context) => !context)) {
219
+ return void 0;
220
+ } else {
221
+ const res = contexts.reduce((acc, context) => {
222
+ return { ...acc, ...context };
223
+ }, {});
224
+ return res;
225
+ }
226
+ }
217
227
  function useAsyncState(initialValue = [true, null]) {
218
228
  return useReducer(
219
229
  (_state, action = null) => [false, action],
@@ -524,8 +534,129 @@ var useAuth = () => {
524
534
  };
525
535
  };
526
536
 
537
+ // src/hooks/core/use-app-provider.tsx
538
+ import { createContext, useContext, useMemo as useMemo7 } from "react";
539
+
540
+ // src/hooks/core/use-company.ts
541
+ import {
542
+ getEnv as getEnv4,
543
+ useGetCompanyInfo,
544
+ useGetCurrentCompany
545
+ } from "@fctc/interface-logic";
546
+ import { useQuery as useQuery3 } from "@tanstack/react-query";
547
+ import { useEffect as useEffect6, useMemo as useMemo6 } from "react";
548
+ var useCompany = (accessToken) => {
549
+ const getCurrentCompany = useGetCurrentCompany();
550
+ const fetchCurrentCompany = async () => {
551
+ return await getCurrentCompany.mutateAsync();
552
+ };
553
+ const currentCompany = useQuery3({
554
+ queryKey: ["currentCompany", accessToken],
555
+ queryFn: fetchCurrentCompany,
556
+ enabled: !!accessToken
557
+ });
558
+ const current_company_id = useMemo6(() => {
559
+ return currentCompany.data?.current_company_id;
560
+ }, [currentCompany.data]);
561
+ useEffect6(() => {
562
+ if (current_company_id) {
563
+ const companyIDs = [current_company_id];
564
+ const env = getEnv4();
565
+ env.setAllowCompanies([...companyIDs]);
566
+ env.setCompanies(companyIDs);
567
+ }
568
+ }, [current_company_id]);
569
+ const getCompanyInfo = useGetCompanyInfo();
570
+ const companyInfo = useQuery3({
571
+ queryKey: ["companyInfoQuery", current_company_id, accessToken],
572
+ queryFn: () => getCompanyInfo.mutateAsync(Number(current_company_id)),
573
+ enabled: !!current_company_id && !!accessToken
574
+ });
575
+ useEffect6(() => {
576
+ if (companyInfo.data) {
577
+ const companyInfoData = companyInfo.data;
578
+ if (companyInfoData?.length) {
579
+ const env = getEnv4();
580
+ env.setDefaultCompany(companyInfoData[0]);
581
+ }
582
+ }
583
+ }, [companyInfo.data]);
584
+ return {
585
+ currentCompany,
586
+ companyInfo,
587
+ context: { allowed_company_ids: [current_company_id] }
588
+ };
589
+ };
590
+ var use_company_default = useCompany;
591
+
592
+ // src/hooks/core/use-app-provider.tsx
593
+ import { evalJSONContext } from "@fctc/interface-logic";
594
+ import { jsx } from "react/jsx-runtime";
595
+ var AppProviderInitialValue = {
596
+ config: {},
597
+ user: {},
598
+ auth: {},
599
+ company: {},
600
+ action: {},
601
+ menu: {},
602
+ view: {},
603
+ list: {}
604
+ };
605
+ var ReactContext = createContext(AppProviderInitialValue);
606
+ var AppProvider = ({ children }) => {
607
+ const config = useConfig({});
608
+ const auth = useAuth();
609
+ const user = useUser(auth.accessToken);
610
+ const company = use_company_default(auth.accessToken);
611
+ const menuContext = useMemo7(() => {
612
+ return combineContexts([user.context, company.context]);
613
+ }, [user.context, company.context]);
614
+ const menu = useMenu({ context: menuContext });
615
+ const action = useMemo7(() => {
616
+ return menu.state.action;
617
+ }, [menu.state.action]);
618
+ const viewContext = useMemo7(() => {
619
+ return combineContexts([
620
+ menuContext,
621
+ { ...evalJSONContext(action?.result?.context) }
622
+ ]);
623
+ }, [menuContext, action?.result?.context]);
624
+ const view = useViewV2({
625
+ action,
626
+ context: viewContext
627
+ });
628
+ const list = useListData({
629
+ action,
630
+ viewResponse: view.data,
631
+ context: viewContext
632
+ });
633
+ return /* @__PURE__ */ jsx(
634
+ ReactContext.Provider,
635
+ {
636
+ value: {
637
+ config,
638
+ auth,
639
+ user,
640
+ company,
641
+ menu,
642
+ list,
643
+ action,
644
+ view
645
+ },
646
+ children
647
+ }
648
+ );
649
+ };
650
+ var useAppProvider = () => {
651
+ const context = useContext(ReactContext);
652
+ if (!context) {
653
+ return AppProviderInitialValue;
654
+ }
655
+ return context;
656
+ };
657
+
527
658
  // src/hooks/utils/use-click-outside.ts
528
- import { useEffect as useEffect6, useRef as useRef2 } from "react";
659
+ import { useEffect as useEffect7, useRef as useRef2 } from "react";
529
660
  var DEFAULT_EVENTS = ["mousedown", "touchstart"];
530
661
  var useClickOutside = ({
531
662
  handler,
@@ -534,7 +665,7 @@ var useClickOutside = ({
534
665
  refs
535
666
  }) => {
536
667
  const ref = useRef2(null);
537
- useEffect6(() => {
668
+ useEffect7(() => {
538
669
  const listener = (event) => {
539
670
  const { target } = event;
540
671
  if (refs && refs?.length > 0 && refs?.some((r) => r.current?.contains(target))) {
@@ -556,10 +687,10 @@ var useClickOutside = ({
556
687
  };
557
688
 
558
689
  // src/hooks/utils/use-debounce.ts
559
- import { useEffect as useEffect7, useState as useState5 } from "react";
690
+ import { useEffect as useEffect8, useState as useState5 } from "react";
560
691
  function useDebounce(value, delay) {
561
692
  const [debouncedValue, setDebouncedValue] = useState5(value);
562
- useEffect7(() => {
693
+ useEffect8(() => {
563
694
  const handler = setTimeout(() => {
564
695
  setDebouncedValue(value);
565
696
  }, delay);
@@ -569,16 +700,150 @@ function useDebounce(value, delay) {
569
700
  }, [value, delay]);
570
701
  return [debouncedValue];
571
702
  }
703
+
704
+ // src/hooks/api/use-switch-locale.ts
705
+ import {
706
+ getEnv as getEnv5,
707
+ selectEnv,
708
+ useAppSelector as useAppSelector2,
709
+ useSwitchLocale
710
+ } from "@fctc/interface-logic";
711
+ import { useCallback as useCallback2 } from "react";
712
+ var useSwitchLocaleHandler = () => {
713
+ const switchUserLocale = useSwitchLocale();
714
+ const env = getEnv5();
715
+ const { context } = useAppSelector2(selectEnv);
716
+ const switchLocale = useCallback2(
717
+ async (langId) => {
718
+ if (!langId) return;
719
+ await switchUserLocale.mutateAsync({
720
+ data: {
721
+ id: parseInt(context?.uid),
722
+ values: { lang: langId }
723
+ }
724
+ });
725
+ env.setLang(langId);
726
+ },
727
+ [switchUserLocale]
728
+ );
729
+ return {
730
+ switchLocale,
731
+ isLoading: switchUserLocale.isPending,
732
+ error: switchUserLocale.error
733
+ };
734
+ };
735
+
736
+ // src/hooks/api/use-login.ts
737
+ import { useLoginCredential as useLoginCredential2 } from "@fctc/interface-logic";
738
+ import { useCallback as useCallback3 } from "react";
739
+ var useLoginHandler = () => {
740
+ const loginMutate = useLoginCredential2();
741
+ const login = useCallback3(
742
+ ({
743
+ email,
744
+ password,
745
+ path
746
+ }, {
747
+ onSuccess,
748
+ onError
749
+ }) => {
750
+ loginMutate.mutate(
751
+ {
752
+ email,
753
+ password,
754
+ path
755
+ },
756
+ {
757
+ onSuccess,
758
+ onError
759
+ }
760
+ );
761
+ },
762
+ [loginMutate]
763
+ );
764
+ return {
765
+ login,
766
+ isLoading: loginMutate.isPending,
767
+ error: loginMutate.error
768
+ };
769
+ };
770
+
771
+ // src/hooks/api/use-forgot-password.ts
772
+ import { useForgotPassword } from "@fctc/interface-logic";
773
+ import { useCallback as useCallback4 } from "react";
774
+ var useForgotPasswordHandler = () => {
775
+ const forgotPasswordMutate = useForgotPassword();
776
+ const sendForgotPassword = useCallback4(
777
+ (email, {
778
+ onSuccess,
779
+ onError
780
+ } = {}) => {
781
+ forgotPasswordMutate.mutate(email, {
782
+ onSuccess,
783
+ onError
784
+ });
785
+ },
786
+ [forgotPasswordMutate]
787
+ );
788
+ return {
789
+ sendForgotPassword,
790
+ isLoading: forgotPasswordMutate.isPending,
791
+ error: forgotPasswordMutate.error
792
+ };
793
+ };
794
+
795
+ // src/hooks/api/use-reset-password.ts
796
+ import { useResetPassword } from "@fctc/interface-logic";
797
+ import { useCallback as useCallback5 } from "react";
798
+ var useResetPasswordHandler = () => {
799
+ const resetPasswordMutate = useResetPassword();
800
+ const resetPassword = useCallback5(
801
+ ({
802
+ password,
803
+ confirmPassword,
804
+ token
805
+ }, {
806
+ onSuccess,
807
+ onError
808
+ }) => {
809
+ resetPasswordMutate.mutate(
810
+ {
811
+ data: {
812
+ password,
813
+ confirmPassword
814
+ },
815
+ token
816
+ },
817
+ {
818
+ onSuccess,
819
+ onError
820
+ }
821
+ );
822
+ },
823
+ [resetPasswordMutate]
824
+ );
825
+ return {
826
+ resetPassword,
827
+ isLoading: resetPasswordMutate.isPending,
828
+ error: resetPasswordMutate.error
829
+ };
830
+ };
572
831
  export {
832
+ AppProvider,
833
+ useAppProvider,
573
834
  useAuth,
574
835
  useCallAction,
575
836
  useClickOutside,
576
837
  useConfig,
577
838
  useDebounce,
578
839
  useDetail,
840
+ useForgotPasswordHandler,
579
841
  useListData,
842
+ useLoginHandler,
580
843
  useMenu,
581
844
  useProfile,
845
+ useResetPasswordHandler,
846
+ useSwitchLocaleHandler,
582
847
  useUser,
583
848
  useViewV2
584
849
  };
package/dist/index.d.mts CHANGED
@@ -1,17 +1,15 @@
1
- export { ActionResultType, Context, Record, ViewResponse, useAuth, useAuthType, useCallAction, useCallActionType, useClickOutside, useConfig, useConfigType, useDebounce, useDetail, useListData, useListDataType, useMenu, useMenuType, useProfile, useUser, useUserType, useViewV2, useViewV2Type } from './hooks.mjs';
1
+ export { ActionResultType, AppProvider, Context, Record, ViewResponse, useAppProvider, useAuth, useAuthType, useCallAction, useCallActionType, useClickOutside, useConfig, useConfigType, useDebounce, useDetail, useForgotPasswordHandler, useListData, useListDataType, useLoginHandler, useMenu, useMenuType, useProfile, useResetPasswordHandler, useSwitchLocaleHandler, useUser, useUserType, useViewV2, useViewV2Type } from './hooks.mjs';
2
2
  export { CloseIcon, EyeIcon, LoadingIcon } from './icons.mjs';
3
3
  import { IInputFieldProps, ValuePropsType } from './types.mjs';
4
4
  import * as react from 'react';
5
5
  import { ChangeEvent } from 'react';
6
- import * as _fctc_interface_logic from '@fctc/interface-logic';
7
- import { BaseModelInit } from '@fctc/interface-logic';
8
- import * as _fctc_interface_logic_dist_index_C_nK1Mii from '@fctc/interface-logic/dist/index-C_nK1Mii';
9
6
  import day from 'react-datepicker/dist/day';
10
7
  import month from 'react-datepicker/dist/month';
11
8
  import year from 'react-datepicker/dist/year';
12
9
  import moment from 'moment';
13
10
  export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useGetRowIds, useStorageState } from './utils.mjs';
14
11
  import '@tanstack/react-query';
12
+ import '@fctc/interface-logic';
15
13
 
16
14
  type TStatus = 'normal' | 'done' | 'blocked';
17
15
  interface TStatusDropdownFieldProps extends IInputFieldProps {
@@ -31,39 +29,34 @@ declare const statusDropdownController: (props: TStatusDropdownFieldProps) => {
31
29
  colors: Record<TStatus, string>;
32
30
  };
33
31
 
34
- interface Many2OneProps {
35
- name: string;
36
- methods: any;
37
- formValues: any;
38
- domain: any;
39
- relation: any;
40
- onChange: any;
41
- value: any;
42
- context: any;
43
- options: any;
44
- showDetail: any;
45
- actionData: any;
32
+ interface IMany2OneProps extends IInputFieldProps {
33
+ context?: any;
34
+ options?: any;
35
+ showDetail?: boolean;
36
+ actionData?: any;
46
37
  }
47
38
 
48
- declare const many2oneFieldController: (props: Many2OneProps) => {
49
- allowShowDetail: any;
39
+ declare const many2oneFieldController: (props: IMany2OneProps) => {
40
+ allowShowDetail: boolean;
50
41
  handleClose: () => void;
51
42
  handleChooseRecord: (idRecord: number) => void;
52
43
  handleSelectChange: (selectedOption: any) => void;
53
44
  initValue: any;
54
45
  isFetching: boolean;
55
46
  isShowModalMany2Many: boolean;
56
- options: never[];
57
- domainModal: null;
47
+ options: any[];
48
+ fetchMoreOptions: () => void;
49
+ domainModal: any;
58
50
  tempSelectedOption: any;
59
- setTempSelectedOption: react.Dispatch<any>;
60
- setDomainModal: react.Dispatch<react.SetStateAction<null>>;
51
+ setTempSelectedOption: React.Dispatch<React.SetStateAction<any>>;
52
+ setDomainModal: React.Dispatch<React.SetStateAction<any>>;
61
53
  dataOfSelection: any;
62
- selectOptions: any;
63
- optionsObject: {};
54
+ refetch: () => void;
55
+ selectOptions: any[];
56
+ optionsObject: any;
64
57
  contextObject: any;
65
58
  actionId: any;
66
- setIsShowModalMany2Many: react.Dispatch<react.SetStateAction<boolean>>;
59
+ setIsShowModalMany2Many: React.Dispatch<React.SetStateAction<boolean>>;
67
60
  };
68
61
 
69
62
  type Option = {
@@ -74,12 +67,9 @@ declare const many2oneButtonController: (props: IInputFieldProps) => {
74
67
  options: Option[];
75
68
  };
76
69
 
77
- interface Many2ManyControllerProps {
78
- relation: string;
79
- domain: any;
70
+ interface IMany2ManyControllerProps extends IInputFieldProps {
80
71
  context: any;
81
72
  tab: any;
82
- model: string;
83
73
  aid: number;
84
74
  setSelectedRowKeys: any;
85
75
  fields: any;
@@ -90,48 +80,7 @@ interface Many2ManyControllerProps {
90
80
  sessionStorageUtils: any;
91
81
  }
92
82
 
93
- declare const many2manyFieldController: (props: Many2ManyControllerProps) => {
94
- rows: any[];
95
- columns: any;
96
- typeTable: "list" | "calendar" | "group" | undefined;
97
- handleCreateNewOnPage: () => Promise<void>;
98
- isLoadedData: boolean;
99
- domainMany2Many: any;
100
- isDataLoading: boolean;
101
- isDataResponseFetched: boolean;
102
- isPlaceholderData: boolean;
103
- queryKey: any[];
104
- data: {
105
- model: string;
106
- specification: Record<string, any> | null;
107
- domain: any;
108
- offset: number;
109
- limit: number;
110
- context: any;
111
- fields: any;
112
- groupby: any[];
113
- sort: string | null;
114
- };
115
- specification: Record<string, any> | null;
116
- enabled: boolean;
117
- isViewReponseFetched: boolean;
118
- actionData: any;
119
- viewResponse: any;
120
- debouncedPage: number;
121
- order: undefined;
122
- default_order: any;
123
- optionsObject: {} | null;
124
- setDomainMany2Many: react.Dispatch<any>;
125
- selectedTags: [];
126
- initModel: {
127
- initModel: (modelData: _fctc_interface_logic_dist_index_C_nK1Mii.a) => _fctc_interface_logic.BaseModel;
128
- };
129
- modelInstance: _fctc_interface_logic.BaseModel | null;
130
- baseModel: BaseModelInit;
131
- dataResponse: any;
132
- isLoading: boolean;
133
- setOrder: react.Dispatch<react.SetStateAction<undefined>>;
134
- };
83
+ declare const many2manyFieldController: (props: IMany2ManyControllerProps) => {};
135
84
 
136
85
  interface IMany2ManyTagFieldProps extends IInputFieldProps {
137
86
  options: any;
package/dist/index.d.ts CHANGED
@@ -1,17 +1,15 @@
1
- export { ActionResultType, Context, Record, ViewResponse, useAuth, useAuthType, useCallAction, useCallActionType, useClickOutside, useConfig, useConfigType, useDebounce, useDetail, useListData, useListDataType, useMenu, useMenuType, useProfile, useUser, useUserType, useViewV2, useViewV2Type } from './hooks.js';
1
+ export { ActionResultType, AppProvider, Context, Record, ViewResponse, useAppProvider, useAuth, useAuthType, useCallAction, useCallActionType, useClickOutside, useConfig, useConfigType, useDebounce, useDetail, useForgotPasswordHandler, useListData, useListDataType, useLoginHandler, useMenu, useMenuType, useProfile, useResetPasswordHandler, useSwitchLocaleHandler, useUser, useUserType, useViewV2, useViewV2Type } from './hooks.js';
2
2
  export { CloseIcon, EyeIcon, LoadingIcon } from './icons.js';
3
3
  import { IInputFieldProps, ValuePropsType } from './types.js';
4
4
  import * as react from 'react';
5
5
  import { ChangeEvent } from 'react';
6
- import * as _fctc_interface_logic from '@fctc/interface-logic';
7
- import { BaseModelInit } from '@fctc/interface-logic';
8
- import * as _fctc_interface_logic_dist_index_C_nK1Mii from '@fctc/interface-logic/dist/index-C_nK1Mii';
9
6
  import day from 'react-datepicker/dist/day';
10
7
  import month from 'react-datepicker/dist/month';
11
8
  import year from 'react-datepicker/dist/year';
12
9
  import moment from 'moment';
13
10
  export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useGetRowIds, useStorageState } from './utils.js';
14
11
  import '@tanstack/react-query';
12
+ import '@fctc/interface-logic';
15
13
 
16
14
  type TStatus = 'normal' | 'done' | 'blocked';
17
15
  interface TStatusDropdownFieldProps extends IInputFieldProps {
@@ -31,39 +29,34 @@ declare const statusDropdownController: (props: TStatusDropdownFieldProps) => {
31
29
  colors: Record<TStatus, string>;
32
30
  };
33
31
 
34
- interface Many2OneProps {
35
- name: string;
36
- methods: any;
37
- formValues: any;
38
- domain: any;
39
- relation: any;
40
- onChange: any;
41
- value: any;
42
- context: any;
43
- options: any;
44
- showDetail: any;
45
- actionData: any;
32
+ interface IMany2OneProps extends IInputFieldProps {
33
+ context?: any;
34
+ options?: any;
35
+ showDetail?: boolean;
36
+ actionData?: any;
46
37
  }
47
38
 
48
- declare const many2oneFieldController: (props: Many2OneProps) => {
49
- allowShowDetail: any;
39
+ declare const many2oneFieldController: (props: IMany2OneProps) => {
40
+ allowShowDetail: boolean;
50
41
  handleClose: () => void;
51
42
  handleChooseRecord: (idRecord: number) => void;
52
43
  handleSelectChange: (selectedOption: any) => void;
53
44
  initValue: any;
54
45
  isFetching: boolean;
55
46
  isShowModalMany2Many: boolean;
56
- options: never[];
57
- domainModal: null;
47
+ options: any[];
48
+ fetchMoreOptions: () => void;
49
+ domainModal: any;
58
50
  tempSelectedOption: any;
59
- setTempSelectedOption: react.Dispatch<any>;
60
- setDomainModal: react.Dispatch<react.SetStateAction<null>>;
51
+ setTempSelectedOption: React.Dispatch<React.SetStateAction<any>>;
52
+ setDomainModal: React.Dispatch<React.SetStateAction<any>>;
61
53
  dataOfSelection: any;
62
- selectOptions: any;
63
- optionsObject: {};
54
+ refetch: () => void;
55
+ selectOptions: any[];
56
+ optionsObject: any;
64
57
  contextObject: any;
65
58
  actionId: any;
66
- setIsShowModalMany2Many: react.Dispatch<react.SetStateAction<boolean>>;
59
+ setIsShowModalMany2Many: React.Dispatch<React.SetStateAction<boolean>>;
67
60
  };
68
61
 
69
62
  type Option = {
@@ -74,12 +67,9 @@ declare const many2oneButtonController: (props: IInputFieldProps) => {
74
67
  options: Option[];
75
68
  };
76
69
 
77
- interface Many2ManyControllerProps {
78
- relation: string;
79
- domain: any;
70
+ interface IMany2ManyControllerProps extends IInputFieldProps {
80
71
  context: any;
81
72
  tab: any;
82
- model: string;
83
73
  aid: number;
84
74
  setSelectedRowKeys: any;
85
75
  fields: any;
@@ -90,48 +80,7 @@ interface Many2ManyControllerProps {
90
80
  sessionStorageUtils: any;
91
81
  }
92
82
 
93
- declare const many2manyFieldController: (props: Many2ManyControllerProps) => {
94
- rows: any[];
95
- columns: any;
96
- typeTable: "list" | "calendar" | "group" | undefined;
97
- handleCreateNewOnPage: () => Promise<void>;
98
- isLoadedData: boolean;
99
- domainMany2Many: any;
100
- isDataLoading: boolean;
101
- isDataResponseFetched: boolean;
102
- isPlaceholderData: boolean;
103
- queryKey: any[];
104
- data: {
105
- model: string;
106
- specification: Record<string, any> | null;
107
- domain: any;
108
- offset: number;
109
- limit: number;
110
- context: any;
111
- fields: any;
112
- groupby: any[];
113
- sort: string | null;
114
- };
115
- specification: Record<string, any> | null;
116
- enabled: boolean;
117
- isViewReponseFetched: boolean;
118
- actionData: any;
119
- viewResponse: any;
120
- debouncedPage: number;
121
- order: undefined;
122
- default_order: any;
123
- optionsObject: {} | null;
124
- setDomainMany2Many: react.Dispatch<any>;
125
- selectedTags: [];
126
- initModel: {
127
- initModel: (modelData: _fctc_interface_logic_dist_index_C_nK1Mii.a) => _fctc_interface_logic.BaseModel;
128
- };
129
- modelInstance: _fctc_interface_logic.BaseModel | null;
130
- baseModel: BaseModelInit;
131
- dataResponse: any;
132
- isLoading: boolean;
133
- setOrder: react.Dispatch<react.SetStateAction<undefined>>;
134
- };
83
+ declare const many2manyFieldController: (props: IMany2ManyControllerProps) => {};
135
84
 
136
85
  interface IMany2ManyTagFieldProps extends IInputFieldProps {
137
86
  options: any;