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