@chimera-pe/react-saas 0.2.0 → 0.3.0
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/react-saas.js +248 -239
- package/dist/react-saas.umd.cjs +1 -1
- package/package.json +24 -28
package/dist/react-saas.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { jsx as a, jsxs as d, Fragment as
|
|
2
|
-
import { Box as
|
|
3
|
-
import { useTranslate as
|
|
1
|
+
import { jsx as a, jsxs as d, Fragment as te } from "react/jsx-runtime";
|
|
2
|
+
import { Box as S, CircularProgress as P, Alert as B, AlertTitle as se, Snackbar as ce, useMediaQuery as le, CssBaseline as de, Container as ue, Grid as b, Typography as z, Card as pe, CardHeader as me, CardContent as ge, AppBar as fe, Toolbar as he, Link as ye, InputAdornment as N, Button as xe } from "@mui/material";
|
|
3
|
+
import { useTranslate as R, I18n as ke } from "react-polyglot";
|
|
4
4
|
import t from "prop-types";
|
|
5
|
-
import { useDispatch as
|
|
6
|
-
import { createSlice as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { useState as
|
|
10
|
-
import { enGB as
|
|
11
|
-
import { LocalizationProvider as
|
|
12
|
-
import { AdapterDateFns as
|
|
13
|
-
import
|
|
14
|
-
import { createTheme as
|
|
15
|
-
import { grey as
|
|
16
|
-
import { useLocation as
|
|
17
|
-
import { Email as
|
|
18
|
-
import { Form as
|
|
19
|
-
import { TextField as
|
|
20
|
-
import
|
|
21
|
-
const
|
|
5
|
+
import { useDispatch as f, useSelector as u, Provider as be } from "react-redux";
|
|
6
|
+
import { createSlice as v, createAsyncThunk as D, configureStore as Te } from "@reduxjs/toolkit";
|
|
7
|
+
import q from "axios";
|
|
8
|
+
import { jwtDecode as _ } from "jwt-decode";
|
|
9
|
+
import { useState as Se, useEffect as T, useMemo as we, useCallback as Ce } from "react";
|
|
10
|
+
import { enGB as Ie, es as Re } from "date-fns/locale";
|
|
11
|
+
import { LocalizationProvider as ve } from "@mui/x-date-pickers";
|
|
12
|
+
import { AdapterDateFns as je } from "@mui/x-date-pickers/AdapterDateFns";
|
|
13
|
+
import Ae from "navigator-languages";
|
|
14
|
+
import { createTheme as ze, ThemeProvider as Le } from "@mui/material/styles";
|
|
15
|
+
import { grey as E } from "@mui/material/colors";
|
|
16
|
+
import { useLocation as M, Navigate as G, BrowserRouter as qe, Routes as De, Route as O } from "react-router-dom";
|
|
17
|
+
import { Email as Ne, Lock as _e } from "@mui/icons-material";
|
|
18
|
+
import { Form as Ee } from "react-final-form";
|
|
19
|
+
import { TextField as U } from "mui-rff";
|
|
20
|
+
import $ from "lodash/memoize";
|
|
21
|
+
const Oe = () => /* @__PURE__ */ a(S, { sx: {
|
|
22
22
|
display: "flex",
|
|
23
23
|
flexDirection: "column",
|
|
24
24
|
flexGrow: 1,
|
|
25
25
|
justifyContent: "center",
|
|
26
26
|
alignItems: "center"
|
|
27
|
-
}, children: /* @__PURE__ */ a(
|
|
28
|
-
const i =
|
|
29
|
-
return /* @__PURE__ */ a(
|
|
27
|
+
}, children: /* @__PURE__ */ a(P, {}) }), H = ({ titulo: o, texto: e, align: n = "center", severity: r = "error" }) => {
|
|
28
|
+
const i = R();
|
|
29
|
+
return /* @__PURE__ */ a(S, { sx: {
|
|
30
30
|
display: "flex",
|
|
31
31
|
flexDirection: "column",
|
|
32
32
|
flexGrow: 1,
|
|
33
33
|
justifyContent: "center",
|
|
34
|
-
alignItems:
|
|
35
|
-
}, children: /* @__PURE__ */ d(
|
|
36
|
-
/* @__PURE__ */ a(
|
|
34
|
+
alignItems: n
|
|
35
|
+
}, children: /* @__PURE__ */ d(B, { severity: r, children: [
|
|
36
|
+
/* @__PURE__ */ a(se, { children: i(o) }),
|
|
37
37
|
e && i(e)
|
|
38
38
|
] }) });
|
|
39
39
|
};
|
|
40
|
-
|
|
40
|
+
H.propTypes = {
|
|
41
41
|
titulo: t.string.isRequired,
|
|
42
42
|
texto: t.string,
|
|
43
43
|
align: t.string,
|
|
44
44
|
severity: t.string
|
|
45
45
|
};
|
|
46
|
-
const
|
|
46
|
+
const K = v({
|
|
47
47
|
name: "ui",
|
|
48
48
|
initialState: {
|
|
49
49
|
tema: "light",
|
|
@@ -58,8 +58,8 @@ const B = C({
|
|
|
58
58
|
o.idioma = e.payload;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
}), { cambiarTema:
|
|
62
|
-
login: (e,
|
|
61
|
+
}), { cambiarTema: Ue, cambiarIdioma: Fe } = K.actions, Pe = K.reducer, Be = "https://saas.chimera.com.pe/backend", Me = "https://saas.chimera.com.pe/oauth", y = "saas-token", x = "saas-token-expiration", k = "saas-refresh-token", V = (o = Me) => ({
|
|
62
|
+
login: (e, n) => q({
|
|
63
63
|
url: `${o}/oauth/token`,
|
|
64
64
|
headers: {
|
|
65
65
|
"content-type": "application/x-www-form-urlencoded",
|
|
@@ -67,12 +67,12 @@ const B = C({
|
|
|
67
67
|
},
|
|
68
68
|
method: "post",
|
|
69
69
|
data: {
|
|
70
|
-
username:
|
|
71
|
-
password:
|
|
70
|
+
username: n.correo,
|
|
71
|
+
password: n.password,
|
|
72
72
|
grant_type: "password"
|
|
73
73
|
}
|
|
74
74
|
}),
|
|
75
|
-
refreshToken: (e,
|
|
75
|
+
refreshToken: (e, n) => q({
|
|
76
76
|
url: `${o}/oauth/token`,
|
|
77
77
|
headers: {
|
|
78
78
|
"content-type": "application/x-www-form-urlencoded",
|
|
@@ -80,11 +80,11 @@ const B = C({
|
|
|
80
80
|
},
|
|
81
81
|
method: "post",
|
|
82
82
|
data: {
|
|
83
|
-
refresh_token:
|
|
83
|
+
refresh_token: n,
|
|
84
84
|
grant_type: "refresh_token"
|
|
85
85
|
}
|
|
86
86
|
})
|
|
87
|
-
}),
|
|
87
|
+
}), Z = v({
|
|
88
88
|
name: "login",
|
|
89
89
|
initialState: {
|
|
90
90
|
cargando: !1,
|
|
@@ -97,30 +97,34 @@ const B = C({
|
|
|
97
97
|
error: null
|
|
98
98
|
},
|
|
99
99
|
reducers: {
|
|
100
|
+
login: (o, e) => {
|
|
101
|
+
const n = e.payload.token, r = _(n), i = /* @__PURE__ */ new Date();
|
|
102
|
+
i.setSeconds(i.getSeconds() + e.payload.expiracion), o.cargando = !1, o.autenticado = !0, o.token = n, o.refreshToken = e.payload.refreshToken, o.expiracion = i.getTime(), o.usuario = r.name, o.perfiles = r.authorities;
|
|
103
|
+
},
|
|
100
104
|
logout: (o) => {
|
|
101
|
-
o.cargando = !1, o.autenticado = !1, o.token = null, o.refreshToken = null, o.expiracion = null, o.usuario = null, o.perfiles = [], o.error = null, sessionStorage.removeItem(
|
|
105
|
+
o.cargando = !1, o.autenticado = !1, o.token = null, o.refreshToken = null, o.expiracion = null, o.usuario = null, o.perfiles = [], o.error = null, sessionStorage.removeItem(y), sessionStorage.removeItem(k), sessionStorage.removeItem(x);
|
|
102
106
|
}
|
|
103
107
|
},
|
|
104
108
|
extraReducers(o) {
|
|
105
|
-
o.addCase(
|
|
109
|
+
o.addCase(w.pending, (e) => {
|
|
106
110
|
e.cargando = !0, e.error = null;
|
|
107
|
-
}).addCase(
|
|
108
|
-
const
|
|
109
|
-
c.setSeconds(c.getSeconds() +
|
|
110
|
-
}).addCase(
|
|
111
|
-
var
|
|
112
|
-
console.log(
|
|
113
|
-
}).addCase(
|
|
111
|
+
}).addCase(w.fulfilled, (e, n) => {
|
|
112
|
+
const r = n.payload.access_token, i = _(r), c = /* @__PURE__ */ new Date();
|
|
113
|
+
c.setSeconds(c.getSeconds() + n.payload.expires_in), e.cargando = !1, e.autenticado = !0, e.token = r, e.refreshToken = n.payload.refresh_token, e.expiracion = c.getTime(), e.usuario = i.name, e.perfiles = i.authorities, sessionStorage.setItem(y, r), sessionStorage.setItem(k, n.payload.refresh_token), sessionStorage.setItem(x, c.getTime());
|
|
114
|
+
}).addCase(w.rejected, (e, n) => {
|
|
115
|
+
var r;
|
|
116
|
+
console.log(n), e.cargando = !1, e.autenticado = !1, e.token = null, e.refreshToken = null, e.expiracion = null, e.usuario = null, e.perfiles = [], e.error = (r = n.error) == null ? void 0 : r.message, sessionStorage.removeItem(y), sessionStorage.removeItem(k), sessionStorage.removeItem(x);
|
|
117
|
+
}).addCase(C.pending, (e) => {
|
|
114
118
|
e.cargando = !0;
|
|
115
|
-
}).addCase(
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
}).addCase(
|
|
119
|
-
var
|
|
120
|
-
e.cargando = !1, e.autenticado = !1, e.token = null, e.refreshToken = null, e.expiracion = null, e.usuario = null, e.perfiles = [], e.error = (
|
|
119
|
+
}).addCase(C.fulfilled, (e, n) => {
|
|
120
|
+
const r = /* @__PURE__ */ new Date();
|
|
121
|
+
r.setSeconds(r.getSeconds() + n.payload.expires_in), e.token = n.payload.access_token, e.refreshToken = n.payload.refresh_token, e.expiracion = r.getTime(), sessionStorage.setItem(y, n.payload.access_token), sessionStorage.setItem(k, n.payload.refresh_token), sessionStorage.setItem(x, r.getTime());
|
|
122
|
+
}).addCase(C.rejected, (e, n) => {
|
|
123
|
+
var r;
|
|
124
|
+
e.cargando = !1, e.autenticado = !1, e.token = null, e.refreshToken = null, e.expiracion = null, e.usuario = null, e.perfiles = [], e.error = (r = n.error) == null ? void 0 : r.message, sessionStorage.removeItem(y), sessionStorage.removeItem(k), sessionStorage.removeItem(x);
|
|
121
125
|
});
|
|
122
126
|
}
|
|
123
|
-
}),
|
|
127
|
+
}), w = D("login/requestToken", async (o) => (await V(o.devURL).login(o.clientCredentials, o.data)).data), C = D("login/refreshToken", async (o, e, n) => (await V(o).refreshToken(e, n)).data), { login: Ge, logout: F } = Z.actions, jo = (o) => o.login.token, Ao = (o) => o.login.usuario, zo = (o) => o.login.perfiles, $e = Z.reducer, W = v({
|
|
124
128
|
name: "notificacion",
|
|
125
129
|
initialState: [],
|
|
126
130
|
reducers: {
|
|
@@ -131,73 +135,73 @@ const B = C({
|
|
|
131
135
|
o.pop();
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
|
-
}), { mostrarNotificacion:
|
|
138
|
+
}), { mostrarNotificacion: He, ocultarNotificacion: Ke } = W.actions, Ve = W.reducer, Ze = (o = Be, e) => q({
|
|
135
139
|
url: `${o}/identidad/`,
|
|
136
140
|
params: {
|
|
137
141
|
codigoAplicacion: e
|
|
138
142
|
}
|
|
139
|
-
}),
|
|
143
|
+
}), L = {
|
|
140
144
|
primary: "#1C6CCC",
|
|
141
145
|
secondary: "#17A7FF",
|
|
142
146
|
error: "#f44336",
|
|
143
147
|
warning: "#ff9800",
|
|
144
148
|
info: "#2196f3",
|
|
145
149
|
success: "#4caf50"
|
|
146
|
-
},
|
|
150
|
+
}, We = v({
|
|
147
151
|
name: "inicializar",
|
|
148
152
|
initialState: {
|
|
149
153
|
inicializando: !0,
|
|
150
154
|
inicializado: !1,
|
|
151
155
|
instancia: {
|
|
152
|
-
color:
|
|
156
|
+
color: L
|
|
153
157
|
},
|
|
154
158
|
error: null
|
|
155
159
|
},
|
|
156
160
|
extraReducers(o) {
|
|
157
|
-
o.addCase(
|
|
161
|
+
o.addCase(I.pending, (e) => {
|
|
158
162
|
e.inicializando = !0;
|
|
159
|
-
}).addCase(
|
|
163
|
+
}).addCase(I.fulfilled, (e, n) => {
|
|
160
164
|
e.inicializando = !1, e.inicializado = !0, e.instancia = {
|
|
161
|
-
...
|
|
162
|
-
abreviatura:
|
|
165
|
+
...n.payload,
|
|
166
|
+
abreviatura: n.payload.nombre.match(/\b([A-Z])/g).join(""),
|
|
163
167
|
color: {
|
|
164
|
-
...
|
|
165
|
-
...
|
|
168
|
+
...L,
|
|
169
|
+
...n.payload.color
|
|
166
170
|
}
|
|
167
171
|
}, e.error = null;
|
|
168
|
-
}).addCase(
|
|
172
|
+
}).addCase(I.rejected, (e, n) => {
|
|
169
173
|
e.inicializando = !1, e.inicializado = !1, e.instancia = {
|
|
170
|
-
color:
|
|
171
|
-
}, e.error =
|
|
174
|
+
color: L
|
|
175
|
+
}, e.error = n.payload;
|
|
172
176
|
});
|
|
173
177
|
}
|
|
174
|
-
}),
|
|
178
|
+
}), I = D("inicializar", async (o) => (await Ze(o.devURL, o.aplicacion)).data), Lo = (o) => o.aplicacion.instancia, Xe = We.reducer, Je = (o) => Te({
|
|
175
179
|
reducer: {
|
|
176
|
-
ui:
|
|
177
|
-
aplicacion:
|
|
178
|
-
login:
|
|
179
|
-
notificaciones:
|
|
180
|
+
ui: Pe,
|
|
181
|
+
aplicacion: Xe,
|
|
182
|
+
login: $e,
|
|
183
|
+
notificaciones: Ve,
|
|
180
184
|
...o
|
|
181
185
|
}
|
|
182
|
-
}),
|
|
183
|
-
const [o, e] =
|
|
184
|
-
|
|
186
|
+
}), Qe = () => {
|
|
187
|
+
const [o, e] = Se(!1), n = f(), r = R(), i = u((s) => s.notificaciones[0]);
|
|
188
|
+
T(() => {
|
|
185
189
|
e(!!i);
|
|
186
190
|
}, [i]);
|
|
187
191
|
const c = () => {
|
|
188
|
-
e(!1),
|
|
192
|
+
e(!1), n(Ke());
|
|
189
193
|
};
|
|
190
194
|
return /* @__PURE__ */ a(
|
|
191
|
-
|
|
195
|
+
ce,
|
|
192
196
|
{
|
|
193
197
|
open: o,
|
|
194
|
-
message: (i == null ? void 0 : i.mensaje) && i.tipo === "default" &&
|
|
198
|
+
message: (i == null ? void 0 : i.mensaje) && i.tipo === "default" && r(i.mensaje),
|
|
195
199
|
autoHideDuration: 5e3,
|
|
196
200
|
onClose: c,
|
|
197
|
-
children: (i == null ? void 0 : i.mensaje) && i.tipo !== "default" && /* @__PURE__ */ a(
|
|
201
|
+
children: (i == null ? void 0 : i.mensaje) && i.tipo !== "default" && /* @__PURE__ */ a(B, { severity: i.tipo, children: r(i.mensaje) })
|
|
198
202
|
}
|
|
199
203
|
);
|
|
200
|
-
},
|
|
204
|
+
}, Ye = {
|
|
201
205
|
inicializar: {
|
|
202
206
|
error: {
|
|
203
207
|
titulo: "Error iniciando aplicación",
|
|
@@ -216,99 +220,104 @@ const B = C({
|
|
|
216
220
|
error: "Usuario o contraseña incorrectos"
|
|
217
221
|
},
|
|
218
222
|
copy: "Todos los derechos reservados "
|
|
219
|
-
},
|
|
220
|
-
es:
|
|
221
|
-
},
|
|
222
|
-
const
|
|
223
|
-
return /* @__PURE__ */ a(
|
|
223
|
+
}, eo = {
|
|
224
|
+
es: Ye
|
|
225
|
+
}, oo = { en: Ie, es: Re }, X = ({ messages: o, children: e }) => {
|
|
226
|
+
const n = u((r) => r.ui.idioma);
|
|
227
|
+
return /* @__PURE__ */ a(ke, { locale: n, messages: o[n], children: /* @__PURE__ */ a(ve, { dateAdapter: je, adapterLocale: oo[n], children: e }) });
|
|
224
228
|
};
|
|
225
|
-
|
|
229
|
+
X.propTypes = {
|
|
226
230
|
messages: t.object,
|
|
227
231
|
children: t.element.isRequired
|
|
228
232
|
};
|
|
229
|
-
const
|
|
230
|
-
const o =
|
|
233
|
+
const no = () => {
|
|
234
|
+
const o = Ae();
|
|
231
235
|
if (!(o != null && o.length))
|
|
232
236
|
return;
|
|
233
237
|
const e = o[0];
|
|
234
238
|
return e.indexOf("-") ? e.substring(0, e.indexOf("-")) : e;
|
|
235
|
-
},
|
|
236
|
-
const
|
|
237
|
-
|
|
239
|
+
}, J = ({ messages: o, idiomaDefecto: e, children: n }) => {
|
|
240
|
+
const r = f(), i = no();
|
|
241
|
+
T(() => {
|
|
238
242
|
let s = Reflect.ownKeys(o)[0];
|
|
239
|
-
i && Object.hasOwn(o, i) ? s = i : e && Object.hasOwn(o, e) && (s = e),
|
|
240
|
-
}, [
|
|
243
|
+
i && Object.hasOwn(o, i) ? s = i : e && Object.hasOwn(o, e) && (s = e), r(Fe(s));
|
|
244
|
+
}, [r, o, e, i]);
|
|
241
245
|
const c = {};
|
|
242
246
|
return Object.keys(o).forEach((s) => {
|
|
243
247
|
c[s] = {
|
|
244
248
|
...o[s],
|
|
245
|
-
saas:
|
|
249
|
+
saas: eo[s]
|
|
246
250
|
};
|
|
247
|
-
}), /* @__PURE__ */ a(
|
|
251
|
+
}), /* @__PURE__ */ a(X, { messages: c, children: n });
|
|
248
252
|
};
|
|
249
|
-
|
|
253
|
+
J.propTypes = {
|
|
250
254
|
messages: t.object,
|
|
251
255
|
idiomaDefecto: t.string,
|
|
252
256
|
children: t.element.isRequired
|
|
253
257
|
};
|
|
254
|
-
const
|
|
255
|
-
const e =
|
|
256
|
-
|
|
257
|
-
e(
|
|
258
|
+
const Q = ({ children: o }) => {
|
|
259
|
+
const e = f(), { instancia: n } = u((s) => s.aplicacion), r = u((s) => s.ui.tema), i = le("(prefers-color-scheme: dark)");
|
|
260
|
+
T(() => {
|
|
261
|
+
e(Ue(i ? "dark" : "light"));
|
|
258
262
|
}, [e, i]);
|
|
259
|
-
const c =
|
|
263
|
+
const c = we(() => ze({
|
|
260
264
|
palette: {
|
|
261
|
-
mode:
|
|
265
|
+
mode: r,
|
|
262
266
|
primary: {
|
|
263
|
-
main:
|
|
267
|
+
main: n.color.primary
|
|
264
268
|
},
|
|
265
269
|
secondary: {
|
|
266
|
-
main:
|
|
270
|
+
main: n.color.secondary
|
|
267
271
|
},
|
|
268
272
|
error: {
|
|
269
|
-
main:
|
|
273
|
+
main: n.color.error
|
|
270
274
|
},
|
|
271
275
|
warning: {
|
|
272
|
-
main:
|
|
276
|
+
main: n.color.warning
|
|
273
277
|
},
|
|
274
278
|
info: {
|
|
275
|
-
main:
|
|
279
|
+
main: n.color.info
|
|
276
280
|
},
|
|
277
281
|
success: {
|
|
278
|
-
main:
|
|
282
|
+
main: n.color.success
|
|
279
283
|
},
|
|
280
|
-
...
|
|
284
|
+
...r === "light" && {
|
|
281
285
|
background: {
|
|
282
|
-
default:
|
|
283
|
-
paper:
|
|
286
|
+
default: E.A200,
|
|
287
|
+
paper: E[100]
|
|
284
288
|
}
|
|
285
289
|
}
|
|
286
290
|
},
|
|
287
291
|
shape: {
|
|
288
292
|
borderRadius: 6
|
|
289
293
|
}
|
|
290
|
-
}), [
|
|
291
|
-
return /* @__PURE__ */ d(
|
|
292
|
-
/* @__PURE__ */ a(
|
|
294
|
+
}), [r, n]);
|
|
295
|
+
return /* @__PURE__ */ d(Le, { theme: c, children: [
|
|
296
|
+
/* @__PURE__ */ a(de, {}),
|
|
293
297
|
o
|
|
294
298
|
] });
|
|
295
299
|
};
|
|
296
|
-
|
|
300
|
+
Q.propTypes = {
|
|
297
301
|
children: t.element.isRequired
|
|
298
302
|
};
|
|
299
|
-
const
|
|
300
|
-
const e =
|
|
301
|
-
return
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
303
|
+
const Y = (o) => {
|
|
304
|
+
const e = f(), n = u((i) => i.loginStatus), r = u((i) => i.aplicacion.instancia);
|
|
305
|
+
return T(() => {
|
|
306
|
+
if (n.autenticado)
|
|
307
|
+
n.expiracion && new Date(n.expiracion) < /* @__PURE__ */ new Date() && (n.refreshToken ? e(C(o, r.clientCredentials, n.refreshToken)) : e(F()));
|
|
308
|
+
else {
|
|
309
|
+
const i = sessionStorage.getItem(y), c = sessionStorage.getItem(x), s = sessionStorage.getItem(k);
|
|
310
|
+
i && c && (new Date(c) < /* @__PURE__ */ new Date() ? e(s ? s(o, r.clientCredentials, s) : F()) : e(Ge({ token: i, expiracion: c, refreshToken: s })));
|
|
311
|
+
}
|
|
312
|
+
}, [o, r.clientCredentials, n, e]), n.autenticado;
|
|
313
|
+
}, ro = () => {
|
|
314
|
+
const o = f();
|
|
315
|
+
return Ce((e, n = "default") => {
|
|
316
|
+
o(He({ mensaje: e, tipo: n }));
|
|
308
317
|
}, [o]);
|
|
309
|
-
},
|
|
310
|
-
const e =
|
|
311
|
-
e(
|
|
318
|
+
}, ee = ({ devURL: o }) => {
|
|
319
|
+
const e = f(), n = R(), r = ro(), { cargando: i, error: c } = u((l) => l.login), s = u((l) => l.aplicacion.instancia), h = (l) => {
|
|
320
|
+
e(w({
|
|
312
321
|
devURL: o,
|
|
313
322
|
clientCredentials: s.clientCredentials,
|
|
314
323
|
data: {
|
|
@@ -316,58 +325,58 @@ const W = (o) => {
|
|
|
316
325
|
password: l.password
|
|
317
326
|
}
|
|
318
327
|
}));
|
|
319
|
-
},
|
|
320
|
-
const
|
|
321
|
-
return l.correo || (
|
|
328
|
+
}, j = (l) => {
|
|
329
|
+
const A = { correo: void 0, password: void 0 };
|
|
330
|
+
return l.correo || (A.correo = n("saas.login.validacion.correo")), l.password || (A.password = n("saas.login.validacion.password")), A;
|
|
322
331
|
};
|
|
323
|
-
return
|
|
324
|
-
c &&
|
|
325
|
-
}, [
|
|
326
|
-
|
|
332
|
+
return T(() => {
|
|
333
|
+
c && r("saas.login.error", "error");
|
|
334
|
+
}, [r, c]), /* @__PURE__ */ a(
|
|
335
|
+
Ee,
|
|
327
336
|
{
|
|
328
337
|
onSubmit: h,
|
|
329
|
-
validate:
|
|
338
|
+
validate: j,
|
|
330
339
|
render: ({ handleSubmit: l }) => /* @__PURE__ */ d("form", { onSubmit: l, children: [
|
|
331
340
|
/* @__PURE__ */ a(
|
|
332
|
-
|
|
341
|
+
U,
|
|
333
342
|
{
|
|
334
343
|
id: "correo",
|
|
335
344
|
name: "correo",
|
|
336
|
-
label:
|
|
345
|
+
label: n("saas.login.correo"),
|
|
337
346
|
variant: "outlined",
|
|
338
347
|
autoComplete: "off",
|
|
339
348
|
disabled: i,
|
|
340
349
|
autoFocus: !0,
|
|
341
350
|
InputProps: {
|
|
342
|
-
startAdornment: /* @__PURE__ */ a(
|
|
351
|
+
startAdornment: /* @__PURE__ */ a(N, { position: "start", children: /* @__PURE__ */ a(Ne, { color: "primary" }) })
|
|
343
352
|
}
|
|
344
353
|
}
|
|
345
354
|
),
|
|
346
355
|
/* @__PURE__ */ a(
|
|
347
|
-
|
|
356
|
+
U,
|
|
348
357
|
{
|
|
349
358
|
id: "password",
|
|
350
359
|
name: "password",
|
|
351
360
|
type: "password",
|
|
352
|
-
label:
|
|
361
|
+
label: n("saas.login.password"),
|
|
353
362
|
variant: "outlined",
|
|
354
363
|
autoComplete: "current-password",
|
|
355
364
|
disabled: i,
|
|
356
365
|
InputProps: {
|
|
357
|
-
startAdornment: /* @__PURE__ */ a(
|
|
366
|
+
startAdornment: /* @__PURE__ */ a(N, { position: "start", children: /* @__PURE__ */ a(_e, { color: "primary" }) })
|
|
358
367
|
}
|
|
359
368
|
}
|
|
360
369
|
),
|
|
361
|
-
/* @__PURE__ */ d(
|
|
362
|
-
/* @__PURE__ */ a(
|
|
363
|
-
/* @__PURE__ */ a(
|
|
364
|
-
|
|
370
|
+
/* @__PURE__ */ d(b, { container: !0, children: [
|
|
371
|
+
/* @__PURE__ */ a(b, { item: !0, xs: 6 }),
|
|
372
|
+
/* @__PURE__ */ a(b, { item: !0, xs: 6, align: "right", children: /* @__PURE__ */ a(
|
|
373
|
+
xe,
|
|
365
374
|
{
|
|
366
375
|
variant: "contained",
|
|
367
376
|
color: "primary",
|
|
368
377
|
type: "submit",
|
|
369
378
|
disabled: i,
|
|
370
|
-
children: i ? /* @__PURE__ */ a(
|
|
379
|
+
children: i ? /* @__PURE__ */ a(P, { size: 24, thickness: 4 }) : n("saas.login.ingresar")
|
|
371
380
|
}
|
|
372
381
|
) })
|
|
373
382
|
] })
|
|
@@ -375,12 +384,12 @@ const W = (o) => {
|
|
|
375
384
|
}
|
|
376
385
|
);
|
|
377
386
|
};
|
|
378
|
-
|
|
387
|
+
ee.propTypes = {
|
|
379
388
|
devURL: t.string
|
|
380
389
|
};
|
|
381
|
-
const
|
|
382
|
-
const e = u((s) => s.aplicacion.instancia),
|
|
383
|
-
return !e.requiereLogin || i ? /* @__PURE__ */ a(
|
|
390
|
+
const oe = ({ devURL: o }) => {
|
|
391
|
+
const e = u((s) => s.aplicacion.instancia), n = R(), r = M(), i = Y(o), { from: c } = r.state || { from: { pathname: "/" } };
|
|
392
|
+
return !e.requiereLogin || i ? /* @__PURE__ */ a(G, { to: c }) : /* @__PURE__ */ d(S, { sx: {
|
|
384
393
|
position: "relative",
|
|
385
394
|
display: "flex",
|
|
386
395
|
flexDirection: "column",
|
|
@@ -402,118 +411,118 @@ const K = ({ devURL: o }) => {
|
|
|
402
411
|
filter: "grayscale(100%)"
|
|
403
412
|
}
|
|
404
413
|
}, children: [
|
|
405
|
-
/* @__PURE__ */ a(
|
|
414
|
+
/* @__PURE__ */ a(S, { sx: {
|
|
406
415
|
display: "flex",
|
|
407
416
|
justifyContent: "center",
|
|
408
417
|
alignItems: "center",
|
|
409
418
|
flexGrow: 1
|
|
410
|
-
}, children: /* @__PURE__ */ a(
|
|
411
|
-
/* @__PURE__ */ d(
|
|
419
|
+
}, children: /* @__PURE__ */ a(ue, { maxWidth: "md", children: /* @__PURE__ */ d(b, { container: !0, spacing: 3, children: [
|
|
420
|
+
/* @__PURE__ */ d(b, { item: !0, xs: 12, lg: 5, align: "center", children: [
|
|
412
421
|
/* @__PURE__ */ a("img", { src: e.logo, alt: e.nombre, style: { maxWidth: "100%" } }),
|
|
413
|
-
/* @__PURE__ */ a(
|
|
414
|
-
/* @__PURE__ */ a(
|
|
422
|
+
/* @__PURE__ */ a(z, { variant: "h3", align: "center", children: n("aplicacion.nombre", { smart_count: 1 }) }),
|
|
423
|
+
/* @__PURE__ */ a(z, { variant: "h5", align: "center", children: e.nombre })
|
|
415
424
|
] }),
|
|
416
|
-
/* @__PURE__ */ a(
|
|
425
|
+
/* @__PURE__ */ a(b, { item: !0, xs: 12, lg: 7, sx: {
|
|
417
426
|
display: "flex",
|
|
418
427
|
alignItems: "center",
|
|
419
428
|
justifyContent: "center",
|
|
420
429
|
zIndex: 5
|
|
421
|
-
}, children: /* @__PURE__ */ d(
|
|
422
|
-
/* @__PURE__ */ a(
|
|
423
|
-
/* @__PURE__ */ a(
|
|
430
|
+
}, children: /* @__PURE__ */ d(pe, { elevation: 5, children: [
|
|
431
|
+
/* @__PURE__ */ a(me, { title: n("saas.login.titulo"), titleTypographyProps: { align: "center" } }),
|
|
432
|
+
/* @__PURE__ */ a(ge, { sx: {
|
|
424
433
|
"& .MuiTextField-root": {
|
|
425
434
|
mb: 2
|
|
426
435
|
}
|
|
427
|
-
}, children: /* @__PURE__ */ a(
|
|
436
|
+
}, children: /* @__PURE__ */ a(ee, { devURL: o }) })
|
|
428
437
|
] }) })
|
|
429
438
|
] }) }) }),
|
|
430
|
-
/* @__PURE__ */ a(
|
|
431
|
-
|
|
432
|
-
/* @__PURE__ */ a(
|
|
439
|
+
/* @__PURE__ */ a(fe, { position: "static", color: "primary", children: /* @__PURE__ */ a(he, { sx: { justifyContent: "center" }, children: /* @__PURE__ */ d(z, { variant: "caption", children: [
|
|
440
|
+
n("saas.copy"),
|
|
441
|
+
/* @__PURE__ */ a(ye, { href: "//chimera.com.pe", color: "inherit", target: "_blank", rel: "noreferrer", children: "Chimera Software" })
|
|
433
442
|
] }) }) })
|
|
434
443
|
] });
|
|
435
444
|
};
|
|
436
|
-
|
|
445
|
+
oe.propTypes = {
|
|
437
446
|
devURL: t.string
|
|
438
447
|
};
|
|
439
|
-
const
|
|
440
|
-
const
|
|
441
|
-
return
|
|
448
|
+
const ne = ({ devURL: o, redirectTo: e, children: n }) => {
|
|
449
|
+
const r = M();
|
|
450
|
+
return Y(o) ? n : /* @__PURE__ */ a(G, { to: e, state: { from: r }, replace: !0 });
|
|
442
451
|
};
|
|
443
|
-
|
|
452
|
+
ne.propTypes = {
|
|
444
453
|
devURL: t.string,
|
|
445
454
|
redirectTo: t.string.isRequired,
|
|
446
455
|
children: t.element.isRequired
|
|
447
456
|
};
|
|
448
|
-
const
|
|
457
|
+
const re = ({
|
|
449
458
|
devURL: o,
|
|
450
459
|
requiereLogin: e,
|
|
451
|
-
basename:
|
|
452
|
-
children:
|
|
453
|
-
}) => /* @__PURE__ */ a(
|
|
454
|
-
/* @__PURE__ */ a(
|
|
460
|
+
basename: n,
|
|
461
|
+
children: r
|
|
462
|
+
}) => /* @__PURE__ */ a(qe, { basename: n, children: /* @__PURE__ */ d(De, { children: [
|
|
463
|
+
/* @__PURE__ */ a(O, { path: "/login", element: /* @__PURE__ */ a(oe, { devURL: o }) }),
|
|
455
464
|
/* @__PURE__ */ a(
|
|
456
|
-
|
|
465
|
+
O,
|
|
457
466
|
{
|
|
458
467
|
path: "/*",
|
|
459
|
-
element: e ? /* @__PURE__ */ a(
|
|
468
|
+
element: e ? /* @__PURE__ */ a(ne, { devURL: o, redirectTo: "/login", children: r }) : r
|
|
460
469
|
}
|
|
461
470
|
)
|
|
462
471
|
] }) });
|
|
463
|
-
|
|
472
|
+
re.propTypes = {
|
|
464
473
|
devURL: t.string,
|
|
465
474
|
requiereLogin: t.bool,
|
|
466
475
|
basename: t.string,
|
|
467
476
|
children: t.element.isRequired
|
|
468
477
|
};
|
|
469
|
-
const
|
|
470
|
-
const
|
|
471
|
-
return /* @__PURE__ */ a(
|
|
478
|
+
const ie = ({ devURL: o, basename: e, children: n }) => {
|
|
479
|
+
const r = u((i) => i.aplicacion);
|
|
480
|
+
return /* @__PURE__ */ a(S, { sx: {
|
|
472
481
|
display: "flex",
|
|
473
482
|
flexDirection: "column",
|
|
474
483
|
minHeight: "100vh",
|
|
475
484
|
justifyContent: "flex-start",
|
|
476
485
|
backgroundColor: "background.default"
|
|
477
|
-
}, children:
|
|
486
|
+
}, children: r.inicializando ? /* @__PURE__ */ a(Oe, {}) : r.error || !r.inicializado ? /* @__PURE__ */ a(H, { titulo: "saas.inicializar.error.titulo", texto: "saas.inicializar.error.mensaje" }) : /* @__PURE__ */ d(te, { children: [
|
|
478
487
|
/* @__PURE__ */ a(
|
|
479
|
-
|
|
488
|
+
re,
|
|
480
489
|
{
|
|
481
490
|
devURL: o,
|
|
482
|
-
requiereLogin:
|
|
491
|
+
requiereLogin: r.instancia.requiereLogin,
|
|
483
492
|
basename: e,
|
|
484
|
-
children:
|
|
493
|
+
children: n
|
|
485
494
|
}
|
|
486
495
|
),
|
|
487
|
-
/* @__PURE__ */ a(
|
|
496
|
+
/* @__PURE__ */ a(Qe, {})
|
|
488
497
|
] }) });
|
|
489
498
|
};
|
|
490
|
-
|
|
499
|
+
ie.propTypes = {
|
|
491
500
|
devURL: t.string,
|
|
492
501
|
basename: t.string,
|
|
493
502
|
children: t.element.isRequired
|
|
494
503
|
};
|
|
495
|
-
const
|
|
504
|
+
const ae = ({
|
|
496
505
|
aplicacion: o,
|
|
497
506
|
devSaasURL: e,
|
|
498
|
-
devAuthURL:
|
|
499
|
-
messages:
|
|
507
|
+
devAuthURL: n,
|
|
508
|
+
messages: r,
|
|
500
509
|
idiomaDefecto: i,
|
|
501
510
|
basename: c,
|
|
502
511
|
children: s
|
|
503
512
|
}) => {
|
|
504
|
-
const h =
|
|
505
|
-
return
|
|
506
|
-
h(
|
|
507
|
-
}, [h, o, e]), /* @__PURE__ */ a(
|
|
508
|
-
|
|
513
|
+
const h = f();
|
|
514
|
+
return T(() => {
|
|
515
|
+
h(I({ devURL: e, aplicacion: o }));
|
|
516
|
+
}, [h, o, e]), /* @__PURE__ */ a(J, { messages: r, idiomaDefecto: i, children: /* @__PURE__ */ a(Q, { children: /* @__PURE__ */ a(
|
|
517
|
+
ie,
|
|
509
518
|
{
|
|
510
|
-
devURL:
|
|
519
|
+
devURL: n,
|
|
511
520
|
basename: c,
|
|
512
521
|
children: s
|
|
513
522
|
}
|
|
514
523
|
) }) });
|
|
515
524
|
};
|
|
516
|
-
|
|
525
|
+
ae.propTypes = {
|
|
517
526
|
aplicacion: t.string.isRequired,
|
|
518
527
|
devSaasURL: t.string,
|
|
519
528
|
devAuthURL: t.string,
|
|
@@ -522,29 +531,29 @@ ee.propTypes = {
|
|
|
522
531
|
basename: t.string,
|
|
523
532
|
children: t.element.isRequired
|
|
524
533
|
};
|
|
525
|
-
const
|
|
534
|
+
const io = ({
|
|
526
535
|
customReducers: o,
|
|
527
536
|
aplicacion: e,
|
|
528
|
-
devSaasURL:
|
|
529
|
-
devAuthURL:
|
|
537
|
+
devSaasURL: n,
|
|
538
|
+
devAuthURL: r,
|
|
530
539
|
dev: i = !1,
|
|
531
540
|
idiomaDefecto: c,
|
|
532
541
|
messages: s,
|
|
533
542
|
basename: h,
|
|
534
|
-
children:
|
|
535
|
-
}) => /* @__PURE__ */ a(
|
|
536
|
-
|
|
543
|
+
children: j
|
|
544
|
+
}) => /* @__PURE__ */ a(be, { store: Je(o), children: /* @__PURE__ */ a(
|
|
545
|
+
ae,
|
|
537
546
|
{
|
|
538
547
|
aplicacion: e,
|
|
539
|
-
devSaasURL: i ?
|
|
540
|
-
devAuthURL: i ?
|
|
548
|
+
devSaasURL: i ? n : void 0,
|
|
549
|
+
devAuthURL: i ? r : void 0,
|
|
541
550
|
idiomaDefecto: c,
|
|
542
551
|
messages: s,
|
|
543
552
|
basename: h,
|
|
544
|
-
children:
|
|
553
|
+
children: j
|
|
545
554
|
}
|
|
546
555
|
) });
|
|
547
|
-
|
|
556
|
+
io.propTypes = {
|
|
548
557
|
customReducers: t.object,
|
|
549
558
|
aplicacion: t.string.isRequired,
|
|
550
559
|
devSaasURL: t.string,
|
|
@@ -555,46 +564,46 @@ eo.propTypes = {
|
|
|
555
564
|
basename: t.string,
|
|
556
565
|
children: t.element.isRequired
|
|
557
566
|
};
|
|
558
|
-
const
|
|
559
|
-
(c, s) => c || typeof s == "function" && s(e,
|
|
567
|
+
const ao = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, m = (o) => typeof o > "u" || o === null || o === "" || Array.isArray(o) && o.length === 0, p = (o, e, n, r) => typeof o == "function" ? o({ args: e, value: n, values: r }) : e ? { message: o, args: e } : o, g = (o) => $(o, (...e) => JSON.stringify(e)), qo = (...o) => (e, n, r) => (Array.isArray(o[0]) ? o[0] : o).reduce(
|
|
568
|
+
(c, s) => c || typeof s == "function" && s(e, n, r),
|
|
560
569
|
void 0
|
|
561
|
-
),
|
|
562
|
-
(e,
|
|
570
|
+
), Do = g((o = "validacion.obligatorio") => Object.assign(
|
|
571
|
+
(e, n) => m(e) ? p(o, void 0, e, n) : void 0,
|
|
563
572
|
{ isRequired: !0 }
|
|
564
|
-
)),
|
|
565
|
-
(e,
|
|
573
|
+
)), No = g((o = "validacion.obligatorio") => Object.assign(
|
|
574
|
+
(e, n) => m(e) || !e ? p(o, void 0, e, n) : void 0,
|
|
566
575
|
{ isRequired: !0 }
|
|
567
|
-
)),
|
|
568
|
-
(o, e = "validacion.longitud.minima") => (
|
|
569
|
-
),
|
|
570
|
-
(o, e = "validacion.longitud.maxima") => (
|
|
571
|
-
),
|
|
572
|
-
(o, e = "validacion.minimo") => (
|
|
573
|
-
),
|
|
574
|
-
(o, e = "validacion.maximo") => (
|
|
575
|
-
),
|
|
576
|
-
(o, e = "validacion.regex") => (
|
|
576
|
+
)), _o = g((o = "validacion.numero") => (e, n) => !m(e) && isNaN(e) ? p(o, void 0, e, n) : void 0), Eo = g(
|
|
577
|
+
(o, e = "validacion.longitud.minima") => (n, r) => !m(n) && n.length < o ? p(e, void 0, n, r) : void 0
|
|
578
|
+
), Oo = g(
|
|
579
|
+
(o, e = "validacion.longitud.maxima") => (n, r) => !m(n) && n.length > o ? p(e, void 0, n, r) : void 0
|
|
580
|
+
), Uo = g(
|
|
581
|
+
(o, e = "validacion.minimo") => (n, r) => !m(n) && parseFloat(n) < o ? p(e, void 0, n, r) : void 0
|
|
582
|
+
), Fo = g(
|
|
583
|
+
(o, e = "validacion.maximo") => (n, r) => !m(n) && parseFloat(n) > o ? p(e, void 0, n, r) : void 0
|
|
584
|
+
), to = $(
|
|
585
|
+
(o, e = "validacion.regex") => (n, r) => !m(n) && typeof n == "string" && !o.test(n) ? p(e, void 0, n, r) : void 0,
|
|
577
586
|
(o, e) => o.toString() + e
|
|
578
|
-
),
|
|
587
|
+
), Po = g((o = "validacion.correo") => to(ao, o)), Bo = g((o, e, n = "validacion.remote") => (r, i, c) => c.active && !m(r) && o(r, e).then((s) => s ? p(n, void 0, r, i) : void 0).catch((s) => p(s.message, void 0, r, i)));
|
|
579
588
|
export {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
589
|
+
Oe as Cargando,
|
|
590
|
+
H as Error,
|
|
591
|
+
io as SaasApp,
|
|
592
|
+
qo as composeValidators,
|
|
593
|
+
Po as email,
|
|
594
|
+
Lo as getInstancia,
|
|
595
|
+
zo as getPerfiles,
|
|
596
|
+
jo as getToken,
|
|
597
|
+
Ao as getUsuario,
|
|
598
|
+
F as logout,
|
|
599
|
+
Fo as max,
|
|
600
|
+
Oo as maxLength,
|
|
601
|
+
Uo as min,
|
|
602
|
+
Eo as minLength,
|
|
603
|
+
_o as number,
|
|
604
|
+
to as regex,
|
|
605
|
+
Bo as remote,
|
|
606
|
+
Do as required,
|
|
607
|
+
No as requiredNotFalse,
|
|
608
|
+
ro as useNotificar
|
|
600
609
|
};
|
package/dist/react-saas.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("@mui/material"),require("react-polyglot"),require("prop-types"),require("react-redux"),require("@reduxjs/toolkit"),require("axios"),require("jwt-decode"),require("react"),require("date-fns/locale"),require("@mui/x-date-pickers"),require("@mui/x-date-pickers/AdapterDateFns"),require("navigator-languages"),require("@mui/material/styles"),require("@mui/material/colors"),require("react-router-dom"),require("@mui/icons-material"),require("react-final-form"),require("mui-rff"),require("lodash/memoize")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@mui/material","react-polyglot","prop-types","react-redux","@reduxjs/toolkit","axios","jwt-decode","react","date-fns/locale","@mui/x-date-pickers","@mui/x-date-pickers/AdapterDateFns","navigator-languages","@mui/material/styles","@mui/material/colors","react-router-dom","@mui/icons-material","react-final-form","mui-rff","lodash/memoize"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s["react-saas"]={},s.ReactJSX,s.MuiMaterial,s.ReactPolyglot,s.PropTypes,s.ReactRedux,s.ReduxToolkit,s.Axios,s.JWTDecode,s.React,s.DateFNSLocale,s.MuiXDatePickers,s.MuiXDatePickersAdapter,s.NavigatorLanguages,s.MuiMaterialStyles,s.MuiMaterialColors,s.ReactRouterDom,s.MuiIconsMaterial,s.ReactFinalForm,s.MUIRFF,s.LodashMemoize))})(this,function(s,o,c,x,t,u,k,b,ee,h,L,ne,re,ie,z,T,S,D,oe,F,N){"use strict";const M=()=>o.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center"},children:o.jsx(c.CircularProgress,{})}),I=({titulo:n,texto:e,align:r="center",severity:i="error"})=>{const a=x.useTranslate();return o.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:r},children:o.jsxs(c.Alert,{severity:i,children:[o.jsx(c.AlertTitle,{children:a(n)}),e&&a(e)]})})};I.propTypes={titulo:t.string.isRequired,texto:t.string,align:t.string,severity:t.string};const U=k.createSlice({name:"ui",initialState:{tema:"light",temaSeleccionado:!1,idioma:"es"},reducers:{cambiarTema:(n,e)=>{n.tema=e.payload,n.temaSeleccionado=!0,localStorage.setItem("tema",e.payload)},cambiarIdioma:(n,e)=>{n.idioma=e.payload}}}),{cambiarTema:ae,cambiarIdioma:se}=U.actions,te=U.reducer,ce="https://saas.chimera.com.pe/backend",de="https://saas.chimera.com.pe/oauth",_=(n=de)=>({login:(e,r)=>b({url:`${n}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${e}`},method:"post",data:{username:r.correo,password:r.password,grant_type:"password"}}),refreshToken:(e,r)=>b({url:`${n}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${e}`},method:"post",data:{refresh_token:r,grant_type:"refresh_token"}})}),E=k.createSlice({name:"login",initialState:{cargando:!1,autenticado:!1,token:null,refreshToken:null,expiracion:null,usuario:null,perfiles:[],error:null},reducers:{logout:n=>{n.cargando=!1,n.autenticado=!1,n.token=null,n.refreshToken=null,n.expiracion=null,n.usuario=null,n.perfiles=[],n.error=null,sessionStorage.removeItem("saas-token"),sessionStorage.removeItem("saas-refresh-token"),sessionStorage.removeItem("saas-expiration")}},extraReducers(n){n.addCase(q.pending,e=>{e.cargando=!0,e.error=null}).addCase(q.fulfilled,(e,r)=>{const i=r.payload.access_token,a=ee(i),l=new Date;l.setSeconds(l.getSeconds()+r.payload.expires_in),e.cargando=!1,e.autenticado=!0,e.token=i,e.refreshToken=r.payload.refresh_token,e.expiracion=l.getTime(),e.usuario=a.name,e.perfiles=a.authorities,sessionStorage.setItem("saas-token",i),sessionStorage.setItem("saas-refresh-token",r.payload.refresh_token),sessionStorage.setItem("saas-expiration",l.getTime())}).addCase(q.rejected,(e,r)=>{var i;console.log(r),e.cargando=!1,e.autenticado=!1,e.token=null,e.refreshToken=null,e.expiracion=null,e.usuario=null,e.perfiles=[],e.error=(i=r.error)==null?void 0:i.message,sessionStorage.removeItem("saas-token"),sessionStorage.removeItem("saas-refresh-token"),sessionStorage.removeItem("saas-expiration")}).addCase(C.pending,e=>{e.cargando=!0}).addCase(C.fulfilled,(e,r)=>{const i=new Date;i.setSeconds(i.getSeconds()+r.payload.expires_in),e.token=r.payload.access_token,e.refreshToken=r.payload.refresh_token,e.expiracion=i.getTime(),sessionStorage.setItem("saas-token",r.payload.access_token),sessionStorage.setItem("saas-refresh-token",r.payload.refresh_token),sessionStorage.setItem("saas-expiration",i.getTime())}).addCase(C.rejected,(e,r)=>{var i;e.cargando=!1,e.autenticado=!1,e.token=null,e.refreshToken=null,e.expiracion=null,e.usuario=null,e.perfiles=[],e.error=(i=r.error)==null?void 0:i.message,sessionStorage.removeItem("saas-token"),sessionStorage.removeItem("saas-refresh-token"),sessionStorage.removeItem("saas-expiration")})}}),q=k.createAsyncThunk("login/requestToken",async n=>(await _(n.devURL).login(n.clientCredentials,n.data)).data),C=k.createAsyncThunk("login/refreshToken",async(n,e,r)=>(await _(n).refreshToken(e,r)).data),{logout:B}=E.actions,le=n=>n.login.token,ue=n=>n.login.usuario,fe=n=>n.login.perfiles,ge=E.reducer,G=k.createSlice({name:"notificacion",initialState:[],reducers:{mostrarNotificacion:(n,e)=>{n.push(e.payload)},ocultarNotificacion:n=>{n.pop()}}}),{mostrarNotificacion:he,ocultarNotificacion:pe}=G.actions,me=G.reducer,ke=(n=ce,e)=>b({url:`${n}/identidad/`,params:{codigoAplicacion:e}}),A={primary:"#1C6CCC",secondary:"#17A7FF",error:"#f44336",warning:"#ff9800",info:"#2196f3",success:"#4caf50"},Se=k.createSlice({name:"inicializar",initialState:{inicializando:!0,inicializado:!1,instancia:{color:A},error:null},extraReducers(n){n.addCase(w.pending,e=>{e.inicializando=!0}).addCase(w.fulfilled,(e,r)=>{e.inicializando=!1,e.inicializado=!0,e.instancia={...r.payload,abreviatura:r.payload.nombre.match(/\b([A-Z])/g).join(""),color:{...A,...r.payload.color}},e.error=null}).addCase(w.rejected,(e,r)=>{e.inicializando=!1,e.inicializado=!1,e.instancia={color:A},e.error=r.payload})}}),w=k.createAsyncThunk("inicializar",async n=>(await ke(n.devURL,n.aplicacion)).data),ye=n=>n.aplicacion.instancia,xe=Se.reducer,qe=n=>k.configureStore({reducer:{ui:te,aplicacion:xe,login:ge,notificaciones:me,...n}}),Ce=()=>{const[n,e]=h.useState(!1),r=u.useDispatch(),i=x.useTranslate(),a=u.useSelector(d=>d.notificaciones[0]);h.useEffect(()=>{e(!!a)},[a]);const l=()=>{e(!1),r(pe())};return o.jsx(c.Snackbar,{open:n,message:(a==null?void 0:a.mensaje)&&a.tipo==="default"&&i(a.mensaje),autoHideDuration:5e3,onClose:l,children:(a==null?void 0:a.mensaje)&&a.tipo!=="default"&&o.jsx(c.Alert,{severity:a.tipo,children:i(a.mensaje)})})},we={es:{inicializar:{error:{titulo:"Error iniciando aplicación",mensaje:"No fue posible conectarnos con el servicio"}},login:{titulo:"Acceder al sistema",correo:"Correo electrónico",password:"Contraseña",ingresar:"Acceder",validacion:{correo:"Debe ingresar una dirección de correo",password:"Debe ingresar una contraseña"},error:"Usuario o contraseña incorrectos"},copy:"Todos los derechos reservados "}},be={en:L.enGB,es:L.es},O=({messages:n,children:e})=>{const r=u.useSelector(i=>i.ui.idioma);return o.jsx(x.I18n,{locale:r,messages:n[r],children:o.jsx(ne.LocalizationProvider,{dateAdapter:re.AdapterDateFns,adapterLocale:be[r],children:e})})};O.propTypes={messages:t.object,children:t.element.isRequired};const Ie=()=>{const n=ie();if(!(n!=null&&n.length))return;const e=n[0];return e.indexOf("-")?e.substring(0,e.indexOf("-")):e},$=({messages:n,idiomaDefecto:e,children:r})=>{const i=u.useDispatch(),a=Ie();h.useEffect(()=>{let d=Reflect.ownKeys(n)[0];a&&Object.hasOwn(n,a)?d=a:e&&Object.hasOwn(n,e)&&(d=e),i(se(d))},[i,n,e,a]);const l={};return Object.keys(n).forEach(d=>{l[d]={...n[d],saas:we[d]}}),o.jsx(O,{messages:l,children:r})};$.propTypes={messages:t.object,idiomaDefecto:t.string,children:t.element.isRequired};const H=({children:n})=>{const e=u.useDispatch(),{instancia:r}=u.useSelector(d=>d.aplicacion),i=u.useSelector(d=>d.ui.tema),a=c.useMediaQuery("(prefers-color-scheme: dark)");h.useEffect(()=>{e(ae(a?"dark":"light"))},[e,a]);const l=h.useMemo(()=>z.createTheme({palette:{mode:i,primary:{main:r.color.primary},secondary:{main:r.color.secondary},error:{main:r.color.error},warning:{main:r.color.warning},info:{main:r.color.info},success:{main:r.color.success},...i==="light"&&{background:{default:T.grey.A200,paper:T.grey[100]}}},shape:{borderRadius:6}}),[i,r]);return o.jsxs(z.ThemeProvider,{theme:l,children:[o.jsx(c.CssBaseline,{}),n]})};H.propTypes={children:t.element.isRequired};const V=n=>{const e=u.useDispatch(),r=u.useSelector(a=>a.login),i=u.useSelector(a=>a.aplicacion.instancia);return h.useEffect(()=>{r.autenticado&&r.expiracion&&new Date(r.expiracion)<new Date&&(r.refreshToken?e(C(n,i.clientCredentials,r.refreshToken)):e(B()))},[n,i.clientCredentials,r,e]),r.autenticado},X=()=>{const n=u.useDispatch();return h.useCallback((e,r="default")=>{n(he({mensaje:e,tipo:r}))},[n])},J=({devURL:n})=>{const e=u.useDispatch(),r=x.useTranslate(),i=X(),{cargando:a,error:l}=u.useSelector(f=>f.login),d=u.useSelector(f=>f.aplicacion.instancia),y=f=>{e(q({devURL:n,clientCredentials:d.clientCredentials,data:{correo:f.correo,password:f.password}}))},v=f=>{const j={correo:void 0,password:void 0};return f.correo||(j.correo=r("saas.login.validacion.correo")),f.password||(j.password=r("saas.login.validacion.password")),j};return h.useEffect(()=>{l&&i("saas.login.error","error")},[i,l]),o.jsx(oe.Form,{onSubmit:y,validate:v,render:({handleSubmit:f})=>o.jsxs("form",{onSubmit:f,children:[o.jsx(F.TextField,{id:"correo",name:"correo",label:r("saas.login.correo"),variant:"outlined",autoComplete:"off",disabled:a,autoFocus:!0,InputProps:{startAdornment:o.jsx(c.InputAdornment,{position:"start",children:o.jsx(D.Email,{color:"primary"})})}}),o.jsx(F.TextField,{id:"password",name:"password",type:"password",label:r("saas.login.password"),variant:"outlined",autoComplete:"current-password",disabled:a,InputProps:{startAdornment:o.jsx(c.InputAdornment,{position:"start",children:o.jsx(D.Lock,{color:"primary"})})}}),o.jsxs(c.Grid,{container:!0,children:[o.jsx(c.Grid,{item:!0,xs:6}),o.jsx(c.Grid,{item:!0,xs:6,align:"right",children:o.jsx(c.Button,{variant:"contained",color:"primary",type:"submit",disabled:a,children:a?o.jsx(c.CircularProgress,{size:24,thickness:4}):r("saas.login.ingresar")})})]})]})})};J.propTypes={devURL:t.string};const W=({devURL:n})=>{const e=u.useSelector(d=>d.aplicacion.instancia),r=x.useTranslate(),i=S.useLocation(),a=V(n),{from:l}=i.state||{from:{pathname:"/"}};return!e.requiereLogin||a?o.jsx(S.Navigate,{to:l}):o.jsxs(c.Box,{sx:{position:"relative",display:"flex",flexDirection:"column",flexGrow:1,minHeight:"100vh",backgroundColor:"primary.main","&::before":{content:'""',backgroundImage:`url(${e.logo})`,backgroundSize:"contain",backgroundRepeat:"no-repeat",backgroundPosition:"right",position:"absolute",top:"20%",bottom:0,right:0,width:"50%",opacity:.02,filter:"grayscale(100%)"}},children:[o.jsx(c.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",flexGrow:1},children:o.jsx(c.Container,{maxWidth:"md",children:o.jsxs(c.Grid,{container:!0,spacing:3,children:[o.jsxs(c.Grid,{item:!0,xs:12,lg:5,align:"center",children:[o.jsx("img",{src:e.logo,alt:e.nombre,style:{maxWidth:"100%"}}),o.jsx(c.Typography,{variant:"h3",align:"center",children:r("aplicacion.nombre",{smart_count:1})}),o.jsx(c.Typography,{variant:"h5",align:"center",children:e.nombre})]}),o.jsx(c.Grid,{item:!0,xs:12,lg:7,sx:{display:"flex",alignItems:"center",justifyContent:"center",zIndex:5},children:o.jsxs(c.Card,{elevation:5,children:[o.jsx(c.CardHeader,{title:r("saas.login.titulo"),titleTypographyProps:{align:"center"}}),o.jsx(c.CardContent,{sx:{"& .MuiTextField-root":{mb:2}},children:o.jsx(J,{devURL:n})})]})})]})})}),o.jsx(c.AppBar,{position:"static",color:"primary",children:o.jsx(c.Toolbar,{sx:{justifyContent:"center"},children:o.jsxs(c.Typography,{variant:"caption",children:[r("saas.copy"),o.jsx(c.Link,{href:"//chimera.com.pe",color:"inherit",target:"_blank",rel:"noreferrer",children:"Chimera Software"})]})})})]})};W.propTypes={devURL:t.string};const Z=({devURL:n,redirectTo:e,children:r})=>{const i=S.useLocation();return V(n)?r:o.jsx(S.Navigate,{to:e,state:{from:i},replace:!0})};Z.propTypes={devURL:t.string,redirectTo:t.string.isRequired,children:t.element.isRequired};const K=({devURL:n,requiereLogin:e,basename:r,children:i})=>o.jsx(S.BrowserRouter,{basename:r,children:o.jsxs(S.Routes,{children:[o.jsx(S.Route,{path:"/login",element:o.jsx(W,{devURL:n})}),o.jsx(S.Route,{path:"/*",element:e?o.jsx(Z,{devURL:n,redirectTo:"/login",children:i}):i})]})});K.propTypes={devURL:t.string,requiereLogin:t.bool,basename:t.string,children:t.element.isRequired};const Q=({devURL:n,basename:e,children:r})=>{const i=u.useSelector(a=>a.aplicacion);return o.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh",justifyContent:"flex-start",backgroundColor:"background.default"},children:i.inicializando?o.jsx(M,{}):i.error||!i.inicializado?o.jsx(I,{titulo:"saas.inicializar.error.titulo",texto:"saas.inicializar.error.mensaje"}):o.jsxs(o.Fragment,{children:[o.jsx(K,{devURL:n,requiereLogin:i.instancia.requiereLogin,basename:e,children:r}),o.jsx(Ce,{})]})})};Q.propTypes={devURL:t.string,basename:t.string,children:t.element.isRequired};const Y=({aplicacion:n,devSaasURL:e,devAuthURL:r,messages:i,idiomaDefecto:a,basename:l,children:d})=>{const y=u.useDispatch();return h.useEffect(()=>{y(w({devURL:e,aplicacion:n}))},[y,n,e]),o.jsx($,{messages:i,idiomaDefecto:a,children:o.jsx(H,{children:o.jsx(Q,{devURL:r,basename:l,children:d})})})};Y.propTypes={aplicacion:t.string.isRequired,devSaasURL:t.string,devAuthURL:t.string,messages:t.object.isRequired,idiomaDefecto:t.string,basename:t.string,children:t.element.isRequired};const P=({customReducers:n,aplicacion:e,devSaasURL:r,devAuthURL:i,dev:a=!1,idiomaDefecto:l,messages:d,basename:y,children:v})=>o.jsx(u.Provider,{store:qe(n),children:o.jsx(Y,{aplicacion:e,devSaasURL:a?r:void 0,devAuthURL:a?i:void 0,idiomaDefecto:l,messages:d,basename:y,children:v})});P.propTypes={customReducers:t.object,aplicacion:t.string.isRequired,devSaasURL:t.string,devAuthURL:t.string,dev:t.bool,idiomaDefecto:t.string,messages:t.object,basename:t.string,children:t.element.isRequired};const Ae=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,p=n=>typeof n>"u"||n===null||n===""||Array.isArray(n)&&n.length===0,g=(n,e,r,i)=>typeof n=="function"?n({args:e,value:r,values:i}):e?{message:n,args:e}:n,m=n=>N(n,(...e)=>JSON.stringify(e)),ve=(...n)=>(e,r,i)=>(Array.isArray(n[0])?n[0]:n).reduce((l,d)=>l||typeof d=="function"&&d(e,r,i),void 0),je=m((n="validacion.obligatorio")=>Object.assign((e,r)=>p(e)?g(n,void 0,e,r):void 0,{isRequired:!0})),Le=m((n="validacion.obligatorio")=>Object.assign((e,r)=>p(e)||!e?g(n,void 0,e,r):void 0,{isRequired:!0})),ze=m((n="validacion.numero")=>(e,r)=>!p(e)&&isNaN(e)?g(n,void 0,e,r):void 0),Te=m((n,e="validacion.longitud.minima")=>(r,i)=>!p(r)&&r.length<n?g(e,void 0,r,i):void 0),De=m((n,e="validacion.longitud.maxima")=>(r,i)=>!p(r)&&r.length>n?g(e,void 0,r,i):void 0),Fe=m((n,e="validacion.minimo")=>(r,i)=>!p(r)&&parseFloat(r)<n?g(e,void 0,r,i):void 0),Ne=m((n,e="validacion.maximo")=>(r,i)=>!p(r)&&parseFloat(r)>n?g(e,void 0,r,i):void 0),R=N((n,e="validacion.regex")=>(r,i)=>!p(r)&&typeof r=="string"&&!n.test(r)?g(e,void 0,r,i):void 0,(n,e)=>n.toString()+e),Me=m((n="validacion.correo")=>R(Ae,n)),Ue=m((n,e,r="validacion.remote")=>(i,a,l)=>l.active&&!p(i)&&n(i,e).then(d=>d?g(r,void 0,i,a):void 0).catch(d=>g(d.message,void 0,i,a)));s.Cargando=M,s.Error=I,s.SaasApp=P,s.composeValidators=ve,s.email=Me,s.getInstancia=ye,s.getPerfiles=fe,s.getToken=le,s.getUsuario=ue,s.logout=B,s.max=Ne,s.maxLength=De,s.min=Fe,s.minLength=Te,s.number=ze,s.regex=R,s.remote=Ue,s.required=je,s.requiredNotFalse=Le,s.useNotificar=X,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(a,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("@mui/material"),require("react-polyglot"),require("prop-types"),require("react-redux"),require("@reduxjs/toolkit"),require("axios"),require("jwt-decode"),require("react"),require("date-fns/locale"),require("@mui/x-date-pickers"),require("@mui/x-date-pickers/AdapterDateFns"),require("navigator-languages"),require("@mui/material/styles"),require("@mui/material/colors"),require("react-router-dom"),require("@mui/icons-material"),require("react-final-form"),require("mui-rff"),require("lodash/memoize")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@mui/material","react-polyglot","prop-types","react-redux","@reduxjs/toolkit","axios","jwt-decode","react","date-fns/locale","@mui/x-date-pickers","@mui/x-date-pickers/AdapterDateFns","navigator-languages","@mui/material/styles","@mui/material/colors","react-router-dom","@mui/icons-material","react-final-form","mui-rff","lodash/memoize"],o):(a=typeof globalThis<"u"?globalThis:a||self,o(a["react-saas"]={},a.ReactJSX,a.MuiMaterial,a.ReactPolyglot,a.PropTypes,a.ReactRedux,a.ReduxToolkit,a.Axios,a.JWTDecode,a.React,a.DateFNSLocale,a.MuiXDatePickers,a.MuiXDatePickersAdapter,a.NavigatorLanguages,a.MuiMaterialStyles,a.MuiMaterialColors,a.ReactRouterDom,a.MuiIconsMaterial,a.ReactFinalForm,a.MUIRFF,a.LodashMemoize))})(this,function(a,o,d,q,t,u,S,j,N,p,F,oe,se,ae,E,M,k,_,te,O,U){"use strict";const B=()=>o.jsx(d.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center"},children:o.jsx(d.CircularProgress,{})}),v=({titulo:n,texto:e,align:i="center",severity:r="error"})=>{const s=q.useTranslate();return o.jsx(d.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:i},children:o.jsxs(d.Alert,{severity:r,children:[o.jsx(d.AlertTitle,{children:s(n)}),e&&s(e)]})})};v.propTypes={titulo:t.string.isRequired,texto:t.string,align:t.string,severity:t.string};const G=S.createSlice({name:"ui",initialState:{tema:"light",temaSeleccionado:!1,idioma:"es"},reducers:{cambiarTema:(n,e)=>{n.tema=e.payload,n.temaSeleccionado=!0,localStorage.setItem("tema",e.payload)},cambiarIdioma:(n,e)=>{n.idioma=e.payload}}}),{cambiarTema:ce,cambiarIdioma:de}=G.actions,le=G.reducer,ue="https://saas.chimera.com.pe/backend",fe="https://saas.chimera.com.pe/oauth",y="saas-token",w="saas-token-expiration",x="saas-refresh-token",$=(n=fe)=>({login:(e,i)=>j({url:`${n}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${e}`},method:"post",data:{username:i.correo,password:i.password,grant_type:"password"}}),refreshToken:(e,i)=>j({url:`${n}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${e}`},method:"post",data:{refresh_token:i,grant_type:"refresh_token"}})}),H=S.createSlice({name:"login",initialState:{cargando:!1,autenticado:!1,token:null,refreshToken:null,expiracion:null,usuario:null,perfiles:[],error:null},reducers:{login:(n,e)=>{const i=e.payload.token,r=N.jwtDecode(i),s=new Date;s.setSeconds(s.getSeconds()+e.payload.expiracion),n.cargando=!1,n.autenticado=!0,n.token=i,n.refreshToken=e.payload.refreshToken,n.expiracion=s.getTime(),n.usuario=r.name,n.perfiles=r.authorities},logout:n=>{n.cargando=!1,n.autenticado=!1,n.token=null,n.refreshToken=null,n.expiracion=null,n.usuario=null,n.perfiles=[],n.error=null,sessionStorage.removeItem(y),sessionStorage.removeItem(x),sessionStorage.removeItem(w)}},extraReducers(n){n.addCase(I.pending,e=>{e.cargando=!0,e.error=null}).addCase(I.fulfilled,(e,i)=>{const r=i.payload.access_token,s=N.jwtDecode(r),l=new Date;l.setSeconds(l.getSeconds()+i.payload.expires_in),e.cargando=!1,e.autenticado=!0,e.token=r,e.refreshToken=i.payload.refresh_token,e.expiracion=l.getTime(),e.usuario=s.name,e.perfiles=s.authorities,sessionStorage.setItem(y,r),sessionStorage.setItem(x,i.payload.refresh_token),sessionStorage.setItem(w,l.getTime())}).addCase(I.rejected,(e,i)=>{var r;console.log(i),e.cargando=!1,e.autenticado=!1,e.token=null,e.refreshToken=null,e.expiracion=null,e.usuario=null,e.perfiles=[],e.error=(r=i.error)==null?void 0:r.message,sessionStorage.removeItem(y),sessionStorage.removeItem(x),sessionStorage.removeItem(w)}).addCase(b.pending,e=>{e.cargando=!0}).addCase(b.fulfilled,(e,i)=>{const r=new Date;r.setSeconds(r.getSeconds()+i.payload.expires_in),e.token=i.payload.access_token,e.refreshToken=i.payload.refresh_token,e.expiracion=r.getTime(),sessionStorage.setItem(y,i.payload.access_token),sessionStorage.setItem(x,i.payload.refresh_token),sessionStorage.setItem(w,r.getTime())}).addCase(b.rejected,(e,i)=>{var r;e.cargando=!1,e.autenticado=!1,e.token=null,e.refreshToken=null,e.expiracion=null,e.usuario=null,e.perfiles=[],e.error=(r=i.error)==null?void 0:r.message,sessionStorage.removeItem(y),sessionStorage.removeItem(x),sessionStorage.removeItem(w)})}}),I=S.createAsyncThunk("login/requestToken",async n=>(await $(n.devURL).login(n.clientCredentials,n.data)).data),b=S.createAsyncThunk("login/refreshToken",async(n,e,i)=>(await $(n).refreshToken(e,i)).data),{login:ge,logout:T}=H.actions,pe=n=>n.login.token,he=n=>n.login.usuario,me=n=>n.login.perfiles,Se=H.reducer,X=S.createSlice({name:"notificacion",initialState:[],reducers:{mostrarNotificacion:(n,e)=>{n.push(e.payload)},ocultarNotificacion:n=>{n.pop()}}}),{mostrarNotificacion:ke,ocultarNotificacion:ye}=X.actions,we=X.reducer,xe=(n=ue,e)=>j({url:`${n}/identidad/`,params:{codigoAplicacion:e}}),L={primary:"#1C6CCC",secondary:"#17A7FF",error:"#f44336",warning:"#ff9800",info:"#2196f3",success:"#4caf50"},Ce=S.createSlice({name:"inicializar",initialState:{inicializando:!0,inicializado:!1,instancia:{color:L},error:null},extraReducers(n){n.addCase(A.pending,e=>{e.inicializando=!0}).addCase(A.fulfilled,(e,i)=>{e.inicializando=!1,e.inicializado=!0,e.instancia={...i.payload,abreviatura:i.payload.nombre.match(/\b([A-Z])/g).join(""),color:{...L,...i.payload.color}},e.error=null}).addCase(A.rejected,(e,i)=>{e.inicializando=!1,e.inicializado=!1,e.instancia={color:L},e.error=i.payload})}}),A=S.createAsyncThunk("inicializar",async n=>(await xe(n.devURL,n.aplicacion)).data),qe=n=>n.aplicacion.instancia,Ie=Ce.reducer,be=n=>S.configureStore({reducer:{ui:le,aplicacion:Ie,login:Se,notificaciones:we,...n}}),Ae=()=>{const[n,e]=p.useState(!1),i=u.useDispatch(),r=q.useTranslate(),s=u.useSelector(c=>c.notificaciones[0]);p.useEffect(()=>{e(!!s)},[s]);const l=()=>{e(!1),i(ye())};return o.jsx(d.Snackbar,{open:n,message:(s==null?void 0:s.mensaje)&&s.tipo==="default"&&r(s.mensaje),autoHideDuration:5e3,onClose:l,children:(s==null?void 0:s.mensaje)&&s.tipo!=="default"&&o.jsx(d.Alert,{severity:s.tipo,children:r(s.mensaje)})})},je={es:{inicializar:{error:{titulo:"Error iniciando aplicación",mensaje:"No fue posible conectarnos con el servicio"}},login:{titulo:"Acceder al sistema",correo:"Correo electrónico",password:"Contraseña",ingresar:"Acceder",validacion:{correo:"Debe ingresar una dirección de correo",password:"Debe ingresar una contraseña"},error:"Usuario o contraseña incorrectos"},copy:"Todos los derechos reservados "}},ve={en:F.enGB,es:F.es},K=({messages:n,children:e})=>{const i=u.useSelector(r=>r.ui.idioma);return o.jsx(q.I18n,{locale:i,messages:n[i],children:o.jsx(oe.LocalizationProvider,{dateAdapter:se.AdapterDateFns,adapterLocale:ve[i],children:e})})};K.propTypes={messages:t.object,children:t.element.isRequired};const Te=()=>{const n=ae();if(!(n!=null&&n.length))return;const e=n[0];return e.indexOf("-")?e.substring(0,e.indexOf("-")):e},V=({messages:n,idiomaDefecto:e,children:i})=>{const r=u.useDispatch(),s=Te();p.useEffect(()=>{let c=Reflect.ownKeys(n)[0];s&&Object.hasOwn(n,s)?c=s:e&&Object.hasOwn(n,e)&&(c=e),r(de(c))},[r,n,e,s]);const l={};return Object.keys(n).forEach(c=>{l[c]={...n[c],saas:je[c]}}),o.jsx(K,{messages:l,children:i})};V.propTypes={messages:t.object,idiomaDefecto:t.string,children:t.element.isRequired};const J=({children:n})=>{const e=u.useDispatch(),{instancia:i}=u.useSelector(c=>c.aplicacion),r=u.useSelector(c=>c.ui.tema),s=d.useMediaQuery("(prefers-color-scheme: dark)");p.useEffect(()=>{e(ce(s?"dark":"light"))},[e,s]);const l=p.useMemo(()=>E.createTheme({palette:{mode:r,primary:{main:i.color.primary},secondary:{main:i.color.secondary},error:{main:i.color.error},warning:{main:i.color.warning},info:{main:i.color.info},success:{main:i.color.success},...r==="light"&&{background:{default:M.grey.A200,paper:M.grey[100]}}},shape:{borderRadius:6}}),[r,i]);return o.jsxs(E.ThemeProvider,{theme:l,children:[o.jsx(d.CssBaseline,{}),n]})};J.propTypes={children:t.element.isRequired};const W=n=>{const e=u.useDispatch(),i=u.useSelector(s=>s.loginStatus),r=u.useSelector(s=>s.aplicacion.instancia);return p.useEffect(()=>{if(i.autenticado)i.expiracion&&new Date(i.expiracion)<new Date&&(i.refreshToken?e(b(n,r.clientCredentials,i.refreshToken)):e(T()));else{const s=sessionStorage.getItem(y),l=sessionStorage.getItem(w),c=sessionStorage.getItem(x);s&&l&&(new Date(l)<new Date?e(c?c(n,r.clientCredentials,c):T()):e(ge({token:s,expiracion:l,refreshToken:c})))}},[n,r.clientCredentials,i,e]),i.autenticado},Z=()=>{const n=u.useDispatch();return p.useCallback((e,i="default")=>{n(ke({mensaje:e,tipo:i}))},[n])},Q=({devURL:n})=>{const e=u.useDispatch(),i=q.useTranslate(),r=Z(),{cargando:s,error:l}=u.useSelector(f=>f.login),c=u.useSelector(f=>f.aplicacion.instancia),C=f=>{e(I({devURL:n,clientCredentials:c.clientCredentials,data:{correo:f.correo,password:f.password}}))},z=f=>{const D={correo:void 0,password:void 0};return f.correo||(D.correo=i("saas.login.validacion.correo")),f.password||(D.password=i("saas.login.validacion.password")),D};return p.useEffect(()=>{l&&r("saas.login.error","error")},[r,l]),o.jsx(te.Form,{onSubmit:C,validate:z,render:({handleSubmit:f})=>o.jsxs("form",{onSubmit:f,children:[o.jsx(O.TextField,{id:"correo",name:"correo",label:i("saas.login.correo"),variant:"outlined",autoComplete:"off",disabled:s,autoFocus:!0,InputProps:{startAdornment:o.jsx(d.InputAdornment,{position:"start",children:o.jsx(_.Email,{color:"primary"})})}}),o.jsx(O.TextField,{id:"password",name:"password",type:"password",label:i("saas.login.password"),variant:"outlined",autoComplete:"current-password",disabled:s,InputProps:{startAdornment:o.jsx(d.InputAdornment,{position:"start",children:o.jsx(_.Lock,{color:"primary"})})}}),o.jsxs(d.Grid,{container:!0,children:[o.jsx(d.Grid,{item:!0,xs:6}),o.jsx(d.Grid,{item:!0,xs:6,align:"right",children:o.jsx(d.Button,{variant:"contained",color:"primary",type:"submit",disabled:s,children:s?o.jsx(d.CircularProgress,{size:24,thickness:4}):i("saas.login.ingresar")})})]})]})})};Q.propTypes={devURL:t.string};const Y=({devURL:n})=>{const e=u.useSelector(c=>c.aplicacion.instancia),i=q.useTranslate(),r=k.useLocation(),s=W(n),{from:l}=r.state||{from:{pathname:"/"}};return!e.requiereLogin||s?o.jsx(k.Navigate,{to:l}):o.jsxs(d.Box,{sx:{position:"relative",display:"flex",flexDirection:"column",flexGrow:1,minHeight:"100vh",backgroundColor:"primary.main","&::before":{content:'""',backgroundImage:`url(${e.logo})`,backgroundSize:"contain",backgroundRepeat:"no-repeat",backgroundPosition:"right",position:"absolute",top:"20%",bottom:0,right:0,width:"50%",opacity:.02,filter:"grayscale(100%)"}},children:[o.jsx(d.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",flexGrow:1},children:o.jsx(d.Container,{maxWidth:"md",children:o.jsxs(d.Grid,{container:!0,spacing:3,children:[o.jsxs(d.Grid,{item:!0,xs:12,lg:5,align:"center",children:[o.jsx("img",{src:e.logo,alt:e.nombre,style:{maxWidth:"100%"}}),o.jsx(d.Typography,{variant:"h3",align:"center",children:i("aplicacion.nombre",{smart_count:1})}),o.jsx(d.Typography,{variant:"h5",align:"center",children:e.nombre})]}),o.jsx(d.Grid,{item:!0,xs:12,lg:7,sx:{display:"flex",alignItems:"center",justifyContent:"center",zIndex:5},children:o.jsxs(d.Card,{elevation:5,children:[o.jsx(d.CardHeader,{title:i("saas.login.titulo"),titleTypographyProps:{align:"center"}}),o.jsx(d.CardContent,{sx:{"& .MuiTextField-root":{mb:2}},children:o.jsx(Q,{devURL:n})})]})})]})})}),o.jsx(d.AppBar,{position:"static",color:"primary",children:o.jsx(d.Toolbar,{sx:{justifyContent:"center"},children:o.jsxs(d.Typography,{variant:"caption",children:[i("saas.copy"),o.jsx(d.Link,{href:"//chimera.com.pe",color:"inherit",target:"_blank",rel:"noreferrer",children:"Chimera Software"})]})})})]})};Y.propTypes={devURL:t.string};const P=({devURL:n,redirectTo:e,children:i})=>{const r=k.useLocation();return W(n)?i:o.jsx(k.Navigate,{to:e,state:{from:r},replace:!0})};P.propTypes={devURL:t.string,redirectTo:t.string.isRequired,children:t.element.isRequired};const R=({devURL:n,requiereLogin:e,basename:i,children:r})=>o.jsx(k.BrowserRouter,{basename:i,children:o.jsxs(k.Routes,{children:[o.jsx(k.Route,{path:"/login",element:o.jsx(Y,{devURL:n})}),o.jsx(k.Route,{path:"/*",element:e?o.jsx(P,{devURL:n,redirectTo:"/login",children:r}):r})]})});R.propTypes={devURL:t.string,requiereLogin:t.bool,basename:t.string,children:t.element.isRequired};const ee=({devURL:n,basename:e,children:i})=>{const r=u.useSelector(s=>s.aplicacion);return o.jsx(d.Box,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh",justifyContent:"flex-start",backgroundColor:"background.default"},children:r.inicializando?o.jsx(B,{}):r.error||!r.inicializado?o.jsx(v,{titulo:"saas.inicializar.error.titulo",texto:"saas.inicializar.error.mensaje"}):o.jsxs(o.Fragment,{children:[o.jsx(R,{devURL:n,requiereLogin:r.instancia.requiereLogin,basename:e,children:i}),o.jsx(Ae,{})]})})};ee.propTypes={devURL:t.string,basename:t.string,children:t.element.isRequired};const ne=({aplicacion:n,devSaasURL:e,devAuthURL:i,messages:r,idiomaDefecto:s,basename:l,children:c})=>{const C=u.useDispatch();return p.useEffect(()=>{C(A({devURL:e,aplicacion:n}))},[C,n,e]),o.jsx(V,{messages:r,idiomaDefecto:s,children:o.jsx(J,{children:o.jsx(ee,{devURL:i,basename:l,children:c})})})};ne.propTypes={aplicacion:t.string.isRequired,devSaasURL:t.string,devAuthURL:t.string,messages:t.object.isRequired,idiomaDefecto:t.string,basename:t.string,children:t.element.isRequired};const ie=({customReducers:n,aplicacion:e,devSaasURL:i,devAuthURL:r,dev:s=!1,idiomaDefecto:l,messages:c,basename:C,children:z})=>o.jsx(u.Provider,{store:be(n),children:o.jsx(ne,{aplicacion:e,devSaasURL:s?i:void 0,devAuthURL:s?r:void 0,idiomaDefecto:l,messages:c,basename:C,children:z})});ie.propTypes={customReducers:t.object,aplicacion:t.string.isRequired,devSaasURL:t.string,devAuthURL:t.string,dev:t.bool,idiomaDefecto:t.string,messages:t.object,basename:t.string,children:t.element.isRequired};const Le=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,h=n=>typeof n>"u"||n===null||n===""||Array.isArray(n)&&n.length===0,g=(n,e,i,r)=>typeof n=="function"?n({args:e,value:i,values:r}):e?{message:n,args:e}:n,m=n=>U(n,(...e)=>JSON.stringify(e)),ze=(...n)=>(e,i,r)=>(Array.isArray(n[0])?n[0]:n).reduce((l,c)=>l||typeof c=="function"&&c(e,i,r),void 0),De=m((n="validacion.obligatorio")=>Object.assign((e,i)=>h(e)?g(n,void 0,e,i):void 0,{isRequired:!0})),Ne=m((n="validacion.obligatorio")=>Object.assign((e,i)=>h(e)||!e?g(n,void 0,e,i):void 0,{isRequired:!0})),Fe=m((n="validacion.numero")=>(e,i)=>!h(e)&&isNaN(e)?g(n,void 0,e,i):void 0),Ee=m((n,e="validacion.longitud.minima")=>(i,r)=>!h(i)&&i.length<n?g(e,void 0,i,r):void 0),Me=m((n,e="validacion.longitud.maxima")=>(i,r)=>!h(i)&&i.length>n?g(e,void 0,i,r):void 0),_e=m((n,e="validacion.minimo")=>(i,r)=>!h(i)&&parseFloat(i)<n?g(e,void 0,i,r):void 0),Oe=m((n,e="validacion.maximo")=>(i,r)=>!h(i)&&parseFloat(i)>n?g(e,void 0,i,r):void 0),re=U((n,e="validacion.regex")=>(i,r)=>!h(i)&&typeof i=="string"&&!n.test(i)?g(e,void 0,i,r):void 0,(n,e)=>n.toString()+e),Ue=m((n="validacion.correo")=>re(Le,n)),Be=m((n,e,i="validacion.remote")=>(r,s,l)=>l.active&&!h(r)&&n(r,e).then(c=>c?g(i,void 0,r,s):void 0).catch(c=>g(c.message,void 0,r,s)));a.Cargando=B,a.Error=v,a.SaasApp=ie,a.composeValidators=ze,a.email=Ue,a.getInstancia=qe,a.getPerfiles=me,a.getToken=pe,a.getUsuario=he,a.logout=T,a.max=Oe,a.maxLength=Me,a.min=_e,a.minLength=Ee,a.number=Fe,a.regex=re,a.remote=Be,a.required=De,a.requiredNotFalse=Ne,a.useNotificar=Z,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chimera-pe/react-saas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -8,42 +8,38 @@
|
|
|
8
8
|
"lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
|
9
9
|
"preview": "vite preview"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
12
|
-
"@emotion/react": "^11.
|
|
13
|
-
"@emotion/styled": "^11.
|
|
14
|
-
"@mui/icons-material": "^5.
|
|
15
|
-
"@mui/lab": "^5.0.0-alpha.
|
|
16
|
-
"@mui/material": "^5.
|
|
17
|
-
"@mui/x-date-pickers": "^
|
|
18
|
-
"@reduxjs/toolkit": "^2.2.
|
|
19
|
-
"axios": "^1.
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@emotion/react": "^11.13.0",
|
|
13
|
+
"@emotion/styled": "^11.13.0",
|
|
14
|
+
"@mui/icons-material": "^5.16.5",
|
|
15
|
+
"@mui/lab": "^5.0.0-alpha.171",
|
|
16
|
+
"@mui/material": "^5.16.5",
|
|
17
|
+
"@mui/x-date-pickers": "^7.11.1",
|
|
18
|
+
"@reduxjs/toolkit": "^2.2.7",
|
|
19
|
+
"axios": "^1.7.2",
|
|
20
20
|
"date-fns": "^2.30.0",
|
|
21
21
|
"final-form": "^4.20.10",
|
|
22
22
|
"jwt-decode": "^4.0.0",
|
|
23
23
|
"lodash": "^4.17.21",
|
|
24
|
-
"mui-rff": "^7.
|
|
24
|
+
"mui-rff": "^7.4.1",
|
|
25
25
|
"navigator-languages": "^2.0.2",
|
|
26
|
-
"node-polyglot": "^2.
|
|
27
|
-
"react": "^18.
|
|
28
|
-
"react-dom": "^18.
|
|
26
|
+
"node-polyglot": "^2.6.0",
|
|
27
|
+
"react": "^18.3.1",
|
|
28
|
+
"react-dom": "^18.3.1",
|
|
29
29
|
"react-final-form": "^6.5.9",
|
|
30
30
|
"react-polyglot": "^0.7.2",
|
|
31
|
-
"react-redux": "^9.1.
|
|
32
|
-
"react-router-dom": "^6.
|
|
33
|
-
},
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"react": "^18.2.0",
|
|
36
|
-
"react-dom": "^18.2.0"
|
|
31
|
+
"react-redux": "^9.1.2",
|
|
32
|
+
"react-router-dom": "^6.25.1"
|
|
37
33
|
},
|
|
38
34
|
"devDependencies": {
|
|
39
|
-
"@types/react": "^18.
|
|
40
|
-
"@types/react-dom": "^18.
|
|
41
|
-
"@vitejs/plugin-react": "^4.
|
|
42
|
-
"eslint": "^8.
|
|
43
|
-
"eslint-plugin-react": "^7.
|
|
44
|
-
"eslint-plugin-react-hooks": "^4.6.
|
|
45
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
46
|
-
"vite": "^5.
|
|
35
|
+
"@types/react": "^18.3.3",
|
|
36
|
+
"@types/react-dom": "^18.3.0",
|
|
37
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
38
|
+
"eslint": "^8.57.0",
|
|
39
|
+
"eslint-plugin-react": "^7.35.0",
|
|
40
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
41
|
+
"eslint-plugin-react-refresh": "^0.4.9",
|
|
42
|
+
"vite": "^5.3.5"
|
|
47
43
|
},
|
|
48
44
|
"description": "Componente integrador con SaaS",
|
|
49
45
|
"main": "./dist/react-saas.umd.cjs",
|