@nocios/crudify-ui 3.0.20 → 3.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +111 -2
- package/dist/index.d.ts +111 -2
- package/dist/index.js +1144 -447
- package/dist/index.mjs +1079 -389
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
CrudifyLogin: () => CrudifyLogin_default,
|
|
35
35
|
ERROR_CODES: () => ERROR_CODES,
|
|
36
36
|
ERROR_SEVERITY_MAP: () => ERROR_SEVERITY_MAP,
|
|
37
|
+
GlobalNotificationProvider: () => GlobalNotificationProvider,
|
|
37
38
|
LoginComponent: () => LoginComponent,
|
|
38
39
|
POLICY_ACTIONS: () => POLICY_ACTIONS,
|
|
39
40
|
PREFERRED_POLICY_ORDER: () => PREFERRED_POLICY_ORDER,
|
|
@@ -45,7 +46,8 @@ __export(index_exports, {
|
|
|
45
46
|
SessionStatus: () => SessionStatus,
|
|
46
47
|
TokenStorage: () => TokenStorage,
|
|
47
48
|
UserProfileDisplay: () => UserProfileDisplay_default,
|
|
48
|
-
|
|
49
|
+
createErrorTranslator: () => createErrorTranslator,
|
|
50
|
+
crudify: () => import_crudify_browser7.default,
|
|
49
51
|
decodeJwtSafely: () => decodeJwtSafely,
|
|
50
52
|
getCookie: () => getCookie,
|
|
51
53
|
getCurrentUserEmail: () => getCurrentUserEmail,
|
|
@@ -57,19 +59,24 @@ __export(index_exports, {
|
|
|
57
59
|
parseTransactionError: () => parseTransactionError,
|
|
58
60
|
secureLocalStorage: () => secureLocalStorage,
|
|
59
61
|
secureSessionStorage: () => secureSessionStorage,
|
|
62
|
+
translateError: () => translateError,
|
|
63
|
+
translateErrorCode: () => translateErrorCode,
|
|
64
|
+
translateErrorCodes: () => translateErrorCodes,
|
|
60
65
|
useAuth: () => useAuth,
|
|
66
|
+
useCrudifyWithNotifications: () => useCrudifyWithNotifications,
|
|
61
67
|
useData: () => useData,
|
|
68
|
+
useGlobalNotification: () => useGlobalNotification,
|
|
62
69
|
useSession: () => useSession,
|
|
63
70
|
useSessionContext: () => useSessionContext,
|
|
64
71
|
useUserData: () => useUserData,
|
|
65
72
|
useUserProfile: () => useUserProfile
|
|
66
73
|
});
|
|
67
74
|
module.exports = __toCommonJS(index_exports);
|
|
68
|
-
var
|
|
75
|
+
var import_crudify_browser7 = __toESM(require("@nocios/crudify-browser"));
|
|
69
76
|
__reExport(index_exports, require("@nocios/crudify-browser"), module.exports);
|
|
70
77
|
|
|
71
78
|
// src/components/CrudifyLogin/index.tsx
|
|
72
|
-
var
|
|
79
|
+
var import_material7 = require("@mui/material");
|
|
73
80
|
|
|
74
81
|
// src/components/CrudifyLogin/context/I18nProvider.tsx
|
|
75
82
|
var import_react2 = require("react");
|
|
@@ -457,7 +464,7 @@ var useLoginState = () => {
|
|
|
457
464
|
};
|
|
458
465
|
|
|
459
466
|
// src/providers/SessionProvider.tsx
|
|
460
|
-
var
|
|
467
|
+
var import_react7 = require("react");
|
|
461
468
|
|
|
462
469
|
// src/hooks/useSession.ts
|
|
463
470
|
var import_react5 = require("react");
|
|
@@ -1113,12 +1120,149 @@ var isTokenExpired = (token) => {
|
|
|
1113
1120
|
}
|
|
1114
1121
|
};
|
|
1115
1122
|
|
|
1116
|
-
// src/
|
|
1123
|
+
// src/components/GlobalNotificationProvider.tsx
|
|
1124
|
+
var import_react6 = require("react");
|
|
1125
|
+
var import_material = require("@mui/material");
|
|
1126
|
+
var import_uuid = require("uuid");
|
|
1117
1127
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1118
|
-
var
|
|
1119
|
-
|
|
1128
|
+
var GlobalNotificationContext = (0, import_react6.createContext)(null);
|
|
1129
|
+
var GlobalNotificationProvider = ({
|
|
1130
|
+
children,
|
|
1131
|
+
maxNotifications = 5,
|
|
1132
|
+
defaultAutoHideDuration = 6e3,
|
|
1133
|
+
position = { vertical: "top", horizontal: "right" },
|
|
1134
|
+
enabled = false
|
|
1135
|
+
// ✅ Por defecto DESACTIVADO
|
|
1136
|
+
}) => {
|
|
1137
|
+
const [notifications, setNotifications] = (0, import_react6.useState)([]);
|
|
1138
|
+
const showNotification = (0, import_react6.useCallback)(
|
|
1139
|
+
(message, severity = "info", options) => {
|
|
1140
|
+
if (!enabled) {
|
|
1141
|
+
return "";
|
|
1142
|
+
}
|
|
1143
|
+
const id = (0, import_uuid.v4)();
|
|
1144
|
+
const newNotification = {
|
|
1145
|
+
id,
|
|
1146
|
+
message,
|
|
1147
|
+
severity,
|
|
1148
|
+
autoHideDuration: options?.autoHideDuration ?? defaultAutoHideDuration,
|
|
1149
|
+
persistent: options?.persistent ?? false
|
|
1150
|
+
};
|
|
1151
|
+
setNotifications((prev) => {
|
|
1152
|
+
const updatedNotifications = prev.length >= maxNotifications ? prev.slice(-(maxNotifications - 1)) : prev;
|
|
1153
|
+
return [...updatedNotifications, newNotification];
|
|
1154
|
+
});
|
|
1155
|
+
return id;
|
|
1156
|
+
},
|
|
1157
|
+
[maxNotifications, defaultAutoHideDuration, enabled]
|
|
1158
|
+
);
|
|
1159
|
+
const hideNotification = (0, import_react6.useCallback)((id) => {
|
|
1160
|
+
setNotifications((prev) => prev.filter((notification) => notification.id !== id));
|
|
1161
|
+
}, []);
|
|
1162
|
+
const clearAllNotifications = (0, import_react6.useCallback)(() => {
|
|
1163
|
+
setNotifications([]);
|
|
1164
|
+
}, []);
|
|
1165
|
+
const value = {
|
|
1166
|
+
showNotification,
|
|
1167
|
+
hideNotification,
|
|
1168
|
+
clearAllNotifications
|
|
1169
|
+
};
|
|
1170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(GlobalNotificationContext.Provider, { value, children: [
|
|
1171
|
+
children,
|
|
1172
|
+
enabled && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_material.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1173
|
+
import_material.Box,
|
|
1174
|
+
{
|
|
1175
|
+
sx: {
|
|
1176
|
+
position: "fixed",
|
|
1177
|
+
zIndex: 9999,
|
|
1178
|
+
[position.vertical]: position.vertical === "top" ? 24 : 24,
|
|
1179
|
+
[position.horizontal]: position.horizontal === "right" ? 24 : position.horizontal === "left" ? 24 : "50%",
|
|
1180
|
+
...position.horizontal === "center" && {
|
|
1181
|
+
transform: "translateX(-50%)"
|
|
1182
|
+
},
|
|
1183
|
+
display: "flex",
|
|
1184
|
+
flexDirection: position.vertical === "top" ? "column" : "column-reverse",
|
|
1185
|
+
gap: 1,
|
|
1186
|
+
maxWidth: "400px",
|
|
1187
|
+
width: "auto"
|
|
1188
|
+
},
|
|
1189
|
+
children: notifications.map((notification) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(NotificationItem, { notification, onClose: () => hideNotification(notification.id) }, notification.id))
|
|
1190
|
+
}
|
|
1191
|
+
) })
|
|
1192
|
+
] });
|
|
1193
|
+
};
|
|
1194
|
+
var NotificationItem = ({ notification, onClose }) => {
|
|
1195
|
+
const [open, setOpen] = (0, import_react6.useState)(true);
|
|
1196
|
+
const handleClose = (0, import_react6.useCallback)(
|
|
1197
|
+
(_event, reason) => {
|
|
1198
|
+
if (reason === "clickaway") return;
|
|
1199
|
+
setOpen(false);
|
|
1200
|
+
setTimeout(onClose, 300);
|
|
1201
|
+
},
|
|
1202
|
+
[onClose]
|
|
1203
|
+
);
|
|
1204
|
+
(0, import_react6.useEffect)(() => {
|
|
1205
|
+
if (!notification.persistent && notification.autoHideDuration) {
|
|
1206
|
+
const timer = setTimeout(() => {
|
|
1207
|
+
handleClose();
|
|
1208
|
+
}, notification.autoHideDuration);
|
|
1209
|
+
return () => clearTimeout(timer);
|
|
1210
|
+
}
|
|
1211
|
+
}, [notification.autoHideDuration, notification.persistent, handleClose]);
|
|
1212
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1213
|
+
import_material.Snackbar,
|
|
1214
|
+
{
|
|
1215
|
+
open,
|
|
1216
|
+
onClose: handleClose,
|
|
1217
|
+
sx: {
|
|
1218
|
+
position: "relative",
|
|
1219
|
+
"& .MuiSnackbarContent-root": {
|
|
1220
|
+
minWidth: "auto"
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
TransitionProps: {
|
|
1224
|
+
enter: true,
|
|
1225
|
+
exit: true
|
|
1226
|
+
},
|
|
1227
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1228
|
+
import_material.Alert,
|
|
1229
|
+
{
|
|
1230
|
+
variant: "filled",
|
|
1231
|
+
severity: notification.severity,
|
|
1232
|
+
onClose: handleClose,
|
|
1233
|
+
sx: {
|
|
1234
|
+
width: "100%",
|
|
1235
|
+
minWidth: "280px",
|
|
1236
|
+
maxWidth: "400px",
|
|
1237
|
+
wordBreak: "break-word"
|
|
1238
|
+
},
|
|
1239
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { dangerouslySetInnerHTML: { __html: notification.message } })
|
|
1240
|
+
}
|
|
1241
|
+
)
|
|
1242
|
+
}
|
|
1243
|
+
);
|
|
1244
|
+
};
|
|
1245
|
+
var useGlobalNotification = () => {
|
|
1246
|
+
const context = (0, import_react6.useContext)(GlobalNotificationContext);
|
|
1247
|
+
if (!context) {
|
|
1248
|
+
throw new Error("useGlobalNotification debe ser usado dentro de un GlobalNotificationProvider");
|
|
1249
|
+
}
|
|
1250
|
+
return context;
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
// src/providers/SessionProvider.tsx
|
|
1254
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1255
|
+
var SessionContext = (0, import_react7.createContext)(void 0);
|
|
1256
|
+
function SessionProvider({
|
|
1257
|
+
children,
|
|
1258
|
+
options = {},
|
|
1259
|
+
config: propConfig,
|
|
1260
|
+
showNotifications = false,
|
|
1261
|
+
// ✅ Por defecto DESACTIVADO
|
|
1262
|
+
notificationOptions = {}
|
|
1263
|
+
}) {
|
|
1120
1264
|
const sessionHook = useSession(options);
|
|
1121
|
-
const resolvedConfig = (0,
|
|
1265
|
+
const resolvedConfig = (0, import_react7.useMemo)(() => {
|
|
1122
1266
|
let publicApiKey;
|
|
1123
1267
|
let env;
|
|
1124
1268
|
let appName;
|
|
@@ -1180,7 +1324,7 @@ function SessionProvider({ children, options = {}, config: propConfig }) {
|
|
|
1180
1324
|
colors
|
|
1181
1325
|
};
|
|
1182
1326
|
}, [propConfig]);
|
|
1183
|
-
const sessionData = (0,
|
|
1327
|
+
const sessionData = (0, import_react7.useMemo)(() => {
|
|
1184
1328
|
if (!sessionHook.tokens?.accessToken || !sessionHook.isAuthenticated) {
|
|
1185
1329
|
return null;
|
|
1186
1330
|
}
|
|
@@ -1209,35 +1353,41 @@ function SessionProvider({ children, options = {}, config: propConfig }) {
|
|
|
1209
1353
|
sessionData,
|
|
1210
1354
|
config: resolvedConfig
|
|
1211
1355
|
};
|
|
1212
|
-
|
|
1356
|
+
const notificationConfig = {
|
|
1357
|
+
enabled: showNotifications,
|
|
1358
|
+
maxNotifications: notificationOptions.maxNotifications || 5,
|
|
1359
|
+
defaultAutoHideDuration: notificationOptions.defaultAutoHideDuration || 6e3,
|
|
1360
|
+
position: notificationOptions.position || { vertical: "top", horizontal: "right" }
|
|
1361
|
+
};
|
|
1362
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(GlobalNotificationProvider, { ...notificationConfig, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SessionContext.Provider, { value: contextValue, children }) });
|
|
1213
1363
|
}
|
|
1214
1364
|
function useSessionContext() {
|
|
1215
|
-
const context = (0,
|
|
1365
|
+
const context = (0, import_react7.useContext)(SessionContext);
|
|
1216
1366
|
if (context === void 0) {
|
|
1217
1367
|
throw new Error("useSessionContext must be used within a SessionProvider");
|
|
1218
1368
|
}
|
|
1219
1369
|
return context;
|
|
1220
1370
|
}
|
|
1221
|
-
function ProtectedRoute({ children, fallback = /* @__PURE__ */ (0,
|
|
1371
|
+
function ProtectedRoute({ children, fallback = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: "Please log in to access this content" }), redirectTo }) {
|
|
1222
1372
|
const { isAuthenticated, isLoading, isInitialized } = useSessionContext();
|
|
1223
1373
|
if (!isInitialized || isLoading) {
|
|
1224
|
-
return /* @__PURE__ */ (0,
|
|
1374
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: "Loading..." });
|
|
1225
1375
|
}
|
|
1226
1376
|
if (!isAuthenticated) {
|
|
1227
1377
|
if (redirectTo) {
|
|
1228
1378
|
redirectTo();
|
|
1229
1379
|
return null;
|
|
1230
1380
|
}
|
|
1231
|
-
return /* @__PURE__ */ (0,
|
|
1381
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: fallback });
|
|
1232
1382
|
}
|
|
1233
|
-
return /* @__PURE__ */ (0,
|
|
1383
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children });
|
|
1234
1384
|
}
|
|
1235
1385
|
function SessionDebugInfo() {
|
|
1236
1386
|
const session = useSessionContext();
|
|
1237
1387
|
if (!session.isInitialized) {
|
|
1238
|
-
return /* @__PURE__ */ (0,
|
|
1388
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: "Session not initialized" });
|
|
1239
1389
|
}
|
|
1240
|
-
return /* @__PURE__ */ (0,
|
|
1390
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1241
1391
|
"div",
|
|
1242
1392
|
{
|
|
1243
1393
|
style: {
|
|
@@ -1249,49 +1399,49 @@ function SessionDebugInfo() {
|
|
|
1249
1399
|
fontFamily: "monospace"
|
|
1250
1400
|
},
|
|
1251
1401
|
children: [
|
|
1252
|
-
/* @__PURE__ */ (0,
|
|
1253
|
-
/* @__PURE__ */ (0,
|
|
1254
|
-
/* @__PURE__ */ (0,
|
|
1402
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h4", { children: "Session Debug Info" }),
|
|
1403
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1404
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Authenticated:" }),
|
|
1255
1405
|
" ",
|
|
1256
1406
|
session.isAuthenticated ? "Yes" : "No"
|
|
1257
1407
|
] }),
|
|
1258
|
-
/* @__PURE__ */ (0,
|
|
1259
|
-
/* @__PURE__ */ (0,
|
|
1408
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1409
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Loading:" }),
|
|
1260
1410
|
" ",
|
|
1261
1411
|
session.isLoading ? "Yes" : "No"
|
|
1262
1412
|
] }),
|
|
1263
|
-
/* @__PURE__ */ (0,
|
|
1264
|
-
/* @__PURE__ */ (0,
|
|
1413
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1414
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Error:" }),
|
|
1265
1415
|
" ",
|
|
1266
1416
|
session.error || "None"
|
|
1267
1417
|
] }),
|
|
1268
|
-
session.tokens && /* @__PURE__ */ (0,
|
|
1269
|
-
/* @__PURE__ */ (0,
|
|
1270
|
-
/* @__PURE__ */ (0,
|
|
1418
|
+
session.tokens && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1419
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1420
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Access Token:" }),
|
|
1271
1421
|
" ",
|
|
1272
1422
|
session.tokens.accessToken.substring(0, 20),
|
|
1273
1423
|
"..."
|
|
1274
1424
|
] }),
|
|
1275
|
-
/* @__PURE__ */ (0,
|
|
1276
|
-
/* @__PURE__ */ (0,
|
|
1425
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1426
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Refresh Token:" }),
|
|
1277
1427
|
" ",
|
|
1278
1428
|
session.tokens.refreshToken.substring(0, 20),
|
|
1279
1429
|
"..."
|
|
1280
1430
|
] }),
|
|
1281
|
-
/* @__PURE__ */ (0,
|
|
1282
|
-
/* @__PURE__ */ (0,
|
|
1431
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1432
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Access Expires In:" }),
|
|
1283
1433
|
" ",
|
|
1284
1434
|
Math.round(session.expiresIn / 1e3 / 60),
|
|
1285
1435
|
" minutes"
|
|
1286
1436
|
] }),
|
|
1287
|
-
/* @__PURE__ */ (0,
|
|
1288
|
-
/* @__PURE__ */ (0,
|
|
1437
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1438
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Refresh Expires In:" }),
|
|
1289
1439
|
" ",
|
|
1290
1440
|
Math.round(session.refreshExpiresIn / 1e3 / 60 / 60),
|
|
1291
1441
|
" hours"
|
|
1292
1442
|
] }),
|
|
1293
|
-
/* @__PURE__ */ (0,
|
|
1294
|
-
/* @__PURE__ */ (0,
|
|
1443
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1444
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Expiring Soon:" }),
|
|
1295
1445
|
" ",
|
|
1296
1446
|
session.isExpiringSoon ? "Yes" : "No"
|
|
1297
1447
|
] })
|
|
@@ -1302,8 +1452,8 @@ function SessionDebugInfo() {
|
|
|
1302
1452
|
}
|
|
1303
1453
|
|
|
1304
1454
|
// src/components/CrudifyLogin/Forms/LoginForm.tsx
|
|
1305
|
-
var
|
|
1306
|
-
var
|
|
1455
|
+
var import_react8 = require("react");
|
|
1456
|
+
var import_material2 = require("@mui/material");
|
|
1307
1457
|
|
|
1308
1458
|
// src/utils/errorHandler.ts
|
|
1309
1459
|
var ERROR_CODES = {
|
|
@@ -1575,14 +1725,158 @@ function handleCrudifyError(error) {
|
|
|
1575
1725
|
];
|
|
1576
1726
|
}
|
|
1577
1727
|
|
|
1728
|
+
// src/utils/errorTranslation.ts
|
|
1729
|
+
var ERROR_TRANSLATION_HIERARCHY = [
|
|
1730
|
+
"errors.{category}.{code}",
|
|
1731
|
+
// errors.auth.INVALID_CREDENTIALS
|
|
1732
|
+
"errors.{code}",
|
|
1733
|
+
// errors.INVALID_CREDENTIALS
|
|
1734
|
+
"login.{code}",
|
|
1735
|
+
// login.INVALID_CREDENTIALS (legacy)
|
|
1736
|
+
"error.{code}",
|
|
1737
|
+
// error.INVALID_CREDENTIALS (singular)
|
|
1738
|
+
"messages.{code}",
|
|
1739
|
+
// messages.INVALID_CREDENTIALS
|
|
1740
|
+
"{code}"
|
|
1741
|
+
// INVALID_CREDENTIALS (direct)
|
|
1742
|
+
];
|
|
1743
|
+
var ERROR_CATEGORY_MAP = {
|
|
1744
|
+
// Authentication errors
|
|
1745
|
+
"INVALID_CREDENTIALS": "auth",
|
|
1746
|
+
"UNAUTHORIZED": "auth",
|
|
1747
|
+
"INVALID_API_KEY": "auth",
|
|
1748
|
+
"USER_NOT_FOUND": "auth",
|
|
1749
|
+
"USER_NOT_ACTIVE": "auth",
|
|
1750
|
+
"NO_PERMISSION": "auth",
|
|
1751
|
+
"SESSION_EXPIRED": "auth",
|
|
1752
|
+
// Data errors
|
|
1753
|
+
"ITEM_NOT_FOUND": "data",
|
|
1754
|
+
"NOT_FOUND": "data",
|
|
1755
|
+
"IN_USE": "data",
|
|
1756
|
+
"DUPLICATE_ENTRY": "data",
|
|
1757
|
+
// Validation errors
|
|
1758
|
+
"FIELD_ERROR": "validation",
|
|
1759
|
+
"BAD_REQUEST": "validation",
|
|
1760
|
+
"INVALID_EMAIL": "validation",
|
|
1761
|
+
"INVALID_CODE": "validation",
|
|
1762
|
+
"REQUIRED_FIELD": "validation",
|
|
1763
|
+
// System errors
|
|
1764
|
+
"INTERNAL_SERVER_ERROR": "system",
|
|
1765
|
+
"DATABASE_CONNECTION_ERROR": "system",
|
|
1766
|
+
"INVALID_CONFIGURATION": "system",
|
|
1767
|
+
"UNKNOWN_OPERATION": "system",
|
|
1768
|
+
"TIMEOUT_ERROR": "system",
|
|
1769
|
+
"NETWORK_ERROR": "system",
|
|
1770
|
+
// Rate limiting
|
|
1771
|
+
"TOO_MANY_REQUESTS": "rate_limit"
|
|
1772
|
+
};
|
|
1773
|
+
var DEFAULT_ERROR_MESSAGES = {
|
|
1774
|
+
"INVALID_CREDENTIALS": "Invalid username or password",
|
|
1775
|
+
"UNAUTHORIZED": "You are not authorized to perform this action",
|
|
1776
|
+
"USER_NOT_FOUND": "User not found",
|
|
1777
|
+
"ITEM_NOT_FOUND": "Item not found",
|
|
1778
|
+
"FIELD_ERROR": "Invalid field value",
|
|
1779
|
+
"INTERNAL_SERVER_ERROR": "An internal error occurred",
|
|
1780
|
+
"NETWORK_ERROR": "Network connection error",
|
|
1781
|
+
"TIMEOUT_ERROR": "Request timeout",
|
|
1782
|
+
"UNKNOWN_OPERATION": "Unknown operation",
|
|
1783
|
+
"INVALID_EMAIL": "Invalid email format",
|
|
1784
|
+
"INVALID_CODE": "Invalid code",
|
|
1785
|
+
"TOO_MANY_REQUESTS": "Too many requests, please try again later"
|
|
1786
|
+
};
|
|
1787
|
+
function translateErrorCode(errorCode, config) {
|
|
1788
|
+
const { translateFn, currentLanguage, enableDebug } = config;
|
|
1789
|
+
if (enableDebug) {
|
|
1790
|
+
console.log(`\u{1F50D} [ErrorTranslation] Translating error code: ${errorCode} (lang: ${currentLanguage || "unknown"})`);
|
|
1791
|
+
}
|
|
1792
|
+
const normalizedCode = errorCode.toUpperCase();
|
|
1793
|
+
const category = ERROR_CATEGORY_MAP[normalizedCode];
|
|
1794
|
+
const translationKeys = ERROR_TRANSLATION_HIERARCHY.map((pattern) => {
|
|
1795
|
+
return pattern.replace("{category}", category || "general").replace("{code}", normalizedCode);
|
|
1796
|
+
});
|
|
1797
|
+
if (enableDebug) {
|
|
1798
|
+
console.log(`\u{1F511} [ErrorTranslation] Searching keys:`, translationKeys);
|
|
1799
|
+
}
|
|
1800
|
+
for (const key of translationKeys) {
|
|
1801
|
+
const translated = translateFn(key);
|
|
1802
|
+
if (translated && translated !== key) {
|
|
1803
|
+
if (enableDebug) {
|
|
1804
|
+
console.log(`\u2705 [ErrorTranslation] Found translation at key: ${key} = "${translated}"`);
|
|
1805
|
+
}
|
|
1806
|
+
return translated;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
const defaultMessage = DEFAULT_ERROR_MESSAGES[normalizedCode];
|
|
1810
|
+
if (defaultMessage) {
|
|
1811
|
+
if (enableDebug) {
|
|
1812
|
+
console.log(`\u{1F504} [ErrorTranslation] Using default message: "${defaultMessage}"`);
|
|
1813
|
+
}
|
|
1814
|
+
return defaultMessage;
|
|
1815
|
+
}
|
|
1816
|
+
const friendlyCode = normalizedCode.replace(/_/g, " ").toLowerCase().replace(/\b\w/g, (l) => l.toUpperCase());
|
|
1817
|
+
if (enableDebug) {
|
|
1818
|
+
console.log(`\u26A0\uFE0F [ErrorTranslation] No translation found, using friendly code: "${friendlyCode}"`);
|
|
1819
|
+
}
|
|
1820
|
+
return friendlyCode;
|
|
1821
|
+
}
|
|
1822
|
+
function translateErrorCodes(errorCodes, config) {
|
|
1823
|
+
return errorCodes.map((code) => translateErrorCode(code, config));
|
|
1824
|
+
}
|
|
1825
|
+
function translateError(error, config) {
|
|
1826
|
+
const { enableDebug } = config;
|
|
1827
|
+
if (enableDebug) {
|
|
1828
|
+
console.log(`\u{1F50D} [ErrorTranslation] Translating error:`, error);
|
|
1829
|
+
}
|
|
1830
|
+
if (error.message && !error.message.includes("Error:") && error.message.length > 0) {
|
|
1831
|
+
if (enableDebug) {
|
|
1832
|
+
console.log(`\u2705 [ErrorTranslation] Using API message: "${error.message}"`);
|
|
1833
|
+
}
|
|
1834
|
+
return error.message;
|
|
1835
|
+
}
|
|
1836
|
+
const translatedCode = translateErrorCode(error.code, config);
|
|
1837
|
+
if (error.field) {
|
|
1838
|
+
return `${error.field}: ${translatedCode}`;
|
|
1839
|
+
}
|
|
1840
|
+
return translatedCode;
|
|
1841
|
+
}
|
|
1842
|
+
function createErrorTranslator(translateFn, options = {}) {
|
|
1843
|
+
const config = {
|
|
1844
|
+
translateFn,
|
|
1845
|
+
currentLanguage: options.currentLanguage,
|
|
1846
|
+
enableDebug: options.enableDebug || false
|
|
1847
|
+
};
|
|
1848
|
+
return {
|
|
1849
|
+
translateErrorCode: (code) => translateErrorCode(code, config),
|
|
1850
|
+
translateErrorCodes: (codes) => translateErrorCodes(codes, config),
|
|
1851
|
+
translateError: (error) => translateError(error, config),
|
|
1852
|
+
// Método de conveniencia para errores de API
|
|
1853
|
+
translateApiError: (apiResponse) => {
|
|
1854
|
+
if (apiResponse?.data?.response?.status) {
|
|
1855
|
+
return translateErrorCode(apiResponse.data.response.status, config);
|
|
1856
|
+
}
|
|
1857
|
+
if (apiResponse?.status) {
|
|
1858
|
+
return translateErrorCode(apiResponse.status, config);
|
|
1859
|
+
}
|
|
1860
|
+
if (apiResponse?.code) {
|
|
1861
|
+
return translateErrorCode(apiResponse.code, config);
|
|
1862
|
+
}
|
|
1863
|
+
return "Unknown error";
|
|
1864
|
+
}
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1578
1868
|
// src/components/CrudifyLogin/Forms/LoginForm.tsx
|
|
1579
|
-
var
|
|
1869
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1580
1870
|
var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError, redirectUrl = "/" }) => {
|
|
1581
|
-
const { crudify:
|
|
1871
|
+
const { crudify: crudify7 } = useCrudify();
|
|
1582
1872
|
const { state, updateFormData, setFieldError, clearErrors, setLoading } = useLoginState();
|
|
1583
1873
|
const { login: sessionLogin } = useSessionContext();
|
|
1584
|
-
const { t } = useTranslation();
|
|
1585
|
-
const usernameInputRef = (0,
|
|
1874
|
+
const { t, i18n } = useTranslation();
|
|
1875
|
+
const usernameInputRef = (0, import_react8.useRef)(null);
|
|
1876
|
+
const errorTranslator = createErrorTranslator(t, {
|
|
1877
|
+
currentLanguage: i18n?.language,
|
|
1878
|
+
enableDebug: process.env.NODE_ENV === "development"
|
|
1879
|
+
});
|
|
1586
1880
|
const getRedirectUrl = () => {
|
|
1587
1881
|
if (state.searchParams.redirect) {
|
|
1588
1882
|
try {
|
|
@@ -1595,27 +1889,18 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1595
1889
|
}
|
|
1596
1890
|
return redirectUrl || "/";
|
|
1597
1891
|
};
|
|
1598
|
-
(0,
|
|
1892
|
+
(0, import_react8.useEffect)(() => {
|
|
1599
1893
|
const timer = setTimeout(() => {
|
|
1600
1894
|
if (usernameInputRef.current) usernameInputRef.current.focus();
|
|
1601
1895
|
}, 100);
|
|
1602
1896
|
return () => clearTimeout(timer);
|
|
1603
1897
|
}, []);
|
|
1604
|
-
const
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
`login.${parsedError.code.toLowerCase()}`
|
|
1611
|
-
];
|
|
1612
|
-
for (const key of possibleKeys) {
|
|
1613
|
-
const translated = t(key);
|
|
1614
|
-
if (translated !== key) {
|
|
1615
|
-
return translated;
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
return parsedError.message || t("error.unknown");
|
|
1898
|
+
const translateError2 = (parsedError) => {
|
|
1899
|
+
return errorTranslator.translateError({
|
|
1900
|
+
code: parsedError.code,
|
|
1901
|
+
message: parsedError.message,
|
|
1902
|
+
field: parsedError.field
|
|
1903
|
+
});
|
|
1619
1904
|
};
|
|
1620
1905
|
const handleLogin = async () => {
|
|
1621
1906
|
if (state.loading) return;
|
|
@@ -1645,7 +1930,7 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1645
1930
|
} catch (error) {
|
|
1646
1931
|
setLoading(false);
|
|
1647
1932
|
const parsedErrors = handleCrudifyError(error);
|
|
1648
|
-
const translatedErrors = parsedErrors.map(
|
|
1933
|
+
const translatedErrors = parsedErrors.map(translateError2);
|
|
1649
1934
|
setFieldError("global", translatedErrors);
|
|
1650
1935
|
if (onError) {
|
|
1651
1936
|
onError(translatedErrors.join(", "));
|
|
@@ -1656,10 +1941,10 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1656
1941
|
const parsedErrors = handleCrudifyError(response);
|
|
1657
1942
|
parsedErrors.forEach((error) => {
|
|
1658
1943
|
if (error.field) {
|
|
1659
|
-
setFieldError(error.field,
|
|
1944
|
+
setFieldError(error.field, translateError2(error));
|
|
1660
1945
|
} else {
|
|
1661
1946
|
const currentGlobalErrors = state.errors.global || [];
|
|
1662
|
-
setFieldError("global", [...currentGlobalErrors,
|
|
1947
|
+
setFieldError("global", [...currentGlobalErrors, translateError2(error)]);
|
|
1663
1948
|
}
|
|
1664
1949
|
});
|
|
1665
1950
|
};
|
|
@@ -1673,9 +1958,9 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1673
1958
|
handleLogin();
|
|
1674
1959
|
}
|
|
1675
1960
|
};
|
|
1676
|
-
return /* @__PURE__ */ (0,
|
|
1677
|
-
/* @__PURE__ */ (0,
|
|
1678
|
-
|
|
1961
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1962
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1963
|
+
import_material2.Box,
|
|
1679
1964
|
{
|
|
1680
1965
|
component: "form",
|
|
1681
1966
|
noValidate: true,
|
|
@@ -1683,9 +1968,9 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1683
1968
|
onKeyDown: handleKeyDown,
|
|
1684
1969
|
sx: { width: "100%", display: "flex", flexDirection: "column", gap: 2 },
|
|
1685
1970
|
children: [
|
|
1686
|
-
/* @__PURE__ */ (0,
|
|
1687
|
-
/* @__PURE__ */ (0,
|
|
1688
|
-
|
|
1971
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_material2.Box, { sx: { mb: 1 }, children: [
|
|
1972
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1973
|
+
import_material2.Typography,
|
|
1689
1974
|
{
|
|
1690
1975
|
variant: "body2",
|
|
1691
1976
|
component: "label",
|
|
@@ -1694,8 +1979,8 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1694
1979
|
children: t("login.usernameOrEmailLabel")
|
|
1695
1980
|
}
|
|
1696
1981
|
),
|
|
1697
|
-
/* @__PURE__ */ (0,
|
|
1698
|
-
|
|
1982
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1983
|
+
import_material2.TextField,
|
|
1699
1984
|
{
|
|
1700
1985
|
fullWidth: true,
|
|
1701
1986
|
id: "email",
|
|
@@ -1713,9 +1998,9 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1713
1998
|
}
|
|
1714
1999
|
)
|
|
1715
2000
|
] }),
|
|
1716
|
-
/* @__PURE__ */ (0,
|
|
1717
|
-
/* @__PURE__ */ (0,
|
|
1718
|
-
|
|
2001
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_material2.Box, { sx: { mb: 1 }, children: [
|
|
2002
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2003
|
+
import_material2.Typography,
|
|
1719
2004
|
{
|
|
1720
2005
|
variant: "body2",
|
|
1721
2006
|
component: "label",
|
|
@@ -1724,8 +2009,8 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1724
2009
|
children: t("login.passwordLabel")
|
|
1725
2010
|
}
|
|
1726
2011
|
),
|
|
1727
|
-
/* @__PURE__ */ (0,
|
|
1728
|
-
|
|
2012
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2013
|
+
import_material2.TextField,
|
|
1729
2014
|
{
|
|
1730
2015
|
fullWidth: true,
|
|
1731
2016
|
id: "password",
|
|
@@ -1742,8 +2027,8 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1742
2027
|
}
|
|
1743
2028
|
)
|
|
1744
2029
|
] }),
|
|
1745
|
-
state.config.loginActions?.includes("forgotPassword") && /* @__PURE__ */ (0,
|
|
1746
|
-
|
|
2030
|
+
state.config.loginActions?.includes("forgotPassword") && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material2.Box, { sx: { display: "flex", justifyContent: "flex-end", alignItems: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2031
|
+
import_material2.Link,
|
|
1747
2032
|
{
|
|
1748
2033
|
sx: { cursor: "pointer" },
|
|
1749
2034
|
onClick: () => {
|
|
@@ -1754,16 +2039,16 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1754
2039
|
children: t("login.forgotPasswordLink")
|
|
1755
2040
|
}
|
|
1756
2041
|
) }),
|
|
1757
|
-
/* @__PURE__ */ (0,
|
|
2042
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material2.Button, { disabled: state.loading, type: "submit", fullWidth: true, variant: "contained", color: "primary", sx: { mt: 1, mb: 2 }, children: state.loading ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material2.CircularProgress, { size: 20 }) : t("login.loginButton") })
|
|
1758
2043
|
]
|
|
1759
2044
|
}
|
|
1760
2045
|
),
|
|
1761
|
-
/* @__PURE__ */ (0,
|
|
1762
|
-
state.config.loginActions?.includes("createUser") && /* @__PURE__ */ (0,
|
|
2046
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material2.Box, { children: state.errors.global && state.errors.global.length > 0 && state.errors.global.map((error, index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material2.Alert, { variant: "filled", sx: { mt: 2 }, severity: "error", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { children: error }) }, index)) }),
|
|
2047
|
+
state.config.loginActions?.includes("createUser") && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_material2.Typography, { variant: "body2", align: "center", sx: { color: "text.secondary", mt: 3 }, children: [
|
|
1763
2048
|
t("login.noAccountPrompt"),
|
|
1764
2049
|
" ",
|
|
1765
|
-
/* @__PURE__ */ (0,
|
|
1766
|
-
|
|
2050
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2051
|
+
import_material2.Link,
|
|
1767
2052
|
{
|
|
1768
2053
|
sx: { cursor: "pointer" },
|
|
1769
2054
|
onClick: () => {
|
|
@@ -1782,19 +2067,19 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
1782
2067
|
var LoginForm_default = LoginForm;
|
|
1783
2068
|
|
|
1784
2069
|
// src/components/CrudifyLogin/Forms/ForgotPasswordForm.tsx
|
|
1785
|
-
var
|
|
1786
|
-
var
|
|
1787
|
-
var
|
|
2070
|
+
var import_react9 = require("react");
|
|
2071
|
+
var import_material3 = require("@mui/material");
|
|
2072
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1788
2073
|
var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
1789
|
-
const { crudify:
|
|
1790
|
-
const [email, setEmail] = (0,
|
|
1791
|
-
const [loading, setLoading] = (0,
|
|
1792
|
-
const [errors, setErrors] = (0,
|
|
1793
|
-
const [helperTextEmail, setHelperTextEmail] = (0,
|
|
1794
|
-
const [emailSent, setEmailSent] = (0,
|
|
1795
|
-
const [codeAlreadyExists, setCodeAlreadyExists] = (0,
|
|
2074
|
+
const { crudify: crudify7 } = useCrudify();
|
|
2075
|
+
const [email, setEmail] = (0, import_react9.useState)("");
|
|
2076
|
+
const [loading, setLoading] = (0, import_react9.useState)(false);
|
|
2077
|
+
const [errors, setErrors] = (0, import_react9.useState)([]);
|
|
2078
|
+
const [helperTextEmail, setHelperTextEmail] = (0, import_react9.useState)(null);
|
|
2079
|
+
const [emailSent, setEmailSent] = (0, import_react9.useState)(false);
|
|
2080
|
+
const [codeAlreadyExists, setCodeAlreadyExists] = (0, import_react9.useState)(false);
|
|
1796
2081
|
const { t } = useTranslation();
|
|
1797
|
-
const
|
|
2082
|
+
const translateError2 = (parsedError) => {
|
|
1798
2083
|
const possibleKeys = [
|
|
1799
2084
|
`errors.auth.${parsedError.code}`,
|
|
1800
2085
|
`errors.data.${parsedError.code}`,
|
|
@@ -1815,7 +2100,7 @@ var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
|
1815
2100
|
return emailRegex.test(email2);
|
|
1816
2101
|
};
|
|
1817
2102
|
const handleSubmit = async () => {
|
|
1818
|
-
if (loading || !
|
|
2103
|
+
if (loading || !crudify7) return;
|
|
1819
2104
|
setErrors([]);
|
|
1820
2105
|
setHelperTextEmail(null);
|
|
1821
2106
|
if (!email) {
|
|
@@ -1829,7 +2114,7 @@ var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
|
1829
2114
|
setLoading(true);
|
|
1830
2115
|
try {
|
|
1831
2116
|
const data = [{ operation: "requestPasswordReset", data: { email } }];
|
|
1832
|
-
const response = await
|
|
2117
|
+
const response = await crudify7.transaction(data);
|
|
1833
2118
|
if (response.success) {
|
|
1834
2119
|
if (response.data && response.data.existingCodeValid) {
|
|
1835
2120
|
setCodeAlreadyExists(true);
|
|
@@ -1838,12 +2123,12 @@ var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
|
1838
2123
|
}
|
|
1839
2124
|
} else {
|
|
1840
2125
|
const parsedErrors = handleCrudifyError(response);
|
|
1841
|
-
const translatedErrors = parsedErrors.map(
|
|
2126
|
+
const translatedErrors = parsedErrors.map(translateError2);
|
|
1842
2127
|
setErrors(translatedErrors);
|
|
1843
2128
|
}
|
|
1844
2129
|
} catch (error) {
|
|
1845
2130
|
const parsedErrors = handleCrudifyError(error);
|
|
1846
|
-
const translatedErrors = parsedErrors.map(
|
|
2131
|
+
const translatedErrors = parsedErrors.map(translateError2);
|
|
1847
2132
|
setErrors(translatedErrors);
|
|
1848
2133
|
if (onError) {
|
|
1849
2134
|
onError(translatedErrors.join(", "));
|
|
@@ -1871,24 +2156,24 @@ var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
|
1871
2156
|
onScreenChange?.("checkCode", { email });
|
|
1872
2157
|
};
|
|
1873
2158
|
if (emailSent || codeAlreadyExists) {
|
|
1874
|
-
return /* @__PURE__ */ (0,
|
|
1875
|
-
/* @__PURE__ */ (0,
|
|
1876
|
-
/* @__PURE__ */ (0,
|
|
1877
|
-
/* @__PURE__ */ (0,
|
|
2159
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material3.Box, { sx: { width: "100%", display: "flex", flexDirection: "column", gap: 2, textAlign: "center" }, children: [
|
|
2160
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material3.Box, { sx: { mb: 2 }, children: [
|
|
2161
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Typography, { variant: "h5", component: "h1", sx: { mb: 1, fontWeight: 600 }, children: codeAlreadyExists ? t("forgotPassword.codeAlreadyExistsMessage") : t("forgotPassword.emailSentMessage") }),
|
|
2162
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Typography, { variant: "body2", sx: { color: codeAlreadyExists ? "success.main" : "grey.600" }, children: codeAlreadyExists ? t("forgotPassword.checkEmailInstructions") : t("forgotPassword.checkEmailInstructions") })
|
|
1878
2163
|
] }),
|
|
1879
|
-
/* @__PURE__ */ (0,
|
|
1880
|
-
/* @__PURE__ */ (0,
|
|
2164
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Button, { type: "button", onClick: handleGoToCheckCode, fullWidth: true, variant: "contained", color: "primary", sx: { mt: 2, mb: 2 }, children: t("forgotPassword.enterCodeLink") }),
|
|
2165
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Box, { sx: { display: "flex", justifyContent: "center", alignItems: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Link, { sx: { cursor: "pointer" }, onClick: handleBack, variant: "body2", color: "secondary", children: t("common.back") }) })
|
|
1881
2166
|
] }) });
|
|
1882
2167
|
}
|
|
1883
|
-
return /* @__PURE__ */ (0,
|
|
1884
|
-
/* @__PURE__ */ (0,
|
|
1885
|
-
/* @__PURE__ */ (0,
|
|
1886
|
-
/* @__PURE__ */ (0,
|
|
1887
|
-
/* @__PURE__ */ (0,
|
|
2168
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
2169
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material3.Box, { component: "form", noValidate: true, sx: { width: "100%", display: "flex", flexDirection: "column", gap: 2 }, children: [
|
|
2170
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material3.Box, { sx: { mb: 2 }, children: [
|
|
2171
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Typography, { variant: "h5", component: "h1", sx: { mb: 1, fontWeight: 600 }, children: t("forgotPassword.title") }),
|
|
2172
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Typography, { variant: "body2", sx: { color: "grey.600" }, children: t("forgotPassword.instructions") })
|
|
1888
2173
|
] }),
|
|
1889
|
-
/* @__PURE__ */ (0,
|
|
1890
|
-
/* @__PURE__ */ (0,
|
|
1891
|
-
|
|
2174
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material3.Box, { sx: { mb: 1 }, children: [
|
|
2175
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2176
|
+
import_material3.Typography,
|
|
1892
2177
|
{
|
|
1893
2178
|
variant: "body2",
|
|
1894
2179
|
component: "label",
|
|
@@ -1897,8 +2182,8 @@ var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
|
1897
2182
|
children: t("forgotPassword.emailLabel")
|
|
1898
2183
|
}
|
|
1899
2184
|
),
|
|
1900
|
-
/* @__PURE__ */ (0,
|
|
1901
|
-
|
|
2185
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2186
|
+
import_material3.TextField,
|
|
1902
2187
|
{
|
|
1903
2188
|
fullWidth: true,
|
|
1904
2189
|
id: "email",
|
|
@@ -1915,39 +2200,39 @@ var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
|
1915
2200
|
}
|
|
1916
2201
|
)
|
|
1917
2202
|
] }),
|
|
1918
|
-
/* @__PURE__ */ (0,
|
|
1919
|
-
/* @__PURE__ */ (0,
|
|
1920
|
-
/* @__PURE__ */ (0,
|
|
1921
|
-
/* @__PURE__ */ (0,
|
|
1922
|
-
/* @__PURE__ */ (0,
|
|
2203
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Button, { disabled: loading, type: "button", onClick: handleSubmit, fullWidth: true, variant: "contained", color: "primary", sx: { mt: 2, mb: 2 }, children: loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.CircularProgress, { size: 20 }) : t("forgotPassword.sendCodeButton") }),
|
|
2204
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material3.Box, { sx: { display: "flex", justifyContent: "center", alignItems: "center", gap: 2 }, children: [
|
|
2205
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Link, { sx: { cursor: "pointer" }, onClick: handleBack, variant: "body2", color: "secondary", children: t("common.back") }),
|
|
2206
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Typography, { variant: "body2", sx: { color: "grey.400" }, children: "\u2022" }),
|
|
2207
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Link, { sx: { cursor: "pointer" }, onClick: handleGoToCheckCode, variant: "body2", color: "secondary", children: t("login.alreadyHaveCodeLink") })
|
|
1923
2208
|
] })
|
|
1924
2209
|
] }),
|
|
1925
|
-
/* @__PURE__ */ (0,
|
|
2210
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Box, { children: errors.length > 0 && errors.map((error, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material3.Alert, { variant: "filled", sx: { mt: 2 }, severity: "error", children: error }, index)) })
|
|
1926
2211
|
] });
|
|
1927
2212
|
};
|
|
1928
2213
|
var ForgotPasswordForm_default = ForgotPasswordForm;
|
|
1929
2214
|
|
|
1930
2215
|
// src/components/CrudifyLogin/Forms/ResetPasswordForm.tsx
|
|
1931
|
-
var
|
|
1932
|
-
var
|
|
1933
|
-
var
|
|
2216
|
+
var import_react10 = require("react");
|
|
2217
|
+
var import_material4 = require("@mui/material");
|
|
2218
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1934
2219
|
var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess }) => {
|
|
1935
|
-
const { crudify:
|
|
1936
|
-
const [newPassword, setNewPassword] = (0,
|
|
1937
|
-
const [confirmPassword, setConfirmPassword] = (0,
|
|
1938
|
-
const [loading, setLoading] = (0,
|
|
1939
|
-
const [errors, setErrors] = (0,
|
|
1940
|
-
const [helperTextNewPassword, setHelperTextNewPassword] = (0,
|
|
1941
|
-
const [helperTextConfirmPassword, setHelperTextConfirmPassword] = (0,
|
|
1942
|
-
const [email, setEmail] = (0,
|
|
1943
|
-
const [code, setCode] = (0,
|
|
1944
|
-
const [fromCodeVerification, setFromCodeVerification] = (0,
|
|
1945
|
-
const [validatingCode, setValidatingCode] = (0,
|
|
1946
|
-
const [codeValidated, setCodeValidated] = (0,
|
|
1947
|
-
const [pendingValidation, setPendingValidation] = (0,
|
|
1948
|
-
const [isValidating, setIsValidating] = (0,
|
|
2220
|
+
const { crudify: crudify7 } = useCrudify();
|
|
2221
|
+
const [newPassword, setNewPassword] = (0, import_react10.useState)("");
|
|
2222
|
+
const [confirmPassword, setConfirmPassword] = (0, import_react10.useState)("");
|
|
2223
|
+
const [loading, setLoading] = (0, import_react10.useState)(false);
|
|
2224
|
+
const [errors, setErrors] = (0, import_react10.useState)([]);
|
|
2225
|
+
const [helperTextNewPassword, setHelperTextNewPassword] = (0, import_react10.useState)(null);
|
|
2226
|
+
const [helperTextConfirmPassword, setHelperTextConfirmPassword] = (0, import_react10.useState)(null);
|
|
2227
|
+
const [email, setEmail] = (0, import_react10.useState)("");
|
|
2228
|
+
const [code, setCode] = (0, import_react10.useState)("");
|
|
2229
|
+
const [fromCodeVerification, setFromCodeVerification] = (0, import_react10.useState)(false);
|
|
2230
|
+
const [validatingCode, setValidatingCode] = (0, import_react10.useState)(true);
|
|
2231
|
+
const [codeValidated, setCodeValidated] = (0, import_react10.useState)(false);
|
|
2232
|
+
const [pendingValidation, setPendingValidation] = (0, import_react10.useState)(null);
|
|
2233
|
+
const [isValidating, setIsValidating] = (0, import_react10.useState)(false);
|
|
1949
2234
|
const { t } = useTranslation();
|
|
1950
|
-
const
|
|
2235
|
+
const translateError2 = (parsedError) => {
|
|
1951
2236
|
const possibleKeys = [
|
|
1952
2237
|
`errors.auth.${parsedError.code}`,
|
|
1953
2238
|
`errors.data.${parsedError.code}`,
|
|
@@ -1970,7 +2255,7 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
1970
2255
|
}
|
|
1971
2256
|
return searchParams[key] || null;
|
|
1972
2257
|
};
|
|
1973
|
-
(0,
|
|
2258
|
+
(0, import_react10.useEffect)(() => {
|
|
1974
2259
|
if (!searchParams) {
|
|
1975
2260
|
return;
|
|
1976
2261
|
}
|
|
@@ -2012,9 +2297,9 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2012
2297
|
setErrors([t("resetPassword.invalidCode")]);
|
|
2013
2298
|
setValidatingCode(false);
|
|
2014
2299
|
setTimeout(() => onScreenChange?.("forgotPassword"), 3e3);
|
|
2015
|
-
}, [searchParams,
|
|
2016
|
-
(0,
|
|
2017
|
-
if (
|
|
2300
|
+
}, [searchParams, crudify7, t, onScreenChange]);
|
|
2301
|
+
(0, import_react10.useEffect)(() => {
|
|
2302
|
+
if (crudify7 && pendingValidation && !isValidating) {
|
|
2018
2303
|
setIsValidating(true);
|
|
2019
2304
|
const validateCode = async (emailToValidate, codeToValidate) => {
|
|
2020
2305
|
try {
|
|
@@ -2024,7 +2309,7 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2024
2309
|
data: { email: emailToValidate, codePassword: codeToValidate }
|
|
2025
2310
|
}
|
|
2026
2311
|
];
|
|
2027
|
-
const response = await
|
|
2312
|
+
const response = await crudify7.transaction(data);
|
|
2028
2313
|
if (response.data && Array.isArray(response.data)) {
|
|
2029
2314
|
const validationResult = response.data[0];
|
|
2030
2315
|
if (validationResult && validationResult.response && validationResult.response.status === "OK") {
|
|
@@ -2036,13 +2321,13 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2036
2321
|
setCodeValidated(true);
|
|
2037
2322
|
} else {
|
|
2038
2323
|
const parsedErrors = handleCrudifyError(response);
|
|
2039
|
-
const translatedErrors = parsedErrors.map(
|
|
2324
|
+
const translatedErrors = parsedErrors.map(translateError2);
|
|
2040
2325
|
setErrors(translatedErrors);
|
|
2041
2326
|
setTimeout(() => onScreenChange?.("forgotPassword"), 3e3);
|
|
2042
2327
|
}
|
|
2043
2328
|
} catch (error) {
|
|
2044
2329
|
const parsedErrors = handleCrudifyError(error);
|
|
2045
|
-
const translatedErrors = parsedErrors.map(
|
|
2330
|
+
const translatedErrors = parsedErrors.map(translateError2);
|
|
2046
2331
|
setErrors(translatedErrors);
|
|
2047
2332
|
setTimeout(() => onScreenChange?.("forgotPassword"), 3e3);
|
|
2048
2333
|
} finally {
|
|
@@ -2053,7 +2338,7 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2053
2338
|
};
|
|
2054
2339
|
validateCode(pendingValidation.email, pendingValidation.code);
|
|
2055
2340
|
}
|
|
2056
|
-
}, [
|
|
2341
|
+
}, [crudify7, pendingValidation, t, onScreenChange]);
|
|
2057
2342
|
const validatePassword = (password) => {
|
|
2058
2343
|
if (password.length < 8) {
|
|
2059
2344
|
return t("resetPassword.passwordTooShort");
|
|
@@ -2061,7 +2346,7 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2061
2346
|
return null;
|
|
2062
2347
|
};
|
|
2063
2348
|
const handleSubmit = async () => {
|
|
2064
|
-
if (loading || !
|
|
2349
|
+
if (loading || !crudify7) return;
|
|
2065
2350
|
setErrors([]);
|
|
2066
2351
|
setHelperTextNewPassword(null);
|
|
2067
2352
|
setHelperTextConfirmPassword(null);
|
|
@@ -2092,7 +2377,7 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2092
2377
|
data: { email, codePassword: code, newPassword }
|
|
2093
2378
|
}
|
|
2094
2379
|
];
|
|
2095
|
-
const response = await
|
|
2380
|
+
const response = await crudify7.transaction(data);
|
|
2096
2381
|
if (response.success) {
|
|
2097
2382
|
setErrors([]);
|
|
2098
2383
|
setTimeout(() => {
|
|
@@ -2100,12 +2385,12 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2100
2385
|
}, 1e3);
|
|
2101
2386
|
} else {
|
|
2102
2387
|
const parsedErrors = handleCrudifyError(response);
|
|
2103
|
-
const translatedErrors = parsedErrors.map(
|
|
2388
|
+
const translatedErrors = parsedErrors.map(translateError2);
|
|
2104
2389
|
setErrors(translatedErrors);
|
|
2105
2390
|
}
|
|
2106
2391
|
} catch (error) {
|
|
2107
2392
|
const parsedErrors = handleCrudifyError(error);
|
|
2108
|
-
const translatedErrors = parsedErrors.map(
|
|
2393
|
+
const translatedErrors = parsedErrors.map(translateError2);
|
|
2109
2394
|
setErrors(translatedErrors);
|
|
2110
2395
|
if (onError) {
|
|
2111
2396
|
onError(translatedErrors.join(", "));
|
|
@@ -2121,20 +2406,20 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2121
2406
|
}
|
|
2122
2407
|
};
|
|
2123
2408
|
if (validatingCode) {
|
|
2124
|
-
return /* @__PURE__ */ (0,
|
|
2409
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Box, { sx: { display: "flex", justifyContent: "center", alignItems: "center", minHeight: "300px" }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.CircularProgress, {}) });
|
|
2125
2410
|
}
|
|
2126
2411
|
if (!codeValidated) {
|
|
2127
|
-
return /* @__PURE__ */ (0,
|
|
2412
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Box, { children: errors.length > 0 && errors.map((error, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Alert, { variant: "filled", sx: { mt: 2 }, severity: "error", children: error }, index)) });
|
|
2128
2413
|
}
|
|
2129
|
-
return /* @__PURE__ */ (0,
|
|
2130
|
-
/* @__PURE__ */ (0,
|
|
2131
|
-
/* @__PURE__ */ (0,
|
|
2132
|
-
/* @__PURE__ */ (0,
|
|
2133
|
-
/* @__PURE__ */ (0,
|
|
2414
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
2415
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_material4.Box, { component: "form", noValidate: true, sx: { width: "100%", display: "flex", flexDirection: "column", gap: 2 }, children: [
|
|
2416
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_material4.Box, { sx: { mb: 2 }, children: [
|
|
2417
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Typography, { variant: "h5", component: "h1", sx: { mb: 1, fontWeight: 600 }, children: t("resetPassword.title") }),
|
|
2418
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Typography, { variant: "body2", sx: { color: "grey.600" }, children: t("resetPassword.instructions") })
|
|
2134
2419
|
] }),
|
|
2135
|
-
/* @__PURE__ */ (0,
|
|
2136
|
-
/* @__PURE__ */ (0,
|
|
2137
|
-
|
|
2420
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_material4.Box, { sx: { mb: 1 }, children: [
|
|
2421
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2422
|
+
import_material4.Typography,
|
|
2138
2423
|
{
|
|
2139
2424
|
variant: "body2",
|
|
2140
2425
|
component: "label",
|
|
@@ -2143,8 +2428,8 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2143
2428
|
children: t("resetPassword.newPasswordLabel")
|
|
2144
2429
|
}
|
|
2145
2430
|
),
|
|
2146
|
-
/* @__PURE__ */ (0,
|
|
2147
|
-
|
|
2431
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2432
|
+
import_material4.TextField,
|
|
2148
2433
|
{
|
|
2149
2434
|
fullWidth: true,
|
|
2150
2435
|
id: "newPassword",
|
|
@@ -2161,9 +2446,9 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2161
2446
|
}
|
|
2162
2447
|
)
|
|
2163
2448
|
] }),
|
|
2164
|
-
/* @__PURE__ */ (0,
|
|
2165
|
-
/* @__PURE__ */ (0,
|
|
2166
|
-
|
|
2449
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_material4.Box, { sx: { mb: 1 }, children: [
|
|
2450
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2451
|
+
import_material4.Typography,
|
|
2167
2452
|
{
|
|
2168
2453
|
variant: "body2",
|
|
2169
2454
|
component: "label",
|
|
@@ -2172,8 +2457,8 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2172
2457
|
children: t("resetPassword.confirmPasswordLabel")
|
|
2173
2458
|
}
|
|
2174
2459
|
),
|
|
2175
|
-
/* @__PURE__ */ (0,
|
|
2176
|
-
|
|
2460
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2461
|
+
import_material4.TextField,
|
|
2177
2462
|
{
|
|
2178
2463
|
fullWidth: true,
|
|
2179
2464
|
id: "confirmPassword",
|
|
@@ -2190,25 +2475,25 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
2190
2475
|
}
|
|
2191
2476
|
)
|
|
2192
2477
|
] }),
|
|
2193
|
-
/* @__PURE__ */ (0,
|
|
2194
|
-
/* @__PURE__ */ (0,
|
|
2478
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Button, { disabled: loading, type: "button", onClick: handleSubmit, fullWidth: true, variant: "contained", color: "primary", sx: { mt: 2, mb: 2 }, children: loading ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.CircularProgress, { size: 20 }) : t("resetPassword.resetPasswordButton") }),
|
|
2479
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Box, { sx: { display: "flex", justifyContent: "center", alignItems: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Link, { sx: { cursor: "pointer" }, onClick: handleBack, variant: "body2", color: "secondary", children: t("common.back") }) })
|
|
2195
2480
|
] }),
|
|
2196
|
-
/* @__PURE__ */ (0,
|
|
2481
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Box, { children: errors.length > 0 && errors.map((error, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material4.Alert, { variant: "filled", sx: { mt: 2 }, severity: "error", children: error }, index)) })
|
|
2197
2482
|
] });
|
|
2198
2483
|
};
|
|
2199
2484
|
var ResetPasswordForm_default = ResetPasswordForm;
|
|
2200
2485
|
|
|
2201
2486
|
// src/components/CrudifyLogin/Forms/CheckCodeForm.tsx
|
|
2202
|
-
var
|
|
2203
|
-
var
|
|
2204
|
-
var
|
|
2487
|
+
var import_react11 = require("react");
|
|
2488
|
+
var import_material5 = require("@mui/material");
|
|
2489
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2205
2490
|
var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
2206
|
-
const { crudify:
|
|
2207
|
-
const [code, setCode] = (0,
|
|
2208
|
-
const [loading, setLoading] = (0,
|
|
2209
|
-
const [errors, setErrors] = (0,
|
|
2210
|
-
const [helperTextCode, setHelperTextCode] = (0,
|
|
2211
|
-
const [email, setEmail] = (0,
|
|
2491
|
+
const { crudify: crudify7 } = useCrudify();
|
|
2492
|
+
const [code, setCode] = (0, import_react11.useState)("");
|
|
2493
|
+
const [loading, setLoading] = (0, import_react11.useState)(false);
|
|
2494
|
+
const [errors, setErrors] = (0, import_react11.useState)([]);
|
|
2495
|
+
const [helperTextCode, setHelperTextCode] = (0, import_react11.useState)(null);
|
|
2496
|
+
const [email, setEmail] = (0, import_react11.useState)("");
|
|
2212
2497
|
const { t } = useTranslation();
|
|
2213
2498
|
const getParam = (key) => {
|
|
2214
2499
|
if (!searchParams) return null;
|
|
@@ -2217,7 +2502,7 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
2217
2502
|
}
|
|
2218
2503
|
return searchParams[key] || null;
|
|
2219
2504
|
};
|
|
2220
|
-
const
|
|
2505
|
+
const translateError2 = (parsedError) => {
|
|
2221
2506
|
const possibleKeys = [
|
|
2222
2507
|
`errors.auth.${parsedError.code}`,
|
|
2223
2508
|
`errors.data.${parsedError.code}`,
|
|
@@ -2233,7 +2518,7 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
2233
2518
|
}
|
|
2234
2519
|
return parsedError.message || t("error.unknown");
|
|
2235
2520
|
};
|
|
2236
|
-
(0,
|
|
2521
|
+
(0, import_react11.useEffect)(() => {
|
|
2237
2522
|
const emailParam = getParam("email");
|
|
2238
2523
|
if (emailParam) {
|
|
2239
2524
|
setEmail(emailParam);
|
|
@@ -2242,7 +2527,7 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
2242
2527
|
}
|
|
2243
2528
|
}, [searchParams, onScreenChange]);
|
|
2244
2529
|
const handleSubmit = async () => {
|
|
2245
|
-
if (loading || !
|
|
2530
|
+
if (loading || !crudify7) return;
|
|
2246
2531
|
setErrors([]);
|
|
2247
2532
|
setHelperTextCode(null);
|
|
2248
2533
|
if (!code) {
|
|
@@ -2261,18 +2546,18 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
2261
2546
|
data: { email, codePassword: code }
|
|
2262
2547
|
}
|
|
2263
2548
|
];
|
|
2264
|
-
const response = await
|
|
2549
|
+
const response = await crudify7.transaction(data);
|
|
2265
2550
|
if (response.success) {
|
|
2266
2551
|
onScreenChange?.("resetPassword", { email, code, fromCodeVerification: "true" });
|
|
2267
2552
|
} else {
|
|
2268
2553
|
const parsedErrors = handleCrudifyError(response);
|
|
2269
|
-
const translatedErrors = parsedErrors.map(
|
|
2554
|
+
const translatedErrors = parsedErrors.map(translateError2);
|
|
2270
2555
|
setErrors(translatedErrors);
|
|
2271
2556
|
setLoading(false);
|
|
2272
2557
|
}
|
|
2273
2558
|
} catch (error) {
|
|
2274
2559
|
const parsedErrors = handleCrudifyError(error);
|
|
2275
|
-
const translatedErrors = parsedErrors.map(
|
|
2560
|
+
const translatedErrors = parsedErrors.map(translateError2);
|
|
2276
2561
|
setErrors(translatedErrors);
|
|
2277
2562
|
setLoading(false);
|
|
2278
2563
|
if (onError) {
|
|
@@ -2287,15 +2572,15 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
2287
2572
|
const value = event.target.value.replace(/\D/g, "").slice(0, 6);
|
|
2288
2573
|
setCode(value);
|
|
2289
2574
|
};
|
|
2290
|
-
return /* @__PURE__ */ (0,
|
|
2291
|
-
/* @__PURE__ */ (0,
|
|
2292
|
-
/* @__PURE__ */ (0,
|
|
2293
|
-
/* @__PURE__ */ (0,
|
|
2294
|
-
/* @__PURE__ */ (0,
|
|
2575
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
2576
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_material5.Box, { component: "form", noValidate: true, sx: { width: "100%", display: "flex", flexDirection: "column", gap: 2 }, children: [
|
|
2577
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_material5.Box, { sx: { mb: 2 }, children: [
|
|
2578
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material5.Typography, { variant: "h5", component: "h1", sx: { mb: 1, fontWeight: 600 }, children: t("checkCode.title") }),
|
|
2579
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material5.Typography, { variant: "body2", sx: { color: "grey.600" }, children: t("checkCode.instructions") })
|
|
2295
2580
|
] }),
|
|
2296
|
-
/* @__PURE__ */ (0,
|
|
2297
|
-
/* @__PURE__ */ (0,
|
|
2298
|
-
|
|
2581
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_material5.Box, { sx: { mb: 1 }, children: [
|
|
2582
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2583
|
+
import_material5.Typography,
|
|
2299
2584
|
{
|
|
2300
2585
|
variant: "body2",
|
|
2301
2586
|
component: "label",
|
|
@@ -2304,8 +2589,8 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
2304
2589
|
children: t("checkCode.codeLabel")
|
|
2305
2590
|
}
|
|
2306
2591
|
),
|
|
2307
|
-
/* @__PURE__ */ (0,
|
|
2308
|
-
|
|
2592
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2593
|
+
import_material5.TextField,
|
|
2309
2594
|
{
|
|
2310
2595
|
fullWidth: true,
|
|
2311
2596
|
id: "code",
|
|
@@ -2325,8 +2610,8 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
2325
2610
|
}
|
|
2326
2611
|
)
|
|
2327
2612
|
] }),
|
|
2328
|
-
/* @__PURE__ */ (0,
|
|
2329
|
-
|
|
2613
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2614
|
+
import_material5.Button,
|
|
2330
2615
|
{
|
|
2331
2616
|
disabled: loading || code.length !== 6,
|
|
2332
2617
|
type: "button",
|
|
@@ -2335,25 +2620,25 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
2335
2620
|
variant: "contained",
|
|
2336
2621
|
color: "primary",
|
|
2337
2622
|
sx: { mt: 2, mb: 2 },
|
|
2338
|
-
children: loading ? /* @__PURE__ */ (0,
|
|
2623
|
+
children: loading ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material5.CircularProgress, { size: 20 }) : t("checkCode.verifyButton")
|
|
2339
2624
|
}
|
|
2340
2625
|
),
|
|
2341
|
-
/* @__PURE__ */ (0,
|
|
2626
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material5.Box, { sx: { display: "flex", justifyContent: "center", alignItems: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material5.Link, { sx: { cursor: "pointer" }, onClick: handleBack, variant: "body2", color: "secondary", children: t("common.back") }) })
|
|
2342
2627
|
] }),
|
|
2343
|
-
/* @__PURE__ */ (0,
|
|
2628
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material5.Box, { children: errors.length > 0 && errors.map((error, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material5.Alert, { sx: { mt: 2 }, severity: "error", children: error }, index)) })
|
|
2344
2629
|
] });
|
|
2345
2630
|
};
|
|
2346
2631
|
var CheckCodeForm_default = CheckCodeForm;
|
|
2347
2632
|
|
|
2348
2633
|
// src/components/CrudifyLogin/components/CrudifyInitializer.tsx
|
|
2349
|
-
var
|
|
2350
|
-
var
|
|
2634
|
+
var import_material6 = require("@mui/material");
|
|
2635
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2351
2636
|
var CrudifyInitializer = ({ children, fallback }) => {
|
|
2352
2637
|
const { isLoading, error, isInitialized } = useCrudify();
|
|
2353
2638
|
const { t } = useTranslation();
|
|
2354
2639
|
if (isLoading) {
|
|
2355
|
-
return fallback || /* @__PURE__ */ (0,
|
|
2356
|
-
|
|
2640
|
+
return fallback || /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2641
|
+
import_material6.Box,
|
|
2357
2642
|
{
|
|
2358
2643
|
sx: {
|
|
2359
2644
|
display: "flex",
|
|
@@ -2364,14 +2649,14 @@ var CrudifyInitializer = ({ children, fallback }) => {
|
|
|
2364
2649
|
gap: 2
|
|
2365
2650
|
},
|
|
2366
2651
|
children: [
|
|
2367
|
-
/* @__PURE__ */ (0,
|
|
2368
|
-
/* @__PURE__ */ (0,
|
|
2652
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material6.CircularProgress, {}),
|
|
2653
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material6.Typography, { variant: "body2", color: "text.secondary", children: t("login.initializing") !== "login.initializing" ? t("login.initializing") : "Initializing..." })
|
|
2369
2654
|
]
|
|
2370
2655
|
}
|
|
2371
2656
|
);
|
|
2372
2657
|
}
|
|
2373
2658
|
if (error) {
|
|
2374
|
-
return /* @__PURE__ */ (0,
|
|
2659
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material6.Alert, { severity: "error", sx: { mt: 2 }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_material6.Typography, { variant: "body2", children: [
|
|
2375
2660
|
t("login.initializationError") !== "login.initializationError" ? t("login.initializationError") : "Initialization error",
|
|
2376
2661
|
":",
|
|
2377
2662
|
" ",
|
|
@@ -2379,13 +2664,13 @@ var CrudifyInitializer = ({ children, fallback }) => {
|
|
|
2379
2664
|
] }) });
|
|
2380
2665
|
}
|
|
2381
2666
|
if (!isInitialized) {
|
|
2382
|
-
return /* @__PURE__ */ (0,
|
|
2667
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material6.Alert, { severity: "warning", sx: { mt: 2 }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material6.Typography, { variant: "body2", children: t("login.notInitialized") !== "login.notInitialized" ? t("login.notInitialized") : "System not initialized" }) });
|
|
2383
2668
|
}
|
|
2384
|
-
return /* @__PURE__ */ (0,
|
|
2669
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children });
|
|
2385
2670
|
};
|
|
2386
2671
|
|
|
2387
2672
|
// src/components/CrudifyLogin/index.tsx
|
|
2388
|
-
var
|
|
2673
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2389
2674
|
var CrudifyLoginInternal = ({
|
|
2390
2675
|
onScreenChange,
|
|
2391
2676
|
onExternalNavigate,
|
|
@@ -2415,11 +2700,11 @@ var CrudifyLoginInternal = ({
|
|
|
2415
2700
|
};
|
|
2416
2701
|
switch (state.currentScreen) {
|
|
2417
2702
|
case "forgotPassword":
|
|
2418
|
-
return /* @__PURE__ */ (0,
|
|
2703
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ForgotPasswordForm_default, { ...commonProps });
|
|
2419
2704
|
case "checkCode":
|
|
2420
|
-
return /* @__PURE__ */ (0,
|
|
2705
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CheckCodeForm_default, { ...commonProps, searchParams: state.searchParams });
|
|
2421
2706
|
case "resetPassword":
|
|
2422
|
-
return /* @__PURE__ */ (0,
|
|
2707
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2423
2708
|
ResetPasswordForm_default,
|
|
2424
2709
|
{
|
|
2425
2710
|
...commonProps,
|
|
@@ -2430,11 +2715,11 @@ var CrudifyLoginInternal = ({
|
|
|
2430
2715
|
}
|
|
2431
2716
|
);
|
|
2432
2717
|
default:
|
|
2433
|
-
return /* @__PURE__ */ (0,
|
|
2718
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(LoginForm_default, { ...commonProps, onLoginSuccess });
|
|
2434
2719
|
}
|
|
2435
2720
|
};
|
|
2436
|
-
return /* @__PURE__ */ (0,
|
|
2437
|
-
/* @__PURE__ */ (0,
|
|
2721
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(CrudifyInitializer, { children: [
|
|
2722
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_material7.Box, { sx: { display: "flex", justifyContent: "center", mb: 3 }, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2438
2723
|
"img",
|
|
2439
2724
|
{
|
|
2440
2725
|
src: config.logo || "/nocios-default.png",
|
|
@@ -2450,8 +2735,8 @@ var CrudifyLoginInternal = ({
|
|
|
2450
2735
|
}
|
|
2451
2736
|
}
|
|
2452
2737
|
) }),
|
|
2453
|
-
config.appName && /* @__PURE__ */ (0,
|
|
2454
|
-
|
|
2738
|
+
config.appName && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2739
|
+
import_material7.Typography,
|
|
2455
2740
|
{
|
|
2456
2741
|
variant: "h6",
|
|
2457
2742
|
component: "h1",
|
|
@@ -2475,34 +2760,34 @@ var CrudifyLogin = ({
|
|
|
2475
2760
|
...props
|
|
2476
2761
|
}) => {
|
|
2477
2762
|
const { config } = useSessionContext();
|
|
2478
|
-
return /* @__PURE__ */ (0,
|
|
2763
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(I18nProvider, { translations, translationsUrl, language, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CrudifyProvider, { config, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(LoginStateProvider, { config, initialScreen, autoReadFromCookies, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CrudifyLoginInternal, { ...props }) }) }) });
|
|
2479
2764
|
};
|
|
2480
2765
|
var CrudifyLogin_default = CrudifyLogin;
|
|
2481
2766
|
|
|
2482
2767
|
// src/components/UserProfile/UserProfileDisplay.tsx
|
|
2483
|
-
var
|
|
2768
|
+
var import_material8 = require("@mui/material");
|
|
2484
2769
|
var import_icons_material = require("@mui/icons-material");
|
|
2485
2770
|
|
|
2486
2771
|
// src/hooks/useUserProfile.ts
|
|
2487
|
-
var
|
|
2772
|
+
var import_react12 = require("react");
|
|
2488
2773
|
var import_crudify_browser3 = __toESM(require("@nocios/crudify-browser"));
|
|
2489
2774
|
var useUserProfile = (options = {}) => {
|
|
2490
2775
|
const { autoFetch = true, retryOnError = false, maxRetries = 3 } = options;
|
|
2491
|
-
const [userProfile, setUserProfile] = (0,
|
|
2492
|
-
const [loading, setLoading] = (0,
|
|
2493
|
-
const [error, setError] = (0,
|
|
2494
|
-
const [extendedData, setExtendedData] = (0,
|
|
2495
|
-
const abortControllerRef = (0,
|
|
2496
|
-
const mountedRef = (0,
|
|
2497
|
-
const requestIdRef = (0,
|
|
2498
|
-
const retryCountRef = (0,
|
|
2499
|
-
const clearProfile = (0,
|
|
2776
|
+
const [userProfile, setUserProfile] = (0, import_react12.useState)(null);
|
|
2777
|
+
const [loading, setLoading] = (0, import_react12.useState)(false);
|
|
2778
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
2779
|
+
const [extendedData, setExtendedData] = (0, import_react12.useState)({});
|
|
2780
|
+
const abortControllerRef = (0, import_react12.useRef)(null);
|
|
2781
|
+
const mountedRef = (0, import_react12.useRef)(true);
|
|
2782
|
+
const requestIdRef = (0, import_react12.useRef)(0);
|
|
2783
|
+
const retryCountRef = (0, import_react12.useRef)(0);
|
|
2784
|
+
const clearProfile = (0, import_react12.useCallback)(() => {
|
|
2500
2785
|
setUserProfile(null);
|
|
2501
2786
|
setError(null);
|
|
2502
2787
|
setLoading(false);
|
|
2503
2788
|
setExtendedData({});
|
|
2504
2789
|
}, []);
|
|
2505
|
-
const refreshProfile = (0,
|
|
2790
|
+
const refreshProfile = (0, import_react12.useCallback)(async () => {
|
|
2506
2791
|
const userEmail = getCurrentUserEmail();
|
|
2507
2792
|
if (!userEmail) {
|
|
2508
2793
|
if (mountedRef.current) {
|
|
@@ -2603,12 +2888,12 @@ var useUserProfile = (options = {}) => {
|
|
|
2603
2888
|
}
|
|
2604
2889
|
}
|
|
2605
2890
|
}, [retryOnError, maxRetries]);
|
|
2606
|
-
(0,
|
|
2891
|
+
(0, import_react12.useEffect)(() => {
|
|
2607
2892
|
if (autoFetch) {
|
|
2608
2893
|
refreshProfile();
|
|
2609
2894
|
}
|
|
2610
2895
|
}, [autoFetch, refreshProfile]);
|
|
2611
|
-
(0,
|
|
2896
|
+
(0, import_react12.useEffect)(() => {
|
|
2612
2897
|
mountedRef.current = true;
|
|
2613
2898
|
return () => {
|
|
2614
2899
|
mountedRef.current = false;
|
|
@@ -2629,8 +2914,8 @@ var useUserProfile = (options = {}) => {
|
|
|
2629
2914
|
};
|
|
2630
2915
|
|
|
2631
2916
|
// src/components/UserProfile/UserProfileDisplay.tsx
|
|
2632
|
-
var
|
|
2633
|
-
var
|
|
2917
|
+
var import_react13 = require("react");
|
|
2918
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2634
2919
|
var UserProfileDisplay = ({
|
|
2635
2920
|
showExtendedData = true,
|
|
2636
2921
|
showProfileCard = true,
|
|
@@ -2641,19 +2926,19 @@ var UserProfileDisplay = ({
|
|
|
2641
2926
|
retryOnError: true,
|
|
2642
2927
|
maxRetries: 3
|
|
2643
2928
|
});
|
|
2644
|
-
const [showAllFields, setShowAllFields] = (0,
|
|
2929
|
+
const [showAllFields, setShowAllFields] = (0, import_react13.useState)(false);
|
|
2645
2930
|
if (loading) {
|
|
2646
|
-
return /* @__PURE__ */ (0,
|
|
2647
|
-
/* @__PURE__ */ (0,
|
|
2648
|
-
/* @__PURE__ */ (0,
|
|
2931
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { display: "flex", justifyContent: "center", alignItems: "center", p: 3, children: [
|
|
2932
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.CircularProgress, {}),
|
|
2933
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "body2", sx: { ml: 2 }, children: "Cargando perfil de usuario..." })
|
|
2649
2934
|
] });
|
|
2650
2935
|
}
|
|
2651
2936
|
if (error) {
|
|
2652
|
-
return /* @__PURE__ */ (0,
|
|
2653
|
-
|
|
2937
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
2938
|
+
import_material8.Alert,
|
|
2654
2939
|
{
|
|
2655
2940
|
severity: "error",
|
|
2656
|
-
action: /* @__PURE__ */ (0,
|
|
2941
|
+
action: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.IconButton, { color: "inherit", size: "small", onClick: refreshProfile, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "caption", children: "Reintentar" }) }),
|
|
2657
2942
|
children: [
|
|
2658
2943
|
"Error al cargar el perfil: ",
|
|
2659
2944
|
error
|
|
@@ -2662,7 +2947,7 @@ var UserProfileDisplay = ({
|
|
|
2662
2947
|
);
|
|
2663
2948
|
}
|
|
2664
2949
|
if (!userProfile) {
|
|
2665
|
-
return /* @__PURE__ */ (0,
|
|
2950
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Alert, { severity: "warning", children: "No se encontr\xF3 informaci\xF3n del usuario" });
|
|
2666
2951
|
}
|
|
2667
2952
|
const displayData = extendedData?.displayData || {};
|
|
2668
2953
|
const totalFields = extendedData?.totalFields || 0;
|
|
@@ -2688,11 +2973,11 @@ var UserProfileDisplay = ({
|
|
|
2688
2973
|
return String(value);
|
|
2689
2974
|
};
|
|
2690
2975
|
const basicFields = [
|
|
2691
|
-
{ key: "id", label: "ID", icon: /* @__PURE__ */ (0,
|
|
2692
|
-
{ key: "email", label: "Email", icon: /* @__PURE__ */ (0,
|
|
2693
|
-
{ key: "username", label: "Usuario", icon: /* @__PURE__ */ (0,
|
|
2694
|
-
{ key: "fullName", label: "Nombre completo", icon: /* @__PURE__ */ (0,
|
|
2695
|
-
{ key: "role", label: "Rol", icon: /* @__PURE__ */ (0,
|
|
2976
|
+
{ key: "id", label: "ID", icon: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material.Badge, {}) },
|
|
2977
|
+
{ key: "email", label: "Email", icon: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material.Email, {}) },
|
|
2978
|
+
{ key: "username", label: "Usuario", icon: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material.Person, {}) },
|
|
2979
|
+
{ key: "fullName", label: "Nombre completo", icon: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material.AccountCircle, {}) },
|
|
2980
|
+
{ key: "role", label: "Rol", icon: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material.Security, {}) }
|
|
2696
2981
|
];
|
|
2697
2982
|
const extendedFields = [
|
|
2698
2983
|
{ key: "firstName", label: "Nombre" },
|
|
@@ -2704,22 +2989,22 @@ var UserProfileDisplay = ({
|
|
|
2704
2989
|
];
|
|
2705
2990
|
const knownFields = [...basicFields.map((f) => f.key), ...extendedFields.map((f) => f.key), "permissions"];
|
|
2706
2991
|
const customFields = Object.keys(displayData).filter((key) => !knownFields.includes(key)).map((key) => ({ key, label: key }));
|
|
2707
|
-
return /* @__PURE__ */ (0,
|
|
2708
|
-
showProfileCard && /* @__PURE__ */ (0,
|
|
2709
|
-
/* @__PURE__ */ (0,
|
|
2710
|
-
/* @__PURE__ */ (0,
|
|
2711
|
-
|
|
2992
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { children: [
|
|
2993
|
+
showProfileCard && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Card, { sx: { mb: 2 }, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.CardContent, { children: [
|
|
2994
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { display: "flex", alignItems: "center", mb: 2, children: [
|
|
2995
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
2996
|
+
import_material8.Avatar,
|
|
2712
2997
|
{
|
|
2713
2998
|
src: displayData.avatar,
|
|
2714
2999
|
sx: { width: 56, height: 56, mr: 2 },
|
|
2715
3000
|
children: displayData.fullName?.[0] || displayData.username?.[0] || displayData.email?.[0]
|
|
2716
3001
|
}
|
|
2717
3002
|
),
|
|
2718
|
-
/* @__PURE__ */ (0,
|
|
2719
|
-
/* @__PURE__ */ (0,
|
|
2720
|
-
/* @__PURE__ */ (0,
|
|
2721
|
-
displayData.isActive !== void 0 && /* @__PURE__ */ (0,
|
|
2722
|
-
|
|
3003
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { children: [
|
|
3004
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "h6", children: displayData.fullName || displayData.username || displayData.email }),
|
|
3005
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "body2", color: "text.secondary", children: displayData.role || "Usuario" }),
|
|
3006
|
+
displayData.isActive !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3007
|
+
import_material8.Chip,
|
|
2723
3008
|
{
|
|
2724
3009
|
label: displayData.isActive ? "Activo" : "Inactivo",
|
|
2725
3010
|
color: displayData.isActive ? "success" : "error",
|
|
@@ -2729,59 +3014,59 @@ var UserProfileDisplay = ({
|
|
|
2729
3014
|
)
|
|
2730
3015
|
] })
|
|
2731
3016
|
] }),
|
|
2732
|
-
/* @__PURE__ */ (0,
|
|
2733
|
-
({ key, label, icon }) => displayData[key] ? /* @__PURE__ */ (0,
|
|
2734
|
-
/* @__PURE__ */ (0,
|
|
2735
|
-
/* @__PURE__ */ (0,
|
|
2736
|
-
/* @__PURE__ */ (0,
|
|
2737
|
-
/* @__PURE__ */ (0,
|
|
3017
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Box, { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(250px, 1fr))", gap: 2, children: basicFields.map(
|
|
3018
|
+
({ key, label, icon }) => displayData[key] ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { display: "flex", alignItems: "center", children: [
|
|
3019
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Box, { sx: { mr: 1, color: "text.secondary" }, children: icon }),
|
|
3020
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { children: [
|
|
3021
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "caption", color: "text.secondary", children: label }),
|
|
3022
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "body2", children: renderFieldValue(key, displayData[key]) })
|
|
2738
3023
|
] })
|
|
2739
3024
|
] }, key) : null
|
|
2740
3025
|
) }),
|
|
2741
|
-
displayData.permissions && Array.isArray(displayData.permissions) && displayData.permissions.length > 0 && /* @__PURE__ */ (0,
|
|
2742
|
-
/* @__PURE__ */ (0,
|
|
2743
|
-
/* @__PURE__ */ (0,
|
|
2744
|
-
displayData.permissions.slice(0, 5).map((permission, index) => /* @__PURE__ */ (0,
|
|
2745
|
-
displayData.permissions.length > 5 && /* @__PURE__ */ (0,
|
|
3026
|
+
displayData.permissions && Array.isArray(displayData.permissions) && displayData.permissions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { mt: 2, children: [
|
|
3027
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "caption", color: "text.secondary", display: "block", children: "Permisos" }),
|
|
3028
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { display: "flex", flexWrap: "wrap", gap: 0.5, mt: 0.5, children: [
|
|
3029
|
+
displayData.permissions.slice(0, 5).map((permission, index) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Chip, { label: permission, size: "small", variant: "outlined" }, index)),
|
|
3030
|
+
displayData.permissions.length > 5 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Chip, { label: `+${displayData.permissions.length - 5} m\xE1s`, size: "small" })
|
|
2746
3031
|
] })
|
|
2747
3032
|
] })
|
|
2748
3033
|
] }) }),
|
|
2749
|
-
showExtendedData && /* @__PURE__ */ (0,
|
|
2750
|
-
/* @__PURE__ */ (0,
|
|
2751
|
-
/* @__PURE__ */ (0,
|
|
2752
|
-
/* @__PURE__ */ (0,
|
|
3034
|
+
showExtendedData && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.CardContent, { children: [
|
|
3035
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2, children: [
|
|
3036
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Typography, { variant: "h6", display: "flex", alignItems: "center", children: [
|
|
3037
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material.Info, { sx: { mr: 1 } }),
|
|
2753
3038
|
"Informaci\xF3n Detallada"
|
|
2754
3039
|
] }),
|
|
2755
|
-
/* @__PURE__ */ (0,
|
|
3040
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Chip, { label: `${totalFields} campos totales`, size: "small" })
|
|
2756
3041
|
] }),
|
|
2757
|
-
/* @__PURE__ */ (0,
|
|
2758
|
-
extendedFields.map(({ key, label }) => displayData[key] !== void 0 && /* @__PURE__ */ (0,
|
|
2759
|
-
/* @__PURE__ */ (0,
|
|
2760
|
-
/* @__PURE__ */ (0,
|
|
2761
|
-
|
|
3042
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.List, { dense: true, children: [
|
|
3043
|
+
extendedFields.map(({ key, label }) => displayData[key] !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.ListItem, { divider: true, children: [
|
|
3044
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.ListItemIcon, { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material.Schedule, { fontSize: "small" }) }),
|
|
3045
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3046
|
+
import_material8.ListItemText,
|
|
2762
3047
|
{
|
|
2763
3048
|
primary: label,
|
|
2764
3049
|
secondary: key.includes("At") || key.includes("Login") ? formatDate(displayData[key]) : renderFieldValue(key, displayData[key])
|
|
2765
3050
|
}
|
|
2766
3051
|
)
|
|
2767
3052
|
] }, key)),
|
|
2768
|
-
customFields.length > 0 && /* @__PURE__ */ (0,
|
|
2769
|
-
/* @__PURE__ */ (0,
|
|
2770
|
-
/* @__PURE__ */ (0,
|
|
2771
|
-
|
|
3053
|
+
customFields.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
|
|
3054
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Divider, { sx: { my: 1 } }),
|
|
3055
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.ListItem, { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3056
|
+
import_material8.ListItemText,
|
|
2772
3057
|
{
|
|
2773
|
-
primary: /* @__PURE__ */ (0,
|
|
2774
|
-
/* @__PURE__ */ (0,
|
|
3058
|
+
primary: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { display: "flex", justifyContent: "space-between", alignItems: "center", children: [
|
|
3059
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Typography, { variant: "subtitle2", children: [
|
|
2775
3060
|
"Campos Personalizados (",
|
|
2776
3061
|
customFields.length,
|
|
2777
3062
|
")"
|
|
2778
3063
|
] }),
|
|
2779
|
-
/* @__PURE__ */ (0,
|
|
3064
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.IconButton, { size: "small", onClick: () => setShowAllFields(!showAllFields), children: showAllFields ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material.ExpandLess, {}) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_material.ExpandMore, {}) })
|
|
2780
3065
|
] })
|
|
2781
3066
|
}
|
|
2782
3067
|
) }),
|
|
2783
|
-
/* @__PURE__ */ (0,
|
|
2784
|
-
|
|
3068
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Collapse, { in: showAllFields, children: customFields.map(({ key, label }) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.ListItem, { sx: { pl: 4 }, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3069
|
+
import_material8.ListItemText,
|
|
2785
3070
|
{
|
|
2786
3071
|
primary: label,
|
|
2787
3072
|
secondary: renderFieldValue(key, displayData[key])
|
|
@@ -2789,12 +3074,12 @@ var UserProfileDisplay = ({
|
|
|
2789
3074
|
) }, key)) })
|
|
2790
3075
|
] })
|
|
2791
3076
|
] }),
|
|
2792
|
-
/* @__PURE__ */ (0,
|
|
2793
|
-
/* @__PURE__ */ (0,
|
|
3077
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Box, { mt: 2, display: "flex", justifyContent: "space-between", alignItems: "center", children: [
|
|
3078
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material8.Typography, { variant: "caption", color: "text.secondary", children: [
|
|
2794
3079
|
"\xDAltima actualizaci\xF3n: ",
|
|
2795
3080
|
formatDate(displayData.updatedAt)
|
|
2796
3081
|
] }),
|
|
2797
|
-
/* @__PURE__ */ (0,
|
|
3082
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.IconButton, { size: "small", onClick: refreshProfile, disabled: loading, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material8.Typography, { variant: "caption", children: "Actualizar" }) })
|
|
2798
3083
|
] })
|
|
2799
3084
|
] }) })
|
|
2800
3085
|
] });
|
|
@@ -2802,23 +3087,23 @@ var UserProfileDisplay = ({
|
|
|
2802
3087
|
var UserProfileDisplay_default = UserProfileDisplay;
|
|
2803
3088
|
|
|
2804
3089
|
// src/components/PublicPolicies/Policies.tsx
|
|
2805
|
-
var
|
|
3090
|
+
var import_react16 = require("react");
|
|
2806
3091
|
var import_react_i18next3 = require("react-i18next");
|
|
2807
|
-
var
|
|
3092
|
+
var import_material11 = require("@mui/material");
|
|
2808
3093
|
var import_icons_material4 = require("@mui/icons-material");
|
|
2809
3094
|
|
|
2810
3095
|
// src/components/PublicPolicies/PolicyItem/PolicyItem.tsx
|
|
2811
|
-
var
|
|
3096
|
+
var import_react15 = require("react");
|
|
2812
3097
|
var import_react_i18next2 = require("react-i18next");
|
|
2813
|
-
var
|
|
3098
|
+
var import_material10 = require("@mui/material");
|
|
2814
3099
|
var import_icons_material3 = require("@mui/icons-material");
|
|
2815
3100
|
|
|
2816
3101
|
// src/components/PublicPolicies/FieldSelector/FieldSelector.tsx
|
|
2817
|
-
var
|
|
3102
|
+
var import_react14 = require("react");
|
|
2818
3103
|
var import_react_i18next = require("react-i18next");
|
|
2819
|
-
var
|
|
3104
|
+
var import_material9 = require("@mui/material");
|
|
2820
3105
|
var import_icons_material2 = require("@mui/icons-material");
|
|
2821
|
-
var
|
|
3106
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2822
3107
|
var FieldSelector = ({
|
|
2823
3108
|
value,
|
|
2824
3109
|
onChange,
|
|
@@ -2827,9 +3112,9 @@ var FieldSelector = ({
|
|
|
2827
3112
|
disabled = false
|
|
2828
3113
|
}) => {
|
|
2829
3114
|
const { t } = (0, import_react_i18next.useTranslation)();
|
|
2830
|
-
const [mode, setMode] = (0,
|
|
2831
|
-
const isUpdatingRef = (0,
|
|
2832
|
-
(0,
|
|
3115
|
+
const [mode, setMode] = (0, import_react14.useState)("custom");
|
|
3116
|
+
const isUpdatingRef = (0, import_react14.useRef)(false);
|
|
3117
|
+
(0, import_react14.useEffect)(() => {
|
|
2833
3118
|
const current = value || { allow: [], owner_allow: [], deny: [] };
|
|
2834
3119
|
const all = new Set(availableFields);
|
|
2835
3120
|
const allow = (current.allow || []).filter((f) => all.has(f));
|
|
@@ -2885,20 +3170,20 @@ var FieldSelector = ({
|
|
|
2885
3170
|
}, 0);
|
|
2886
3171
|
};
|
|
2887
3172
|
if (availableFields.length === 0) {
|
|
2888
|
-
return /* @__PURE__ */ (0,
|
|
2889
|
-
/* @__PURE__ */ (0,
|
|
2890
|
-
/* @__PURE__ */ (0,
|
|
2891
|
-
error && /* @__PURE__ */ (0,
|
|
3173
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Box, { children: [
|
|
3174
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 1 }, children: t("modules.form.publicPolicies.fields.conditions.label") }),
|
|
3175
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Typography, { variant: "body2", color: "text.secondary", sx: { fontStyle: "italic" }, children: t("modules.form.publicPolicies.fields.conditions.noFieldsAvailable") }),
|
|
3176
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.FormHelperText, { error: true, sx: { mt: 1 }, children: error })
|
|
2892
3177
|
] });
|
|
2893
3178
|
}
|
|
2894
|
-
return /* @__PURE__ */ (0,
|
|
2895
|
-
/* @__PURE__ */ (0,
|
|
2896
|
-
/* @__PURE__ */ (0,
|
|
2897
|
-
/* @__PURE__ */ (0,
|
|
2898
|
-
|
|
3179
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Box, { children: [
|
|
3180
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 2 }, children: t("modules.form.publicPolicies.fields.conditions.label") }),
|
|
3181
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Stack, { direction: "row", spacing: 1, sx: { mb: 3 }, children: [
|
|
3182
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3183
|
+
import_material9.Button,
|
|
2899
3184
|
{
|
|
2900
3185
|
variant: mode === "all" ? "contained" : "outlined",
|
|
2901
|
-
startIcon: /* @__PURE__ */ (0,
|
|
3186
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons_material2.SelectAll, {}),
|
|
2902
3187
|
onClick: setAllAllow,
|
|
2903
3188
|
disabled,
|
|
2904
3189
|
size: "small",
|
|
@@ -2912,11 +3197,11 @@ var FieldSelector = ({
|
|
|
2912
3197
|
children: t("modules.form.publicPolicies.fields.conditions.allFields")
|
|
2913
3198
|
}
|
|
2914
3199
|
),
|
|
2915
|
-
/* @__PURE__ */ (0,
|
|
2916
|
-
|
|
3200
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3201
|
+
import_material9.Button,
|
|
2917
3202
|
{
|
|
2918
3203
|
variant: mode === "none" ? "contained" : "outlined",
|
|
2919
|
-
startIcon: /* @__PURE__ */ (0,
|
|
3204
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons_material2.ClearAll, {}),
|
|
2920
3205
|
onClick: setAllDeny,
|
|
2921
3206
|
disabled,
|
|
2922
3207
|
size: "small",
|
|
@@ -2931,15 +3216,15 @@ var FieldSelector = ({
|
|
|
2931
3216
|
}
|
|
2932
3217
|
)
|
|
2933
3218
|
] }),
|
|
2934
|
-
/* @__PURE__ */ (0,
|
|
2935
|
-
/* @__PURE__ */ (0,
|
|
2936
|
-
/* @__PURE__ */ (0,
|
|
3219
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Box, { sx: { p: 2, border: "1px solid #d1d9e0", borderRadius: 1, backgroundColor: "#f6f8fa" }, children: [
|
|
3220
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 2 }, children: t("modules.form.publicPolicies.fields.conditions.help") }),
|
|
3221
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Stack, { spacing: 1, children: availableFields.map((fieldName) => {
|
|
2937
3222
|
const fieldState = getFieldState(fieldName);
|
|
2938
|
-
return /* @__PURE__ */ (0,
|
|
2939
|
-
/* @__PURE__ */ (0,
|
|
2940
|
-
/* @__PURE__ */ (0,
|
|
2941
|
-
/* @__PURE__ */ (0,
|
|
2942
|
-
|
|
3223
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.Stack, { direction: "row", spacing: 1, alignItems: "center", children: [
|
|
3224
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.Typography, { variant: "body2", sx: { minWidth: 100, fontFamily: "monospace" }, children: fieldName }),
|
|
3225
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material9.ToggleButtonGroup, { value: fieldState, exclusive: true, size: "small", children: [
|
|
3226
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
3227
|
+
import_material9.ToggleButton,
|
|
2943
3228
|
{
|
|
2944
3229
|
value: "allow",
|
|
2945
3230
|
onClick: () => setFieldState(fieldName, "allow"),
|
|
@@ -2962,13 +3247,13 @@ var FieldSelector = ({
|
|
|
2962
3247
|
}
|
|
2963
3248
|
},
|
|
2964
3249
|
children: [
|
|
2965
|
-
/* @__PURE__ */ (0,
|
|
3250
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons_material2.CheckCircle, { sx: { fontSize: 16, mr: 0.5 } }),
|
|
2966
3251
|
t("modules.form.publicPolicies.fields.conditions.states.allow")
|
|
2967
3252
|
]
|
|
2968
3253
|
}
|
|
2969
3254
|
),
|
|
2970
|
-
/* @__PURE__ */ (0,
|
|
2971
|
-
|
|
3255
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3256
|
+
import_material9.ToggleButton,
|
|
2972
3257
|
{
|
|
2973
3258
|
value: "owner_allow",
|
|
2974
3259
|
onClick: () => setFieldState(fieldName, "owner_allow"),
|
|
@@ -2993,8 +3278,8 @@ var FieldSelector = ({
|
|
|
2993
3278
|
children: t("modules.form.publicPolicies.fields.conditions.states.ownerAllow")
|
|
2994
3279
|
}
|
|
2995
3280
|
),
|
|
2996
|
-
/* @__PURE__ */ (0,
|
|
2997
|
-
|
|
3281
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
3282
|
+
import_material9.ToggleButton,
|
|
2998
3283
|
{
|
|
2999
3284
|
value: "deny",
|
|
3000
3285
|
onClick: () => setFieldState(fieldName, "deny"),
|
|
@@ -3017,7 +3302,7 @@ var FieldSelector = ({
|
|
|
3017
3302
|
}
|
|
3018
3303
|
},
|
|
3019
3304
|
children: [
|
|
3020
|
-
/* @__PURE__ */ (0,
|
|
3305
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons_material2.Cancel, { sx: { fontSize: 16, mr: 0.5 } }),
|
|
3021
3306
|
t("modules.form.publicPolicies.fields.conditions.states.deny")
|
|
3022
3307
|
]
|
|
3023
3308
|
}
|
|
@@ -3026,7 +3311,7 @@ var FieldSelector = ({
|
|
|
3026
3311
|
] }, fieldName);
|
|
3027
3312
|
}) })
|
|
3028
3313
|
] }),
|
|
3029
|
-
error && /* @__PURE__ */ (0,
|
|
3314
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material9.FormHelperText, { error: true, sx: { mt: 1 }, children: error })
|
|
3030
3315
|
] });
|
|
3031
3316
|
};
|
|
3032
3317
|
var FieldSelector_default = FieldSelector;
|
|
@@ -3041,8 +3326,8 @@ var PREFERRED_POLICY_ORDER = [
|
|
|
3041
3326
|
];
|
|
3042
3327
|
|
|
3043
3328
|
// src/components/PublicPolicies/PolicyItem/PolicyItem.tsx
|
|
3044
|
-
var
|
|
3045
|
-
var PolicyItem = (0,
|
|
3329
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
3330
|
+
var PolicyItem = (0, import_react15.forwardRef)(({
|
|
3046
3331
|
policy,
|
|
3047
3332
|
onChange,
|
|
3048
3333
|
onRemove,
|
|
@@ -3058,8 +3343,8 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3058
3343
|
value: a,
|
|
3059
3344
|
label: t(`modules.form.publicPolicies.fields.action.options.${a}`)
|
|
3060
3345
|
}));
|
|
3061
|
-
return /* @__PURE__ */ (0,
|
|
3062
|
-
|
|
3346
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
3347
|
+
import_material10.Paper,
|
|
3063
3348
|
{
|
|
3064
3349
|
ref,
|
|
3065
3350
|
sx: {
|
|
@@ -3070,9 +3355,9 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3070
3355
|
backgroundColor: "#ffffff"
|
|
3071
3356
|
},
|
|
3072
3357
|
children: [
|
|
3073
|
-
/* @__PURE__ */ (0,
|
|
3074
|
-
/* @__PURE__ */ (0,
|
|
3075
|
-
|
|
3358
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Box, { sx: { display: "flex", justifyContent: "space-between", alignItems: "flex-start", mb: 3 }, children: [
|
|
3359
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3360
|
+
import_material10.Typography,
|
|
3076
3361
|
{
|
|
3077
3362
|
variant: "subtitle1",
|
|
3078
3363
|
sx: {
|
|
@@ -3083,8 +3368,8 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3083
3368
|
children: t("modules.form.publicPolicies.policyTitle")
|
|
3084
3369
|
}
|
|
3085
3370
|
),
|
|
3086
|
-
/* @__PURE__ */ (0,
|
|
3087
|
-
|
|
3371
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3372
|
+
import_material10.IconButton,
|
|
3088
3373
|
{
|
|
3089
3374
|
onClick: onRemove,
|
|
3090
3375
|
size: "small",
|
|
@@ -3097,15 +3382,15 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3097
3382
|
backgroundColor: "rgba(207, 34, 46, 0.1)"
|
|
3098
3383
|
}
|
|
3099
3384
|
},
|
|
3100
|
-
children: /* @__PURE__ */ (0,
|
|
3385
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons_material3.Delete, {})
|
|
3101
3386
|
}
|
|
3102
3387
|
)
|
|
3103
3388
|
] }),
|
|
3104
|
-
/* @__PURE__ */ (0,
|
|
3105
|
-
/* @__PURE__ */ (0,
|
|
3106
|
-
/* @__PURE__ */ (0,
|
|
3107
|
-
/* @__PURE__ */ (0,
|
|
3108
|
-
|
|
3389
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Stack, { spacing: 3, children: [
|
|
3390
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Stack, { direction: { xs: "column", md: "row" }, spacing: 2, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Box, { sx: { flex: 1, minWidth: 200 }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.FormControl, { fullWidth: true, children: [
|
|
3391
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.InputLabel, { children: t("modules.form.publicPolicies.fields.action.label") }),
|
|
3392
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3393
|
+
import_material10.Select,
|
|
3109
3394
|
{
|
|
3110
3395
|
value: policy.action,
|
|
3111
3396
|
label: t("modules.form.publicPolicies.fields.action.label"),
|
|
@@ -3134,20 +3419,20 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3134
3419
|
},
|
|
3135
3420
|
children: actionOptions.map((option) => {
|
|
3136
3421
|
const disabledOption = takenActions.has(option.value);
|
|
3137
|
-
return /* @__PURE__ */ (0,
|
|
3422
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.MenuItem, { value: option.value, disabled: disabledOption, children: option.label }, option.value);
|
|
3138
3423
|
})
|
|
3139
3424
|
}
|
|
3140
3425
|
),
|
|
3141
|
-
error && /* @__PURE__ */ (0,
|
|
3426
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.FormHelperText, { error: true, children: error })
|
|
3142
3427
|
] }) }) }),
|
|
3143
|
-
policy.action === "delete" ? /* @__PURE__ */ (0,
|
|
3144
|
-
/* @__PURE__ */ (0,
|
|
3145
|
-
/* @__PURE__ */ (0,
|
|
3146
|
-
/* @__PURE__ */ (0,
|
|
3147
|
-
|
|
3428
|
+
policy.action === "delete" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Box, { children: [
|
|
3429
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 2 }, children: t("modules.form.publicPolicies.fields.conditions.label") }),
|
|
3430
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Stack, { direction: "row", spacing: 1, sx: { mb: 3 }, children: [
|
|
3431
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3432
|
+
import_material10.Button,
|
|
3148
3433
|
{
|
|
3149
3434
|
variant: policy.permission === "*" ? "contained" : "outlined",
|
|
3150
|
-
startIcon: /* @__PURE__ */ (0,
|
|
3435
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons_material3.SelectAll, {}),
|
|
3151
3436
|
onClick: () => onChange({ ...policy, permission: "*" }),
|
|
3152
3437
|
disabled: isSubmitting,
|
|
3153
3438
|
size: "small",
|
|
@@ -3162,8 +3447,8 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3162
3447
|
children: t("modules.form.publicPolicies.fields.conditions.allFields")
|
|
3163
3448
|
}
|
|
3164
3449
|
),
|
|
3165
|
-
/* @__PURE__ */ (0,
|
|
3166
|
-
|
|
3450
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3451
|
+
import_material10.Button,
|
|
3167
3452
|
{
|
|
3168
3453
|
variant: policy.permission === "owner" ? "contained" : "outlined",
|
|
3169
3454
|
onClick: () => onChange({ ...policy, permission: "owner" }),
|
|
@@ -3180,11 +3465,11 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3180
3465
|
children: t("modules.form.publicPolicies.fields.conditions.states.ownerAllow")
|
|
3181
3466
|
}
|
|
3182
3467
|
),
|
|
3183
|
-
/* @__PURE__ */ (0,
|
|
3184
|
-
|
|
3468
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3469
|
+
import_material10.Button,
|
|
3185
3470
|
{
|
|
3186
3471
|
variant: policy.permission === "deny" ? "contained" : "outlined",
|
|
3187
|
-
startIcon: /* @__PURE__ */ (0,
|
|
3472
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons_material3.ClearAll, {}),
|
|
3188
3473
|
onClick: () => onChange({ ...policy, permission: "deny" }),
|
|
3189
3474
|
disabled: isSubmitting,
|
|
3190
3475
|
size: "small",
|
|
@@ -3200,7 +3485,7 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3200
3485
|
}
|
|
3201
3486
|
)
|
|
3202
3487
|
] })
|
|
3203
|
-
] }) : /* @__PURE__ */ (0,
|
|
3488
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3204
3489
|
FieldSelector_default,
|
|
3205
3490
|
{
|
|
3206
3491
|
value: policy.fields || { allow: [], owner_allow: [], deny: [] },
|
|
@@ -3209,8 +3494,8 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3209
3494
|
disabled: isSubmitting
|
|
3210
3495
|
}
|
|
3211
3496
|
),
|
|
3212
|
-
/* @__PURE__ */ (0,
|
|
3213
|
-
/* @__PURE__ */ (0,
|
|
3497
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Paper, { variant: "outlined", sx: { p: 2, backgroundColor: "#f9fafb" }, children: policy.action === "delete" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Typography, { variant: "body2", sx: { fontFamily: "monospace", color: "text.secondary" }, children: [
|
|
3498
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Box, { component: "span", sx: {
|
|
3214
3499
|
color: policy.permission === "*" ? "#16a34a" : policy.permission === "owner" ? "#0ea5e9" : "#dc2626"
|
|
3215
3500
|
}, children: [
|
|
3216
3501
|
t("modules.form.publicPolicies.fields.conditions.states.allow"),
|
|
@@ -3218,25 +3503,25 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3218
3503
|
] }),
|
|
3219
3504
|
" ",
|
|
3220
3505
|
policy.permission || "-"
|
|
3221
|
-
] }) : /* @__PURE__ */ (0,
|
|
3222
|
-
/* @__PURE__ */ (0,
|
|
3223
|
-
/* @__PURE__ */ (0,
|
|
3506
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Stack, { spacing: 0.5, divider: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material10.Divider, { sx: { borderColor: "#e5e7eb" } }), children: [
|
|
3507
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Typography, { variant: "body2", sx: { fontFamily: "monospace", color: "text.secondary" }, children: [
|
|
3508
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Box, { component: "span", sx: { color: "#16a34a" }, children: [
|
|
3224
3509
|
t("modules.form.publicPolicies.fields.conditions.states.allow"),
|
|
3225
3510
|
":"
|
|
3226
3511
|
] }),
|
|
3227
3512
|
" ",
|
|
3228
3513
|
(policy?.fields?.allow || []).join(", ") || "-"
|
|
3229
3514
|
] }),
|
|
3230
|
-
/* @__PURE__ */ (0,
|
|
3231
|
-
/* @__PURE__ */ (0,
|
|
3515
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Typography, { variant: "body2", sx: { fontFamily: "monospace", color: "text.secondary" }, children: [
|
|
3516
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Box, { component: "span", sx: { color: "#0ea5e9" }, children: [
|
|
3232
3517
|
t("modules.form.publicPolicies.fields.conditions.states.ownerAllow"),
|
|
3233
3518
|
":"
|
|
3234
3519
|
] }),
|
|
3235
3520
|
" ",
|
|
3236
3521
|
(policy?.fields?.owner_allow || []).join(", ") || "-"
|
|
3237
3522
|
] }),
|
|
3238
|
-
/* @__PURE__ */ (0,
|
|
3239
|
-
/* @__PURE__ */ (0,
|
|
3523
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Typography, { variant: "body2", sx: { fontFamily: "monospace", color: "text.secondary" }, children: [
|
|
3524
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Box, { component: "span", sx: { color: "#dc2626" }, children: [
|
|
3240
3525
|
t("modules.form.publicPolicies.fields.conditions.states.deny"),
|
|
3241
3526
|
":"
|
|
3242
3527
|
] }),
|
|
@@ -3252,7 +3537,7 @@ var PolicyItem = (0, import_react14.forwardRef)(({
|
|
|
3252
3537
|
var PolicyItem_default = PolicyItem;
|
|
3253
3538
|
|
|
3254
3539
|
// src/components/PublicPolicies/Policies.tsx
|
|
3255
|
-
var
|
|
3540
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
3256
3541
|
var generateId = () => {
|
|
3257
3542
|
const c = globalThis?.crypto;
|
|
3258
3543
|
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
|
@@ -3266,7 +3551,7 @@ var Policies = ({
|
|
|
3266
3551
|
isSubmitting = false
|
|
3267
3552
|
}) => {
|
|
3268
3553
|
const { t } = (0, import_react_i18next3.useTranslation)();
|
|
3269
|
-
const policyRefs = (0,
|
|
3554
|
+
const policyRefs = (0, import_react16.useRef)({});
|
|
3270
3555
|
const takenActions = new Set((policies || []).map((p) => p.action).filter(Boolean));
|
|
3271
3556
|
const remainingActions = PREFERRED_POLICY_ORDER.filter((a) => !takenActions.has(a));
|
|
3272
3557
|
const canAddPolicy = remainingActions.length > 0;
|
|
@@ -3307,12 +3592,12 @@ var Policies = ({
|
|
|
3307
3592
|
return typeof msg === "string" ? msg : null;
|
|
3308
3593
|
})();
|
|
3309
3594
|
const usedActions = new Set((policies || []).map((p) => p.action));
|
|
3310
|
-
return /* @__PURE__ */ (0,
|
|
3311
|
-
/* @__PURE__ */ (0,
|
|
3312
|
-
/* @__PURE__ */ (0,
|
|
3313
|
-
/* @__PURE__ */ (0,
|
|
3314
|
-
/* @__PURE__ */ (0,
|
|
3315
|
-
|
|
3595
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
|
|
3596
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_material11.Divider, { sx: { borderColor: "#e0e4e7" } }),
|
|
3597
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_material11.Box, { children: [
|
|
3598
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_material11.Box, { display: "flex", justifyContent: "space-between", alignItems: "center", mb: 3, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_material11.Box, { children: [
|
|
3599
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
3600
|
+
import_material11.Typography,
|
|
3316
3601
|
{
|
|
3317
3602
|
variant: "h6",
|
|
3318
3603
|
sx: {
|
|
@@ -3323,8 +3608,8 @@ var Policies = ({
|
|
|
3323
3608
|
children: t("modules.form.publicPolicies.title")
|
|
3324
3609
|
}
|
|
3325
3610
|
),
|
|
3326
|
-
/* @__PURE__ */ (0,
|
|
3327
|
-
|
|
3611
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
3612
|
+
import_material11.Typography,
|
|
3328
3613
|
{
|
|
3329
3614
|
variant: "body2",
|
|
3330
3615
|
color: "text.secondary",
|
|
@@ -3333,9 +3618,9 @@ var Policies = ({
|
|
|
3333
3618
|
}
|
|
3334
3619
|
)
|
|
3335
3620
|
] }) }),
|
|
3336
|
-
arrayError && /* @__PURE__ */ (0,
|
|
3337
|
-
/* @__PURE__ */ (0,
|
|
3338
|
-
(policies || []).length === 0 ? /* @__PURE__ */ (0,
|
|
3621
|
+
arrayError && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_material11.Alert, { severity: "error", sx: { mb: 3 }, children: arrayError }),
|
|
3622
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_material11.Stack, { spacing: 3, children: [
|
|
3623
|
+
(policies || []).length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_material11.Alert, { severity: "info", children: t("modules.form.publicPolicies.noPolicies") }) : policies.map((policy, index) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
3339
3624
|
PolicyItem_default,
|
|
3340
3625
|
{
|
|
3341
3626
|
ref: (el) => {
|
|
@@ -3355,12 +3640,12 @@ var Policies = ({
|
|
|
3355
3640
|
},
|
|
3356
3641
|
policy.id
|
|
3357
3642
|
)),
|
|
3358
|
-
canAddPolicy && /* @__PURE__ */ (0,
|
|
3359
|
-
|
|
3643
|
+
canAddPolicy && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_material11.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
3644
|
+
import_material11.Button,
|
|
3360
3645
|
{
|
|
3361
3646
|
type: "button",
|
|
3362
3647
|
variant: "outlined",
|
|
3363
|
-
startIcon: /* @__PURE__ */ (0,
|
|
3648
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_icons_material4.Add, {}),
|
|
3364
3649
|
onClick: addPolicy,
|
|
3365
3650
|
disabled: isSubmitting,
|
|
3366
3651
|
sx: {
|
|
@@ -3381,13 +3666,13 @@ var Policies = ({
|
|
|
3381
3666
|
var Policies_default = Policies;
|
|
3382
3667
|
|
|
3383
3668
|
// src/components/LoginComponent.tsx
|
|
3384
|
-
var
|
|
3385
|
-
var
|
|
3386
|
-
var
|
|
3669
|
+
var import_react17 = require("react");
|
|
3670
|
+
var import_material12 = require("@mui/material");
|
|
3671
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
3387
3672
|
function LoginComponent() {
|
|
3388
|
-
const [email, setEmail] = (0,
|
|
3389
|
-
const [password, setPassword] = (0,
|
|
3390
|
-
const [showForm, setShowForm] = (0,
|
|
3673
|
+
const [email, setEmail] = (0, import_react17.useState)("");
|
|
3674
|
+
const [password, setPassword] = (0, import_react17.useState)("");
|
|
3675
|
+
const [showForm, setShowForm] = (0, import_react17.useState)(false);
|
|
3391
3676
|
const {
|
|
3392
3677
|
isAuthenticated,
|
|
3393
3678
|
isLoading,
|
|
@@ -3418,31 +3703,31 @@ function LoginComponent() {
|
|
|
3418
3703
|
await refreshTokens();
|
|
3419
3704
|
};
|
|
3420
3705
|
if (isAuthenticated) {
|
|
3421
|
-
return /* @__PURE__ */ (0,
|
|
3422
|
-
/* @__PURE__ */ (0,
|
|
3423
|
-
/* @__PURE__ */ (0,
|
|
3424
|
-
/* @__PURE__ */ (0,
|
|
3425
|
-
/* @__PURE__ */ (0,
|
|
3426
|
-
/* @__PURE__ */ (0,
|
|
3706
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material12.Box, { sx: { maxWidth: 600, mx: "auto", p: 3 }, children: [
|
|
3707
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Typography, { variant: "h4", gutterBottom: true, children: "Welcome! \u{1F389}" }),
|
|
3708
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Alert, { severity: "success", sx: { mb: 3 }, children: "You are successfully logged in with Refresh Token Pattern enabled" }),
|
|
3709
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material12.Box, { sx: { mb: 3, p: 2, bgcolor: "background.paper", border: 1, borderColor: "divider", borderRadius: 1 }, children: [
|
|
3710
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Typography, { variant: "h6", gutterBottom: true, children: "Token Status" }),
|
|
3711
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material12.Typography, { variant: "body2", color: "text.secondary", children: [
|
|
3427
3712
|
"Access Token expires in: ",
|
|
3428
3713
|
Math.round(expiresIn / 1e3 / 60),
|
|
3429
3714
|
" minutes"
|
|
3430
3715
|
] }),
|
|
3431
|
-
isExpiringSoon && /* @__PURE__ */ (0,
|
|
3716
|
+
isExpiringSoon && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Alert, { severity: "warning", sx: { mt: 1 }, children: "Token expires soon - automatic refresh will happen" })
|
|
3432
3717
|
] }),
|
|
3433
|
-
/* @__PURE__ */ (0,
|
|
3434
|
-
/* @__PURE__ */ (0,
|
|
3435
|
-
|
|
3718
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material12.Box, { sx: { display: "flex", gap: 2, flexWrap: "wrap" }, children: [
|
|
3719
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3720
|
+
import_material12.Button,
|
|
3436
3721
|
{
|
|
3437
3722
|
variant: "contained",
|
|
3438
3723
|
onClick: handleRefreshTokens,
|
|
3439
3724
|
disabled: isLoading,
|
|
3440
|
-
startIcon: isLoading ? /* @__PURE__ */ (0,
|
|
3725
|
+
startIcon: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.CircularProgress, { size: 16 }) : null,
|
|
3441
3726
|
children: "Refresh Tokens"
|
|
3442
3727
|
}
|
|
3443
3728
|
),
|
|
3444
|
-
/* @__PURE__ */ (0,
|
|
3445
|
-
|
|
3729
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3730
|
+
import_material12.Button,
|
|
3446
3731
|
{
|
|
3447
3732
|
variant: "outlined",
|
|
3448
3733
|
color: "error",
|
|
@@ -3452,14 +3737,14 @@ function LoginComponent() {
|
|
|
3452
3737
|
}
|
|
3453
3738
|
)
|
|
3454
3739
|
] }),
|
|
3455
|
-
error && /* @__PURE__ */ (0,
|
|
3740
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Alert, { severity: "error", sx: { mt: 2 }, onClose: clearError, children: error })
|
|
3456
3741
|
] });
|
|
3457
3742
|
}
|
|
3458
|
-
return /* @__PURE__ */ (0,
|
|
3459
|
-
/* @__PURE__ */ (0,
|
|
3460
|
-
/* @__PURE__ */ (0,
|
|
3461
|
-
!showForm ? /* @__PURE__ */ (0,
|
|
3462
|
-
|
|
3743
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material12.Box, { sx: { maxWidth: 400, mx: "auto", p: 3 }, children: [
|
|
3744
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Typography, { variant: "h4", gutterBottom: true, align: "center", children: "Login with Refresh Tokens" }),
|
|
3745
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Alert, { severity: "info", sx: { mb: 3 }, children: "This demo shows the new Refresh Token Pattern with automatic session management" }),
|
|
3746
|
+
!showForm ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3747
|
+
import_material12.Button,
|
|
3463
3748
|
{
|
|
3464
3749
|
fullWidth: true,
|
|
3465
3750
|
variant: "contained",
|
|
@@ -3468,9 +3753,9 @@ function LoginComponent() {
|
|
|
3468
3753
|
sx: { mt: 2 },
|
|
3469
3754
|
children: "Show Login Form"
|
|
3470
3755
|
}
|
|
3471
|
-
) : /* @__PURE__ */ (0,
|
|
3472
|
-
/* @__PURE__ */ (0,
|
|
3473
|
-
|
|
3756
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("form", { onSubmit: handleLogin, children: [
|
|
3757
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3758
|
+
import_material12.TextField,
|
|
3474
3759
|
{
|
|
3475
3760
|
fullWidth: true,
|
|
3476
3761
|
label: "Email",
|
|
@@ -3482,8 +3767,8 @@ function LoginComponent() {
|
|
|
3482
3767
|
autoComplete: "email"
|
|
3483
3768
|
}
|
|
3484
3769
|
),
|
|
3485
|
-
/* @__PURE__ */ (0,
|
|
3486
|
-
|
|
3770
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3771
|
+
import_material12.TextField,
|
|
3487
3772
|
{
|
|
3488
3773
|
fullWidth: true,
|
|
3489
3774
|
label: "Password",
|
|
@@ -3495,37 +3780,37 @@ function LoginComponent() {
|
|
|
3495
3780
|
autoComplete: "current-password"
|
|
3496
3781
|
}
|
|
3497
3782
|
),
|
|
3498
|
-
/* @__PURE__ */ (0,
|
|
3499
|
-
|
|
3783
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3784
|
+
import_material12.Button,
|
|
3500
3785
|
{
|
|
3501
3786
|
type: "submit",
|
|
3502
3787
|
fullWidth: true,
|
|
3503
3788
|
variant: "contained",
|
|
3504
3789
|
size: "large",
|
|
3505
3790
|
disabled: isLoading,
|
|
3506
|
-
startIcon: isLoading ? /* @__PURE__ */ (0,
|
|
3791
|
+
startIcon: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.CircularProgress, { size: 16 }) : null,
|
|
3507
3792
|
sx: { mt: 3, mb: 2 },
|
|
3508
3793
|
children: isLoading ? "Logging in..." : "Login"
|
|
3509
3794
|
}
|
|
3510
3795
|
)
|
|
3511
3796
|
] }),
|
|
3512
|
-
error && /* @__PURE__ */ (0,
|
|
3797
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Alert, { severity: "error", sx: { mt: 2 }, onClose: clearError, children: error })
|
|
3513
3798
|
] });
|
|
3514
3799
|
}
|
|
3515
3800
|
function SessionStatus() {
|
|
3516
3801
|
const { isAuthenticated, isLoading, isExpiringSoon, expiresIn } = useSessionContext();
|
|
3517
3802
|
if (isLoading) {
|
|
3518
|
-
return /* @__PURE__ */ (0,
|
|
3519
|
-
/* @__PURE__ */ (0,
|
|
3520
|
-
/* @__PURE__ */ (0,
|
|
3803
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material12.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
|
|
3804
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.CircularProgress, { size: 16 }),
|
|
3805
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Typography, { variant: "caption", children: "Loading session..." })
|
|
3521
3806
|
] });
|
|
3522
3807
|
}
|
|
3523
3808
|
if (!isAuthenticated) {
|
|
3524
|
-
return /* @__PURE__ */ (0,
|
|
3809
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Typography, { variant: "caption", color: "text.secondary", children: "Not logged in" });
|
|
3525
3810
|
}
|
|
3526
|
-
return /* @__PURE__ */ (0,
|
|
3527
|
-
/* @__PURE__ */ (0,
|
|
3528
|
-
isExpiringSoon && /* @__PURE__ */ (0,
|
|
3811
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material12.Box, { children: [
|
|
3812
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_material12.Typography, { variant: "caption", color: "success.main", children: "\u2713 Authenticated" }),
|
|
3813
|
+
isExpiringSoon && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_material12.Typography, { variant: "caption", color: "warning.main", display: "block", children: [
|
|
3529
3814
|
"\u26A0 Token expires in ",
|
|
3530
3815
|
Math.round(expiresIn / 1e3 / 60),
|
|
3531
3816
|
" min"
|
|
@@ -3534,29 +3819,29 @@ function SessionStatus() {
|
|
|
3534
3819
|
}
|
|
3535
3820
|
|
|
3536
3821
|
// src/hooks/useUserData.ts
|
|
3537
|
-
var
|
|
3822
|
+
var import_react18 = require("react");
|
|
3538
3823
|
var import_crudify_browser4 = __toESM(require("@nocios/crudify-browser"));
|
|
3539
3824
|
var useUserData = (options = {}) => {
|
|
3540
3825
|
const { autoFetch = true, retryOnError = false, maxRetries = 3 } = options;
|
|
3541
3826
|
const { isAuthenticated, isInitialized, sessionData, tokens } = useSessionContext();
|
|
3542
|
-
const [userData, setUserData] = (0,
|
|
3543
|
-
const [loading, setLoading] = (0,
|
|
3544
|
-
const [error, setError] = (0,
|
|
3545
|
-
const abortControllerRef = (0,
|
|
3546
|
-
const mountedRef = (0,
|
|
3547
|
-
const requestIdRef = (0,
|
|
3548
|
-
const retryCountRef = (0,
|
|
3549
|
-
const getUserEmail = (0,
|
|
3827
|
+
const [userData, setUserData] = (0, import_react18.useState)(null);
|
|
3828
|
+
const [loading, setLoading] = (0, import_react18.useState)(false);
|
|
3829
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
3830
|
+
const abortControllerRef = (0, import_react18.useRef)(null);
|
|
3831
|
+
const mountedRef = (0, import_react18.useRef)(true);
|
|
3832
|
+
const requestIdRef = (0, import_react18.useRef)(0);
|
|
3833
|
+
const retryCountRef = (0, import_react18.useRef)(0);
|
|
3834
|
+
const getUserEmail = (0, import_react18.useCallback)(() => {
|
|
3550
3835
|
if (!sessionData) return null;
|
|
3551
3836
|
return sessionData.email || sessionData["cognito:username"] || null;
|
|
3552
3837
|
}, [sessionData]);
|
|
3553
|
-
const clearProfile = (0,
|
|
3838
|
+
const clearProfile = (0, import_react18.useCallback)(() => {
|
|
3554
3839
|
setUserData(null);
|
|
3555
3840
|
setError(null);
|
|
3556
3841
|
setLoading(false);
|
|
3557
3842
|
retryCountRef.current = 0;
|
|
3558
3843
|
}, []);
|
|
3559
|
-
const refreshProfile = (0,
|
|
3844
|
+
const refreshProfile = (0, import_react18.useCallback)(async () => {
|
|
3560
3845
|
const userEmail = getUserEmail();
|
|
3561
3846
|
console.log("\u{1F464} useUserData - Refreshing profile for:", userEmail);
|
|
3562
3847
|
if (!userEmail) {
|
|
@@ -3688,14 +3973,14 @@ var useUserData = (options = {}) => {
|
|
|
3688
3973
|
}
|
|
3689
3974
|
}
|
|
3690
3975
|
}, [isInitialized, getUserEmail, retryOnError, maxRetries]);
|
|
3691
|
-
(0,
|
|
3976
|
+
(0, import_react18.useEffect)(() => {
|
|
3692
3977
|
if (autoFetch && isAuthenticated && isInitialized) {
|
|
3693
3978
|
refreshProfile();
|
|
3694
3979
|
} else if (!isAuthenticated) {
|
|
3695
3980
|
clearProfile();
|
|
3696
3981
|
}
|
|
3697
3982
|
}, [autoFetch, isAuthenticated, isInitialized, refreshProfile, clearProfile]);
|
|
3698
|
-
(0,
|
|
3983
|
+
(0, import_react18.useEffect)(() => {
|
|
3699
3984
|
mountedRef.current = true;
|
|
3700
3985
|
return () => {
|
|
3701
3986
|
mountedRef.current = false;
|
|
@@ -3721,7 +4006,7 @@ var useUserData = (options = {}) => {
|
|
|
3721
4006
|
};
|
|
3722
4007
|
|
|
3723
4008
|
// src/hooks/useAuth.ts
|
|
3724
|
-
var
|
|
4009
|
+
var import_react19 = require("react");
|
|
3725
4010
|
var useAuth = () => {
|
|
3726
4011
|
const {
|
|
3727
4012
|
isAuthenticated,
|
|
@@ -3739,7 +4024,7 @@ var useAuth = () => {
|
|
|
3739
4024
|
expiresIn,
|
|
3740
4025
|
refreshExpiresIn
|
|
3741
4026
|
} = useSessionContext();
|
|
3742
|
-
const setToken = (0,
|
|
4027
|
+
const setToken = (0, import_react19.useCallback)((token) => {
|
|
3743
4028
|
if (token) {
|
|
3744
4029
|
console.warn("useAuth.setToken() is deprecated. Use login() method instead for better security.");
|
|
3745
4030
|
} else {
|
|
@@ -3774,7 +4059,7 @@ var useAuth = () => {
|
|
|
3774
4059
|
};
|
|
3775
4060
|
|
|
3776
4061
|
// src/hooks/useData.ts
|
|
3777
|
-
var
|
|
4062
|
+
var import_react20 = require("react");
|
|
3778
4063
|
var import_crudify_browser5 = __toESM(require("@nocios/crudify-browser"));
|
|
3779
4064
|
var useData = () => {
|
|
3780
4065
|
const {
|
|
@@ -3784,10 +4069,10 @@ var useData = () => {
|
|
|
3784
4069
|
isAuthenticated,
|
|
3785
4070
|
login: sessionLogin
|
|
3786
4071
|
} = useSessionContext();
|
|
3787
|
-
const isReady = (0,
|
|
4072
|
+
const isReady = (0, import_react20.useCallback)(() => {
|
|
3788
4073
|
return isInitialized && !isLoading && !error;
|
|
3789
4074
|
}, [isInitialized, isLoading, error]);
|
|
3790
|
-
const waitForReady = (0,
|
|
4075
|
+
const waitForReady = (0, import_react20.useCallback)(async () => {
|
|
3791
4076
|
return new Promise((resolve, reject) => {
|
|
3792
4077
|
const checkReady = () => {
|
|
3793
4078
|
if (isReady()) {
|
|
@@ -3801,36 +4086,36 @@ var useData = () => {
|
|
|
3801
4086
|
checkReady();
|
|
3802
4087
|
});
|
|
3803
4088
|
}, [isReady, error]);
|
|
3804
|
-
const ensureReady = (0,
|
|
4089
|
+
const ensureReady = (0, import_react20.useCallback)(async () => {
|
|
3805
4090
|
if (!isReady()) {
|
|
3806
4091
|
throw new Error("System not ready. Check isInitialized, isLoading, and error states.");
|
|
3807
4092
|
}
|
|
3808
4093
|
}, [isReady]);
|
|
3809
|
-
const readItems = (0,
|
|
4094
|
+
const readItems = (0, import_react20.useCallback)(async (moduleKey, filter, options) => {
|
|
3810
4095
|
await ensureReady();
|
|
3811
4096
|
return await import_crudify_browser5.default.readItems(moduleKey, filter || {}, options);
|
|
3812
4097
|
}, [ensureReady]);
|
|
3813
|
-
const readItem = (0,
|
|
4098
|
+
const readItem = (0, import_react20.useCallback)(async (moduleKey, filter, options) => {
|
|
3814
4099
|
await ensureReady();
|
|
3815
4100
|
return await import_crudify_browser5.default.readItem(moduleKey, filter, options);
|
|
3816
4101
|
}, [ensureReady]);
|
|
3817
|
-
const createItem = (0,
|
|
4102
|
+
const createItem = (0, import_react20.useCallback)(async (moduleKey, data, options) => {
|
|
3818
4103
|
await ensureReady();
|
|
3819
4104
|
return await import_crudify_browser5.default.createItem(moduleKey, data, options);
|
|
3820
4105
|
}, [ensureReady]);
|
|
3821
|
-
const updateItem = (0,
|
|
4106
|
+
const updateItem = (0, import_react20.useCallback)(async (moduleKey, data, options) => {
|
|
3822
4107
|
await ensureReady();
|
|
3823
4108
|
return await import_crudify_browser5.default.updateItem(moduleKey, data, options);
|
|
3824
4109
|
}, [ensureReady]);
|
|
3825
|
-
const deleteItem = (0,
|
|
4110
|
+
const deleteItem = (0, import_react20.useCallback)(async (moduleKey, id, options) => {
|
|
3826
4111
|
await ensureReady();
|
|
3827
4112
|
return await import_crudify_browser5.default.deleteItem(moduleKey, id, options);
|
|
3828
4113
|
}, [ensureReady]);
|
|
3829
|
-
const transaction = (0,
|
|
4114
|
+
const transaction = (0, import_react20.useCallback)(async (operations, options) => {
|
|
3830
4115
|
await ensureReady();
|
|
3831
4116
|
return await import_crudify_browser5.default.transaction(operations, options);
|
|
3832
4117
|
}, [ensureReady]);
|
|
3833
|
-
const login = (0,
|
|
4118
|
+
const login = (0, import_react20.useCallback)(async (email, password) => {
|
|
3834
4119
|
try {
|
|
3835
4120
|
const result = await sessionLogin(email, password);
|
|
3836
4121
|
if (result.success) {
|
|
@@ -3979,11 +4264,417 @@ var SecureStorage = class {
|
|
|
3979
4264
|
};
|
|
3980
4265
|
var secureSessionStorage = new SecureStorage("sessionStorage");
|
|
3981
4266
|
var secureLocalStorage = new SecureStorage("localStorage");
|
|
4267
|
+
|
|
4268
|
+
// src/hooks/useCrudifyWithNotifications.ts
|
|
4269
|
+
var import_react21 = require("react");
|
|
4270
|
+
var import_crudify_browser6 = __toESM(require("@nocios/crudify-browser"));
|
|
4271
|
+
var ERROR_SEVERITY_MAP2 = {
|
|
4272
|
+
// Errores de autenticación - warning porque el usuario puede corregirlos
|
|
4273
|
+
INVALID_CREDENTIALS: "warning",
|
|
4274
|
+
UNAUTHORIZED: "warning",
|
|
4275
|
+
INVALID_API_KEY: "error",
|
|
4276
|
+
// Errores de usuario/permisos - warning
|
|
4277
|
+
USER_NOT_FOUND: "warning",
|
|
4278
|
+
USER_NOT_ACTIVE: "warning",
|
|
4279
|
+
NO_PERMISSION: "warning",
|
|
4280
|
+
// Errores de datos - info porque pueden ser esperados
|
|
4281
|
+
ITEM_NOT_FOUND: "info",
|
|
4282
|
+
NOT_FOUND: "info",
|
|
4283
|
+
IN_USE: "warning",
|
|
4284
|
+
// Errores de validación - warning
|
|
4285
|
+
FIELD_ERROR: "warning",
|
|
4286
|
+
BAD_REQUEST: "warning",
|
|
4287
|
+
// Errores del sistema - error
|
|
4288
|
+
INTERNAL_SERVER_ERROR: "error",
|
|
4289
|
+
DATABASE_CONNECTION_ERROR: "error",
|
|
4290
|
+
INVALID_CONFIGURATION: "error",
|
|
4291
|
+
UNKNOWN_OPERATION: "error",
|
|
4292
|
+
// Rate limiting - warning con mayor duración
|
|
4293
|
+
TOO_MANY_REQUESTS: "warning"
|
|
4294
|
+
};
|
|
4295
|
+
var ERROR_TRANSLATION_MAP = {
|
|
4296
|
+
INVALID_CREDENTIALS: "errors.auth.INVALID_CREDENTIALS",
|
|
4297
|
+
UNAUTHORIZED: "errors.auth.UNAUTHORIZED",
|
|
4298
|
+
INVALID_API_KEY: "errors.auth.INVALID_API_KEY",
|
|
4299
|
+
USER_NOT_FOUND: "errors.auth.USER_NOT_FOUND",
|
|
4300
|
+
USER_NOT_ACTIVE: "errors.auth.USER_NOT_ACTIVE",
|
|
4301
|
+
NO_PERMISSION: "errors.auth.NO_PERMISSION",
|
|
4302
|
+
ITEM_NOT_FOUND: "errors.data.ITEM_NOT_FOUND",
|
|
4303
|
+
NOT_FOUND: "errors.data.NOT_FOUND",
|
|
4304
|
+
IN_USE: "errors.data.IN_USE",
|
|
4305
|
+
FIELD_ERROR: "errors.data.FIELD_ERROR",
|
|
4306
|
+
BAD_REQUEST: "errors.data.BAD_REQUEST",
|
|
4307
|
+
INTERNAL_SERVER_ERROR: "errors.system.INTERNAL_SERVER_ERROR",
|
|
4308
|
+
DATABASE_CONNECTION_ERROR: "errors.system.DATABASE_CONNECTION_ERROR",
|
|
4309
|
+
INVALID_CONFIGURATION: "errors.system.INVALID_CONFIGURATION",
|
|
4310
|
+
UNKNOWN_OPERATION: "errors.system.UNKNOWN_OPERATION",
|
|
4311
|
+
TOO_MANY_REQUESTS: "errors.system.TOO_MANY_REQUESTS"
|
|
4312
|
+
};
|
|
4313
|
+
var useCrudifyWithNotifications = (options = {}) => {
|
|
4314
|
+
const { showNotification } = useGlobalNotification();
|
|
4315
|
+
const {
|
|
4316
|
+
showSuccessNotifications = false,
|
|
4317
|
+
showErrorNotifications = true,
|
|
4318
|
+
customErrorMessages = {},
|
|
4319
|
+
defaultErrorMessage = "Ha ocurrido un error inesperado",
|
|
4320
|
+
autoHideDuration = 6e3,
|
|
4321
|
+
appStructure = [],
|
|
4322
|
+
translateFn = (key) => key
|
|
4323
|
+
// Fallback si no hay función de traducción
|
|
4324
|
+
} = options;
|
|
4325
|
+
const shouldShowNotification = (0, import_react21.useCallback)((response) => {
|
|
4326
|
+
if (!response.success && response.errors) {
|
|
4327
|
+
const hasFieldErrors = Object.keys(response.errors).some((key) => key !== "_error" && key !== "_graphql" && key !== "_transaction");
|
|
4328
|
+
if (hasFieldErrors) return false;
|
|
4329
|
+
if (response.errors._transaction?.includes("ONE_OR_MORE_OPERATIONS_FAILED")) return false;
|
|
4330
|
+
if (response.errors._error?.includes("TOO_MANY_REQUESTS")) return false;
|
|
4331
|
+
}
|
|
4332
|
+
if (!response.success && response.data?.response?.status === "TOO_MANY_REQUESTS") return false;
|
|
4333
|
+
return true;
|
|
4334
|
+
}, []);
|
|
4335
|
+
const getSafeTranslation = (0, import_react21.useCallback)(
|
|
4336
|
+
(key, fallback) => {
|
|
4337
|
+
const translated = translateFn(key);
|
|
4338
|
+
if (translated === key) return fallback || translateFn("error.unknown");
|
|
4339
|
+
return translated;
|
|
4340
|
+
},
|
|
4341
|
+
[translateFn]
|
|
4342
|
+
);
|
|
4343
|
+
const isCrudOperation = (0, import_react21.useCallback)((operation) => {
|
|
4344
|
+
return ["create", "update", "delete"].includes(operation);
|
|
4345
|
+
}, []);
|
|
4346
|
+
const shouldShowSuccessNotification = (0, import_react21.useCallback)(
|
|
4347
|
+
(operation, moduleKey) => {
|
|
4348
|
+
if (!showSuccessNotifications) return false;
|
|
4349
|
+
if (isCrudOperation(operation) && moduleKey) return true;
|
|
4350
|
+
return appStructure.some((action) => action.key === operation);
|
|
4351
|
+
},
|
|
4352
|
+
[showSuccessNotifications, appStructure, isCrudOperation]
|
|
4353
|
+
);
|
|
4354
|
+
const getSuccessMessage = (0, import_react21.useCallback)(
|
|
4355
|
+
(operation, moduleKey, actionConfig) => {
|
|
4356
|
+
const operationKey = actionConfig?.key && typeof actionConfig.key === "string" ? actionConfig.key : operation;
|
|
4357
|
+
const successKey = `action.onSuccess.${operationKey}`;
|
|
4358
|
+
const successMessage = getSafeTranslation(successKey);
|
|
4359
|
+
if (successMessage !== translateFn("error.unknown")) {
|
|
4360
|
+
if (isCrudOperation(operationKey) && moduleKey) {
|
|
4361
|
+
const itemNameKey = `action.${moduleKey}Singular`;
|
|
4362
|
+
const itemName = getSafeTranslation(itemNameKey);
|
|
4363
|
+
if (itemName !== translateFn("error.unknown")) {
|
|
4364
|
+
return translateFn(successKey, { item: itemName });
|
|
4365
|
+
} else {
|
|
4366
|
+
const withoutItemKey = `action.onSuccess.${operationKey}WithoutItem`;
|
|
4367
|
+
const withoutItemMessage = getSafeTranslation(withoutItemKey);
|
|
4368
|
+
return withoutItemMessage !== translateFn("error.unknown") ? withoutItemMessage : successMessage;
|
|
4369
|
+
}
|
|
4370
|
+
}
|
|
4371
|
+
return successMessage;
|
|
4372
|
+
}
|
|
4373
|
+
return translateFn("success.transaction");
|
|
4374
|
+
},
|
|
4375
|
+
[getSafeTranslation, translateFn, isCrudOperation]
|
|
4376
|
+
);
|
|
4377
|
+
const getErrorMessage2 = (0, import_react21.useCallback)(
|
|
4378
|
+
(response) => {
|
|
4379
|
+
if (response.errorCode && customErrorMessages[response.errorCode]) {
|
|
4380
|
+
return customErrorMessages[response.errorCode];
|
|
4381
|
+
}
|
|
4382
|
+
if (response.errorCode && ERROR_TRANSLATION_MAP[response.errorCode]) {
|
|
4383
|
+
return getSafeTranslation(ERROR_TRANSLATION_MAP[response.errorCode]);
|
|
4384
|
+
}
|
|
4385
|
+
if (response.errorCode) {
|
|
4386
|
+
const possibleKeys = [
|
|
4387
|
+
`errors.auth.${response.errorCode}`,
|
|
4388
|
+
`errors.data.${response.errorCode}`,
|
|
4389
|
+
`errors.system.${response.errorCode}`,
|
|
4390
|
+
`errors.${response.errorCode}`
|
|
4391
|
+
];
|
|
4392
|
+
for (const key of possibleKeys) {
|
|
4393
|
+
const translated = getSafeTranslation(key);
|
|
4394
|
+
if (translated !== translateFn("error.unknown")) {
|
|
4395
|
+
return translated;
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4398
|
+
}
|
|
4399
|
+
if (typeof response.data === "string" && response.data.startsWith("errors.")) {
|
|
4400
|
+
const translated = getSafeTranslation(response.data);
|
|
4401
|
+
if (translated !== translateFn("error.unknown")) {
|
|
4402
|
+
return translated;
|
|
4403
|
+
}
|
|
4404
|
+
}
|
|
4405
|
+
if (response.errors && Object.keys(response.errors).length > 0) {
|
|
4406
|
+
const errorFields = Object.keys(response.errors);
|
|
4407
|
+
if (errorFields.length === 1 && errorFields[0] === "_transaction") {
|
|
4408
|
+
const transactionErrors = response.errors["_transaction"];
|
|
4409
|
+
if (transactionErrors?.includes("ONE_OR_MORE_OPERATIONS_FAILED")) {
|
|
4410
|
+
return "";
|
|
4411
|
+
}
|
|
4412
|
+
if (Array.isArray(transactionErrors) && transactionErrors.length > 0) {
|
|
4413
|
+
const firstError = transactionErrors[0];
|
|
4414
|
+
if (typeof firstError === "string" && firstError !== "ONE_OR_MORE_OPERATIONS_FAILED") {
|
|
4415
|
+
try {
|
|
4416
|
+
const parsed = JSON.parse(firstError);
|
|
4417
|
+
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
4418
|
+
const firstTransactionError = parsed[0];
|
|
4419
|
+
if (firstTransactionError?.response?.errorCode) {
|
|
4420
|
+
const errorCode = firstTransactionError.response.errorCode;
|
|
4421
|
+
if (ERROR_TRANSLATION_MAP[errorCode]) {
|
|
4422
|
+
return getSafeTranslation(ERROR_TRANSLATION_MAP[errorCode]);
|
|
4423
|
+
}
|
|
4424
|
+
const possibleKeys = [
|
|
4425
|
+
`errors.auth.${errorCode}`,
|
|
4426
|
+
`errors.data.${errorCode}`,
|
|
4427
|
+
`errors.system.${errorCode}`,
|
|
4428
|
+
`errors.${errorCode}`
|
|
4429
|
+
];
|
|
4430
|
+
for (const key of possibleKeys) {
|
|
4431
|
+
const translated = getSafeTranslation(key);
|
|
4432
|
+
if (translated !== getSafeTranslation("error.unknown")) {
|
|
4433
|
+
return translated;
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
if (firstTransactionError?.response?.data) {
|
|
4438
|
+
return firstTransactionError.response.data;
|
|
4439
|
+
}
|
|
4440
|
+
}
|
|
4441
|
+
if (parsed?.response?.message) {
|
|
4442
|
+
const errorMsg = parsed.response.message.toLowerCase();
|
|
4443
|
+
if (errorMsg.includes("expired")) {
|
|
4444
|
+
return getSafeTranslation("resetPassword.linkExpired", "El enlace ha expirado");
|
|
4445
|
+
} else if (errorMsg.includes("invalid")) {
|
|
4446
|
+
return getSafeTranslation("resetPassword.invalidCode", "C\xF3digo inv\xE1lido");
|
|
4447
|
+
}
|
|
4448
|
+
return parsed.response.message;
|
|
4449
|
+
}
|
|
4450
|
+
} catch {
|
|
4451
|
+
if (firstError.toLowerCase().includes("expired")) {
|
|
4452
|
+
return getSafeTranslation("resetPassword.linkExpired", "El enlace ha expirado");
|
|
4453
|
+
} else if (firstError.toLowerCase().includes("invalid")) {
|
|
4454
|
+
return getSafeTranslation("resetPassword.invalidCode", "C\xF3digo inv\xE1lido");
|
|
4455
|
+
}
|
|
4456
|
+
return firstError;
|
|
4457
|
+
}
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
return getSafeTranslation("error.transaction", "Error en la operaci\xF3n");
|
|
4461
|
+
}
|
|
4462
|
+
if (errorFields.length === 1 && errorFields[0] === "_error") {
|
|
4463
|
+
const errorMessages = response.errors["_error"];
|
|
4464
|
+
return Array.isArray(errorMessages) ? errorMessages[0] : String(errorMessages);
|
|
4465
|
+
}
|
|
4466
|
+
if (errorFields.length === 1 && errorFields[0] === "_graphql") {
|
|
4467
|
+
return getSafeTranslation("errors.system.DATABASE_CONNECTION_ERROR");
|
|
4468
|
+
}
|
|
4469
|
+
return `${getSafeTranslation("errors.data.FIELD_ERROR")}: ${errorFields.join(", ")}`;
|
|
4470
|
+
}
|
|
4471
|
+
return defaultErrorMessage || translateFn("error.unknown");
|
|
4472
|
+
},
|
|
4473
|
+
[customErrorMessages, defaultErrorMessage, translateFn, getSafeTranslation]
|
|
4474
|
+
);
|
|
4475
|
+
const getErrorSeverity = (0, import_react21.useCallback)((response) => {
|
|
4476
|
+
if (response.errorCode && ERROR_SEVERITY_MAP2[response.errorCode]) {
|
|
4477
|
+
return ERROR_SEVERITY_MAP2[response.errorCode];
|
|
4478
|
+
}
|
|
4479
|
+
return "error";
|
|
4480
|
+
}, []);
|
|
4481
|
+
const createItem = (0, import_react21.useCallback)(
|
|
4482
|
+
async (moduleKey, data, options2) => {
|
|
4483
|
+
const response = await import_crudify_browser6.default.createItem(moduleKey, data, options2);
|
|
4484
|
+
if (!response.success && showErrorNotifications && shouldShowNotification(response)) {
|
|
4485
|
+
const message = getErrorMessage2(response);
|
|
4486
|
+
const severity = getErrorSeverity(response);
|
|
4487
|
+
showNotification(message, severity, { autoHideDuration });
|
|
4488
|
+
} else if (response.success) {
|
|
4489
|
+
const actionConfig = options2?.actionConfig;
|
|
4490
|
+
const operation = actionConfig?.key || "create";
|
|
4491
|
+
const effectiveModuleKey = actionConfig?.moduleKey || moduleKey;
|
|
4492
|
+
if (shouldShowSuccessNotification(operation, effectiveModuleKey)) {
|
|
4493
|
+
const message = getSuccessMessage(operation, effectiveModuleKey, actionConfig);
|
|
4494
|
+
showNotification(message, "success", { autoHideDuration });
|
|
4495
|
+
}
|
|
4496
|
+
}
|
|
4497
|
+
return response;
|
|
4498
|
+
},
|
|
4499
|
+
[
|
|
4500
|
+
showErrorNotifications,
|
|
4501
|
+
shouldShowSuccessNotification,
|
|
4502
|
+
showNotification,
|
|
4503
|
+
getErrorMessage2,
|
|
4504
|
+
getErrorSeverity,
|
|
4505
|
+
getSuccessMessage,
|
|
4506
|
+
autoHideDuration,
|
|
4507
|
+
shouldShowNotification
|
|
4508
|
+
]
|
|
4509
|
+
);
|
|
4510
|
+
const updateItem = (0, import_react21.useCallback)(
|
|
4511
|
+
async (moduleKey, data, options2) => {
|
|
4512
|
+
const response = await import_crudify_browser6.default.updateItem(moduleKey, data, options2);
|
|
4513
|
+
if (!response.success && showErrorNotifications && shouldShowNotification(response)) {
|
|
4514
|
+
const message = getErrorMessage2(response);
|
|
4515
|
+
const severity = getErrorSeverity(response);
|
|
4516
|
+
showNotification(message, severity, { autoHideDuration });
|
|
4517
|
+
} else if (response.success) {
|
|
4518
|
+
const actionConfig = options2?.actionConfig;
|
|
4519
|
+
const operation = actionConfig?.key || "update";
|
|
4520
|
+
const effectiveModuleKey = actionConfig?.moduleKey || moduleKey;
|
|
4521
|
+
if (shouldShowSuccessNotification(operation, effectiveModuleKey)) {
|
|
4522
|
+
const message = getSuccessMessage(operation, effectiveModuleKey, actionConfig);
|
|
4523
|
+
showNotification(message, "success", { autoHideDuration });
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
return response;
|
|
4527
|
+
},
|
|
4528
|
+
[
|
|
4529
|
+
showErrorNotifications,
|
|
4530
|
+
shouldShowSuccessNotification,
|
|
4531
|
+
showNotification,
|
|
4532
|
+
getErrorMessage2,
|
|
4533
|
+
getErrorSeverity,
|
|
4534
|
+
getSuccessMessage,
|
|
4535
|
+
autoHideDuration,
|
|
4536
|
+
shouldShowNotification
|
|
4537
|
+
]
|
|
4538
|
+
);
|
|
4539
|
+
const deleteItem = (0, import_react21.useCallback)(
|
|
4540
|
+
async (moduleKey, id, options2) => {
|
|
4541
|
+
const response = await import_crudify_browser6.default.deleteItem(moduleKey, id, options2);
|
|
4542
|
+
if (!response.success && showErrorNotifications && shouldShowNotification(response)) {
|
|
4543
|
+
const message = getErrorMessage2(response);
|
|
4544
|
+
const severity = getErrorSeverity(response);
|
|
4545
|
+
showNotification(message, severity, { autoHideDuration });
|
|
4546
|
+
} else if (response.success) {
|
|
4547
|
+
const actionConfig = options2?.actionConfig;
|
|
4548
|
+
const operation = actionConfig?.key || "delete";
|
|
4549
|
+
const effectiveModuleKey = actionConfig?.moduleKey || moduleKey;
|
|
4550
|
+
if (shouldShowSuccessNotification(operation, effectiveModuleKey)) {
|
|
4551
|
+
const message = getSuccessMessage(operation, effectiveModuleKey, actionConfig);
|
|
4552
|
+
showNotification(message, "success", { autoHideDuration });
|
|
4553
|
+
}
|
|
4554
|
+
}
|
|
4555
|
+
return response;
|
|
4556
|
+
},
|
|
4557
|
+
[
|
|
4558
|
+
showErrorNotifications,
|
|
4559
|
+
shouldShowSuccessNotification,
|
|
4560
|
+
showNotification,
|
|
4561
|
+
getErrorMessage2,
|
|
4562
|
+
getErrorSeverity,
|
|
4563
|
+
getSuccessMessage,
|
|
4564
|
+
autoHideDuration,
|
|
4565
|
+
shouldShowNotification
|
|
4566
|
+
]
|
|
4567
|
+
);
|
|
4568
|
+
const readItem = (0, import_react21.useCallback)(
|
|
4569
|
+
async (moduleKey, filter, options2) => {
|
|
4570
|
+
const response = await import_crudify_browser6.default.readItem(moduleKey, filter, options2);
|
|
4571
|
+
if (!response.success && showErrorNotifications && shouldShowNotification(response)) {
|
|
4572
|
+
const message = getErrorMessage2(response);
|
|
4573
|
+
const severity = getErrorSeverity(response);
|
|
4574
|
+
showNotification(message, severity, { autoHideDuration });
|
|
4575
|
+
}
|
|
4576
|
+
return response;
|
|
4577
|
+
},
|
|
4578
|
+
[showErrorNotifications, showNotification, getErrorMessage2, getErrorSeverity, autoHideDuration, shouldShowNotification]
|
|
4579
|
+
);
|
|
4580
|
+
const readItems = (0, import_react21.useCallback)(
|
|
4581
|
+
async (moduleKey, filter, options2) => {
|
|
4582
|
+
const response = await import_crudify_browser6.default.readItems(moduleKey, filter, options2);
|
|
4583
|
+
if (!response.success && showErrorNotifications && shouldShowNotification(response)) {
|
|
4584
|
+
const message = getErrorMessage2(response);
|
|
4585
|
+
const severity = getErrorSeverity(response);
|
|
4586
|
+
showNotification(message, severity, { autoHideDuration });
|
|
4587
|
+
}
|
|
4588
|
+
return response;
|
|
4589
|
+
},
|
|
4590
|
+
[showErrorNotifications, showNotification, getErrorMessage2, getErrorSeverity, autoHideDuration, shouldShowNotification]
|
|
4591
|
+
);
|
|
4592
|
+
const transaction = (0, import_react21.useCallback)(
|
|
4593
|
+
async (data, options2) => {
|
|
4594
|
+
const response = await import_crudify_browser6.default.transaction(data, options2);
|
|
4595
|
+
const skipNotifications = options2?.skipNotifications === true;
|
|
4596
|
+
if (!skipNotifications && !response.success && showErrorNotifications && shouldShowNotification(response)) {
|
|
4597
|
+
const message = getErrorMessage2(response);
|
|
4598
|
+
const severity = getErrorSeverity(response);
|
|
4599
|
+
showNotification(message, severity, { autoHideDuration });
|
|
4600
|
+
} else if (!skipNotifications && response.success) {
|
|
4601
|
+
let operation = "transaction";
|
|
4602
|
+
let moduleKey;
|
|
4603
|
+
let actionConfig = null;
|
|
4604
|
+
if (options2?.actionConfig) {
|
|
4605
|
+
actionConfig = options2.actionConfig;
|
|
4606
|
+
operation = actionConfig.key;
|
|
4607
|
+
moduleKey = actionConfig.moduleKey;
|
|
4608
|
+
} else if (Array.isArray(data) && data.length > 0 && data[0].operation) {
|
|
4609
|
+
operation = data[0].operation;
|
|
4610
|
+
actionConfig = appStructure.find((action) => action.key === operation);
|
|
4611
|
+
if (actionConfig) {
|
|
4612
|
+
moduleKey = actionConfig.moduleKey;
|
|
4613
|
+
}
|
|
4614
|
+
}
|
|
4615
|
+
if (shouldShowSuccessNotification(operation, moduleKey)) {
|
|
4616
|
+
const message = getSuccessMessage(operation, moduleKey, actionConfig);
|
|
4617
|
+
showNotification(message, "success", { autoHideDuration });
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
return response;
|
|
4621
|
+
},
|
|
4622
|
+
[
|
|
4623
|
+
showErrorNotifications,
|
|
4624
|
+
shouldShowSuccessNotification,
|
|
4625
|
+
showNotification,
|
|
4626
|
+
getErrorMessage2,
|
|
4627
|
+
getErrorSeverity,
|
|
4628
|
+
getSuccessMessage,
|
|
4629
|
+
autoHideDuration,
|
|
4630
|
+
shouldShowNotification,
|
|
4631
|
+
appStructure
|
|
4632
|
+
]
|
|
4633
|
+
);
|
|
4634
|
+
const handleResponse = (0, import_react21.useCallback)(
|
|
4635
|
+
(response, successMessage) => {
|
|
4636
|
+
if (!response.success && showErrorNotifications && shouldShowNotification(response)) {
|
|
4637
|
+
const message = getErrorMessage2(response);
|
|
4638
|
+
const severity = getErrorSeverity(response);
|
|
4639
|
+
showNotification(message, severity, { autoHideDuration });
|
|
4640
|
+
} else if (response.success && showSuccessNotifications && successMessage) {
|
|
4641
|
+
showNotification(successMessage, "success", { autoHideDuration });
|
|
4642
|
+
}
|
|
4643
|
+
return response;
|
|
4644
|
+
},
|
|
4645
|
+
[
|
|
4646
|
+
showErrorNotifications,
|
|
4647
|
+
showSuccessNotifications,
|
|
4648
|
+
showNotification,
|
|
4649
|
+
getErrorMessage2,
|
|
4650
|
+
getErrorSeverity,
|
|
4651
|
+
autoHideDuration,
|
|
4652
|
+
shouldShowNotification,
|
|
4653
|
+
translateFn
|
|
4654
|
+
]
|
|
4655
|
+
);
|
|
4656
|
+
return {
|
|
4657
|
+
// Métodos de crudify con notificaciones automáticas
|
|
4658
|
+
createItem,
|
|
4659
|
+
updateItem,
|
|
4660
|
+
deleteItem,
|
|
4661
|
+
readItem,
|
|
4662
|
+
readItems,
|
|
4663
|
+
transaction,
|
|
4664
|
+
// Método genérico para manejar respuestas
|
|
4665
|
+
handleResponse,
|
|
4666
|
+
// Funciones de utilidad
|
|
4667
|
+
getErrorMessage: getErrorMessage2,
|
|
4668
|
+
getErrorSeverity,
|
|
4669
|
+
shouldShowNotification
|
|
4670
|
+
};
|
|
4671
|
+
};
|
|
3982
4672
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3983
4673
|
0 && (module.exports = {
|
|
3984
4674
|
CrudifyLogin,
|
|
3985
4675
|
ERROR_CODES,
|
|
3986
4676
|
ERROR_SEVERITY_MAP,
|
|
4677
|
+
GlobalNotificationProvider,
|
|
3987
4678
|
LoginComponent,
|
|
3988
4679
|
POLICY_ACTIONS,
|
|
3989
4680
|
PREFERRED_POLICY_ORDER,
|
|
@@ -3995,6 +4686,7 @@ var secureLocalStorage = new SecureStorage("localStorage");
|
|
|
3995
4686
|
SessionStatus,
|
|
3996
4687
|
TokenStorage,
|
|
3997
4688
|
UserProfileDisplay,
|
|
4689
|
+
createErrorTranslator,
|
|
3998
4690
|
crudify,
|
|
3999
4691
|
decodeJwtSafely,
|
|
4000
4692
|
getCookie,
|
|
@@ -4007,8 +4699,13 @@ var secureLocalStorage = new SecureStorage("localStorage");
|
|
|
4007
4699
|
parseTransactionError,
|
|
4008
4700
|
secureLocalStorage,
|
|
4009
4701
|
secureSessionStorage,
|
|
4702
|
+
translateError,
|
|
4703
|
+
translateErrorCode,
|
|
4704
|
+
translateErrorCodes,
|
|
4010
4705
|
useAuth,
|
|
4706
|
+
useCrudifyWithNotifications,
|
|
4011
4707
|
useData,
|
|
4708
|
+
useGlobalNotification,
|
|
4012
4709
|
useSession,
|
|
4013
4710
|
useSessionContext,
|
|
4014
4711
|
useUserData,
|