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