@m4l/layouts 0.1.38 → 0.1.40
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/components/BaseModule/index.6309486a.js +24 -24
- package/components/BaseModule/index.d.ts +2 -1
- package/components/MFHostApp/index.420c2626.js +58 -58
- package/components/MFHostApp/index.d.ts +2 -1
- package/components/MFIsolationApp/index.d.ts +2 -1
- package/components/MFIsolationApp/index.e36cf308.js +175 -0
- package/components/MFIsolationApp/subcomponents/MFAuthApp/index.d.ts +2 -1
- package/components/{index.604759d6.js → index.aeb3cf83.js} +1 -1
- package/contexts/AuthContext/index.6f966215.js +118 -88
- package/contexts/AuthContext/index.d.ts +1 -1
- package/hooks/index.a0c767ed.js +4 -0
- package/hooks/useAuth/index.cb6a3420.js +7 -7
- package/hooks/useMasterDetail/index.927c0c26.js +6 -0
- package/hooks/useModule/index.edcd7b28.js +11 -0
- package/index.js +27 -27
- package/layouts/MasterDetailLayout/contexts/MasterDetailContext/index.d.ts +1 -1
- package/layouts/MasterDetailLayout/index.bca0fce5.js +136 -0
- package/layouts/MasterDetailLayout/index.d.ts +2 -1
- package/layouts/ModuleLayout/contexts/ModuleContext/index.d.ts +1 -1
- package/layouts/ModuleLayout/index.850f7dcf.js +118 -0
- package/layouts/ModuleLayout/subcomponents/InnerModule/styles.d.ts +3 -0
- package/layouts/NoAuthModuleLayout/index.d.ts +2 -1
- package/layouts/NoAuthModuleLayout/index.eabf38c1.js +179 -146
- package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/index.d.ts +2 -1
- package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/styles.d.ts +2 -0
- package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/DesktopContent/index.d.ts +2 -1
- package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/DesktopContent/styles.d.ts +9 -0
- package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/MobileContent/index.d.ts +2 -1
- package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/MobileContent/styles.d.ts +9 -0
- package/layouts/{index.3e2d546f.js → index.07aacf57.js} +2 -2
- package/package.json +2 -1
- package/components/MFIsolationApp/index.ed197bc0.js +0 -152
- package/hooks/index.18c6b299.js +0 -4
- package/hooks/useMasterDetail/index.50331312.js +0 -6
- package/hooks/useModule/index.35cc5fe0.js +0 -11
- package/layouts/MasterDetailLayout/index.2c363c7a.js +0 -109
- package/layouts/ModuleLayout/index.90b4dc8e.js +0 -103
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { ModalProvider
|
|
2
|
-
import { FlagsProvider
|
|
3
|
-
import { jsx
|
|
4
|
-
function
|
|
1
|
+
import { ModalProvider } from "@m4l/components";
|
|
2
|
+
import { FlagsProvider, ModuleDictionaryProvider, ModuleSkeletonProvider, ModulePrivilegesProvider } from "@m4l/core";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
function BaseModule(props) {
|
|
5
5
|
const {
|
|
6
|
-
children
|
|
7
|
-
moduleId
|
|
8
|
-
moduleNameField
|
|
9
|
-
skeletonFlags
|
|
10
|
-
privileges
|
|
11
|
-
componentsDictionary
|
|
12
|
-
} =
|
|
13
|
-
return /* @__PURE__ */
|
|
14
|
-
children: /* @__PURE__ */
|
|
15
|
-
isAuth:
|
|
16
|
-
moduleId
|
|
17
|
-
moduleNameField
|
|
18
|
-
componentsDictionary
|
|
19
|
-
children: /* @__PURE__ */
|
|
20
|
-
flags:
|
|
21
|
-
children: /* @__PURE__ */
|
|
22
|
-
queryPrivileges:
|
|
23
|
-
children: /* @__PURE__ */
|
|
24
|
-
children
|
|
6
|
+
children,
|
|
7
|
+
moduleId,
|
|
8
|
+
moduleNameField,
|
|
9
|
+
skeletonFlags,
|
|
10
|
+
privileges,
|
|
11
|
+
componentsDictionary
|
|
12
|
+
} = props;
|
|
13
|
+
return /* @__PURE__ */ jsx(FlagsProvider, {
|
|
14
|
+
children: /* @__PURE__ */ jsx(ModuleDictionaryProvider, {
|
|
15
|
+
isAuth: true,
|
|
16
|
+
moduleId,
|
|
17
|
+
moduleNameField,
|
|
18
|
+
componentsDictionary,
|
|
19
|
+
children: /* @__PURE__ */ jsx(ModuleSkeletonProvider, {
|
|
20
|
+
flags: skeletonFlags,
|
|
21
|
+
children: /* @__PURE__ */ jsx(ModulePrivilegesProvider, {
|
|
22
|
+
queryPrivileges: privileges,
|
|
23
|
+
children: /* @__PURE__ */ jsx(ModalProvider, {
|
|
24
|
+
children
|
|
25
25
|
})
|
|
26
26
|
})
|
|
27
27
|
})
|
|
@@ -29,5 +29,5 @@ function h(r) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
export {
|
|
32
|
-
|
|
32
|
+
BaseModule as B
|
|
33
33
|
};
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { unstable_HistoryRouter
|
|
2
|
-
import { EnvironmentProvider
|
|
3
|
-
import { LocalesProvider
|
|
4
|
-
import { WindowToolsMFProvider
|
|
5
|
-
import { B as
|
|
6
|
-
import { jsx
|
|
7
|
-
function
|
|
1
|
+
import { unstable_HistoryRouter } from "react-router-dom";
|
|
2
|
+
import { EnvironmentProvider, HostToolsProvider, NetworkProvider, DomainCountryProvider } from "@m4l/core";
|
|
3
|
+
import { LocalesProvider, HostThemeProvider, FormatterProvider } from "@m4l/graphics";
|
|
4
|
+
import { WindowToolsMFProvider, DynamicMFParmsProvider } from "@m4l/components";
|
|
5
|
+
import { B as BaseModule } from "../BaseModule/index.6309486a.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
function MFHostApp(props) {
|
|
8
8
|
const {
|
|
9
|
-
children
|
|
10
|
-
currentLocale
|
|
11
|
-
hostTheme
|
|
12
|
-
environment
|
|
13
|
-
hostTools
|
|
14
|
-
axiosOperation
|
|
15
|
-
formatters
|
|
16
|
-
moduleId
|
|
17
|
-
moduleNameField
|
|
18
|
-
skeletonFlags
|
|
19
|
-
privileges
|
|
20
|
-
componentsDictionary
|
|
21
|
-
dynamicMFStore
|
|
22
|
-
windowTools
|
|
23
|
-
} =
|
|
24
|
-
return /* @__PURE__ */
|
|
25
|
-
...
|
|
26
|
-
children: /* @__PURE__ */
|
|
27
|
-
...
|
|
28
|
-
children: /* @__PURE__ */
|
|
29
|
-
axiosOperation
|
|
30
|
-
children: /* @__PURE__ */
|
|
31
|
-
isMicroFrontEnd:
|
|
32
|
-
localeHost:
|
|
33
|
-
children: /* @__PURE__ */
|
|
34
|
-
isMicroFrontEnd:
|
|
35
|
-
...
|
|
36
|
-
children: /* @__PURE__ */
|
|
37
|
-
history:
|
|
38
|
-
children: /* @__PURE__ */
|
|
39
|
-
isMicroFrontEnd:
|
|
40
|
-
id:
|
|
41
|
-
currency:
|
|
42
|
-
currency_decimal_digits:
|
|
43
|
-
decimal_symbol:
|
|
44
|
-
thousands_symbol:
|
|
45
|
-
children: /* @__PURE__ */
|
|
46
|
-
moduleId
|
|
47
|
-
moduleNameField
|
|
48
|
-
componentsDictionary
|
|
49
|
-
skeletonFlags
|
|
50
|
-
privileges
|
|
51
|
-
children: /* @__PURE__ */
|
|
52
|
-
isMicroFrontEnd:
|
|
53
|
-
...
|
|
54
|
-
children: /* @__PURE__ */
|
|
55
|
-
...
|
|
56
|
-
children: /* @__PURE__ */
|
|
57
|
-
store:
|
|
58
|
-
children
|
|
9
|
+
children,
|
|
10
|
+
currentLocale,
|
|
11
|
+
hostTheme,
|
|
12
|
+
environment,
|
|
13
|
+
hostTools,
|
|
14
|
+
axiosOperation,
|
|
15
|
+
formatters,
|
|
16
|
+
moduleId,
|
|
17
|
+
moduleNameField,
|
|
18
|
+
skeletonFlags,
|
|
19
|
+
privileges,
|
|
20
|
+
componentsDictionary,
|
|
21
|
+
dynamicMFStore,
|
|
22
|
+
windowTools
|
|
23
|
+
} = props;
|
|
24
|
+
return /* @__PURE__ */ jsx(EnvironmentProvider, {
|
|
25
|
+
...environment,
|
|
26
|
+
children: /* @__PURE__ */ jsx(HostToolsProvider, {
|
|
27
|
+
...hostTools,
|
|
28
|
+
children: /* @__PURE__ */ jsx(NetworkProvider, {
|
|
29
|
+
axiosOperation,
|
|
30
|
+
children: /* @__PURE__ */ jsx(LocalesProvider, {
|
|
31
|
+
isMicroFrontEnd: true,
|
|
32
|
+
localeHost: currentLocale,
|
|
33
|
+
children: /* @__PURE__ */ jsx(HostThemeProvider, {
|
|
34
|
+
isMicroFrontEnd: true,
|
|
35
|
+
...hostTheme,
|
|
36
|
+
children: /* @__PURE__ */ jsx(unstable_HistoryRouter, {
|
|
37
|
+
history: hostTools.history,
|
|
38
|
+
children: /* @__PURE__ */ jsx(DomainCountryProvider, {
|
|
39
|
+
isMicroFrontEnd: true,
|
|
40
|
+
id: dynamicMFStore?.getState().dynamicMFParameters?.id || 1,
|
|
41
|
+
currency: formatters.currencyFormatter.code,
|
|
42
|
+
currency_decimal_digits: formatters.currencyFormatter.decimalDigits,
|
|
43
|
+
decimal_symbol: formatters.numberFormatter.decimalSymbol,
|
|
44
|
+
thousands_symbol: formatters.numberFormatter.thousandsSymbol,
|
|
45
|
+
children: /* @__PURE__ */ jsx(BaseModule, {
|
|
46
|
+
moduleId,
|
|
47
|
+
moduleNameField,
|
|
48
|
+
componentsDictionary,
|
|
49
|
+
skeletonFlags,
|
|
50
|
+
privileges,
|
|
51
|
+
children: /* @__PURE__ */ jsx(FormatterProvider, {
|
|
52
|
+
isMicroFrontEnd: true,
|
|
53
|
+
...formatters,
|
|
54
|
+
children: /* @__PURE__ */ jsx(WindowToolsMFProvider, {
|
|
55
|
+
...windowTools,
|
|
56
|
+
children: /* @__PURE__ */ jsx(DynamicMFParmsProvider, {
|
|
57
|
+
store: dynamicMFStore,
|
|
58
|
+
children
|
|
59
59
|
})
|
|
60
60
|
})
|
|
61
61
|
})
|
|
@@ -69,5 +69,5 @@ function L(t) {
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
export {
|
|
72
|
-
|
|
72
|
+
MFHostApp as M
|
|
73
73
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { MFIsolationAppProps } from './types';
|
|
2
|
-
export declare function MFIsolationApp(props: MFIsolationAppProps): JSX.Element;
|
|
3
|
+
export declare function MFIsolationApp(props: MFIsolationAppProps): import("react").JSX.Element;
|
|
3
4
|
export default MFIsolationApp;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { useEffect, useMemo, useCallback } from "react";
|
|
2
|
+
import { unstable_HistoryRouter } from "react-router-dom";
|
|
3
|
+
import { ToastContainer, toast } from "react-toastify";
|
|
4
|
+
import { HostThemeProvider, GlobalStyles, FormatterProvider, LocalesProvider, getLocaleFromNetwork } from "@m4l/graphics";
|
|
5
|
+
import { A as AuthProvider } from "../../contexts/AuthContext/index.6f966215.js";
|
|
6
|
+
import { DomainCountryProvider, EnvironmentProvider, HostToolsProvider, NetworkProvider, axiosOperation } from "@m4l/core";
|
|
7
|
+
import { createBrowserHistory } from "history";
|
|
8
|
+
import EventEmitter from "eventemitter3";
|
|
9
|
+
import { format } from "date-fns";
|
|
10
|
+
import { defaultThemeOptions, fnComponentsOverrides } from "@m4l/styles";
|
|
11
|
+
import { u as useAuth } from "../../hooks/useAuth/index.cb6a3420.js";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import NProgress from "nprogress";
|
|
14
|
+
import { B as BaseModule } from "../BaseModule/index.6309486a.js";
|
|
15
|
+
import { AreasProvider } from "@m4l/components";
|
|
16
|
+
function MFAuthApp(props) {
|
|
17
|
+
const {
|
|
18
|
+
children,
|
|
19
|
+
user,
|
|
20
|
+
pwd
|
|
21
|
+
} = props;
|
|
22
|
+
const {
|
|
23
|
+
isAuthenticated,
|
|
24
|
+
isInitialized,
|
|
25
|
+
login,
|
|
26
|
+
user: authUser
|
|
27
|
+
} = useAuth();
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (isInitialized && isAuthenticated === false) {
|
|
30
|
+
login(user, pwd, false);
|
|
31
|
+
}
|
|
32
|
+
}, [isInitialized, isAuthenticated]);
|
|
33
|
+
if (!isAuthenticated)
|
|
34
|
+
return /* @__PURE__ */ jsx("div", {
|
|
35
|
+
children: "Pendiente x atenticar"
|
|
36
|
+
});
|
|
37
|
+
const domianCountry = {
|
|
38
|
+
id: 1,
|
|
39
|
+
currency: "USD",
|
|
40
|
+
currency_decimal_digits: 2,
|
|
41
|
+
decimal_symbol: ".",
|
|
42
|
+
thousands_symbol: ","
|
|
43
|
+
};
|
|
44
|
+
if (authUser?.domain_country) {
|
|
45
|
+
domianCountry.id = authUser?.domain_country.id ?? domianCountry.id;
|
|
46
|
+
domianCountry.currency = authUser?.domain_country.currency ?? domianCountry.currency;
|
|
47
|
+
domianCountry.currency_decimal_digits = authUser?.domain_country.currency_decimal_digits ?? domianCountry.currency_decimal_digits;
|
|
48
|
+
domianCountry.decimal_symbol = authUser?.domain_country.decimal_symbol ?? domianCountry.decimal_symbol;
|
|
49
|
+
domianCountry.thousands_symbol = authUser?.domain_country?.thousands_symbol ?? domianCountry.thousands_symbol;
|
|
50
|
+
}
|
|
51
|
+
return /* @__PURE__ */ jsxs(HostThemeProvider, {
|
|
52
|
+
hostThemeOptions: defaultThemeOptions,
|
|
53
|
+
fnComponentsOverrides,
|
|
54
|
+
isMicroFrontEnd: true,
|
|
55
|
+
children: [/* @__PURE__ */ jsx(ToastContainer, {}), /* @__PURE__ */ jsx(GlobalStyles, {}), /* @__PURE__ */ jsx(DomainCountryProvider, {
|
|
56
|
+
...domianCountry,
|
|
57
|
+
isMicroFrontEnd: false,
|
|
58
|
+
children: /* @__PURE__ */ jsx(FormatterProvider, {
|
|
59
|
+
isMicroFrontEnd: false,
|
|
60
|
+
dateFormatter: {
|
|
61
|
+
formatDate: format
|
|
62
|
+
},
|
|
63
|
+
currencyFormatter: {
|
|
64
|
+
code: domianCountry.currency,
|
|
65
|
+
decimalDigits: domianCountry.currency_decimal_digits
|
|
66
|
+
},
|
|
67
|
+
children
|
|
68
|
+
})
|
|
69
|
+
})]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const history = createBrowserHistory({
|
|
73
|
+
window
|
|
74
|
+
});
|
|
75
|
+
function MFIsolationApp(props) {
|
|
76
|
+
const {
|
|
77
|
+
children,
|
|
78
|
+
user,
|
|
79
|
+
pwd,
|
|
80
|
+
host_api_local,
|
|
81
|
+
host_api_remote,
|
|
82
|
+
host_static_assets,
|
|
83
|
+
environment_assets,
|
|
84
|
+
moduleId,
|
|
85
|
+
skeletonFlags,
|
|
86
|
+
moduleNameField,
|
|
87
|
+
privileges,
|
|
88
|
+
componentsDictionary,
|
|
89
|
+
onLoad,
|
|
90
|
+
activeAreasNetwork = false,
|
|
91
|
+
activeCookiesFromNetwork = false
|
|
92
|
+
} = props;
|
|
93
|
+
const eventEmitter = useMemo(() => new EventEmitter(), []);
|
|
94
|
+
const events_add_listener = useCallback((eventName, handler) => {
|
|
95
|
+
eventEmitter.on(eventName, handler);
|
|
96
|
+
}, [eventEmitter]);
|
|
97
|
+
const events_remove_listener = useCallback((eventName, handler) => {
|
|
98
|
+
if (handler === null) {
|
|
99
|
+
eventEmitter.removeListener(eventName);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
eventEmitter.removeListener(eventName, handler);
|
|
103
|
+
}, [eventEmitter]);
|
|
104
|
+
const events_emit = useCallback((eventName, arg) => {
|
|
105
|
+
eventEmitter.emit(eventName, arg);
|
|
106
|
+
}, [eventEmitter]);
|
|
107
|
+
const startProgress = () => {
|
|
108
|
+
NProgress.configure({
|
|
109
|
+
showSpinner: true
|
|
110
|
+
});
|
|
111
|
+
NProgress.start();
|
|
112
|
+
};
|
|
113
|
+
const stopProgress = () => {
|
|
114
|
+
NProgress.done();
|
|
115
|
+
};
|
|
116
|
+
const environment = useMemo(() => ({
|
|
117
|
+
host: "",
|
|
118
|
+
isLocalhost: true,
|
|
119
|
+
domain_token: "lab1",
|
|
120
|
+
host_api_local,
|
|
121
|
+
host_api_remote,
|
|
122
|
+
host_static_assets,
|
|
123
|
+
environment_assets
|
|
124
|
+
}), []);
|
|
125
|
+
const hostTools = useMemo(() => ({
|
|
126
|
+
history,
|
|
127
|
+
toast,
|
|
128
|
+
startProgress,
|
|
129
|
+
stopProgress,
|
|
130
|
+
events_add_listener,
|
|
131
|
+
events_remove_listener,
|
|
132
|
+
events_emit
|
|
133
|
+
}), []);
|
|
134
|
+
return /* @__PURE__ */ jsx(EnvironmentProvider, {
|
|
135
|
+
...environment,
|
|
136
|
+
children: /* @__PURE__ */ jsx(HostToolsProvider, {
|
|
137
|
+
...hostTools,
|
|
138
|
+
children: /* @__PURE__ */ jsx(NetworkProvider, {
|
|
139
|
+
axiosOperation,
|
|
140
|
+
children: /* @__PURE__ */ jsx(unstable_HistoryRouter, {
|
|
141
|
+
history,
|
|
142
|
+
children: /* @__PURE__ */ jsx(LocalesProvider, {
|
|
143
|
+
isMicroFrontEnd: false,
|
|
144
|
+
getLocaleFromNetwork,
|
|
145
|
+
children: /* @__PURE__ */ jsx(AuthProvider, {
|
|
146
|
+
children: /* @__PURE__ */ jsx(MFAuthApp, {
|
|
147
|
+
user,
|
|
148
|
+
pwd,
|
|
149
|
+
children: /* @__PURE__ */ jsx(BaseModule, {
|
|
150
|
+
moduleId,
|
|
151
|
+
privileges,
|
|
152
|
+
skeletonFlags,
|
|
153
|
+
componentsDictionary,
|
|
154
|
+
moduleNameField,
|
|
155
|
+
children: /* @__PURE__ */ jsx(AreasProvider, {
|
|
156
|
+
onLoad,
|
|
157
|
+
loadAreasFromNetwork: activeAreasNetwork,
|
|
158
|
+
loadCookiesFromNetwork: activeCookiesFromNetwork,
|
|
159
|
+
onSelectLayout: (modId) => {
|
|
160
|
+
console.log("onSelectLayout", modId);
|
|
161
|
+
},
|
|
162
|
+
children
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
export {
|
|
174
|
+
MFIsolationApp as M
|
|
175
|
+
};
|
|
@@ -1,130 +1,160 @@
|
|
|
1
|
-
import { createContext
|
|
2
|
-
import { useHostTools
|
|
3
|
-
import { jsx
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { createContext, useReducer, useEffect } from "react";
|
|
2
|
+
import { useHostTools, useNetwork, useEnvironment, useLocalStorageWithListener, EmitEvents, getLocalStorage, setLocalStorage } from "@m4l/core";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
var EnumTypes = /* @__PURE__ */ ((EnumTypes2) => {
|
|
5
|
+
EnumTypes2["Initial"] = "INITIALIZE";
|
|
6
|
+
EnumTypes2["Login"] = "LOGIN";
|
|
7
|
+
EnumTypes2["Logout"] = "LOGOUT";
|
|
8
|
+
return EnumTypes2;
|
|
9
|
+
})(EnumTypes || {});
|
|
10
|
+
const initialState = {
|
|
11
|
+
isAuthenticated: false,
|
|
12
|
+
isInitialized: false,
|
|
8
13
|
user: null
|
|
9
|
-
}
|
|
10
|
-
|
|
14
|
+
};
|
|
15
|
+
const JWTReducer = (state, action) => {
|
|
16
|
+
switch (action.type) {
|
|
11
17
|
case "INITIALIZE":
|
|
12
18
|
return {
|
|
13
|
-
isAuthenticated:
|
|
14
|
-
isInitialized:
|
|
15
|
-
user:
|
|
19
|
+
isAuthenticated: action.payload.isAuthenticated,
|
|
20
|
+
isInitialized: true,
|
|
21
|
+
user: action.payload.user
|
|
16
22
|
};
|
|
17
23
|
case "LOGIN":
|
|
18
24
|
return {
|
|
19
|
-
...
|
|
20
|
-
isAuthenticated:
|
|
21
|
-
user:
|
|
25
|
+
...state,
|
|
26
|
+
isAuthenticated: true,
|
|
27
|
+
user: action.payload.user
|
|
22
28
|
};
|
|
23
29
|
case "LOGOUT":
|
|
24
30
|
return {
|
|
25
|
-
...
|
|
26
|
-
isAuthenticated:
|
|
31
|
+
...state,
|
|
32
|
+
isAuthenticated: false,
|
|
27
33
|
user: null
|
|
28
34
|
};
|
|
29
35
|
default:
|
|
30
|
-
return
|
|
36
|
+
return state;
|
|
31
37
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
};
|
|
39
|
+
const AuthContext = createContext(null);
|
|
40
|
+
function dispatchInitial(dispatch) {
|
|
41
|
+
dispatch({
|
|
42
|
+
type: EnumTypes.Initial,
|
|
36
43
|
payload: {
|
|
37
|
-
isAuthenticated:
|
|
44
|
+
isAuthenticated: false,
|
|
38
45
|
user: null
|
|
39
46
|
}
|
|
40
47
|
});
|
|
41
48
|
}
|
|
42
|
-
function
|
|
49
|
+
function AuthProvider(props) {
|
|
50
|
+
const {
|
|
51
|
+
children
|
|
52
|
+
} = props;
|
|
53
|
+
const [state, dispatch] = useReducer(JWTReducer, initialState);
|
|
54
|
+
const {
|
|
55
|
+
events_add_listener
|
|
56
|
+
} = useHostTools();
|
|
43
57
|
const {
|
|
44
|
-
|
|
45
|
-
} =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
domain_token: m
|
|
51
|
-
} = v(), [f, l] = N(
|
|
58
|
+
networkOperation
|
|
59
|
+
} = useNetwork();
|
|
60
|
+
const {
|
|
61
|
+
domain_token
|
|
62
|
+
} = useEnvironment();
|
|
63
|
+
const [nextValSession, setNextValSession] = useLocalStorageWithListener(
|
|
52
64
|
"vSession",
|
|
53
65
|
new Date().getTime() + ""
|
|
54
66
|
);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const initialize = async () => {
|
|
69
|
+
networkOperation({
|
|
58
70
|
method: "GET",
|
|
59
|
-
endPoint:
|
|
71
|
+
endPoint: `auth/login`,
|
|
60
72
|
parms: {
|
|
61
|
-
user_data:
|
|
73
|
+
user_data: true
|
|
62
74
|
},
|
|
63
|
-
checkUnAuthorized:
|
|
64
|
-
}).then((
|
|
65
|
-
|
|
66
|
-
type:
|
|
75
|
+
checkUnAuthorized: false
|
|
76
|
+
}).then((response) => {
|
|
77
|
+
dispatch({
|
|
78
|
+
type: EnumTypes.Initial,
|
|
67
79
|
payload: {
|
|
68
|
-
isAuthenticated:
|
|
69
|
-
user:
|
|
80
|
+
isAuthenticated: true,
|
|
81
|
+
user: response.user
|
|
70
82
|
}
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
});
|
|
84
|
+
const useSaved = getLocalStorage("userData", {
|
|
85
|
+
email: response.user.email,
|
|
86
|
+
remember: true
|
|
87
|
+
});
|
|
88
|
+
if (useSaved?.email !== response.user.email) {
|
|
89
|
+
setLocalStorage("userData", {
|
|
90
|
+
email: response.user.email
|
|
91
|
+
}, true);
|
|
92
|
+
}
|
|
77
93
|
}).catch(() => {
|
|
78
|
-
|
|
94
|
+
dispatchInitial(dispatch);
|
|
79
95
|
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
96
|
+
};
|
|
97
|
+
initialize();
|
|
98
|
+
}, [nextValSession]);
|
|
99
|
+
const login = async (email, password, remember) => {
|
|
100
|
+
await networkOperation({
|
|
101
|
+
endPoint: `auth/login`,
|
|
85
102
|
method: "POST",
|
|
86
103
|
data: {
|
|
87
|
-
email
|
|
88
|
-
password
|
|
89
|
-
domain_token
|
|
104
|
+
email,
|
|
105
|
+
password,
|
|
106
|
+
domain_token
|
|
107
|
+
}
|
|
108
|
+
}).then((response) => {
|
|
109
|
+
const user = response.data;
|
|
110
|
+
if (remember) {
|
|
111
|
+
setLocalStorage("userData", {
|
|
112
|
+
email,
|
|
113
|
+
remember
|
|
114
|
+
});
|
|
115
|
+
} else {
|
|
116
|
+
setLocalStorage("userData", {
|
|
117
|
+
email: "",
|
|
118
|
+
remember
|
|
119
|
+
});
|
|
90
120
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
o ? r("userData", {
|
|
94
|
-
email: i,
|
|
95
|
-
remember: o
|
|
96
|
-
}) : r("userData", {
|
|
97
|
-
email: "",
|
|
98
|
-
remember: o
|
|
99
|
-
}), s({
|
|
100
|
-
type: n.Login,
|
|
121
|
+
dispatch({
|
|
122
|
+
type: EnumTypes.Login,
|
|
101
123
|
payload: {
|
|
102
|
-
user
|
|
124
|
+
user
|
|
103
125
|
}
|
|
104
|
-
})
|
|
126
|
+
});
|
|
127
|
+
setNextValSession(new Date().getTime() + "");
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
const logout = async (isAuthenticated) => {
|
|
131
|
+
if (isAuthenticated) {
|
|
132
|
+
await networkOperation({
|
|
133
|
+
endPoint: `auth/logout`,
|
|
134
|
+
method: "POST"
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
dispatch({
|
|
138
|
+
type: EnumTypes.Logout
|
|
105
139
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}), s({
|
|
111
|
-
type: n.Logout
|
|
112
|
-
}), l(new Date().getTime() + "");
|
|
113
|
-
}, p = () => {
|
|
114
|
-
c(!1);
|
|
140
|
+
setNextValSession(new Date().getTime() + "");
|
|
141
|
+
};
|
|
142
|
+
const onNetserviceUnautorized = () => {
|
|
143
|
+
logout(false);
|
|
115
144
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}, [])
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
events_add_listener(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, onNetserviceUnautorized);
|
|
147
|
+
}, []);
|
|
148
|
+
return /* @__PURE__ */ jsx(AuthContext.Provider, {
|
|
119
149
|
value: {
|
|
120
|
-
...
|
|
121
|
-
login
|
|
122
|
-
logout
|
|
150
|
+
...state,
|
|
151
|
+
login,
|
|
152
|
+
logout
|
|
123
153
|
},
|
|
124
|
-
children
|
|
154
|
+
children
|
|
125
155
|
});
|
|
126
156
|
}
|
|
127
157
|
export {
|
|
128
|
-
|
|
129
|
-
|
|
158
|
+
AuthProvider as A,
|
|
159
|
+
AuthContext as a
|
|
130
160
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { AuthProviderProps, SessionContextType } from './types';
|
|
3
3
|
declare const AuthContext: import("react").Context<SessionContextType | null>;
|
|
4
|
-
declare function AuthProvider(props: AuthProviderProps): JSX.Element;
|
|
4
|
+
declare function AuthProvider(props: AuthProviderProps): import("react").JSX.Element;
|
|
5
5
|
export { AuthContext, AuthProvider };
|