admin-lib-cms 1.2.12 → 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 +131 -22
- package/dist/index.mjs +133 -23
- package/dist/types.d.mts +2 -0
- package/dist/types.d.ts +2 -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,11 @@ 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)({});
|
|
2499
2503
|
const [isCreatingManual, setIsCreatingManual] = (0, import_react5.useState)(false);
|
|
2500
2504
|
const [saving, setSaving] = (0, import_react5.useState)(false);
|
|
2501
2505
|
const [deletingId, setDeletingId] = (0, import_react5.useState)(null);
|
|
@@ -2523,6 +2527,8 @@ function CollectionEditor({ collection }) {
|
|
|
2523
2527
|
}, [load]);
|
|
2524
2528
|
const startNew = () => {
|
|
2525
2529
|
setIsCreatingManual(true);
|
|
2530
|
+
setOriginalId(null);
|
|
2531
|
+
setDuplicateErrors({});
|
|
2526
2532
|
const base = { id: crypto.randomUUID() };
|
|
2527
2533
|
collection.fields.forEach((f) => {
|
|
2528
2534
|
if (f.id === "order") {
|
|
@@ -2576,9 +2582,42 @@ function CollectionEditor({ collection }) {
|
|
|
2576
2582
|
finalEditing[f.id] = val;
|
|
2577
2583
|
}
|
|
2578
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
|
+
}
|
|
2579
2616
|
await ctx.adapter.putEntry(collection.id, finalEditing);
|
|
2617
|
+
message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
|
|
2580
2618
|
ctx.notifyCollectionChanged();
|
|
2581
2619
|
setEditing(null);
|
|
2620
|
+
setOriginalId(null);
|
|
2582
2621
|
setIsCreatingManual(false);
|
|
2583
2622
|
load();
|
|
2584
2623
|
} finally {
|
|
@@ -2747,6 +2786,7 @@ function CollectionEditor({ collection }) {
|
|
|
2747
2786
|
onCancel: () => {
|
|
2748
2787
|
if (!saving) {
|
|
2749
2788
|
setEditing(null);
|
|
2789
|
+
setOriginalId(null);
|
|
2750
2790
|
setIsCreatingManual(false);
|
|
2751
2791
|
}
|
|
2752
2792
|
},
|
|
@@ -3275,18 +3315,61 @@ function CollectionEditor({ collection }) {
|
|
|
3275
3315
|
]
|
|
3276
3316
|
}
|
|
3277
3317
|
) : null
|
|
3278
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
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
|
+
] })
|
|
3290
3373
|
] }, f.id);
|
|
3291
3374
|
}) }) }),
|
|
3292
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: [
|
|
@@ -3296,6 +3379,8 @@ function CollectionEditor({ collection }) {
|
|
|
3296
3379
|
size: "large",
|
|
3297
3380
|
onClick: () => {
|
|
3298
3381
|
setEditing(null);
|
|
3382
|
+
setOriginalId(null);
|
|
3383
|
+
setDuplicateErrors({});
|
|
3299
3384
|
setIsCreatingManual(false);
|
|
3300
3385
|
},
|
|
3301
3386
|
disabled: saving,
|
|
@@ -3310,7 +3395,8 @@ function CollectionEditor({ collection }) {
|
|
|
3310
3395
|
type: "primary",
|
|
3311
3396
|
onClick: save,
|
|
3312
3397
|
loading: saving,
|
|
3313
|
-
|
|
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",
|
|
3314
3400
|
children: isCreatingEntry ? collection.submitLabel || (t.create ? t.create.toUpperCase() : "CREAR") : collection.saveLabel || (t.save ? t.save.toUpperCase() : "GUARDAR")
|
|
3315
3401
|
}
|
|
3316
3402
|
)
|
|
@@ -3394,7 +3480,9 @@ function CollectionEditor({ collection }) {
|
|
|
3394
3480
|
{
|
|
3395
3481
|
onClick: () => {
|
|
3396
3482
|
setIsCreatingManual(false);
|
|
3397
|
-
|
|
3483
|
+
setOriginalId(String(e.id || ""));
|
|
3484
|
+
setDuplicateErrors({});
|
|
3485
|
+
setEditing({ ...e });
|
|
3398
3486
|
},
|
|
3399
3487
|
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
|
|
3400
3488
|
title: t.edit,
|
|
@@ -4069,9 +4157,9 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
4069
4157
|
}
|
|
4070
4158
|
function PasswordField({ value, onChange }) {
|
|
4071
4159
|
const [show, setShow] = (0, import_react5.useState)(false);
|
|
4072
|
-
const
|
|
4073
|
-
const [displayValue, setDisplayValue] = (0, import_react5.useState)(
|
|
4074
|
-
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);
|
|
4075
4163
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
|
|
4076
4164
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4077
4165
|
"input",
|
|
@@ -4083,7 +4171,7 @@ function PasswordField({ value, onChange }) {
|
|
|
4083
4171
|
setDisplayValue(e.target.value);
|
|
4084
4172
|
onChange(e.target.value);
|
|
4085
4173
|
},
|
|
4086
|
-
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",
|
|
4087
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"
|
|
4088
4176
|
}
|
|
4089
4177
|
),
|
|
@@ -4976,6 +5064,7 @@ function ReferenceSelect({
|
|
|
4976
5064
|
}) {
|
|
4977
5065
|
const ctx = useCmsContext();
|
|
4978
5066
|
const t = useAdminI18n();
|
|
5067
|
+
const { message } = import_antd.App.useApp();
|
|
4979
5068
|
const [options, setOptions] = (0, import_react5.useState)([]);
|
|
4980
5069
|
const [loading, setLoading] = (0, import_react5.useState)(true);
|
|
4981
5070
|
const [clientModalOpen, setClientModalOpen] = (0, import_react5.useState)(false);
|
|
@@ -5002,6 +5091,12 @@ function ReferenceSelect({
|
|
|
5002
5091
|
setClientError(t.nameRequired);
|
|
5003
5092
|
return;
|
|
5004
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
|
+
}
|
|
5005
5100
|
setCreatingClient(true);
|
|
5006
5101
|
try {
|
|
5007
5102
|
const entry = {
|
|
@@ -5038,7 +5133,7 @@ function ReferenceSelect({
|
|
|
5038
5133
|
ciudad: "",
|
|
5039
5134
|
direccion: ""
|
|
5040
5135
|
});
|
|
5041
|
-
|
|
5136
|
+
message.success(t.clientCreatedSuccess);
|
|
5042
5137
|
} catch (err) {
|
|
5043
5138
|
setClientError(err?.message || "Error al crear cliente.");
|
|
5044
5139
|
} finally {
|
|
@@ -5227,9 +5322,23 @@ function ReferenceSelect({
|
|
|
5227
5322
|
import_antd.Input,
|
|
5228
5323
|
{
|
|
5229
5324
|
size: "large",
|
|
5325
|
+
status: clientError && clientError.includes("identificaci\xF3n") ? "error" : void 0,
|
|
5230
5326
|
placeholder: t.clientIdentification,
|
|
5231
5327
|
value: newClient.id,
|
|
5232
|
-
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
|
+
}
|
|
5233
5342
|
}
|
|
5234
5343
|
)
|
|
5235
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,11 @@ 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({});
|
|
1736
1741
|
const [isCreatingManual, setIsCreatingManual] = useState(false);
|
|
1737
1742
|
const [saving, setSaving] = useState(false);
|
|
1738
1743
|
const [deletingId, setDeletingId] = useState(null);
|
|
@@ -1760,6 +1765,8 @@ function CollectionEditor({ collection }) {
|
|
|
1760
1765
|
}, [load]);
|
|
1761
1766
|
const startNew = () => {
|
|
1762
1767
|
setIsCreatingManual(true);
|
|
1768
|
+
setOriginalId(null);
|
|
1769
|
+
setDuplicateErrors({});
|
|
1763
1770
|
const base = { id: crypto.randomUUID() };
|
|
1764
1771
|
collection.fields.forEach((f) => {
|
|
1765
1772
|
if (f.id === "order") {
|
|
@@ -1813,9 +1820,42 @@ function CollectionEditor({ collection }) {
|
|
|
1813
1820
|
finalEditing[f.id] = val;
|
|
1814
1821
|
}
|
|
1815
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
|
+
}
|
|
1816
1854
|
await ctx.adapter.putEntry(collection.id, finalEditing);
|
|
1855
|
+
message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
|
|
1817
1856
|
ctx.notifyCollectionChanged();
|
|
1818
1857
|
setEditing(null);
|
|
1858
|
+
setOriginalId(null);
|
|
1819
1859
|
setIsCreatingManual(false);
|
|
1820
1860
|
load();
|
|
1821
1861
|
} finally {
|
|
@@ -1984,6 +2024,7 @@ function CollectionEditor({ collection }) {
|
|
|
1984
2024
|
onCancel: () => {
|
|
1985
2025
|
if (!saving) {
|
|
1986
2026
|
setEditing(null);
|
|
2027
|
+
setOriginalId(null);
|
|
1987
2028
|
setIsCreatingManual(false);
|
|
1988
2029
|
}
|
|
1989
2030
|
},
|
|
@@ -2512,18 +2553,61 @@ function CollectionEditor({ collection }) {
|
|
|
2512
2553
|
]
|
|
2513
2554
|
}
|
|
2514
2555
|
) : null
|
|
2515
|
-
] }) : /* @__PURE__ */
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
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
|
+
] })
|
|
2527
2611
|
] }, f.id);
|
|
2528
2612
|
}) }) }),
|
|
2529
2613
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 justify-end gap-3 border-t border-slate-200 bg-white px-6 py-4", children: [
|
|
@@ -2533,6 +2617,8 @@ function CollectionEditor({ collection }) {
|
|
|
2533
2617
|
size: "large",
|
|
2534
2618
|
onClick: () => {
|
|
2535
2619
|
setEditing(null);
|
|
2620
|
+
setOriginalId(null);
|
|
2621
|
+
setDuplicateErrors({});
|
|
2536
2622
|
setIsCreatingManual(false);
|
|
2537
2623
|
},
|
|
2538
2624
|
disabled: saving,
|
|
@@ -2547,7 +2633,8 @@ function CollectionEditor({ collection }) {
|
|
|
2547
2633
|
type: "primary",
|
|
2548
2634
|
onClick: save,
|
|
2549
2635
|
loading: saving,
|
|
2550
|
-
|
|
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",
|
|
2551
2638
|
children: isCreatingEntry ? collection.submitLabel || (t.create ? t.create.toUpperCase() : "CREAR") : collection.saveLabel || (t.save ? t.save.toUpperCase() : "GUARDAR")
|
|
2552
2639
|
}
|
|
2553
2640
|
)
|
|
@@ -2631,7 +2718,9 @@ function CollectionEditor({ collection }) {
|
|
|
2631
2718
|
{
|
|
2632
2719
|
onClick: () => {
|
|
2633
2720
|
setIsCreatingManual(false);
|
|
2634
|
-
|
|
2721
|
+
setOriginalId(String(e.id || ""));
|
|
2722
|
+
setDuplicateErrors({});
|
|
2723
|
+
setEditing({ ...e });
|
|
2635
2724
|
},
|
|
2636
2725
|
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
|
|
2637
2726
|
title: t.edit,
|
|
@@ -3306,9 +3395,9 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
3306
3395
|
}
|
|
3307
3396
|
function PasswordField({ value, onChange }) {
|
|
3308
3397
|
const [show, setShow] = useState(false);
|
|
3309
|
-
const
|
|
3310
|
-
const [displayValue, setDisplayValue] = useState(
|
|
3311
|
-
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);
|
|
3312
3401
|
return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
3313
3402
|
/* @__PURE__ */ jsx(
|
|
3314
3403
|
"input",
|
|
@@ -3320,7 +3409,7 @@ function PasswordField({ value, onChange }) {
|
|
|
3320
3409
|
setDisplayValue(e.target.value);
|
|
3321
3410
|
onChange(e.target.value);
|
|
3322
3411
|
},
|
|
3323
|
-
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",
|
|
3324
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"
|
|
3325
3414
|
}
|
|
3326
3415
|
),
|
|
@@ -4213,6 +4302,7 @@ function ReferenceSelect({
|
|
|
4213
4302
|
}) {
|
|
4214
4303
|
const ctx = useCmsContext();
|
|
4215
4304
|
const t = useAdminI18n();
|
|
4305
|
+
const { message } = App.useApp();
|
|
4216
4306
|
const [options, setOptions] = useState([]);
|
|
4217
4307
|
const [loading, setLoading] = useState(true);
|
|
4218
4308
|
const [clientModalOpen, setClientModalOpen] = useState(false);
|
|
@@ -4239,6 +4329,12 @@ function ReferenceSelect({
|
|
|
4239
4329
|
setClientError(t.nameRequired);
|
|
4240
4330
|
return;
|
|
4241
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
|
+
}
|
|
4242
4338
|
setCreatingClient(true);
|
|
4243
4339
|
try {
|
|
4244
4340
|
const entry = {
|
|
@@ -4464,9 +4560,23 @@ function ReferenceSelect({
|
|
|
4464
4560
|
Input,
|
|
4465
4561
|
{
|
|
4466
4562
|
size: "large",
|
|
4563
|
+
status: clientError && clientError.includes("identificaci\xF3n") ? "error" : void 0,
|
|
4467
4564
|
placeholder: t.clientIdentification,
|
|
4468
4565
|
value: newClient.id,
|
|
4469
|
-
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
|
+
}
|
|
4470
4580
|
}
|
|
4471
4581
|
)
|
|
4472
4582
|
] }),
|
package/dist/types.d.mts
CHANGED
|
@@ -61,12 +61,14 @@ 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[];
|
package/dist/types.d.ts
CHANGED
|
@@ -61,12 +61,14 @@ 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[];
|