admin-lib-cms 1.2.11 → 1.2.13
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.js +147 -26
- package/dist/index.mjs +149 -27
- package/dist/types.d.mts +3 -0
- package/dist/types.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1127,10 +1127,11 @@ function FilePickerButton({
|
|
|
1127
1127
|
] });
|
|
1128
1128
|
}
|
|
1129
1129
|
function AdminApp(props) {
|
|
1130
|
+
const content = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd.App, { className: "min-h-screen", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AdminAppContent, { ...props }) });
|
|
1130
1131
|
if (props.projectId) {
|
|
1131
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children:
|
|
1132
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: content });
|
|
1132
1133
|
}
|
|
1133
|
-
return
|
|
1134
|
+
return content;
|
|
1134
1135
|
}
|
|
1135
1136
|
function AdminAppContent(props) {
|
|
1136
1137
|
const ctx = useCmsContext();
|
|
@@ -2494,8 +2495,12 @@ function CollectionsSection() {
|
|
|
2494
2495
|
function CollectionEditor({ collection }) {
|
|
2495
2496
|
const ctx = useCmsContext();
|
|
2496
2497
|
const t = useAdminI18n();
|
|
2498
|
+
const { message } = import_antd.App.useApp();
|
|
2497
2499
|
const [entries, setEntries] = (0, import_react5.useState)([]);
|
|
2498
2500
|
const [editing, setEditing] = (0, import_react5.useState)(null);
|
|
2501
|
+
const [originalId, setOriginalId] = (0, import_react5.useState)(null);
|
|
2502
|
+
const [duplicateErrors, setDuplicateErrors] = (0, import_react5.useState)({});
|
|
2503
|
+
const [isCreatingManual, setIsCreatingManual] = (0, import_react5.useState)(false);
|
|
2499
2504
|
const [saving, setSaving] = (0, import_react5.useState)(false);
|
|
2500
2505
|
const [deletingId, setDeletingId] = (0, import_react5.useState)(null);
|
|
2501
2506
|
const [loadingEntries, setLoadingEntries] = (0, import_react5.useState)(true);
|
|
@@ -2521,6 +2526,9 @@ function CollectionEditor({ collection }) {
|
|
|
2521
2526
|
load();
|
|
2522
2527
|
}, [load]);
|
|
2523
2528
|
const startNew = () => {
|
|
2529
|
+
setIsCreatingManual(true);
|
|
2530
|
+
setOriginalId(null);
|
|
2531
|
+
setDuplicateErrors({});
|
|
2524
2532
|
const base = { id: crypto.randomUUID() };
|
|
2525
2533
|
collection.fields.forEach((f) => {
|
|
2526
2534
|
if (f.id === "order") {
|
|
@@ -2574,9 +2582,43 @@ function CollectionEditor({ collection }) {
|
|
|
2574
2582
|
finalEditing[f.id] = val;
|
|
2575
2583
|
}
|
|
2576
2584
|
});
|
|
2585
|
+
const isClientOrEmployee = collection.id === "clients" || collection.id === "employees";
|
|
2586
|
+
const uniqueFields = collection.fields.filter((f) => f.unique || isClientOrEmployee && f.id === "id");
|
|
2587
|
+
for (const f of uniqueFields) {
|
|
2588
|
+
const val = String(finalEditing[f.id] || "").trim().toLowerCase();
|
|
2589
|
+
if (!val) {
|
|
2590
|
+
message.error(`El campo "${f.label || f.id}" es obligatorio.`);
|
|
2591
|
+
setSaving(false);
|
|
2592
|
+
return;
|
|
2593
|
+
}
|
|
2594
|
+
const isDuplicate = entries.some((e) => {
|
|
2595
|
+
if (originalId && String(e.id).trim().toLowerCase() === originalId.trim().toLowerCase()) {
|
|
2596
|
+
return false;
|
|
2597
|
+
}
|
|
2598
|
+
const existingVal = String(e[f.id] || "").trim().toLowerCase();
|
|
2599
|
+
return existingVal === val;
|
|
2600
|
+
});
|
|
2601
|
+
if (isDuplicate) {
|
|
2602
|
+
message.error(
|
|
2603
|
+
`Ya existe un registro en ${collection.name} con ${f.label || f.id}: "${finalEditing[f.id]}". No se pueden repetir c\xE9dulas ni NIT.`
|
|
2604
|
+
);
|
|
2605
|
+
setSaving(false);
|
|
2606
|
+
return;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
if (originalId && String(finalEditing.id).trim().toLowerCase() !== originalId.trim().toLowerCase()) {
|
|
2610
|
+
try {
|
|
2611
|
+
await ctx.adapter.deleteEntry(collection.id, originalId);
|
|
2612
|
+
} catch (cleanupErr) {
|
|
2613
|
+
console.warn("No se pudo limpiar el registro anterior:", cleanupErr);
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2577
2616
|
await ctx.adapter.putEntry(collection.id, finalEditing);
|
|
2617
|
+
message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
|
|
2578
2618
|
ctx.notifyCollectionChanged();
|
|
2579
2619
|
setEditing(null);
|
|
2620
|
+
setOriginalId(null);
|
|
2621
|
+
setIsCreatingManual(false);
|
|
2580
2622
|
load();
|
|
2581
2623
|
} finally {
|
|
2582
2624
|
setSaving(false);
|
|
@@ -2629,7 +2671,7 @@ function CollectionEditor({ collection }) {
|
|
|
2629
2671
|
setDragOverIdx(null);
|
|
2630
2672
|
};
|
|
2631
2673
|
const visibleFields = collection.tableFields?.length ? collection.tableFields.map((tf) => collection.fields.find((f) => f.id === tf)).filter(Boolean) : collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 6);
|
|
2632
|
-
const isCreatingEntry = editing ? !entries.some((entry) => entry.id === editing.id) : false;
|
|
2674
|
+
const isCreatingEntry = isCreatingManual || (editing ? !entries.some((entry) => entry.id && entry.id === editing.id || entry._id && entry._id === (editing._id || editing.id)) : false);
|
|
2633
2675
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mx-auto max-w-5xl", children: [
|
|
2634
2676
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-8 flex items-center justify-between", children: [
|
|
2635
2677
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
@@ -2742,7 +2784,11 @@ function CollectionEditor({ collection }) {
|
|
|
2742
2784
|
] })
|
|
2743
2785
|
] }),
|
|
2744
2786
|
onCancel: () => {
|
|
2745
|
-
if (!saving)
|
|
2787
|
+
if (!saving) {
|
|
2788
|
+
setEditing(null);
|
|
2789
|
+
setOriginalId(null);
|
|
2790
|
+
setIsCreatingManual(false);
|
|
2791
|
+
}
|
|
2746
2792
|
},
|
|
2747
2793
|
footer: null,
|
|
2748
2794
|
centered: true,
|
|
@@ -3269,18 +3315,61 @@ function CollectionEditor({ collection }) {
|
|
|
3269
3315
|
]
|
|
3270
3316
|
}
|
|
3271
3317
|
) : null
|
|
3272
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3318
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
3319
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3320
|
+
import_antd.Input,
|
|
3321
|
+
{
|
|
3322
|
+
size: "large",
|
|
3323
|
+
status: duplicateErrors[f.id] ? "error" : void 0,
|
|
3324
|
+
value: String(editing[f.id] ?? ""),
|
|
3325
|
+
readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
|
|
3326
|
+
disabled: f.readOnly,
|
|
3327
|
+
onChange: (e) => {
|
|
3328
|
+
const val = e.target.value;
|
|
3329
|
+
setEditing({ ...editing, [f.id]: val });
|
|
3330
|
+
if (duplicateErrors[f.id]) {
|
|
3331
|
+
setDuplicateErrors((prev) => {
|
|
3332
|
+
const next = { ...prev };
|
|
3333
|
+
delete next[f.id];
|
|
3334
|
+
return next;
|
|
3335
|
+
});
|
|
3336
|
+
}
|
|
3337
|
+
},
|
|
3338
|
+
onBlur: (e) => {
|
|
3339
|
+
const isUniqueField = f.unique || (collection.id === "clients" || collection.id === "employees") && f.id === "id";
|
|
3340
|
+
if (isUniqueField) {
|
|
3341
|
+
const val = (e.target.value || "").trim().toLowerCase();
|
|
3342
|
+
if (val) {
|
|
3343
|
+
const dup = entries.find((entry) => {
|
|
3344
|
+
if (originalId && String(entry.id).trim().toLowerCase() === originalId.trim().toLowerCase()) {
|
|
3345
|
+
return false;
|
|
3346
|
+
}
|
|
3347
|
+
return String(entry[f.id] || "").trim().toLowerCase() === val;
|
|
3348
|
+
});
|
|
3349
|
+
if (dup) {
|
|
3350
|
+
const dupName = dup.nombre ? ` (\xAB${dup.nombre} ${dup.apellido || ""}\xBB)` : "";
|
|
3351
|
+
const errMsg = `Esta identificaci\xF3n ya est\xE1 registrada${dupName}. No puedes usar una c\xE9dula o NIT repetido.`;
|
|
3352
|
+
setDuplicateErrors((prev) => ({ ...prev, [f.id]: errMsg }));
|
|
3353
|
+
message.warning(`\u26A0\uFE0F Ya existe un registro con esta identificaci\xF3n: ${e.target.value.trim()}.`);
|
|
3354
|
+
} else {
|
|
3355
|
+
setDuplicateErrors((prev) => {
|
|
3356
|
+
const next = { ...prev };
|
|
3357
|
+
delete next[f.id];
|
|
3358
|
+
return next;
|
|
3359
|
+
});
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
},
|
|
3364
|
+
placeholder: f.label,
|
|
3365
|
+
className: "w-full rounded-xl"
|
|
3366
|
+
}
|
|
3367
|
+
),
|
|
3368
|
+
duplicateErrors[f.id] && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "text-xs text-rose-600 font-bold mt-1.5 flex items-center gap-1.5 animate-in fade-in duration-200", children: [
|
|
3369
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.AlertTriangle, { className: "w-3.5 h-3.5 shrink-0 text-rose-500" }),
|
|
3370
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: duplicateErrors[f.id] })
|
|
3371
|
+
] })
|
|
3372
|
+
] })
|
|
3284
3373
|
] }, f.id);
|
|
3285
3374
|
}) }) }),
|
|
3286
3375
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex shrink-0 justify-end gap-3 border-t border-slate-200 bg-white px-6 py-4", children: [
|
|
@@ -3288,7 +3377,12 @@ function CollectionEditor({ collection }) {
|
|
|
3288
3377
|
import_antd.Button,
|
|
3289
3378
|
{
|
|
3290
3379
|
size: "large",
|
|
3291
|
-
onClick: () =>
|
|
3380
|
+
onClick: () => {
|
|
3381
|
+
setEditing(null);
|
|
3382
|
+
setOriginalId(null);
|
|
3383
|
+
setDuplicateErrors({});
|
|
3384
|
+
setIsCreatingManual(false);
|
|
3385
|
+
},
|
|
3292
3386
|
disabled: saving,
|
|
3293
3387
|
className: "rounded-xl font-medium",
|
|
3294
3388
|
children: t.cancel
|
|
@@ -3301,8 +3395,9 @@ function CollectionEditor({ collection }) {
|
|
|
3301
3395
|
type: "primary",
|
|
3302
3396
|
onClick: save,
|
|
3303
3397
|
loading: saving,
|
|
3304
|
-
|
|
3305
|
-
|
|
3398
|
+
disabled: saving || Object.keys(duplicateErrors).length > 0,
|
|
3399
|
+
className: "min-w-[140px] rounded-xl font-bold shadow-sm bg-blue-600 hover:bg-blue-700 disabled:opacity-50",
|
|
3400
|
+
children: isCreatingEntry ? collection.submitLabel || (t.create ? t.create.toUpperCase() : "CREAR") : collection.saveLabel || (t.save ? t.save.toUpperCase() : "GUARDAR")
|
|
3306
3401
|
}
|
|
3307
3402
|
)
|
|
3308
3403
|
] })
|
|
@@ -3383,7 +3478,12 @@ function CollectionEditor({ collection }) {
|
|
|
3383
3478
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3384
3479
|
"button",
|
|
3385
3480
|
{
|
|
3386
|
-
onClick: () =>
|
|
3481
|
+
onClick: () => {
|
|
3482
|
+
setIsCreatingManual(false);
|
|
3483
|
+
setOriginalId(String(e.id || ""));
|
|
3484
|
+
setDuplicateErrors({});
|
|
3485
|
+
setEditing({ ...e });
|
|
3486
|
+
},
|
|
3387
3487
|
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
|
|
3388
3488
|
title: t.edit,
|
|
3389
3489
|
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "h-4 w-4" })
|
|
@@ -4057,9 +4157,9 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
4057
4157
|
}
|
|
4058
4158
|
function PasswordField({ value, onChange }) {
|
|
4059
4159
|
const [show, setShow] = (0, import_react5.useState)(false);
|
|
4060
|
-
const
|
|
4061
|
-
const [displayValue, setDisplayValue] = (0, import_react5.useState)(
|
|
4062
|
-
const [pristine, setPristine] = (0, import_react5.useState)(
|
|
4160
|
+
const hasExisting = Boolean(value && String(value).trim().length > 0);
|
|
4161
|
+
const [displayValue, setDisplayValue] = (0, import_react5.useState)("");
|
|
4162
|
+
const [pristine, setPristine] = (0, import_react5.useState)(hasExisting);
|
|
4063
4163
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
|
|
4064
4164
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4065
4165
|
"input",
|
|
@@ -4071,7 +4171,7 @@ function PasswordField({ value, onChange }) {
|
|
|
4071
4171
|
setDisplayValue(e.target.value);
|
|
4072
4172
|
onChange(e.target.value);
|
|
4073
4173
|
},
|
|
4074
|
-
placeholder: pristine ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 (
|
|
4174
|
+
placeholder: pristine ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 (dejar en blanco para conservar)" : "Ingresa la contrase\xF1a",
|
|
4075
4175
|
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all pr-10"
|
|
4076
4176
|
}
|
|
4077
4177
|
),
|
|
@@ -4964,6 +5064,7 @@ function ReferenceSelect({
|
|
|
4964
5064
|
}) {
|
|
4965
5065
|
const ctx = useCmsContext();
|
|
4966
5066
|
const t = useAdminI18n();
|
|
5067
|
+
const { message } = import_antd.App.useApp();
|
|
4967
5068
|
const [options, setOptions] = (0, import_react5.useState)([]);
|
|
4968
5069
|
const [loading, setLoading] = (0, import_react5.useState)(true);
|
|
4969
5070
|
const [clientModalOpen, setClientModalOpen] = (0, import_react5.useState)(false);
|
|
@@ -4990,6 +5091,12 @@ function ReferenceSelect({
|
|
|
4990
5091
|
setClientError(t.nameRequired);
|
|
4991
5092
|
return;
|
|
4992
5093
|
}
|
|
5094
|
+
const cleanId = newClient.id.trim().toLowerCase();
|
|
5095
|
+
const isDuplicate = options.some((opt) => String(opt.value || "").trim().toLowerCase() === cleanId);
|
|
5096
|
+
if (isDuplicate) {
|
|
5097
|
+
setClientError("Ya existe un cliente con este NIT o C\xE9dula. No se pueden repetir.");
|
|
5098
|
+
return;
|
|
5099
|
+
}
|
|
4993
5100
|
setCreatingClient(true);
|
|
4994
5101
|
try {
|
|
4995
5102
|
const entry = {
|
|
@@ -5026,7 +5133,7 @@ function ReferenceSelect({
|
|
|
5026
5133
|
ciudad: "",
|
|
5027
5134
|
direccion: ""
|
|
5028
5135
|
});
|
|
5029
|
-
|
|
5136
|
+
message.success(t.clientCreatedSuccess);
|
|
5030
5137
|
} catch (err) {
|
|
5031
5138
|
setClientError(err?.message || "Error al crear cliente.");
|
|
5032
5139
|
} finally {
|
|
@@ -5215,9 +5322,23 @@ function ReferenceSelect({
|
|
|
5215
5322
|
import_antd.Input,
|
|
5216
5323
|
{
|
|
5217
5324
|
size: "large",
|
|
5325
|
+
status: clientError && clientError.includes("identificaci\xF3n") ? "error" : void 0,
|
|
5218
5326
|
placeholder: t.clientIdentification,
|
|
5219
5327
|
value: newClient.id,
|
|
5220
|
-
onChange: (e) =>
|
|
5328
|
+
onChange: (e) => {
|
|
5329
|
+
setNewClient((prev) => ({ ...prev, id: e.target.value }));
|
|
5330
|
+
if (clientError) setClientError("");
|
|
5331
|
+
},
|
|
5332
|
+
onBlur: (e) => {
|
|
5333
|
+
const clean = (e.target.value || "").trim().toLowerCase();
|
|
5334
|
+
if (clean) {
|
|
5335
|
+
const dup = options.find((opt) => String(opt.value || "").trim().toLowerCase() === clean);
|
|
5336
|
+
if (dup) {
|
|
5337
|
+
setClientError(`Ya existe un cliente con esta identificaci\xF3n (\xAB${dup.label || clean}\xBB).`);
|
|
5338
|
+
message.warning(`\u26A0\uFE0F Ya existe un cliente con esta identificaci\xF3n: ${clean}.`);
|
|
5339
|
+
}
|
|
5340
|
+
}
|
|
5341
|
+
}
|
|
5221
5342
|
}
|
|
5222
5343
|
)
|
|
5223
5344
|
] }),
|
package/dist/index.mjs
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
Switch,
|
|
36
36
|
Button,
|
|
37
37
|
Image,
|
|
38
|
-
|
|
38
|
+
App
|
|
39
39
|
} from "antd";
|
|
40
40
|
import dayjs from "dayjs";
|
|
41
41
|
import {
|
|
@@ -66,7 +66,8 @@ import {
|
|
|
66
66
|
LogOut,
|
|
67
67
|
ExternalLink,
|
|
68
68
|
Check,
|
|
69
|
-
GripVertical
|
|
69
|
+
GripVertical,
|
|
70
|
+
AlertTriangle
|
|
70
71
|
} from "lucide-react";
|
|
71
72
|
|
|
72
73
|
// src/admin/i18n.ts
|
|
@@ -364,10 +365,11 @@ function FilePickerButton({
|
|
|
364
365
|
] });
|
|
365
366
|
}
|
|
366
367
|
function AdminApp(props) {
|
|
368
|
+
const content = /* @__PURE__ */ jsx(App, { className: "min-h-screen", children: /* @__PURE__ */ jsx(AdminAppContent, { ...props }) });
|
|
367
369
|
if (props.projectId) {
|
|
368
|
-
return /* @__PURE__ */ jsx(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children:
|
|
370
|
+
return /* @__PURE__ */ jsx(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: content });
|
|
369
371
|
}
|
|
370
|
-
return
|
|
372
|
+
return content;
|
|
371
373
|
}
|
|
372
374
|
function AdminAppContent(props) {
|
|
373
375
|
const ctx = useCmsContext();
|
|
@@ -1731,8 +1733,12 @@ function CollectionsSection() {
|
|
|
1731
1733
|
function CollectionEditor({ collection }) {
|
|
1732
1734
|
const ctx = useCmsContext();
|
|
1733
1735
|
const t = useAdminI18n();
|
|
1736
|
+
const { message } = App.useApp();
|
|
1734
1737
|
const [entries, setEntries] = useState([]);
|
|
1735
1738
|
const [editing, setEditing] = useState(null);
|
|
1739
|
+
const [originalId, setOriginalId] = useState(null);
|
|
1740
|
+
const [duplicateErrors, setDuplicateErrors] = useState({});
|
|
1741
|
+
const [isCreatingManual, setIsCreatingManual] = useState(false);
|
|
1736
1742
|
const [saving, setSaving] = useState(false);
|
|
1737
1743
|
const [deletingId, setDeletingId] = useState(null);
|
|
1738
1744
|
const [loadingEntries, setLoadingEntries] = useState(true);
|
|
@@ -1758,6 +1764,9 @@ function CollectionEditor({ collection }) {
|
|
|
1758
1764
|
load();
|
|
1759
1765
|
}, [load]);
|
|
1760
1766
|
const startNew = () => {
|
|
1767
|
+
setIsCreatingManual(true);
|
|
1768
|
+
setOriginalId(null);
|
|
1769
|
+
setDuplicateErrors({});
|
|
1761
1770
|
const base = { id: crypto.randomUUID() };
|
|
1762
1771
|
collection.fields.forEach((f) => {
|
|
1763
1772
|
if (f.id === "order") {
|
|
@@ -1811,9 +1820,43 @@ function CollectionEditor({ collection }) {
|
|
|
1811
1820
|
finalEditing[f.id] = val;
|
|
1812
1821
|
}
|
|
1813
1822
|
});
|
|
1823
|
+
const isClientOrEmployee = collection.id === "clients" || collection.id === "employees";
|
|
1824
|
+
const uniqueFields = collection.fields.filter((f) => f.unique || isClientOrEmployee && f.id === "id");
|
|
1825
|
+
for (const f of uniqueFields) {
|
|
1826
|
+
const val = String(finalEditing[f.id] || "").trim().toLowerCase();
|
|
1827
|
+
if (!val) {
|
|
1828
|
+
message.error(`El campo "${f.label || f.id}" es obligatorio.`);
|
|
1829
|
+
setSaving(false);
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
const isDuplicate = entries.some((e) => {
|
|
1833
|
+
if (originalId && String(e.id).trim().toLowerCase() === originalId.trim().toLowerCase()) {
|
|
1834
|
+
return false;
|
|
1835
|
+
}
|
|
1836
|
+
const existingVal = String(e[f.id] || "").trim().toLowerCase();
|
|
1837
|
+
return existingVal === val;
|
|
1838
|
+
});
|
|
1839
|
+
if (isDuplicate) {
|
|
1840
|
+
message.error(
|
|
1841
|
+
`Ya existe un registro en ${collection.name} con ${f.label || f.id}: "${finalEditing[f.id]}". No se pueden repetir c\xE9dulas ni NIT.`
|
|
1842
|
+
);
|
|
1843
|
+
setSaving(false);
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
if (originalId && String(finalEditing.id).trim().toLowerCase() !== originalId.trim().toLowerCase()) {
|
|
1848
|
+
try {
|
|
1849
|
+
await ctx.adapter.deleteEntry(collection.id, originalId);
|
|
1850
|
+
} catch (cleanupErr) {
|
|
1851
|
+
console.warn("No se pudo limpiar el registro anterior:", cleanupErr);
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1814
1854
|
await ctx.adapter.putEntry(collection.id, finalEditing);
|
|
1855
|
+
message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
|
|
1815
1856
|
ctx.notifyCollectionChanged();
|
|
1816
1857
|
setEditing(null);
|
|
1858
|
+
setOriginalId(null);
|
|
1859
|
+
setIsCreatingManual(false);
|
|
1817
1860
|
load();
|
|
1818
1861
|
} finally {
|
|
1819
1862
|
setSaving(false);
|
|
@@ -1866,7 +1909,7 @@ function CollectionEditor({ collection }) {
|
|
|
1866
1909
|
setDragOverIdx(null);
|
|
1867
1910
|
};
|
|
1868
1911
|
const visibleFields = collection.tableFields?.length ? collection.tableFields.map((tf) => collection.fields.find((f) => f.id === tf)).filter(Boolean) : collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 6);
|
|
1869
|
-
const isCreatingEntry = editing ? !entries.some((entry) => entry.id === editing.id) : false;
|
|
1912
|
+
const isCreatingEntry = isCreatingManual || (editing ? !entries.some((entry) => entry.id && entry.id === editing.id || entry._id && entry._id === (editing._id || editing.id)) : false);
|
|
1870
1913
|
return /* @__PURE__ */ jsxs("div", { className: "mx-auto max-w-5xl", children: [
|
|
1871
1914
|
/* @__PURE__ */ jsxs("div", { className: "mb-8 flex items-center justify-between", children: [
|
|
1872
1915
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
@@ -1979,7 +2022,11 @@ function CollectionEditor({ collection }) {
|
|
|
1979
2022
|
] })
|
|
1980
2023
|
] }),
|
|
1981
2024
|
onCancel: () => {
|
|
1982
|
-
if (!saving)
|
|
2025
|
+
if (!saving) {
|
|
2026
|
+
setEditing(null);
|
|
2027
|
+
setOriginalId(null);
|
|
2028
|
+
setIsCreatingManual(false);
|
|
2029
|
+
}
|
|
1983
2030
|
},
|
|
1984
2031
|
footer: null,
|
|
1985
2032
|
centered: true,
|
|
@@ -2506,18 +2553,61 @@ function CollectionEditor({ collection }) {
|
|
|
2506
2553
|
]
|
|
2507
2554
|
}
|
|
2508
2555
|
) : null
|
|
2509
|
-
] }) : /* @__PURE__ */
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2556
|
+
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
2557
|
+
/* @__PURE__ */ jsx(
|
|
2558
|
+
Input,
|
|
2559
|
+
{
|
|
2560
|
+
size: "large",
|
|
2561
|
+
status: duplicateErrors[f.id] ? "error" : void 0,
|
|
2562
|
+
value: String(editing[f.id] ?? ""),
|
|
2563
|
+
readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
|
|
2564
|
+
disabled: f.readOnly,
|
|
2565
|
+
onChange: (e) => {
|
|
2566
|
+
const val = e.target.value;
|
|
2567
|
+
setEditing({ ...editing, [f.id]: val });
|
|
2568
|
+
if (duplicateErrors[f.id]) {
|
|
2569
|
+
setDuplicateErrors((prev) => {
|
|
2570
|
+
const next = { ...prev };
|
|
2571
|
+
delete next[f.id];
|
|
2572
|
+
return next;
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2575
|
+
},
|
|
2576
|
+
onBlur: (e) => {
|
|
2577
|
+
const isUniqueField = f.unique || (collection.id === "clients" || collection.id === "employees") && f.id === "id";
|
|
2578
|
+
if (isUniqueField) {
|
|
2579
|
+
const val = (e.target.value || "").trim().toLowerCase();
|
|
2580
|
+
if (val) {
|
|
2581
|
+
const dup = entries.find((entry) => {
|
|
2582
|
+
if (originalId && String(entry.id).trim().toLowerCase() === originalId.trim().toLowerCase()) {
|
|
2583
|
+
return false;
|
|
2584
|
+
}
|
|
2585
|
+
return String(entry[f.id] || "").trim().toLowerCase() === val;
|
|
2586
|
+
});
|
|
2587
|
+
if (dup) {
|
|
2588
|
+
const dupName = dup.nombre ? ` (\xAB${dup.nombre} ${dup.apellido || ""}\xBB)` : "";
|
|
2589
|
+
const errMsg = `Esta identificaci\xF3n ya est\xE1 registrada${dupName}. No puedes usar una c\xE9dula o NIT repetido.`;
|
|
2590
|
+
setDuplicateErrors((prev) => ({ ...prev, [f.id]: errMsg }));
|
|
2591
|
+
message.warning(`\u26A0\uFE0F Ya existe un registro con esta identificaci\xF3n: ${e.target.value.trim()}.`);
|
|
2592
|
+
} else {
|
|
2593
|
+
setDuplicateErrors((prev) => {
|
|
2594
|
+
const next = { ...prev };
|
|
2595
|
+
delete next[f.id];
|
|
2596
|
+
return next;
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
},
|
|
2602
|
+
placeholder: f.label,
|
|
2603
|
+
className: "w-full rounded-xl"
|
|
2604
|
+
}
|
|
2605
|
+
),
|
|
2606
|
+
duplicateErrors[f.id] && /* @__PURE__ */ jsxs("p", { className: "text-xs text-rose-600 font-bold mt-1.5 flex items-center gap-1.5 animate-in fade-in duration-200", children: [
|
|
2607
|
+
/* @__PURE__ */ jsx(AlertTriangle, { className: "w-3.5 h-3.5 shrink-0 text-rose-500" }),
|
|
2608
|
+
/* @__PURE__ */ jsx("span", { children: duplicateErrors[f.id] })
|
|
2609
|
+
] })
|
|
2610
|
+
] })
|
|
2521
2611
|
] }, f.id);
|
|
2522
2612
|
}) }) }),
|
|
2523
2613
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 justify-end gap-3 border-t border-slate-200 bg-white px-6 py-4", children: [
|
|
@@ -2525,7 +2615,12 @@ function CollectionEditor({ collection }) {
|
|
|
2525
2615
|
Button,
|
|
2526
2616
|
{
|
|
2527
2617
|
size: "large",
|
|
2528
|
-
onClick: () =>
|
|
2618
|
+
onClick: () => {
|
|
2619
|
+
setEditing(null);
|
|
2620
|
+
setOriginalId(null);
|
|
2621
|
+
setDuplicateErrors({});
|
|
2622
|
+
setIsCreatingManual(false);
|
|
2623
|
+
},
|
|
2529
2624
|
disabled: saving,
|
|
2530
2625
|
className: "rounded-xl font-medium",
|
|
2531
2626
|
children: t.cancel
|
|
@@ -2538,8 +2633,9 @@ function CollectionEditor({ collection }) {
|
|
|
2538
2633
|
type: "primary",
|
|
2539
2634
|
onClick: save,
|
|
2540
2635
|
loading: saving,
|
|
2541
|
-
|
|
2542
|
-
|
|
2636
|
+
disabled: saving || Object.keys(duplicateErrors).length > 0,
|
|
2637
|
+
className: "min-w-[140px] rounded-xl font-bold shadow-sm bg-blue-600 hover:bg-blue-700 disabled:opacity-50",
|
|
2638
|
+
children: isCreatingEntry ? collection.submitLabel || (t.create ? t.create.toUpperCase() : "CREAR") : collection.saveLabel || (t.save ? t.save.toUpperCase() : "GUARDAR")
|
|
2543
2639
|
}
|
|
2544
2640
|
)
|
|
2545
2641
|
] })
|
|
@@ -2620,7 +2716,12 @@ function CollectionEditor({ collection }) {
|
|
|
2620
2716
|
/* @__PURE__ */ jsx(
|
|
2621
2717
|
"button",
|
|
2622
2718
|
{
|
|
2623
|
-
onClick: () =>
|
|
2719
|
+
onClick: () => {
|
|
2720
|
+
setIsCreatingManual(false);
|
|
2721
|
+
setOriginalId(String(e.id || ""));
|
|
2722
|
+
setDuplicateErrors({});
|
|
2723
|
+
setEditing({ ...e });
|
|
2724
|
+
},
|
|
2624
2725
|
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
|
|
2625
2726
|
title: t.edit,
|
|
2626
2727
|
children: /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4" })
|
|
@@ -3294,9 +3395,9 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
3294
3395
|
}
|
|
3295
3396
|
function PasswordField({ value, onChange }) {
|
|
3296
3397
|
const [show, setShow] = useState(false);
|
|
3297
|
-
const
|
|
3298
|
-
const [displayValue, setDisplayValue] = useState(
|
|
3299
|
-
const [pristine, setPristine] = useState(
|
|
3398
|
+
const hasExisting = Boolean(value && String(value).trim().length > 0);
|
|
3399
|
+
const [displayValue, setDisplayValue] = useState("");
|
|
3400
|
+
const [pristine, setPristine] = useState(hasExisting);
|
|
3300
3401
|
return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
3301
3402
|
/* @__PURE__ */ jsx(
|
|
3302
3403
|
"input",
|
|
@@ -3308,7 +3409,7 @@ function PasswordField({ value, onChange }) {
|
|
|
3308
3409
|
setDisplayValue(e.target.value);
|
|
3309
3410
|
onChange(e.target.value);
|
|
3310
3411
|
},
|
|
3311
|
-
placeholder: pristine ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 (
|
|
3412
|
+
placeholder: pristine ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 (dejar en blanco para conservar)" : "Ingresa la contrase\xF1a",
|
|
3312
3413
|
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all pr-10"
|
|
3313
3414
|
}
|
|
3314
3415
|
),
|
|
@@ -4201,6 +4302,7 @@ function ReferenceSelect({
|
|
|
4201
4302
|
}) {
|
|
4202
4303
|
const ctx = useCmsContext();
|
|
4203
4304
|
const t = useAdminI18n();
|
|
4305
|
+
const { message } = App.useApp();
|
|
4204
4306
|
const [options, setOptions] = useState([]);
|
|
4205
4307
|
const [loading, setLoading] = useState(true);
|
|
4206
4308
|
const [clientModalOpen, setClientModalOpen] = useState(false);
|
|
@@ -4227,6 +4329,12 @@ function ReferenceSelect({
|
|
|
4227
4329
|
setClientError(t.nameRequired);
|
|
4228
4330
|
return;
|
|
4229
4331
|
}
|
|
4332
|
+
const cleanId = newClient.id.trim().toLowerCase();
|
|
4333
|
+
const isDuplicate = options.some((opt) => String(opt.value || "").trim().toLowerCase() === cleanId);
|
|
4334
|
+
if (isDuplicate) {
|
|
4335
|
+
setClientError("Ya existe un cliente con este NIT o C\xE9dula. No se pueden repetir.");
|
|
4336
|
+
return;
|
|
4337
|
+
}
|
|
4230
4338
|
setCreatingClient(true);
|
|
4231
4339
|
try {
|
|
4232
4340
|
const entry = {
|
|
@@ -4452,9 +4560,23 @@ function ReferenceSelect({
|
|
|
4452
4560
|
Input,
|
|
4453
4561
|
{
|
|
4454
4562
|
size: "large",
|
|
4563
|
+
status: clientError && clientError.includes("identificaci\xF3n") ? "error" : void 0,
|
|
4455
4564
|
placeholder: t.clientIdentification,
|
|
4456
4565
|
value: newClient.id,
|
|
4457
|
-
onChange: (e) =>
|
|
4566
|
+
onChange: (e) => {
|
|
4567
|
+
setNewClient((prev) => ({ ...prev, id: e.target.value }));
|
|
4568
|
+
if (clientError) setClientError("");
|
|
4569
|
+
},
|
|
4570
|
+
onBlur: (e) => {
|
|
4571
|
+
const clean = (e.target.value || "").trim().toLowerCase();
|
|
4572
|
+
if (clean) {
|
|
4573
|
+
const dup = options.find((opt) => String(opt.value || "").trim().toLowerCase() === clean);
|
|
4574
|
+
if (dup) {
|
|
4575
|
+
setClientError(`Ya existe un cliente con esta identificaci\xF3n (\xAB${dup.label || clean}\xBB).`);
|
|
4576
|
+
message.warning(`\u26A0\uFE0F Ya existe un cliente con esta identificaci\xF3n: ${clean}.`);
|
|
4577
|
+
}
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4458
4580
|
}
|
|
4459
4581
|
)
|
|
4460
4582
|
] }),
|
package/dist/types.d.mts
CHANGED
|
@@ -61,17 +61,20 @@ interface CollectionField {
|
|
|
61
61
|
})[]>;
|
|
62
62
|
colSpan?: 1 | 2 | 6 | 12;
|
|
63
63
|
readOnly?: boolean;
|
|
64
|
+
unique?: boolean;
|
|
64
65
|
}
|
|
65
66
|
interface CollectionDef {
|
|
66
67
|
id: string;
|
|
67
68
|
name: string;
|
|
68
69
|
description?: string;
|
|
69
70
|
fields: CollectionField[];
|
|
71
|
+
uniqueFields?: string[];
|
|
70
72
|
searchBy?: string[];
|
|
71
73
|
filterBy?: string[];
|
|
72
74
|
tableFields?: string[];
|
|
73
75
|
createTitle?: string;
|
|
74
76
|
submitLabel?: string;
|
|
77
|
+
saveLabel?: string;
|
|
75
78
|
isSeparator?: boolean;
|
|
76
79
|
}
|
|
77
80
|
interface GlobalGroup {
|
package/dist/types.d.ts
CHANGED
|
@@ -61,17 +61,20 @@ interface CollectionField {
|
|
|
61
61
|
})[]>;
|
|
62
62
|
colSpan?: 1 | 2 | 6 | 12;
|
|
63
63
|
readOnly?: boolean;
|
|
64
|
+
unique?: boolean;
|
|
64
65
|
}
|
|
65
66
|
interface CollectionDef {
|
|
66
67
|
id: string;
|
|
67
68
|
name: string;
|
|
68
69
|
description?: string;
|
|
69
70
|
fields: CollectionField[];
|
|
71
|
+
uniqueFields?: string[];
|
|
70
72
|
searchBy?: string[];
|
|
71
73
|
filterBy?: string[];
|
|
72
74
|
tableFields?: string[];
|
|
73
75
|
createTitle?: string;
|
|
74
76
|
submitLabel?: string;
|
|
77
|
+
saveLabel?: string;
|
|
75
78
|
isSeparator?: boolean;
|
|
76
79
|
}
|
|
77
80
|
interface GlobalGroup {
|