admin-lib-cms 1.2.15 → 1.2.17
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 +383 -314
- package/dist/index.mjs +383 -314
- package/dist/storage.js +10 -2
- package/dist/storage.mjs +10 -2
- package/dist/types.d.mts +13 -0
- package/dist/types.d.ts +13 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -126,8 +126,11 @@ var translations = {
|
|
|
126
126
|
saveSignature: "Guardar Firma",
|
|
127
127
|
selectOption: "-- Selecciona una opci\xF3n --",
|
|
128
128
|
loadingOptions: "Cargando opciones...",
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
cantFindOption: "\xBFNo encuentras la opci\xF3n?",
|
|
130
|
+
createNewOption: "Crear nuevo",
|
|
131
|
+
recordCreatedSuccess: "Registro creado y seleccionado exitosamente.",
|
|
132
|
+
cantFindClient: "\xBFNo encuentras la opci\xF3n?",
|
|
133
|
+
createClient: "Crear nuevo",
|
|
131
134
|
newBtn: "Nuevo",
|
|
132
135
|
basicDetails: "Datos b\xE1sicos",
|
|
133
136
|
clientType: "Tipo",
|
|
@@ -209,8 +212,11 @@ var translations = {
|
|
|
209
212
|
saveSignature: "Save Signature",
|
|
210
213
|
selectOption: "-- Select an option --",
|
|
211
214
|
loadingOptions: "Loading options...",
|
|
212
|
-
|
|
213
|
-
|
|
215
|
+
cantFindOption: "Can't find the option?",
|
|
216
|
+
createNewOption: "Create new",
|
|
217
|
+
recordCreatedSuccess: "Record created and selected successfully.",
|
|
218
|
+
cantFindClient: "Can't find the option?",
|
|
219
|
+
createClient: "Create new",
|
|
214
220
|
newBtn: "New",
|
|
215
221
|
basicDetails: "Basic details",
|
|
216
222
|
clientType: "Type",
|
|
@@ -1764,9 +1770,29 @@ function CollectionEditor({ collection }) {
|
|
|
1764
1770
|
setLoadingEntries(true);
|
|
1765
1771
|
ctx.adapter.listEntries(collection.id).then((res) => {
|
|
1766
1772
|
const sorted = [...res].sort((a, b) => {
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1773
|
+
if (collection.defaultSort) {
|
|
1774
|
+
if (typeof collection.defaultSort === "function") {
|
|
1775
|
+
return collection.defaultSort(a, b);
|
|
1776
|
+
}
|
|
1777
|
+
const field = collection.defaultSort.field;
|
|
1778
|
+
const valA = a[field];
|
|
1779
|
+
const valB = b[field];
|
|
1780
|
+
const dir = collection.defaultSort.direction === "desc" ? -1 : 1;
|
|
1781
|
+
if (valA === valB) return 0;
|
|
1782
|
+
if (valA === void 0 || valA === null) return 1;
|
|
1783
|
+
if (valB === void 0 || valB === null) return -1;
|
|
1784
|
+
if (typeof valA === "number" && typeof valB === "number") {
|
|
1785
|
+
return (valA - valB) * dir;
|
|
1786
|
+
}
|
|
1787
|
+
return String(valA).localeCompare(String(valB)) * dir;
|
|
1788
|
+
}
|
|
1789
|
+
const hasOrderField = collection.fields.some((f) => f.id === "order");
|
|
1790
|
+
if (hasOrderField) {
|
|
1791
|
+
const orderA = Number(a.order) || 0;
|
|
1792
|
+
const orderB = Number(b.order) || 0;
|
|
1793
|
+
if (orderA !== orderB) return orderA - orderB;
|
|
1794
|
+
}
|
|
1795
|
+
return 0;
|
|
1770
1796
|
});
|
|
1771
1797
|
setEntries(sorted);
|
|
1772
1798
|
setLoadingEntries(false);
|
|
@@ -1830,10 +1856,35 @@ function CollectionEditor({ collection }) {
|
|
|
1830
1856
|
let val = String(finalEditing[sourceField] || finalEditing.id || "");
|
|
1831
1857
|
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
1832
1858
|
finalEditing[f.id] = val;
|
|
1859
|
+
} else if (f.type === "list" || f.multiple) {
|
|
1860
|
+
if (Array.isArray(finalEditing[f.id])) {
|
|
1861
|
+
finalEditing[f.id] = finalEditing[f.id].filter(
|
|
1862
|
+
(item) => item !== void 0 && item !== null && String(item).trim() !== ""
|
|
1863
|
+
);
|
|
1864
|
+
} else if (typeof finalEditing[f.id] === "string" && finalEditing[f.id]) {
|
|
1865
|
+
finalEditing[f.id] = [String(finalEditing[f.id]).trim()];
|
|
1866
|
+
}
|
|
1833
1867
|
}
|
|
1834
1868
|
});
|
|
1835
|
-
const
|
|
1836
|
-
|
|
1869
|
+
for (const f of collection.fields) {
|
|
1870
|
+
if (f.required) {
|
|
1871
|
+
if (isCreatingEntry && f.hideOnCreate) continue;
|
|
1872
|
+
if (f.dependsOn && finalEditing[f.dependsOn.field] !== void 0) {
|
|
1873
|
+
const targetVal = f.dependsOn.value;
|
|
1874
|
+
const currentVal = finalEditing[f.dependsOn.field];
|
|
1875
|
+
const match = Array.isArray(targetVal) ? targetVal.includes(currentVal) : currentVal === targetVal;
|
|
1876
|
+
if (!match) continue;
|
|
1877
|
+
}
|
|
1878
|
+
const rawVal = finalEditing[f.id];
|
|
1879
|
+
const isEmpty = rawVal === void 0 || rawVal === null || typeof rawVal === "string" && rawVal.trim() === "" || Array.isArray(rawVal) && rawVal.length === 0;
|
|
1880
|
+
if (isEmpty) {
|
|
1881
|
+
message.error(`El campo "${f.label || f.id}" es obligatorio.`);
|
|
1882
|
+
setSaving(false);
|
|
1883
|
+
return;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
const uniqueFields = collection.fields.filter((f) => f.unique);
|
|
1837
1888
|
for (const f of uniqueFields) {
|
|
1838
1889
|
const val = String(finalEditing[f.id] || "").trim().toLowerCase();
|
|
1839
1890
|
if (!val) {
|
|
@@ -1866,6 +1917,18 @@ function CollectionEditor({ collection }) {
|
|
|
1866
1917
|
await ctx.adapter.putEntry(collection.id, finalEditing);
|
|
1867
1918
|
message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
|
|
1868
1919
|
ctx.notifyCollectionChanged();
|
|
1920
|
+
setEntries((prev) => {
|
|
1921
|
+
const next = [...prev];
|
|
1922
|
+
const matchIdx = next.findIndex(
|
|
1923
|
+
(e) => originalId && String(e.id || "").trim().toLowerCase() === String(originalId).trim().toLowerCase() || String(e.id || "").trim().toLowerCase() === String(finalEditing.id || "").trim().toLowerCase()
|
|
1924
|
+
);
|
|
1925
|
+
if (matchIdx >= 0) {
|
|
1926
|
+
next[matchIdx] = { ...next[matchIdx], ...finalEditing };
|
|
1927
|
+
} else {
|
|
1928
|
+
next.unshift(finalEditing);
|
|
1929
|
+
}
|
|
1930
|
+
return next;
|
|
1931
|
+
});
|
|
1869
1932
|
setEditing(null);
|
|
1870
1933
|
setOriginalId(null);
|
|
1871
1934
|
setIsCreatingManual(false);
|
|
@@ -1879,6 +1942,9 @@ function CollectionEditor({ collection }) {
|
|
|
1879
1942
|
setDeletingId(id);
|
|
1880
1943
|
try {
|
|
1881
1944
|
await ctx.adapter.deleteEntry(collection.id, id);
|
|
1945
|
+
setEntries(
|
|
1946
|
+
(prev) => prev.filter((e) => String(e.id || "").trim().toLowerCase() !== String(id).trim().toLowerCase())
|
|
1947
|
+
);
|
|
1882
1948
|
ctx.notifyCollectionChanged();
|
|
1883
1949
|
load();
|
|
1884
1950
|
} finally {
|
|
@@ -1946,7 +2012,10 @@ function CollectionEditor({ collection }) {
|
|
|
1946
2012
|
{
|
|
1947
2013
|
size: "large",
|
|
1948
2014
|
prefix: /* @__PURE__ */ jsx(Search, { className: "h-4 w-4 text-slate-400" }),
|
|
1949
|
-
placeholder: `Buscar por ${collection.searchBy.map((s) =>
|
|
2015
|
+
placeholder: `Buscar por ${collection.searchBy.map((s) => {
|
|
2016
|
+
const f = collection.fields.find((field) => field.id === s);
|
|
2017
|
+
return f?.label ? f.label.toLowerCase() : s;
|
|
2018
|
+
}).join(", ")}...`,
|
|
1950
2019
|
value: search,
|
|
1951
2020
|
allowClear: true,
|
|
1952
2021
|
onChange: (e) => {
|
|
@@ -2076,7 +2145,7 @@ function CollectionEditor({ collection }) {
|
|
|
2076
2145
|
}
|
|
2077
2146
|
return true;
|
|
2078
2147
|
}).map((f) => {
|
|
2079
|
-
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";
|
|
2148
|
+
const isFullWidth = f.colSpan === 2 || f.colSpan === 12 || f.multiple || 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";
|
|
2080
2149
|
const colSpanClass = isFullWidth ? "lg:col-span-2 col-span-1" : "col-span-1";
|
|
2081
2150
|
if (isViewingDetail) {
|
|
2082
2151
|
return /* @__PURE__ */ jsxs("div", { className: `block ${colSpanClass}`, children: [
|
|
@@ -2086,7 +2155,9 @@ function CollectionEditor({ collection }) {
|
|
|
2086
2155
|
record: editing,
|
|
2087
2156
|
onChange: () => {
|
|
2088
2157
|
},
|
|
2089
|
-
isCreatingEntry: false
|
|
2158
|
+
isCreatingEntry: false,
|
|
2159
|
+
isViewingDetail: true,
|
|
2160
|
+
readOnly: true
|
|
2090
2161
|
}) : 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(
|
|
2091
2162
|
"img",
|
|
2092
2163
|
{
|
|
@@ -2094,14 +2165,14 @@ function CollectionEditor({ collection }) {
|
|
|
2094
2165
|
alt: f.label,
|
|
2095
2166
|
className: "h-28 w-auto max-w-full object-contain"
|
|
2096
2167
|
}
|
|
2097
|
-
) }) : /* @__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(
|
|
2168
|
+
) }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-slate-400 italic py-1", children: "Sin firma registrada" }) : f.type === "list" || f.multiple ? 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(
|
|
2098
2169
|
"span",
|
|
2099
2170
|
{
|
|
2100
|
-
className: "rounded-
|
|
2171
|
+
className: "rounded-xl bg-slate-100 text-slate-700 px-3 py-1 text-xs font-medium border border-slate-200",
|
|
2101
2172
|
children: String(item)
|
|
2102
2173
|
},
|
|
2103
2174
|
idx
|
|
2104
|
-
)) }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-slate-400 italic py-1", children: "Ninguno" }) : f.type === "link" ? Boolean(editing[f.id]) ? /* @__PURE__ */ jsxs(
|
|
2175
|
+
)) }) : typeof editing[f.id] === "string" && editing[f.id] ? /* @__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]) }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-slate-400 italic py-1", children: "Ninguno" }) : f.type === "link" ? Boolean(editing[f.id]) ? /* @__PURE__ */ jsxs(
|
|
2105
2176
|
"a",
|
|
2106
2177
|
{
|
|
2107
2178
|
href: String(editing[f.id]),
|
|
@@ -2118,14 +2189,19 @@ function CollectionEditor({ collection }) {
|
|
|
2118
2189
|
}
|
|
2119
2190
|
return /* @__PURE__ */ jsxs("div", { className: `block ${colSpanClass}`, children: [
|
|
2120
2191
|
/* @__PURE__ */ jsxs("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
|
|
2121
|
-
|
|
2192
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
2193
|
+
f.label,
|
|
2194
|
+
(f.required || f.unique) && /* @__PURE__ */ jsx("span", { className: "text-rose-500 ml-1 font-bold", title: "Campo obligatorio", children: "*" })
|
|
2195
|
+
] }),
|
|
2122
2196
|
/* @__PURE__ */ jsx("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
|
|
2123
2197
|
] }),
|
|
2124
2198
|
f.customRender ? f.customRender({
|
|
2125
2199
|
value: editing[f.id],
|
|
2126
2200
|
record: editing,
|
|
2127
2201
|
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2128
|
-
isCreatingEntry
|
|
2202
|
+
isCreatingEntry,
|
|
2203
|
+
isViewingDetail: false,
|
|
2204
|
+
readOnly: false
|
|
2129
2205
|
}) : f.type === "branch-settings" ? /* @__PURE__ */ jsx(
|
|
2130
2206
|
BranchSettingsEditor,
|
|
2131
2207
|
{
|
|
@@ -2259,21 +2335,8 @@ function CollectionEditor({ collection }) {
|
|
|
2259
2335
|
value: editing[f.id],
|
|
2260
2336
|
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2261
2337
|
onSelectRecord: (rec) => {
|
|
2262
|
-
if (f.
|
|
2263
|
-
setEditing((prev) => prev ? {
|
|
2264
|
-
...prev,
|
|
2265
|
-
clienteId: rec.id || prev.clienteId,
|
|
2266
|
-
clienteNombre: rec.nombre || rec.name || prev.clienteNombre,
|
|
2267
|
-
ciudad: rec.ciudad || prev.ciudad,
|
|
2268
|
-
direccion: rec.direccion || prev.direccion,
|
|
2269
|
-
telefono: rec.telefono || prev.telefono
|
|
2270
|
-
} : prev);
|
|
2271
|
-
} else if (f.id === "empleadoId" && rec) {
|
|
2272
|
-
setEditing((prev) => prev ? {
|
|
2273
|
-
...prev,
|
|
2274
|
-
empleadoId: rec.id || prev.empleadoId,
|
|
2275
|
-
empleadoNombre: rec.apellido ? `${rec.nombre || rec.name || ""} ${rec.apellido}`.trim() : rec.nombre || rec.name || prev.empleadoNombre
|
|
2276
|
-
} : prev);
|
|
2338
|
+
if (f.onSelectRecord) {
|
|
2339
|
+
setEditing((prev) => prev ? { ...prev, ...f.onSelectRecord(rec, prev) } : prev);
|
|
2277
2340
|
}
|
|
2278
2341
|
}
|
|
2279
2342
|
}
|
|
@@ -2529,63 +2592,61 @@ function CollectionEditor({ collection }) {
|
|
|
2529
2592
|
]
|
|
2530
2593
|
}
|
|
2531
2594
|
)
|
|
2532
|
-
] }) : f.type === "list" ? /* @__PURE__ */
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
"
|
|
2595
|
+
] }) : f.type === "list" || f.multiple ? /* @__PURE__ */ jsx("div", { className: "space-y-3", children: (() => {
|
|
2596
|
+
const currentArr = Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" && editing[f.id] ? [editing[f.id]] : [""];
|
|
2597
|
+
const displayArr = currentArr.length > 0 ? currentArr : [""];
|
|
2598
|
+
const singularLabel = f.label.endsWith("es") ? f.label.slice(0, -2) : f.label.endsWith("s") ? f.label.slice(0, -1) : f.label;
|
|
2599
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-2.5", children: [
|
|
2600
|
+
displayArr.map((item, idx) => /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center", children: [
|
|
2601
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs font-mono font-bold text-slate-400 w-7 text-right shrink-0", children: [
|
|
2602
|
+
"#",
|
|
2603
|
+
idx + 1
|
|
2540
2604
|
] }),
|
|
2541
2605
|
/* @__PURE__ */ jsx(
|
|
2542
2606
|
"input",
|
|
2543
2607
|
{
|
|
2544
2608
|
type: "text",
|
|
2545
2609
|
value: String(item ?? ""),
|
|
2546
|
-
placeholder
|
|
2610
|
+
placeholder: `${singularLabel} #${idx + 1}...`,
|
|
2547
2611
|
onChange: (e) => {
|
|
2548
|
-
|
|
2612
|
+
const arr = [...displayArr];
|
|
2549
2613
|
arr[idx] = e.target.value;
|
|
2550
2614
|
setEditing({ ...editing, [f.id]: arr });
|
|
2551
2615
|
},
|
|
2552
2616
|
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all bg-white"
|
|
2553
2617
|
}
|
|
2554
2618
|
),
|
|
2555
|
-
/* @__PURE__ */ jsx(
|
|
2619
|
+
displayArr.length > 1 && /* @__PURE__ */ jsx(
|
|
2556
2620
|
"button",
|
|
2557
2621
|
{
|
|
2558
2622
|
type: "button",
|
|
2559
2623
|
onClick: () => {
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
setEditing({ ...editing, [f.id]: arr });
|
|
2624
|
+
const arr = displayArr.filter((_, i) => i !== idx);
|
|
2625
|
+
setEditing({ ...editing, [f.id]: arr.length > 0 ? arr : [""] });
|
|
2563
2626
|
},
|
|
2564
|
-
className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer",
|
|
2627
|
+
className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer shrink-0",
|
|
2565
2628
|
title: "Eliminar elemento",
|
|
2566
2629
|
children: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" })
|
|
2567
2630
|
}
|
|
2568
2631
|
)
|
|
2569
|
-
] }, idx)
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
)
|
|
2588
|
-
] }) : f.type === "link" ? /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center", children: [
|
|
2632
|
+
] }, idx)),
|
|
2633
|
+
/* @__PURE__ */ jsxs(
|
|
2634
|
+
"button",
|
|
2635
|
+
{
|
|
2636
|
+
type: "button",
|
|
2637
|
+
onClick: () => {
|
|
2638
|
+
setEditing({ ...editing, [f.id]: [...displayArr, ""] });
|
|
2639
|
+
},
|
|
2640
|
+
className: "inline-flex items-center gap-1.5 px-3.5 py-2 bg-indigo-50 hover:bg-indigo-100 text-indigo-700 text-xs font-bold rounded-xl border border-indigo-100 transition-colors cursor-pointer",
|
|
2641
|
+
children: [
|
|
2642
|
+
/* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
|
|
2643
|
+
" Agregar ",
|
|
2644
|
+
singularLabel.toLowerCase()
|
|
2645
|
+
]
|
|
2646
|
+
}
|
|
2647
|
+
)
|
|
2648
|
+
] });
|
|
2649
|
+
})() }) : f.type === "link" ? /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center", children: [
|
|
2589
2650
|
/* @__PURE__ */ jsx(
|
|
2590
2651
|
Input,
|
|
2591
2652
|
{
|
|
@@ -2632,7 +2693,7 @@ function CollectionEditor({ collection }) {
|
|
|
2632
2693
|
}
|
|
2633
2694
|
},
|
|
2634
2695
|
onBlur: (e) => {
|
|
2635
|
-
const isUniqueField = f.unique
|
|
2696
|
+
const isUniqueField = Boolean(f.unique);
|
|
2636
2697
|
if (isUniqueField) {
|
|
2637
2698
|
const val = (e.target.value || "").trim().toLowerCase();
|
|
2638
2699
|
if (val) {
|
|
@@ -2767,7 +2828,30 @@ function CollectionEditor({ collection }) {
|
|
|
2767
2828
|
onDragEnd,
|
|
2768
2829
|
className: `hover:bg-slate-50/50 transition-colors group cursor-grab active:cursor-grabbing ${deletingId === e.id ? "opacity-50" : ""} ${dragOverIdx === idx ? "border-t-2 border-t-indigo-500" : ""}`,
|
|
2769
2830
|
children: [
|
|
2770
|
-
visibleFields.map((f) => /* @__PURE__ */ jsx("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "branch-settings" ? /* @__PURE__ */ jsx(BranchSettingsSummary, { value: e[f.id] }) : f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && (Array.isArray(e[f.id]) ? e[f.id].length > 0 : !!e[f.id]) ? /* @__PURE__ */ jsx("img", { src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : (f.id === "status" || f.id === "estado") && e[f.id] ? /* @__PURE__ */ jsx("span", { className: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold ${String(e[f.id]) === "Terminado" || String(e[f.id]) === "Terminada" || String(e[f.id]).includes("Entregado") ? "bg-emerald-50 text-emerald-700 border border-emerald-200" : String(e[f.id]) === "Proceso" || String(e[f.id]).includes("Preparaci\xF3n") ? "bg-amber-50 text-amber-700 border border-amber-200" : String(e[f.id]) === "Cancelado" || String(e[f.id]).includes("Cancelado") ? "bg-slate-100 text-slate-700 border border-slate-200" : String(e[f.id]) === "Vencido" || String(e[f.id]).toLowerCase().includes("vencid") ? "bg-rose-50 text-rose-700 border border-rose-200" : "bg-blue-50 text-blue-700 border border-blue-200"}`, children: String(e[f.id]) }) : (f.type === "reference" || f.type === "select" && f.collection) && e[f.id] ?
|
|
2831
|
+
visibleFields.map((f) => /* @__PURE__ */ jsx("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.renderCell ? f.renderCell(e[f.id], e) : f.type === "branch-settings" ? /* @__PURE__ */ jsx(BranchSettingsSummary, { value: e[f.id] }) : f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && (Array.isArray(e[f.id]) ? e[f.id].length > 0 : !!e[f.id]) ? /* @__PURE__ */ jsx("img", { src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : (f.id === "status" || f.id === "estado") && e[f.id] ? /* @__PURE__ */ jsx("span", { className: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold ${String(e[f.id]) === "Terminado" || String(e[f.id]) === "Terminada" || String(e[f.id]).includes("Entregado") ? "bg-emerald-50 text-emerald-700 border border-emerald-200" : String(e[f.id]) === "Proceso" || String(e[f.id]).includes("Preparaci\xF3n") ? "bg-amber-50 text-amber-700 border border-amber-200" : String(e[f.id]) === "Cancelado" || String(e[f.id]).includes("Cancelado") ? "bg-slate-100 text-slate-700 border border-slate-200" : String(e[f.id]) === "Vencido" || String(e[f.id]).toLowerCase().includes("vencid") ? "bg-rose-50 text-rose-700 border border-rose-200" : "bg-blue-50 text-blue-700 border border-blue-200"}`, children: String(e[f.id]) }) : (f.type === "reference" || f.type === "select" && f.collection) && e[f.id] ? f.onCellClick ? /* @__PURE__ */ jsx(
|
|
2832
|
+
"button",
|
|
2833
|
+
{
|
|
2834
|
+
type: "button",
|
|
2835
|
+
onClick: () => f.onCellClick(e[f.id], e),
|
|
2836
|
+
className: "font-medium text-indigo-600 hover:text-indigo-800 hover:underline cursor-pointer text-left truncate block max-w-full",
|
|
2837
|
+
children: /* @__PURE__ */ jsx(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple })
|
|
2838
|
+
}
|
|
2839
|
+
) : /* @__PURE__ */ jsx(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple }) : (f.type === "list" || f.multiple) && e[f.id] ? Array.isArray(e[f.id]) ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2840
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: String(e[f.id][0] || "") }),
|
|
2841
|
+
e[f.id].length > 1 && /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center px-1.5 py-0.2 rounded text-[10px] font-bold bg-indigo-50 text-indigo-700 border border-indigo-100 shrink-0", children: [
|
|
2842
|
+
"+",
|
|
2843
|
+
e[f.id].length - 1,
|
|
2844
|
+
" m\xE1s"
|
|
2845
|
+
] })
|
|
2846
|
+
] }) : /* @__PURE__ */ jsx("span", { children: String(e[f.id]) }) : f.onCellClick ? /* @__PURE__ */ jsx(
|
|
2847
|
+
"button",
|
|
2848
|
+
{
|
|
2849
|
+
type: "button",
|
|
2850
|
+
onClick: () => f.onCellClick(e[f.id], e),
|
|
2851
|
+
className: "font-medium text-indigo-600 hover:text-indigo-800 hover:underline cursor-pointer text-left truncate block w-full",
|
|
2852
|
+
children: String(e[f.id] ?? "")
|
|
2853
|
+
}
|
|
2854
|
+
) : f.type === "signature" && e[f.id] ? /* @__PURE__ */ jsx(Image, { src: String(e[f.id]), alt: "Firma", className: "h-7 max-w-[80px] object-contain rounded bg-white border border-slate-200 p-0.5 inline-block shadow-xs cursor-pointer", preview: { mask: "Ver" } }) : f.type === "number" && e[f.id] !== void 0 && e[f.id] !== null && String(e[f.id]) !== "" ? f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.includes("$") || f.id.toLowerCase().includes("amount") || f.id.toLowerCase().includes("total") ? /* @__PURE__ */ jsxs("span", { className: "font-semibold text-slate-800", children: [
|
|
2771
2855
|
"$ ",
|
|
2772
2856
|
Number(e[f.id]).toLocaleString("es-CO")
|
|
2773
2857
|
] }) : /* @__PURE__ */ jsx("span", { children: Number(e[f.id]).toLocaleString("es-CO") }) : f.type === "link" || typeof e[f.id] === "string" && String(e[f.id]).startsWith("http") ? /* @__PURE__ */ jsxs(
|
|
@@ -2784,18 +2868,22 @@ function CollectionEditor({ collection }) {
|
|
|
2784
2868
|
}
|
|
2785
2869
|
) : 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)),
|
|
2786
2870
|
/* @__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: [
|
|
2787
|
-
collection.enableDetailView && /* @__PURE__ */ jsx(
|
|
2871
|
+
(collection.enableDetailView || collection.onViewRecord) && /* @__PURE__ */ jsx(
|
|
2788
2872
|
"button",
|
|
2789
2873
|
{
|
|
2790
2874
|
onClick: () => {
|
|
2875
|
+
if (collection.onViewRecord) {
|
|
2876
|
+
collection.onViewRecord(e);
|
|
2877
|
+
return;
|
|
2878
|
+
}
|
|
2791
2879
|
setIsCreatingManual(false);
|
|
2792
2880
|
setIsViewingDetail(true);
|
|
2793
2881
|
setOriginalId(String(e.id || ""));
|
|
2794
2882
|
setDuplicateErrors({});
|
|
2795
2883
|
setEditing({ ...e });
|
|
2796
2884
|
},
|
|
2797
|
-
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
|
|
2798
|
-
title: "Ver detalle",
|
|
2885
|
+
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors cursor-pointer",
|
|
2886
|
+
title: collection.viewRecordTitle || "Ver detalle",
|
|
2799
2887
|
children: /* @__PURE__ */ jsx(Eye, { className: "h-4 w-4" })
|
|
2800
2888
|
}
|
|
2801
2889
|
),
|
|
@@ -4389,9 +4477,9 @@ function ReferenceSelect({
|
|
|
4389
4477
|
displayField = "name",
|
|
4390
4478
|
valueField = "name",
|
|
4391
4479
|
fallbackOptions,
|
|
4392
|
-
multiple = false,
|
|
4480
|
+
multiple: _multiple = false,
|
|
4393
4481
|
searchable = false,
|
|
4394
|
-
max,
|
|
4482
|
+
max: _max,
|
|
4395
4483
|
value,
|
|
4396
4484
|
onChange,
|
|
4397
4485
|
onSelectRecord
|
|
@@ -4401,45 +4489,46 @@ function ReferenceSelect({
|
|
|
4401
4489
|
const { message } = App.useApp();
|
|
4402
4490
|
const [options, setOptions] = useState([]);
|
|
4403
4491
|
const [loading, setLoading] = useState(true);
|
|
4404
|
-
const [
|
|
4405
|
-
const [
|
|
4406
|
-
const [
|
|
4407
|
-
const [
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
if (!newClient.nombre.trim()) {
|
|
4425
|
-
setClientError(t.nameRequired);
|
|
4426
|
-
return;
|
|
4427
|
-
}
|
|
4428
|
-
const cleanId = newClient.id.trim().toLowerCase();
|
|
4429
|
-
const isDuplicate = options.some((opt) => String(opt.value || "").trim().toLowerCase() === cleanId);
|
|
4430
|
-
if (isDuplicate) {
|
|
4431
|
-
setClientError("Ya existe un cliente con este NIT o C\xE9dula. No se pueden repetir.");
|
|
4432
|
-
return;
|
|
4492
|
+
const [modalOpen, setModalOpen] = useState(false);
|
|
4493
|
+
const [saving, setSaving] = useState(false);
|
|
4494
|
+
const [formError, setFormError] = useState("");
|
|
4495
|
+
const [newRecord, setNewRecord] = useState({});
|
|
4496
|
+
const targetCol = ctx.config.collections?.find((c) => c.id === collectionId);
|
|
4497
|
+
const handleSaveRecord = async () => {
|
|
4498
|
+
setFormError("");
|
|
4499
|
+
if (!targetCol) return;
|
|
4500
|
+
const uniqueFields = targetCol.fields.filter((f) => f.unique || f.id === "id" && !f.hideOnCreate);
|
|
4501
|
+
for (const uf of uniqueFields) {
|
|
4502
|
+
const val = String(newRecord[uf.id] || "").trim();
|
|
4503
|
+
if (!val) {
|
|
4504
|
+
setFormError(`El campo "${uf.label || uf.id}" es obligatorio.`);
|
|
4505
|
+
return;
|
|
4506
|
+
}
|
|
4507
|
+
const isDup = options.some((opt) => String(opt.value || "").trim().toLowerCase() === val.toLowerCase());
|
|
4508
|
+
if (isDup) {
|
|
4509
|
+
setFormError(`Ya existe un registro con este ${uf.label.toLowerCase()} (\xAB${val}\xBB).`);
|
|
4510
|
+
return;
|
|
4511
|
+
}
|
|
4433
4512
|
}
|
|
4434
|
-
|
|
4513
|
+
setSaving(true);
|
|
4435
4514
|
try {
|
|
4436
|
-
const
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
nombre: newClient.nombre.trim()
|
|
4515
|
+
const entryToSave = {
|
|
4516
|
+
id: String(newRecord.id || Date.now()).trim(),
|
|
4517
|
+
...newRecord
|
|
4440
4518
|
};
|
|
4441
|
-
|
|
4442
|
-
|
|
4519
|
+
targetCol.fields.forEach((f) => {
|
|
4520
|
+
if (f.type === "list" || f.multiple) {
|
|
4521
|
+
if (Array.isArray(entryToSave[f.id])) {
|
|
4522
|
+
entryToSave[f.id] = entryToSave[f.id].filter(
|
|
4523
|
+
(item) => item !== void 0 && item !== null && String(item).trim() !== ""
|
|
4524
|
+
);
|
|
4525
|
+
} else if (typeof entryToSave[f.id] === "string" && entryToSave[f.id]) {
|
|
4526
|
+
entryToSave[f.id] = [String(entryToSave[f.id]).trim()];
|
|
4527
|
+
}
|
|
4528
|
+
}
|
|
4529
|
+
});
|
|
4530
|
+
await ctx.adapter.putEntry(collectionId, entryToSave);
|
|
4531
|
+
const res = await ctx.adapter.listEntries(collectionId);
|
|
4443
4532
|
const fromCollection = (res || []).map((r) => {
|
|
4444
4533
|
const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
|
|
4445
4534
|
const fullName = r.apellido ? `${r.nombre || r.name || ""} ${r.apellido}`.trim() : "";
|
|
@@ -4451,27 +4540,18 @@ function ReferenceSelect({
|
|
|
4451
4540
|
};
|
|
4452
4541
|
});
|
|
4453
4542
|
setOptions(fromCollection);
|
|
4454
|
-
|
|
4543
|
+
const selectedVal = valueField && entryToSave[valueField] !== void 0 ? String(entryToSave[valueField]) : entryToSave.id;
|
|
4544
|
+
onChange(selectedVal);
|
|
4455
4545
|
if (onSelectRecord) {
|
|
4456
|
-
onSelectRecord(
|
|
4546
|
+
onSelectRecord(entryToSave);
|
|
4457
4547
|
}
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
tipoDocumento: "C\xE9dula de ciudadan\xEDa",
|
|
4462
|
-
id: "",
|
|
4463
|
-
sucursal: "",
|
|
4464
|
-
nombre: "",
|
|
4465
|
-
email: "",
|
|
4466
|
-
telefono: "",
|
|
4467
|
-
ciudad: "",
|
|
4468
|
-
direccion: ""
|
|
4469
|
-
});
|
|
4470
|
-
message.success(t.clientCreatedSuccess);
|
|
4548
|
+
setModalOpen(false);
|
|
4549
|
+
setNewRecord({});
|
|
4550
|
+
message.success(t.recordCreatedSuccess || "Registro creado y seleccionado exitosamente.");
|
|
4471
4551
|
} catch (err) {
|
|
4472
|
-
|
|
4552
|
+
setFormError(err?.message || "Error al crear registro.");
|
|
4473
4553
|
} finally {
|
|
4474
|
-
|
|
4554
|
+
setSaving(false);
|
|
4475
4555
|
}
|
|
4476
4556
|
};
|
|
4477
4557
|
useEffect(() => {
|
|
@@ -4496,41 +4576,24 @@ function ReferenceSelect({
|
|
|
4496
4576
|
});
|
|
4497
4577
|
setOptions(fromCollection);
|
|
4498
4578
|
setLoading(false);
|
|
4499
|
-
}).catch(() => {
|
|
4500
|
-
|
|
4579
|
+
}).catch((err) => {
|
|
4580
|
+
console.error(`Failed to load reference entries for ${collectionId}:`, err);
|
|
4581
|
+
if (fallbackOptions && fallbackOptions.length > 0) {
|
|
4582
|
+
setOptions(fallbackOptions.map((opt) => typeof opt === "string" ? { value: opt, label: opt } : opt));
|
|
4583
|
+
}
|
|
4501
4584
|
setLoading(false);
|
|
4502
4585
|
});
|
|
4503
|
-
}, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
filterOption: (input, option) => {
|
|
4515
|
-
if (!input) return true;
|
|
4516
|
-
const q = input.toLowerCase();
|
|
4517
|
-
const label = String(option?.label ?? "").toLowerCase();
|
|
4518
|
-
const val = String(option?.value ?? "").toLowerCase();
|
|
4519
|
-
return label.includes(q) || val.includes(q);
|
|
4520
|
-
},
|
|
4521
|
-
maxCount: max,
|
|
4522
|
-
value: selectedList,
|
|
4523
|
-
onChange,
|
|
4524
|
-
options,
|
|
4525
|
-
className: "w-full"
|
|
4526
|
-
}
|
|
4527
|
-
);
|
|
4528
|
-
}
|
|
4529
|
-
const singleVal = value !== void 0 && value !== null && value !== "" ? String(value) : void 0;
|
|
4530
|
-
const displayOptions = [...options];
|
|
4531
|
-
if (singleVal && !displayOptions.some((o) => o.value === singleVal)) {
|
|
4532
|
-
displayOptions.unshift({ value: singleVal, label: singleVal });
|
|
4533
|
-
}
|
|
4586
|
+
}, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter]);
|
|
4587
|
+
const rawVal = Array.isArray(value) ? value : value !== void 0 && value !== null && value !== "" ? [value] : [];
|
|
4588
|
+
const singleVal = rawVal[0] !== void 0 ? String(rawVal[0]) : void 0;
|
|
4589
|
+
const displayOptions = useMemo(() => {
|
|
4590
|
+
const list = [...options];
|
|
4591
|
+
if (singleVal && !list.some((o) => o.value === singleVal)) {
|
|
4592
|
+
list.unshift({ value: singleVal, label: `${singleVal} (actual)` });
|
|
4593
|
+
}
|
|
4594
|
+
return list;
|
|
4595
|
+
}, [options, singleVal]);
|
|
4596
|
+
const canQuickCreate = Boolean(targetCol && targetCol.enableQuickCreate !== false);
|
|
4534
4597
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4535
4598
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
4536
4599
|
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
@@ -4559,8 +4622,8 @@ function ReferenceSelect({
|
|
|
4559
4622
|
options: displayOptions,
|
|
4560
4623
|
dropdownRender: (menu) => /* @__PURE__ */ jsxs("div", { children: [
|
|
4561
4624
|
menu,
|
|
4562
|
-
|
|
4563
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs text-slate-500 font-medium", children: t.
|
|
4625
|
+
canQuickCreate && /* @__PURE__ */ jsxs("div", { className: "p-2 border-t border-slate-100 flex items-center justify-between bg-slate-50", children: [
|
|
4626
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-slate-500 font-medium", children: t.cantFindOption || "\xBFNo encuentras la opci\xF3n?" }),
|
|
4564
4627
|
/* @__PURE__ */ jsx(
|
|
4565
4628
|
Button,
|
|
4566
4629
|
{
|
|
@@ -4568,11 +4631,18 @@ function ReferenceSelect({
|
|
|
4568
4631
|
size: "small",
|
|
4569
4632
|
icon: /* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
|
|
4570
4633
|
onClick: () => {
|
|
4571
|
-
|
|
4572
|
-
|
|
4634
|
+
setFormError("");
|
|
4635
|
+
const init = {};
|
|
4636
|
+
targetCol.fields.forEach((f) => {
|
|
4637
|
+
if (f.defaultValue !== void 0) init[f.id] = f.defaultValue;
|
|
4638
|
+
else if (f.type === "list" || f.multiple) init[f.id] = [""];
|
|
4639
|
+
else init[f.id] = "";
|
|
4640
|
+
});
|
|
4641
|
+
setNewRecord(init);
|
|
4642
|
+
setModalOpen(true);
|
|
4573
4643
|
},
|
|
4574
4644
|
className: "bg-blue-600 hover:bg-blue-700 text-xs font-semibold rounded-lg shadow-sm",
|
|
4575
|
-
children: t.
|
|
4645
|
+
children: t.createNewOption || `Crear ${targetCol.name}`
|
|
4576
4646
|
}
|
|
4577
4647
|
)
|
|
4578
4648
|
] })
|
|
@@ -4580,192 +4650,191 @@ function ReferenceSelect({
|
|
|
4580
4650
|
className: "w-full"
|
|
4581
4651
|
}
|
|
4582
4652
|
) }),
|
|
4583
|
-
|
|
4653
|
+
canQuickCreate && /* @__PURE__ */ jsx(
|
|
4584
4654
|
Button,
|
|
4585
4655
|
{
|
|
4586
4656
|
type: "primary",
|
|
4587
4657
|
size: "large",
|
|
4588
4658
|
icon: /* @__PURE__ */ jsx(Plus, { className: "w-4 h-4" }),
|
|
4589
4659
|
onClick: () => {
|
|
4590
|
-
|
|
4591
|
-
|
|
4660
|
+
setFormError("");
|
|
4661
|
+
const init = {};
|
|
4662
|
+
targetCol.fields.forEach((f) => {
|
|
4663
|
+
if (f.defaultValue !== void 0) init[f.id] = f.defaultValue;
|
|
4664
|
+
else if (f.type === "list" || f.multiple) init[f.id] = [""];
|
|
4665
|
+
else init[f.id] = "";
|
|
4666
|
+
});
|
|
4667
|
+
setNewRecord(init);
|
|
4668
|
+
setModalOpen(true);
|
|
4592
4669
|
},
|
|
4593
4670
|
className: "bg-blue-600 hover:bg-blue-700 font-bold rounded-xl shrink-0 h-10 px-4 text-xs uppercase tracking-wider",
|
|
4594
|
-
children: t.newBtn
|
|
4671
|
+
children: targetCol.submitLabel || t.newBtn
|
|
4595
4672
|
}
|
|
4596
4673
|
)
|
|
4597
4674
|
] }),
|
|
4598
|
-
|
|
4675
|
+
canQuickCreate && /* @__PURE__ */ jsx(
|
|
4599
4676
|
Modal,
|
|
4600
4677
|
{
|
|
4601
|
-
open:
|
|
4602
|
-
title: /* @__PURE__ */ jsx("span", { className: "text-xl font-bold text-slate-900 font-display", children: t.
|
|
4603
|
-
onCancel: () =>
|
|
4678
|
+
open: modalOpen,
|
|
4679
|
+
title: /* @__PURE__ */ jsx("span", { className: "text-xl font-bold text-slate-900 font-display", children: targetCol.createTitle || `${t.newBtn} ${targetCol.name}` }),
|
|
4680
|
+
onCancel: () => setModalOpen(false),
|
|
4604
4681
|
centered: true,
|
|
4605
4682
|
width: 650,
|
|
4606
4683
|
footer: null,
|
|
4607
4684
|
children: /* @__PURE__ */ jsxs("div", { className: "pt-2 space-y-4", children: [
|
|
4608
|
-
/* @__PURE__ */
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4685
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: targetCol.fields.filter((f) => !f.hideOnCreate && !f.readOnly && f.type !== "signature").map((f) => {
|
|
4686
|
+
if (f.dependsOn && newRecord[f.dependsOn.field] !== void 0) {
|
|
4687
|
+
const targetVal = f.dependsOn.value;
|
|
4688
|
+
const currentVal = newRecord[f.dependsOn.field];
|
|
4689
|
+
const match = Array.isArray(targetVal) ? targetVal.includes(currentVal) : currentVal === targetVal;
|
|
4690
|
+
if (!match) return null;
|
|
4691
|
+
}
|
|
4692
|
+
const isFullWidth = f.colSpan === 2 || f.colSpan === 12 || f.multiple || f.type === "list" || f.type === "textarea";
|
|
4693
|
+
const colSpanClass = isFullWidth ? "col-span-1 sm:col-span-2" : "col-span-1";
|
|
4694
|
+
if (f.type === "list" || f.multiple) {
|
|
4695
|
+
const currentList = Array.isArray(newRecord[f.id]) ? newRecord[f.id] : newRecord[f.id] ? [String(newRecord[f.id])] : [""];
|
|
4696
|
+
const singularLabel = f.label.endsWith("es") ? f.label.slice(0, -2) : f.label.endsWith("s") ? f.label.slice(0, -1) : f.label;
|
|
4697
|
+
return /* @__PURE__ */ jsxs("div", { className: colSpanClass, children: [
|
|
4698
|
+
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: f.label }),
|
|
4699
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
4700
|
+
currentList.map((item, idx) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
4701
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs font-mono font-bold text-slate-400 w-6 text-right shrink-0", children: [
|
|
4702
|
+
"#",
|
|
4703
|
+
idx + 1
|
|
4704
|
+
] }),
|
|
4705
|
+
/* @__PURE__ */ jsx(
|
|
4706
|
+
Input,
|
|
4707
|
+
{
|
|
4708
|
+
size: "large",
|
|
4709
|
+
value: item,
|
|
4710
|
+
placeholder: `${singularLabel} #${idx + 1}...`,
|
|
4711
|
+
onChange: (e) => {
|
|
4712
|
+
const updated = [...currentList];
|
|
4713
|
+
updated[idx] = e.target.value;
|
|
4714
|
+
setNewRecord((prev) => ({ ...prev, [f.id]: updated }));
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
),
|
|
4718
|
+
currentList.length > 1 && /* @__PURE__ */ jsx(
|
|
4719
|
+
"button",
|
|
4720
|
+
{
|
|
4721
|
+
type: "button",
|
|
4722
|
+
onClick: () => {
|
|
4723
|
+
const updated = currentList.filter((_, i) => i !== idx);
|
|
4724
|
+
setNewRecord((prev) => ({
|
|
4725
|
+
...prev,
|
|
4726
|
+
[f.id]: updated.length > 0 ? updated : [""]
|
|
4727
|
+
}));
|
|
4728
|
+
},
|
|
4729
|
+
className: "p-2 text-rose-500 hover:text-rose-700 hover:bg-rose-50 rounded-lg cursor-pointer shrink-0",
|
|
4730
|
+
children: /* @__PURE__ */ jsx(Trash2, { className: "size-4" })
|
|
4731
|
+
}
|
|
4732
|
+
)
|
|
4733
|
+
] }, idx)),
|
|
4734
|
+
/* @__PURE__ */ jsxs(
|
|
4735
|
+
Button,
|
|
4736
|
+
{
|
|
4737
|
+
type: "dashed",
|
|
4738
|
+
size: "small",
|
|
4739
|
+
icon: /* @__PURE__ */ jsx(Plus, { className: "size-3.5" }),
|
|
4740
|
+
onClick: () => setNewRecord((prev) => ({
|
|
4741
|
+
...prev,
|
|
4742
|
+
[f.id]: [...currentList, ""]
|
|
4743
|
+
})),
|
|
4744
|
+
className: "w-full text-xs font-semibold",
|
|
4745
|
+
children: [
|
|
4746
|
+
"+ Agregar ",
|
|
4747
|
+
singularLabel.toLowerCase()
|
|
4748
|
+
]
|
|
4749
|
+
}
|
|
4750
|
+
)
|
|
4751
|
+
] })
|
|
4752
|
+
] }, f.id);
|
|
4753
|
+
}
|
|
4754
|
+
if (f.type === "select") {
|
|
4755
|
+
const opts = f.optionsMap && f.dependsOnField ? f.optionsMap[String(newRecord[f.dependsOnField] || "")] || f.options || [] : f.options || [];
|
|
4756
|
+
const formattedOpts = opts.map((o) => typeof o === "string" ? { label: o, value: o } : o);
|
|
4757
|
+
return /* @__PURE__ */ jsxs("div", { className: colSpanClass, children: [
|
|
4758
|
+
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: f.label }),
|
|
4759
|
+
/* @__PURE__ */ jsx(
|
|
4760
|
+
Select,
|
|
4761
|
+
{
|
|
4762
|
+
size: "large",
|
|
4763
|
+
value: newRecord[f.id] || void 0,
|
|
4764
|
+
onChange: (val) => {
|
|
4765
|
+
setNewRecord((prev) => {
|
|
4766
|
+
const next = { ...prev, [f.id]: val };
|
|
4767
|
+
targetCol.fields.forEach((dep) => {
|
|
4768
|
+
if (dep.dependsOnField === f.id && dep.optionsMap) {
|
|
4769
|
+
const nextOpts = dep.optionsMap[val] || dep.options || [];
|
|
4770
|
+
const firstVal = typeof nextOpts[0] === "string" ? nextOpts[0] : nextOpts[0]?.value;
|
|
4771
|
+
next[dep.id] = firstVal || "";
|
|
4772
|
+
}
|
|
4773
|
+
});
|
|
4774
|
+
return next;
|
|
4775
|
+
});
|
|
4776
|
+
},
|
|
4777
|
+
options: formattedOpts,
|
|
4778
|
+
className: "w-full"
|
|
4779
|
+
}
|
|
4780
|
+
)
|
|
4781
|
+
] }, f.id);
|
|
4782
|
+
}
|
|
4783
|
+
if (f.type === "textarea") {
|
|
4784
|
+
return /* @__PURE__ */ jsxs("div", { className: colSpanClass, children: [
|
|
4785
|
+
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: f.label }),
|
|
4786
|
+
/* @__PURE__ */ jsx(
|
|
4787
|
+
Input.TextArea,
|
|
4788
|
+
{
|
|
4789
|
+
rows: 3,
|
|
4790
|
+
value: newRecord[f.id] || "",
|
|
4791
|
+
onChange: (e) => setNewRecord((prev) => ({ ...prev, [f.id]: e.target.value }))
|
|
4792
|
+
}
|
|
4793
|
+
)
|
|
4794
|
+
] }, f.id);
|
|
4795
|
+
}
|
|
4796
|
+
return /* @__PURE__ */ jsxs("div", { className: colSpanClass, children: [
|
|
4651
4797
|
/* @__PURE__ */ jsxs("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
|
|
4652
|
-
|
|
4653
|
-
"
|
|
4798
|
+
f.label,
|
|
4799
|
+
" ",
|
|
4800
|
+
f.unique ? "*" : ""
|
|
4654
4801
|
] }),
|
|
4655
4802
|
/* @__PURE__ */ jsx(
|
|
4656
4803
|
Input,
|
|
4657
4804
|
{
|
|
4658
4805
|
size: "large",
|
|
4659
|
-
|
|
4660
|
-
placeholder:
|
|
4661
|
-
value: newClient.id,
|
|
4806
|
+
value: newRecord[f.id] || "",
|
|
4807
|
+
placeholder: f.label,
|
|
4662
4808
|
onChange: (e) => {
|
|
4663
|
-
|
|
4664
|
-
if (
|
|
4809
|
+
setNewRecord((prev) => ({ ...prev, [f.id]: e.target.value }));
|
|
4810
|
+
if (formError) setFormError("");
|
|
4665
4811
|
},
|
|
4666
4812
|
onBlur: (e) => {
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4813
|
+
if (f.unique) {
|
|
4814
|
+
const clean = (e.target.value || "").trim().toLowerCase();
|
|
4815
|
+
if (clean) {
|
|
4816
|
+
const dup = options.find((opt) => String(opt.value || "").trim().toLowerCase() === clean);
|
|
4817
|
+
if (dup) {
|
|
4818
|
+
setFormError(`Ya existe un registro con este ${f.label.toLowerCase()} (\xAB${dup.label || clean}\xBB).`);
|
|
4819
|
+
message.warning(`\u26A0\uFE0F Ya existe un registro con este ${f.label.toLowerCase()}: ${clean}.`);
|
|
4820
|
+
}
|
|
4673
4821
|
}
|
|
4674
4822
|
}
|
|
4675
4823
|
}
|
|
4676
4824
|
}
|
|
4677
4825
|
)
|
|
4678
|
-
] })
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
/* @__PURE__ */ jsx(
|
|
4682
|
-
Input,
|
|
4683
|
-
{
|
|
4684
|
-
size: "large",
|
|
4685
|
-
placeholder: t.clientBranch,
|
|
4686
|
-
value: newClient.sucursal,
|
|
4687
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, sucursal: e.target.value }))
|
|
4688
|
-
}
|
|
4689
|
-
)
|
|
4690
|
-
] })
|
|
4691
|
-
] }),
|
|
4692
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
|
|
4693
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4694
|
-
/* @__PURE__ */ jsxs("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
|
|
4695
|
-
t.clientName,
|
|
4696
|
-
" *"
|
|
4697
|
-
] }),
|
|
4698
|
-
/* @__PURE__ */ jsx(
|
|
4699
|
-
Input,
|
|
4700
|
-
{
|
|
4701
|
-
size: "large",
|
|
4702
|
-
placeholder: t.clientName,
|
|
4703
|
-
value: newClient.nombre,
|
|
4704
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, nombre: e.target.value }))
|
|
4705
|
-
}
|
|
4706
|
-
)
|
|
4707
|
-
] }),
|
|
4708
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4709
|
-
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientEmail }),
|
|
4710
|
-
/* @__PURE__ */ jsx(
|
|
4711
|
-
Input,
|
|
4712
|
-
{
|
|
4713
|
-
size: "large",
|
|
4714
|
-
placeholder: t.clientEmail,
|
|
4715
|
-
value: newClient.email,
|
|
4716
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, email: e.target.value }))
|
|
4717
|
-
}
|
|
4718
|
-
)
|
|
4719
|
-
] })
|
|
4720
|
-
] }),
|
|
4721
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
|
|
4722
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4723
|
-
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientPhone }),
|
|
4724
|
-
/* @__PURE__ */ jsx(
|
|
4725
|
-
Input,
|
|
4726
|
-
{
|
|
4727
|
-
size: "large",
|
|
4728
|
-
placeholder: t.clientPhone,
|
|
4729
|
-
value: newClient.telefono,
|
|
4730
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, telefono: e.target.value }))
|
|
4731
|
-
}
|
|
4732
|
-
)
|
|
4733
|
-
] }),
|
|
4734
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4735
|
-
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientCity }),
|
|
4736
|
-
/* @__PURE__ */ jsx(
|
|
4737
|
-
Input,
|
|
4738
|
-
{
|
|
4739
|
-
size: "large",
|
|
4740
|
-
placeholder: t.clientCity,
|
|
4741
|
-
value: newClient.ciudad,
|
|
4742
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, ciudad: e.target.value }))
|
|
4743
|
-
}
|
|
4744
|
-
)
|
|
4745
|
-
] })
|
|
4746
|
-
] }),
|
|
4747
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4748
|
-
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientAddress }),
|
|
4749
|
-
/* @__PURE__ */ jsx(
|
|
4750
|
-
Input,
|
|
4751
|
-
{
|
|
4752
|
-
size: "large",
|
|
4753
|
-
placeholder: t.clientAddress,
|
|
4754
|
-
value: newClient.direccion,
|
|
4755
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, direccion: e.target.value }))
|
|
4756
|
-
}
|
|
4757
|
-
)
|
|
4758
|
-
] }),
|
|
4759
|
-
clientError && /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold text-red-600 bg-red-50 p-2.5 rounded-lg border border-red-200", children: clientError }),
|
|
4826
|
+
] }, f.id);
|
|
4827
|
+
}) }),
|
|
4828
|
+
formError && /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold text-red-600 bg-red-50 p-2.5 rounded-lg border border-red-200", children: formError }),
|
|
4760
4829
|
/* @__PURE__ */ jsx(
|
|
4761
4830
|
Button,
|
|
4762
4831
|
{
|
|
4763
4832
|
type: "primary",
|
|
4764
4833
|
size: "large",
|
|
4765
|
-
loading:
|
|
4766
|
-
onClick:
|
|
4834
|
+
loading: saving,
|
|
4835
|
+
onClick: handleSaveRecord,
|
|
4767
4836
|
className: "w-full bg-blue-600 hover:bg-blue-700 font-bold uppercase rounded-xl h-11 text-xs tracking-wider shadow-sm mt-2",
|
|
4768
|
-
children: t.create.toUpperCase()
|
|
4837
|
+
children: (targetCol.submitLabel || t.create).toUpperCase()
|
|
4769
4838
|
}
|
|
4770
4839
|
)
|
|
4771
4840
|
] })
|