@chimera-pe/react-saas 0.0.3 → 0.0.4
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 +236 -177
- package/dist/react-saas.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/react-saas.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { Box as
|
|
3
|
-
import { useTranslate as k, I18n as
|
|
4
|
-
import
|
|
5
|
-
import { useDispatch as u, useSelector 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 { createTheme as
|
|
14
|
-
import { grey as
|
|
15
|
-
import { useLocation as
|
|
16
|
-
import { Email as
|
|
17
|
-
import { Form as
|
|
18
|
-
import { TextField as
|
|
19
|
-
const
|
|
1
|
+
import { jsx as i, jsxs as d, Fragment as V } from "react/jsx-runtime";
|
|
2
|
+
import { Box as g, CircularProgress as q, Alert as I, AlertTitle as X, Snackbar as Y, useMediaQuery as ee, CssBaseline as re, Container as oe, Grid as m, Typography as w, Card as ie, CardHeader as ne, CardContent as ae, AppBar as te, Toolbar as se, Link as ce, InputAdornment as j, Button as le } from "@mui/material";
|
|
3
|
+
import { useTranslate as k, I18n as de } from "react-polyglot";
|
|
4
|
+
import t from "prop-types";
|
|
5
|
+
import { useDispatch as u, useSelector as p, Provider as pe } from "react-redux";
|
|
6
|
+
import { createSlice as b, createAsyncThunk as S, configureStore as ue } from "@reduxjs/toolkit";
|
|
7
|
+
import v from "axios";
|
|
8
|
+
import me from "jwt-decode";
|
|
9
|
+
import { useState as fe, useEffect as f, useMemo as ge, useCallback as he } from "react";
|
|
10
|
+
import { enGB as ye, es as xe } from "date-fns/locale";
|
|
11
|
+
import { LocalizationProvider as ke } from "@mui/x-date-pickers";
|
|
12
|
+
import { AdapterDateFns as be } from "@mui/x-date-pickers/AdapterDateFns";
|
|
13
|
+
import { createTheme as Te, ThemeProvider as Ce } from "@mui/material/styles";
|
|
14
|
+
import { grey as L } from "@mui/material/colors";
|
|
15
|
+
import { useLocation as D, Navigate as U, BrowserRouter as we, Routes as Re, Route as z } from "react-router-dom";
|
|
16
|
+
import { Email as ve, Lock as Se } from "@mui/icons-material";
|
|
17
|
+
import { Form as je } from "react-final-form";
|
|
18
|
+
import { TextField as A } from "mui-rff";
|
|
19
|
+
const Le = () => /* @__PURE__ */ i(g, { sx: {
|
|
20
20
|
display: "flex",
|
|
21
21
|
flexDirection: "column",
|
|
22
22
|
flexGrow: 1,
|
|
23
23
|
justifyContent: "center",
|
|
24
24
|
alignItems: "center"
|
|
25
|
-
}, children: /* @__PURE__ */
|
|
25
|
+
}, children: /* @__PURE__ */ i(q, {}) }), _ = ({ titulo: o, texto: e, align: r = "center", severity: n = "error" }) => {
|
|
26
26
|
const a = k();
|
|
27
|
-
return /* @__PURE__ */
|
|
27
|
+
return /* @__PURE__ */ i(g, { sx: {
|
|
28
28
|
display: "flex",
|
|
29
29
|
flexDirection: "column",
|
|
30
30
|
flexGrow: 1,
|
|
31
31
|
justifyContent: "center",
|
|
32
32
|
alignItems: r
|
|
33
|
-
}, children: /* @__PURE__ */
|
|
34
|
-
/* @__PURE__ */
|
|
33
|
+
}, children: /* @__PURE__ */ d(I, { severity: n, children: [
|
|
34
|
+
/* @__PURE__ */ i(X, { children: a(o) }),
|
|
35
35
|
e && a(e)
|
|
36
36
|
] }) });
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
titulo:
|
|
40
|
-
texto:
|
|
41
|
-
align:
|
|
42
|
-
severity:
|
|
38
|
+
_.propTypes = {
|
|
39
|
+
titulo: t.string.isRequired,
|
|
40
|
+
texto: t.string,
|
|
41
|
+
align: t.string,
|
|
42
|
+
severity: t.string
|
|
43
43
|
};
|
|
44
|
-
const
|
|
44
|
+
const $ = b({
|
|
45
45
|
name: "ui",
|
|
46
46
|
initialState: {
|
|
47
47
|
tema: "light",
|
|
@@ -56,8 +56,8 @@ const P = C({
|
|
|
56
56
|
o.idioma = e.payload;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
}), { cambiarTema:
|
|
60
|
-
login: (e, r) =>
|
|
59
|
+
}), { cambiarTema: ze, cambiarIdioma: Ae } = $.actions, qe = $.reducer, Ie = "https://saas.chimera.com.pe/backend", De = "https://saas.chimera.com.pe/oauth", F = (o = De) => ({
|
|
60
|
+
login: (e, r) => v({
|
|
61
61
|
url: `${o}/oauth/token`,
|
|
62
62
|
headers: {
|
|
63
63
|
"content-type": "application/x-www-form-urlencoded",
|
|
@@ -70,7 +70,7 @@ const P = C({
|
|
|
70
70
|
grant_type: "password"
|
|
71
71
|
}
|
|
72
72
|
}),
|
|
73
|
-
refreshToken: (e, r) =>
|
|
73
|
+
refreshToken: (e, r) => v({
|
|
74
74
|
url: `${o}/oauth/token`,
|
|
75
75
|
headers: {
|
|
76
76
|
"content-type": "application/x-www-form-urlencoded",
|
|
@@ -82,7 +82,7 @@ const P = C({
|
|
|
82
82
|
grant_type: "refresh_token"
|
|
83
83
|
}
|
|
84
84
|
})
|
|
85
|
-
}),
|
|
85
|
+
}), P = b({
|
|
86
86
|
name: "login",
|
|
87
87
|
initialState: {
|
|
88
88
|
cargando: !1,
|
|
@@ -100,25 +100,25 @@ const P = C({
|
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
102
|
extraReducers(o) {
|
|
103
|
-
o.addCase(
|
|
103
|
+
o.addCase(h.pending, (e) => {
|
|
104
104
|
e.cargando = !0, e.error = null;
|
|
105
|
-
}).addCase(
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
}).addCase(
|
|
109
|
-
var
|
|
110
|
-
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 = (
|
|
105
|
+
}).addCase(h.fulfilled, (e, r) => {
|
|
106
|
+
const n = r.payload.access_token, a = me(n), s = /* @__PURE__ */ new Date();
|
|
107
|
+
s.setSeconds(s.getSeconds() + r.payload.expires_in), e.cargando = !1, e.autenticado = !0, e.token = n, e.refreshToken = r.payload.refresh_token, e.expiracion = s.getTime(), e.usuario = a.name, e.perfiles = a.authorities;
|
|
108
|
+
}).addCase(h.rejected, (e, r) => {
|
|
109
|
+
var n;
|
|
110
|
+
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 = (n = r.error) == null ? void 0 : n.message;
|
|
111
111
|
}).addCase(y.pending, (e) => {
|
|
112
112
|
e.cargando = !0;
|
|
113
113
|
}).addCase(y.fulfilled, (e, r) => {
|
|
114
|
-
const
|
|
115
|
-
|
|
114
|
+
const n = /* @__PURE__ */ new Date();
|
|
115
|
+
n.setSeconds(n.getSeconds() + r.payload.expires_in), e.token = r.payload.access_token, e.refreshToken = r.payload.refresh_token, e.expiracion = n.getTime();
|
|
116
116
|
}).addCase(y.rejected, (e, r) => {
|
|
117
|
-
var
|
|
118
|
-
e.cargando = !1, e.autenticado = !1, e.token = null, e.refreshToken = null, e.expiracion = null, e.usuario = null, e.perfiles = [], e.error = (
|
|
117
|
+
var n;
|
|
118
|
+
e.cargando = !1, e.autenticado = !1, e.token = null, e.refreshToken = null, e.expiracion = null, e.usuario = null, e.perfiles = [], e.error = (n = r.error) == null ? void 0 : n.message;
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
}),
|
|
121
|
+
}), h = S("login/requestToken", async (o) => (await F(o.devURL).login(o.clientCredentials, o.data)).data), y = S("login/refreshToken", async (o, e, r) => (await F(o).refreshToken(e, r)).data), { logout: Ue } = P.actions, _e = P.reducer, B = b({
|
|
122
122
|
name: "notificacion",
|
|
123
123
|
initialState: [],
|
|
124
124
|
reducers: {
|
|
@@ -129,25 +129,25 @@ const P = C({
|
|
|
129
129
|
o.pop();
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
}), { mostrarNotificacion:
|
|
132
|
+
}), { mostrarNotificacion: $e, ocultarNotificacion: Fe } = B.actions, Pe = B.reducer, Be = (o = Ie, e) => v({
|
|
133
133
|
url: `${o}/identidad/`,
|
|
134
134
|
params: {
|
|
135
135
|
codigoAplicacion: e
|
|
136
136
|
}
|
|
137
|
-
}),
|
|
137
|
+
}), R = {
|
|
138
138
|
primary: "#1C6CCC",
|
|
139
139
|
secondary: "#17A7FF",
|
|
140
140
|
error: "#f44336",
|
|
141
141
|
warning: "#ff9800",
|
|
142
142
|
info: "#2196f3",
|
|
143
143
|
success: "#4caf50"
|
|
144
|
-
},
|
|
144
|
+
}, Ne = b({
|
|
145
145
|
name: "inicializar",
|
|
146
146
|
initialState: {
|
|
147
147
|
inicializando: !0,
|
|
148
148
|
inicializado: !1,
|
|
149
149
|
instancia: {
|
|
150
|
-
color:
|
|
150
|
+
color: R
|
|
151
151
|
},
|
|
152
152
|
error: null
|
|
153
153
|
},
|
|
@@ -159,43 +159,43 @@ const P = C({
|
|
|
159
159
|
...r.payload,
|
|
160
160
|
abreviatura: r.payload.nombre.match(/\b([A-Z])/g).join(""),
|
|
161
161
|
color: {
|
|
162
|
-
...
|
|
162
|
+
...R,
|
|
163
163
|
...r.payload.color
|
|
164
164
|
}
|
|
165
165
|
}, e.error = null;
|
|
166
166
|
}).addCase(x.rejected, (e, r) => {
|
|
167
167
|
e.inicializando = !1, e.inicializado = !1, e.instancia = {
|
|
168
|
-
color:
|
|
168
|
+
color: R
|
|
169
169
|
}, e.error = r.payload;
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
|
-
}), x =
|
|
172
|
+
}), x = S("inicializar", async (o) => (await Be(o.devURL, o.aplicacion)).data), Ge = Ne.reducer, Ee = (o) => ue({
|
|
173
173
|
reducer: {
|
|
174
|
-
ui:
|
|
175
|
-
aplicacion:
|
|
176
|
-
login:
|
|
177
|
-
notificaciones:
|
|
174
|
+
ui: qe,
|
|
175
|
+
aplicacion: Ge,
|
|
176
|
+
login: _e,
|
|
177
|
+
notificaciones: Pe,
|
|
178
178
|
...o
|
|
179
179
|
}
|
|
180
|
-
}),
|
|
181
|
-
const [o, e] =
|
|
182
|
-
|
|
180
|
+
}), Me = () => {
|
|
181
|
+
const [o, e] = fe(!1), r = u(), n = k(), a = p((c) => c.notificaciones[0]);
|
|
182
|
+
f(() => {
|
|
183
183
|
e(!!a);
|
|
184
184
|
}, [a]);
|
|
185
|
-
const
|
|
186
|
-
e(!1), r(
|
|
185
|
+
const s = () => {
|
|
186
|
+
e(!1), r(Fe());
|
|
187
187
|
};
|
|
188
|
-
return /* @__PURE__ */
|
|
189
|
-
|
|
188
|
+
return /* @__PURE__ */ i(
|
|
189
|
+
Y,
|
|
190
190
|
{
|
|
191
191
|
open: o,
|
|
192
|
-
message: a && a.mensaje && a.tipo === "default" &&
|
|
192
|
+
message: a && a.mensaje && a.tipo === "default" && n(a.mensaje),
|
|
193
193
|
autoHideDuration: 5e3,
|
|
194
|
-
onClose:
|
|
195
|
-
children: a && a.mensaje && a.tipo !== "default" && /* @__PURE__ */
|
|
194
|
+
onClose: s,
|
|
195
|
+
children: a && a.mensaje && a.tipo !== "default" && /* @__PURE__ */ i(I, { severity: a.tipo, children: n(a.mensaje) })
|
|
196
196
|
}
|
|
197
197
|
);
|
|
198
|
-
},
|
|
198
|
+
}, He = {
|
|
199
199
|
inicializar: {
|
|
200
200
|
error: {
|
|
201
201
|
titulo: "Error iniciando aplicación",
|
|
@@ -214,31 +214,42 @@ const P = C({
|
|
|
214
214
|
error: "Usuario o contraseña incorrectos"
|
|
215
215
|
},
|
|
216
216
|
copy: "Todos los derechos reservados "
|
|
217
|
-
},
|
|
218
|
-
es:
|
|
219
|
-
},
|
|
220
|
-
const r =
|
|
221
|
-
return /* @__PURE__ */
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
217
|
+
}, Oe = {
|
|
218
|
+
es: He
|
|
219
|
+
}, We = { en: ye, es: xe }, N = ({ messages: o, children: e }) => {
|
|
220
|
+
const r = p((n) => n.ui.idioma);
|
|
221
|
+
return /* @__PURE__ */ i(de, { locale: r, messages: o[r], children: /* @__PURE__ */ i(ke, { dateAdapter: be, adapterLocale: We[r], children: e }) });
|
|
222
|
+
};
|
|
223
|
+
N.propTypes = {
|
|
224
|
+
messages: t.object,
|
|
225
|
+
children: t.element.isRequired
|
|
226
|
+
};
|
|
227
|
+
const G = ({ messages: o, idioma: e, children: r }) => {
|
|
228
|
+
const n = u();
|
|
229
|
+
f(() => {
|
|
230
|
+
e && n(Ae(e));
|
|
231
|
+
}, [n, e]);
|
|
227
232
|
const a = {};
|
|
228
|
-
return Object.keys(o).forEach((
|
|
229
|
-
a[
|
|
230
|
-
...o[
|
|
231
|
-
saas:
|
|
233
|
+
return Object.keys(o).forEach((s) => {
|
|
234
|
+
a[s] = {
|
|
235
|
+
...o[s],
|
|
236
|
+
saas: Oe[s]
|
|
232
237
|
};
|
|
233
|
-
}), /* @__PURE__ */
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
+
}), /* @__PURE__ */ i(N, { messages: a, children: r });
|
|
239
|
+
};
|
|
240
|
+
G.propTypes = {
|
|
241
|
+
messages: t.object,
|
|
242
|
+
idioma: t.string,
|
|
243
|
+
children: t.element.isRequired
|
|
244
|
+
};
|
|
245
|
+
const E = ({ children: o }) => {
|
|
246
|
+
const e = u(), { instancia: r } = p((c) => c.aplicacion), n = p((c) => c.ui.tema), a = ee("(prefers-color-scheme: dark)");
|
|
247
|
+
f(() => {
|
|
248
|
+
e(ze(a ? "dark" : "light"));
|
|
238
249
|
}, [e, a]);
|
|
239
|
-
const
|
|
250
|
+
const s = ge(() => Te({
|
|
240
251
|
palette: {
|
|
241
|
-
mode:
|
|
252
|
+
mode: n,
|
|
242
253
|
primary: {
|
|
243
254
|
main: r.color.primary
|
|
244
255
|
},
|
|
@@ -257,55 +268,59 @@ const P = C({
|
|
|
257
268
|
success: {
|
|
258
269
|
main: r.color.success
|
|
259
270
|
},
|
|
260
|
-
...
|
|
271
|
+
...n === "light" && {
|
|
261
272
|
background: {
|
|
262
|
-
default:
|
|
263
|
-
paper:
|
|
273
|
+
default: L.A200,
|
|
274
|
+
paper: L[100]
|
|
264
275
|
}
|
|
265
276
|
}
|
|
266
277
|
},
|
|
267
278
|
shape: {
|
|
268
279
|
borderRadius: 6
|
|
269
280
|
}
|
|
270
|
-
}), [
|
|
271
|
-
return /* @__PURE__ */
|
|
272
|
-
/* @__PURE__ */
|
|
281
|
+
}), [n, r]);
|
|
282
|
+
return /* @__PURE__ */ d(Ce, { theme: s, children: [
|
|
283
|
+
/* @__PURE__ */ i(re, {}),
|
|
273
284
|
o
|
|
274
285
|
] });
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
286
|
+
};
|
|
287
|
+
E.propTypes = {
|
|
288
|
+
children: t.element.isRequired
|
|
289
|
+
};
|
|
290
|
+
const M = (o) => {
|
|
291
|
+
const e = u(), r = p((a) => a.login), n = p((a) => a.aplicacion.instancia);
|
|
292
|
+
return f(() => {
|
|
293
|
+
r.autenticado && r.expiracion && new Date(r.expiracion) < /* @__PURE__ */ new Date() && (r.refreshToken ? e(y(o, n.clientCredentials, r.refreshToken)) : e(Ue()));
|
|
294
|
+
}, [o, n.clientCredentials, r, e]), r.autenticado;
|
|
295
|
+
}, Qe = () => {
|
|
281
296
|
const o = u();
|
|
282
|
-
return
|
|
283
|
-
o(
|
|
297
|
+
return he((e, r = "default") => {
|
|
298
|
+
o($e({ mensaje: e, tipo: r }));
|
|
284
299
|
}, [o]);
|
|
285
|
-
},
|
|
286
|
-
const e = u(), r = k(),
|
|
287
|
-
e(
|
|
300
|
+
}, H = ({ devURL: o }) => {
|
|
301
|
+
const e = u(), r = k(), n = Qe(), { cargando: a, error: s } = p((l) => l.login), c = p((l) => l.aplicacion.instancia), T = (l) => {
|
|
302
|
+
e(h({
|
|
288
303
|
devURL: o,
|
|
289
304
|
clientCredentials: c.clientCredentials,
|
|
290
305
|
data: {
|
|
291
|
-
correo:
|
|
292
|
-
password:
|
|
306
|
+
correo: l.correo,
|
|
307
|
+
password: l.password
|
|
293
308
|
}
|
|
294
309
|
}));
|
|
295
|
-
},
|
|
296
|
-
const
|
|
297
|
-
return
|
|
310
|
+
}, K = (l) => {
|
|
311
|
+
const C = { correo: void 0, password: void 0 };
|
|
312
|
+
return l.correo || (C.correo = r("saas.login.validacion.correo")), l.password || (C.password = r("saas.login.validacion.password")), C;
|
|
298
313
|
};
|
|
299
|
-
return
|
|
300
|
-
|
|
301
|
-
}, [
|
|
302
|
-
|
|
314
|
+
return f(() => {
|
|
315
|
+
s && n("saas.login.error", "error");
|
|
316
|
+
}, [n, s]), /* @__PURE__ */ i(
|
|
317
|
+
je,
|
|
303
318
|
{
|
|
304
|
-
onSubmit:
|
|
305
|
-
validate:
|
|
306
|
-
render: ({ handleSubmit:
|
|
307
|
-
/* @__PURE__ */
|
|
308
|
-
|
|
319
|
+
onSubmit: T,
|
|
320
|
+
validate: K,
|
|
321
|
+
render: ({ handleSubmit: l }) => /* @__PURE__ */ d("form", { onSubmit: l, children: [
|
|
322
|
+
/* @__PURE__ */ i(
|
|
323
|
+
A,
|
|
309
324
|
{
|
|
310
325
|
id: "correo",
|
|
311
326
|
name: "correo",
|
|
@@ -315,12 +330,12 @@ const P = C({
|
|
|
315
330
|
disabled: a,
|
|
316
331
|
autoFocus: !0,
|
|
317
332
|
InputProps: {
|
|
318
|
-
startAdornment: /* @__PURE__ */
|
|
333
|
+
startAdornment: /* @__PURE__ */ i(j, { position: "start", children: /* @__PURE__ */ i(ve, { color: "primary" }) })
|
|
319
334
|
}
|
|
320
335
|
}
|
|
321
336
|
),
|
|
322
|
-
/* @__PURE__ */
|
|
323
|
-
|
|
337
|
+
/* @__PURE__ */ i(
|
|
338
|
+
A,
|
|
324
339
|
{
|
|
325
340
|
id: "password",
|
|
326
341
|
name: "password",
|
|
@@ -330,29 +345,33 @@ const P = C({
|
|
|
330
345
|
autoComplete: "current-password",
|
|
331
346
|
disabled: a,
|
|
332
347
|
InputProps: {
|
|
333
|
-
startAdornment: /* @__PURE__ */
|
|
348
|
+
startAdornment: /* @__PURE__ */ i(j, { position: "start", children: /* @__PURE__ */ i(Se, { color: "primary" }) })
|
|
334
349
|
}
|
|
335
350
|
}
|
|
336
351
|
),
|
|
337
|
-
/* @__PURE__ */
|
|
338
|
-
/* @__PURE__ */
|
|
339
|
-
/* @__PURE__ */
|
|
340
|
-
|
|
352
|
+
/* @__PURE__ */ d(m, { container: !0, children: [
|
|
353
|
+
/* @__PURE__ */ i(m, { item: !0, xs: 6 }),
|
|
354
|
+
/* @__PURE__ */ i(m, { item: !0, xs: 6, align: "right", children: /* @__PURE__ */ i(
|
|
355
|
+
le,
|
|
341
356
|
{
|
|
342
357
|
variant: "contained",
|
|
343
358
|
color: "primary",
|
|
344
359
|
type: "submit",
|
|
345
360
|
disabled: a,
|
|
346
|
-
children: a ? /* @__PURE__ */
|
|
361
|
+
children: a ? /* @__PURE__ */ i(q, { size: 24, thickness: 4 }) : r("saas.login.ingresar")
|
|
347
362
|
}
|
|
348
363
|
) })
|
|
349
364
|
] })
|
|
350
365
|
] })
|
|
351
366
|
}
|
|
352
367
|
);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
368
|
+
};
|
|
369
|
+
H.propTypes = {
|
|
370
|
+
devURL: t.string
|
|
371
|
+
};
|
|
372
|
+
const O = ({ devURL: o }) => {
|
|
373
|
+
const e = p((c) => c.aplicacion.instancia), r = k(), n = D(), a = M(o), { from: s } = n.state || { from: { pathname: "/" } };
|
|
374
|
+
return !e.requiereLogin || a ? /* @__PURE__ */ i(U, { to: s }) : /* @__PURE__ */ d(g, { sx: {
|
|
356
375
|
position: "relative",
|
|
357
376
|
display: "flex",
|
|
358
377
|
flexDirection: "column",
|
|
@@ -374,96 +393,136 @@ const P = C({
|
|
|
374
393
|
filter: "grayscale(100%)"
|
|
375
394
|
}
|
|
376
395
|
}, children: [
|
|
377
|
-
/* @__PURE__ */
|
|
396
|
+
/* @__PURE__ */ i(g, { sx: {
|
|
378
397
|
display: "flex",
|
|
379
398
|
justifyContent: "center",
|
|
380
399
|
alignItems: "center",
|
|
381
400
|
flexGrow: 1
|
|
382
|
-
}, children: /* @__PURE__ */
|
|
383
|
-
/* @__PURE__ */
|
|
384
|
-
/* @__PURE__ */
|
|
385
|
-
/* @__PURE__ */
|
|
386
|
-
/* @__PURE__ */
|
|
401
|
+
}, children: /* @__PURE__ */ i(oe, { maxWidth: "md", children: /* @__PURE__ */ d(m, { container: !0, spacing: 3, children: [
|
|
402
|
+
/* @__PURE__ */ d(m, { item: !0, xs: 12, lg: 5, align: "center", children: [
|
|
403
|
+
/* @__PURE__ */ i("img", { src: e.logo, alt: e.nombre, style: { maxWidth: "100%" } }),
|
|
404
|
+
/* @__PURE__ */ i(w, { variant: "h3", align: "center", children: r("aplicacion.nombre", { smart_count: 1 }) }),
|
|
405
|
+
/* @__PURE__ */ i(w, { variant: "h5", align: "center", children: e.nombre })
|
|
387
406
|
] }),
|
|
388
|
-
/* @__PURE__ */
|
|
407
|
+
/* @__PURE__ */ i(m, { item: !0, xs: 12, lg: 7, sx: {
|
|
389
408
|
display: "flex",
|
|
390
409
|
alignItems: "center",
|
|
391
410
|
justifyContent: "center",
|
|
392
411
|
zIndex: 5
|
|
393
|
-
}, children: /* @__PURE__ */
|
|
394
|
-
/* @__PURE__ */
|
|
395
|
-
/* @__PURE__ */
|
|
412
|
+
}, children: /* @__PURE__ */ d(ie, { elevation: 5, children: [
|
|
413
|
+
/* @__PURE__ */ i(ne, { title: r("saas.login.titulo"), titleTypographyProps: { align: "center" } }),
|
|
414
|
+
/* @__PURE__ */ i(ae, { sx: {
|
|
396
415
|
"& .MuiTextField-root": {
|
|
397
416
|
mb: 2
|
|
398
417
|
}
|
|
399
|
-
}, children: /* @__PURE__ */
|
|
418
|
+
}, children: /* @__PURE__ */ i(H, { devURL: o }) })
|
|
400
419
|
] }) })
|
|
401
420
|
] }) }) }),
|
|
402
|
-
/* @__PURE__ */
|
|
421
|
+
/* @__PURE__ */ i(te, { position: "static", color: "primary", children: /* @__PURE__ */ i(se, { sx: { justifyContent: "center" }, children: /* @__PURE__ */ d(w, { variant: "caption", children: [
|
|
403
422
|
r("saas.copy"),
|
|
404
|
-
/* @__PURE__ */
|
|
423
|
+
/* @__PURE__ */ i(ce, { href: "//chimera.com.pe", color: "inherit", target: "_blank", rel: "noreferrer", children: "Chimera Software" })
|
|
405
424
|
] }) }) })
|
|
406
425
|
] });
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
426
|
+
};
|
|
427
|
+
O.propTypes = {
|
|
428
|
+
devURL: t.string
|
|
429
|
+
};
|
|
430
|
+
const W = ({ devURL: o, redirectTo: e, children: r }) => {
|
|
431
|
+
const n = D();
|
|
432
|
+
return M(o) ? r : /* @__PURE__ */ i(U, { to: e, state: { from: n }, replace: !0 });
|
|
433
|
+
};
|
|
434
|
+
W.propTypes = {
|
|
435
|
+
devURL: t.string,
|
|
436
|
+
redirectTo: t.string.isRequired,
|
|
437
|
+
children: t.element.isRequired
|
|
438
|
+
};
|
|
439
|
+
const Q = ({ devURL: o, requiereLogin: e, children: r }) => /* @__PURE__ */ i(we, { children: /* @__PURE__ */ d(Re, { children: [
|
|
440
|
+
/* @__PURE__ */ i(z, { path: "/login", element: /* @__PURE__ */ i(O, { devURL: o }) }),
|
|
441
|
+
/* @__PURE__ */ i(
|
|
442
|
+
z,
|
|
414
443
|
{
|
|
415
444
|
path: "/*",
|
|
416
|
-
element: e ? /* @__PURE__ */
|
|
445
|
+
element: e ? /* @__PURE__ */ i(W, { devURL: o, redirectTo: "/login", children: r }) : r
|
|
417
446
|
}
|
|
418
447
|
)
|
|
419
|
-
] }) })
|
|
420
|
-
|
|
421
|
-
|
|
448
|
+
] }) });
|
|
449
|
+
Q.propTypes = {
|
|
450
|
+
devURL: t.string,
|
|
451
|
+
requiereLogin: t.bool,
|
|
452
|
+
children: t.element.isRequired
|
|
453
|
+
};
|
|
454
|
+
const Z = ({ devURL: o, children: e }) => {
|
|
455
|
+
const r = p((n) => n.aplicacion);
|
|
456
|
+
return /* @__PURE__ */ i(g, { sx: {
|
|
422
457
|
display: "flex",
|
|
423
458
|
flexDirection: "column",
|
|
424
459
|
minHeight: "100vh",
|
|
425
460
|
justifyContent: "flex-start",
|
|
426
461
|
backgroundColor: "background.default"
|
|
427
|
-
}, children: r.inicializando ? /* @__PURE__ */
|
|
428
|
-
/* @__PURE__ */
|
|
429
|
-
/* @__PURE__ */
|
|
462
|
+
}, children: r.inicializando ? /* @__PURE__ */ i(Le, {}) : r.error || !r.inicializado ? /* @__PURE__ */ i(_, { titulo: "saas.inicializar.error.titulo", texto: "saas.inicializar.error.mensaje" }) : /* @__PURE__ */ d(V, { children: [
|
|
463
|
+
/* @__PURE__ */ i(Q, { devURL: o, requiereLogin: r.instancia.requiereLogin, children: e }),
|
|
464
|
+
/* @__PURE__ */ i(Me, {})
|
|
430
465
|
] }) });
|
|
431
|
-
}
|
|
466
|
+
};
|
|
467
|
+
Z.propTypes = {
|
|
468
|
+
devURL: t.string,
|
|
469
|
+
children: t.element.isRequired
|
|
470
|
+
};
|
|
471
|
+
const J = ({
|
|
432
472
|
aplicacion: o,
|
|
433
473
|
devSaasURL: e,
|
|
434
474
|
devAuthURL: r,
|
|
435
|
-
messages:
|
|
475
|
+
messages: n,
|
|
436
476
|
idioma: a,
|
|
437
|
-
children:
|
|
477
|
+
children: s
|
|
438
478
|
}) => {
|
|
439
479
|
const c = u();
|
|
440
|
-
return
|
|
480
|
+
return f(() => {
|
|
441
481
|
c(x({ devURL: e, aplicacion: o }));
|
|
442
|
-
}, [c, o, e]), /* @__PURE__ */
|
|
443
|
-
}
|
|
482
|
+
}, [c, o, e]), /* @__PURE__ */ i(G, { messages: n, idioma: a, children: /* @__PURE__ */ i(E, { children: /* @__PURE__ */ i(Z, { devURL: r, children: s }) }) });
|
|
483
|
+
};
|
|
484
|
+
J.propTypes = {
|
|
485
|
+
aplicacion: t.string.isRequired,
|
|
486
|
+
devSaasURL: t.string,
|
|
487
|
+
devAuthURL: t.string,
|
|
488
|
+
messages: t.object,
|
|
489
|
+
idioma: t.string,
|
|
490
|
+
children: t.element.isRequired
|
|
491
|
+
};
|
|
492
|
+
const Ze = ({
|
|
444
493
|
customReducers: o,
|
|
445
494
|
aplicacion: e,
|
|
446
495
|
devSaasURL: r,
|
|
447
|
-
devAuthURL:
|
|
496
|
+
devAuthURL: n,
|
|
448
497
|
dev: a = !1,
|
|
449
|
-
idioma:
|
|
498
|
+
idioma: s,
|
|
450
499
|
messages: c,
|
|
451
|
-
children:
|
|
452
|
-
}) => /* @__PURE__ */
|
|
453
|
-
|
|
500
|
+
children: T
|
|
501
|
+
}) => /* @__PURE__ */ i(pe, { store: Ee(o), children: /* @__PURE__ */ i(
|
|
502
|
+
J,
|
|
454
503
|
{
|
|
455
504
|
aplicacion: e,
|
|
456
505
|
devSaasURL: a && r,
|
|
457
|
-
devAuthURL: a &&
|
|
458
|
-
idioma:
|
|
506
|
+
devAuthURL: a && n,
|
|
507
|
+
idioma: s,
|
|
459
508
|
messages: c,
|
|
460
|
-
children:
|
|
509
|
+
children: T
|
|
461
510
|
}
|
|
462
511
|
) });
|
|
512
|
+
Ze.propTypes = {
|
|
513
|
+
customReducers: t.object,
|
|
514
|
+
aplicacion: t.string.isRequired,
|
|
515
|
+
devSaasURL: t.string,
|
|
516
|
+
devAuthURL: t.string,
|
|
517
|
+
dev: t.bool,
|
|
518
|
+
idioma: t.string,
|
|
519
|
+
messages: t.object,
|
|
520
|
+
children: t.element.isRequired
|
|
521
|
+
};
|
|
463
522
|
export {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
523
|
+
Le as Cargando,
|
|
524
|
+
_ as Error,
|
|
525
|
+
Ze as SaasApp,
|
|
526
|
+
Ue as logout,
|
|
527
|
+
Qe as useNotificar
|
|
469
528
|
};
|
package/dist/react-saas.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,i){typeof exports=="object"&&typeof module<"u"?i(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("@mui/material/styles"),require("@mui/material/colors"),require("react-router-dom"),require("@mui/icons-material"),require("react-final-form"),require("mui-rff")):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","@mui/material/styles","@mui/material/colors","react-router-dom","@mui/icons-material","react-final-form","mui-rff"],i):(c=typeof globalThis<"u"?globalThis:c||self,i(c["react-saas"]={},c.ReactJSX,c.MuiMaterial,c.ReactPolyglot,c.PropTypes,c.ReactRedux,c.ReduxToolkit,c.Axios,c.JWTDecode,c.React,c.DateFNSLocale,c.MuiXDatePickers,c.MuiXDatePickersAdapter,c.MuiMaterialStyles,c.MuiMaterialColors,c.ReactRouterDom,c.MuiIconsMaterial,c.ReactFinalForm,c.MUIRFF))})(this,function(c,i,s,g,y,l,f,S,G,p,b,N,$,j,v,h,q,P,z){"use strict";const I=()=>i.jsx(s.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center"},children:i.jsx(s.CircularProgress,{})}),C=({titulo:o,texto:e,align:r="center",severity:n="error"})=>{const a=g.useTranslate();return i.jsx(s.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:r},children:i.jsxs(s.Alert,{severity:n,children:[i.jsx(s.AlertTitle,{children:a(o)}),e&&a(e)]})})};C.propTypes={titulo:y.string.isRequired,texto:y.string,align:y.string,severity:y.string};const D=f.createSlice({name:"ui",initialState:{tema:"light",temaSeleccionado:!1,idioma:"es"},reducers:{cambiarTema:(o,e)=>{o.tema=e.payload,o.temaSeleccionado=!0,localStorage.setItem("tema",e.payload)},cambiarIdioma:(o,e)=>{o.idioma=e.payload}}}),{cambiarTema:U,cambiarIdioma:H}=D.actions,O=D.reducer,W="https://saas.chimera.com.pe/backend",X="https://saas.chimera.com.pe/oauth",L=(o=X)=>({login:(e,r)=>S({url:`${o}/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)=>S({url:`${o}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${e}`},method:"post",data:{refresh_token:r,grant_type:"refresh_token"}})}),F=f.createSlice({name:"login",initialState:{cargando:!1,autenticado:!1,token:null,refreshToken:null,expiracion:null,usuario:null,perfiles:[],error:null},reducers:{logout:o=>{o.cargando=!1,o.autenticado=!1,o.token=null,o.refreshToken=null,o.expiracion=null,o.usuario=null,o.perfiles=[],o.error=null}},extraReducers(o){o.addCase(m.pending,e=>{e.cargando=!0,e.error=null}).addCase(m.fulfilled,(e,r)=>{const n=r.payload.access_token,a=G(n),t=new Date;t.setSeconds(t.getSeconds()+r.payload.expires_in),e.cargando=!1,e.autenticado=!0,e.token=n,e.refreshToken=r.payload.refresh_token,e.expiracion=t.getTime(),e.usuario=a.name,e.perfiles=a.authorities}).addCase(m.rejected,(e,r)=>{var n;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=(n=r.error)==null?void 0:n.message}).addCase(k.pending,e=>{e.cargando=!0}).addCase(k.fulfilled,(e,r)=>{const n=new Date;n.setSeconds(n.getSeconds()+r.payload.expires_in),e.token=r.payload.access_token,e.refreshToken=r.payload.refresh_token,e.expiracion=n.getTime()}).addCase(k.rejected,(e,r)=>{var n;e.cargando=!1,e.autenticado=!1,e.token=null,e.refreshToken=null,e.expiracion=null,e.usuario=null,e.perfiles=[],e.error=(n=r.error)==null?void 0:n.message})}}),m=f.createAsyncThunk("login/requestToken",async o=>(await L(o.devURL).login(o.clientCredentials,o.data)).data),k=f.createAsyncThunk("login/refreshToken",async(o,e,r)=>(await L(o).refreshToken(e,r)).data),{logout:M}=F.actions,J=F.reducer,B=f.createSlice({name:"notificacion",initialState:[],reducers:{mostrarNotificacion:(o,e)=>{o.push(e.payload)},ocultarNotificacion:o=>{o.pop()}}}),{mostrarNotificacion:Q,ocultarNotificacion:Z}=B.actions,K=B.reducer,V=(o=W,e)=>S({url:`${o}/identidad/`,params:{codigoAplicacion:e}}),T={primary:"#1C6CCC",secondary:"#17A7FF",error:"#f44336",warning:"#ff9800",info:"#2196f3",success:"#4caf50"},Y=f.createSlice({name:"inicializar",initialState:{inicializando:!0,inicializado:!1,instancia:{color:T},error:null},extraReducers(o){o.addCase(x.pending,e=>{e.inicializando=!0}).addCase(x.fulfilled,(e,r)=>{e.inicializando=!1,e.inicializado=!0,e.instancia={...r.payload,abreviatura:r.payload.nombre.match(/\b([A-Z])/g).join(""),color:{...T,...r.payload.color}},e.error=null}).addCase(x.rejected,(e,r)=>{e.inicializando=!1,e.inicializado=!1,e.instancia={color:T},e.error=r.payload})}}),x=f.createAsyncThunk("inicializar",async o=>(await V(o.devURL,o.aplicacion)).data),R=Y.reducer,ee=o=>f.configureStore({reducer:{ui:O,aplicacion:R,login:J,notificaciones:K,...o}}),re=()=>{const[o,e]=p.useState(!1),r=l.useDispatch(),n=g.useTranslate(),a=l.useSelector(d=>d.notificaciones[0]);p.useEffect(()=>{e(!!a)},[a]);const t=()=>{e(!1),r(Z())};return i.jsx(s.Snackbar,{open:o,message:a&&a.mensaje&&a.tipo==="default"&&n(a.mensaje),autoHideDuration:5e3,onClose:t,children:a&&a.mensaje&&a.tipo!=="default"&&i.jsx(s.Alert,{severity:a.tipo,children:n(a.mensaje)})})},oe={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 "}},ie={en:b.enGB,es:b.es},ne=({messages:o,children:e})=>{const r=l.useSelector(n=>n.ui.idioma);return i.jsx(g.I18n,{locale:r,messages:o[r],children:i.jsx(N.LocalizationProvider,{dateAdapter:$.AdapterDateFns,adapterLocale:ie[r],children:e})})},ae=({messages:o,idioma:e,children:r})=>{const n=l.useDispatch();p.useEffect(()=>{e&&n(H(e))},[n,e]);const a={};return Object.keys(o).forEach(t=>{a[t]={...o[t],saas:oe[t]}}),i.jsx(ne,{messages:a,children:r})},se=({children:o})=>{const e=l.useDispatch(),{instancia:r}=l.useSelector(d=>d.aplicacion),n=l.useSelector(d=>d.ui.tema),a=s.useMediaQuery("(prefers-color-scheme: dark)");p.useEffect(()=>{e(U(a?"dark":"light"))},[e,a]);const t=p.useMemo(()=>j.createTheme({palette:{mode:n,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},...n==="light"&&{background:{default:v.grey.A200,paper:v.grey[100]}}},shape:{borderRadius:6}}),[n,r]);return i.jsxs(j.ThemeProvider,{theme:t,children:[i.jsx(s.CssBaseline,{}),o]})},_=o=>{const e=l.useDispatch(),r=l.useSelector(a=>a.login),n=l.useSelector(a=>a.aplicacion.instancia);return p.useEffect(()=>{r.autenticado&&r.expiracion&&new Date(r.expiracion)<new Date&&(r.refreshToken?e(k(o,n.clientCredentials,r.refreshToken)):e(M()))},[o,n.clientCredentials,r,e]),r.autenticado},E=()=>{const o=l.useDispatch();return p.useCallback((e,r="default")=>{o(Q({mensaje:e,tipo:r}))},[o])},ce=({devURL:o})=>{const e=l.useDispatch(),r=g.useTranslate(),n=E(),{cargando:a,error:t}=l.useSelector(u=>u.login),d=l.useSelector(u=>u.aplicacion.instancia),w=u=>{e(m({devURL:o,clientCredentials:d.clientCredentials,data:{correo:u.correo,password:u.password}}))},he=u=>{const A={correo:void 0,password:void 0};return u.correo||(A.correo=r("saas.login.validacion.correo")),u.password||(A.password=r("saas.login.validacion.password")),A};return p.useEffect(()=>{t&&n("saas.login.error","error")},[n,t]),i.jsx(P.Form,{onSubmit:w,validate:he,render:({handleSubmit:u})=>i.jsxs("form",{onSubmit:u,children:[i.jsx(z.TextField,{id:"correo",name:"correo",label:r("saas.login.correo"),variant:"outlined",autoComplete:"off",disabled:a,autoFocus:!0,InputProps:{startAdornment:i.jsx(s.InputAdornment,{position:"start",children:i.jsx(q.Email,{color:"primary"})})}}),i.jsx(z.TextField,{id:"password",name:"password",type:"password",label:r("saas.login.password"),variant:"outlined",autoComplete:"current-password",disabled:a,InputProps:{startAdornment:i.jsx(s.InputAdornment,{position:"start",children:i.jsx(q.Lock,{color:"primary"})})}}),i.jsxs(s.Grid,{container:!0,children:[i.jsx(s.Grid,{item:!0,xs:6}),i.jsx(s.Grid,{item:!0,xs:6,align:"right",children:i.jsx(s.Button,{variant:"contained",color:"primary",type:"submit",disabled:a,children:a?i.jsx(s.CircularProgress,{size:24,thickness:4}):r("saas.login.ingresar")})})]})]})})},te=({devURL:o})=>{const e=l.useSelector(d=>d.aplicacion.instancia),r=g.useTranslate(),n=h.useLocation(),a=_(o),{from:t}=n.state||{from:{pathname:"/"}};return!e.requiereLogin||a?i.jsx(h.Navigate,{to:t}):i.jsxs(s.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:[i.jsx(s.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",flexGrow:1},children:i.jsx(s.Container,{maxWidth:"md",children:i.jsxs(s.Grid,{container:!0,spacing:3,children:[i.jsxs(s.Grid,{item:!0,xs:12,lg:5,align:"center",children:[i.jsx("img",{src:e.logo,alt:e.nombre,style:{maxWidth:"100%"}}),i.jsx(s.Typography,{variant:"h3",align:"center",children:r("aplicacion.nombre",{smart_count:1})}),i.jsx(s.Typography,{variant:"h5",align:"center",children:e.nombre})]}),i.jsx(s.Grid,{item:!0,xs:12,lg:7,sx:{display:"flex",alignItems:"center",justifyContent:"center",zIndex:5},children:i.jsxs(s.Card,{elevation:5,children:[i.jsx(s.CardHeader,{title:r("saas.login.titulo"),titleTypographyProps:{align:"center"}}),i.jsx(s.CardContent,{sx:{"& .MuiTextField-root":{mb:2}},children:i.jsx(ce,{devURL:o})})]})})]})})}),i.jsx(s.AppBar,{position:"static",color:"primary",children:i.jsx(s.Toolbar,{sx:{justifyContent:"center"},children:i.jsxs(s.Typography,{variant:"caption",children:[r("saas.copy"),i.jsx(s.Link,{href:"//chimera.com.pe",color:"inherit",target:"_blank",rel:"noreferrer",children:"Chimera Software"})]})})})]})},le=({devURL:o,redirectTo:e,children:r})=>{const n=h.useLocation();return _(o)?r:i.jsx(h.Navigate,{to:e,state:{from:n},replace:!0})},de=({devURL:o,requiereLogin:e,children:r})=>i.jsx(h.BrowserRouter,{children:i.jsxs(h.Routes,{children:[i.jsx(h.Route,{path:"/login",element:i.jsx(te,{devURL:o})}),i.jsx(h.Route,{path:"/*",element:e?i.jsx(le,{devURL:o,redirectTo:"/login",children:r}):r})]})}),ue=({devURL:o,children:e})=>{const r=l.useSelector(n=>n.aplicacion);return i.jsx(s.Box,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh",justifyContent:"flex-start",backgroundColor:"background.default"},children:r.inicializando?i.jsx(I,{}):r.error||!r.inicializado?i.jsx(C,{titulo:"saas.inicializar.error.titulo",texto:"saas.inicializar.error.mensaje"}):i.jsxs(i.Fragment,{children:[i.jsx(de,{devURL:o,requiereLogin:r.instancia.requiereLogin,children:e}),i.jsx(re,{})]})})},pe=({aplicacion:o,devSaasURL:e,devAuthURL:r,messages:n,idioma:a,children:t})=>{const d=l.useDispatch();return p.useEffect(()=>{d(x({devURL:e,aplicacion:o}))},[d,o,e]),i.jsx(ae,{messages:n,idioma:a,children:i.jsx(se,{children:i.jsx(ue,{devURL:r,children:t})})})},fe=({customReducers:o,aplicacion:e,devSaasURL:r,devAuthURL:n,dev:a=!1,idioma:t,messages:d,children:w})=>i.jsx(l.Provider,{store:ee(o),children:i.jsx(pe,{aplicacion:e,devSaasURL:a&&r,devAuthURL:a&&n,idioma:t,messages:d,children:w})});c.Cargando=I,c.Error=C,c.SaasApp=fe,c.logout=M,c.useNotificar=E,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(t,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("@mui/material/styles"),require("@mui/material/colors"),require("react-router-dom"),require("@mui/icons-material"),require("react-final-form"),require("mui-rff")):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","@mui/material/styles","@mui/material/colors","react-router-dom","@mui/icons-material","react-final-form","mui-rff"],o):(t=typeof globalThis<"u"?globalThis:t||self,o(t["react-saas"]={},t.ReactJSX,t.MuiMaterial,t.ReactPolyglot,t.PropTypes,t.ReactRedux,t.ReduxToolkit,t.Axios,t.JWTDecode,t.React,t.DateFNSLocale,t.MuiXDatePickers,t.MuiXDatePickersAdapter,t.MuiMaterialStyles,t.MuiMaterialColors,t.ReactRouterDom,t.MuiIconsMaterial,t.ReactFinalForm,t.MUIRFF))})(this,function(t,o,c,m,s,d,h,S,Z,f,b,K,V,A,j,g,L,Y,z){"use strict";const T=()=>o.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center"},children:o.jsx(c.CircularProgress,{})}),C=({titulo:i,texto:e,align:r="center",severity:n="error"})=>{const a=m.useTranslate();return o.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:r},children:o.jsxs(c.Alert,{severity:n,children:[o.jsx(c.AlertTitle,{children:a(i)}),e&&a(e)]})})};C.propTypes={titulo:s.string.isRequired,texto:s.string,align:s.string,severity:s.string};const I=h.createSlice({name:"ui",initialState:{tema:"light",temaSeleccionado:!1,idioma:"es"},reducers:{cambiarTema:(i,e)=>{i.tema=e.payload,i.temaSeleccionado=!0,localStorage.setItem("tema",e.payload)},cambiarIdioma:(i,e)=>{i.idioma=e.payload}}}),{cambiarTema:P,cambiarIdioma:R}=I.actions,ee=I.reducer,re="https://saas.chimera.com.pe/backend",ie="https://saas.chimera.com.pe/oauth",D=(i=ie)=>({login:(e,r)=>S({url:`${i}/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)=>S({url:`${i}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${e}`},method:"post",data:{refresh_token:r,grant_type:"refresh_token"}})}),F=h.createSlice({name:"login",initialState:{cargando:!1,autenticado:!1,token:null,refreshToken:null,expiracion:null,usuario:null,perfiles:[],error:null},reducers:{logout:i=>{i.cargando=!1,i.autenticado=!1,i.token=null,i.refreshToken=null,i.expiracion=null,i.usuario=null,i.perfiles=[],i.error=null}},extraReducers(i){i.addCase(k.pending,e=>{e.cargando=!0,e.error=null}).addCase(k.fulfilled,(e,r)=>{const n=r.payload.access_token,a=Z(n),l=new Date;l.setSeconds(l.getSeconds()+r.payload.expires_in),e.cargando=!1,e.autenticado=!0,e.token=n,e.refreshToken=r.payload.refresh_token,e.expiracion=l.getTime(),e.usuario=a.name,e.perfiles=a.authorities}).addCase(k.rejected,(e,r)=>{var n;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=(n=r.error)==null?void 0:n.message}).addCase(x.pending,e=>{e.cargando=!0}).addCase(x.fulfilled,(e,r)=>{const n=new Date;n.setSeconds(n.getSeconds()+r.payload.expires_in),e.token=r.payload.access_token,e.refreshToken=r.payload.refresh_token,e.expiracion=n.getTime()}).addCase(x.rejected,(e,r)=>{var n;e.cargando=!1,e.autenticado=!1,e.token=null,e.refreshToken=null,e.expiracion=null,e.usuario=null,e.perfiles=[],e.error=(n=r.error)==null?void 0:n.message})}}),k=h.createAsyncThunk("login/requestToken",async i=>(await D(i.devURL).login(i.clientCredentials,i.data)).data),x=h.createAsyncThunk("login/refreshToken",async(i,e,r)=>(await D(i).refreshToken(e,r)).data),{logout:M}=F.actions,oe=F.reducer,U=h.createSlice({name:"notificacion",initialState:[],reducers:{mostrarNotificacion:(i,e)=>{i.push(e.payload)},ocultarNotificacion:i=>{i.pop()}}}),{mostrarNotificacion:ne,ocultarNotificacion:ae}=U.actions,se=U.reducer,ce=(i=re,e)=>S({url:`${i}/identidad/`,params:{codigoAplicacion:e}}),w={primary:"#1C6CCC",secondary:"#17A7FF",error:"#f44336",warning:"#ff9800",info:"#2196f3",success:"#4caf50"},te=h.createSlice({name:"inicializar",initialState:{inicializando:!0,inicializado:!1,instancia:{color:w},error:null},extraReducers(i){i.addCase(y.pending,e=>{e.inicializando=!0}).addCase(y.fulfilled,(e,r)=>{e.inicializando=!1,e.inicializado=!0,e.instancia={...r.payload,abreviatura:r.payload.nombre.match(/\b([A-Z])/g).join(""),color:{...w,...r.payload.color}},e.error=null}).addCase(y.rejected,(e,r)=>{e.inicializando=!1,e.inicializado=!1,e.instancia={color:w},e.error=r.payload})}}),y=h.createAsyncThunk("inicializar",async i=>(await ce(i.devURL,i.aplicacion)).data),le=te.reducer,de=i=>h.configureStore({reducer:{ui:ee,aplicacion:le,login:oe,notificaciones:se,...i}}),ue=()=>{const[i,e]=f.useState(!1),r=d.useDispatch(),n=m.useTranslate(),a=d.useSelector(u=>u.notificaciones[0]);f.useEffect(()=>{e(!!a)},[a]);const l=()=>{e(!1),r(ae())};return o.jsx(c.Snackbar,{open:i,message:a&&a.mensaje&&a.tipo==="default"&&n(a.mensaje),autoHideDuration:5e3,onClose:l,children:a&&a.mensaje&&a.tipo!=="default"&&o.jsx(c.Alert,{severity:a.tipo,children:n(a.mensaje)})})},pe={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 "}},fe={en:b.enGB,es:b.es},B=({messages:i,children:e})=>{const r=d.useSelector(n=>n.ui.idioma);return o.jsx(m.I18n,{locale:r,messages:i[r],children:o.jsx(K.LocalizationProvider,{dateAdapter:V.AdapterDateFns,adapterLocale:fe[r],children:e})})};B.propTypes={messages:s.object,children:s.element.isRequired};const _=({messages:i,idioma:e,children:r})=>{const n=d.useDispatch();f.useEffect(()=>{e&&n(R(e))},[n,e]);const a={};return Object.keys(i).forEach(l=>{a[l]={...i[l],saas:pe[l]}}),o.jsx(B,{messages:a,children:r})};_.propTypes={messages:s.object,idioma:s.string,children:s.element.isRequired};const E=({children:i})=>{const e=d.useDispatch(),{instancia:r}=d.useSelector(u=>u.aplicacion),n=d.useSelector(u=>u.ui.tema),a=c.useMediaQuery("(prefers-color-scheme: dark)");f.useEffect(()=>{e(P(a?"dark":"light"))},[e,a]);const l=f.useMemo(()=>A.createTheme({palette:{mode:n,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},...n==="light"&&{background:{default:j.grey.A200,paper:j.grey[100]}}},shape:{borderRadius:6}}),[n,r]);return o.jsxs(A.ThemeProvider,{theme:l,children:[o.jsx(c.CssBaseline,{}),i]})};E.propTypes={children:s.element.isRequired};const G=i=>{const e=d.useDispatch(),r=d.useSelector(a=>a.login),n=d.useSelector(a=>a.aplicacion.instancia);return f.useEffect(()=>{r.autenticado&&r.expiracion&&new Date(r.expiracion)<new Date&&(r.refreshToken?e(x(i,n.clientCredentials,r.refreshToken)):e(M()))},[i,n.clientCredentials,r,e]),r.autenticado},N=()=>{const i=d.useDispatch();return f.useCallback((e,r="default")=>{i(ne({mensaje:e,tipo:r}))},[i])},$=({devURL:i})=>{const e=d.useDispatch(),r=m.useTranslate(),n=N(),{cargando:a,error:l}=d.useSelector(p=>p.login),u=d.useSelector(p=>p.aplicacion.instancia),q=p=>{e(k({devURL:i,clientCredentials:u.clientCredentials,data:{correo:p.correo,password:p.password}}))},he=p=>{const v={correo:void 0,password:void 0};return p.correo||(v.correo=r("saas.login.validacion.correo")),p.password||(v.password=r("saas.login.validacion.password")),v};return f.useEffect(()=>{l&&n("saas.login.error","error")},[n,l]),o.jsx(Y.Form,{onSubmit:q,validate:he,render:({handleSubmit:p})=>o.jsxs("form",{onSubmit:p,children:[o.jsx(z.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(L.Email,{color:"primary"})})}}),o.jsx(z.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(L.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")})})]})]})})};$.propTypes={devURL:s.string};const H=({devURL:i})=>{const e=d.useSelector(u=>u.aplicacion.instancia),r=m.useTranslate(),n=g.useLocation(),a=G(i),{from:l}=n.state||{from:{pathname:"/"}};return!e.requiereLogin||a?o.jsx(g.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($,{devURL:i})})]})})]})})}),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"})]})})})]})};H.propTypes={devURL:s.string};const O=({devURL:i,redirectTo:e,children:r})=>{const n=g.useLocation();return G(i)?r:o.jsx(g.Navigate,{to:e,state:{from:n},replace:!0})};O.propTypes={devURL:s.string,redirectTo:s.string.isRequired,children:s.element.isRequired};const W=({devURL:i,requiereLogin:e,children:r})=>o.jsx(g.BrowserRouter,{children:o.jsxs(g.Routes,{children:[o.jsx(g.Route,{path:"/login",element:o.jsx(H,{devURL:i})}),o.jsx(g.Route,{path:"/*",element:e?o.jsx(O,{devURL:i,redirectTo:"/login",children:r}):r})]})});W.propTypes={devURL:s.string,requiereLogin:s.bool,children:s.element.isRequired};const X=({devURL:i,children:e})=>{const r=d.useSelector(n=>n.aplicacion);return o.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh",justifyContent:"flex-start",backgroundColor:"background.default"},children:r.inicializando?o.jsx(T,{}):r.error||!r.inicializado?o.jsx(C,{titulo:"saas.inicializar.error.titulo",texto:"saas.inicializar.error.mensaje"}):o.jsxs(o.Fragment,{children:[o.jsx(W,{devURL:i,requiereLogin:r.instancia.requiereLogin,children:e}),o.jsx(ue,{})]})})};X.propTypes={devURL:s.string,children:s.element.isRequired};const J=({aplicacion:i,devSaasURL:e,devAuthURL:r,messages:n,idioma:a,children:l})=>{const u=d.useDispatch();return f.useEffect(()=>{u(y({devURL:e,aplicacion:i}))},[u,i,e]),o.jsx(_,{messages:n,idioma:a,children:o.jsx(E,{children:o.jsx(X,{devURL:r,children:l})})})};J.propTypes={aplicacion:s.string.isRequired,devSaasURL:s.string,devAuthURL:s.string,messages:s.object,idioma:s.string,children:s.element.isRequired};const Q=({customReducers:i,aplicacion:e,devSaasURL:r,devAuthURL:n,dev:a=!1,idioma:l,messages:u,children:q})=>o.jsx(d.Provider,{store:de(i),children:o.jsx(J,{aplicacion:e,devSaasURL:a&&r,devAuthURL:a&&n,idioma:l,messages:u,children:q})});Q.propTypes={customReducers:s.object,aplicacion:s.string.isRequired,devSaasURL:s.string,devAuthURL:s.string,dev:s.bool,idioma:s.string,messages:s.object,children:s.element.isRequired},t.Cargando=T,t.Error=C,t.SaasApp=Q,t.logout=M,t.useNotificar=N,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|