@m4l/layouts 0.1.22 → 0.1.25
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/.eslintignore +2 -0
- package/.eslintrc.cjs +118 -0
- package/.gitignore +23 -0
- package/.gitlab-ci.yml +16 -0
- package/.prettierignore +3 -0
- package/.prettierrc.json +26 -0
- package/.vscode/settings.json +50 -0
- package/dist/components/BaseModule/index.6309486a.js +33 -0
- package/dist/components/BaseModule/index.d.ts +4 -0
- package/dist/components/BaseModule/types.d.ts +9 -0
- package/dist/components/MFHostApp/index.1700d13a.js +69 -0
- package/{components → dist/components}/MFHostApp/types.d.ts +3 -7
- package/dist/components/MFIsolationApp/index.b21e5671.js +151 -0
- package/dist/components/MFIsolationApp/types.d.ts +11 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.deb4e7ac.js +6 -0
- package/{contexts → dist/contexts}/AuthContext/types.d.ts +1 -1
- package/dist/contexts/index.b46a2699.js +1 -0
- package/dist/hooks/index.2022a179.js +4 -0
- package/{hooks/useMasterDetail/index.8e9e900b.js → dist/hooks/useMasterDetail/index.1b024fd5.js} +1 -1
- package/{hooks/useModule/index.096d7d13.js → dist/hooks/useModule/index.6ff7d08a.js} +1 -1
- package/dist/index.js +41 -0
- package/dist/layouts/MasterDetailLayout/index.3da0ffda.js +104 -0
- package/{layouts → dist/layouts}/ModuleLayout/contexts/ModuleContext/types.d.ts +2 -7
- package/dist/layouts/ModuleLayout/index.a76397df.js +101 -0
- package/dist/layouts/ModuleLayout/types.d.ts +15 -0
- package/dist/layouts/index.014e41ba.js +8 -0
- package/{layouts → dist/layouts}/index.d.ts +0 -1
- package/dist/package.json +36 -0
- package/package.json +57 -12
- package/src/@types/index.ts +8 -0
- package/src/components/BaseModule/index.tsx +59 -0
- package/src/components/BaseModule/types.ts +12 -0
- package/src/components/MFHostApp/index.tsx +95 -0
- package/src/components/MFHostApp/types.ts +16 -0
- package/src/components/MFIsolationApp/index.tsx +164 -0
- package/src/components/MFIsolationApp/subcomponents/MFAuthApp/index.tsx +98 -0
- package/src/components/MFIsolationApp/subcomponents/MFAuthApp/types.ts +7 -0
- package/src/components/MFIsolationApp/types.ts +12 -0
- package/src/components/index.ts +5 -0
- package/src/contexts/AuthContext/index.tsx +189 -0
- package/src/contexts/AuthContext/types.ts +65 -0
- package/src/contexts/index.ts +1 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useAuth/index.ts +12 -0
- package/src/hooks/useMasterDetail/index.ts +6 -0
- package/src/hooks/useModule/index.ts +13 -0
- package/src/index.ts +7 -0
- package/src/layouts/MasterDetailLayout/components/ButtonDetail/index.tsx +38 -0
- package/src/layouts/MasterDetailLayout/contexts/MasterDetailContext/index.tsx +34 -0
- package/src/layouts/MasterDetailLayout/contexts/MasterDetailContext/types.ts +19 -0
- package/src/layouts/MasterDetailLayout/dicctionary.ts +20 -0
- package/src/layouts/MasterDetailLayout/index.tsx +165 -0
- package/src/layouts/MasterDetailLayout/types.ts +11 -0
- package/src/layouts/ModuleLayout/contexts/ModuleContext/index.tsx +56 -0
- package/src/layouts/ModuleLayout/contexts/ModuleContext/types.ts +23 -0
- package/src/layouts/ModuleLayout/dicctionary.ts +11 -0
- package/src/layouts/ModuleLayout/index.tsx +59 -0
- package/src/layouts/ModuleLayout/subcomponents/InnerModule/index.tsx +35 -0
- package/src/layouts/ModuleLayout/subcomponents/InnerModule/styles.tsx +31 -0
- package/src/layouts/ModuleLayout/subcomponents/InnerModule/types.ts +11 -0
- package/src/layouts/ModuleLayout/types.ts +31 -0
- package/src/layouts/NoAuthModuleLayout/dicctionary.ts +9 -0
- package/src/layouts/NoAuthModuleLayout/index.tsx +85 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/index.tsx +43 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/styles.tsx +6 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/index.tsx +14 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/styles.tsx +7 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/AppBar/index.tsx +25 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/AppBar/styles.tsx +11 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/index.tsx +17 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/styles.tsx +19 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/subcomponents/NameDescription/index.tsx +25 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/subcomponents/NameDescription/styles.tsx +8 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/types.ts +5 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/types.ts +5 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/LogoLeyend/index.tsx +28 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/LogoLeyend/styles.tsx +16 -0
- package/src/layouts/NoAuthModuleLayout/subcomponents/InnerModule/types.ts +5 -0
- package/src/layouts/NoAuthModuleLayout/types.ts +22 -0
- package/src/layouts/index.ts +8 -0
- package/src/test/setup.ts +1 -0
- package/src/test/utils.tsx +20 -0
- package/src/vite-env.d.ts +3 -0
- package/tsconfig.json +29 -0
- package/tsconfig.node.json +8 -0
- package/vite.config.ts +172 -0
- package/components/MFHostApp/index.b3c15ec3.js +0 -52
- package/components/MFIsolationApp/index.28f538a3.js +0 -106
- package/components/MFIsolationApp/types.d.ts +0 -10
- package/components/index.d.ts +0 -3
- package/index.js +0 -38
- package/layouts/MasterDetailLayout/components/ButtonDetail/index.d.ts +0 -3
- package/layouts/MasterDetailLayout/index.71de0dc7.js +0 -141
- package/layouts/ModuleLayout/index.842072c5.js +0 -348
- package/layouts/ModuleLayout/subcomponents/InnerModule/subcomponents/Header/index.d.ts +0 -2
- package/layouts/ModuleLayout/subcomponents/InnerModule/subcomponents/Header/skeleton.d.ts +0 -2
- package/layouts/ModuleLayout/subcomponents/InnerModule/subcomponents/Header/styles.d.ts +0 -8
- package/layouts/ModuleLayout/subcomponents/InnerModule/subcomponents/Header/types.d.ts +0 -2
- package/layouts/ModuleLayout/types.d.ts +0 -29
- package/node_modules.26043cf4.js +0 -1601
- package/vendor.95e38403.js +0 -20
- /package/{components → dist/components}/MFHostApp/index.d.ts +0 -0
- /package/{components → dist/components}/MFIsolationApp/index.d.ts +0 -0
- /package/{components → dist/components}/MFIsolationApp/subcomponents/MFAuthApp/index.d.ts +0 -0
- /package/{components → dist/components}/MFIsolationApp/subcomponents/MFAuthApp/types.d.ts +0 -0
- /package/{contexts → dist/contexts}/AuthContext/index.6f966215.js +0 -0
- /package/{contexts → dist/contexts}/AuthContext/index.d.ts +0 -0
- /package/{contexts → dist/contexts}/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useAuth/index.cb6a3420.js +0 -0
- /package/{hooks → dist/hooks}/useAuth/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useMasterDetail/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useModule/index.d.ts +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{layouts → dist/layouts}/MasterDetailLayout/contexts/MasterDetailContext/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/MasterDetailLayout/contexts/MasterDetailContext/types.d.ts +0 -0
- /package/{layouts → dist/layouts}/MasterDetailLayout/dicctionary.d.ts +0 -0
- /package/{layouts → dist/layouts}/MasterDetailLayout/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/MasterDetailLayout/types.d.ts +0 -0
- /package/{layouts → dist/layouts}/ModuleLayout/contexts/ModuleContext/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/ModuleLayout/dicctionary.d.ts +0 -0
- /package/{layouts → dist/layouts}/ModuleLayout/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/ModuleLayout/subcomponents/InnerModule/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/ModuleLayout/subcomponents/InnerModule/styles.d.ts +0 -0
- /package/{layouts → dist/layouts}/ModuleLayout/subcomponents/InnerModule/types.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/dicctionary.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/index.5d1098ef.js +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/styles.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/styles.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/AppBar/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/AppBar/styles.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/styles.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/subcomponents/NameDescription/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/subcomponents/NameDescription/styles.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/subcomponents/Form/types.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/AppBarForm/types.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/LogoLeyend/index.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/LogoLeyend/styles.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/subcomponents/InnerModule/types.d.ts +0 -0
- /package/{layouts → dist/layouts}/NoAuthModuleLayout/types.d.ts +0 -0
- /package/{vite-env.d.ts → dist/vite-env.d.ts} +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// react
|
|
2
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
3
|
+
import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
|
|
4
|
+
|
|
5
|
+
import { toast } from 'react-toastify';
|
|
6
|
+
|
|
7
|
+
//m4l
|
|
8
|
+
import { getLocaleFromNetwork, LocalesProvider } from '@m4l/graphics';
|
|
9
|
+
import { AuthProvider } from '../../contexts/AuthContext';
|
|
10
|
+
import {
|
|
11
|
+
axiosOperation,
|
|
12
|
+
EnvironmentProvider,
|
|
13
|
+
EnvironmentType,
|
|
14
|
+
EventListenerBase,
|
|
15
|
+
HostToolsProvider,
|
|
16
|
+
HostToolsType,
|
|
17
|
+
Maybe,
|
|
18
|
+
NetworkProvider,
|
|
19
|
+
} from '@m4l/core';
|
|
20
|
+
// external components
|
|
21
|
+
import { createBrowserHistory } from 'history';
|
|
22
|
+
import EventEmitter from 'eventemitter3';
|
|
23
|
+
// mui
|
|
24
|
+
// internal components
|
|
25
|
+
// hooks /providers
|
|
26
|
+
|
|
27
|
+
// sub comoponents
|
|
28
|
+
import MFAuthApp from './subcomponents/MFAuthApp';
|
|
29
|
+
// types
|
|
30
|
+
import { MFIsolationAppProps } from './types';
|
|
31
|
+
// network
|
|
32
|
+
|
|
33
|
+
// config
|
|
34
|
+
|
|
35
|
+
// utils
|
|
36
|
+
|
|
37
|
+
// css
|
|
38
|
+
import NProgress from 'nprogress';
|
|
39
|
+
import BaseModule from '../BaseModule';
|
|
40
|
+
import { AreasProvider } from '@m4l/components';
|
|
41
|
+
|
|
42
|
+
const history = createBrowserHistory({ window });
|
|
43
|
+
|
|
44
|
+
export function MFIsolationApp(props: MFIsolationAppProps) {
|
|
45
|
+
const {
|
|
46
|
+
children,
|
|
47
|
+
user,
|
|
48
|
+
pwd,
|
|
49
|
+
host_api_local,
|
|
50
|
+
host_api_remote,
|
|
51
|
+
host_static_assets,
|
|
52
|
+
environment_assets,
|
|
53
|
+
moduleId,
|
|
54
|
+
skeletonFlags,
|
|
55
|
+
moduleNameField,
|
|
56
|
+
privileges,
|
|
57
|
+
componentsDictionary,
|
|
58
|
+
onLoad,
|
|
59
|
+
activeAreasNetwork = false,
|
|
60
|
+
} = props;
|
|
61
|
+
|
|
62
|
+
const eventEmitter = useMemo(() => new EventEmitter(), []);
|
|
63
|
+
|
|
64
|
+
const events_add_listener = useCallback(
|
|
65
|
+
(eventName: string, handler: EventListenerBase) => {
|
|
66
|
+
eventEmitter.on(eventName, handler);
|
|
67
|
+
},
|
|
68
|
+
[eventEmitter],
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const events_remove_listener = useCallback(
|
|
72
|
+
(eventName: string, handler: Maybe<EventListenerBase>) => {
|
|
73
|
+
if (handler === null) {
|
|
74
|
+
eventEmitter.removeListener(eventName);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
eventEmitter.removeListener(eventName, handler);
|
|
78
|
+
},
|
|
79
|
+
[eventEmitter],
|
|
80
|
+
);
|
|
81
|
+
const events_emit = useCallback(
|
|
82
|
+
(eventName: string, arg: any) => {
|
|
83
|
+
eventEmitter.emit(eventName, arg);
|
|
84
|
+
},
|
|
85
|
+
[eventEmitter],
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const startProgress = () => {
|
|
89
|
+
NProgress.configure({
|
|
90
|
+
showSpinner: true,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
NProgress.start();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const stopProgress = () => {
|
|
97
|
+
NProgress.done();
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const environment: EnvironmentType = useMemo(
|
|
101
|
+
() => ({
|
|
102
|
+
host: '',
|
|
103
|
+
isLocalhost: true,
|
|
104
|
+
domain_token: 'lab1',
|
|
105
|
+
host_api_local,
|
|
106
|
+
host_api_remote,
|
|
107
|
+
host_static_assets,
|
|
108
|
+
environment_assets,
|
|
109
|
+
}),
|
|
110
|
+
[],
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const hostTools: HostToolsType = useMemo(
|
|
114
|
+
() => ({
|
|
115
|
+
history,
|
|
116
|
+
toast,
|
|
117
|
+
startProgress,
|
|
118
|
+
stopProgress,
|
|
119
|
+
events_add_listener,
|
|
120
|
+
events_remove_listener,
|
|
121
|
+
events_emit,
|
|
122
|
+
}),
|
|
123
|
+
[],
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
console.log('useEffect IsolationApp');
|
|
128
|
+
}, []);
|
|
129
|
+
return (
|
|
130
|
+
<EnvironmentProvider {...environment}>
|
|
131
|
+
<HostToolsProvider {...hostTools}>
|
|
132
|
+
<NetworkProvider axiosOperation={axiosOperation}>
|
|
133
|
+
<HistoryRouter history={history}>
|
|
134
|
+
<LocalesProvider
|
|
135
|
+
isMicroFrontEnd={false}
|
|
136
|
+
getLocaleFromNetwork={getLocaleFromNetwork}
|
|
137
|
+
>
|
|
138
|
+
<AuthProvider>
|
|
139
|
+
<MFAuthApp user={user} pwd={pwd}>
|
|
140
|
+
<BaseModule
|
|
141
|
+
moduleId={moduleId}
|
|
142
|
+
privileges={privileges}
|
|
143
|
+
skeletonFlags={skeletonFlags}
|
|
144
|
+
componentsDictionary={componentsDictionary}
|
|
145
|
+
moduleNameField={moduleNameField}
|
|
146
|
+
>
|
|
147
|
+
<AreasProvider
|
|
148
|
+
onLoad={onLoad}
|
|
149
|
+
activeAreasNetwork={activeAreasNetwork}
|
|
150
|
+
>
|
|
151
|
+
{children}
|
|
152
|
+
</AreasProvider>
|
|
153
|
+
</BaseModule>
|
|
154
|
+
</MFAuthApp>
|
|
155
|
+
</AuthProvider>
|
|
156
|
+
</LocalesProvider>
|
|
157
|
+
</HistoryRouter>
|
|
158
|
+
</NetworkProvider>
|
|
159
|
+
</HostToolsProvider>
|
|
160
|
+
</EnvironmentProvider>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export default MFIsolationApp;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// react
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { format } from 'date-fns';
|
|
4
|
+
//m4l
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
defaultThemeOptions,
|
|
8
|
+
fnComponentsOverrides,
|
|
9
|
+
FormatterProvider,
|
|
10
|
+
HostThemeProvider,
|
|
11
|
+
// ProgressBarStyle,
|
|
12
|
+
} from '@m4l/graphics';
|
|
13
|
+
// external components
|
|
14
|
+
|
|
15
|
+
// mui
|
|
16
|
+
|
|
17
|
+
// internal components
|
|
18
|
+
|
|
19
|
+
// hooks /providers
|
|
20
|
+
|
|
21
|
+
// sub comoponents
|
|
22
|
+
|
|
23
|
+
// types
|
|
24
|
+
|
|
25
|
+
// network
|
|
26
|
+
|
|
27
|
+
// config
|
|
28
|
+
|
|
29
|
+
// utils
|
|
30
|
+
|
|
31
|
+
// css
|
|
32
|
+
|
|
33
|
+
import { useAuth } from '../../../../hooks/useAuth';
|
|
34
|
+
import { MFAuthAppProps } from './types';
|
|
35
|
+
import { ToastContainer } from 'react-toastify';
|
|
36
|
+
import { DomainCountry, DomainCountryProvider } from '@m4l/core';
|
|
37
|
+
|
|
38
|
+
export function MFAuthApp(props: MFAuthAppProps) {
|
|
39
|
+
const { children, user, pwd } = props;
|
|
40
|
+
const { isAuthenticated, isInitialized, login, user: authUser } = useAuth();
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
// Atenticarse si no lo logro en el paso anterior dado por el efecto de AuthProvider
|
|
44
|
+
|
|
45
|
+
if (isInitialized && isAuthenticated === false) {
|
|
46
|
+
console.log('useEffect MFAuthApp Login');
|
|
47
|
+
login(user, pwd, false);
|
|
48
|
+
}
|
|
49
|
+
}, [isInitialized, isAuthenticated]);
|
|
50
|
+
|
|
51
|
+
if (!isAuthenticated) return <div>Pendiente x atenticar</div>;
|
|
52
|
+
|
|
53
|
+
const domianCountry: DomainCountry = {
|
|
54
|
+
id: 1,
|
|
55
|
+
currency: 'USD',
|
|
56
|
+
currency_decimal_digits: 2,
|
|
57
|
+
decimal_symbol: '.',
|
|
58
|
+
thousands_symbol: ',',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if (authUser?.domain_country) {
|
|
62
|
+
domianCountry.id = authUser?.domain_country.id ?? domianCountry.id;
|
|
63
|
+
domianCountry.currency = authUser?.domain_country.currency ?? domianCountry.currency;
|
|
64
|
+
domianCountry.currency_decimal_digits =
|
|
65
|
+
authUser?.domain_country.currency_decimal_digits ??
|
|
66
|
+
domianCountry.currency_decimal_digits;
|
|
67
|
+
domianCountry.decimal_symbol =
|
|
68
|
+
authUser?.domain_country.decimal_symbol ?? domianCountry.decimal_symbol;
|
|
69
|
+
domianCountry.thousands_symbol =
|
|
70
|
+
authUser?.domain_country?.thousands_symbol ?? domianCountry.thousands_symbol;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<HostThemeProvider
|
|
75
|
+
hostThemeOptions={defaultThemeOptions}
|
|
76
|
+
fnComponentsOverrides={fnComponentsOverrides}
|
|
77
|
+
isMicroFrontEnd={true}
|
|
78
|
+
>
|
|
79
|
+
<ToastContainer />
|
|
80
|
+
<DomainCountryProvider {...domianCountry} isMicroFrontEnd={false}>
|
|
81
|
+
<FormatterProvider
|
|
82
|
+
isMicroFrontEnd={false}
|
|
83
|
+
dateFormatter={{
|
|
84
|
+
formatDate: format,
|
|
85
|
+
}}
|
|
86
|
+
currencyFormatter={{
|
|
87
|
+
code: domianCountry.currency,
|
|
88
|
+
decimalDigits: domianCountry.currency_decimal_digits,
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
{children}
|
|
92
|
+
</FormatterProvider>
|
|
93
|
+
</DomainCountryProvider>
|
|
94
|
+
</HostThemeProvider>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default MFAuthApp;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseModuleProps } from '../BaseModule/types';
|
|
2
|
+
|
|
3
|
+
export type MFIsolationAppProps = BaseModuleProps & {
|
|
4
|
+
user: string;
|
|
5
|
+
pwd: string;
|
|
6
|
+
host_api_local: string;
|
|
7
|
+
host_api_remote: string;
|
|
8
|
+
host_static_assets: string;
|
|
9
|
+
environment_assets: string;
|
|
10
|
+
onLoad: () => void;
|
|
11
|
+
activeAreasNetwork?: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// react
|
|
2
|
+
import { createContext, useEffect, useReducer } from 'react';
|
|
3
|
+
// m4l
|
|
4
|
+
import {
|
|
5
|
+
getLocalStorage,
|
|
6
|
+
setLocalStorage,
|
|
7
|
+
useEnvironment,
|
|
8
|
+
useHostTools,
|
|
9
|
+
useLocalStorageWithListener,
|
|
10
|
+
useNetwork,
|
|
11
|
+
} from '@m4l/core';
|
|
12
|
+
// utils
|
|
13
|
+
|
|
14
|
+
// types
|
|
15
|
+
|
|
16
|
+
import type { AuthProviderProps, AuthState, SessionActions, SessionContextType } from './types';
|
|
17
|
+
|
|
18
|
+
// constants
|
|
19
|
+
import { EnumTypes } from './types';
|
|
20
|
+
import { EmitEvents } from '@m4l/core';
|
|
21
|
+
|
|
22
|
+
const initialState: AuthState = {
|
|
23
|
+
isAuthenticated: false,
|
|
24
|
+
isInitialized: false,
|
|
25
|
+
user: null,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const JWTReducer = (state: AuthState, action: SessionActions) => {
|
|
29
|
+
switch (action.type) {
|
|
30
|
+
case 'INITIALIZE':
|
|
31
|
+
return {
|
|
32
|
+
isAuthenticated: action.payload.isAuthenticated,
|
|
33
|
+
isInitialized: true,
|
|
34
|
+
user: action.payload.user,
|
|
35
|
+
};
|
|
36
|
+
case 'LOGIN':
|
|
37
|
+
return {
|
|
38
|
+
...state,
|
|
39
|
+
isAuthenticated: true,
|
|
40
|
+
user: action.payload.user,
|
|
41
|
+
};
|
|
42
|
+
case 'LOGOUT':
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
isAuthenticated: false,
|
|
46
|
+
user: null,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
default:
|
|
50
|
+
return state;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const AuthContext = createContext<SessionContextType | null>(null);
|
|
55
|
+
|
|
56
|
+
// ----------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
function dispatchInitial(dispatch: React.Dispatch<SessionActions>) {
|
|
59
|
+
dispatch({
|
|
60
|
+
type: EnumTypes.Initial,
|
|
61
|
+
payload: {
|
|
62
|
+
isAuthenticated: false,
|
|
63
|
+
user: null,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function AuthProvider(props: AuthProviderProps) {
|
|
69
|
+
const { children } = props;
|
|
70
|
+
const [state, dispatch] = useReducer(JWTReducer, initialState);
|
|
71
|
+
const { events_add_listener } = useHostTools();
|
|
72
|
+
const { networkOperation } = useNetwork();
|
|
73
|
+
const { domain_token } = useEnvironment();
|
|
74
|
+
const [nextValSession, setNextValSession] = useLocalStorageWithListener<string>(
|
|
75
|
+
//Variable para saber si ha cambiado la session en otro navegador
|
|
76
|
+
'vSession',
|
|
77
|
+
new Date().getTime() + '',
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
//Verifica si el usuario esta logueado
|
|
82
|
+
//Si es por primera vez (No hay localstorage) se envía el lenguage del navegador
|
|
83
|
+
|
|
84
|
+
const initialize = async () => {
|
|
85
|
+
networkOperation({
|
|
86
|
+
method: 'GET',
|
|
87
|
+
endPoint: `auth/login`,
|
|
88
|
+
parms: { user_data: true },
|
|
89
|
+
checkUnAuthorized: false,
|
|
90
|
+
})
|
|
91
|
+
.then(response => {
|
|
92
|
+
// const user_logged: User = response.user;
|
|
93
|
+
|
|
94
|
+
dispatch({
|
|
95
|
+
type: EnumTypes.Initial,
|
|
96
|
+
payload: {
|
|
97
|
+
isAuthenticated: true,
|
|
98
|
+
user: response.user,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
//requintar el localstorage por si cambia externamente
|
|
102
|
+
const useSaved = getLocalStorage('userData', {
|
|
103
|
+
email: response.user.email,
|
|
104
|
+
remember: true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
if (useSaved?.email !== response.user.email) {
|
|
108
|
+
//Si cambiaron el usuario
|
|
109
|
+
setLocalStorage('userData', { email: response.user.email }, true);
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
.catch(() => {
|
|
113
|
+
//No está logueado
|
|
114
|
+
dispatchInitial(dispatch);
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
initialize();
|
|
119
|
+
|
|
120
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
121
|
+
}, [nextValSession]);
|
|
122
|
+
|
|
123
|
+
const login = async (email: string, password: string, remember: boolean) => {
|
|
124
|
+
await networkOperation({
|
|
125
|
+
endPoint: `auth/login`,
|
|
126
|
+
method: 'POST',
|
|
127
|
+
data: {
|
|
128
|
+
email,
|
|
129
|
+
password,
|
|
130
|
+
domain_token,
|
|
131
|
+
},
|
|
132
|
+
}).then(response => {
|
|
133
|
+
const user = response.data;
|
|
134
|
+
|
|
135
|
+
if (remember) {
|
|
136
|
+
setLocalStorage('userData', { email, remember });
|
|
137
|
+
} else {
|
|
138
|
+
setLocalStorage('userData', { email: '', remember });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
dispatch({
|
|
142
|
+
type: EnumTypes.Login,
|
|
143
|
+
payload: {
|
|
144
|
+
user,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
setNextValSession(new Date().getTime() + '');
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const logout = async (isAuthenticated: boolean) => {
|
|
152
|
+
if (isAuthenticated) {
|
|
153
|
+
await networkOperation({
|
|
154
|
+
endPoint: `auth/logout`,
|
|
155
|
+
method: 'POST',
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
dispatch({ type: EnumTypes.Logout });
|
|
159
|
+
setNextValSession(new Date().getTime() + '');
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const onNetserviceUnautorized = () => {
|
|
163
|
+
logout(false);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
//Verifica si el usuario esta logueado
|
|
168
|
+
|
|
169
|
+
events_add_listener(
|
|
170
|
+
EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED,
|
|
171
|
+
onNetserviceUnautorized,
|
|
172
|
+
);
|
|
173
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
174
|
+
}, []);
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<AuthContext.Provider
|
|
178
|
+
value={{
|
|
179
|
+
...state,
|
|
180
|
+
login,
|
|
181
|
+
logout,
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
{children}
|
|
185
|
+
</AuthContext.Provider>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { AuthContext, AuthProvider };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { DomainCountry, Maybe } from '@m4l/core';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line no-shadow
|
|
5
|
+
export enum EnumTypes {
|
|
6
|
+
Initial = 'INITIALIZE',
|
|
7
|
+
Login = 'LOGIN',
|
|
8
|
+
Logout = 'LOGOUT',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type AuthProviderProps = {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ActionMap<M extends { [index: string]: any }> = {
|
|
16
|
+
[Key in keyof M]: M[Key] extends undefined
|
|
17
|
+
? {
|
|
18
|
+
type: Key;
|
|
19
|
+
}
|
|
20
|
+
: {
|
|
21
|
+
type: Key;
|
|
22
|
+
payload: M[Key];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type SessionAuthPayload = {
|
|
27
|
+
[EnumTypes.Initial]: {
|
|
28
|
+
isAuthenticated: boolean;
|
|
29
|
+
user: AuthUser;
|
|
30
|
+
};
|
|
31
|
+
[EnumTypes.Login]: {
|
|
32
|
+
user: AuthUser;
|
|
33
|
+
};
|
|
34
|
+
[EnumTypes.Logout]: undefined;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type SessionActions = ActionMap<SessionAuthPayload>[keyof ActionMap<SessionAuthPayload>];
|
|
38
|
+
|
|
39
|
+
// export type AuthStoreState = {
|
|
40
|
+
// user: User;
|
|
41
|
+
// remember?: boolean;
|
|
42
|
+
// };
|
|
43
|
+
|
|
44
|
+
export interface User {
|
|
45
|
+
email: string;
|
|
46
|
+
id: number;
|
|
47
|
+
first_name: string;
|
|
48
|
+
last_name: string;
|
|
49
|
+
account_id: number;
|
|
50
|
+
domain_country: DomainCountry;
|
|
51
|
+
avatar_url?: Maybe<string>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type AuthUser = Maybe<User>;
|
|
55
|
+
|
|
56
|
+
export type AuthState = {
|
|
57
|
+
isAuthenticated: boolean;
|
|
58
|
+
isInitialized: boolean;
|
|
59
|
+
user: AuthUser;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export interface SessionContextType extends AuthState {
|
|
63
|
+
login: (email: string, password: string, remember: boolean) => object | undefined;
|
|
64
|
+
logout: (isAuthenticated: boolean) => Promise<void>;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AuthContext';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { AuthContext } from '../../contexts/AuthContext';
|
|
3
|
+
|
|
4
|
+
export const useAuth = () => {
|
|
5
|
+
const context = useContext(AuthContext);
|
|
6
|
+
|
|
7
|
+
if (!context) throw new Error('Auth context must be use inside AuthProvider');
|
|
8
|
+
|
|
9
|
+
return context;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default useAuth;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { MasterDetailContext } from '../../layouts/MasterDetailLayout/contexts/MasterDetailContext';
|
|
3
|
+
|
|
4
|
+
// ----------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
export const useMasterDetail = () => useContext(MasterDetailContext);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { ModuleContext } from '../../layouts/ModuleLayout/contexts/ModuleContext';
|
|
3
|
+
|
|
4
|
+
// ----------------------------------------------------------------------
|
|
5
|
+
export const useModule = () => {
|
|
6
|
+
const context = useContext(ModuleContext);
|
|
7
|
+
|
|
8
|
+
if (!context) throw new Error('useModule context must be use inside ModuleContext');
|
|
9
|
+
|
|
10
|
+
return context;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default useModule;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// react
|
|
2
|
+
|
|
3
|
+
// mui
|
|
4
|
+
import { Button } from '@mui/material';
|
|
5
|
+
import { ComponentActionProps } from '@m4l/components';
|
|
6
|
+
import { useMasterDetail } from '../../../../hooks/useMasterDetail';
|
|
7
|
+
|
|
8
|
+
// external libraries
|
|
9
|
+
|
|
10
|
+
// componentes estilados
|
|
11
|
+
|
|
12
|
+
// sub components
|
|
13
|
+
|
|
14
|
+
// dictionary
|
|
15
|
+
|
|
16
|
+
// context
|
|
17
|
+
|
|
18
|
+
// hooks
|
|
19
|
+
|
|
20
|
+
// types
|
|
21
|
+
|
|
22
|
+
// constants
|
|
23
|
+
|
|
24
|
+
export function ButtonDetail(props: ComponentActionProps) {
|
|
25
|
+
const { masterSelection } = useMasterDetail();
|
|
26
|
+
const { onClick, description } = props;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Button
|
|
30
|
+
key="miDetail"
|
|
31
|
+
onClick={onClick}
|
|
32
|
+
variant="outlined"
|
|
33
|
+
disabled={masterSelection === undefined ? true : false}
|
|
34
|
+
>
|
|
35
|
+
{description}
|
|
36
|
+
</Button>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// react
|
|
2
|
+
import { createContext, useState } from 'react';
|
|
3
|
+
import { voidFunction } from '@m4l/core';
|
|
4
|
+
|
|
5
|
+
// types
|
|
6
|
+
import { MasterDetailContextProps, MasterDetailProviderProps, MasterSelecion } from './types';
|
|
7
|
+
|
|
8
|
+
const initialState: MasterDetailContextProps = {
|
|
9
|
+
masterSelection: undefined,
|
|
10
|
+
onChangeMasterSelection: voidFunction,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const MasterDetailContext = createContext<MasterDetailContextProps>(initialState);
|
|
14
|
+
|
|
15
|
+
// ----------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
function MasterDetailProvider(props: MasterDetailProviderProps) {
|
|
18
|
+
const { children } = props;
|
|
19
|
+
|
|
20
|
+
const [masterSelection, setMasterSelection] = useState<MasterSelecion>(undefined);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<MasterDetailContext.Provider
|
|
24
|
+
value={{
|
|
25
|
+
masterSelection,
|
|
26
|
+
onChangeMasterSelection: setMasterSelection,
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</MasterDetailContext.Provider>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { MasterDetailProvider, MasterDetailContext };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type MasterSelecion = any | any[] | undefined;
|
|
4
|
+
|
|
5
|
+
export interface MasterDetailContextStateProps {
|
|
6
|
+
masterSelection?: MasterSelecion;
|
|
7
|
+
// splitPosition?: SplitPosition;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface MasterDetailProviderProps {
|
|
11
|
+
// masterSelection: MasterSelecion;
|
|
12
|
+
// setMasterSelection: (newMasterSelecion: MasterSelecion) => void;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface MasterDetailContextProps extends MasterDetailContextStateProps {
|
|
17
|
+
onChangeMasterSelection: (newMasterSelection: MasterSelecion) => void;
|
|
18
|
+
// onChangeSplitPosition: (newMasterSelection: MasterSelecion) => void;
|
|
19
|
+
}
|