@fctc/interface-logic 1.9.1 → 1.9.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.mjs CHANGED
@@ -2402,700 +2402,126 @@ var axiosClient = {
2402
2402
  }
2403
2403
  };
2404
2404
 
2405
- // src/store/index.ts
2406
- import { useDispatch, useSelector } from "react-redux";
2407
-
2408
- // src/store/reducers/breadcrums-slice/index.ts
2409
- import { createSlice } from "@reduxjs/toolkit";
2410
- var initialState = {
2411
- breadCrumbs: []
2412
- };
2413
- var breadcrumbsSlice = createSlice({
2414
- name: "breadcrumbs",
2415
- initialState,
2416
- reducers: {
2417
- setBreadCrumbs: (state, action) => {
2418
- state.breadCrumbs = [...state.breadCrumbs, action.payload];
2419
- }
2420
- }
2421
- });
2422
- var { setBreadCrumbs } = breadcrumbsSlice.actions;
2423
- var breadcrums_slice_default = breadcrumbsSlice.reducer;
2424
-
2425
- // src/store/reducers/env-slice/index.ts
2426
- import { createSlice as createSlice2 } from "@reduxjs/toolkit";
2427
- var initialState2 = {
2428
- baseUrl: "",
2429
- companies: [],
2430
- user: {},
2431
- db: "",
2432
- refreshTokenEndpoint: "",
2433
- config: null,
2434
- envFile: null,
2435
- requests: null,
2436
- defaultCompany: {
2437
- id: null,
2438
- logo: "",
2439
- secondary_color: "",
2440
- primary_color: ""
2441
- },
2442
- context: {
2443
- uid: null,
2444
- allowed_company_ids: [],
2445
- lang: "vi_VN",
2446
- tz: "Asia/Saigon"
2447
- }
2448
- };
2449
- var envSlice = createSlice2({
2450
- name: "env",
2451
- initialState: initialState2,
2452
- reducers: {
2453
- setEnv: (state, action) => {
2454
- Object.assign(state, action.payload);
2455
- },
2456
- setUid: (state, action) => {
2457
- state.context.uid = action.payload;
2458
- },
2459
- setAllowCompanies: (state, action) => {
2460
- state.context.allowed_company_ids = action.payload;
2461
- },
2462
- setCompanies: (state, action) => {
2463
- state.companies = action.payload;
2464
- },
2465
- setDefaultCompany: (state, action) => {
2466
- state.defaultCompany = action.payload;
2467
- },
2468
- setLang: (state, action) => {
2469
- state.context.lang = action.payload;
2470
- },
2471
- setUser: (state, action) => {
2472
- state.user = action.payload;
2473
- },
2474
- setConfig: (state, action) => {
2475
- state.config = action.payload;
2476
- },
2477
- setEnvFile: (state, action) => {
2478
- state.envFile = action.payload;
2479
- }
2480
- }
2481
- });
2482
- var {
2483
- setEnv,
2484
- setUid,
2485
- setLang,
2486
- setAllowCompanies,
2487
- setCompanies,
2488
- setDefaultCompany,
2489
- setUser,
2490
- setConfig,
2491
- setEnvFile
2492
- } = envSlice.actions;
2493
- var env_slice_default = envSlice.reducer;
2494
-
2495
- // src/store/reducers/excel-slice/index.ts
2496
- import { createSlice as createSlice3 } from "@reduxjs/toolkit";
2497
- var initialState3 = {
2498
- dataParse: null,
2499
- idFile: null,
2500
- isFileLoaded: false,
2501
- loadingImport: false,
2502
- selectedFile: null,
2503
- errorData: null
2504
- };
2505
- var excelSlice = createSlice3({
2506
- name: "excel",
2507
- initialState: initialState3,
2508
- reducers: {
2509
- setDataParse: (state, action) => {
2510
- state.dataParse = action.payload;
2511
- },
2512
- setIdFile: (state, action) => {
2513
- state.idFile = action.payload;
2514
- },
2515
- setIsFileLoaded: (state, action) => {
2516
- state.isFileLoaded = action.payload;
2517
- },
2518
- setLoadingImport: (state, action) => {
2519
- state.loadingImport = action.payload;
2520
- },
2521
- setSelectedFile: (state, action) => {
2522
- state.selectedFile = action.payload;
2523
- },
2524
- setErrorData: (state, action) => {
2525
- state.errorData = action.payload;
2526
- }
2527
- }
2528
- });
2529
- var {
2530
- setDataParse,
2531
- setIdFile,
2532
- setIsFileLoaded,
2533
- setLoadingImport,
2534
- setSelectedFile,
2535
- setErrorData
2536
- } = excelSlice.actions;
2537
- var excel_slice_default = excelSlice.reducer;
2538
-
2539
- // src/store/reducers/form-slice/index.ts
2540
- import { createSlice as createSlice4 } from "@reduxjs/toolkit";
2541
- var initialState4 = {
2542
- viewDataStore: {},
2543
- isShowingModalDetail: false,
2544
- isShowModalTranslate: false,
2545
- formSubmitComponent: {},
2546
- fieldTranslation: null,
2547
- listSubject: {},
2548
- dataUser: {}
2549
- };
2550
- var formSlice = createSlice4({
2551
- name: "form",
2552
- initialState: initialState4,
2553
- reducers: {
2554
- setViewDataStore: (state, action) => {
2555
- state.viewDataStore = action.payload;
2556
- },
2557
- setIsShowingModalDetail: (state, action) => {
2558
- state.isShowingModalDetail = action.payload;
2559
- },
2560
- setIsShowModalTranslate: (state, action) => {
2561
- state.isShowModalTranslate = action.payload;
2562
- },
2563
- setFormSubmitComponent: (state, action) => {
2564
- state.formSubmitComponent[action.payload.key] = action.payload.component;
2565
- },
2566
- setFieldTranslate: (state, action) => {
2567
- state.fieldTranslation = action.payload;
2568
- },
2569
- setListSubject: (state, action) => {
2570
- state.listSubject = action.payload;
2571
- },
2572
- setDataUser: (state, action) => {
2573
- state.dataUser = action.payload;
2574
- }
2575
- }
2576
- });
2577
- var {
2578
- setViewDataStore,
2579
- setIsShowingModalDetail,
2580
- setIsShowModalTranslate,
2581
- setFormSubmitComponent,
2582
- setFieldTranslate,
2583
- setListSubject,
2584
- setDataUser
2585
- } = formSlice.actions;
2586
- var form_slice_default = formSlice.reducer;
2587
-
2588
- // src/store/reducers/header-slice/index.ts
2589
- import { createSlice as createSlice5 } from "@reduxjs/toolkit";
2590
- var headerSlice = createSlice5({
2591
- name: "header",
2592
- initialState: {
2593
- value: { allowedCompanyIds: [] }
2594
- },
2595
- reducers: {
2596
- setHeader: (state, action) => {
2597
- state.value = { ...state.value, ...action.payload };
2598
- },
2599
- setAllowedCompanyIds: (state, action) => {
2600
- state.value.allowedCompanyIds = action.payload;
2601
- }
2602
- }
2603
- });
2604
- var { setAllowedCompanyIds, setHeader } = headerSlice.actions;
2605
- var header_slice_default = headerSlice.reducer;
2606
-
2607
- // src/store/reducers/list-slice/index.ts
2608
- import { createSlice as createSlice6 } from "@reduxjs/toolkit";
2609
- var initialState5 = {
2610
- pageLimit: 10,
2611
- fields: {},
2612
- order: "",
2613
- selectedRowKeys: [],
2614
- selectedRadioKey: 0,
2615
- indexRowTableModal: -2,
2616
- isUpdateTableModal: false,
2617
- footerGroupTable: {},
2618
- transferDetail: null,
2619
- page: 0,
2620
- domainTable: []
2621
- };
2622
- var listSlice = createSlice6({
2623
- name: "list",
2624
- initialState: initialState5,
2625
- reducers: {
2626
- setPageLimit: (state, action) => {
2627
- state.pageLimit = action.payload;
2628
- },
2629
- setFields: (state, action) => {
2630
- state.fields = action.payload;
2631
- },
2632
- setOrder: (state, action) => {
2633
- state.order = action.payload;
2634
- },
2635
- setSelectedRowKeys: (state, action) => {
2636
- state.selectedRowKeys = action.payload;
2637
- },
2638
- setSelectedRadioKey: (state, action) => {
2639
- state.selectedRadioKey = action.payload;
2640
- },
2641
- setIndexRowTableModal: (state, action) => {
2642
- state.indexRowTableModal = action.payload;
2643
- },
2644
- setTransferDetail: (state, action) => {
2645
- state.transferDetail = action.payload;
2646
- },
2647
- setIsUpdateTableModal: (state, action) => {
2648
- state.isUpdateTableModal = action.payload;
2649
- },
2650
- setPage: (state, action) => {
2651
- state.page = action.payload;
2652
- },
2653
- setDomainTable: (state, action) => {
2654
- state.domainTable = action.payload;
2655
- }
2656
- }
2657
- });
2658
- var {
2659
- setPageLimit,
2660
- setFields,
2661
- setOrder,
2662
- setSelectedRowKeys,
2663
- setIndexRowTableModal,
2664
- setIsUpdateTableModal,
2665
- setPage,
2666
- setSelectedRadioKey,
2667
- setTransferDetail,
2668
- setDomainTable
2669
- } = listSlice.actions;
2670
- var list_slice_default = listSlice.reducer;
2671
-
2672
- // src/store/reducers/login-slice/index.ts
2673
- import { createSlice as createSlice7 } from "@reduxjs/toolkit";
2674
- var initialState6 = {
2675
- db: "",
2676
- redirectTo: "/",
2677
- forgotPasswordUrl: "/"
2678
- };
2679
- var loginSlice = createSlice7({
2680
- name: "login",
2681
- initialState: initialState6,
2682
- reducers: {
2683
- setDb: (state, action) => {
2684
- state.db = action.payload;
2685
- },
2686
- setRedirectTo: (state, action) => {
2687
- state.redirectTo = action.payload;
2688
- },
2689
- setForgotPasswordUrl: (state, action) => {
2690
- state.forgotPasswordUrl = action.payload;
2691
- }
2692
- }
2693
- });
2694
- var { setDb, setRedirectTo, setForgotPasswordUrl } = loginSlice.actions;
2695
- var login_slice_default = loginSlice.reducer;
2696
-
2697
- // src/store/reducers/navbar-slice/index.ts
2698
- import { createSlice as createSlice8 } from "@reduxjs/toolkit";
2699
- var initialState7 = {
2700
- menuFocus: {},
2701
- menuAction: {},
2702
- navbarWidth: 250,
2703
- menuList: []
2704
- };
2705
- var navbarSlice = createSlice8({
2706
- name: "navbar",
2707
- initialState: initialState7,
2708
- reducers: {
2709
- setMenuFocus: (state, action) => {
2710
- state.menuFocus = action.payload;
2711
- },
2712
- setMenuFocusAction: (state, action) => {
2713
- state.menuAction = action.payload;
2714
- },
2715
- setNavbarWidth: (state, action) => {
2716
- state.navbarWidth = action.payload;
2717
- },
2718
- setMenuList: (state, action) => {
2719
- state.menuList = action.payload;
2720
- }
2721
- }
2722
- });
2723
- var { setMenuFocus, setMenuFocusAction, setNavbarWidth, setMenuList } = navbarSlice.actions;
2724
- var navbar_slice_default = navbarSlice.reducer;
2725
-
2726
- // src/store/reducers/profile-slice/index.ts
2727
- import { createSlice as createSlice9 } from "@reduxjs/toolkit";
2728
- var initialState8 = {
2729
- profile: {}
2730
- };
2731
- var profileSlice = createSlice9({
2732
- name: "profile",
2733
- initialState: initialState8,
2734
- reducers: {
2735
- setProfile: (state, action) => {
2736
- state.profile = action.payload;
2405
+ // src/environment/EnvStore.ts
2406
+ var EventEmitter = class {
2407
+ listeners = {};
2408
+ on(event, callback) {
2409
+ if (!this.listeners[event]) {
2410
+ this.listeners[event] = [];
2737
2411
  }
2412
+ this.listeners[event].push(callback);
2738
2413
  }
2739
- });
2740
- var { setProfile } = profileSlice.actions;
2741
- var profile_slice_default = profileSlice.reducer;
2742
-
2743
- // src/store/reducers/search-slice/index.ts
2744
- import { createSlice as createSlice10 } from "@reduxjs/toolkit";
2745
- var initialState9 = {
2746
- groupByDomain: null,
2747
- searchBy: [],
2748
- searchString: "",
2749
- hoveredIndexSearchList: null,
2750
- selectedTags: [],
2751
- firstDomain: null,
2752
- searchMap: {},
2753
- filterBy: [],
2754
- groupBy: []
2755
- };
2756
- var searchSlice = createSlice10({
2757
- name: "search",
2758
- initialState: initialState9,
2759
- reducers: {
2760
- setGroupByDomain: (state, action) => {
2761
- state.groupByDomain = action.payload;
2762
- },
2763
- setSearchBy: (state, action) => {
2764
- state.searchBy = action.payload;
2765
- },
2766
- setSearchString: (state, action) => {
2767
- state.searchString = action.payload;
2768
- },
2769
- setHoveredIndexSearchList: (state, action) => {
2770
- state.hoveredIndexSearchList = action.payload;
2771
- },
2772
- setSelectedTags: (state, action) => {
2773
- state.selectedTags = action.payload;
2774
- },
2775
- setFirstDomain: (state, action) => {
2776
- state.firstDomain = action.payload;
2777
- },
2778
- setFilterBy: (state, action) => {
2779
- state.filterBy = action.payload;
2780
- },
2781
- setGroupBy: (state, action) => {
2782
- state.groupBy = action.payload;
2783
- },
2784
- setSearchMap: (state, action) => {
2785
- state.searchMap = action.payload;
2786
- },
2787
- updateSearchMap: (state, action) => {
2788
- if (!state.searchMap[action.payload.key]) {
2789
- state.searchMap[action.payload.key] = [];
2790
- }
2791
- state.searchMap[action.payload.key].push(action.payload.value);
2792
- },
2793
- removeKeyFromSearchMap: (state, action) => {
2794
- const { key, item } = action.payload;
2795
- const values = state.searchMap[key];
2796
- if (!values) return;
2797
- if (item) {
2798
- const filtered = values.filter((value) => value.name !== item.name);
2799
- if (filtered.length > 0) {
2800
- state.searchMap[key] = filtered;
2801
- } else {
2802
- delete state.searchMap[key];
2803
- }
2804
- } else {
2805
- delete state.searchMap[key];
2806
- }
2807
- },
2808
- clearSearchMap: (state) => {
2809
- state.searchMap = {};
2414
+ emit(event, data) {
2415
+ if (this.listeners[event]) {
2416
+ this.listeners[event].forEach((callback) => callback(data));
2810
2417
  }
2811
2418
  }
2812
- });
2813
- var {
2814
- setGroupByDomain,
2815
- setSelectedTags,
2816
- setSearchString,
2817
- setHoveredIndexSearchList,
2818
- setFirstDomain,
2819
- setSearchBy,
2820
- setFilterBy,
2821
- setSearchMap,
2822
- updateSearchMap,
2823
- removeKeyFromSearchMap,
2824
- setGroupBy,
2825
- clearSearchMap
2826
- } = searchSlice.actions;
2827
- var search_slice_default = searchSlice.reducer;
2828
-
2829
- // src/store/store.ts
2830
- import { configureStore } from "@reduxjs/toolkit";
2831
-
2832
- // node_modules/redux/dist/redux.mjs
2833
- function formatProdErrorMessage(code) {
2834
- return `Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
2835
- }
2836
- var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
2837
- var ActionTypes = {
2838
- INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
2839
- REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
2840
- PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
2841
2419
  };
2842
- var actionTypes_default = ActionTypes;
2843
- function isPlainObject(obj) {
2844
- if (typeof obj !== "object" || obj === null)
2845
- return false;
2846
- let proto = obj;
2847
- while (Object.getPrototypeOf(proto) !== null) {
2848
- proto = Object.getPrototypeOf(proto);
2849
- }
2850
- return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
2851
- }
2852
- function miniKindOf(val) {
2853
- if (val === void 0)
2854
- return "undefined";
2855
- if (val === null)
2856
- return "null";
2857
- const type = typeof val;
2858
- switch (type) {
2859
- case "boolean":
2860
- case "string":
2861
- case "number":
2862
- case "symbol":
2863
- case "function": {
2864
- return type;
2865
- }
2866
- }
2867
- if (Array.isArray(val))
2868
- return "array";
2869
- if (isDate(val))
2870
- return "date";
2871
- if (isError(val))
2872
- return "error";
2873
- const constructorName = ctorName(val);
2874
- switch (constructorName) {
2875
- case "Symbol":
2876
- case "Promise":
2877
- case "WeakMap":
2878
- case "WeakSet":
2879
- case "Map":
2880
- case "Set":
2881
- return constructorName;
2882
- }
2883
- return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, "");
2884
- }
2885
- function ctorName(val) {
2886
- return typeof val.constructor === "function" ? val.constructor.name : null;
2887
- }
2888
- function isError(val) {
2889
- return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
2890
- }
2891
- function isDate(val) {
2892
- if (val instanceof Date)
2893
- return true;
2894
- return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
2895
- }
2896
- function kindOf(val) {
2897
- let typeOfVal = typeof val;
2898
- if (process.env.NODE_ENV !== "production") {
2899
- typeOfVal = miniKindOf(val);
2900
- }
2901
- return typeOfVal;
2902
- }
2903
- function warning(message) {
2904
- if (typeof console !== "undefined" && typeof console.error === "function") {
2905
- console.error(message);
2906
- }
2907
- try {
2908
- throw new Error(message);
2909
- } catch (e) {
2910
- }
2911
- }
2912
- function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
2913
- const reducerKeys = Object.keys(reducers);
2914
- const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer";
2915
- if (reducerKeys.length === 0) {
2916
- return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";
2917
- }
2918
- if (!isPlainObject(inputState)) {
2919
- return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`;
2920
- }
2921
- const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]);
2922
- unexpectedKeys.forEach((key) => {
2923
- unexpectedKeyCache[key] = true;
2924
- });
2925
- if (action && action.type === actionTypes_default.REPLACE)
2926
- return;
2927
- if (unexpectedKeys.length > 0) {
2928
- return `Unexpected ${unexpectedKeys.length > 1 ? "keys" : "key"} "${unexpectedKeys.join('", "')}" found in ${argumentName}. Expected to find one of the known reducer keys instead: "${reducerKeys.join('", "')}". Unexpected keys will be ignored.`;
2929
- }
2930
- }
2931
- function assertReducerShape(reducers) {
2932
- Object.keys(reducers).forEach((key) => {
2933
- const reducer = reducers[key];
2934
- const initialState10 = reducer(void 0, {
2935
- type: actionTypes_default.INIT
2936
- });
2937
- if (typeof initialState10 === "undefined") {
2938
- throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : `The slice reducer for key "${key}" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);
2939
- }
2940
- if (typeof reducer(void 0, {
2941
- type: actionTypes_default.PROBE_UNKNOWN_ACTION()
2942
- }) === "undefined") {
2943
- throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : `The slice reducer for key "${key}" returned undefined when probed with a random type. Don't try to handle '${actionTypes_default.INIT}' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.`);
2944
- }
2945
- });
2946
- }
2947
- function combineReducers(reducers) {
2948
- const reducerKeys = Object.keys(reducers);
2949
- const finalReducers = {};
2950
- for (let i = 0; i < reducerKeys.length; i++) {
2951
- const key = reducerKeys[i];
2952
- if (process.env.NODE_ENV !== "production") {
2953
- if (typeof reducers[key] === "undefined") {
2954
- warning(`No reducer provided for key "${key}"`);
2955
- }
2956
- }
2957
- if (typeof reducers[key] === "function") {
2958
- finalReducers[key] = reducers[key];
2959
- }
2960
- }
2961
- const finalReducerKeys = Object.keys(finalReducers);
2962
- let unexpectedKeyCache;
2963
- if (process.env.NODE_ENV !== "production") {
2964
- unexpectedKeyCache = {};
2420
+ var EnvStore = class {
2421
+ state;
2422
+ emitter;
2423
+ localStorageUtil;
2424
+ sessionStorageUtil;
2425
+ constructor(localStorageUtil = localStorageUtils(), sessionStorageUtil = sessionStorageUtils()) {
2426
+ this.state = {
2427
+ baseUrl: "",
2428
+ requests: null,
2429
+ companies: [],
2430
+ user: {},
2431
+ config: null,
2432
+ envFile: null,
2433
+ defaultCompany: {
2434
+ id: null,
2435
+ logo: "",
2436
+ secondary_color: "",
2437
+ primary_color: ""
2438
+ },
2439
+ context: {
2440
+ uid: null,
2441
+ allowed_company_ids: [],
2442
+ lang: "vi_VN",
2443
+ tz: "Asia/Saigon"
2444
+ },
2445
+ localStorageUtils: localStorageUtil,
2446
+ sessionStorageUtils: sessionStorageUtil
2447
+ };
2448
+ this.emitter = new EventEmitter();
2449
+ this.localStorageUtil = localStorageUtil;
2450
+ this.sessionStorageUtil = sessionStorageUtil;
2965
2451
  }
2966
- let shapeAssertionError;
2967
- try {
2968
- assertReducerShape(finalReducers);
2969
- } catch (e) {
2970
- shapeAssertionError = e;
2452
+ getEnv() {
2453
+ return { ...this.state };
2971
2454
  }
2972
- return function combination(state = {}, action) {
2973
- if (shapeAssertionError) {
2974
- throw shapeAssertionError;
2975
- }
2976
- if (process.env.NODE_ENV !== "production") {
2977
- const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
2978
- if (warningMessage) {
2979
- warning(warningMessage);
2980
- }
2981
- }
2982
- let hasChanged = false;
2983
- const nextState = {};
2984
- for (let i = 0; i < finalReducerKeys.length; i++) {
2985
- const key = finalReducerKeys[i];
2986
- const reducer = finalReducers[key];
2987
- const previousStateForKey = state[key];
2988
- const nextStateForKey = reducer(previousStateForKey, action);
2989
- if (typeof nextStateForKey === "undefined") {
2990
- const actionType = action && action.type;
2991
- throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : `When called with an action of type ${actionType ? `"${String(actionType)}"` : "(unknown type)"}, the slice reducer for key "${key}" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.`);
2992
- }
2993
- nextState[key] = nextStateForKey;
2994
- hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
2995
- }
2996
- hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
2997
- return hasChanged ? nextState : state;
2998
- };
2999
- }
3000
-
3001
- // src/store/store.ts
3002
- var rootReducer = combineReducers({
3003
- env: env_slice_default,
3004
- header: header_slice_default,
3005
- navbar: navbar_slice_default,
3006
- list: list_slice_default,
3007
- search: search_slice_default,
3008
- form: form_slice_default,
3009
- breadcrumbs: breadcrums_slice_default,
3010
- login: login_slice_default,
3011
- excel: excel_slice_default,
3012
- profile: profile_slice_default
3013
- });
3014
- var envStore = configureStore({
3015
- reducer: rootReducer,
3016
- middleware: (getDefaultMiddleware) => getDefaultMiddleware({
3017
- serializableCheck: false
3018
- })
3019
- });
3020
-
3021
- // src/environment/EnvStore.ts
3022
- var EnvStore = class {
3023
- envStore;
3024
- baseUrl;
3025
- requests;
3026
- context;
3027
- defaultCompany;
3028
- config;
3029
- companies;
3030
- user;
3031
- db;
3032
- localStorageUtils;
3033
- sessionStorageUtils;
3034
- refreshTokenEndpoint;
3035
- constructor(envStore2, localStorageUtils2, sessionStorageUtils2) {
3036
- this.envStore = envStore2;
3037
- this.localStorageUtils = localStorageUtils2;
3038
- this.sessionStorageUtils = sessionStorageUtils2;
3039
- this.setup();
3040
- }
3041
- setup() {
3042
- const env2 = this.envStore.getState().env;
3043
- this.baseUrl = env2?.baseUrl;
3044
- this.requests = env2?.requests;
3045
- this.context = env2?.context;
3046
- this.defaultCompany = env2?.defaultCompany;
3047
- this.config = env2?.config;
3048
- this.companies = env2?.companies || [];
3049
- this.user = env2?.user;
3050
- this.db = env2?.db;
3051
- this.refreshTokenEndpoint = env2?.refreshTokenEndpoint;
2455
+ onUpdate(callback) {
2456
+ this.emitter.on("update", callback);
3052
2457
  }
3053
2458
  setupEnv(envConfig) {
3054
- const dispatch = this.envStore.dispatch;
3055
- const env2 = {
2459
+ this.state = {
2460
+ ...this.state,
3056
2461
  ...envConfig,
3057
- localStorageUtils: this.localStorageUtils,
3058
- sessionStorageUtils: this.sessionStorageUtils
2462
+ localStorageUtils: this.localStorageUtil,
2463
+ sessionStorageUtils: this.sessionStorageUtil
3059
2464
  };
3060
- const requests = axiosClient.init(env2);
3061
- dispatch(setEnv({ ...env2, requests }));
3062
- this.setup();
2465
+ this.state.requests = axiosClient.init(this.state);
2466
+ this.emitter.emit("update", this.getEnv());
2467
+ return this.getEnv();
3063
2468
  }
3064
2469
  setUid(uid) {
3065
- const dispatch = this.envStore.dispatch;
3066
- dispatch(setUid(uid));
3067
- this.setup();
2470
+ this.state = {
2471
+ ...this.state,
2472
+ context: { ...this.state.context, uid }
2473
+ };
2474
+ this.emitter.emit("update", this.getEnv());
3068
2475
  }
3069
2476
  setLang(lang) {
3070
- const dispatch = this.envStore.dispatch;
3071
- dispatch(setLang(lang));
3072
- this.setup();
2477
+ this.state = {
2478
+ ...this.state,
2479
+ context: { ...this.state.context, lang }
2480
+ };
2481
+ this.emitter.emit("update", this.getEnv());
3073
2482
  }
3074
- setAllowCompanies(allowCompanies) {
3075
- const dispatch = this.envStore.dispatch;
3076
- dispatch(setAllowCompanies(allowCompanies));
3077
- this.setup();
2483
+ setAllowCompanies(allowed_company_ids) {
2484
+ this.state = {
2485
+ ...this.state,
2486
+ context: { ...this.state.context, allowed_company_ids }
2487
+ };
2488
+ this.emitter.emit("update", this.getEnv());
3078
2489
  }
3079
2490
  setCompanies(companies) {
3080
- const dispatch = this.envStore.dispatch;
3081
- dispatch(setCompanies(companies));
3082
- this.setup();
2491
+ this.state = { ...this.state, companies };
2492
+ this.emitter.emit("update", this.getEnv());
2493
+ }
2494
+ setDefaultCompany(defaultCompany) {
2495
+ this.state = { ...this.state, defaultCompany };
2496
+ this.emitter.emit("update", this.getEnv());
3083
2497
  }
3084
- setDefaultCompany(company) {
3085
- const dispatch = this.envStore.dispatch;
3086
- dispatch(setDefaultCompany(company));
3087
- this.setup();
2498
+ setUserInfo(user) {
2499
+ this.state = { ...this.state, user };
2500
+ this.emitter.emit("update", this.getEnv());
3088
2501
  }
3089
- setUserInfo(userInfo) {
3090
- const dispatch = this.envStore.dispatch;
3091
- dispatch(setUser(userInfo));
3092
- this.setup();
2502
+ setConfig(config) {
2503
+ this.state = { ...this.state, config };
2504
+ this.emitter.emit("update", this.getEnv());
2505
+ }
2506
+ setEnvFile(envFile) {
2507
+ this.state = { ...this.state, envFile };
2508
+ this.emitter.emit("update", this.getEnv());
3093
2509
  }
3094
2510
  };
3095
2511
  var env = null;
2512
+ function initEnv({
2513
+ localStorageUtils: localStorageUtil = localStorageUtils(),
2514
+ sessionStorageUtils: sessionStorageUtil = sessionStorageUtils()
2515
+ }) {
2516
+ if (!env) {
2517
+ env = new EnvStore(localStorageUtil, sessionStorageUtil);
2518
+ }
2519
+ return env;
2520
+ }
3096
2521
  function getEnv() {
3097
- if (!env)
3098
- env = new EnvStore(envStore, localStorageUtils(), sessionStorageUtils());
2522
+ if (!env) {
2523
+ env = initEnv({});
2524
+ }
3099
2525
  return env;
3100
2526
  }
3101
2527
 
@@ -4691,269 +4117,12 @@ var useIsValidToken = () => {
4691
4117
  };
4692
4118
  var use_isvalid_token_default = useIsValidToken;
4693
4119
 
4694
- // src/hooks/auth/use-login-credential.tsx
4120
+ // src/hooks/auth/use-login-credential.ts
4695
4121
  import { useMutation as useMutation5 } from "@tanstack/react-query";
4696
-
4697
- // src/services/auth-service/backup.ts
4698
- import { useCallback as useCallback3 } from "react";
4699
-
4700
- // src/provider/react-query-provider.tsx
4701
- import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
4702
- import { jsx } from "react/jsx-runtime";
4703
-
4704
- // src/provider/redux-provider.tsx
4705
- import { Provider } from "react-redux";
4706
- import { jsx as jsx2 } from "react/jsx-runtime";
4707
-
4708
- // src/provider/main-provider.tsx
4709
- import { jsx as jsx3 } from "react/jsx-runtime";
4710
-
4711
- // src/provider/version-gate-provider.tsx
4712
- import { useEffect as useEffect2, useState as useState2 } from "react";
4713
- import { useQueryClient } from "@tanstack/react-query";
4714
-
4715
- // src/services/view-service/backup.ts
4716
- import { useCallback } from "react";
4717
-
4718
- // src/provider/version-gate-provider.tsx
4719
- import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
4720
-
4721
- // src/provider/env-provider.tsx
4722
- import { createContext, useContext, useState as useState3, useCallback as useCallback2 } from "react";
4723
- import { jsx as jsx5 } from "react/jsx-runtime";
4724
- var EnvContext = createContext(null);
4725
- function useEnv() {
4726
- const context = useContext(EnvContext);
4727
- if (!context) {
4728
- throw new Error("useEnv must be used within an EnvProvider");
4729
- }
4730
- return context;
4731
- }
4732
-
4733
- // src/services/auth-service/backup.ts
4734
- function useAuthService() {
4735
- const { env: env2 } = useEnv();
4736
- const login = useCallback3(
4737
- async (body) => {
4738
- const payload = Object.fromEntries(
4739
- Object.entries({
4740
- username: body.email,
4741
- password: body.password,
4742
- grant_type: env2?.config?.grantType || "",
4743
- client_id: env2?.config?.clientId || "",
4744
- client_secret: env2?.config?.clientSecret || ""
4745
- }).filter(([_, value]) => !!value)
4746
- );
4747
- const encodedData = new URLSearchParams(payload).toString();
4748
- return env2?.requests?.post(body.path, encodedData, {
4749
- headers: {
4750
- "Content-Type": "application/x-www-form-urlencoded"
4751
- }
4752
- });
4753
- },
4754
- [env2]
4755
- );
4756
- const forgotPassword = useCallback3(
4757
- async (email) => {
4758
- const bodyData = {
4759
- login: email,
4760
- url: `${window.location.origin}/reset-password`
4761
- };
4762
- return env2?.requests?.post("/reset_password" /* RESET_PASSWORD_PATH */, bodyData, {
4763
- headers: {
4764
- "Content-Type": "application/json"
4765
- }
4766
- });
4767
- },
4768
- [env2]
4769
- );
4770
- const forgotPasswordSSO = useCallback3(
4771
- async ({
4772
- email,
4773
- with_context,
4774
- method
4775
- }) => {
4776
- const body = {
4777
- method,
4778
- kwargs: {
4779
- vals: {
4780
- email
4781
- }
4782
- },
4783
- with_context
4784
- };
4785
- return env2?.requests?.post("/call" /* CALL_PATH */, body, {
4786
- headers: {
4787
- "Content-Type": "application/json"
4788
- }
4789
- });
4790
- },
4791
- [env2]
4792
- );
4793
- const resetPassword = useCallback3(
4794
- async (data, token) => {
4795
- const bodyData = {
4796
- token,
4797
- password: data.password,
4798
- new_password: data.confirmPassword
4799
- };
4800
- return env2?.requests?.post("/change_password" /* CHANGE_PASSWORD_PATH */, bodyData, {
4801
- headers: {
4802
- "Content-Type": "application/json"
4803
- }
4804
- });
4805
- },
4806
- [env2]
4807
- );
4808
- const resetPasswordSSO = useCallback3(
4809
- async ({
4810
- method,
4811
- password,
4812
- with_context
4813
- }) => {
4814
- const bodyData = {
4815
- method,
4816
- kwargs: {
4817
- vals: {
4818
- password
4819
- }
4820
- },
4821
- with_context
4822
- };
4823
- return env2?.requests?.post("/call" /* CALL_PATH */, bodyData, {
4824
- headers: {
4825
- "Content-Type": "application/json"
4826
- }
4827
- });
4828
- },
4829
- [env2]
4830
- );
4831
- const updatePassword = useCallback3(
4832
- async (data, token) => {
4833
- const bodyData = {
4834
- token,
4835
- old_password: data.oldPassword,
4836
- new_password: data.newPassword
4837
- };
4838
- return env2?.requests?.post("/change_password_parent" /* UPDATE_PASSWORD_PATH */, bodyData, {
4839
- headers: {
4840
- "Content-Type": "application/json"
4841
- }
4842
- });
4843
- },
4844
- [env2]
4845
- );
4846
- const isValidToken = useCallback3(
4847
- async (token) => {
4848
- const bodyData = {
4849
- token
4850
- };
4851
- return env2?.requests?.post("/check_token" /* TOKEN */, bodyData, {
4852
- headers: {
4853
- "Content-Type": "application/json"
4854
- }
4855
- });
4856
- },
4857
- [env2]
4858
- );
4859
- const isValidActionToken = useCallback3(
4860
- async (actionToken, path) => {
4861
- return env2?.requests?.post(
4862
- path,
4863
- {},
4864
- {
4865
- headers: {
4866
- "Content-Type": "application/json"
4867
- },
4868
- useActionToken: true,
4869
- actionToken
4870
- }
4871
- );
4872
- },
4873
- [env2]
4874
- );
4875
- const loginSocial = useCallback3(
4876
- async ({
4877
- db,
4878
- state,
4879
- access_token
4880
- }) => {
4881
- return env2?.requests?.post(
4882
- "/token/generate" /* GENTOKEN_SOCIAL */,
4883
- { state, access_token },
4884
- {
4885
- headers: {
4886
- "Content-Type": "application/json"
4887
- }
4888
- }
4889
- );
4890
- },
4891
- [env2]
4892
- );
4893
- const getProviders = useCallback3(
4894
- async (db) => {
4895
- return env2?.requests?.get("/oauth/providers", { params: { db } });
4896
- },
4897
- [env2]
4898
- );
4899
- const getAccessByCode = useCallback3(
4900
- async (code) => {
4901
- const data = new URLSearchParams();
4902
- data.append("code", code);
4903
- data.append("grant_type", "authorization_code");
4904
- data.append("client_id", env2?.config?.clientId || "");
4905
- data.append("redirect_uri", env2?.config?.redirectUri || "");
4906
- return env2?.requests?.post(
4907
- `${env2?.baseUrl?.replace("/mms/", "/id/")}/${"/token" /* TOKEN_BY_CODE */}`,
4908
- data,
4909
- {
4910
- headers: {
4911
- "Content-Type": "application/x-www-form-urlencoded"
4912
- }
4913
- }
4914
- );
4915
- },
4916
- [env2]
4917
- );
4918
- const logout = useCallback3(
4919
- async (data) => {
4920
- console.log(data);
4921
- return env2?.requests?.post(
4922
- "/logout" /* LOGOUT */,
4923
- {},
4924
- {
4925
- headers: {
4926
- "Content-Type": "application/json"
4927
- },
4928
- withCredentials: true,
4929
- useRefreshToken: true
4930
- }
4931
- );
4932
- },
4933
- [env2]
4934
- );
4935
- return {
4936
- login,
4937
- forgotPassword,
4938
- forgotPasswordSSO,
4939
- resetPassword,
4940
- resetPasswordSSO,
4941
- updatePassword,
4942
- isValidToken,
4943
- isValidActionToken,
4944
- loginSocial,
4945
- getProviders,
4946
- getAccessByCode,
4947
- logout
4948
- };
4949
- }
4950
-
4951
- // src/hooks/auth/use-login-credential.tsx
4952
4122
  var useLoginCredential = () => {
4953
- const { login } = useAuthService();
4954
4123
  return useMutation5({
4955
4124
  mutationFn: (data) => {
4956
- return login(data);
4125
+ return auth_service_default.login(data);
4957
4126
  }
4958
4127
  });
4959
4128
  };