@chimera-pe/react-saas 0.1.5 → 0.1.6

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