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