admin-lib-cms 1.2.12 → 1.2.14

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 CHANGED
@@ -1016,8 +1016,8 @@ var AdminI18nContext = import_react5.default.createContext(getAdminTranslations(
1016
1016
  function useAdminI18n() {
1017
1017
  return import_react5.default.useContext(AdminI18nContext);
1018
1018
  }
1019
- var TIME_STORAGE_FORMAT = "HH:mm";
1020
- var TIME_DISPLAY_FORMAT = "h:mm A";
1019
+ var TIME_STORAGE_FORMAT = "h:mm a";
1020
+ var TIME_DISPLAY_FORMAT = "h:mm a";
1021
1021
  var TIME_PICKER_THEME = {
1022
1022
  token: {
1023
1023
  borderRadius: 12,
@@ -1078,6 +1078,16 @@ function toDayjsTime(value) {
1078
1078
  function toStoredTime(value) {
1079
1079
  return value?.format(TIME_STORAGE_FORMAT) ?? "";
1080
1080
  }
1081
+ function formatTo12Hour(value) {
1082
+ const str = String(value ?? "").trim();
1083
+ if (!str || str === "\u2014" || str === "undefined") return "";
1084
+ if (/\b(am|pm)\b/i.test(str)) return str.toLowerCase();
1085
+ const d = toDayjsTime(str);
1086
+ if (d && d.isValid()) {
1087
+ return d.format("h:mm a");
1088
+ }
1089
+ return str;
1090
+ }
1081
1091
  async function handleImageFile(file, onUrl, uploadImage) {
1082
1092
  if (uploadImage) {
1083
1093
  try {
@@ -1127,10 +1137,11 @@ function FilePickerButton({
1127
1137
  ] });
1128
1138
  }
1129
1139
  function AdminApp(props) {
1140
+ 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
1141
  if (props.projectId) {
1131
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AdminAppContent, { ...props }) });
1142
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: content });
1132
1143
  }
1133
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AdminAppContent, { ...props });
1144
+ return content;
1134
1145
  }
1135
1146
  function AdminAppContent(props) {
1136
1147
  const ctx = useCmsContext();
@@ -2494,9 +2505,13 @@ function CollectionsSection() {
2494
2505
  function CollectionEditor({ collection }) {
2495
2506
  const ctx = useCmsContext();
2496
2507
  const t = useAdminI18n();
2508
+ const { message } = import_antd.App.useApp();
2497
2509
  const [entries, setEntries] = (0, import_react5.useState)([]);
2498
2510
  const [editing, setEditing] = (0, import_react5.useState)(null);
2511
+ const [originalId, setOriginalId] = (0, import_react5.useState)(null);
2512
+ const [duplicateErrors, setDuplicateErrors] = (0, import_react5.useState)({});
2499
2513
  const [isCreatingManual, setIsCreatingManual] = (0, import_react5.useState)(false);
2514
+ const [isViewingDetail, setIsViewingDetail] = (0, import_react5.useState)(false);
2500
2515
  const [saving, setSaving] = (0, import_react5.useState)(false);
2501
2516
  const [deletingId, setDeletingId] = (0, import_react5.useState)(null);
2502
2517
  const [loadingEntries, setLoadingEntries] = (0, import_react5.useState)(true);
@@ -2523,6 +2538,8 @@ function CollectionEditor({ collection }) {
2523
2538
  }, [load]);
2524
2539
  const startNew = () => {
2525
2540
  setIsCreatingManual(true);
2541
+ setOriginalId(null);
2542
+ setDuplicateErrors({});
2526
2543
  const base = { id: crypto.randomUUID() };
2527
2544
  collection.fields.forEach((f) => {
2528
2545
  if (f.id === "order") {
@@ -2576,9 +2593,42 @@ function CollectionEditor({ collection }) {
2576
2593
  finalEditing[f.id] = val;
2577
2594
  }
2578
2595
  });
2596
+ const isClientOrEmployee = collection.id === "clients" || collection.id === "employees";
2597
+ const uniqueFields = collection.fields.filter((f) => f.unique || isClientOrEmployee && f.id === "id");
2598
+ for (const f of uniqueFields) {
2599
+ const val = String(finalEditing[f.id] || "").trim().toLowerCase();
2600
+ if (!val) {
2601
+ message.error(`El campo "${f.label || f.id}" es obligatorio.`);
2602
+ setSaving(false);
2603
+ return;
2604
+ }
2605
+ const isDuplicate = entries.some((e) => {
2606
+ if (originalId && String(e.id).trim().toLowerCase() === originalId.trim().toLowerCase()) {
2607
+ return false;
2608
+ }
2609
+ const existingVal = String(e[f.id] || "").trim().toLowerCase();
2610
+ return existingVal === val;
2611
+ });
2612
+ if (isDuplicate) {
2613
+ message.error(
2614
+ `Ya existe un registro en ${collection.name} con ${f.label || f.id}: "${finalEditing[f.id]}". No se pueden repetir c\xE9dulas ni NIT.`
2615
+ );
2616
+ setSaving(false);
2617
+ return;
2618
+ }
2619
+ }
2620
+ if (originalId && String(finalEditing.id).trim().toLowerCase() !== originalId.trim().toLowerCase()) {
2621
+ try {
2622
+ await ctx.adapter.deleteEntry(collection.id, originalId);
2623
+ } catch (cleanupErr) {
2624
+ console.warn("No se pudo limpiar el registro anterior:", cleanupErr);
2625
+ }
2626
+ }
2579
2627
  await ctx.adapter.putEntry(collection.id, finalEditing);
2628
+ message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
2580
2629
  ctx.notifyCollectionChanged();
2581
2630
  setEditing(null);
2631
+ setOriginalId(null);
2582
2632
  setIsCreatingManual(false);
2583
2633
  load();
2584
2634
  } finally {
@@ -2722,10 +2772,11 @@ function CollectionEditor({ collection }) {
2722
2772
  open: Boolean(editing),
2723
2773
  title: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-between pr-8", children: [
2724
2774
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "flex items-center gap-2 text-slate-900 font-bold", children: [
2725
- isCreatingEntry ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "h-4 w-4 text-indigo-600" }),
2726
- isCreatingEntry ? collection.createTitle || `Nueva ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}` : `Editar ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}`
2775
+ isViewingDetail ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Eye, { className: "h-4 w-4 text-indigo-600" }) : isCreatingEntry ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "h-4 w-4 text-indigo-600" }),
2776
+ isViewingDetail ? `Detalle de ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}${editing?.numero ? ` #${editing.numero}` : ""}` : isCreatingEntry ? collection.createTitle || `Nueva ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}` : `Editar ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}`
2727
2777
  ] }),
2728
- !isCreatingEntry && editing && editing.estado !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
2778
+ isViewingDetail && editing && editing.estado !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: `px-2.5 py-1 text-xs font-semibold rounded-full ${String(editing.estado).toLowerCase().includes("terminad") ? "bg-emerald-50 text-emerald-700 border border-emerald-200" : String(editing.estado).toLowerCase().includes("proceso") ? "bg-sky-50 text-sky-700 border border-sky-200" : String(editing.estado).toLowerCase().includes("cancelad") ? "bg-rose-50 text-rose-700 border border-rose-200" : "bg-amber-50 text-amber-700 border border-amber-200"}`, children: String(editing.estado) }),
2779
+ !isViewingDetail && !isCreatingEntry && editing && editing.estado !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
2729
2780
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs text-slate-400 font-medium", children: "Estado:" }),
2730
2781
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2731
2782
  import_antd.Select,
@@ -2747,7 +2798,9 @@ function CollectionEditor({ collection }) {
2747
2798
  onCancel: () => {
2748
2799
  if (!saving) {
2749
2800
  setEditing(null);
2801
+ setOriginalId(null);
2750
2802
  setIsCreatingManual(false);
2803
+ setIsViewingDetail(false);
2751
2804
  }
2752
2805
  },
2753
2806
  footer: null,
@@ -2785,12 +2838,55 @@ function CollectionEditor({ collection }) {
2785
2838
  }).map((f) => {
2786
2839
  const isFullWidth = f.colSpan === 2 || f.colSpan === 12 || f.type === "signature" || f.type === "date" || f.type === "datetime" || f.type === "richtext" || f.type === "textarea" || f.type === "list" || f.type === "branch-settings" || f.type === "time-range";
2787
2840
  const colSpanClass = isFullWidth ? "lg:col-span-2 col-span-1" : "col-span-1";
2841
+ if (isViewingDetail) {
2842
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `block ${colSpanClass}`, children: [
2843
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: f.label }),
2844
+ f.customRender ? f.customRender({
2845
+ value: editing[f.id],
2846
+ record: editing,
2847
+ onChange: () => {
2848
+ },
2849
+ isCreatingEntry: false
2850
+ }) : f.type === "signature" ? editing[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl border border-slate-200 bg-white p-3 flex items-center justify-center shadow-sm", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2851
+ "img",
2852
+ {
2853
+ src: String(editing[f.id]),
2854
+ alt: f.label,
2855
+ className: "h-28 w-auto max-w-full object-contain"
2856
+ }
2857
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-400 italic py-1", children: "Sin firma registrada" }) : f.type === "list" ? Array.isArray(editing[f.id]) && editing[f.id].length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-1.5 pt-0.5", children: editing[f.id].map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2858
+ "span",
2859
+ {
2860
+ className: "rounded-full bg-slate-100 text-slate-700 px-3 py-1 text-xs font-medium border border-slate-200",
2861
+ children: String(item)
2862
+ },
2863
+ idx
2864
+ )) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-400 italic py-1", children: "Ninguno" }) : f.type === "link" ? Boolean(editing[f.id]) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2865
+ "a",
2866
+ {
2867
+ href: String(editing[f.id]),
2868
+ target: "_blank",
2869
+ rel: "noopener noreferrer",
2870
+ className: "inline-flex items-center gap-1.5 text-xs text-blue-600 hover:text-blue-800 underline font-medium py-1",
2871
+ children: [
2872
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ExternalLink, { className: "w-3.5 h-3.5" }),
2873
+ String(editing[f.id]).includes("maps") ? "Ver en Google Maps" : String(editing[f.id])
2874
+ ]
2875
+ }
2876
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs text-slate-400 py-1 block", children: "\u2014" }) : f.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2.5 text-sm text-slate-800 whitespace-pre-line leading-relaxed", children: String(editing[f.id] || "\u2014") }) : f.type === "time" || f.id.toLowerCase().includes("hora") || f.id === "inicioServicio" || f.id === "finServicio" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2 text-sm text-slate-800 font-medium", children: formatTo12Hour(editing[f.id]) || String(editing[f.id] ?? "\u2014") }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2 text-sm text-slate-800 font-medium", children: String(editing[f.id] ?? "\u2014") })
2877
+ ] }, f.id);
2878
+ }
2788
2879
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `block ${colSpanClass}`, children: [
2789
2880
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
2790
2881
  f.label,
2791
2882
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
2792
2883
  ] }),
2793
- f.type === "branch-settings" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2884
+ f.customRender ? f.customRender({
2885
+ value: editing[f.id],
2886
+ record: editing,
2887
+ onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2888
+ isCreatingEntry
2889
+ }) : f.type === "branch-settings" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2794
2890
  BranchSettingsEditor,
2795
2891
  {
2796
2892
  collectionId: f.collection || "",
@@ -3275,45 +3371,105 @@ function CollectionEditor({ collection }) {
3275
3371
  ]
3276
3372
  }
3277
3373
  ) : null
3278
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3279
- import_antd.Input,
3280
- {
3281
- size: "large",
3282
- value: String(editing[f.id] ?? ""),
3283
- readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
3284
- disabled: f.readOnly,
3285
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
3286
- placeholder: f.label,
3287
- className: "w-full rounded-xl"
3288
- }
3289
- )
3374
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
3375
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3376
+ import_antd.Input,
3377
+ {
3378
+ size: "large",
3379
+ status: duplicateErrors[f.id] ? "error" : void 0,
3380
+ value: String(editing[f.id] ?? ""),
3381
+ readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
3382
+ disabled: f.readOnly,
3383
+ onChange: (e) => {
3384
+ const val = e.target.value;
3385
+ setEditing({ ...editing, [f.id]: val });
3386
+ if (duplicateErrors[f.id]) {
3387
+ setDuplicateErrors((prev) => {
3388
+ const next = { ...prev };
3389
+ delete next[f.id];
3390
+ return next;
3391
+ });
3392
+ }
3393
+ },
3394
+ onBlur: (e) => {
3395
+ const isUniqueField = f.unique || (collection.id === "clients" || collection.id === "employees") && f.id === "id";
3396
+ if (isUniqueField) {
3397
+ const val = (e.target.value || "").trim().toLowerCase();
3398
+ if (val) {
3399
+ const dup = entries.find((entry) => {
3400
+ if (originalId && String(entry.id).trim().toLowerCase() === originalId.trim().toLowerCase()) {
3401
+ return false;
3402
+ }
3403
+ return String(entry[f.id] || "").trim().toLowerCase() === val;
3404
+ });
3405
+ if (dup) {
3406
+ const dupName = dup.nombre ? ` (\xAB${dup.nombre} ${dup.apellido || ""}\xBB)` : "";
3407
+ const errMsg = `Esta identificaci\xF3n ya est\xE1 registrada${dupName}. No puedes usar una c\xE9dula o NIT repetido.`;
3408
+ setDuplicateErrors((prev) => ({ ...prev, [f.id]: errMsg }));
3409
+ message.warning(`\u26A0\uFE0F Ya existe un registro con esta identificaci\xF3n: ${e.target.value.trim()}.`);
3410
+ } else {
3411
+ setDuplicateErrors((prev) => {
3412
+ const next = { ...prev };
3413
+ delete next[f.id];
3414
+ return next;
3415
+ });
3416
+ }
3417
+ }
3418
+ }
3419
+ },
3420
+ placeholder: f.label,
3421
+ className: "w-full rounded-xl"
3422
+ }
3423
+ ),
3424
+ 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: [
3425
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.AlertTriangle, { className: "w-3.5 h-3.5 shrink-0 text-rose-500" }),
3426
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: duplicateErrors[f.id] })
3427
+ ] })
3428
+ ] })
3290
3429
  ] }, f.id);
3291
3430
  }) }) }),
3292
- /* @__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: [
3293
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3294
- import_antd.Button,
3295
- {
3296
- size: "large",
3297
- onClick: () => {
3298
- setEditing(null);
3299
- setIsCreatingManual(false);
3300
- },
3301
- disabled: saving,
3302
- className: "rounded-xl font-medium",
3303
- children: t.cancel
3304
- }
3305
- ),
3306
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3431
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex shrink-0 justify-between items-center border-t border-slate-200 bg-white px-6 py-4", children: [
3432
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: isViewingDetail && collection.onDownloadPdf && (!collection.canDownloadPdf || collection.canDownloadPdf(editing)) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3307
3433
  import_antd.Button,
3308
3434
  {
3309
3435
  size: "large",
3310
3436
  type: "primary",
3311
- onClick: save,
3312
- loading: saving,
3313
- className: "min-w-[140px] rounded-xl font-bold shadow-sm bg-blue-600 hover:bg-blue-700",
3314
- children: isCreatingEntry ? collection.submitLabel || (t.create ? t.create.toUpperCase() : "CREAR") : collection.saveLabel || (t.save ? t.save.toUpperCase() : "GUARDAR")
3437
+ icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileDown, { className: "w-4 h-4" }),
3438
+ onClick: () => collection.onDownloadPdf?.(editing),
3439
+ className: "rounded-xl font-semibold bg-emerald-600 hover:bg-emerald-500 border-emerald-600 shadow-sm",
3440
+ children: "Descargar PDF"
3315
3441
  }
3316
- )
3442
+ ) }),
3443
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-3", children: [
3444
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3445
+ import_antd.Button,
3446
+ {
3447
+ size: "large",
3448
+ onClick: () => {
3449
+ setEditing(null);
3450
+ setOriginalId(null);
3451
+ setDuplicateErrors({});
3452
+ setIsCreatingManual(false);
3453
+ setIsViewingDetail(false);
3454
+ },
3455
+ disabled: saving,
3456
+ className: "rounded-xl font-medium",
3457
+ children: isViewingDetail ? "Cerrar" : t.cancel
3458
+ }
3459
+ ),
3460
+ !isViewingDetail && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3461
+ import_antd.Button,
3462
+ {
3463
+ size: "large",
3464
+ type: "primary",
3465
+ onClick: save,
3466
+ loading: saving,
3467
+ disabled: saving || Object.keys(duplicateErrors).length > 0,
3468
+ className: "min-w-[140px] rounded-xl font-bold shadow-sm bg-blue-600 hover:bg-blue-700 disabled:opacity-50",
3469
+ children: isCreatingEntry ? collection.submitLabel || (t.create ? t.create.toUpperCase() : "CREAR") : collection.saveLabel || (t.save ? t.save.toUpperCase() : "GUARDAR")
3470
+ }
3471
+ )
3472
+ ] })
3317
3473
  ] })
3318
3474
  ] }) })
3319
3475
  }
@@ -3386,22 +3542,48 @@ function CollectionEditor({ collection }) {
3386
3542
  String(e[f.id]).includes("maps") ? "Ver mapa" : "Abrir"
3387
3543
  ]
3388
3544
  }
3389
- ) : String(e[f.id] ?? "") }, f.id)),
3390
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { className: "px-6 py-4 text-right sticky right-0 bg-white border-l border-slate-100 group-hover:bg-slate-50/50 transition-colors", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-end gap-2", children: [
3391
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "p-2 text-slate-300 cursor-grab active:cursor-grabbing", title: "Drag to reorder", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { width: "15", height: "15", viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "w-4 h-4", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M5.5 3C6.32843 3 7 3.67157 7 4.5C7 5.32843 6.32843 6 5.5 6C4.67157 6 4 5.32843 4 4.5C4 3.67157 4.67157 3 5.5 3ZM9.5 3C10.3284 3 11 3.67157 11 4.5C11 5.32843 10.3284 6 9.5 6C8.67157 6 8 5.32843 8 4.5C8 3.67157 8.67157 3 9.5 3ZM5.5 7.5C6.32843 7.5 7 8.17157 7 9C7 9.82843 6.32843 10.5 5.5 10.5C4.67157 10.5 4 9.82843 4 9C4 8.17157 4.67157 7.5 5.5 7.5ZM9.5 7.5C10.3284 7.5 11 8.17157 11 9C11 9.82843 10.3284 10.5 9.5 10.5C8.67157 10.5 8 9.82843 8 9C8 8.17157 8.67157 7.5 9.5 7.5ZM5.5 12C6.32843 12 7 12.6716 7 13.5C7 14.3284 6.32843 15 5.5 15C4.67157 15 4 14.3284 4 13.5C4 12.6716 4.67157 12 5.5 12ZM9.5 12C10.3284 12 11 12.6716 11 13.5C11 14.3284 10.3284 15 9.5 15C8.67157 15 8 14.3284 8 13.5C8 12.6716 8.67157 12 9.5 12Z", fill: "currentColor", fillRule: "evenodd", clipRule: "evenodd" }) }) }),
3392
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3545
+ ) : f.type === "time" || f.id.toLowerCase().includes("hora") || f.id === "inicioServicio" || f.id === "finServicio" ? formatTo12Hour(e[f.id]) || String(e[f.id] ?? "") : String(e[f.id] ?? "") }, f.id)),
3546
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { className: "px-6 py-4 text-right sticky right-0 bg-white border-l border-slate-100 group-hover:bg-slate-50/50 transition-colors", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-end gap-1.5", children: [
3547
+ collection.enableDetailView && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3548
+ "button",
3549
+ {
3550
+ onClick: () => {
3551
+ setIsCreatingManual(false);
3552
+ setIsViewingDetail(true);
3553
+ setOriginalId(String(e.id || ""));
3554
+ setDuplicateErrors({});
3555
+ setEditing({ ...e });
3556
+ },
3557
+ className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
3558
+ title: "Ver detalle",
3559
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Eye, { className: "h-4 w-4" })
3560
+ }
3561
+ ),
3562
+ collection.onDownloadPdf && (!collection.canDownloadPdf || collection.canDownloadPdf(e)) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3563
+ "button",
3564
+ {
3565
+ onClick: () => collection.onDownloadPdf?.(e),
3566
+ className: "p-2 rounded-lg text-slate-400 hover:text-emerald-600 hover:bg-emerald-50 transition-colors",
3567
+ title: "Descargar PDF",
3568
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileDown, { className: "h-4 w-4" })
3569
+ }
3570
+ ),
3571
+ !collection.disableEdit && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3393
3572
  "button",
3394
3573
  {
3395
3574
  onClick: () => {
3396
3575
  setIsCreatingManual(false);
3397
- setEditing(e);
3576
+ setIsViewingDetail(false);
3577
+ setOriginalId(String(e.id || ""));
3578
+ setDuplicateErrors({});
3579
+ setEditing({ ...e });
3398
3580
  },
3399
3581
  className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
3400
3582
  title: t.edit,
3401
3583
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "h-4 w-4" })
3402
3584
  }
3403
3585
  ),
3404
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3586
+ !collection.disableDelete && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3405
3587
  "button",
3406
3588
  {
3407
3589
  onClick: () => remove(e.id),
@@ -4069,9 +4251,9 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
4069
4251
  }
4070
4252
  function PasswordField({ value, onChange }) {
4071
4253
  const [show, setShow] = (0, import_react5.useState)(false);
4072
- const isHash = value.startsWith("$2a$") || value.startsWith("$2b$");
4073
- const [displayValue, setDisplayValue] = (0, import_react5.useState)(isHash ? "" : value);
4074
- const [pristine, setPristine] = (0, import_react5.useState)(isHash);
4254
+ const hasExisting = Boolean(value && String(value).trim().length > 0);
4255
+ const [displayValue, setDisplayValue] = (0, import_react5.useState)("");
4256
+ const [pristine, setPristine] = (0, import_react5.useState)(hasExisting);
4075
4257
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
4076
4258
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4077
4259
  "input",
@@ -4083,7 +4265,7 @@ function PasswordField({ value, onChange }) {
4083
4265
  setDisplayValue(e.target.value);
4084
4266
  onChange(e.target.value);
4085
4267
  },
4086
- placeholder: pristine ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 (unchanged)" : "Enter new password",
4268
+ 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
4269
  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
4270
  }
4089
4271
  ),
@@ -4976,6 +5158,7 @@ function ReferenceSelect({
4976
5158
  }) {
4977
5159
  const ctx = useCmsContext();
4978
5160
  const t = useAdminI18n();
5161
+ const { message } = import_antd.App.useApp();
4979
5162
  const [options, setOptions] = (0, import_react5.useState)([]);
4980
5163
  const [loading, setLoading] = (0, import_react5.useState)(true);
4981
5164
  const [clientModalOpen, setClientModalOpen] = (0, import_react5.useState)(false);
@@ -5002,6 +5185,12 @@ function ReferenceSelect({
5002
5185
  setClientError(t.nameRequired);
5003
5186
  return;
5004
5187
  }
5188
+ const cleanId = newClient.id.trim().toLowerCase();
5189
+ const isDuplicate = options.some((opt) => String(opt.value || "").trim().toLowerCase() === cleanId);
5190
+ if (isDuplicate) {
5191
+ setClientError("Ya existe un cliente con este NIT o C\xE9dula. No se pueden repetir.");
5192
+ return;
5193
+ }
5005
5194
  setCreatingClient(true);
5006
5195
  try {
5007
5196
  const entry = {
@@ -5038,7 +5227,7 @@ function ReferenceSelect({
5038
5227
  ciudad: "",
5039
5228
  direccion: ""
5040
5229
  });
5041
- import_antd.message.success(t.clientCreatedSuccess);
5230
+ message.success(t.clientCreatedSuccess);
5042
5231
  } catch (err) {
5043
5232
  setClientError(err?.message || "Error al crear cliente.");
5044
5233
  } finally {
@@ -5227,9 +5416,23 @@ function ReferenceSelect({
5227
5416
  import_antd.Input,
5228
5417
  {
5229
5418
  size: "large",
5419
+ status: clientError && clientError.includes("identificaci\xF3n") ? "error" : void 0,
5230
5420
  placeholder: t.clientIdentification,
5231
5421
  value: newClient.id,
5232
- onChange: (e) => setNewClient((prev) => ({ ...prev, id: e.target.value }))
5422
+ onChange: (e) => {
5423
+ setNewClient((prev) => ({ ...prev, id: e.target.value }));
5424
+ if (clientError) setClientError("");
5425
+ },
5426
+ onBlur: (e) => {
5427
+ const clean = (e.target.value || "").trim().toLowerCase();
5428
+ if (clean) {
5429
+ const dup = options.find((opt) => String(opt.value || "").trim().toLowerCase() === clean);
5430
+ if (dup) {
5431
+ setClientError(`Ya existe un cliente con esta identificaci\xF3n (\xAB${dup.label || clean}\xBB).`);
5432
+ message.warning(`\u26A0\uFE0F Ya existe un cliente con esta identificaci\xF3n: ${clean}.`);
5433
+ }
5434
+ }
5435
+ }
5233
5436
  }
5234
5437
  )
5235
5438
  ] }),
package/dist/index.mjs CHANGED
@@ -35,7 +35,7 @@ import {
35
35
  Switch,
36
36
  Button,
37
37
  Image,
38
- message
38
+ App
39
39
  } from "antd";
40
40
  import dayjs from "dayjs";
41
41
  import {
@@ -66,7 +66,9 @@ import {
66
66
  LogOut,
67
67
  ExternalLink,
68
68
  Check,
69
- GripVertical
69
+ GripVertical,
70
+ AlertTriangle,
71
+ FileDown
70
72
  } from "lucide-react";
71
73
 
72
74
  // src/admin/i18n.ts
@@ -253,8 +255,8 @@ var AdminI18nContext = React.createContext(getAdminTranslations("en"));
253
255
  function useAdminI18n() {
254
256
  return React.useContext(AdminI18nContext);
255
257
  }
256
- var TIME_STORAGE_FORMAT = "HH:mm";
257
- var TIME_DISPLAY_FORMAT = "h:mm A";
258
+ var TIME_STORAGE_FORMAT = "h:mm a";
259
+ var TIME_DISPLAY_FORMAT = "h:mm a";
258
260
  var TIME_PICKER_THEME = {
259
261
  token: {
260
262
  borderRadius: 12,
@@ -315,6 +317,16 @@ function toDayjsTime(value) {
315
317
  function toStoredTime(value) {
316
318
  return value?.format(TIME_STORAGE_FORMAT) ?? "";
317
319
  }
320
+ function formatTo12Hour(value) {
321
+ const str = String(value ?? "").trim();
322
+ if (!str || str === "\u2014" || str === "undefined") return "";
323
+ if (/\b(am|pm)\b/i.test(str)) return str.toLowerCase();
324
+ const d = toDayjsTime(str);
325
+ if (d && d.isValid()) {
326
+ return d.format("h:mm a");
327
+ }
328
+ return str;
329
+ }
318
330
  async function handleImageFile(file, onUrl, uploadImage) {
319
331
  if (uploadImage) {
320
332
  try {
@@ -364,10 +376,11 @@ function FilePickerButton({
364
376
  ] });
365
377
  }
366
378
  function AdminApp(props) {
379
+ const content = /* @__PURE__ */ jsx(App, { className: "min-h-screen", children: /* @__PURE__ */ jsx(AdminAppContent, { ...props }) });
367
380
  if (props.projectId) {
368
- return /* @__PURE__ */ jsx(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: /* @__PURE__ */ jsx(AdminAppContent, { ...props }) });
381
+ return /* @__PURE__ */ jsx(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: content });
369
382
  }
370
- return /* @__PURE__ */ jsx(AdminAppContent, { ...props });
383
+ return content;
371
384
  }
372
385
  function AdminAppContent(props) {
373
386
  const ctx = useCmsContext();
@@ -1731,9 +1744,13 @@ function CollectionsSection() {
1731
1744
  function CollectionEditor({ collection }) {
1732
1745
  const ctx = useCmsContext();
1733
1746
  const t = useAdminI18n();
1747
+ const { message } = App.useApp();
1734
1748
  const [entries, setEntries] = useState([]);
1735
1749
  const [editing, setEditing] = useState(null);
1750
+ const [originalId, setOriginalId] = useState(null);
1751
+ const [duplicateErrors, setDuplicateErrors] = useState({});
1736
1752
  const [isCreatingManual, setIsCreatingManual] = useState(false);
1753
+ const [isViewingDetail, setIsViewingDetail] = useState(false);
1737
1754
  const [saving, setSaving] = useState(false);
1738
1755
  const [deletingId, setDeletingId] = useState(null);
1739
1756
  const [loadingEntries, setLoadingEntries] = useState(true);
@@ -1760,6 +1777,8 @@ function CollectionEditor({ collection }) {
1760
1777
  }, [load]);
1761
1778
  const startNew = () => {
1762
1779
  setIsCreatingManual(true);
1780
+ setOriginalId(null);
1781
+ setDuplicateErrors({});
1763
1782
  const base = { id: crypto.randomUUID() };
1764
1783
  collection.fields.forEach((f) => {
1765
1784
  if (f.id === "order") {
@@ -1813,9 +1832,42 @@ function CollectionEditor({ collection }) {
1813
1832
  finalEditing[f.id] = val;
1814
1833
  }
1815
1834
  });
1835
+ const isClientOrEmployee = collection.id === "clients" || collection.id === "employees";
1836
+ const uniqueFields = collection.fields.filter((f) => f.unique || isClientOrEmployee && f.id === "id");
1837
+ for (const f of uniqueFields) {
1838
+ const val = String(finalEditing[f.id] || "").trim().toLowerCase();
1839
+ if (!val) {
1840
+ message.error(`El campo "${f.label || f.id}" es obligatorio.`);
1841
+ setSaving(false);
1842
+ return;
1843
+ }
1844
+ const isDuplicate = entries.some((e) => {
1845
+ if (originalId && String(e.id).trim().toLowerCase() === originalId.trim().toLowerCase()) {
1846
+ return false;
1847
+ }
1848
+ const existingVal = String(e[f.id] || "").trim().toLowerCase();
1849
+ return existingVal === val;
1850
+ });
1851
+ if (isDuplicate) {
1852
+ message.error(
1853
+ `Ya existe un registro en ${collection.name} con ${f.label || f.id}: "${finalEditing[f.id]}". No se pueden repetir c\xE9dulas ni NIT.`
1854
+ );
1855
+ setSaving(false);
1856
+ return;
1857
+ }
1858
+ }
1859
+ if (originalId && String(finalEditing.id).trim().toLowerCase() !== originalId.trim().toLowerCase()) {
1860
+ try {
1861
+ await ctx.adapter.deleteEntry(collection.id, originalId);
1862
+ } catch (cleanupErr) {
1863
+ console.warn("No se pudo limpiar el registro anterior:", cleanupErr);
1864
+ }
1865
+ }
1816
1866
  await ctx.adapter.putEntry(collection.id, finalEditing);
1867
+ message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
1817
1868
  ctx.notifyCollectionChanged();
1818
1869
  setEditing(null);
1870
+ setOriginalId(null);
1819
1871
  setIsCreatingManual(false);
1820
1872
  load();
1821
1873
  } finally {
@@ -1959,10 +2011,11 @@ function CollectionEditor({ collection }) {
1959
2011
  open: Boolean(editing),
1960
2012
  title: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between pr-8", children: [
1961
2013
  /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-slate-900 font-bold", children: [
1962
- isCreatingEntry ? /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4 text-indigo-600" }),
1963
- isCreatingEntry ? collection.createTitle || `Nueva ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}` : `Editar ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}`
2014
+ isViewingDetail ? /* @__PURE__ */ jsx(Eye, { className: "h-4 w-4 text-indigo-600" }) : isCreatingEntry ? /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4 text-indigo-600" }),
2015
+ isViewingDetail ? `Detalle de ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}${editing?.numero ? ` #${editing.numero}` : ""}` : isCreatingEntry ? collection.createTitle || `Nueva ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}` : `Editar ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}`
1964
2016
  ] }),
1965
- !isCreatingEntry && editing && editing.estado !== void 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
2017
+ isViewingDetail && editing && editing.estado !== void 0 && /* @__PURE__ */ jsx("span", { className: `px-2.5 py-1 text-xs font-semibold rounded-full ${String(editing.estado).toLowerCase().includes("terminad") ? "bg-emerald-50 text-emerald-700 border border-emerald-200" : String(editing.estado).toLowerCase().includes("proceso") ? "bg-sky-50 text-sky-700 border border-sky-200" : String(editing.estado).toLowerCase().includes("cancelad") ? "bg-rose-50 text-rose-700 border border-rose-200" : "bg-amber-50 text-amber-700 border border-amber-200"}`, children: String(editing.estado) }),
2018
+ !isViewingDetail && !isCreatingEntry && editing && editing.estado !== void 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1966
2019
  /* @__PURE__ */ jsx("span", { className: "text-xs text-slate-400 font-medium", children: "Estado:" }),
1967
2020
  /* @__PURE__ */ jsx(
1968
2021
  Select,
@@ -1984,7 +2037,9 @@ function CollectionEditor({ collection }) {
1984
2037
  onCancel: () => {
1985
2038
  if (!saving) {
1986
2039
  setEditing(null);
2040
+ setOriginalId(null);
1987
2041
  setIsCreatingManual(false);
2042
+ setIsViewingDetail(false);
1988
2043
  }
1989
2044
  },
1990
2045
  footer: null,
@@ -2022,12 +2077,55 @@ function CollectionEditor({ collection }) {
2022
2077
  }).map((f) => {
2023
2078
  const isFullWidth = f.colSpan === 2 || f.colSpan === 12 || f.type === "signature" || f.type === "date" || f.type === "datetime" || f.type === "richtext" || f.type === "textarea" || f.type === "list" || f.type === "branch-settings" || f.type === "time-range";
2024
2079
  const colSpanClass = isFullWidth ? "lg:col-span-2 col-span-1" : "col-span-1";
2080
+ if (isViewingDetail) {
2081
+ return /* @__PURE__ */ jsxs("div", { className: `block ${colSpanClass}`, children: [
2082
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: f.label }),
2083
+ f.customRender ? f.customRender({
2084
+ value: editing[f.id],
2085
+ record: editing,
2086
+ onChange: () => {
2087
+ },
2088
+ isCreatingEntry: false
2089
+ }) : f.type === "signature" ? editing[f.id] ? /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-slate-200 bg-white p-3 flex items-center justify-center shadow-sm", children: /* @__PURE__ */ jsx(
2090
+ "img",
2091
+ {
2092
+ src: String(editing[f.id]),
2093
+ alt: f.label,
2094
+ className: "h-28 w-auto max-w-full object-contain"
2095
+ }
2096
+ ) }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-slate-400 italic py-1", children: "Sin firma registrada" }) : f.type === "list" ? Array.isArray(editing[f.id]) && editing[f.id].length > 0 ? /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5 pt-0.5", children: editing[f.id].map((item, idx) => /* @__PURE__ */ jsx(
2097
+ "span",
2098
+ {
2099
+ className: "rounded-full bg-slate-100 text-slate-700 px-3 py-1 text-xs font-medium border border-slate-200",
2100
+ children: String(item)
2101
+ },
2102
+ idx
2103
+ )) }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-slate-400 italic py-1", children: "Ninguno" }) : f.type === "link" ? Boolean(editing[f.id]) ? /* @__PURE__ */ jsxs(
2104
+ "a",
2105
+ {
2106
+ href: String(editing[f.id]),
2107
+ target: "_blank",
2108
+ rel: "noopener noreferrer",
2109
+ className: "inline-flex items-center gap-1.5 text-xs text-blue-600 hover:text-blue-800 underline font-medium py-1",
2110
+ children: [
2111
+ /* @__PURE__ */ jsx(ExternalLink, { className: "w-3.5 h-3.5" }),
2112
+ String(editing[f.id]).includes("maps") ? "Ver en Google Maps" : String(editing[f.id])
2113
+ ]
2114
+ }
2115
+ ) : /* @__PURE__ */ jsx("span", { className: "text-xs text-slate-400 py-1 block", children: "\u2014" }) : f.type === "textarea" ? /* @__PURE__ */ jsx("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2.5 text-sm text-slate-800 whitespace-pre-line leading-relaxed", children: String(editing[f.id] || "\u2014") }) : f.type === "time" || f.id.toLowerCase().includes("hora") || f.id === "inicioServicio" || f.id === "finServicio" ? /* @__PURE__ */ jsx("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2 text-sm text-slate-800 font-medium", children: formatTo12Hour(editing[f.id]) || String(editing[f.id] ?? "\u2014") }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2 text-sm text-slate-800 font-medium", children: String(editing[f.id] ?? "\u2014") })
2116
+ ] }, f.id);
2117
+ }
2025
2118
  return /* @__PURE__ */ jsxs("div", { className: `block ${colSpanClass}`, children: [
2026
2119
  /* @__PURE__ */ jsxs("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
2027
2120
  f.label,
2028
2121
  /* @__PURE__ */ jsx("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
2029
2122
  ] }),
2030
- f.type === "branch-settings" ? /* @__PURE__ */ jsx(
2123
+ f.customRender ? f.customRender({
2124
+ value: editing[f.id],
2125
+ record: editing,
2126
+ onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2127
+ isCreatingEntry
2128
+ }) : f.type === "branch-settings" ? /* @__PURE__ */ jsx(
2031
2129
  BranchSettingsEditor,
2032
2130
  {
2033
2131
  collectionId: f.collection || "",
@@ -2512,45 +2610,105 @@ function CollectionEditor({ collection }) {
2512
2610
  ]
2513
2611
  }
2514
2612
  ) : null
2515
- ] }) : /* @__PURE__ */ jsx(
2516
- Input,
2517
- {
2518
- size: "large",
2519
- value: String(editing[f.id] ?? ""),
2520
- readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
2521
- disabled: f.readOnly,
2522
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2523
- placeholder: f.label,
2524
- className: "w-full rounded-xl"
2525
- }
2526
- )
2613
+ ] }) : /* @__PURE__ */ jsxs("div", { children: [
2614
+ /* @__PURE__ */ jsx(
2615
+ Input,
2616
+ {
2617
+ size: "large",
2618
+ status: duplicateErrors[f.id] ? "error" : void 0,
2619
+ value: String(editing[f.id] ?? ""),
2620
+ readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
2621
+ disabled: f.readOnly,
2622
+ onChange: (e) => {
2623
+ const val = e.target.value;
2624
+ setEditing({ ...editing, [f.id]: val });
2625
+ if (duplicateErrors[f.id]) {
2626
+ setDuplicateErrors((prev) => {
2627
+ const next = { ...prev };
2628
+ delete next[f.id];
2629
+ return next;
2630
+ });
2631
+ }
2632
+ },
2633
+ onBlur: (e) => {
2634
+ const isUniqueField = f.unique || (collection.id === "clients" || collection.id === "employees") && f.id === "id";
2635
+ if (isUniqueField) {
2636
+ const val = (e.target.value || "").trim().toLowerCase();
2637
+ if (val) {
2638
+ const dup = entries.find((entry) => {
2639
+ if (originalId && String(entry.id).trim().toLowerCase() === originalId.trim().toLowerCase()) {
2640
+ return false;
2641
+ }
2642
+ return String(entry[f.id] || "").trim().toLowerCase() === val;
2643
+ });
2644
+ if (dup) {
2645
+ const dupName = dup.nombre ? ` (\xAB${dup.nombre} ${dup.apellido || ""}\xBB)` : "";
2646
+ const errMsg = `Esta identificaci\xF3n ya est\xE1 registrada${dupName}. No puedes usar una c\xE9dula o NIT repetido.`;
2647
+ setDuplicateErrors((prev) => ({ ...prev, [f.id]: errMsg }));
2648
+ message.warning(`\u26A0\uFE0F Ya existe un registro con esta identificaci\xF3n: ${e.target.value.trim()}.`);
2649
+ } else {
2650
+ setDuplicateErrors((prev) => {
2651
+ const next = { ...prev };
2652
+ delete next[f.id];
2653
+ return next;
2654
+ });
2655
+ }
2656
+ }
2657
+ }
2658
+ },
2659
+ placeholder: f.label,
2660
+ className: "w-full rounded-xl"
2661
+ }
2662
+ ),
2663
+ 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: [
2664
+ /* @__PURE__ */ jsx(AlertTriangle, { className: "w-3.5 h-3.5 shrink-0 text-rose-500" }),
2665
+ /* @__PURE__ */ jsx("span", { children: duplicateErrors[f.id] })
2666
+ ] })
2667
+ ] })
2527
2668
  ] }, f.id);
2528
2669
  }) }) }),
2529
- /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 justify-end gap-3 border-t border-slate-200 bg-white px-6 py-4", children: [
2530
- /* @__PURE__ */ jsx(
2531
- Button,
2532
- {
2533
- size: "large",
2534
- onClick: () => {
2535
- setEditing(null);
2536
- setIsCreatingManual(false);
2537
- },
2538
- disabled: saving,
2539
- className: "rounded-xl font-medium",
2540
- children: t.cancel
2541
- }
2542
- ),
2543
- /* @__PURE__ */ jsx(
2670
+ /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 justify-between items-center border-t border-slate-200 bg-white px-6 py-4", children: [
2671
+ /* @__PURE__ */ jsx("div", { children: isViewingDetail && collection.onDownloadPdf && (!collection.canDownloadPdf || collection.canDownloadPdf(editing)) && /* @__PURE__ */ jsx(
2544
2672
  Button,
2545
2673
  {
2546
2674
  size: "large",
2547
2675
  type: "primary",
2548
- onClick: save,
2549
- loading: saving,
2550
- className: "min-w-[140px] rounded-xl font-bold shadow-sm bg-blue-600 hover:bg-blue-700",
2551
- children: isCreatingEntry ? collection.submitLabel || (t.create ? t.create.toUpperCase() : "CREAR") : collection.saveLabel || (t.save ? t.save.toUpperCase() : "GUARDAR")
2676
+ icon: /* @__PURE__ */ jsx(FileDown, { className: "w-4 h-4" }),
2677
+ onClick: () => collection.onDownloadPdf?.(editing),
2678
+ className: "rounded-xl font-semibold bg-emerald-600 hover:bg-emerald-500 border-emerald-600 shadow-sm",
2679
+ children: "Descargar PDF"
2552
2680
  }
2553
- )
2681
+ ) }),
2682
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
2683
+ /* @__PURE__ */ jsx(
2684
+ Button,
2685
+ {
2686
+ size: "large",
2687
+ onClick: () => {
2688
+ setEditing(null);
2689
+ setOriginalId(null);
2690
+ setDuplicateErrors({});
2691
+ setIsCreatingManual(false);
2692
+ setIsViewingDetail(false);
2693
+ },
2694
+ disabled: saving,
2695
+ className: "rounded-xl font-medium",
2696
+ children: isViewingDetail ? "Cerrar" : t.cancel
2697
+ }
2698
+ ),
2699
+ !isViewingDetail && /* @__PURE__ */ jsx(
2700
+ Button,
2701
+ {
2702
+ size: "large",
2703
+ type: "primary",
2704
+ onClick: save,
2705
+ loading: saving,
2706
+ disabled: saving || Object.keys(duplicateErrors).length > 0,
2707
+ className: "min-w-[140px] rounded-xl font-bold shadow-sm bg-blue-600 hover:bg-blue-700 disabled:opacity-50",
2708
+ children: isCreatingEntry ? collection.submitLabel || (t.create ? t.create.toUpperCase() : "CREAR") : collection.saveLabel || (t.save ? t.save.toUpperCase() : "GUARDAR")
2709
+ }
2710
+ )
2711
+ ] })
2554
2712
  ] })
2555
2713
  ] }) })
2556
2714
  }
@@ -2623,22 +2781,48 @@ function CollectionEditor({ collection }) {
2623
2781
  String(e[f.id]).includes("maps") ? "Ver mapa" : "Abrir"
2624
2782
  ]
2625
2783
  }
2626
- ) : String(e[f.id] ?? "") }, f.id)),
2627
- /* @__PURE__ */ jsx("td", { className: "px-6 py-4 text-right sticky right-0 bg-white border-l border-slate-100 group-hover:bg-slate-50/50 transition-colors", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-2", children: [
2628
- /* @__PURE__ */ jsx("div", { className: "p-2 text-slate-300 cursor-grab active:cursor-grabbing", title: "Drag to reorder", children: /* @__PURE__ */ jsx("svg", { width: "15", height: "15", viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "w-4 h-4", children: /* @__PURE__ */ jsx("path", { d: "M5.5 3C6.32843 3 7 3.67157 7 4.5C7 5.32843 6.32843 6 5.5 6C4.67157 6 4 5.32843 4 4.5C4 3.67157 4.67157 3 5.5 3ZM9.5 3C10.3284 3 11 3.67157 11 4.5C11 5.32843 10.3284 6 9.5 6C8.67157 6 8 5.32843 8 4.5C8 3.67157 8.67157 3 9.5 3ZM5.5 7.5C6.32843 7.5 7 8.17157 7 9C7 9.82843 6.32843 10.5 5.5 10.5C4.67157 10.5 4 9.82843 4 9C4 8.17157 4.67157 7.5 5.5 7.5ZM9.5 7.5C10.3284 7.5 11 8.17157 11 9C11 9.82843 10.3284 10.5 9.5 10.5C8.67157 10.5 8 9.82843 8 9C8 8.17157 8.67157 7.5 9.5 7.5ZM5.5 12C6.32843 12 7 12.6716 7 13.5C7 14.3284 6.32843 15 5.5 15C4.67157 15 4 14.3284 4 13.5C4 12.6716 4.67157 12 5.5 12ZM9.5 12C10.3284 12 11 12.6716 11 13.5C11 14.3284 10.3284 15 9.5 15C8.67157 15 8 14.3284 8 13.5C8 12.6716 8.67157 12 9.5 12Z", fill: "currentColor", fillRule: "evenodd", clipRule: "evenodd" }) }) }),
2629
- /* @__PURE__ */ jsx(
2784
+ ) : f.type === "time" || f.id.toLowerCase().includes("hora") || f.id === "inicioServicio" || f.id === "finServicio" ? formatTo12Hour(e[f.id]) || String(e[f.id] ?? "") : String(e[f.id] ?? "") }, f.id)),
2785
+ /* @__PURE__ */ jsx("td", { className: "px-6 py-4 text-right sticky right-0 bg-white border-l border-slate-100 group-hover:bg-slate-50/50 transition-colors", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-1.5", children: [
2786
+ collection.enableDetailView && /* @__PURE__ */ jsx(
2787
+ "button",
2788
+ {
2789
+ onClick: () => {
2790
+ setIsCreatingManual(false);
2791
+ setIsViewingDetail(true);
2792
+ setOriginalId(String(e.id || ""));
2793
+ setDuplicateErrors({});
2794
+ setEditing({ ...e });
2795
+ },
2796
+ className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
2797
+ title: "Ver detalle",
2798
+ children: /* @__PURE__ */ jsx(Eye, { className: "h-4 w-4" })
2799
+ }
2800
+ ),
2801
+ collection.onDownloadPdf && (!collection.canDownloadPdf || collection.canDownloadPdf(e)) && /* @__PURE__ */ jsx(
2802
+ "button",
2803
+ {
2804
+ onClick: () => collection.onDownloadPdf?.(e),
2805
+ className: "p-2 rounded-lg text-slate-400 hover:text-emerald-600 hover:bg-emerald-50 transition-colors",
2806
+ title: "Descargar PDF",
2807
+ children: /* @__PURE__ */ jsx(FileDown, { className: "h-4 w-4" })
2808
+ }
2809
+ ),
2810
+ !collection.disableEdit && /* @__PURE__ */ jsx(
2630
2811
  "button",
2631
2812
  {
2632
2813
  onClick: () => {
2633
2814
  setIsCreatingManual(false);
2634
- setEditing(e);
2815
+ setIsViewingDetail(false);
2816
+ setOriginalId(String(e.id || ""));
2817
+ setDuplicateErrors({});
2818
+ setEditing({ ...e });
2635
2819
  },
2636
2820
  className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
2637
2821
  title: t.edit,
2638
2822
  children: /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4" })
2639
2823
  }
2640
2824
  ),
2641
- /* @__PURE__ */ jsx(
2825
+ !collection.disableDelete && /* @__PURE__ */ jsx(
2642
2826
  "button",
2643
2827
  {
2644
2828
  onClick: () => remove(e.id),
@@ -3306,9 +3490,9 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
3306
3490
  }
3307
3491
  function PasswordField({ value, onChange }) {
3308
3492
  const [show, setShow] = useState(false);
3309
- const isHash = value.startsWith("$2a$") || value.startsWith("$2b$");
3310
- const [displayValue, setDisplayValue] = useState(isHash ? "" : value);
3311
- const [pristine, setPristine] = useState(isHash);
3493
+ const hasExisting = Boolean(value && String(value).trim().length > 0);
3494
+ const [displayValue, setDisplayValue] = useState("");
3495
+ const [pristine, setPristine] = useState(hasExisting);
3312
3496
  return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
3313
3497
  /* @__PURE__ */ jsx(
3314
3498
  "input",
@@ -3320,7 +3504,7 @@ function PasswordField({ value, onChange }) {
3320
3504
  setDisplayValue(e.target.value);
3321
3505
  onChange(e.target.value);
3322
3506
  },
3323
- placeholder: pristine ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 (unchanged)" : "Enter new password",
3507
+ 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
3508
  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
3509
  }
3326
3510
  ),
@@ -4213,6 +4397,7 @@ function ReferenceSelect({
4213
4397
  }) {
4214
4398
  const ctx = useCmsContext();
4215
4399
  const t = useAdminI18n();
4400
+ const { message } = App.useApp();
4216
4401
  const [options, setOptions] = useState([]);
4217
4402
  const [loading, setLoading] = useState(true);
4218
4403
  const [clientModalOpen, setClientModalOpen] = useState(false);
@@ -4239,6 +4424,12 @@ function ReferenceSelect({
4239
4424
  setClientError(t.nameRequired);
4240
4425
  return;
4241
4426
  }
4427
+ const cleanId = newClient.id.trim().toLowerCase();
4428
+ const isDuplicate = options.some((opt) => String(opt.value || "").trim().toLowerCase() === cleanId);
4429
+ if (isDuplicate) {
4430
+ setClientError("Ya existe un cliente con este NIT o C\xE9dula. No se pueden repetir.");
4431
+ return;
4432
+ }
4242
4433
  setCreatingClient(true);
4243
4434
  try {
4244
4435
  const entry = {
@@ -4464,9 +4655,23 @@ function ReferenceSelect({
4464
4655
  Input,
4465
4656
  {
4466
4657
  size: "large",
4658
+ status: clientError && clientError.includes("identificaci\xF3n") ? "error" : void 0,
4467
4659
  placeholder: t.clientIdentification,
4468
4660
  value: newClient.id,
4469
- onChange: (e) => setNewClient((prev) => ({ ...prev, id: e.target.value }))
4661
+ onChange: (e) => {
4662
+ setNewClient((prev) => ({ ...prev, id: e.target.value }));
4663
+ if (clientError) setClientError("");
4664
+ },
4665
+ onBlur: (e) => {
4666
+ const clean = (e.target.value || "").trim().toLowerCase();
4667
+ if (clean) {
4668
+ const dup = options.find((opt) => String(opt.value || "").trim().toLowerCase() === clean);
4669
+ if (dup) {
4670
+ setClientError(`Ya existe un cliente con esta identificaci\xF3n (\xAB${dup.label || clean}\xBB).`);
4671
+ message.warning(`\u26A0\uFE0F Ya existe un cliente con esta identificaci\xF3n: ${clean}.`);
4672
+ }
4673
+ }
4674
+ }
4470
4675
  }
4471
4676
  )
4472
4677
  ] }),
package/dist/types.d.mts CHANGED
@@ -61,12 +61,20 @@ interface CollectionField {
61
61
  })[]>;
62
62
  colSpan?: 1 | 2 | 6 | 12;
63
63
  readOnly?: boolean;
64
+ unique?: boolean;
65
+ customRender?: (props: {
66
+ value: any;
67
+ record: any;
68
+ onChange?: (val: any) => void;
69
+ isCreatingEntry?: boolean;
70
+ }) => React.ReactNode;
64
71
  }
65
72
  interface CollectionDef {
66
73
  id: string;
67
74
  name: string;
68
75
  description?: string;
69
76
  fields: CollectionField[];
77
+ uniqueFields?: string[];
70
78
  searchBy?: string[];
71
79
  filterBy?: string[];
72
80
  tableFields?: string[];
@@ -74,6 +82,16 @@ interface CollectionDef {
74
82
  submitLabel?: string;
75
83
  saveLabel?: string;
76
84
  isSeparator?: boolean;
85
+ enableDetailView?: boolean;
86
+ disableEdit?: boolean;
87
+ disableDelete?: boolean;
88
+ onDownloadPdf?: (record: any) => void;
89
+ canDownloadPdf?: (record: any) => boolean;
90
+ customRowActions?: (props: {
91
+ record: any;
92
+ openDetail: () => void;
93
+ openEdit: () => void;
94
+ }) => React.ReactNode;
77
95
  }
78
96
  interface GlobalGroup {
79
97
  id: string;
package/dist/types.d.ts CHANGED
@@ -61,12 +61,20 @@ interface CollectionField {
61
61
  })[]>;
62
62
  colSpan?: 1 | 2 | 6 | 12;
63
63
  readOnly?: boolean;
64
+ unique?: boolean;
65
+ customRender?: (props: {
66
+ value: any;
67
+ record: any;
68
+ onChange?: (val: any) => void;
69
+ isCreatingEntry?: boolean;
70
+ }) => React.ReactNode;
64
71
  }
65
72
  interface CollectionDef {
66
73
  id: string;
67
74
  name: string;
68
75
  description?: string;
69
76
  fields: CollectionField[];
77
+ uniqueFields?: string[];
70
78
  searchBy?: string[];
71
79
  filterBy?: string[];
72
80
  tableFields?: string[];
@@ -74,6 +82,16 @@ interface CollectionDef {
74
82
  submitLabel?: string;
75
83
  saveLabel?: string;
76
84
  isSeparator?: boolean;
85
+ enableDetailView?: boolean;
86
+ disableEdit?: boolean;
87
+ disableDelete?: boolean;
88
+ onDownloadPdf?: (record: any) => void;
89
+ canDownloadPdf?: (record: any) => boolean;
90
+ customRowActions?: (props: {
91
+ record: any;
92
+ openDetail: () => void;
93
+ openEdit: () => void;
94
+ }) => React.ReactNode;
77
95
  }
78
96
  interface GlobalGroup {
79
97
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin-lib-cms",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
4
4
  "description": "Agnostic Admin CMS Library",
5
5
  "keywords": [
6
6
  "cms",