@chimera-pe/react-saas 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react-saas.js +26 -26
- package/dist/react-saas.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/react-saas.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as o, jsxs as d, Fragment as $e } from "react/jsx-runtime";
|
|
2
|
-
import { Box as $, CircularProgress as X, Alert as Q, AlertTitle as xe, Snackbar as Te, useMediaQuery as we, CssBaseline as Se, Container as je, Grid as
|
|
2
|
+
import { Box as $, CircularProgress as X, Alert as Q, AlertTitle as xe, Snackbar as Te, useMediaQuery as we, CssBaseline as Se, Container as je, Grid as m, Typography as A, Card as Oe, CardHeader as Re, CardContent as ke, AppBar as ze, Toolbar as De, Link as Ie, InputAdornment as G, Button as Ae } from "@mui/material";
|
|
3
3
|
import { useTranslate as j, I18n as Le } from "react-polyglot";
|
|
4
4
|
import i from "prop-types";
|
|
5
|
-
import { useDispatch as
|
|
5
|
+
import { useDispatch as g, useSelector as u, Provider as Pe } from "react-redux";
|
|
6
6
|
import { createSlice as O, createAsyncThunk as q, configureStore as Ne } from "@reduxjs/toolkit";
|
|
7
7
|
import N from "axios";
|
|
8
8
|
import qe from "jwt-decode";
|
|
@@ -119,7 +119,7 @@ const re = O({
|
|
|
119
119
|
r.cargando = !1, r.autenticado = !1, r.token = null, r.refreshToken = null, r.expiracion = null, r.usuario = null, r.perfiles = [], r.error = (a = t.error) == null ? void 0 : a.message;
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
}), T = q("login/requestToken", async (e) => (await te(e.devURL).login(e.clientCredentials, e.data)).data), w = q("login/refreshToken", async (e, r, t) => (await te(e).refreshToken(r, t)).data), { logout: sr } = ae.actions, Sn = (e) => e.token, jn = (e) => e.usuario, On = (e) => e.perfiles, cr = ae.reducer, ne = O({
|
|
122
|
+
}), T = q("login/requestToken", async (e) => (await te(e.devURL).login(e.clientCredentials, e.data)).data), w = q("login/refreshToken", async (e, r, t) => (await te(e).refreshToken(r, t)).data), { logout: sr } = ae.actions, Sn = (e) => e.login.token, jn = (e) => e.login.usuario, On = (e) => e.login.perfiles, cr = ae.reducer, ne = O({
|
|
123
123
|
name: "notificacion",
|
|
124
124
|
initialState: [],
|
|
125
125
|
reducers: {
|
|
@@ -170,7 +170,7 @@ const re = O({
|
|
|
170
170
|
}, r.error = t.payload;
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
|
-
}), S = q("inicializar", async (e) => (await pr(e.devURL, e.aplicacion)).data), Rn = (e) => e.instancia, fr = hr.reducer,
|
|
173
|
+
}), S = q("inicializar", async (e) => (await pr(e.devURL, e.aplicacion)).data), Rn = (e) => e.aplicacion.instancia, fr = hr.reducer, gr = (e) => Ne({
|
|
174
174
|
reducer: {
|
|
175
175
|
ui: nr,
|
|
176
176
|
aplicacion: fr,
|
|
@@ -178,8 +178,8 @@ const re = O({
|
|
|
178
178
|
notificaciones: ur,
|
|
179
179
|
...e
|
|
180
180
|
}
|
|
181
|
-
}),
|
|
182
|
-
const [e, r] = Fe(!1), t =
|
|
181
|
+
}), mr = () => {
|
|
182
|
+
const [e, r] = Fe(!1), t = g(), a = j(), n = u((s) => s.notificaciones[0]);
|
|
183
183
|
v(() => {
|
|
184
184
|
r(!!n);
|
|
185
185
|
}, [n]);
|
|
@@ -232,7 +232,7 @@ const br = () => {
|
|
|
232
232
|
const r = e[0];
|
|
233
233
|
return r.indexOf("-") ? r.substring(0, r.indexOf("-")) : r;
|
|
234
234
|
}, ie = ({ messages: e, idiomaDefecto: r, children: t }) => {
|
|
235
|
-
const a =
|
|
235
|
+
const a = g(), n = br();
|
|
236
236
|
v(() => {
|
|
237
237
|
let s = Reflect.ownKeys(e)[0];
|
|
238
238
|
n && Object.hasOwn(e, n) ? s = n : r && Object.hasOwn(e, r) && (s = r), a(ar(s));
|
|
@@ -251,7 +251,7 @@ ie.propTypes = {
|
|
|
251
251
|
children: i.element.isRequired
|
|
252
252
|
};
|
|
253
253
|
const se = ({ children: e }) => {
|
|
254
|
-
const r =
|
|
254
|
+
const r = g(), { instancia: t } = u((s) => s.aplicacion), a = u((s) => s.ui.tema), n = we("(prefers-color-scheme: dark)");
|
|
255
255
|
v(() => {
|
|
256
256
|
r(tr(n ? "dark" : "light"));
|
|
257
257
|
}, [r, n]);
|
|
@@ -296,17 +296,17 @@ se.propTypes = {
|
|
|
296
296
|
children: i.element.isRequired
|
|
297
297
|
};
|
|
298
298
|
const ce = (e) => {
|
|
299
|
-
const r =
|
|
299
|
+
const r = g(), t = u((n) => n.login), a = u((n) => n.aplicacion.instancia);
|
|
300
300
|
return v(() => {
|
|
301
301
|
t.autenticado && t.expiracion && new Date(t.expiracion) < /* @__PURE__ */ new Date() && (t.refreshToken ? r(w(e, a.clientCredentials, t.refreshToken)) : r(sr()));
|
|
302
302
|
}, [e, a.clientCredentials, t, r]), t.autenticado;
|
|
303
303
|
}, Cr = () => {
|
|
304
|
-
const e =
|
|
304
|
+
const e = g();
|
|
305
305
|
return Ge((r, t = "default") => {
|
|
306
306
|
e(lr({ mensaje: r, tipo: t }));
|
|
307
307
|
}, [e]);
|
|
308
308
|
}, le = ({ devURL: e }) => {
|
|
309
|
-
const r =
|
|
309
|
+
const r = g(), t = j(), a = Cr(), { cargando: n, error: c } = u((l) => l.login), s = u((l) => l.aplicacion.instancia), D = (l) => {
|
|
310
310
|
r(T({
|
|
311
311
|
devURL: e,
|
|
312
312
|
clientCredentials: s.clientCredentials,
|
|
@@ -357,9 +357,9 @@ const ce = (e) => {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
),
|
|
360
|
-
/* @__PURE__ */ d(
|
|
361
|
-
/* @__PURE__ */ o(
|
|
362
|
-
/* @__PURE__ */ o(
|
|
360
|
+
/* @__PURE__ */ d(m, { container: !0, children: [
|
|
361
|
+
/* @__PURE__ */ o(m, { item: !0, xs: 6 }),
|
|
362
|
+
/* @__PURE__ */ o(m, { item: !0, xs: 6, align: "right", children: /* @__PURE__ */ o(
|
|
363
363
|
Ae,
|
|
364
364
|
{
|
|
365
365
|
variant: "contained",
|
|
@@ -406,13 +406,13 @@ const de = ({ devURL: e }) => {
|
|
|
406
406
|
justifyContent: "center",
|
|
407
407
|
alignItems: "center",
|
|
408
408
|
flexGrow: 1
|
|
409
|
-
}, children: /* @__PURE__ */ o(je, { maxWidth: "md", children: /* @__PURE__ */ d(
|
|
410
|
-
/* @__PURE__ */ d(
|
|
409
|
+
}, children: /* @__PURE__ */ o(je, { maxWidth: "md", children: /* @__PURE__ */ d(m, { container: !0, spacing: 3, children: [
|
|
410
|
+
/* @__PURE__ */ d(m, { item: !0, xs: 12, lg: 5, align: "center", children: [
|
|
411
411
|
/* @__PURE__ */ o("img", { src: r.logo, alt: r.nombre, style: { maxWidth: "100%" } }),
|
|
412
412
|
/* @__PURE__ */ o(A, { variant: "h3", align: "center", children: t("aplicacion.nombre", { smart_count: 1 }) }),
|
|
413
413
|
/* @__PURE__ */ o(A, { variant: "h5", align: "center", children: r.nombre })
|
|
414
414
|
] }),
|
|
415
|
-
/* @__PURE__ */ o(
|
|
415
|
+
/* @__PURE__ */ o(m, { item: !0, xs: 12, lg: 7, sx: {
|
|
416
416
|
display: "flex",
|
|
417
417
|
alignItems: "center",
|
|
418
418
|
justifyContent: "center",
|
|
@@ -469,7 +469,7 @@ const he = ({ devURL: e, children: r }) => {
|
|
|
469
469
|
backgroundColor: "background.default"
|
|
470
470
|
}, children: t.inicializando ? /* @__PURE__ */ o(er, {}) : t.error || !t.inicializado ? /* @__PURE__ */ o(rr, { titulo: "saas.inicializar.error.titulo", texto: "saas.inicializar.error.mensaje" }) : /* @__PURE__ */ d($e, { children: [
|
|
471
471
|
/* @__PURE__ */ o(pe, { devURL: e, requiereLogin: t.instancia.requiereLogin, children: r }),
|
|
472
|
-
/* @__PURE__ */ o(
|
|
472
|
+
/* @__PURE__ */ o(mr, {})
|
|
473
473
|
] }) });
|
|
474
474
|
};
|
|
475
475
|
he.propTypes = {
|
|
@@ -484,7 +484,7 @@ const fe = ({
|
|
|
484
484
|
idiomaDefecto: n,
|
|
485
485
|
children: c
|
|
486
486
|
}) => {
|
|
487
|
-
const s =
|
|
487
|
+
const s = g();
|
|
488
488
|
return v(() => {
|
|
489
489
|
s(S({ devURL: r, aplicacion: e }));
|
|
490
490
|
}, [s, e, r]), /* @__PURE__ */ o(ie, { messages: a, idiomaDefecto: n, children: /* @__PURE__ */ o(se, { children: /* @__PURE__ */ o(he, { devURL: t, children: c }) }) });
|
|
@@ -506,7 +506,7 @@ const $r = ({
|
|
|
506
506
|
idiomaDefecto: c,
|
|
507
507
|
messages: s,
|
|
508
508
|
children: D
|
|
509
|
-
}) => /* @__PURE__ */ o(Pe, { store:
|
|
509
|
+
}) => /* @__PURE__ */ o(Pe, { store: gr(e), children: /* @__PURE__ */ o(
|
|
510
510
|
fe,
|
|
511
511
|
{
|
|
512
512
|
aplicacion: r,
|
|
@@ -531,7 +531,7 @@ var x = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
531
531
|
function xr(e) {
|
|
532
532
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
533
533
|
}
|
|
534
|
-
var Tr = typeof x == "object" && x && x.Object === Object && x, wr = Tr, Sr = wr, jr = typeof self == "object" && self && self.Object === Object && self, Or = Sr || jr || Function("return this")(), F = Or, Rr = F, kr = Rr.Symbol,
|
|
534
|
+
var Tr = typeof x == "object" && x && x.Object === Object && x, wr = Tr, Sr = wr, jr = typeof self == "object" && self && self.Object === Object && self, Or = Sr || jr || Function("return this")(), F = Or, Rr = F, kr = Rr.Symbol, ge = kr, B = ge, me = Object.prototype, zr = me.hasOwnProperty, Dr = me.toString, C = B ? B.toStringTag : void 0;
|
|
535
535
|
function Ir(e) {
|
|
536
536
|
var r = zr.call(e, C), t = e[C];
|
|
537
537
|
try {
|
|
@@ -546,7 +546,7 @@ var Ar = Ir, Lr = Object.prototype, Pr = Lr.toString;
|
|
|
546
546
|
function Nr(e) {
|
|
547
547
|
return Pr.call(e);
|
|
548
548
|
}
|
|
549
|
-
var qr = Nr, V =
|
|
549
|
+
var qr = Nr, V = ge, Fr = Ar, Mr = qr, Gr = "[object Null]", Er = "[object Undefined]", K = V ? V.toStringTag : void 0;
|
|
550
550
|
function Hr(e) {
|
|
551
551
|
return e == null ? e === void 0 ? Er : Gr : K && K in Object(e) ? Fr(e) : Mr(e);
|
|
552
552
|
}
|
|
@@ -583,7 +583,7 @@ function st(e) {
|
|
|
583
583
|
}
|
|
584
584
|
return "";
|
|
585
585
|
}
|
|
586
|
-
var ct = st, lt = Yr, dt = nt, ut = ve, pt = ct, ht = /[\\^$.*+?()[\]{}|]/g, ft = /^\[object .+?Constructor\]$/,
|
|
586
|
+
var ct = st, lt = Yr, dt = nt, ut = ve, pt = ct, ht = /[\\^$.*+?()[\]{}|]/g, ft = /^\[object .+?Constructor\]$/, gt = Function.prototype, mt = Object.prototype, vt = gt.toString, yt = mt.hasOwnProperty, _t = RegExp(
|
|
587
587
|
"^" + vt.call(yt).replace(ht, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
588
588
|
);
|
|
589
589
|
function bt(e) {
|
|
@@ -671,15 +671,15 @@ function pa(e) {
|
|
|
671
671
|
return t < 0 ? void 0 : r[t][1];
|
|
672
672
|
}
|
|
673
673
|
var ha = pa, fa = k;
|
|
674
|
-
function
|
|
674
|
+
function ga(e) {
|
|
675
675
|
return fa(this.__data__, e) > -1;
|
|
676
676
|
}
|
|
677
|
-
var
|
|
677
|
+
var ma = ga, va = k;
|
|
678
678
|
function ya(e, r) {
|
|
679
679
|
var t = this.__data__, a = va(t, e);
|
|
680
680
|
return a < 0 ? (++this.size, t.push([e, r])) : t[a][1] = r, this;
|
|
681
681
|
}
|
|
682
|
-
var _a = ya, ba = ra, Ca = da, $a = ha, xa =
|
|
682
|
+
var _a = ya, ba = ra, Ca = da, $a = ha, xa = ma, Ta = _a;
|
|
683
683
|
function _(e) {
|
|
684
684
|
var r = -1, t = e == null ? 0 : e.length;
|
|
685
685
|
for (this.clear(); ++r < t; ) {
|
package/dist/react-saas.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,t){typeof exports=="object"&&typeof module<"u"?t(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"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o["react-saas"]={},o.ReactJSX,o.MuiMaterial,o.ReactPolyglot,o.PropTypes,o.ReactRedux,o.ReduxToolkit,o.Axios,o.JWTDecode,o.React,o.DateFNSLocale,o.MuiXDatePickers,o.MuiXDatePickersAdapter,o.NavigatorLanguages,o.MuiMaterialStyles,o.MuiMaterialColors,o.ReactRouterDom,o.MuiIconsMaterial,o.ReactFinalForm,o.MUIRFF))})(this,function(o,t,c,S,s,u,m,z,be,p,N,Se,$e,je,G,E,_,H,we,U){"use strict";const B=()=>t.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center"},children:t.jsx(c.CircularProgress,{})}),V=({titulo:e,texto:r,align:a="center",severity:n="error"})=>{const i=S.useTranslate();return t.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:a},children:t.jsxs(c.Alert,{severity:n,children:[t.jsx(c.AlertTitle,{children:i(e)}),r&&i(r)]})})};Error.propTypes={titulo:s.string.isRequired,texto:s.string,align:s.string,severity:s.string};const J=m.createSlice({name:"ui",initialState:{tema:"light",temaSeleccionado:!1,idioma:"es"},reducers:{cambiarTema:(e,r)=>{e.tema=r.payload,e.temaSeleccionado=!0,localStorage.setItem("tema",r.payload)},cambiarIdioma:(e,r)=>{e.idioma=r.payload}}}),{cambiarTema:xe,cambiarIdioma:Te}=J.actions,ke=J.reducer,Oe="https://saas.chimera.com.pe/backend",qe="https://saas.chimera.com.pe/oauth",K=(e=qe)=>({login:(r,a)=>z({url:`${e}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${r}`},method:"post",data:{username:a.correo,password:a.password,grant_type:"password"}}),refreshToken:(r,a)=>z({url:`${e}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${r}`},method:"post",data:{refresh_token:a,grant_type:"refresh_token"}})}),X=m.createSlice({name:"login",initialState:{cargando:!1,autenticado:!1,token:null,refreshToken:null,expiracion:null,usuario:null,perfiles:[],error:null},reducers:{logout:e=>{e.cargando=!1,e.autenticado=!1,e.token=null,e.refreshToken=null,e.expiracion=null,e.usuario=null,e.perfiles=[],e.error=null}},extraReducers(e){e.addCase(j.pending,r=>{r.cargando=!0,r.error=null}).addCase(j.fulfilled,(r,a)=>{const n=a.payload.access_token,i=be(n),d=new Date;d.setSeconds(d.getSeconds()+a.payload.expires_in),r.cargando=!1,r.autenticado=!0,r.token=n,r.refreshToken=a.payload.refresh_token,r.expiracion=d.getTime(),r.usuario=i.name,r.perfiles=i.authorities}).addCase(j.rejected,(r,a)=>{var n;console.log(a),r.cargando=!1,r.autenticado=!1,r.token=null,r.refreshToken=null,r.expiracion=null,r.usuario=null,r.perfiles=[],r.error=(n=a.error)==null?void 0:n.message}).addCase(w.pending,r=>{r.cargando=!0}).addCase(w.fulfilled,(r,a)=>{const n=new Date;n.setSeconds(n.getSeconds()+a.payload.expires_in),r.token=a.payload.access_token,r.refreshToken=a.payload.refresh_token,r.expiracion=n.getTime()}).addCase(w.rejected,(r,a)=>{var n;r.cargando=!1,r.autenticado=!1,r.token=null,r.refreshToken=null,r.expiracion=null,r.usuario=null,r.perfiles=[],r.error=(n=a.error)==null?void 0:n.message})}}),j=m.createAsyncThunk("login/requestToken",async e=>(await K(e.devURL).login(e.clientCredentials,e.data)).data),w=m.createAsyncThunk("login/refreshToken",async(e,r,a)=>(await K(e).refreshToken(r,a)).data),{logout:W}=X.actions,ze=e=>e.token,De=e=>e.usuario,Ae=e=>e.perfiles,Ie=X.reducer,Z=m.createSlice({name:"notificacion",initialState:[],reducers:{mostrarNotificacion:(e,r)=>{e.push(r.payload)},ocultarNotificacion:e=>{e.pop()}}}),{mostrarNotificacion:Le,ocultarNotificacion:Me}=Z.actions,Fe=Z.reducer,Ne=(e=Oe,r)=>z({url:`${e}/identidad/`,params:{codigoAplicacion:r}}),D={primary:"#1C6CCC",secondary:"#17A7FF",error:"#f44336",warning:"#ff9800",info:"#2196f3",success:"#4caf50"},Ge=m.createSlice({name:"inicializar",initialState:{inicializando:!0,inicializado:!1,instancia:{color:D},error:null},extraReducers(e){e.addCase(x.pending,r=>{r.inicializando=!0}).addCase(x.fulfilled,(r,a)=>{r.inicializando=!1,r.inicializado=!0,r.instancia={...a.payload,abreviatura:a.payload.nombre.match(/\b([A-Z])/g).join(""),color:{...D,...a.payload.color}},r.error=null}).addCase(x.rejected,(r,a)=>{r.inicializando=!1,r.inicializado=!1,r.instancia={color:D},r.error=a.payload})}}),x=m.createAsyncThunk("inicializar",async e=>(await Ne(e.devURL,e.aplicacion)).data),Ee=e=>e.instancia,He=Ge.reducer,Ue=e=>m.configureStore({reducer:{ui:ke,aplicacion:He,login:Ie,notificaciones:Fe,...e}}),Be=()=>{const[e,r]=p.useState(!1),a=u.useDispatch(),n=S.useTranslate(),i=u.useSelector(l=>l.notificaciones[0]);p.useEffect(()=>{r(!!i)},[i]);const d=()=>{r(!1),a(Me())};return t.jsx(c.Snackbar,{open:e,message:(i==null?void 0:i.mensaje)&&i.tipo==="default"&&n(i.mensaje),autoHideDuration:5e3,onClose:d,children:(i==null?void 0:i.mensaje)&&i.tipo!=="default"&&t.jsx(c.Alert,{severity:i.tipo,children:n(i.mensaje)})})},Ve={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 "}},Je={en:N.enGB,es:N.es},Q=({messages:e,children:r})=>{const a=u.useSelector(n=>n.ui.idioma);return t.jsx(S.I18n,{locale:a,messages:e[a],children:t.jsx(Se.LocalizationProvider,{dateAdapter:$e.AdapterDateFns,adapterLocale:Je[a],children:r})})};Q.propTypes={messages:s.object,children:s.element.isRequired};const Ke=()=>{const e=je();if(!(e!=null&&e.length))return;const r=e[0];return r.indexOf("-")?r.substring(0,r.indexOf("-")):r},Y=({messages:e,idiomaDefecto:r,children:a})=>{const n=u.useDispatch(),i=Ke();p.useEffect(()=>{let l=Reflect.ownKeys(e)[0];i&&Object.hasOwn(e,i)?l=i:r&&Object.hasOwn(e,r)&&(l=r),n(Te(l))},[n,e,r,i]);const d={};return Object.keys(e).forEach(l=>{d[l]={...e[l],saas:Ve[l]}}),t.jsx(Q,{messages:d,children:a})};Y.propTypes={messages:s.object,idiomaDefecto:s.string,children:s.element.isRequired};const P=({children:e})=>{const r=u.useDispatch(),{instancia:a}=u.useSelector(l=>l.aplicacion),n=u.useSelector(l=>l.ui.tema),i=c.useMediaQuery("(prefers-color-scheme: dark)");p.useEffect(()=>{r(xe(i?"dark":"light"))},[r,i]);const d=p.useMemo(()=>G.createTheme({palette:{mode:n,primary:{main:a.color.primary},secondary:{main:a.color.secondary},error:{main:a.color.error},warning:{main:a.color.warning},info:{main:a.color.info},success:{main:a.color.success},...n==="light"&&{background:{default:E.grey.A200,paper:E.grey[100]}}},shape:{borderRadius:6}}),[n,a]);return t.jsxs(G.ThemeProvider,{theme:d,children:[t.jsx(c.CssBaseline,{}),e]})};P.propTypes={children:s.element.isRequired};const R=e=>{const r=u.useDispatch(),a=u.useSelector(i=>i.login),n=u.useSelector(i=>i.aplicacion.instancia);return p.useEffect(()=>{a.autenticado&&a.expiracion&&new Date(a.expiracion)<new Date&&(a.refreshToken?r(w(e,n.clientCredentials,a.refreshToken)):r(W()))},[e,n.clientCredentials,a,r]),a.autenticado},ee=()=>{const e=u.useDispatch();return p.useCallback((r,a="default")=>{e(Le({mensaje:r,tipo:a}))},[e])},re=({devURL:e})=>{const r=u.useDispatch(),a=S.useTranslate(),n=ee(),{cargando:i,error:d}=u.useSelector(h=>h.login),l=u.useSelector(h=>h.aplicacion.instancia),M=h=>{r(j({devURL:e,clientCredentials:l.clientCredentials,data:{correo:h.correo,password:h.password}}))},En=h=>{const F={correo:void 0,password:void 0};return h.correo||(F.correo=a("saas.login.validacion.correo")),h.password||(F.password=a("saas.login.validacion.password")),F};return p.useEffect(()=>{d&&n("saas.login.error","error")},[n,d]),t.jsx(we.Form,{onSubmit:M,validate:En,render:({handleSubmit:h})=>t.jsxs("form",{onSubmit:h,children:[t.jsx(U.TextField,{id:"correo",name:"correo",label:a("saas.login.correo"),variant:"outlined",autoComplete:"off",disabled:i,autoFocus:!0,InputProps:{startAdornment:t.jsx(c.InputAdornment,{position:"start",children:t.jsx(H.Email,{color:"primary"})})}}),t.jsx(U.TextField,{id:"password",name:"password",type:"password",label:a("saas.login.password"),variant:"outlined",autoComplete:"current-password",disabled:i,InputProps:{startAdornment:t.jsx(c.InputAdornment,{position:"start",children:t.jsx(H.Lock,{color:"primary"})})}}),t.jsxs(c.Grid,{container:!0,children:[t.jsx(c.Grid,{item:!0,xs:6}),t.jsx(c.Grid,{item:!0,xs:6,align:"right",children:t.jsx(c.Button,{variant:"contained",color:"primary",type:"submit",disabled:i,children:i?t.jsx(c.CircularProgress,{size:24,thickness:4}):a("saas.login.ingresar")})})]})]})})};re.propTypes={devURL:s.string};const ae=({devURL:e})=>{const r=u.useSelector(l=>l.aplicacion.instancia),a=S.useTranslate(),n=_.useLocation(),i=R(e),{from:d}=n.state||{from:{pathname:"/"}};return!r.requiereLogin||i?t.jsx(_.Navigate,{to:d}):t.jsxs(c.Box,{sx:{position:"relative",display:"flex",flexDirection:"column",flexGrow:1,minHeight:"100vh",backgroundColor:"primary.main","&::before":{content:'""',backgroundImage:`url(${r.logo})`,backgroundSize:"contain",backgroundRepeat:"no-repeat",backgroundPosition:"right",position:"absolute",top:"20%",bottom:0,right:0,width:"50%",opacity:.02,filter:"grayscale(100%)"}},children:[t.jsx(c.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",flexGrow:1},children:t.jsx(c.Container,{maxWidth:"md",children:t.jsxs(c.Grid,{container:!0,spacing:3,children:[t.jsxs(c.Grid,{item:!0,xs:12,lg:5,align:"center",children:[t.jsx("img",{src:r.logo,alt:r.nombre,style:{maxWidth:"100%"}}),t.jsx(c.Typography,{variant:"h3",align:"center",children:a("aplicacion.nombre",{smart_count:1})}),t.jsx(c.Typography,{variant:"h5",align:"center",children:r.nombre})]}),t.jsx(c.Grid,{item:!0,xs:12,lg:7,sx:{display:"flex",alignItems:"center",justifyContent:"center",zIndex:5},children:t.jsxs(c.Card,{elevation:5,children:[t.jsx(c.CardHeader,{title:a("saas.login.titulo"),titleTypographyProps:{align:"center"}}),t.jsx(c.CardContent,{sx:{"& .MuiTextField-root":{mb:2}},children:t.jsx(re,{devURL:e})})]})})]})})}),t.jsx(c.AppBar,{position:"static",color:"primary",children:t.jsx(c.Toolbar,{sx:{justifyContent:"center"},children:t.jsxs(c.Typography,{variant:"caption",children:[a("saas.copy"),t.jsx(c.Link,{href:"//chimera.com.pe",color:"inherit",target:"_blank",rel:"noreferrer",children:"Chimera Software"})]})})})]})};ae.propTypes={devURL:s.string};const ne=({devURL:e,redirectTo:r,children:a})=>{const n=_.useLocation();return R(e)?a:t.jsx(_.Navigate,{to:r,state:{from:n},replace:!0})};ne.propTypes={devURL:s.string,redirectTo:s.string.isRequired,children:s.element.isRequired};const te=({devURL:e,requiereLogin:r,children:a})=>t.jsx(_.BrowserRouter,{children:t.jsxs(_.Routes,{children:[t.jsx(_.Route,{path:"/login",element:t.jsx(ae,{devURL:e})}),t.jsx(_.Route,{path:"/*",element:r?t.jsx(ne,{devURL:e,redirectTo:"/login",children:a}):a})]})});te.propTypes={devURL:s.string,requiereLogin:s.bool,children:s.element.isRequired};const ie=({devURL:e,children:r})=>{const a=u.useSelector(n=>n.aplicacion);return t.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh",justifyContent:"flex-start",backgroundColor:"background.default"},children:a.inicializando?t.jsx(B,{}):a.error||!a.inicializado?t.jsx(V,{titulo:"saas.inicializar.error.titulo",texto:"saas.inicializar.error.mensaje"}):t.jsxs(t.Fragment,{children:[t.jsx(te,{devURL:e,requiereLogin:a.instancia.requiereLogin,children:r}),t.jsx(Be,{})]})})};ie.propTypes={devURL:s.string,children:s.element.isRequired};const oe=({aplicacion:e,devSaasURL:r,devAuthURL:a,messages:n,idiomaDefecto:i,children:d})=>{const l=u.useDispatch();return p.useEffect(()=>{l(x({devURL:r,aplicacion:e}))},[l,e,r]),t.jsx(Y,{messages:n,idiomaDefecto:i,children:t.jsx(P,{children:t.jsx(ie,{devURL:a,children:d})})})};oe.propTypes={aplicacion:s.string.isRequired,devSaasURL:s.string,devAuthURL:s.string,messages:s.object.isRequired,idiomaDefecto:s.string,children:s.element.isRequired};const se=({customReducers:e,aplicacion:r,devSaasURL:a,devAuthURL:n,dev:i=!1,idiomaDefecto:d,messages:l,children:M})=>t.jsx(u.Provider,{store:Ue(e),children:t.jsx(oe,{aplicacion:r,devSaasURL:i?a:void 0,devAuthURL:i?n:void 0,idiomaDefecto:d,messages:l,children:M})});se.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};var T=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Xe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var We=typeof T=="object"&&T&&T.Object===Object&&T,Ze=We,Qe=Ze,Ye=typeof self=="object"&&self&&self.Object===Object&&self,Pe=Qe||Ye||Function("return this")(),A=Pe,Re=A,er=Re.Symbol,ce=er,le=ce,de=Object.prototype,rr=de.hasOwnProperty,ar=de.toString,$=le?le.toStringTag:void 0;function nr(e){var r=rr.call(e,$),a=e[$];try{e[$]=void 0;var n=!0}catch{}var i=ar.call(e);return n&&(r?e[$]=a:delete e[$]),i}var tr=nr,ir=Object.prototype,or=ir.toString;function sr(e){return or.call(e)}var cr=sr,ue=ce,lr=tr,dr=cr,ur="[object Null]",hr="[object Undefined]",he=ue?ue.toStringTag:void 0;function fr(e){return e==null?e===void 0?hr:ur:he&&he in Object(e)?lr(e):dr(e)}var pr=fr;function gr(e){var r=typeof e;return e!=null&&(r=="object"||r=="function")}var fe=gr,vr=pr,mr=fe,_r="[object AsyncFunction]",yr="[object Function]",Cr="[object GeneratorFunction]",br="[object Proxy]";function Sr(e){if(!mr(e))return!1;var r=vr(e);return r==yr||r==Cr||r==_r||r==br}var $r=Sr,jr=A,wr=jr["__core-js_shared__"],xr=wr,I=xr,pe=function(){var e=/[^.]+$/.exec(I&&I.keys&&I.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Tr(e){return!!pe&&pe in e}var kr=Tr,Or=Function.prototype,qr=Or.toString;function zr(e){if(e!=null){try{return qr.call(e)}catch{}try{return e+""}catch{}}return""}var Dr=zr,Ar=$r,Ir=kr,Lr=fe,Mr=Dr,Fr=/[\\^$.*+?()[\]{}|]/g,Nr=/^\[object .+?Constructor\]$/,Gr=Function.prototype,Er=Object.prototype,Hr=Gr.toString,Ur=Er.hasOwnProperty,Br=RegExp("^"+Hr.call(Ur).replace(Fr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Vr(e){if(!Lr(e)||Ir(e))return!1;var r=Ar(e)?Br:Nr;return r.test(Mr(e))}var Jr=Vr;function Kr(e,r){return e==null?void 0:e[r]}var Xr=Kr,Wr=Jr,Zr=Xr;function Qr(e,r){var a=Zr(e,r);return Wr(a)?a:void 0}var ge=Qr,Yr=ge,Pr=Yr(Object,"create"),k=Pr,ve=k;function Rr(){this.__data__=ve?ve(null):{},this.size=0}var ea=Rr;function ra(e){var r=this.has(e)&&delete this.__data__[e];return this.size-=r?1:0,r}var aa=ra,na=k,ta="__lodash_hash_undefined__",ia=Object.prototype,oa=ia.hasOwnProperty;function sa(e){var r=this.__data__;if(na){var a=r[e];return a===ta?void 0:a}return oa.call(r,e)?r[e]:void 0}var ca=sa,la=k,da=Object.prototype,ua=da.hasOwnProperty;function ha(e){var r=this.__data__;return la?r[e]!==void 0:ua.call(r,e)}var fa=ha,pa=k,ga="__lodash_hash_undefined__";function va(e,r){var a=this.__data__;return this.size+=this.has(e)?0:1,a[e]=pa&&r===void 0?ga:r,this}var ma=va,_a=ea,ya=aa,Ca=ca,ba=fa,Sa=ma;function y(e){var r=-1,a=e==null?0:e.length;for(this.clear();++r<a;){var n=e[r];this.set(n[0],n[1])}}y.prototype.clear=_a,y.prototype.delete=ya,y.prototype.get=Ca,y.prototype.has=ba,y.prototype.set=Sa;var $a=y;function ja(){this.__data__=[],this.size=0}var wa=ja;function xa(e,r){return e===r||e!==e&&r!==r}var Ta=xa,ka=Ta;function Oa(e,r){for(var a=e.length;a--;)if(ka(e[a][0],r))return a;return-1}var O=Oa,qa=O,za=Array.prototype,Da=za.splice;function Aa(e){var r=this.__data__,a=qa(r,e);if(a<0)return!1;var n=r.length-1;return a==n?r.pop():Da.call(r,a,1),--this.size,!0}var Ia=Aa,La=O;function Ma(e){var r=this.__data__,a=La(r,e);return a<0?void 0:r[a][1]}var Fa=Ma,Na=O;function Ga(e){return Na(this.__data__,e)>-1}var Ea=Ga,Ha=O;function Ua(e,r){var a=this.__data__,n=Ha(a,e);return n<0?(++this.size,a.push([e,r])):a[n][1]=r,this}var Ba=Ua,Va=wa,Ja=Ia,Ka=Fa,Xa=Ea,Wa=Ba;function C(e){var r=-1,a=e==null?0:e.length;for(this.clear();++r<a;){var n=e[r];this.set(n[0],n[1])}}C.prototype.clear=Va,C.prototype.delete=Ja,C.prototype.get=Ka,C.prototype.has=Xa,C.prototype.set=Wa;var Za=C,Qa=ge,Ya=A,Pa=Qa(Ya,"Map"),Ra=Pa,me=$a,en=Za,rn=Ra;function an(){this.size=0,this.__data__={hash:new me,map:new(rn||en),string:new me}}var nn=an;function tn(e){var r=typeof e;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?e!=="__proto__":e===null}var on=tn,sn=on;function cn(e,r){var a=e.__data__;return sn(r)?a[typeof r=="string"?"string":"hash"]:a.map}var q=cn,ln=q;function dn(e){var r=ln(this,e).delete(e);return this.size-=r?1:0,r}var un=dn,hn=q;function fn(e){return hn(this,e).get(e)}var pn=fn,gn=q;function vn(e){return gn(this,e).has(e)}var mn=vn,_n=q;function yn(e,r){var a=_n(this,e),n=a.size;return a.set(e,r),this.size+=a.size==n?0:1,this}var Cn=yn,bn=nn,Sn=un,$n=pn,jn=mn,wn=Cn;function b(e){var r=-1,a=e==null?0:e.length;for(this.clear();++r<a;){var n=e[r];this.set(n[0],n[1])}}b.prototype.clear=bn,b.prototype.delete=Sn,b.prototype.get=$n,b.prototype.has=jn,b.prototype.set=wn;var xn=b,_e=xn,Tn="Expected a function";function L(e,r){if(typeof e!="function"||r!=null&&typeof r!="function")throw new TypeError(Tn);var a=function(){var n=arguments,i=r?r.apply(this,n):n[0],d=a.cache;if(d.has(i))return d.get(i);var l=e.apply(this,n);return a.cache=d.set(i,l)||d,l};return a.cache=new(L.Cache||_e),a}L.Cache=_e;var kn=L;const ye=Xe(kn),On=/^(([^<>()[\]\\.,;:\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,}))$/,g=e=>typeof e>"u"||e===null||e===""||Array.isArray(e)&&e.length===0,f=(e,r,a,n)=>typeof e=="function"?e({args:r,value:a,values:n}):r?{message:e,args:r}:e,v=e=>ye(e,(...r)=>JSON.stringify(r)),qn=(...e)=>(r,a,n)=>(Array.isArray(e[0])?e[0]:e).reduce((d,l)=>d||typeof l=="function"&&l(r,a,n),void 0),zn=v((e="validacion.obligatorio")=>Object.assign((r,a)=>g(r)?f(e,void 0,r,a):void 0,{isRequired:!0})),Dn=v((e="validacion.obligatorio")=>Object.assign((r,a)=>g(r)||!r?f(e,void 0,r,a):void 0,{isRequired:!0})),An=v((e="validacion.numero")=>(r,a)=>!g(r)&&isNaN(r)?f(e,void 0,r,a):void 0),In=v((e,r="validacion.longitud.minima")=>(a,n)=>!g(a)&&a.length<e?f(r,void 0,a,n):void 0),Ln=v((e,r="validacion.longitud.maxima")=>(a,n)=>!g(a)&&a.length>e?f(r,void 0,a,n):void 0),Mn=v((e,r="validacion.minimo")=>(a,n)=>!g(a)&&parseFloat(a)<e?f(r,void 0,a,n):void 0),Fn=v((e,r="validacion.maximo")=>(a,n)=>!g(a)&&parseFloat(a)>e?f(r,void 0,a,n):void 0),Ce=ye((e,r="validacion.regex")=>(a,n)=>!g(a)&&typeof a=="string"&&!e.test(a)?f(r,void 0,a,n):void 0,(e,r)=>e.toString()+r),Nn=v((e="validacion.correo")=>Ce(On,e)),Gn=v((e,r,a="validacion.remote")=>(n,i,d)=>d.active&&!g(n)&&e(n,r).then(l=>l?f(a,void 0,n,i):void 0).catch(l=>f(l.message,void 0,n,i)));o.Cargando=B,o.Error=V,o.SaasApp=se,o.composeValidators=qn,o.email=Nn,o.getInstancia=Ee,o.getPerfiles=Ae,o.getToken=ze,o.getUsuario=De,o.logout=W,o.max=Fn,o.maxLength=Ln,o.min=Mn,o.minLength=In,o.number=An,o.regex=Ce,o.remote=Gn,o.required=zn,o.requiredNotFalse=Dn,o.useNotificar=ee,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(o,t){typeof exports=="object"&&typeof module<"u"?t(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"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o["react-saas"]={},o.ReactJSX,o.MuiMaterial,o.ReactPolyglot,o.PropTypes,o.ReactRedux,o.ReduxToolkit,o.Axios,o.JWTDecode,o.React,o.DateFNSLocale,o.MuiXDatePickers,o.MuiXDatePickersAdapter,o.NavigatorLanguages,o.MuiMaterialStyles,o.MuiMaterialColors,o.ReactRouterDom,o.MuiIconsMaterial,o.ReactFinalForm,o.MUIRFF))})(this,function(o,t,c,S,s,u,m,z,be,p,N,Se,$e,je,G,E,_,H,we,U){"use strict";const B=()=>t.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center"},children:t.jsx(c.CircularProgress,{})}),V=({titulo:e,texto:r,align:a="center",severity:n="error"})=>{const i=S.useTranslate();return t.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:a},children:t.jsxs(c.Alert,{severity:n,children:[t.jsx(c.AlertTitle,{children:i(e)}),r&&i(r)]})})};Error.propTypes={titulo:s.string.isRequired,texto:s.string,align:s.string,severity:s.string};const J=m.createSlice({name:"ui",initialState:{tema:"light",temaSeleccionado:!1,idioma:"es"},reducers:{cambiarTema:(e,r)=>{e.tema=r.payload,e.temaSeleccionado=!0,localStorage.setItem("tema",r.payload)},cambiarIdioma:(e,r)=>{e.idioma=r.payload}}}),{cambiarTema:xe,cambiarIdioma:Te}=J.actions,ke=J.reducer,Oe="https://saas.chimera.com.pe/backend",qe="https://saas.chimera.com.pe/oauth",K=(e=qe)=>({login:(r,a)=>z({url:`${e}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${r}`},method:"post",data:{username:a.correo,password:a.password,grant_type:"password"}}),refreshToken:(r,a)=>z({url:`${e}/oauth/token`,headers:{"content-type":"application/x-www-form-urlencoded",Authorization:`Basic ${r}`},method:"post",data:{refresh_token:a,grant_type:"refresh_token"}})}),X=m.createSlice({name:"login",initialState:{cargando:!1,autenticado:!1,token:null,refreshToken:null,expiracion:null,usuario:null,perfiles:[],error:null},reducers:{logout:e=>{e.cargando=!1,e.autenticado=!1,e.token=null,e.refreshToken=null,e.expiracion=null,e.usuario=null,e.perfiles=[],e.error=null}},extraReducers(e){e.addCase(j.pending,r=>{r.cargando=!0,r.error=null}).addCase(j.fulfilled,(r,a)=>{const n=a.payload.access_token,i=be(n),d=new Date;d.setSeconds(d.getSeconds()+a.payload.expires_in),r.cargando=!1,r.autenticado=!0,r.token=n,r.refreshToken=a.payload.refresh_token,r.expiracion=d.getTime(),r.usuario=i.name,r.perfiles=i.authorities}).addCase(j.rejected,(r,a)=>{var n;console.log(a),r.cargando=!1,r.autenticado=!1,r.token=null,r.refreshToken=null,r.expiracion=null,r.usuario=null,r.perfiles=[],r.error=(n=a.error)==null?void 0:n.message}).addCase(w.pending,r=>{r.cargando=!0}).addCase(w.fulfilled,(r,a)=>{const n=new Date;n.setSeconds(n.getSeconds()+a.payload.expires_in),r.token=a.payload.access_token,r.refreshToken=a.payload.refresh_token,r.expiracion=n.getTime()}).addCase(w.rejected,(r,a)=>{var n;r.cargando=!1,r.autenticado=!1,r.token=null,r.refreshToken=null,r.expiracion=null,r.usuario=null,r.perfiles=[],r.error=(n=a.error)==null?void 0:n.message})}}),j=m.createAsyncThunk("login/requestToken",async e=>(await K(e.devURL).login(e.clientCredentials,e.data)).data),w=m.createAsyncThunk("login/refreshToken",async(e,r,a)=>(await K(e).refreshToken(r,a)).data),{logout:W}=X.actions,ze=e=>e.login.token,De=e=>e.login.usuario,Ae=e=>e.login.perfiles,Ie=X.reducer,Z=m.createSlice({name:"notificacion",initialState:[],reducers:{mostrarNotificacion:(e,r)=>{e.push(r.payload)},ocultarNotificacion:e=>{e.pop()}}}),{mostrarNotificacion:Le,ocultarNotificacion:Me}=Z.actions,Fe=Z.reducer,Ne=(e=Oe,r)=>z({url:`${e}/identidad/`,params:{codigoAplicacion:r}}),D={primary:"#1C6CCC",secondary:"#17A7FF",error:"#f44336",warning:"#ff9800",info:"#2196f3",success:"#4caf50"},Ge=m.createSlice({name:"inicializar",initialState:{inicializando:!0,inicializado:!1,instancia:{color:D},error:null},extraReducers(e){e.addCase(x.pending,r=>{r.inicializando=!0}).addCase(x.fulfilled,(r,a)=>{r.inicializando=!1,r.inicializado=!0,r.instancia={...a.payload,abreviatura:a.payload.nombre.match(/\b([A-Z])/g).join(""),color:{...D,...a.payload.color}},r.error=null}).addCase(x.rejected,(r,a)=>{r.inicializando=!1,r.inicializado=!1,r.instancia={color:D},r.error=a.payload})}}),x=m.createAsyncThunk("inicializar",async e=>(await Ne(e.devURL,e.aplicacion)).data),Ee=e=>e.aplicacion.instancia,He=Ge.reducer,Ue=e=>m.configureStore({reducer:{ui:ke,aplicacion:He,login:Ie,notificaciones:Fe,...e}}),Be=()=>{const[e,r]=p.useState(!1),a=u.useDispatch(),n=S.useTranslate(),i=u.useSelector(l=>l.notificaciones[0]);p.useEffect(()=>{r(!!i)},[i]);const d=()=>{r(!1),a(Me())};return t.jsx(c.Snackbar,{open:e,message:(i==null?void 0:i.mensaje)&&i.tipo==="default"&&n(i.mensaje),autoHideDuration:5e3,onClose:d,children:(i==null?void 0:i.mensaje)&&i.tipo!=="default"&&t.jsx(c.Alert,{severity:i.tipo,children:n(i.mensaje)})})},Ve={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 "}},Je={en:N.enGB,es:N.es},Q=({messages:e,children:r})=>{const a=u.useSelector(n=>n.ui.idioma);return t.jsx(S.I18n,{locale:a,messages:e[a],children:t.jsx(Se.LocalizationProvider,{dateAdapter:$e.AdapterDateFns,adapterLocale:Je[a],children:r})})};Q.propTypes={messages:s.object,children:s.element.isRequired};const Ke=()=>{const e=je();if(!(e!=null&&e.length))return;const r=e[0];return r.indexOf("-")?r.substring(0,r.indexOf("-")):r},Y=({messages:e,idiomaDefecto:r,children:a})=>{const n=u.useDispatch(),i=Ke();p.useEffect(()=>{let l=Reflect.ownKeys(e)[0];i&&Object.hasOwn(e,i)?l=i:r&&Object.hasOwn(e,r)&&(l=r),n(Te(l))},[n,e,r,i]);const d={};return Object.keys(e).forEach(l=>{d[l]={...e[l],saas:Ve[l]}}),t.jsx(Q,{messages:d,children:a})};Y.propTypes={messages:s.object,idiomaDefecto:s.string,children:s.element.isRequired};const P=({children:e})=>{const r=u.useDispatch(),{instancia:a}=u.useSelector(l=>l.aplicacion),n=u.useSelector(l=>l.ui.tema),i=c.useMediaQuery("(prefers-color-scheme: dark)");p.useEffect(()=>{r(xe(i?"dark":"light"))},[r,i]);const d=p.useMemo(()=>G.createTheme({palette:{mode:n,primary:{main:a.color.primary},secondary:{main:a.color.secondary},error:{main:a.color.error},warning:{main:a.color.warning},info:{main:a.color.info},success:{main:a.color.success},...n==="light"&&{background:{default:E.grey.A200,paper:E.grey[100]}}},shape:{borderRadius:6}}),[n,a]);return t.jsxs(G.ThemeProvider,{theme:d,children:[t.jsx(c.CssBaseline,{}),e]})};P.propTypes={children:s.element.isRequired};const R=e=>{const r=u.useDispatch(),a=u.useSelector(i=>i.login),n=u.useSelector(i=>i.aplicacion.instancia);return p.useEffect(()=>{a.autenticado&&a.expiracion&&new Date(a.expiracion)<new Date&&(a.refreshToken?r(w(e,n.clientCredentials,a.refreshToken)):r(W()))},[e,n.clientCredentials,a,r]),a.autenticado},ee=()=>{const e=u.useDispatch();return p.useCallback((r,a="default")=>{e(Le({mensaje:r,tipo:a}))},[e])},re=({devURL:e})=>{const r=u.useDispatch(),a=S.useTranslate(),n=ee(),{cargando:i,error:d}=u.useSelector(h=>h.login),l=u.useSelector(h=>h.aplicacion.instancia),M=h=>{r(j({devURL:e,clientCredentials:l.clientCredentials,data:{correo:h.correo,password:h.password}}))},En=h=>{const F={correo:void 0,password:void 0};return h.correo||(F.correo=a("saas.login.validacion.correo")),h.password||(F.password=a("saas.login.validacion.password")),F};return p.useEffect(()=>{d&&n("saas.login.error","error")},[n,d]),t.jsx(we.Form,{onSubmit:M,validate:En,render:({handleSubmit:h})=>t.jsxs("form",{onSubmit:h,children:[t.jsx(U.TextField,{id:"correo",name:"correo",label:a("saas.login.correo"),variant:"outlined",autoComplete:"off",disabled:i,autoFocus:!0,InputProps:{startAdornment:t.jsx(c.InputAdornment,{position:"start",children:t.jsx(H.Email,{color:"primary"})})}}),t.jsx(U.TextField,{id:"password",name:"password",type:"password",label:a("saas.login.password"),variant:"outlined",autoComplete:"current-password",disabled:i,InputProps:{startAdornment:t.jsx(c.InputAdornment,{position:"start",children:t.jsx(H.Lock,{color:"primary"})})}}),t.jsxs(c.Grid,{container:!0,children:[t.jsx(c.Grid,{item:!0,xs:6}),t.jsx(c.Grid,{item:!0,xs:6,align:"right",children:t.jsx(c.Button,{variant:"contained",color:"primary",type:"submit",disabled:i,children:i?t.jsx(c.CircularProgress,{size:24,thickness:4}):a("saas.login.ingresar")})})]})]})})};re.propTypes={devURL:s.string};const ae=({devURL:e})=>{const r=u.useSelector(l=>l.aplicacion.instancia),a=S.useTranslate(),n=_.useLocation(),i=R(e),{from:d}=n.state||{from:{pathname:"/"}};return!r.requiereLogin||i?t.jsx(_.Navigate,{to:d}):t.jsxs(c.Box,{sx:{position:"relative",display:"flex",flexDirection:"column",flexGrow:1,minHeight:"100vh",backgroundColor:"primary.main","&::before":{content:'""',backgroundImage:`url(${r.logo})`,backgroundSize:"contain",backgroundRepeat:"no-repeat",backgroundPosition:"right",position:"absolute",top:"20%",bottom:0,right:0,width:"50%",opacity:.02,filter:"grayscale(100%)"}},children:[t.jsx(c.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",flexGrow:1},children:t.jsx(c.Container,{maxWidth:"md",children:t.jsxs(c.Grid,{container:!0,spacing:3,children:[t.jsxs(c.Grid,{item:!0,xs:12,lg:5,align:"center",children:[t.jsx("img",{src:r.logo,alt:r.nombre,style:{maxWidth:"100%"}}),t.jsx(c.Typography,{variant:"h3",align:"center",children:a("aplicacion.nombre",{smart_count:1})}),t.jsx(c.Typography,{variant:"h5",align:"center",children:r.nombre})]}),t.jsx(c.Grid,{item:!0,xs:12,lg:7,sx:{display:"flex",alignItems:"center",justifyContent:"center",zIndex:5},children:t.jsxs(c.Card,{elevation:5,children:[t.jsx(c.CardHeader,{title:a("saas.login.titulo"),titleTypographyProps:{align:"center"}}),t.jsx(c.CardContent,{sx:{"& .MuiTextField-root":{mb:2}},children:t.jsx(re,{devURL:e})})]})})]})})}),t.jsx(c.AppBar,{position:"static",color:"primary",children:t.jsx(c.Toolbar,{sx:{justifyContent:"center"},children:t.jsxs(c.Typography,{variant:"caption",children:[a("saas.copy"),t.jsx(c.Link,{href:"//chimera.com.pe",color:"inherit",target:"_blank",rel:"noreferrer",children:"Chimera Software"})]})})})]})};ae.propTypes={devURL:s.string};const ne=({devURL:e,redirectTo:r,children:a})=>{const n=_.useLocation();return R(e)?a:t.jsx(_.Navigate,{to:r,state:{from:n},replace:!0})};ne.propTypes={devURL:s.string,redirectTo:s.string.isRequired,children:s.element.isRequired};const te=({devURL:e,requiereLogin:r,children:a})=>t.jsx(_.BrowserRouter,{children:t.jsxs(_.Routes,{children:[t.jsx(_.Route,{path:"/login",element:t.jsx(ae,{devURL:e})}),t.jsx(_.Route,{path:"/*",element:r?t.jsx(ne,{devURL:e,redirectTo:"/login",children:a}):a})]})});te.propTypes={devURL:s.string,requiereLogin:s.bool,children:s.element.isRequired};const ie=({devURL:e,children:r})=>{const a=u.useSelector(n=>n.aplicacion);return t.jsx(c.Box,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh",justifyContent:"flex-start",backgroundColor:"background.default"},children:a.inicializando?t.jsx(B,{}):a.error||!a.inicializado?t.jsx(V,{titulo:"saas.inicializar.error.titulo",texto:"saas.inicializar.error.mensaje"}):t.jsxs(t.Fragment,{children:[t.jsx(te,{devURL:e,requiereLogin:a.instancia.requiereLogin,children:r}),t.jsx(Be,{})]})})};ie.propTypes={devURL:s.string,children:s.element.isRequired};const oe=({aplicacion:e,devSaasURL:r,devAuthURL:a,messages:n,idiomaDefecto:i,children:d})=>{const l=u.useDispatch();return p.useEffect(()=>{l(x({devURL:r,aplicacion:e}))},[l,e,r]),t.jsx(Y,{messages:n,idiomaDefecto:i,children:t.jsx(P,{children:t.jsx(ie,{devURL:a,children:d})})})};oe.propTypes={aplicacion:s.string.isRequired,devSaasURL:s.string,devAuthURL:s.string,messages:s.object.isRequired,idiomaDefecto:s.string,children:s.element.isRequired};const se=({customReducers:e,aplicacion:r,devSaasURL:a,devAuthURL:n,dev:i=!1,idiomaDefecto:d,messages:l,children:M})=>t.jsx(u.Provider,{store:Ue(e),children:t.jsx(oe,{aplicacion:r,devSaasURL:i?a:void 0,devAuthURL:i?n:void 0,idiomaDefecto:d,messages:l,children:M})});se.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};var T=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Xe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var We=typeof T=="object"&&T&&T.Object===Object&&T,Ze=We,Qe=Ze,Ye=typeof self=="object"&&self&&self.Object===Object&&self,Pe=Qe||Ye||Function("return this")(),A=Pe,Re=A,er=Re.Symbol,ce=er,le=ce,de=Object.prototype,rr=de.hasOwnProperty,ar=de.toString,$=le?le.toStringTag:void 0;function nr(e){var r=rr.call(e,$),a=e[$];try{e[$]=void 0;var n=!0}catch{}var i=ar.call(e);return n&&(r?e[$]=a:delete e[$]),i}var tr=nr,ir=Object.prototype,or=ir.toString;function sr(e){return or.call(e)}var cr=sr,ue=ce,lr=tr,dr=cr,ur="[object Null]",hr="[object Undefined]",he=ue?ue.toStringTag:void 0;function fr(e){return e==null?e===void 0?hr:ur:he&&he in Object(e)?lr(e):dr(e)}var pr=fr;function gr(e){var r=typeof e;return e!=null&&(r=="object"||r=="function")}var fe=gr,vr=pr,mr=fe,_r="[object AsyncFunction]",yr="[object Function]",Cr="[object GeneratorFunction]",br="[object Proxy]";function Sr(e){if(!mr(e))return!1;var r=vr(e);return r==yr||r==Cr||r==_r||r==br}var $r=Sr,jr=A,wr=jr["__core-js_shared__"],xr=wr,I=xr,pe=function(){var e=/[^.]+$/.exec(I&&I.keys&&I.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Tr(e){return!!pe&&pe in e}var kr=Tr,Or=Function.prototype,qr=Or.toString;function zr(e){if(e!=null){try{return qr.call(e)}catch{}try{return e+""}catch{}}return""}var Dr=zr,Ar=$r,Ir=kr,Lr=fe,Mr=Dr,Fr=/[\\^$.*+?()[\]{}|]/g,Nr=/^\[object .+?Constructor\]$/,Gr=Function.prototype,Er=Object.prototype,Hr=Gr.toString,Ur=Er.hasOwnProperty,Br=RegExp("^"+Hr.call(Ur).replace(Fr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Vr(e){if(!Lr(e)||Ir(e))return!1;var r=Ar(e)?Br:Nr;return r.test(Mr(e))}var Jr=Vr;function Kr(e,r){return e==null?void 0:e[r]}var Xr=Kr,Wr=Jr,Zr=Xr;function Qr(e,r){var a=Zr(e,r);return Wr(a)?a:void 0}var ge=Qr,Yr=ge,Pr=Yr(Object,"create"),k=Pr,ve=k;function Rr(){this.__data__=ve?ve(null):{},this.size=0}var ea=Rr;function ra(e){var r=this.has(e)&&delete this.__data__[e];return this.size-=r?1:0,r}var aa=ra,na=k,ta="__lodash_hash_undefined__",ia=Object.prototype,oa=ia.hasOwnProperty;function sa(e){var r=this.__data__;if(na){var a=r[e];return a===ta?void 0:a}return oa.call(r,e)?r[e]:void 0}var ca=sa,la=k,da=Object.prototype,ua=da.hasOwnProperty;function ha(e){var r=this.__data__;return la?r[e]!==void 0:ua.call(r,e)}var fa=ha,pa=k,ga="__lodash_hash_undefined__";function va(e,r){var a=this.__data__;return this.size+=this.has(e)?0:1,a[e]=pa&&r===void 0?ga:r,this}var ma=va,_a=ea,ya=aa,Ca=ca,ba=fa,Sa=ma;function y(e){var r=-1,a=e==null?0:e.length;for(this.clear();++r<a;){var n=e[r];this.set(n[0],n[1])}}y.prototype.clear=_a,y.prototype.delete=ya,y.prototype.get=Ca,y.prototype.has=ba,y.prototype.set=Sa;var $a=y;function ja(){this.__data__=[],this.size=0}var wa=ja;function xa(e,r){return e===r||e!==e&&r!==r}var Ta=xa,ka=Ta;function Oa(e,r){for(var a=e.length;a--;)if(ka(e[a][0],r))return a;return-1}var O=Oa,qa=O,za=Array.prototype,Da=za.splice;function Aa(e){var r=this.__data__,a=qa(r,e);if(a<0)return!1;var n=r.length-1;return a==n?r.pop():Da.call(r,a,1),--this.size,!0}var Ia=Aa,La=O;function Ma(e){var r=this.__data__,a=La(r,e);return a<0?void 0:r[a][1]}var Fa=Ma,Na=O;function Ga(e){return Na(this.__data__,e)>-1}var Ea=Ga,Ha=O;function Ua(e,r){var a=this.__data__,n=Ha(a,e);return n<0?(++this.size,a.push([e,r])):a[n][1]=r,this}var Ba=Ua,Va=wa,Ja=Ia,Ka=Fa,Xa=Ea,Wa=Ba;function C(e){var r=-1,a=e==null?0:e.length;for(this.clear();++r<a;){var n=e[r];this.set(n[0],n[1])}}C.prototype.clear=Va,C.prototype.delete=Ja,C.prototype.get=Ka,C.prototype.has=Xa,C.prototype.set=Wa;var Za=C,Qa=ge,Ya=A,Pa=Qa(Ya,"Map"),Ra=Pa,me=$a,en=Za,rn=Ra;function an(){this.size=0,this.__data__={hash:new me,map:new(rn||en),string:new me}}var nn=an;function tn(e){var r=typeof e;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?e!=="__proto__":e===null}var on=tn,sn=on;function cn(e,r){var a=e.__data__;return sn(r)?a[typeof r=="string"?"string":"hash"]:a.map}var q=cn,ln=q;function dn(e){var r=ln(this,e).delete(e);return this.size-=r?1:0,r}var un=dn,hn=q;function fn(e){return hn(this,e).get(e)}var pn=fn,gn=q;function vn(e){return gn(this,e).has(e)}var mn=vn,_n=q;function yn(e,r){var a=_n(this,e),n=a.size;return a.set(e,r),this.size+=a.size==n?0:1,this}var Cn=yn,bn=nn,Sn=un,$n=pn,jn=mn,wn=Cn;function b(e){var r=-1,a=e==null?0:e.length;for(this.clear();++r<a;){var n=e[r];this.set(n[0],n[1])}}b.prototype.clear=bn,b.prototype.delete=Sn,b.prototype.get=$n,b.prototype.has=jn,b.prototype.set=wn;var xn=b,_e=xn,Tn="Expected a function";function L(e,r){if(typeof e!="function"||r!=null&&typeof r!="function")throw new TypeError(Tn);var a=function(){var n=arguments,i=r?r.apply(this,n):n[0],d=a.cache;if(d.has(i))return d.get(i);var l=e.apply(this,n);return a.cache=d.set(i,l)||d,l};return a.cache=new(L.Cache||_e),a}L.Cache=_e;var kn=L;const ye=Xe(kn),On=/^(([^<>()[\]\\.,;:\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,}))$/,g=e=>typeof e>"u"||e===null||e===""||Array.isArray(e)&&e.length===0,f=(e,r,a,n)=>typeof e=="function"?e({args:r,value:a,values:n}):r?{message:e,args:r}:e,v=e=>ye(e,(...r)=>JSON.stringify(r)),qn=(...e)=>(r,a,n)=>(Array.isArray(e[0])?e[0]:e).reduce((d,l)=>d||typeof l=="function"&&l(r,a,n),void 0),zn=v((e="validacion.obligatorio")=>Object.assign((r,a)=>g(r)?f(e,void 0,r,a):void 0,{isRequired:!0})),Dn=v((e="validacion.obligatorio")=>Object.assign((r,a)=>g(r)||!r?f(e,void 0,r,a):void 0,{isRequired:!0})),An=v((e="validacion.numero")=>(r,a)=>!g(r)&&isNaN(r)?f(e,void 0,r,a):void 0),In=v((e,r="validacion.longitud.minima")=>(a,n)=>!g(a)&&a.length<e?f(r,void 0,a,n):void 0),Ln=v((e,r="validacion.longitud.maxima")=>(a,n)=>!g(a)&&a.length>e?f(r,void 0,a,n):void 0),Mn=v((e,r="validacion.minimo")=>(a,n)=>!g(a)&&parseFloat(a)<e?f(r,void 0,a,n):void 0),Fn=v((e,r="validacion.maximo")=>(a,n)=>!g(a)&&parseFloat(a)>e?f(r,void 0,a,n):void 0),Ce=ye((e,r="validacion.regex")=>(a,n)=>!g(a)&&typeof a=="string"&&!e.test(a)?f(r,void 0,a,n):void 0,(e,r)=>e.toString()+r),Nn=v((e="validacion.correo")=>Ce(On,e)),Gn=v((e,r,a="validacion.remote")=>(n,i,d)=>d.active&&!g(n)&&e(n,r).then(l=>l?f(a,void 0,n,i):void 0).catch(l=>f(l.message,void 0,n,i)));o.Cargando=B,o.Error=V,o.SaasApp=se,o.composeValidators=qn,o.email=Nn,o.getInstancia=Ee,o.getPerfiles=Ae,o.getToken=ze,o.getUsuario=De,o.logout=W,o.max=Fn,o.maxLength=Ln,o.min=Mn,o.minLength=In,o.number=An,o.regex=Ce,o.remote=Gn,o.required=zn,o.requiredNotFalse=Dn,o.useNotificar=ee,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|