@dashadmin/dash-admin 1.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.
@@ -0,0 +1,153 @@
1
+ import { jsx as a, jsxs as b } from "react/jsx-runtime";
2
+ import { Box as S, Alert as C, Button as x, TextField as v } from "@mui/material";
3
+ import { useState as m, useEffect as j } from "react";
4
+ import { useNavigate as R, useSearchParams as E } from "react-router-dom";
5
+ import { b as L, F } from "./index-U84xs0Dc.js";
6
+ import "react-redux";
7
+ import "react-admin";
8
+ import "@dashadmin/dash-admin-state";
9
+ import "@mui/icons-material/MenuOpen";
10
+ import "@dashadmin/dash-auth";
11
+ import "@mui/icons-material/NavigateNext";
12
+ import "@mui/icons-material/Home";
13
+ import "@dashadmin/dash-constants";
14
+ import "react-toastify";
15
+ import "@dashadmin/dash-dialog";
16
+ import "@dashadmin/dash-modal";
17
+ import "@mui/icons-material/ExpandMore";
18
+ import "@dashadmin/dash-auto-admin";
19
+ import "react-router";
20
+ import "@mui/icons-material/NotificationsActive";
21
+ import "react-custom-scrollbars-2";
22
+ import "@dashadmin/dash-utils";
23
+ import "@mui/x-date-pickers";
24
+ import "@mui/x-date-pickers/AdapterDayjs";
25
+ const I = (l) => {
26
+ let s = {};
27
+ for (const e of l) {
28
+ const [d, o] = e;
29
+ s = { ...s, [d]: o };
30
+ }
31
+ return Object.keys(s).length > 0 ? s : null;
32
+ }, re = ({}) => {
33
+ const l = R();
34
+ let [s] = E();
35
+ const e = I(s.entries()), d = e != null && e.email ? decodeURIComponent(e.email).replace(/[)\]\s]+$/, "") : "", [o, w] = m(""), [h, N] = m(""), [c, f] = m(!1), [u, i] = m(""), [y, k] = m(!1), { axios: P } = L();
36
+ return j(() => {
37
+ (!(e != null && e.token) || !(e != null && e.email)) && l("/login");
38
+ }, []), /* @__PURE__ */ a(F, { children: y ? /* @__PURE__ */ b(
39
+ S,
40
+ {
41
+ sx: {
42
+ display: "flex",
43
+ flexDirection: "column",
44
+ alignItems: "center",
45
+ justifyContent: "center",
46
+ boxShadow: 3,
47
+ borderRadius: 2,
48
+ p: 4,
49
+ minWidth: 320,
50
+ minHeight: 200,
51
+ bgcolor: "background.paper",
52
+ mt: 8,
53
+ mx: "auto"
54
+ },
55
+ children: [
56
+ /* @__PURE__ */ a("h1", { className: "dash-app-login-form-title", style: { margin: 0 }, children: "Contraseña cambiada" }),
57
+ /* @__PURE__ */ a(C, { severity: "success", sx: { mt: 2, mb: 2 }, children: "Tu contraseña ha sido cambiada correctamente." }),
58
+ /* @__PURE__ */ a(
59
+ x,
60
+ {
61
+ variant: "contained",
62
+ color: "primary",
63
+ onClick: () => l("/login"),
64
+ sx: { mt: 2 },
65
+ children: "Ir al Login"
66
+ }
67
+ )
68
+ ]
69
+ }
70
+ ) : /* @__PURE__ */ b(
71
+ "form",
72
+ {
73
+ onSubmit: async (n) => {
74
+ var g;
75
+ if (n.preventDefault(), o === h) {
76
+ i(""), f(!0);
77
+ try {
78
+ const { data: t } = await P.post("password/reset", {
79
+ password: o,
80
+ password_confirmation: h,
81
+ token: e == null ? void 0 : e.token,
82
+ email: d
83
+ });
84
+ k(!0);
85
+ } catch (t) {
86
+ let p = "Error al cambiar contraseña";
87
+ if ((g = t == null ? void 0 : t.response) != null && g.data) {
88
+ const r = t.response.data;
89
+ r.errors && r.errors.email && r.errors.email.length > 0 ? p = r.errors.email[0] : r.message && (p = r.message);
90
+ } else t != null && t.message && (p = t.message);
91
+ i(p);
92
+ } finally {
93
+ f(!1);
94
+ }
95
+ } else
96
+ i("Las contraseñas no coinciden");
97
+ },
98
+ className: "dash-app-login-form",
99
+ autoComplete: "on",
100
+ method: "post",
101
+ children: [
102
+ /* @__PURE__ */ a("h1", { className: "dash-app-login-form-title", children: "Cambiar Contraseña" }),
103
+ u && /* @__PURE__ */ a(C, { severity: "error", sx: { mb: 2 }, children: u }),
104
+ /* @__PURE__ */ a("div", { className: "dash-app-form-item", children: /* @__PURE__ */ a(
105
+ v,
106
+ {
107
+ fullWidth: !0,
108
+ label: "Contraseña",
109
+ placeholder: "Contraseña",
110
+ required: !0,
111
+ type: "password",
112
+ value: o,
113
+ onChange: (n) => {
114
+ i(""), w(n.target.value);
115
+ },
116
+ className: "dash-app-form-item-input",
117
+ disabled: c
118
+ }
119
+ ) }),
120
+ /* @__PURE__ */ a("div", { className: "dash-app-form-item", children: /* @__PURE__ */ a(
121
+ v,
122
+ {
123
+ fullWidth: !0,
124
+ label: "Repetir Contraseña",
125
+ placeholder: "Repetir Contraseña",
126
+ required: !0,
127
+ type: "password",
128
+ value: h,
129
+ onChange: (n) => {
130
+ i(""), N(n.target.value);
131
+ },
132
+ className: "dash-app-form-item-input",
133
+ disabled: c
134
+ }
135
+ ) }),
136
+ /* @__PURE__ */ a("div", { className: "dash-app-form-item mt-1", children: /* @__PURE__ */ a(
137
+ x,
138
+ {
139
+ type: "submit",
140
+ variant: "contained",
141
+ className: "submit",
142
+ disabled: c,
143
+ sx: { mb: 2, width: "100%" },
144
+ children: c ? "Cargando..." : "Cambiar Contraseña"
145
+ }
146
+ ) })
147
+ ]
148
+ }
149
+ ) });
150
+ };
151
+ export {
152
+ re as default
153
+ };
@@ -0,0 +1,101 @@
1
+ import { jsx as e, jsxs as f } from "react/jsx-runtime";
2
+ import g, { useState as o, useEffect as h } from "react";
3
+ import { useNotify as y } from "react-admin";
4
+ import { Link as b } from "react-router-dom";
5
+ import { InputLabel as l, Input as d, Button as x } from "@mui/material";
6
+ import { useSelector as v } from "react-redux";
7
+ import { a as C, C as S } from "./index-U84xs0Dc.js";
8
+ import { dashStorage as w } from "@dashadmin/dash-utils";
9
+ const q = () => {
10
+ const [a, m] = o(""), [n, c] = o(""), [r, s] = o(!1), { login: p } = C, i = y();
11
+ g.useContext(S), v(
12
+ (t) => t.common.panelSettings
13
+ );
14
+ const u = (t) => {
15
+ t.preventDefault(), s(!0), p({ username: a, password: n }).then(() => {
16
+ i("Login ok!", { type: "success" });
17
+ }).catch(() => {
18
+ i("Error", { type: "error" }), s(!1);
19
+ });
20
+ };
21
+ return h(() => {
22
+ w.setItem(
23
+ "roles",
24
+ JSON.stringify([])
25
+ );
26
+ }, []), /* @__PURE__ */ e(
27
+ "div",
28
+ {
29
+ className: "dash-app-login-content",
30
+ style: {
31
+ display: "flex",
32
+ flexDirection: "column",
33
+ justifyContent: "center",
34
+ alignItems: "center",
35
+ minHeight: "100vh"
36
+ },
37
+ children: /* @__PURE__ */ f(
38
+ "form",
39
+ {
40
+ onSubmit: u,
41
+ style: {
42
+ width: "100%",
43
+ maxWidth: 400,
44
+ background: "white",
45
+ padding: 32,
46
+ borderRadius: 12,
47
+ boxShadow: "0 2px 16px rgba(0,0,0,0.08)",
48
+ display: "flex",
49
+ flexDirection: "column",
50
+ alignItems: "stretch"
51
+ },
52
+ children: [
53
+ /* @__PURE__ */ e(l, { id: "demo-simple-select-label", children: "Correo" }),
54
+ /* @__PURE__ */ e(
55
+ d,
56
+ {
57
+ name: "email",
58
+ type: "email",
59
+ value: a,
60
+ required: !0,
61
+ readOnly: r,
62
+ onChange: (t) => m(t.target.value)
63
+ }
64
+ ),
65
+ /* @__PURE__ */ e("br", {}),
66
+ /* @__PURE__ */ e(l, { id: "demo-simple-select-label", children: "Contraseña" }),
67
+ /* @__PURE__ */ e(
68
+ d,
69
+ {
70
+ name: "password",
71
+ type: "password",
72
+ value: n,
73
+ required: !0,
74
+ readOnly: r,
75
+ onChange: (t) => c(t.target.value)
76
+ }
77
+ ),
78
+ /* @__PURE__ */ e("br", {}),
79
+ /* @__PURE__ */ e("br", {}),
80
+ /* @__PURE__ */ e(b, { style: { color: "royalblue", alignSelf: "flex-end" }, to: "/reset-password", children: "Olvido contraseña" }),
81
+ /* @__PURE__ */ e("br", {}),
82
+ /* @__PURE__ */ e(
83
+ x,
84
+ {
85
+ type: "submit",
86
+ variant: "contained",
87
+ color: "primary",
88
+ disabled: r,
89
+ style: { marginTop: 16 },
90
+ children: r ? "Cargando..." : "Ingresar"
91
+ }
92
+ )
93
+ ]
94
+ }
95
+ )
96
+ }
97
+ );
98
+ };
99
+ export {
100
+ q as default
101
+ };
@@ -0,0 +1,295 @@
1
+ import { jsxs as o, jsx as e } from "react/jsx-runtime";
2
+ import { useState as x, useEffect as $ } from "react";
3
+ import { IconButton as O, Grid as i, CardContent as h, Typography as j, CardHeader as w, Button as I } from "@mui/material";
4
+ import { useNotify as k, useRefresh as q, Form as H, TextInput as c, Loading as M } from "react-admin";
5
+ import { useDispatch as B } from "react-redux";
6
+ import { DASH_REDUX_ACTIONS as V } from "@dashadmin/dash-admin-state";
7
+ import { u as X, b as J, U as K } from "./index-U84xs0Dc.js";
8
+ import { Upload as Q } from "@mui/icons-material";
9
+ const Y = (y) => {
10
+ const { classNamePrefix: n = "default", currentUrl: p = "single-image-uploader", onChange: d } = y, [u, t] = x(null);
11
+ return /* @__PURE__ */ o("div", { className: `single-image-uploader ${n}-img`, children: [
12
+ u || p ? /* @__PURE__ */ e("img", { src: u || p, alt: "" }) : /* @__PURE__ */ e("div", { className: `${n}-icon` }),
13
+ /* @__PURE__ */ o(
14
+ O,
15
+ {
16
+ "aria-label": "upload image",
17
+ component: "label",
18
+ className: `${n}-edit`,
19
+ children: [
20
+ /* @__PURE__ */ e(Q, { style: { opacity: "0.6" } }),
21
+ /* @__PURE__ */ e(
22
+ "input",
23
+ {
24
+ hidden: !0,
25
+ accept: "image/*",
26
+ type: "file",
27
+ onChange: (m) => {
28
+ t(URL.createObjectURL(m.target.files[0])), d && d(m.target.files[0]);
29
+ }
30
+ }
31
+ )
32
+ ]
33
+ }
34
+ )
35
+ ] });
36
+ }, oe = (y) => {
37
+ const [n, p] = x("auth/update/info"), [d, u] = x(!1), { user: t, fetchAuth: m } = X(), [b, S] = x({ rawFile: null, urlFile: "" }), g = k(), { axios: C } = J(), v = q(), P = B();
38
+ $(() => {
39
+ P(
40
+ V.updatePage({
41
+ title: "Perfil",
42
+ //icon:
43
+ subTitle: "Configuración de perfil"
44
+ })
45
+ );
46
+ }, []);
47
+ const W = (a) => {
48
+ const s = {};
49
+ return n === "auth/update/password" && ((a.password || a.password_confirmation) && !a.current_password && (s.current_password = "El campo es requerido"), a.current_password && (!a.password || !a.password_confirmation) && (s.password = "El campo es requerido", s.password_confirmation = "El campo es requerido"), a.password_confirmation !== a.password && (s.password = "Las contraseñas no coinciden", s.password_confirmation = "Las contraseñas no coinciden")), s;
50
+ }, R = async (a) => {
51
+ var _, z, N, U, A, E;
52
+ u(!0);
53
+ const s = new FormData(), G = {
54
+ current_password: a.current_password,
55
+ password: a.password,
56
+ password_confirmation: a.password_confirmation
57
+ };
58
+ a.name && s.append("name", a.name), a.lastname && s.append("lastname", a.lastname), a.email && s.append("email", a.email), b.rawFile && s.append("avatar", b.rawFile), s.append("_method", "put");
59
+ try {
60
+ n === "auth/update/info" ? await C.post(n, s, {
61
+ headers: { "Content-Type": "multipart/form-data" }
62
+ }) : await C.put(n, G);
63
+ try {
64
+ await m(), console.log("Auth context refreshed after profile update");
65
+ } catch (r) {
66
+ console.error("Faileds to refresh auth context:", r);
67
+ }
68
+ g("Usuario actualizado correctamente", { type: "success" }), v();
69
+ } catch (r) {
70
+ let F = ((z = (_ = r == null ? void 0 : r.response) == null ? void 0 : _.data) == null ? void 0 : z.message) || ((N = r == null ? void 0 : r.body) == null ? void 0 : N.message) || "", l = ((A = (U = r == null ? void 0 : r.response) == null ? void 0 : U.data) == null ? void 0 : A.errors) || ((E = r == null ? void 0 : r.body) == null ? void 0 : E.errors) || r;
71
+ if (F ? g(`Error al actualizar el usuario, ${F}`, { type: "error" }) : g("Error al actualizar el usuario", { type: "error" }), l && typeof l == "object") {
72
+ const L = {};
73
+ return Object.keys(l).forEach((f) => {
74
+ L[f] = Array.isArray(l[f]) ? l[f].join(" , ") : l[f];
75
+ }), L;
76
+ }
77
+ } finally {
78
+ u(!1);
79
+ }
80
+ }, T = () => {
81
+ p("auth/update/info");
82
+ }, D = () => {
83
+ p("auth/update/password");
84
+ };
85
+ return /* @__PURE__ */ e("div", { className: "dash-profile", children: t ? /* @__PURE__ */ e(
86
+ H,
87
+ {
88
+ onSubmit: R,
89
+ validate: W,
90
+ defaultValues: { name: t == null ? void 0 : t.name, email: t == null ? void 0 : t.email, lastname: t == null ? void 0 : t.lastname },
91
+ className: "dash-form",
92
+ children: /* @__PURE__ */ e("div", { className: "dash-card-content dash-module dash-card-profile", children: /* @__PURE__ */ o(
93
+ i,
94
+ {
95
+ container: !0,
96
+ spacing: { xs: 2, md: 3 },
97
+ sx: { minHeight: "400px" },
98
+ children: [
99
+ /* @__PURE__ */ e(
100
+ i,
101
+ {
102
+ size: { xs: 12, md: 4 },
103
+ display: "flex",
104
+ justifyContent: "center",
105
+ alignItems: "center",
106
+ children: /* @__PURE__ */ o(
107
+ h,
108
+ {
109
+ sx: {
110
+ height: "100%",
111
+ display: "flex",
112
+ flexDirection: "column",
113
+ justifyContent: "center",
114
+ alignItems: "center",
115
+ width: "100%"
116
+ },
117
+ children: [
118
+ /* @__PURE__ */ e(
119
+ Y,
120
+ {
121
+ currentUrl: t == null ? void 0 : t.image_path,
122
+ onChange: (a) => {
123
+ S({
124
+ rawFile: a,
125
+ urlFile: URL.createObjectURL(a)
126
+ });
127
+ },
128
+ classNamePrefix: "dash-profile"
129
+ }
130
+ ),
131
+ /* @__PURE__ */ e(
132
+ j,
133
+ {
134
+ className: "dash-profile-name",
135
+ variant: "h2",
136
+ sx: { mt: 2, textAlign: "center" },
137
+ children: `${(t == null ? void 0 : t.name) || ""}`
138
+ }
139
+ ),
140
+ /* @__PURE__ */ e(
141
+ j,
142
+ {
143
+ variant: "body2",
144
+ sx: {
145
+ display: "block",
146
+ textAlign: "center",
147
+ fontSize: "14px",
148
+ opacity: 0.54,
149
+ mt: 1
150
+ }
151
+ }
152
+ )
153
+ ]
154
+ }
155
+ )
156
+ }
157
+ ),
158
+ /* @__PURE__ */ o(i, { size: { xs: 12, md: 4 }, children: [
159
+ /* @__PURE__ */ e(
160
+ w,
161
+ {
162
+ sx: { padding: "16px 25px 0" },
163
+ title: "Info"
164
+ }
165
+ ),
166
+ /* @__PURE__ */ e(h, { sx: { padding: "25px" }, children: /* @__PURE__ */ o(i, { container: !0, spacing: 2, children: [
167
+ /* @__PURE__ */ e(i, { size: 12, children: /* @__PURE__ */ e(
168
+ c,
169
+ {
170
+ source: "name",
171
+ label: "Nombre",
172
+ variant: "outlined",
173
+ fullWidth: !0
174
+ }
175
+ ) }),
176
+ /* @__PURE__ */ e(i, { size: 12, children: /* @__PURE__ */ e(
177
+ c,
178
+ {
179
+ source: "lastname",
180
+ label: "Apellido",
181
+ variant: "outlined",
182
+ fullWidth: !0
183
+ }
184
+ ) }),
185
+ /* @__PURE__ */ e(i, { size: 12, children: /* @__PURE__ */ e(
186
+ c,
187
+ {
188
+ source: "email",
189
+ label: "Email",
190
+ variant: "outlined",
191
+ fullWidth: !0
192
+ }
193
+ ) }),
194
+ /* @__PURE__ */ e(i, { size: 12, sx: { mt: 2 }, children: /* @__PURE__ */ e(
195
+ I,
196
+ {
197
+ onClick: T,
198
+ disabled: d,
199
+ variant: "contained",
200
+ type: "submit",
201
+ fullWidth: !0,
202
+ sx: {
203
+ position: "relative",
204
+ "&.Mui-disabled": {
205
+ backgroundColor: "primary.main",
206
+ opacity: 0.7,
207
+ color: "white"
208
+ }
209
+ },
210
+ children: d && n === "auth/update/info" ? "Guardando..." : "Guardar"
211
+ }
212
+ ) })
213
+ ] }) })
214
+ ] }),
215
+ /* @__PURE__ */ o(i, { size: { xs: 12, md: 4 }, children: [
216
+ /* @__PURE__ */ e(
217
+ w,
218
+ {
219
+ sx: { padding: "16px 25px 0" },
220
+ title: "Contraseñas"
221
+ }
222
+ ),
223
+ /* @__PURE__ */ e(h, { sx: { padding: "25px" }, children: /* @__PURE__ */ o(i, { container: !0, spacing: 2, children: [
224
+ /* @__PURE__ */ e(i, { size: 12, children: /* @__PURE__ */ e(
225
+ c,
226
+ {
227
+ type: "password",
228
+ source: "current_password",
229
+ label: "Contraseña actual",
230
+ variant: "outlined",
231
+ fullWidth: !0
232
+ }
233
+ ) }),
234
+ /* @__PURE__ */ e(i, { size: 12, children: /* @__PURE__ */ e(
235
+ c,
236
+ {
237
+ type: "password",
238
+ source: "password",
239
+ label: "Nueva contraseña",
240
+ variant: "outlined",
241
+ fullWidth: !0
242
+ }
243
+ ) }),
244
+ /* @__PURE__ */ e(i, { size: 12, children: /* @__PURE__ */ e(
245
+ c,
246
+ {
247
+ label: "Repita nueva contraseña",
248
+ type: "password",
249
+ source: "password_confirmation",
250
+ variant: "outlined",
251
+ fullWidth: !0
252
+ }
253
+ ) }),
254
+ /* @__PURE__ */ e(i, { size: 12, sx: { mt: 2 }, children: /* @__PURE__ */ e(
255
+ I,
256
+ {
257
+ onClick: D,
258
+ disabled: d,
259
+ variant: "contained",
260
+ type: "submit",
261
+ fullWidth: !0,
262
+ sx: {
263
+ position: "relative",
264
+ "&.Mui-disabled": {
265
+ backgroundColor: "primary.main",
266
+ opacity: 0.7,
267
+ color: "white"
268
+ }
269
+ },
270
+ children: d && n === "auth/update/password" ? "Guardando Contraseñas..." : "Guardar Contraseñas"
271
+ }
272
+ ) })
273
+ ] }) })
274
+ ] }),
275
+ /* @__PURE__ */ o(i, { size: {
276
+ xs: 12
277
+ }, children: [
278
+ /* @__PURE__ */ e(
279
+ w,
280
+ {
281
+ sx: { padding: "16px 25px 0" },
282
+ title: "Preferencias"
283
+ }
284
+ ),
285
+ /* @__PURE__ */ e(h, { sx: { padding: "25px" }, children: /* @__PURE__ */ e(K, {}) })
286
+ ] })
287
+ ]
288
+ }
289
+ ) })
290
+ }
291
+ ) : /* @__PURE__ */ e(M, {}) });
292
+ };
293
+ export {
294
+ oe as default
295
+ };
package/README.md ADDED
File without changes