@fctc/widget-logic 1.1.7 → 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,4 +1,4 @@
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';
@@ -37,24 +37,26 @@ interface IMany2OneProps extends IInputFieldProps {
37
37
  }
38
38
 
39
39
  declare const many2oneFieldController: (props: IMany2OneProps) => {
40
- allowShowDetail: any;
40
+ allowShowDetail: boolean;
41
41
  handleClose: () => void;
42
42
  handleChooseRecord: (idRecord: number) => void;
43
43
  handleSelectChange: (selectedOption: any) => void;
44
44
  initValue: any;
45
45
  isFetching: boolean;
46
46
  isShowModalMany2Many: boolean;
47
- options: never[];
48
- domainModal: null;
47
+ options: any[];
48
+ fetchMoreOptions: () => void;
49
+ domainModal: any;
49
50
  tempSelectedOption: any;
50
- setTempSelectedOption: react.Dispatch<any>;
51
- setDomainModal: react.Dispatch<react.SetStateAction<null>>;
51
+ setTempSelectedOption: React.Dispatch<React.SetStateAction<any>>;
52
+ setDomainModal: React.Dispatch<React.SetStateAction<any>>;
52
53
  dataOfSelection: any;
53
- selectOptions: any;
54
- optionsObject: {};
54
+ refetch: () => void;
55
+ selectOptions: any[];
56
+ optionsObject: any;
55
57
  contextObject: any;
56
58
  actionId: any;
57
- setIsShowModalMany2Many: react.Dispatch<react.SetStateAction<boolean>>;
59
+ setIsShowModalMany2Many: React.Dispatch<React.SetStateAction<boolean>>;
58
60
  };
59
61
 
60
62
  type Option = {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
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';
@@ -37,24 +37,26 @@ interface IMany2OneProps extends IInputFieldProps {
37
37
  }
38
38
 
39
39
  declare const many2oneFieldController: (props: IMany2OneProps) => {
40
- allowShowDetail: any;
40
+ allowShowDetail: boolean;
41
41
  handleClose: () => void;
42
42
  handleChooseRecord: (idRecord: number) => void;
43
43
  handleSelectChange: (selectedOption: any) => void;
44
44
  initValue: any;
45
45
  isFetching: boolean;
46
46
  isShowModalMany2Many: boolean;
47
- options: never[];
48
- domainModal: null;
47
+ options: any[];
48
+ fetchMoreOptions: () => void;
49
+ domainModal: any;
49
50
  tempSelectedOption: any;
50
- setTempSelectedOption: react.Dispatch<any>;
51
- setDomainModal: react.Dispatch<react.SetStateAction<null>>;
51
+ setTempSelectedOption: React.Dispatch<React.SetStateAction<any>>;
52
+ setDomainModal: React.Dispatch<React.SetStateAction<any>>;
52
53
  dataOfSelection: any;
53
- selectOptions: any;
54
- optionsObject: {};
54
+ refetch: () => void;
55
+ selectOptions: any[];
56
+ optionsObject: any;
55
57
  contextObject: any;
56
58
  actionId: any;
57
- setIsShowModalMany2Many: react.Dispatch<react.SetStateAction<boolean>>;
59
+ setIsShowModalMany2Many: React.Dispatch<React.SetStateAction<boolean>>;
58
60
  };
59
61
 
60
62
  type Option = {