admin-lib-cms 1.2.16 → 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 +378 -317
- package/dist/index.mjs +378 -317
- 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,18 +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;
|
|
1833
|
-
} else if (f.type === "list") {
|
|
1859
|
+
} else if (f.type === "list" || f.multiple) {
|
|
1834
1860
|
if (Array.isArray(finalEditing[f.id])) {
|
|
1835
1861
|
finalEditing[f.id] = finalEditing[f.id].filter(
|
|
1836
1862
|
(item) => item !== void 0 && item !== null && String(item).trim() !== ""
|
|
1837
1863
|
);
|
|
1838
|
-
} else if (typeof finalEditing[f.id] === "string") {
|
|
1839
|
-
finalEditing[f.id] = String(finalEditing[f.id]).
|
|
1864
|
+
} else if (typeof finalEditing[f.id] === "string" && finalEditing[f.id]) {
|
|
1865
|
+
finalEditing[f.id] = [String(finalEditing[f.id]).trim()];
|
|
1840
1866
|
}
|
|
1841
1867
|
}
|
|
1842
1868
|
});
|
|
1843
|
-
const
|
|
1844
|
-
|
|
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);
|
|
1845
1888
|
for (const f of uniqueFields) {
|
|
1846
1889
|
const val = String(finalEditing[f.id] || "").trim().toLowerCase();
|
|
1847
1890
|
if (!val) {
|
|
@@ -1874,6 +1917,18 @@ function CollectionEditor({ collection }) {
|
|
|
1874
1917
|
await ctx.adapter.putEntry(collection.id, finalEditing);
|
|
1875
1918
|
message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
|
|
1876
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
|
+
});
|
|
1877
1932
|
setEditing(null);
|
|
1878
1933
|
setOriginalId(null);
|
|
1879
1934
|
setIsCreatingManual(false);
|
|
@@ -1887,6 +1942,9 @@ function CollectionEditor({ collection }) {
|
|
|
1887
1942
|
setDeletingId(id);
|
|
1888
1943
|
try {
|
|
1889
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
|
+
);
|
|
1890
1948
|
ctx.notifyCollectionChanged();
|
|
1891
1949
|
load();
|
|
1892
1950
|
} finally {
|
|
@@ -1954,7 +2012,10 @@ function CollectionEditor({ collection }) {
|
|
|
1954
2012
|
{
|
|
1955
2013
|
size: "large",
|
|
1956
2014
|
prefix: /* @__PURE__ */ jsx(Search, { className: "h-4 w-4 text-slate-400" }),
|
|
1957
|
-
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(", ")}...`,
|
|
1958
2019
|
value: search,
|
|
1959
2020
|
allowClear: true,
|
|
1960
2021
|
onChange: (e) => {
|
|
@@ -2084,7 +2145,7 @@ function CollectionEditor({ collection }) {
|
|
|
2084
2145
|
}
|
|
2085
2146
|
return true;
|
|
2086
2147
|
}).map((f) => {
|
|
2087
|
-
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";
|
|
2088
2149
|
const colSpanClass = isFullWidth ? "lg:col-span-2 col-span-1" : "col-span-1";
|
|
2089
2150
|
if (isViewingDetail) {
|
|
2090
2151
|
return /* @__PURE__ */ jsxs("div", { className: `block ${colSpanClass}`, children: [
|
|
@@ -2094,7 +2155,9 @@ function CollectionEditor({ collection }) {
|
|
|
2094
2155
|
record: editing,
|
|
2095
2156
|
onChange: () => {
|
|
2096
2157
|
},
|
|
2097
|
-
isCreatingEntry: false
|
|
2158
|
+
isCreatingEntry: false,
|
|
2159
|
+
isViewingDetail: true,
|
|
2160
|
+
readOnly: true
|
|
2098
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(
|
|
2099
2162
|
"img",
|
|
2100
2163
|
{
|
|
@@ -2102,14 +2165,14 @@ function CollectionEditor({ collection }) {
|
|
|
2102
2165
|
alt: f.label,
|
|
2103
2166
|
className: "h-28 w-auto max-w-full object-contain"
|
|
2104
2167
|
}
|
|
2105
|
-
) }) : /* @__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(
|
|
2106
2169
|
"span",
|
|
2107
2170
|
{
|
|
2108
|
-
className: "rounded-
|
|
2171
|
+
className: "rounded-xl bg-slate-100 text-slate-700 px-3 py-1 text-xs font-medium border border-slate-200",
|
|
2109
2172
|
children: String(item)
|
|
2110
2173
|
},
|
|
2111
2174
|
idx
|
|
2112
|
-
)) }) : /* @__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(
|
|
2113
2176
|
"a",
|
|
2114
2177
|
{
|
|
2115
2178
|
href: String(editing[f.id]),
|
|
@@ -2126,14 +2189,19 @@ function CollectionEditor({ collection }) {
|
|
|
2126
2189
|
}
|
|
2127
2190
|
return /* @__PURE__ */ jsxs("div", { className: `block ${colSpanClass}`, children: [
|
|
2128
2191
|
/* @__PURE__ */ jsxs("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
|
|
2129
|
-
|
|
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
|
+
] }),
|
|
2130
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 })
|
|
2131
2197
|
] }),
|
|
2132
2198
|
f.customRender ? f.customRender({
|
|
2133
2199
|
value: editing[f.id],
|
|
2134
2200
|
record: editing,
|
|
2135
2201
|
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2136
|
-
isCreatingEntry
|
|
2202
|
+
isCreatingEntry,
|
|
2203
|
+
isViewingDetail: false,
|
|
2204
|
+
readOnly: false
|
|
2137
2205
|
}) : f.type === "branch-settings" ? /* @__PURE__ */ jsx(
|
|
2138
2206
|
BranchSettingsEditor,
|
|
2139
2207
|
{
|
|
@@ -2267,21 +2335,8 @@ function CollectionEditor({ collection }) {
|
|
|
2267
2335
|
value: editing[f.id],
|
|
2268
2336
|
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2269
2337
|
onSelectRecord: (rec) => {
|
|
2270
|
-
if (f.
|
|
2271
|
-
setEditing((prev) => prev ? {
|
|
2272
|
-
...prev,
|
|
2273
|
-
clienteId: rec.id || prev.clienteId,
|
|
2274
|
-
clienteNombre: rec.nombre || rec.name || prev.clienteNombre,
|
|
2275
|
-
ciudad: rec.ciudad || prev.ciudad,
|
|
2276
|
-
direccion: rec.direccion || prev.direccion,
|
|
2277
|
-
telefono: rec.telefono || prev.telefono
|
|
2278
|
-
} : prev);
|
|
2279
|
-
} else if (f.id === "empleadoId" && rec) {
|
|
2280
|
-
setEditing((prev) => prev ? {
|
|
2281
|
-
...prev,
|
|
2282
|
-
empleadoId: rec.id || prev.empleadoId,
|
|
2283
|
-
empleadoNombre: rec.apellido ? `${rec.nombre || rec.name || ""} ${rec.apellido}`.trim() : rec.nombre || rec.name || prev.empleadoNombre
|
|
2284
|
-
} : prev);
|
|
2338
|
+
if (f.onSelectRecord) {
|
|
2339
|
+
setEditing((prev) => prev ? { ...prev, ...f.onSelectRecord(rec, prev) } : prev);
|
|
2285
2340
|
}
|
|
2286
2341
|
}
|
|
2287
2342
|
}
|
|
@@ -2537,63 +2592,61 @@ function CollectionEditor({ collection }) {
|
|
|
2537
2592
|
]
|
|
2538
2593
|
}
|
|
2539
2594
|
)
|
|
2540
|
-
] }) : f.type === "list" ? /* @__PURE__ */
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
"
|
|
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
|
|
2548
2604
|
] }),
|
|
2549
2605
|
/* @__PURE__ */ jsx(
|
|
2550
2606
|
"input",
|
|
2551
2607
|
{
|
|
2552
2608
|
type: "text",
|
|
2553
2609
|
value: String(item ?? ""),
|
|
2554
|
-
placeholder
|
|
2610
|
+
placeholder: `${singularLabel} #${idx + 1}...`,
|
|
2555
2611
|
onChange: (e) => {
|
|
2556
|
-
|
|
2612
|
+
const arr = [...displayArr];
|
|
2557
2613
|
arr[idx] = e.target.value;
|
|
2558
2614
|
setEditing({ ...editing, [f.id]: arr });
|
|
2559
2615
|
},
|
|
2560
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"
|
|
2561
2617
|
}
|
|
2562
2618
|
),
|
|
2563
|
-
/* @__PURE__ */ jsx(
|
|
2619
|
+
displayArr.length > 1 && /* @__PURE__ */ jsx(
|
|
2564
2620
|
"button",
|
|
2565
2621
|
{
|
|
2566
2622
|
type: "button",
|
|
2567
2623
|
onClick: () => {
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
setEditing({ ...editing, [f.id]: arr });
|
|
2624
|
+
const arr = displayArr.filter((_, i) => i !== idx);
|
|
2625
|
+
setEditing({ ...editing, [f.id]: arr.length > 0 ? arr : [""] });
|
|
2571
2626
|
},
|
|
2572
|
-
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",
|
|
2573
2628
|
title: "Eliminar elemento",
|
|
2574
2629
|
children: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" })
|
|
2575
2630
|
}
|
|
2576
2631
|
)
|
|
2577
|
-
] }, idx)
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
)
|
|
2596
|
-
] }) : 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: [
|
|
2597
2650
|
/* @__PURE__ */ jsx(
|
|
2598
2651
|
Input,
|
|
2599
2652
|
{
|
|
@@ -2640,7 +2693,7 @@ function CollectionEditor({ collection }) {
|
|
|
2640
2693
|
}
|
|
2641
2694
|
},
|
|
2642
2695
|
onBlur: (e) => {
|
|
2643
|
-
const isUniqueField = f.unique
|
|
2696
|
+
const isUniqueField = Boolean(f.unique);
|
|
2644
2697
|
if (isUniqueField) {
|
|
2645
2698
|
const val = (e.target.value || "").trim().toLowerCase();
|
|
2646
2699
|
if (val) {
|
|
@@ -2775,7 +2828,30 @@ function CollectionEditor({ collection }) {
|
|
|
2775
2828
|
onDragEnd,
|
|
2776
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" : ""}`,
|
|
2777
2830
|
children: [
|
|
2778
|
-
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: [
|
|
2779
2855
|
"$ ",
|
|
2780
2856
|
Number(e[f.id]).toLocaleString("es-CO")
|
|
2781
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(
|
|
@@ -2792,18 +2868,22 @@ function CollectionEditor({ collection }) {
|
|
|
2792
2868
|
}
|
|
2793
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)),
|
|
2794
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: [
|
|
2795
|
-
collection.enableDetailView && /* @__PURE__ */ jsx(
|
|
2871
|
+
(collection.enableDetailView || collection.onViewRecord) && /* @__PURE__ */ jsx(
|
|
2796
2872
|
"button",
|
|
2797
2873
|
{
|
|
2798
2874
|
onClick: () => {
|
|
2875
|
+
if (collection.onViewRecord) {
|
|
2876
|
+
collection.onViewRecord(e);
|
|
2877
|
+
return;
|
|
2878
|
+
}
|
|
2799
2879
|
setIsCreatingManual(false);
|
|
2800
2880
|
setIsViewingDetail(true);
|
|
2801
2881
|
setOriginalId(String(e.id || ""));
|
|
2802
2882
|
setDuplicateErrors({});
|
|
2803
2883
|
setEditing({ ...e });
|
|
2804
2884
|
},
|
|
2805
|
-
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
|
|
2806
|
-
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",
|
|
2807
2887
|
children: /* @__PURE__ */ jsx(Eye, { className: "h-4 w-4" })
|
|
2808
2888
|
}
|
|
2809
2889
|
),
|
|
@@ -4397,9 +4477,9 @@ function ReferenceSelect({
|
|
|
4397
4477
|
displayField = "name",
|
|
4398
4478
|
valueField = "name",
|
|
4399
4479
|
fallbackOptions,
|
|
4400
|
-
multiple = false,
|
|
4480
|
+
multiple: _multiple = false,
|
|
4401
4481
|
searchable = false,
|
|
4402
|
-
max,
|
|
4482
|
+
max: _max,
|
|
4403
4483
|
value,
|
|
4404
4484
|
onChange,
|
|
4405
4485
|
onSelectRecord
|
|
@@ -4409,45 +4489,46 @@ function ReferenceSelect({
|
|
|
4409
4489
|
const { message } = App.useApp();
|
|
4410
4490
|
const [options, setOptions] = useState([]);
|
|
4411
4491
|
const [loading, setLoading] = useState(true);
|
|
4412
|
-
const [
|
|
4413
|
-
const [
|
|
4414
|
-
const [
|
|
4415
|
-
const [
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
if (!newClient.nombre.trim()) {
|
|
4433
|
-
setClientError(t.nameRequired);
|
|
4434
|
-
return;
|
|
4435
|
-
}
|
|
4436
|
-
const cleanId = newClient.id.trim().toLowerCase();
|
|
4437
|
-
const isDuplicate = options.some((opt) => String(opt.value || "").trim().toLowerCase() === cleanId);
|
|
4438
|
-
if (isDuplicate) {
|
|
4439
|
-
setClientError("Ya existe un cliente con este NIT o C\xE9dula. No se pueden repetir.");
|
|
4440
|
-
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
|
+
}
|
|
4441
4512
|
}
|
|
4442
|
-
|
|
4513
|
+
setSaving(true);
|
|
4443
4514
|
try {
|
|
4444
|
-
const
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
nombre: newClient.nombre.trim()
|
|
4515
|
+
const entryToSave = {
|
|
4516
|
+
id: String(newRecord.id || Date.now()).trim(),
|
|
4517
|
+
...newRecord
|
|
4448
4518
|
};
|
|
4449
|
-
|
|
4450
|
-
|
|
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);
|
|
4451
4532
|
const fromCollection = (res || []).map((r) => {
|
|
4452
4533
|
const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
|
|
4453
4534
|
const fullName = r.apellido ? `${r.nombre || r.name || ""} ${r.apellido}`.trim() : "";
|
|
@@ -4459,27 +4540,18 @@ function ReferenceSelect({
|
|
|
4459
4540
|
};
|
|
4460
4541
|
});
|
|
4461
4542
|
setOptions(fromCollection);
|
|
4462
|
-
|
|
4543
|
+
const selectedVal = valueField && entryToSave[valueField] !== void 0 ? String(entryToSave[valueField]) : entryToSave.id;
|
|
4544
|
+
onChange(selectedVal);
|
|
4463
4545
|
if (onSelectRecord) {
|
|
4464
|
-
onSelectRecord(
|
|
4546
|
+
onSelectRecord(entryToSave);
|
|
4465
4547
|
}
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
tipoDocumento: "C\xE9dula de ciudadan\xEDa",
|
|
4470
|
-
id: "",
|
|
4471
|
-
sucursal: "",
|
|
4472
|
-
nombre: "",
|
|
4473
|
-
email: "",
|
|
4474
|
-
telefono: "",
|
|
4475
|
-
ciudad: "",
|
|
4476
|
-
direccion: ""
|
|
4477
|
-
});
|
|
4478
|
-
message.success(t.clientCreatedSuccess);
|
|
4548
|
+
setModalOpen(false);
|
|
4549
|
+
setNewRecord({});
|
|
4550
|
+
message.success(t.recordCreatedSuccess || "Registro creado y seleccionado exitosamente.");
|
|
4479
4551
|
} catch (err) {
|
|
4480
|
-
|
|
4552
|
+
setFormError(err?.message || "Error al crear registro.");
|
|
4481
4553
|
} finally {
|
|
4482
|
-
|
|
4554
|
+
setSaving(false);
|
|
4483
4555
|
}
|
|
4484
4556
|
};
|
|
4485
4557
|
useEffect(() => {
|
|
@@ -4504,41 +4576,24 @@ function ReferenceSelect({
|
|
|
4504
4576
|
});
|
|
4505
4577
|
setOptions(fromCollection);
|
|
4506
4578
|
setLoading(false);
|
|
4507
|
-
}).catch(() => {
|
|
4508
|
-
|
|
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
|
+
}
|
|
4509
4584
|
setLoading(false);
|
|
4510
4585
|
});
|
|
4511
|
-
}, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
filterOption: (input, option) => {
|
|
4523
|
-
if (!input) return true;
|
|
4524
|
-
const q = input.toLowerCase();
|
|
4525
|
-
const label = String(option?.label ?? "").toLowerCase();
|
|
4526
|
-
const val = String(option?.value ?? "").toLowerCase();
|
|
4527
|
-
return label.includes(q) || val.includes(q);
|
|
4528
|
-
},
|
|
4529
|
-
maxCount: max,
|
|
4530
|
-
value: selectedList,
|
|
4531
|
-
onChange,
|
|
4532
|
-
options,
|
|
4533
|
-
className: "w-full"
|
|
4534
|
-
}
|
|
4535
|
-
);
|
|
4536
|
-
}
|
|
4537
|
-
const singleVal = value !== void 0 && value !== null && value !== "" ? String(value) : void 0;
|
|
4538
|
-
const displayOptions = [...options];
|
|
4539
|
-
if (singleVal && !displayOptions.some((o) => o.value === singleVal)) {
|
|
4540
|
-
displayOptions.unshift({ value: singleVal, label: singleVal });
|
|
4541
|
-
}
|
|
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);
|
|
4542
4597
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4543
4598
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
4544
4599
|
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
@@ -4567,8 +4622,8 @@ function ReferenceSelect({
|
|
|
4567
4622
|
options: displayOptions,
|
|
4568
4623
|
dropdownRender: (menu) => /* @__PURE__ */ jsxs("div", { children: [
|
|
4569
4624
|
menu,
|
|
4570
|
-
|
|
4571
|
-
/* @__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?" }),
|
|
4572
4627
|
/* @__PURE__ */ jsx(
|
|
4573
4628
|
Button,
|
|
4574
4629
|
{
|
|
@@ -4576,11 +4631,18 @@ function ReferenceSelect({
|
|
|
4576
4631
|
size: "small",
|
|
4577
4632
|
icon: /* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
|
|
4578
4633
|
onClick: () => {
|
|
4579
|
-
|
|
4580
|
-
|
|
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);
|
|
4581
4643
|
},
|
|
4582
4644
|
className: "bg-blue-600 hover:bg-blue-700 text-xs font-semibold rounded-lg shadow-sm",
|
|
4583
|
-
children: t.
|
|
4645
|
+
children: t.createNewOption || `Crear ${targetCol.name}`
|
|
4584
4646
|
}
|
|
4585
4647
|
)
|
|
4586
4648
|
] })
|
|
@@ -4588,192 +4650,191 @@ function ReferenceSelect({
|
|
|
4588
4650
|
className: "w-full"
|
|
4589
4651
|
}
|
|
4590
4652
|
) }),
|
|
4591
|
-
|
|
4653
|
+
canQuickCreate && /* @__PURE__ */ jsx(
|
|
4592
4654
|
Button,
|
|
4593
4655
|
{
|
|
4594
4656
|
type: "primary",
|
|
4595
4657
|
size: "large",
|
|
4596
4658
|
icon: /* @__PURE__ */ jsx(Plus, { className: "w-4 h-4" }),
|
|
4597
4659
|
onClick: () => {
|
|
4598
|
-
|
|
4599
|
-
|
|
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);
|
|
4600
4669
|
},
|
|
4601
4670
|
className: "bg-blue-600 hover:bg-blue-700 font-bold rounded-xl shrink-0 h-10 px-4 text-xs uppercase tracking-wider",
|
|
4602
|
-
children: t.newBtn
|
|
4671
|
+
children: targetCol.submitLabel || t.newBtn
|
|
4603
4672
|
}
|
|
4604
4673
|
)
|
|
4605
4674
|
] }),
|
|
4606
|
-
|
|
4675
|
+
canQuickCreate && /* @__PURE__ */ jsx(
|
|
4607
4676
|
Modal,
|
|
4608
4677
|
{
|
|
4609
|
-
open:
|
|
4610
|
-
title: /* @__PURE__ */ jsx("span", { className: "text-xl font-bold text-slate-900 font-display", children: t.
|
|
4611
|
-
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),
|
|
4612
4681
|
centered: true,
|
|
4613
4682
|
width: 650,
|
|
4614
4683
|
footer: null,
|
|
4615
4684
|
children: /* @__PURE__ */ jsxs("div", { className: "pt-2 space-y-4", children: [
|
|
4616
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
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: [
|
|
4659
4797
|
/* @__PURE__ */ jsxs("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
|
|
4660
|
-
|
|
4661
|
-
"
|
|
4798
|
+
f.label,
|
|
4799
|
+
" ",
|
|
4800
|
+
f.unique ? "*" : ""
|
|
4662
4801
|
] }),
|
|
4663
4802
|
/* @__PURE__ */ jsx(
|
|
4664
4803
|
Input,
|
|
4665
4804
|
{
|
|
4666
4805
|
size: "large",
|
|
4667
|
-
|
|
4668
|
-
placeholder:
|
|
4669
|
-
value: newClient.id,
|
|
4806
|
+
value: newRecord[f.id] || "",
|
|
4807
|
+
placeholder: f.label,
|
|
4670
4808
|
onChange: (e) => {
|
|
4671
|
-
|
|
4672
|
-
if (
|
|
4809
|
+
setNewRecord((prev) => ({ ...prev, [f.id]: e.target.value }));
|
|
4810
|
+
if (formError) setFormError("");
|
|
4673
4811
|
},
|
|
4674
4812
|
onBlur: (e) => {
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
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
|
+
}
|
|
4681
4821
|
}
|
|
4682
4822
|
}
|
|
4683
4823
|
}
|
|
4684
4824
|
}
|
|
4685
4825
|
)
|
|
4686
|
-
] })
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
/* @__PURE__ */ jsx(
|
|
4690
|
-
Input,
|
|
4691
|
-
{
|
|
4692
|
-
size: "large",
|
|
4693
|
-
placeholder: t.clientBranch,
|
|
4694
|
-
value: newClient.sucursal,
|
|
4695
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, sucursal: e.target.value }))
|
|
4696
|
-
}
|
|
4697
|
-
)
|
|
4698
|
-
] })
|
|
4699
|
-
] }),
|
|
4700
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
|
|
4701
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4702
|
-
/* @__PURE__ */ jsxs("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
|
|
4703
|
-
t.clientName,
|
|
4704
|
-
" *"
|
|
4705
|
-
] }),
|
|
4706
|
-
/* @__PURE__ */ jsx(
|
|
4707
|
-
Input,
|
|
4708
|
-
{
|
|
4709
|
-
size: "large",
|
|
4710
|
-
placeholder: t.clientName,
|
|
4711
|
-
value: newClient.nombre,
|
|
4712
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, nombre: e.target.value }))
|
|
4713
|
-
}
|
|
4714
|
-
)
|
|
4715
|
-
] }),
|
|
4716
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4717
|
-
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientEmail }),
|
|
4718
|
-
/* @__PURE__ */ jsx(
|
|
4719
|
-
Input,
|
|
4720
|
-
{
|
|
4721
|
-
size: "large",
|
|
4722
|
-
placeholder: t.clientEmail,
|
|
4723
|
-
value: newClient.email,
|
|
4724
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, email: e.target.value }))
|
|
4725
|
-
}
|
|
4726
|
-
)
|
|
4727
|
-
] })
|
|
4728
|
-
] }),
|
|
4729
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
|
|
4730
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4731
|
-
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientPhone }),
|
|
4732
|
-
/* @__PURE__ */ jsx(
|
|
4733
|
-
Input,
|
|
4734
|
-
{
|
|
4735
|
-
size: "large",
|
|
4736
|
-
placeholder: t.clientPhone,
|
|
4737
|
-
value: newClient.telefono,
|
|
4738
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, telefono: e.target.value }))
|
|
4739
|
-
}
|
|
4740
|
-
)
|
|
4741
|
-
] }),
|
|
4742
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4743
|
-
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientCity }),
|
|
4744
|
-
/* @__PURE__ */ jsx(
|
|
4745
|
-
Input,
|
|
4746
|
-
{
|
|
4747
|
-
size: "large",
|
|
4748
|
-
placeholder: t.clientCity,
|
|
4749
|
-
value: newClient.ciudad,
|
|
4750
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, ciudad: e.target.value }))
|
|
4751
|
-
}
|
|
4752
|
-
)
|
|
4753
|
-
] })
|
|
4754
|
-
] }),
|
|
4755
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
4756
|
-
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientAddress }),
|
|
4757
|
-
/* @__PURE__ */ jsx(
|
|
4758
|
-
Input,
|
|
4759
|
-
{
|
|
4760
|
-
size: "large",
|
|
4761
|
-
placeholder: t.clientAddress,
|
|
4762
|
-
value: newClient.direccion,
|
|
4763
|
-
onChange: (e) => setNewClient((prev) => ({ ...prev, direccion: e.target.value }))
|
|
4764
|
-
}
|
|
4765
|
-
)
|
|
4766
|
-
] }),
|
|
4767
|
-
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 }),
|
|
4768
4829
|
/* @__PURE__ */ jsx(
|
|
4769
4830
|
Button,
|
|
4770
4831
|
{
|
|
4771
4832
|
type: "primary",
|
|
4772
4833
|
size: "large",
|
|
4773
|
-
loading:
|
|
4774
|
-
onClick:
|
|
4834
|
+
loading: saving,
|
|
4835
|
+
onClick: handleSaveRecord,
|
|
4775
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",
|
|
4776
|
-
children: t.create.toUpperCase()
|
|
4837
|
+
children: (targetCol.submitLabel || t.create).toUpperCase()
|
|
4777
4838
|
}
|
|
4778
4839
|
)
|
|
4779
4840
|
] })
|