@chimera-pe/react-saas 0.6.0 → 3.0.1
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/dist/react-saas.js +279 -566
- package/dist/react-saas.umd.cjs +1 -1
- package/package.json +35 -51
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/dist/react-saas.js
CHANGED
|
@@ -1,609 +1,322 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
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 = {
|
|
1
|
+
import { jsxs as g, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect as m, useContext as k } from "react";
|
|
3
|
+
import o from "prop-types";
|
|
4
|
+
import { AuthProvider as q, AuthContext as x } from "react-oauth2-code-pkce";
|
|
5
|
+
import { create as w } from "zustand";
|
|
6
|
+
import { useTranslate as f, I18n as I } from "react-polyglot";
|
|
7
|
+
import { union as U } from "lodash";
|
|
8
|
+
import C from "navigator-languages";
|
|
9
|
+
const O = "https://saas.chimera.com.pe/backend/v3", R = "https://saas.chimera.com.pe/oauth/v3", A = "http://localhost:7000", T = "http://localhost:7777", u = {
|
|
144
10
|
primary: "#1C6CCC",
|
|
145
11
|
secondary: "#17A7FF",
|
|
146
|
-
error: "#f44336",
|
|
147
|
-
warning: "#ff9800",
|
|
148
12
|
info: "#2196f3",
|
|
149
|
-
success: "#4caf50"
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
13
|
+
success: "#4caf50",
|
|
14
|
+
error: "#f44336",
|
|
15
|
+
warning: "#ff9800"
|
|
16
|
+
}, d = w((e) => ({
|
|
17
|
+
inicializado: !1,
|
|
18
|
+
estado: {
|
|
153
19
|
inicializando: !0,
|
|
154
|
-
inicializado: !1,
|
|
155
|
-
instancia: {
|
|
156
|
-
color: L
|
|
157
|
-
},
|
|
158
20
|
error: null
|
|
159
21
|
},
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
22
|
+
instancia: {
|
|
23
|
+
identificador: null,
|
|
24
|
+
nombre: null,
|
|
25
|
+
abreviatura: null,
|
|
26
|
+
requiereLogin: !1,
|
|
27
|
+
logo: null,
|
|
28
|
+
color: u
|
|
29
|
+
},
|
|
30
|
+
idioma: "en",
|
|
31
|
+
inicializar: async (i, r) => {
|
|
32
|
+
e({
|
|
33
|
+
estado: {
|
|
34
|
+
inicializando: !0,
|
|
35
|
+
error: null
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
try {
|
|
39
|
+
const t = await fetch(`${i || O}/identidad/?codigoAplicacion=${r}`);
|
|
40
|
+
if (!t.ok)
|
|
41
|
+
throw new Error(`inicializar.error.${t.status}`);
|
|
42
|
+
const n = await t.json();
|
|
43
|
+
e({
|
|
44
|
+
inicializado: !0,
|
|
45
|
+
estado: {
|
|
46
|
+
inicializando: !1,
|
|
47
|
+
error: null
|
|
48
|
+
},
|
|
49
|
+
instancia: {
|
|
50
|
+
identificador: n.identificador,
|
|
51
|
+
nombre: n.nombre,
|
|
52
|
+
abreviatura: n.nombre.match(/\b([A-Z])/g).join(""),
|
|
53
|
+
requiereLogin: n.requiereLogin,
|
|
54
|
+
logo: n.logo,
|
|
55
|
+
color: {
|
|
56
|
+
...u,
|
|
57
|
+
...n.color
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
} catch (t) {
|
|
62
|
+
e({
|
|
63
|
+
inicializado: !1,
|
|
64
|
+
estado: {
|
|
65
|
+
inicializando: !1,
|
|
66
|
+
error: t.message
|
|
67
|
+
},
|
|
68
|
+
instancia: {
|
|
69
|
+
identificador: null,
|
|
70
|
+
nombre: null,
|
|
71
|
+
abreviatura: null,
|
|
72
|
+
requiereLogin: !1,
|
|
73
|
+
logo: null,
|
|
74
|
+
color: u
|
|
170
75
|
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
cambiarIdioma: (i) => {
|
|
80
|
+
e({
|
|
81
|
+
idioma: i
|
|
176
82
|
});
|
|
177
83
|
}
|
|
178
|
-
}),
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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,
|
|
84
|
+
})), E = "data:image/svg+xml,%3csvg%20width='24'%20height='24'%20stroke='%23000'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3cstyle%3e.spinner_V8m1{transform-origin:center;animation:spinner_zKoa%202s%20linear%20infinite}.spinner_V8m1%20circle{stroke-linecap:round;animation:spinner_YpZS%201.5s%20ease-in-out%20infinite}@keyframes%20spinner_zKoa{100%25{transform:rotate(360deg)}}@keyframes%20spinner_YpZS{0%25{stroke-dasharray:0%20150;stroke-dashoffset:0}47.5%25{stroke-dasharray:42%20150;stroke-dashoffset:-16}95%25,100%25{stroke-dasharray:42%20150;stroke-dashoffset:-59}}%3c/style%3e%3cg%20class='spinner_V8m1'%3e%3ccircle%20cx='12'%20cy='12'%20r='9.5'%20fill='none'%20stroke-width='3'%3e%3c/circle%3e%3c/g%3e%3c/svg%3e", L = () => {
|
|
85
|
+
const e = f();
|
|
86
|
+
return /* @__PURE__ */ g(
|
|
87
|
+
"div",
|
|
196
88
|
{
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
|
89
|
+
style: {
|
|
90
|
+
display: "flex",
|
|
91
|
+
gap: "0.5rem"
|
|
283
92
|
},
|
|
284
|
-
|
|
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: [
|
|
93
|
+
children: [
|
|
340
94
|
/* @__PURE__ */ a(
|
|
341
|
-
|
|
95
|
+
"img",
|
|
342
96
|
{
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
autoComplete: "off",
|
|
348
|
-
disabled: i,
|
|
349
|
-
autoFocus: !0,
|
|
350
|
-
InputProps: {
|
|
351
|
-
startAdornment: /* @__PURE__ */ a(N, { position: "start", children: /* @__PURE__ */ a(Ne, { color: "primary" }) })
|
|
97
|
+
src: E,
|
|
98
|
+
alt: e("saas.cargando"),
|
|
99
|
+
style: {
|
|
100
|
+
filter: "invert(99%) sepia(2%) saturate(740%) hue-rotate(250deg) brightness(93%) contrast(93%)"
|
|
352
101
|
}
|
|
353
102
|
}
|
|
354
103
|
),
|
|
104
|
+
/* @__PURE__ */ a("span", { children: e("saas.cargando") })
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}, h = ({ titulo: e, texto: i }) => {
|
|
109
|
+
const r = f();
|
|
110
|
+
return /* @__PURE__ */ g(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
style: {
|
|
114
|
+
borderWidth: "2px",
|
|
115
|
+
borderStyle: "solid",
|
|
116
|
+
borderRadius: "7px",
|
|
117
|
+
backgroundColor: "#f44336",
|
|
118
|
+
padding: "0.5rem",
|
|
119
|
+
borderColor: "#8d1108"
|
|
120
|
+
},
|
|
121
|
+
children: [
|
|
355
122
|
/* @__PURE__ */ a(
|
|
356
|
-
|
|
123
|
+
"h4",
|
|
357
124
|
{
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
autoComplete: "current-password",
|
|
364
|
-
disabled: i,
|
|
365
|
-
InputProps: {
|
|
366
|
-
startAdornment: /* @__PURE__ */ a(N, { position: "start", children: /* @__PURE__ */ a(_e, { color: "primary" }) })
|
|
367
|
-
}
|
|
125
|
+
style: {
|
|
126
|
+
marginTop: 0,
|
|
127
|
+
marginBottom: "0.3rem"
|
|
128
|
+
},
|
|
129
|
+
children: r(e)
|
|
368
130
|
}
|
|
369
131
|
),
|
|
370
|
-
/* @__PURE__ */
|
|
371
|
-
|
|
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
|
-
] })
|
|
132
|
+
i && /* @__PURE__ */ a("p", { children: r(i) })
|
|
133
|
+
]
|
|
384
134
|
}
|
|
385
135
|
);
|
|
386
136
|
};
|
|
387
|
-
|
|
388
|
-
|
|
137
|
+
h.propTypes = {
|
|
138
|
+
titulo: o.string.isRequired,
|
|
139
|
+
texto: o.string
|
|
389
140
|
};
|
|
390
|
-
const
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
] }),
|
|
425
|
-
/* @__PURE__ */ a(b, { item: !0, xs: 12, lg: 7, sx: {
|
|
141
|
+
const b = ({ devAuthUrl: e, redirectUri: i, children: r }) => {
|
|
142
|
+
const t = d((n) => n.instancia);
|
|
143
|
+
if (t.requiereLogin) {
|
|
144
|
+
const n = e || R;
|
|
145
|
+
return /* @__PURE__ */ a(
|
|
146
|
+
q,
|
|
147
|
+
{
|
|
148
|
+
authConfig: {
|
|
149
|
+
clientId: t.identificador,
|
|
150
|
+
authorizationEndpoint: `${n}/oauth2/authorize`,
|
|
151
|
+
tokenEndpoint: `${n}/oauth2/token`,
|
|
152
|
+
logoutEndpoint: `${n}/connect/logout`,
|
|
153
|
+
redirectUri: i,
|
|
154
|
+
scope: "openid profile"
|
|
155
|
+
},
|
|
156
|
+
children: r
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return r;
|
|
161
|
+
};
|
|
162
|
+
b.propTypes = {
|
|
163
|
+
devAuthUrl: o.string,
|
|
164
|
+
redirectUri: o.string.isRequired,
|
|
165
|
+
children: o.element.isRequired
|
|
166
|
+
};
|
|
167
|
+
const v = ({ aplicacion: e, devBackendUrl: i }) => {
|
|
168
|
+
const r = d((n) => n.estado), t = d((n) => n.inicializar);
|
|
169
|
+
return m(() => {
|
|
170
|
+
t(i, e);
|
|
171
|
+
}, [t, i, e]), /* @__PURE__ */ a(
|
|
172
|
+
"div",
|
|
173
|
+
{
|
|
174
|
+
style: {
|
|
426
175
|
display: "flex",
|
|
176
|
+
flexDirection: "column",
|
|
427
177
|
alignItems: "center",
|
|
428
178
|
justifyContent: "center",
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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 });
|
|
179
|
+
minHeight: "100vh",
|
|
180
|
+
backgroundColor: "#141316",
|
|
181
|
+
color: "#e6e1e6"
|
|
182
|
+
},
|
|
183
|
+
children: r.inicializando ? /* @__PURE__ */ a(L, {}) : r.error && /* @__PURE__ */ a(h, { titulo: "saas.error.titulo", texto: r.error })
|
|
184
|
+
}
|
|
185
|
+
);
|
|
451
186
|
};
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
children: t.element.isRequired
|
|
187
|
+
v.propTypes = {
|
|
188
|
+
aplicacion: o.string.isRequired,
|
|
189
|
+
devBackendUrl: o.string
|
|
456
190
|
};
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
191
|
+
const y = ({
|
|
192
|
+
aplicacion: e,
|
|
193
|
+
devBackendUrl: i,
|
|
194
|
+
devAuthUrl: r,
|
|
195
|
+
redirectUri: t,
|
|
196
|
+
children: n
|
|
197
|
+
}) => d((l) => l.inicializado) ? /* @__PURE__ */ a(
|
|
198
|
+
b,
|
|
199
|
+
{
|
|
200
|
+
devAuthUrl: r,
|
|
201
|
+
redirectUri: t,
|
|
202
|
+
children: n
|
|
203
|
+
}
|
|
204
|
+
) : /* @__PURE__ */ a(
|
|
205
|
+
v,
|
|
206
|
+
{
|
|
207
|
+
aplicacion: e,
|
|
208
|
+
devBackendUrl: i
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
y.propTypes = {
|
|
212
|
+
aplicacion: o.string.isRequired,
|
|
213
|
+
devBackendUrl: o.string,
|
|
214
|
+
devAuthUrl: o.string,
|
|
215
|
+
redirectUri: o.string.isRequired,
|
|
216
|
+
children: o.element.isRequired
|
|
477
217
|
};
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
),
|
|
496
|
-
/* @__PURE__ */ a(Qe, {})
|
|
497
|
-
] }) });
|
|
218
|
+
const _ = {
|
|
219
|
+
cargando: "Loading...",
|
|
220
|
+
error: {
|
|
221
|
+
titulo: "Could not initialize application"
|
|
222
|
+
}
|
|
223
|
+
}, B = {
|
|
224
|
+
cargando: "Cargando...",
|
|
225
|
+
error: {
|
|
226
|
+
titulo: "Error iniciando aplicación"
|
|
227
|
+
}
|
|
228
|
+
}, p = {
|
|
229
|
+
en: _,
|
|
230
|
+
es: B
|
|
231
|
+
}, z = ({ mensajes: e, children: i }) => {
|
|
232
|
+
const r = d((t) => t.idioma);
|
|
233
|
+
return /* @__PURE__ */ a(I, { locale: r, messages: e[r], children: i });
|
|
498
234
|
};
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
children: t.element.isRequired
|
|
235
|
+
z.propTypes = {
|
|
236
|
+
mensajes: o.object,
|
|
237
|
+
children: o.element.isRequired
|
|
503
238
|
};
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
{
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
) }) });
|
|
239
|
+
const S = () => {
|
|
240
|
+
const e = C();
|
|
241
|
+
if (!(e != null && e.length))
|
|
242
|
+
return;
|
|
243
|
+
const i = e[0];
|
|
244
|
+
return i.indexOf("-") ? i.substring(0, i.indexOf("-")) : i;
|
|
245
|
+
}, j = ({ mensajes: e, idiomaDefecto: i, children: r }) => {
|
|
246
|
+
const t = d((s) => s.cambiarIdioma), n = S(), c = U(Object.keys(e), Object.keys(p));
|
|
247
|
+
m(() => {
|
|
248
|
+
let s = c[0];
|
|
249
|
+
n && Object.hasOwn(e, n) ? s = n : i && Object.hasOwn(e, i) && (s = i), t(s);
|
|
250
|
+
}, [c, e, i, n, t]);
|
|
251
|
+
const l = {};
|
|
252
|
+
return c.forEach((s) => {
|
|
253
|
+
l[s] = {
|
|
254
|
+
...Object.hasOwn(e, s) ? e[s] : {},
|
|
255
|
+
saas: Object.hasOwn(p, s) ? p[s] : {}
|
|
256
|
+
};
|
|
257
|
+
}), /* @__PURE__ */ a(z, { mensajes: l, children: r });
|
|
524
258
|
};
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
messages: t.object.isRequired,
|
|
530
|
-
idiomaDefecto: t.string,
|
|
531
|
-
basename: t.string,
|
|
532
|
-
children: t.element.isRequired
|
|
259
|
+
j.propTypes = {
|
|
260
|
+
mensajes: o.object,
|
|
261
|
+
idiomaDefecto: o.string,
|
|
262
|
+
children: o.element.isRequired
|
|
533
263
|
};
|
|
534
|
-
const
|
|
535
|
-
customReducers: o,
|
|
264
|
+
const P = ({
|
|
536
265
|
aplicacion: e,
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
dev:
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
266
|
+
devBackendUrl: i = A,
|
|
267
|
+
devAuthUrl: r = T,
|
|
268
|
+
dev: t = !1,
|
|
269
|
+
redirectUri: n,
|
|
270
|
+
idiomaDefecto: c = "en",
|
|
271
|
+
mensajes: l = {
|
|
272
|
+
en: {},
|
|
273
|
+
es: {}
|
|
274
|
+
},
|
|
275
|
+
children: s
|
|
276
|
+
}) => /* @__PURE__ */ a(j, { mensajes: l, children: /* @__PURE__ */ a(
|
|
277
|
+
y,
|
|
546
278
|
{
|
|
547
279
|
aplicacion: e,
|
|
548
|
-
|
|
549
|
-
|
|
280
|
+
devBackendUrl: t && i,
|
|
281
|
+
devAuthUrl: t && r,
|
|
282
|
+
redirectUri: n,
|
|
550
283
|
idiomaDefecto: c,
|
|
551
|
-
|
|
552
|
-
basename: h,
|
|
553
|
-
children: j
|
|
284
|
+
children: s
|
|
554
285
|
}
|
|
555
286
|
) });
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
idiomaDefecto:
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
287
|
+
P.propTypes = {
|
|
288
|
+
aplicacion: o.string.isRequired,
|
|
289
|
+
devBackendUrl: o.string,
|
|
290
|
+
devAuthUrl: o.string,
|
|
291
|
+
dev: o.bool,
|
|
292
|
+
redirectUri: o.string.isRequired,
|
|
293
|
+
idiomaDefecto: o.string,
|
|
294
|
+
mensajes: o.object,
|
|
295
|
+
children: o.element.isRequired
|
|
296
|
+
};
|
|
297
|
+
const W = () => {
|
|
298
|
+
const {
|
|
299
|
+
loginInProgress: e,
|
|
300
|
+
token: i,
|
|
301
|
+
tokenData: r,
|
|
302
|
+
logIn: t,
|
|
303
|
+
logOut: n,
|
|
304
|
+
error: c
|
|
305
|
+
} = k(x);
|
|
306
|
+
return {
|
|
307
|
+
loginInProgress: e,
|
|
308
|
+
token: i,
|
|
309
|
+
logIn: t,
|
|
310
|
+
logOut: n,
|
|
311
|
+
error: c,
|
|
312
|
+
correo: r == null ? void 0 : r.sub,
|
|
313
|
+
nombre: r == null ? void 0 : r.name,
|
|
314
|
+
perfiles: r == null ? void 0 : r.profiles
|
|
315
|
+
};
|
|
566
316
|
};
|
|
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
317
|
export {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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
|
|
318
|
+
y as Inicializar,
|
|
319
|
+
P as SaasApp,
|
|
320
|
+
W as useAuth,
|
|
321
|
+
d as useSaasStore
|
|
609
322
|
};
|
package/dist/react-saas.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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"})});
|
|
1
|
+
(function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("react"),require("prop-types"),require("react-oauth2-code-pkce"),require("zustand"),require("react-polyglot"),require("lodash"),require("navigator-languages")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","prop-types","react-oauth2-code-pkce","zustand","react-polyglot","lodash","navigator-languages"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s["react-saas"]={},s.ReactJSX,s.React,s.PropTypes,s.ReactOauth2CodePkce,s.Zustand,s.ReactPolyglot,s.Lodash,s.NavigatorLanguages))})(this,function(s,o,g,t,v,x,f,I,U){"use strict";const A="https://saas.chimera.com.pe/backend/v3",C="https://saas.chimera.com.pe/oauth/v3",O="http://localhost:7000",S="http://localhost:7777",h={primary:"#1C6CCC",secondary:"#17A7FF",info:"#2196f3",success:"#4caf50",error:"#f44336",warning:"#ff9800"},l=x.create(e=>({inicializado:!1,estado:{inicializando:!0,error:null},instancia:{identificador:null,nombre:null,abreviatura:null,requiereLogin:!1,logo:null,color:h},idioma:"en",inicializar:async(r,i)=>{e({estado:{inicializando:!0,error:null}});try{const a=await fetch(`${r||A}/identidad/?codigoAplicacion=${i}`);if(!a.ok)throw new Error(`inicializar.error.${a.status}`);const n=await a.json();e({inicializado:!0,estado:{inicializando:!1,error:null},instancia:{identificador:n.identificador,nombre:n.nombre,abreviatura:n.nombre.match(/\b([A-Z])/g).join(""),requiereLogin:n.requiereLogin,logo:n.logo,color:{...h,...n.color}}})}catch(a){e({inicializado:!1,estado:{inicializando:!1,error:a.message},instancia:{identificador:null,nombre:null,abreviatura:null,requiereLogin:!1,logo:null,color:h}})}},cambiarIdioma:r=>{e({idioma:r})}})),y="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20stroke='%23000'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3cstyle%3e.spinner_V8m1{transform-origin:center;animation:spinner_zKoa%202s%20linear%20infinite}.spinner_V8m1%20circle{stroke-linecap:round;animation:spinner_YpZS%201.5s%20ease-in-out%20infinite}@keyframes%20spinner_zKoa{100%25{transform:rotate(360deg)}}@keyframes%20spinner_YpZS{0%25{stroke-dasharray:0%20150;stroke-dashoffset:0}47.5%25{stroke-dasharray:42%20150;stroke-dashoffset:-16}95%25,100%25{stroke-dasharray:42%20150;stroke-dashoffset:-59}}%3c/style%3e%3cg%20class='spinner_V8m1'%3e%3ccircle%20cx='12'%20cy='12'%20r='9.5'%20fill='none'%20stroke-width='3'%3e%3c/circle%3e%3c/g%3e%3c/svg%3e",E=()=>{const e=f.useTranslate();return o.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[o.jsx("img",{src:y,alt:e("saas.cargando"),style:{filter:"invert(99%) sepia(2%) saturate(740%) hue-rotate(250deg) brightness(93%) contrast(93%)"}}),o.jsx("span",{children:e("saas.cargando")})]})},b=({titulo:e,texto:r})=>{const i=f.useTranslate();return o.jsxs("div",{style:{borderWidth:"2px",borderStyle:"solid",borderRadius:"7px",backgroundColor:"#f44336",padding:"0.5rem",borderColor:"#8d1108"},children:[o.jsx("h4",{style:{marginTop:0,marginBottom:"0.3rem"},children:i(e)}),r&&o.jsx("p",{children:i(r)})]})};b.propTypes={titulo:t.string.isRequired,texto:t.string};const q=({devAuthUrl:e,redirectUri:r,children:i})=>{const a=l(n=>n.instancia);if(a.requiereLogin){const n=e||C;return o.jsx(v.AuthProvider,{authConfig:{clientId:a.identificador,authorizationEndpoint:`${n}/oauth2/authorize`,tokenEndpoint:`${n}/oauth2/token`,logoutEndpoint:`${n}/connect/logout`,redirectUri:r,scope:"openid profile"},children:i})}return i};q.propTypes={devAuthUrl:t.string,redirectUri:t.string.isRequired,children:t.element.isRequired};const z=({aplicacion:e,devBackendUrl:r})=>{const i=l(n=>n.estado),a=l(n=>n.inicializar);return g.useEffect(()=>{a(r,e)},[a,r,e]),o.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"100vh",backgroundColor:"#141316",color:"#e6e1e6"},children:i.inicializando?o.jsx(E,{}):i.error&&o.jsx(b,{titulo:"saas.error.titulo",texto:i.error})})};z.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string};const m=({aplicacion:e,devBackendUrl:r,devAuthUrl:i,redirectUri:a,children:n})=>l(u=>u.inicializado)?o.jsx(q,{devAuthUrl:i,redirectUri:a,children:n}):o.jsx(z,{aplicacion:e,devBackendUrl:r});m.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string,devAuthUrl:t.string,redirectUri:t.string.isRequired,children:t.element.isRequired};const p={en:{cargando:"Loading...",error:{titulo:"Could not initialize application"}},es:{cargando:"Cargando...",error:{titulo:"Error iniciando aplicación"}}},j=({mensajes:e,children:r})=>{const i=l(a=>a.idioma);return o.jsx(f.I18n,{locale:i,messages:e[i],children:r})};j.propTypes={mensajes:t.object,children:t.element.isRequired};const L=()=>{const e=U();if(!(e!=null&&e.length))return;const r=e[0];return r.indexOf("-")?r.substring(0,r.indexOf("-")):r},k=({mensajes:e,idiomaDefecto:r,children:i})=>{const a=l(c=>c.cambiarIdioma),n=L(),d=I.union(Object.keys(e),Object.keys(p));g.useEffect(()=>{let c=d[0];n&&Object.hasOwn(e,n)?c=n:r&&Object.hasOwn(e,r)&&(c=r),a(c)},[d,e,r,n,a]);const u={};return d.forEach(c=>{u[c]={...Object.hasOwn(e,c)?e[c]:{},saas:Object.hasOwn(p,c)?p[c]:{}}}),o.jsx(j,{mensajes:u,children:i})};k.propTypes={mensajes:t.object,idiomaDefecto:t.string,children:t.element.isRequired};const w=({aplicacion:e,devBackendUrl:r=O,devAuthUrl:i=S,dev:a=!1,redirectUri:n,idiomaDefecto:d="en",mensajes:u={en:{},es:{}},children:c})=>o.jsx(k,{mensajes:u,children:o.jsx(m,{aplicacion:e,devBackendUrl:a&&r,devAuthUrl:a&&i,redirectUri:n,idiomaDefecto:d,children:c})});w.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string,devAuthUrl:t.string,dev:t.bool,redirectUri:t.string.isRequired,idiomaDefecto:t.string,mensajes:t.object,children:t.element.isRequired};const _=()=>{const{loginInProgress:e,token:r,tokenData:i,logIn:a,logOut:n,error:d}=g.useContext(v.AuthContext);return{loginInProgress:e,token:r,logIn:a,logOut:n,error:d,correo:i==null?void 0:i.sub,nombre:i==null?void 0:i.name,perfiles:i==null?void 0:i.profiles}};s.Inicializar=m,s.SaasApp=w,s.useAuth=_,s.useSaasStore=l,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
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.1",
|
|
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,31 @@
|
|
|
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",
|
|
30
|
+
"prepare": "npm run build"
|
|
62
31
|
},
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"lodash": "^4.17.21",
|
|
34
|
+
"navigator-languages": "^2.0.2",
|
|
35
|
+
"react": "^19.1.0",
|
|
36
|
+
"react-dom": "^19.1.0",
|
|
37
|
+
"react-oauth2-code-pkce": "^1.23.0",
|
|
38
|
+
"react-polyglot": "^0.7.2",
|
|
39
|
+
"zustand": "^5.0.4"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@eslint/js": "^9.22.0",
|
|
43
|
+
"@types/react": "^19.1.3",
|
|
44
|
+
"@types/react-dom": "^19.1.3",
|
|
45
|
+
"@vitejs/plugin-react": "^4.4.1",
|
|
46
|
+
"eslint": "^9.26.0",
|
|
47
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
48
|
+
"eslint-plugin-react-refresh": "^0.4.20",
|
|
49
|
+
"globals": "^16.0.0",
|
|
50
|
+
"vite": "^6.3.5"
|
|
51
|
+
}
|
|
68
52
|
}
|