@m4l/layouts 0.1.13 → 0.1.15
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/contexts/AuthContext/index.59755369.js +130 -0
- package/contexts/AuthContext/index.d.ts +5 -0
- package/contexts/AuthContext/types.d.ts +54 -0
- package/contexts/index.d.ts +1 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/useAuth/index.ae68bf71.js +11 -0
- package/hooks/useAuth/index.d.ts +2 -0
- package/hooks/useMasterDetail/{index.7d7b413d.js → index.8e9e900b.js} +1 -1
- package/index.d.ts +1 -0
- package/index.js +20 -15
- package/layouts/MasterDetailLayout/{index.932fdce8.js → index.71de0dc7.js} +19 -19
- package/layouts/NoAuthModuleLayout/{index.798fbe31.js → index.5d1098ef.js} +6 -8
- package/package.json +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createContext as T, useReducer as y, useEffect as d } from "react";
|
|
2
|
+
import { useHostTools as E, useNetwork as S, useEnvironment as v, useLocalStorageWithListener as N, EmitEvents as O, getLocalStorage as w, setLocalStorage as r } from "@m4l/core";
|
|
3
|
+
import { jsx as D } from "react/jsx-runtime";
|
|
4
|
+
var n = /* @__PURE__ */ ((e) => (e.Initial = "INITIALIZE", e.Login = "LOGIN", e.Logout = "LOGOUT", e))(n || {});
|
|
5
|
+
const _ = {
|
|
6
|
+
isAuthenticated: !1,
|
|
7
|
+
isInitialized: !1,
|
|
8
|
+
user: null
|
|
9
|
+
}, P = (e, t) => {
|
|
10
|
+
switch (t.type) {
|
|
11
|
+
case "INITIALIZE":
|
|
12
|
+
return {
|
|
13
|
+
isAuthenticated: t.payload.isAuthenticated,
|
|
14
|
+
isInitialized: !0,
|
|
15
|
+
user: t.payload.user
|
|
16
|
+
};
|
|
17
|
+
case "LOGIN":
|
|
18
|
+
return {
|
|
19
|
+
...e,
|
|
20
|
+
isAuthenticated: !0,
|
|
21
|
+
user: t.payload.user
|
|
22
|
+
};
|
|
23
|
+
case "LOGOUT":
|
|
24
|
+
return {
|
|
25
|
+
...e,
|
|
26
|
+
isAuthenticated: !1,
|
|
27
|
+
user: null
|
|
28
|
+
};
|
|
29
|
+
default:
|
|
30
|
+
return e;
|
|
31
|
+
}
|
|
32
|
+
}, x = T(null);
|
|
33
|
+
function z(e) {
|
|
34
|
+
e({
|
|
35
|
+
type: n.Initial,
|
|
36
|
+
payload: {
|
|
37
|
+
isAuthenticated: !1,
|
|
38
|
+
user: null
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function R(e) {
|
|
43
|
+
const {
|
|
44
|
+
children: t
|
|
45
|
+
} = e, [h, s] = y(P, _), {
|
|
46
|
+
events_add_listener: I
|
|
47
|
+
} = E(), {
|
|
48
|
+
networkOperation: u
|
|
49
|
+
} = S(), {
|
|
50
|
+
domain_token: m
|
|
51
|
+
} = v(), [f, l] = N(
|
|
52
|
+
"vSession",
|
|
53
|
+
new Date().getTime() + ""
|
|
54
|
+
);
|
|
55
|
+
d(() => {
|
|
56
|
+
(async () => {
|
|
57
|
+
u({
|
|
58
|
+
method: "GET",
|
|
59
|
+
endPoint: "auth/login",
|
|
60
|
+
parms: {
|
|
61
|
+
user_data: !0
|
|
62
|
+
},
|
|
63
|
+
checkUnAuthorized: !1
|
|
64
|
+
}).then((a) => {
|
|
65
|
+
s({
|
|
66
|
+
type: n.Initial,
|
|
67
|
+
payload: {
|
|
68
|
+
isAuthenticated: !0,
|
|
69
|
+
user: a.user
|
|
70
|
+
}
|
|
71
|
+
}), w("userData", {
|
|
72
|
+
email: a.user.email,
|
|
73
|
+
remember: !0
|
|
74
|
+
})?.email !== a.user.email && r("userData", {
|
|
75
|
+
email: a.user.email
|
|
76
|
+
}, !0);
|
|
77
|
+
}).catch(() => {
|
|
78
|
+
z(s);
|
|
79
|
+
});
|
|
80
|
+
})();
|
|
81
|
+
}, [f]);
|
|
82
|
+
const g = async (i, a, o) => {
|
|
83
|
+
await u({
|
|
84
|
+
endPoint: "auth/login",
|
|
85
|
+
method: "POST",
|
|
86
|
+
data: {
|
|
87
|
+
email: i,
|
|
88
|
+
password: a,
|
|
89
|
+
domain_token: m
|
|
90
|
+
}
|
|
91
|
+
}).then((A) => {
|
|
92
|
+
const L = A.data;
|
|
93
|
+
o ? r("userData", {
|
|
94
|
+
email: i,
|
|
95
|
+
remember: o
|
|
96
|
+
}) : r("userData", {
|
|
97
|
+
email: "",
|
|
98
|
+
remember: o
|
|
99
|
+
}), s({
|
|
100
|
+
type: n.Login,
|
|
101
|
+
payload: {
|
|
102
|
+
user: L
|
|
103
|
+
}
|
|
104
|
+
}), l(new Date().getTime() + "");
|
|
105
|
+
});
|
|
106
|
+
}, c = async (i) => {
|
|
107
|
+
i && await u({
|
|
108
|
+
endPoint: "auth/logout",
|
|
109
|
+
method: "POST"
|
|
110
|
+
}), s({
|
|
111
|
+
type: n.Logout
|
|
112
|
+
}), l(new Date().getTime() + "");
|
|
113
|
+
}, p = () => {
|
|
114
|
+
c(!1);
|
|
115
|
+
};
|
|
116
|
+
return d(() => {
|
|
117
|
+
I(O.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, p);
|
|
118
|
+
}, []), /* @__PURE__ */ D(x.Provider, {
|
|
119
|
+
value: {
|
|
120
|
+
...h,
|
|
121
|
+
login: g,
|
|
122
|
+
logout: c
|
|
123
|
+
},
|
|
124
|
+
children: t
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
x as A,
|
|
129
|
+
R as a
|
|
130
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { AuthProviderProps, SessionContextType } from './types';
|
|
3
|
+
declare const AuthContext: import("react").Context<SessionContextType | null>;
|
|
4
|
+
declare function AuthProvider(props: AuthProviderProps): JSX.Element;
|
|
5
|
+
export { AuthContext, AuthProvider };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Maybe } from '@m4l/core';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export declare enum EnumTypes {
|
|
4
|
+
Initial = "INITIALIZE",
|
|
5
|
+
Login = "LOGIN",
|
|
6
|
+
Logout = "LOGOUT"
|
|
7
|
+
}
|
|
8
|
+
export declare type AuthProviderProps = {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare type ActionMap<M extends {
|
|
12
|
+
[index: string]: any;
|
|
13
|
+
}> = {
|
|
14
|
+
[Key in keyof M]: M[Key] extends undefined ? {
|
|
15
|
+
type: Key;
|
|
16
|
+
} : {
|
|
17
|
+
type: Key;
|
|
18
|
+
payload: M[Key];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare type SessionAuthPayload = {
|
|
22
|
+
[EnumTypes.Initial]: {
|
|
23
|
+
isAuthenticated: boolean;
|
|
24
|
+
user: AuthUser;
|
|
25
|
+
};
|
|
26
|
+
[EnumTypes.Login]: {
|
|
27
|
+
user: AuthUser;
|
|
28
|
+
};
|
|
29
|
+
[EnumTypes.Logout]: undefined;
|
|
30
|
+
};
|
|
31
|
+
export declare type SessionActions = ActionMap<SessionAuthPayload>[keyof ActionMap<SessionAuthPayload>];
|
|
32
|
+
export declare type AuthStoreState = {
|
|
33
|
+
user: User;
|
|
34
|
+
remember?: boolean;
|
|
35
|
+
};
|
|
36
|
+
export interface User {
|
|
37
|
+
email: string;
|
|
38
|
+
id: number;
|
|
39
|
+
first_name: string;
|
|
40
|
+
last_name: string;
|
|
41
|
+
account_id: number;
|
|
42
|
+
domain_country_id: number;
|
|
43
|
+
avatar_url?: Maybe<string>;
|
|
44
|
+
}
|
|
45
|
+
export declare type AuthUser = Maybe<User>;
|
|
46
|
+
export declare type AuthState = {
|
|
47
|
+
isAuthenticated: boolean;
|
|
48
|
+
isInitialized: boolean;
|
|
49
|
+
user: AuthUser;
|
|
50
|
+
};
|
|
51
|
+
export interface SessionContextType extends AuthState {
|
|
52
|
+
login: (email: string, password: string, remember: boolean) => object | undefined;
|
|
53
|
+
logout: (isAuthenticated: boolean) => Promise<void>;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AuthContext';
|
package/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useContext as o } from "react";
|
|
2
|
+
import { A as e } from "../../contexts/AuthContext/index.59755369.js";
|
|
3
|
+
const n = () => {
|
|
4
|
+
const t = o(e);
|
|
5
|
+
if (!t)
|
|
6
|
+
throw new Error("Auth context must be use inside AuthProvider");
|
|
7
|
+
return t;
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
n as u
|
|
11
|
+
};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as p, a as d } from "./contexts/AuthContext/index.59755369.js";
|
|
2
|
+
import { a as y, d as n, g as M } from "./layouts/ModuleLayout/index.842072c5.js";
|
|
2
3
|
import "@m4l/components";
|
|
3
4
|
import "react";
|
|
4
5
|
import "@m4l/core";
|
|
5
|
-
import { a as
|
|
6
|
+
import { a as D, d as x, g as L } from "./layouts/MasterDetailLayout/index.71de0dc7.js";
|
|
6
7
|
import "@m4l/graphics";
|
|
7
8
|
import "@mui/material";
|
|
8
9
|
import "react/jsx-runtime";
|
|
9
|
-
import { N as
|
|
10
|
-
import { u as N } from "./hooks/useMasterDetail/index.
|
|
11
|
-
import { u as
|
|
10
|
+
import { N as c, d as g, g as h } from "./layouts/NoAuthModuleLayout/index.5d1098ef.js";
|
|
11
|
+
import { u as N } from "./hooks/useMasterDetail/index.8e9e900b.js";
|
|
12
|
+
import { u as P } from "./hooks/useAuth/index.ae68bf71.js";
|
|
13
|
+
import { u as j } from "./hooks/useModule/index.096d7d13.js";
|
|
12
14
|
import "@mui/material/styles";
|
|
13
15
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
p as AuthContext,
|
|
17
|
+
d as AuthProvider,
|
|
18
|
+
D as MasterDetailLayout,
|
|
19
|
+
y as ModuleLayout,
|
|
20
|
+
c as NoAuthModuleLayout,
|
|
21
|
+
x as defaultMasterDetailDictionary,
|
|
22
|
+
n as defaultModuleLayoutDictionary,
|
|
23
|
+
g as defaultNoAuthModuleLayoutDictionary,
|
|
24
|
+
L as getMasterDetailLayoutComponentsDictionary,
|
|
25
|
+
M as getModuleLayoutComponentsDictionary,
|
|
26
|
+
h as getNoAuthModuleLayoutComponentsDictionary,
|
|
27
|
+
P as useAuth,
|
|
23
28
|
N as useMasterDetail,
|
|
24
|
-
|
|
29
|
+
j as useModule
|
|
25
30
|
};
|
|
@@ -5,7 +5,7 @@ import { g as V, a as j } from "../ModuleLayout/index.842072c5.js";
|
|
|
5
5
|
import { jsx as r } from "react/jsx-runtime";
|
|
6
6
|
import { useResponsiveDesktop as E } from "@m4l/graphics";
|
|
7
7
|
import { Button as H } from "@mui/material";
|
|
8
|
-
import { u as T } from "../../hooks/useMasterDetail/index.
|
|
8
|
+
import { u as T } from "../../hooks/useMasterDetail/index.8e9e900b.js";
|
|
9
9
|
function W() {
|
|
10
10
|
return ["master_detail_layout"].concat(V());
|
|
11
11
|
}
|
|
@@ -54,24 +54,24 @@ function nt(i) {
|
|
|
54
54
|
const {
|
|
55
55
|
moduleId: o,
|
|
56
56
|
moduleNameField: e,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
masterComponent: t,
|
|
58
|
+
detailComponent: n,
|
|
59
|
+
moduleActions: y,
|
|
60
|
+
urlIcon: M,
|
|
61
61
|
currentLang: S,
|
|
62
|
-
componentsDictionary:
|
|
62
|
+
componentsDictionary: f,
|
|
63
63
|
breadcrumbLinks: b,
|
|
64
64
|
privileges: k,
|
|
65
65
|
skeletonFlags: A
|
|
66
66
|
} = i, {
|
|
67
67
|
host_static_assets: c,
|
|
68
68
|
environment_assets: a
|
|
69
|
-
} = R(), [w, L] = v("vertical"), d = E(),
|
|
70
|
-
const s = [...
|
|
69
|
+
} = R(), [w, L] = v("vertical"), d = E(), _ = z(null), u = (m) => {
|
|
70
|
+
const s = [...g];
|
|
71
71
|
for (let l = 0; l < s.length; l++)
|
|
72
72
|
s[l].disabled = !1, s[l].tag === m && (s[l].disabled = !0);
|
|
73
73
|
$(s), L(m);
|
|
74
|
-
},
|
|
74
|
+
}, g = [{
|
|
75
75
|
urlIcon: `${c}/${a}/frontend/components/masterdetaillayout/assets/icons/split_vertical.svg`,
|
|
76
76
|
onClick: () => u("vertical"),
|
|
77
77
|
disabled: !0,
|
|
@@ -95,30 +95,30 @@ function nt(i) {
|
|
|
95
95
|
dictionaryField: "master_detail_layout.no_split",
|
|
96
96
|
tag: "none",
|
|
97
97
|
className: "splitactions"
|
|
98
|
-
}],
|
|
99
|
-
|
|
98
|
+
}], C = N(() => {
|
|
99
|
+
_.current?.openModal({
|
|
100
100
|
title: "master_detail_layout.view_detail",
|
|
101
101
|
initialWidth: 500,
|
|
102
102
|
initialHeigth: 680,
|
|
103
|
-
contentComponent:
|
|
103
|
+
contentComponent: n,
|
|
104
104
|
actions: void 0
|
|
105
105
|
});
|
|
106
|
-
}, [
|
|
106
|
+
}, [n]), h = p(() => ({
|
|
107
107
|
urlIcon: `${c}/${a}/frontend/components/masterdetaillayout/assets/icons/view_detail.svg`,
|
|
108
|
-
onClick:
|
|
108
|
+
onClick: C,
|
|
109
109
|
disabled: !1,
|
|
110
110
|
visibility: "allways",
|
|
111
111
|
dictionaryField: "master_detail_layout.view_detail",
|
|
112
112
|
tag: "none",
|
|
113
113
|
className: "",
|
|
114
114
|
component: K
|
|
115
|
-
}), [a,
|
|
115
|
+
}), [a, C]), [D, $] = v(g), F = p(() => O(D, y, h, d), [D, y, d, h]), I = p(() => f.concat(W()), [f]);
|
|
116
116
|
return /* @__PURE__ */ r(J, {
|
|
117
117
|
children: /* @__PURE__ */ r(j, {
|
|
118
|
-
ref:
|
|
118
|
+
ref: _,
|
|
119
119
|
moduleId: o,
|
|
120
120
|
moduleNameField: e,
|
|
121
|
-
urlIcon:
|
|
121
|
+
urlIcon: M,
|
|
122
122
|
moduleActions: F,
|
|
123
123
|
privileges: k,
|
|
124
124
|
skeletonFlags: A,
|
|
@@ -127,8 +127,8 @@ function nt(i) {
|
|
|
127
127
|
breadcrumbLinks: b,
|
|
128
128
|
children: /* @__PURE__ */ r(B, {
|
|
129
129
|
splitPosition: d ? w : "none",
|
|
130
|
-
firstPart:
|
|
131
|
-
secondPart:
|
|
130
|
+
firstPart: t,
|
|
131
|
+
secondPart: n
|
|
132
132
|
})
|
|
133
133
|
})
|
|
134
134
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useResponsive as h, useLocales as N } from "@m4l/graphics";
|
|
2
2
|
import { Image as p, Typography as u, LanguagePopover as W, HelmetPage as k } from "@m4l/components";
|
|
3
|
-
import { useModuleDictionary as m, useBase as g, useEnvironment as
|
|
3
|
+
import { useModuleDictionary as m, useBase as g, useEnvironment as S, BaseProvider as b, FlagsProvider as I, ModuleDictionaryProvider as F, ModuleSkeletonProvider as A } from "@m4l/core";
|
|
4
4
|
import { styled as t } from "@mui/material/styles";
|
|
5
5
|
import { jsxs as i, jsx as e } from "react/jsx-runtime";
|
|
6
6
|
const C = t("div")(({
|
|
@@ -160,23 +160,21 @@ const C = t("div")(({
|
|
|
160
160
|
} = o, {
|
|
161
161
|
host_static_assets: s,
|
|
162
162
|
environment_assets: d
|
|
163
|
-
} =
|
|
164
|
-
|
|
165
|
-
} = N(), w = L || `${s}/${d}/frontend/commons/assets/icons/logotipo_m4l.svg`, M = x || `${s}/${d}/frontend/commons/assets/icons/isotipo_m4l.svg`, U = v || `${s}/${d}/frontend/domain/host/commons/assets/img/illustration_noauth.png`, c = f;
|
|
166
|
-
return c.findIndex((D) => D === "dictionary_loaded") < 0 && c.push("dictionary_loaded"), /* @__PURE__ */ e(I, {
|
|
163
|
+
} = S(), _ = N().currentLocale?.localeString, w = L || `${s}/${d}/frontend/commons/assets/icons/logotipo_m4l.svg`, M = x || `${s}/${d}/frontend/commons/assets/icons/isotipo_m4l.svg`, U = v || `${s}/${d}/frontend/domain/host/commons/assets/img/illustration_noauth.png`, c = f;
|
|
164
|
+
return c.findIndex((D) => D === "dictionary_loaded") < 0 && c.push("dictionary_loaded"), /* @__PURE__ */ e(b, {
|
|
167
165
|
value: {
|
|
168
166
|
subtitle: y,
|
|
169
167
|
companyLogoSmallUrl: M,
|
|
170
168
|
companyLogoNormalUrl: w,
|
|
171
169
|
moduleIlustrationUrl: U
|
|
172
170
|
},
|
|
173
|
-
children: /* @__PURE__ */ e(
|
|
174
|
-
children: /* @__PURE__ */ e(
|
|
171
|
+
children: /* @__PURE__ */ e(I, {
|
|
172
|
+
children: /* @__PURE__ */ e(F, {
|
|
175
173
|
isAuth: !1,
|
|
176
174
|
moduleId: n,
|
|
177
175
|
moduleNameField: l,
|
|
178
176
|
componentsDictionary: a,
|
|
179
|
-
currentLang: _
|
|
177
|
+
currentLang: _,
|
|
180
178
|
children: /* @__PURE__ */ e(A, {
|
|
181
179
|
flags: c,
|
|
182
180
|
children: /* @__PURE__ */ e(z, {
|