admin-lib-cms 1.2.17 → 1.2.19
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/README.md +29 -0
- package/dist/index.d.mts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +2206 -1091
- package/dist/index.mjs +2224 -1099
- package/dist/storage.js +70 -26
- package/dist/storage.mjs +70 -26
- package/dist/types.d.mts +36 -1
- package/dist/types.d.ts +36 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -22,7 +22,14 @@ import {
|
|
|
22
22
|
} from "./chunk-4KJKAYIC.mjs";
|
|
23
23
|
|
|
24
24
|
// src/admin/AdminApp.tsx
|
|
25
|
-
import React, {
|
|
25
|
+
import React, {
|
|
26
|
+
createElement,
|
|
27
|
+
useCallback,
|
|
28
|
+
useEffect,
|
|
29
|
+
useMemo,
|
|
30
|
+
useRef,
|
|
31
|
+
useState
|
|
32
|
+
} from "react";
|
|
26
33
|
import { createPortal } from "react-dom";
|
|
27
34
|
import {
|
|
28
35
|
ConfigProvider,
|
|
@@ -35,9 +42,13 @@ import {
|
|
|
35
42
|
Switch,
|
|
36
43
|
Button,
|
|
37
44
|
Image,
|
|
38
|
-
App
|
|
45
|
+
App,
|
|
46
|
+
Tag,
|
|
47
|
+
Progress,
|
|
48
|
+
Radio,
|
|
49
|
+
Segmented
|
|
39
50
|
} from "antd";
|
|
40
|
-
import
|
|
51
|
+
import dayjs2 from "dayjs";
|
|
41
52
|
import {
|
|
42
53
|
FileText,
|
|
43
54
|
Boxes,
|
|
@@ -68,9 +79,234 @@ import {
|
|
|
68
79
|
Check,
|
|
69
80
|
GripVertical,
|
|
70
81
|
AlertTriangle,
|
|
71
|
-
FileDown
|
|
82
|
+
FileDown,
|
|
83
|
+
FileUp,
|
|
84
|
+
FileSpreadsheet
|
|
72
85
|
} from "lucide-react";
|
|
73
86
|
|
|
87
|
+
// src/admin/excel.ts
|
|
88
|
+
import * as XLSX from "xlsx";
|
|
89
|
+
import dayjs from "dayjs";
|
|
90
|
+
function filterEntriesByDateRange(entries, fieldId, startDate, endDate) {
|
|
91
|
+
if (!startDate && !endDate) return entries;
|
|
92
|
+
const startDayjs = startDate ? dayjs(startDate).startOf("day") : null;
|
|
93
|
+
const endDayjs = endDate ? dayjs(endDate).endOf("day") : null;
|
|
94
|
+
return entries.filter((e) => {
|
|
95
|
+
const val = e[fieldId];
|
|
96
|
+
if (!val) return false;
|
|
97
|
+
const d = dayjs(String(val));
|
|
98
|
+
if (!d.isValid()) return false;
|
|
99
|
+
if (startDayjs && d.isBefore(startDayjs)) return false;
|
|
100
|
+
if (endDayjs && d.isAfter(endDayjs)) return false;
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function findExistingEntry(item, existingEntries, collection) {
|
|
105
|
+
if (item.id && !item.id.startsWith("item_")) {
|
|
106
|
+
const cleanId = String(item.id).trim().toLowerCase();
|
|
107
|
+
const matchById = existingEntries.find(
|
|
108
|
+
(e) => e.id && String(e.id).trim().toLowerCase() === cleanId || e._id && String(e._id).trim().toLowerCase() === cleanId
|
|
109
|
+
);
|
|
110
|
+
if (matchById) return matchById;
|
|
111
|
+
}
|
|
112
|
+
const uniqueFieldIds = [];
|
|
113
|
+
(collection.fields || []).forEach((f) => {
|
|
114
|
+
if (f.unique && !uniqueFieldIds.includes(f.id)) {
|
|
115
|
+
uniqueFieldIds.push(f.id);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
(collection.uniqueFields || []).forEach((uf) => {
|
|
119
|
+
if (!uniqueFieldIds.includes(uf)) {
|
|
120
|
+
uniqueFieldIds.push(uf);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
for (const ufId of uniqueFieldIds) {
|
|
124
|
+
const itemVal = item[ufId];
|
|
125
|
+
if (itemVal !== void 0 && itemVal !== null && String(itemVal).trim() !== "") {
|
|
126
|
+
const cleanVal = String(itemVal).trim().toLowerCase();
|
|
127
|
+
const match = existingEntries.find((e) => {
|
|
128
|
+
const eVal = e[ufId];
|
|
129
|
+
return eVal !== void 0 && eVal !== null && String(eVal).trim().toLowerCase() === cleanVal;
|
|
130
|
+
});
|
|
131
|
+
if (match) return match;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
function formatValueForExport(val, field, entry) {
|
|
137
|
+
if (field?.formatExport && typeof field.formatExport === "function") {
|
|
138
|
+
try {
|
|
139
|
+
const res = field.formatExport(val, entry);
|
|
140
|
+
if (res !== void 0 && res !== null) return res;
|
|
141
|
+
} catch (e) {
|
|
142
|
+
console.error("Error en formatExport:", e);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (val === void 0 || val === null) return "";
|
|
146
|
+
if (typeof val === "number" || typeof val === "boolean") return val;
|
|
147
|
+
if (Array.isArray(val)) {
|
|
148
|
+
return val.map((item) => typeof item === "object" && item !== null ? JSON.stringify(item) : String(item)).join(", ");
|
|
149
|
+
}
|
|
150
|
+
if (typeof val === "object") {
|
|
151
|
+
try {
|
|
152
|
+
return JSON.stringify(val);
|
|
153
|
+
} catch {
|
|
154
|
+
return String(val);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return String(val);
|
|
158
|
+
}
|
|
159
|
+
function exportCollectionToExcel(collection, entries, fileNamePrefix) {
|
|
160
|
+
const columns = [
|
|
161
|
+
{ key: "id", label: "ID" }
|
|
162
|
+
];
|
|
163
|
+
(collection.fields || []).forEach((f) => {
|
|
164
|
+
columns.push({
|
|
165
|
+
key: f.id,
|
|
166
|
+
label: f.label || f.id,
|
|
167
|
+
field: f
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
const rows = entries.map((entry) => {
|
|
171
|
+
const rowObj = {};
|
|
172
|
+
columns.forEach((col) => {
|
|
173
|
+
const rawVal = entry[col.key];
|
|
174
|
+
rowObj[col.label] = formatValueForExport(rawVal, col.field, entry);
|
|
175
|
+
});
|
|
176
|
+
return rowObj;
|
|
177
|
+
});
|
|
178
|
+
const worksheet = XLSX.utils.json_to_sheet(rows);
|
|
179
|
+
const colWidths = columns.map((col) => {
|
|
180
|
+
let maxLen = col.label.length;
|
|
181
|
+
for (let i = 0; i < Math.min(rows.length, 100); i++) {
|
|
182
|
+
const cellVal = String(rows[i]?.[col.label] ?? "");
|
|
183
|
+
if (cellVal.length > maxLen) {
|
|
184
|
+
maxLen = Math.min(cellVal.length, 45);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return { wch: Math.max(maxLen + 3, 12) };
|
|
188
|
+
});
|
|
189
|
+
worksheet["!cols"] = colWidths;
|
|
190
|
+
const workbook = XLSX.utils.book_new();
|
|
191
|
+
const safeSheetName = (collection.name || collection.id).replace(/[\\/?*[\]:]/g, "").slice(0, 31) || "Datos";
|
|
192
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, safeSheetName);
|
|
193
|
+
const dateStr = dayjs().format("YYYY-MM-DD");
|
|
194
|
+
const baseName = fileNamePrefix || (collection.name || collection.id).toLowerCase().replace(/[^a-z0-9_-]+/g, "_");
|
|
195
|
+
const fileName = `${baseName}_${dateStr}.xlsx`;
|
|
196
|
+
XLSX.writeFile(workbook, fileName);
|
|
197
|
+
}
|
|
198
|
+
async function parseExcelForCollection(file, collection, existingEntries = []) {
|
|
199
|
+
const data = await file.arrayBuffer();
|
|
200
|
+
const workbook = XLSX.read(data, { type: "array" });
|
|
201
|
+
const firstSheetName = workbook.SheetNames[0];
|
|
202
|
+
if (!firstSheetName) {
|
|
203
|
+
throw new Error("El archivo no contiene ninguna hoja de c\xE1lculo.");
|
|
204
|
+
}
|
|
205
|
+
const worksheet = workbook.Sheets[firstSheetName];
|
|
206
|
+
const rawRows = XLSX.utils.sheet_to_json(worksheet, { defval: "" });
|
|
207
|
+
if (!rawRows.length) {
|
|
208
|
+
return {
|
|
209
|
+
records: [],
|
|
210
|
+
totalRows: 0,
|
|
211
|
+
matchedFields: [],
|
|
212
|
+
unmatchedHeaders: [],
|
|
213
|
+
samplePreview: [],
|
|
214
|
+
errors: ["El archivo no contiene filas con datos."]
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
const headers = Object.keys(rawRows[0] || {});
|
|
218
|
+
const matchedFields = [];
|
|
219
|
+
const unmatchedHeaders = [];
|
|
220
|
+
const headerToFieldMap = /* @__PURE__ */ new Map();
|
|
221
|
+
headers.forEach((header) => {
|
|
222
|
+
const cleanHeader = header.trim().toLowerCase();
|
|
223
|
+
if (cleanHeader === "id" || cleanHeader === "_id" || cleanHeader === "identificador") {
|
|
224
|
+
headerToFieldMap.set(header, "id");
|
|
225
|
+
matchedFields.push({ label: header, fieldId: "id" });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const matched = (collection.fields || []).find((f) => {
|
|
229
|
+
const fieldLabel = (f.label || "").trim().toLowerCase();
|
|
230
|
+
const fieldId = f.id.trim().toLowerCase();
|
|
231
|
+
return fieldLabel === cleanHeader || fieldId === cleanHeader;
|
|
232
|
+
});
|
|
233
|
+
if (matched) {
|
|
234
|
+
headerToFieldMap.set(header, matched);
|
|
235
|
+
matchedFields.push({ label: header, fieldId: matched.id });
|
|
236
|
+
} else {
|
|
237
|
+
unmatchedHeaders.push(header);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
const records = [];
|
|
241
|
+
const errors = [];
|
|
242
|
+
rawRows.forEach((row, idx) => {
|
|
243
|
+
const entry = { id: "" };
|
|
244
|
+
(collection.fields || []).forEach((f) => {
|
|
245
|
+
if (f.defaultValue !== void 0) {
|
|
246
|
+
entry[f.id] = f.defaultValue;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
headers.forEach((header) => {
|
|
250
|
+
const mapping = headerToFieldMap.get(header);
|
|
251
|
+
const rawVal = row[header];
|
|
252
|
+
if (rawVal === void 0 || rawVal === "") return;
|
|
253
|
+
if (mapping === "id") {
|
|
254
|
+
entry.id = String(rawVal).trim();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (!mapping) return;
|
|
258
|
+
const field = mapping;
|
|
259
|
+
if (field.type === "number") {
|
|
260
|
+
const num = Number(String(rawVal).replace(/[^0-9.-]/g, ""));
|
|
261
|
+
entry[field.id] = isNaN(num) ? rawVal : num;
|
|
262
|
+
} else if (field.type === "boolean") {
|
|
263
|
+
const str = String(rawVal).trim().toLowerCase();
|
|
264
|
+
entry[field.id] = str === "true" || str === "si" || str === "s\xED" || str === "yes" || str === "1" || str === "verdadero";
|
|
265
|
+
} else if (field.multiple || field.type === "list") {
|
|
266
|
+
if (typeof rawVal === "string") {
|
|
267
|
+
entry[field.id] = rawVal.split(/[,;\n]/).map((s) => s.trim()).filter(Boolean);
|
|
268
|
+
} else if (Array.isArray(rawVal)) {
|
|
269
|
+
entry[field.id] = rawVal;
|
|
270
|
+
} else {
|
|
271
|
+
entry[field.id] = [String(rawVal)];
|
|
272
|
+
}
|
|
273
|
+
} else if (typeof rawVal === "string" && (rawVal.startsWith("{") || rawVal.startsWith("["))) {
|
|
274
|
+
try {
|
|
275
|
+
entry[field.id] = JSON.parse(rawVal);
|
|
276
|
+
} catch {
|
|
277
|
+
entry[field.id] = rawVal;
|
|
278
|
+
}
|
|
279
|
+
} else {
|
|
280
|
+
entry[field.id] = rawVal;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
if (!entry.id) {
|
|
284
|
+
entry.id = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `item_${Date.now()}_${idx}`;
|
|
285
|
+
}
|
|
286
|
+
records.push(entry);
|
|
287
|
+
});
|
|
288
|
+
let existingCount = 0;
|
|
289
|
+
let newCount = 0;
|
|
290
|
+
records.forEach((rec) => {
|
|
291
|
+
const existing = findExistingEntry(rec, existingEntries, collection);
|
|
292
|
+
if (existing) {
|
|
293
|
+
existingCount++;
|
|
294
|
+
} else {
|
|
295
|
+
newCount++;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
return {
|
|
299
|
+
records,
|
|
300
|
+
totalRows: records.length,
|
|
301
|
+
matchedFields,
|
|
302
|
+
unmatchedHeaders,
|
|
303
|
+
samplePreview: records.slice(0, 5),
|
|
304
|
+
existingRecordsCount: existingCount,
|
|
305
|
+
newRecordsCount: newCount,
|
|
306
|
+
errors
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
74
310
|
// src/admin/i18n.ts
|
|
75
311
|
var translations = {
|
|
76
312
|
es: {
|
|
@@ -155,6 +391,29 @@ var translations = {
|
|
|
155
391
|
submissions: "Mensajes y Formularios",
|
|
156
392
|
noSubmissions: "No hay env\xEDos registrados",
|
|
157
393
|
exportCsv: "Exportar CSV",
|
|
394
|
+
exportExcel: "Exportar Excel",
|
|
395
|
+
importExcel: "Importar Excel",
|
|
396
|
+
exportSuccess: "Archivo Excel exportado con \xE9xito.",
|
|
397
|
+
importSuccess: "registros procesados exitosamente.",
|
|
398
|
+
exportModalTitle: "Exportar a Excel",
|
|
399
|
+
exportAllRecords: "Todos los registros",
|
|
400
|
+
exportFilterByDate: "Filtrar por rango de fechas",
|
|
401
|
+
exportDateFieldLabel: "Campo de fecha",
|
|
402
|
+
exportDateRangeLabel: "Rango de fechas",
|
|
403
|
+
exportDownloadBtn: "Descargar Excel",
|
|
404
|
+
exportNoRecordsInRange: "No se encontraron registros en el rango seleccionado.",
|
|
405
|
+
importModalTitle: "Importar datos desde Excel / CSV",
|
|
406
|
+
importModalDesc: "Carga un archivo .xlsx, .xls o .csv para agregar o actualizar registros autom\xE1ticamente.",
|
|
407
|
+
importDropzone: "Haz clic o arrastra un archivo Excel aqu\xED",
|
|
408
|
+
importDropzoneSub: "Formatos compatibles: .xlsx, .xls, .csv. La primera fila debe contener los encabezados.",
|
|
409
|
+
importPreviewTitle: "Vista previa de importaci\xF3n",
|
|
410
|
+
importConfirmBtn: "Importar registros",
|
|
411
|
+
importOverwritesWarning: "Tratamiento de registros ya existentes:",
|
|
412
|
+
importingProgress: "Importando registros...",
|
|
413
|
+
importExistingOmit: "Omitir existentes (no volver a crear ni duplicar)",
|
|
414
|
+
importExistingUpdate: "Actualizar existentes con datos del archivo",
|
|
415
|
+
importExistingDetected: "ya existentes",
|
|
416
|
+
importNewDetected: "nuevos a crear",
|
|
158
417
|
markRead: "Marcar como le\xEDdo",
|
|
159
418
|
settingsTitle: "Ajustes del sitio",
|
|
160
419
|
entries: "registros"
|
|
@@ -241,6 +500,29 @@ var translations = {
|
|
|
241
500
|
submissions: "Form Submissions",
|
|
242
501
|
noSubmissions: "No submissions yet",
|
|
243
502
|
exportCsv: "Export CSV",
|
|
503
|
+
exportExcel: "Export Excel",
|
|
504
|
+
importExcel: "Import Excel",
|
|
505
|
+
exportSuccess: "Excel file exported successfully.",
|
|
506
|
+
importSuccess: "records processed successfully.",
|
|
507
|
+
exportModalTitle: "Export to Excel",
|
|
508
|
+
exportAllRecords: "All records",
|
|
509
|
+
exportFilterByDate: "Filter by date range",
|
|
510
|
+
exportDateFieldLabel: "Date field",
|
|
511
|
+
exportDateRangeLabel: "Date range",
|
|
512
|
+
exportDownloadBtn: "Download Excel",
|
|
513
|
+
exportNoRecordsInRange: "No records found in the selected date range.",
|
|
514
|
+
importModalTitle: "Import data from Excel / CSV",
|
|
515
|
+
importModalDesc: "Upload a .xlsx, .xls or .csv file to automatically create or update records.",
|
|
516
|
+
importDropzone: "Click or drag an Excel file here",
|
|
517
|
+
importDropzoneSub: "Supported formats: .xlsx, .xls, .csv. The first row must contain column headers.",
|
|
518
|
+
importPreviewTitle: "Import Preview",
|
|
519
|
+
importConfirmBtn: "Import records",
|
|
520
|
+
importOverwritesWarning: "Handling of existing records:",
|
|
521
|
+
importingProgress: "Importing records...",
|
|
522
|
+
importExistingOmit: "Skip existing (do not recreate or duplicate)",
|
|
523
|
+
importExistingUpdate: "Update existing with file data",
|
|
524
|
+
importExistingDetected: "existing records",
|
|
525
|
+
importNewDetected: "new to create",
|
|
244
526
|
markRead: "Mark as read",
|
|
245
527
|
settingsTitle: "Site Settings",
|
|
246
528
|
entries: "entries"
|
|
@@ -257,12 +539,13 @@ function getAdminTranslations(locale) {
|
|
|
257
539
|
// src/admin/AdminApp.tsx
|
|
258
540
|
import { CreditCard, BarChart3 } from "lucide-react";
|
|
259
541
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
260
|
-
var AdminI18nContext = React.createContext(
|
|
542
|
+
var AdminI18nContext = React.createContext(
|
|
543
|
+
getAdminTranslations("en")
|
|
544
|
+
);
|
|
261
545
|
function useAdminI18n() {
|
|
262
546
|
return React.useContext(AdminI18nContext);
|
|
263
547
|
}
|
|
264
548
|
var TIME_STORAGE_FORMAT = "h:mm a";
|
|
265
|
-
var TIME_DISPLAY_FORMAT = "h:mm a";
|
|
266
549
|
var TIME_PICKER_THEME = {
|
|
267
550
|
token: {
|
|
268
551
|
borderRadius: 12,
|
|
@@ -288,6 +571,21 @@ var TIME_PICKER_THEME = {
|
|
|
288
571
|
}
|
|
289
572
|
}
|
|
290
573
|
};
|
|
574
|
+
function parseCurrencyInput(value, locale) {
|
|
575
|
+
if (!value) return 0;
|
|
576
|
+
const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
577
|
+
const groupSeparator = parts.find((part) => part.type === "group")?.value;
|
|
578
|
+
const decimalSeparator = parts.find((part) => part.type === "decimal")?.value;
|
|
579
|
+
let normalized = value;
|
|
580
|
+
if (groupSeparator) {
|
|
581
|
+
normalized = normalized.split(groupSeparator).join("");
|
|
582
|
+
}
|
|
583
|
+
if (decimalSeparator && decimalSeparator !== ".") {
|
|
584
|
+
normalized = normalized.split(decimalSeparator).join(".");
|
|
585
|
+
}
|
|
586
|
+
const parsed = Number(normalized.replace(/[^\d.-]/g, ""));
|
|
587
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
588
|
+
}
|
|
291
589
|
function AdminTimeRangePicker(props) {
|
|
292
590
|
return /* @__PURE__ */ jsx(ConfigProvider, { theme: TIME_PICKER_THEME, children: /* @__PURE__ */ jsx(
|
|
293
591
|
TimePicker.RangePicker,
|
|
@@ -311,13 +609,19 @@ function toDayjsTime(value) {
|
|
|
311
609
|
const isPm = match12[3].toLowerCase().startsWith("p");
|
|
312
610
|
if (isPm && h < 12) h += 12;
|
|
313
611
|
if (!isPm && h === 12) h = 0;
|
|
314
|
-
return
|
|
612
|
+
return dayjs2().hour(h).minute(m).second(0).millisecond(0);
|
|
315
613
|
}
|
|
316
614
|
const match24 = /^([01]?\d|2[0-3]):([0-5]\d)$/.exec(str);
|
|
317
615
|
if (match24) {
|
|
318
|
-
return
|
|
616
|
+
return dayjs2().hour(Number(match24[1])).minute(Number(match24[2])).second(0).millisecond(0);
|
|
319
617
|
}
|
|
320
|
-
const parsed =
|
|
618
|
+
const parsed = dayjs2(str, [
|
|
619
|
+
"h:mm a",
|
|
620
|
+
"h:mm A",
|
|
621
|
+
"hh:mm a",
|
|
622
|
+
"hh:mm A",
|
|
623
|
+
"HH:mm"
|
|
624
|
+
]);
|
|
321
625
|
return parsed.isValid() ? parsed : null;
|
|
322
626
|
}
|
|
323
627
|
function toStoredTime(value) {
|
|
@@ -384,7 +688,15 @@ function FilePickerButton({
|
|
|
384
688
|
function AdminApp(props) {
|
|
385
689
|
const content = /* @__PURE__ */ jsx(App, { className: "min-h-screen", children: /* @__PURE__ */ jsx(AdminAppContent, { ...props }) });
|
|
386
690
|
if (props.projectId) {
|
|
387
|
-
return /* @__PURE__ */ jsx(
|
|
691
|
+
return /* @__PURE__ */ jsx(
|
|
692
|
+
SubscriptionProvider,
|
|
693
|
+
{
|
|
694
|
+
apiUrl: props.apiUrl,
|
|
695
|
+
projectId: props.projectId,
|
|
696
|
+
email: props.email,
|
|
697
|
+
children: content
|
|
698
|
+
}
|
|
699
|
+
);
|
|
388
700
|
}
|
|
389
701
|
return content;
|
|
390
702
|
}
|
|
@@ -393,7 +705,9 @@ function AdminAppContent(props) {
|
|
|
393
705
|
const rawLocale = props.locale ?? props.lang ?? ctx.config.locale ?? ctx.config.lang ?? "en";
|
|
394
706
|
const t = useMemo(() => getAdminTranslations(rawLocale), [rawLocale]);
|
|
395
707
|
const hasDashboard = Boolean(props.dashboard);
|
|
396
|
-
const [section, setSection] = useState(
|
|
708
|
+
const [section, setSection] = useState(
|
|
709
|
+
hasDashboard ? "dashboard" : "pages"
|
|
710
|
+
);
|
|
397
711
|
const [authChecking, setAuthChecking] = useState(true);
|
|
398
712
|
const [authenticated, setAuthenticated] = useState(false);
|
|
399
713
|
const hideSettings = props.hideSettings ?? ctx.config.hideSettings ?? false;
|
|
@@ -448,13 +762,27 @@ function AdminAppContent(props) {
|
|
|
448
762
|
daysOverdue > 15 && daysOverdue < 30 && /* @__PURE__ */ jsx("div", { className: "bg-rose-600 text-white px-4 py-2.5 text-center text-sm font-bold shadow-sm z-50", children: "Attention: If you do not settle your balance, your account will be suspended soon." }),
|
|
449
763
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col lg:flex-row flex-1 overflow-hidden relative", children: [
|
|
450
764
|
/* @__PURE__ */ jsx("div", { className: "lg:hidden flex items-center justify-between bg-white/80 backdrop-blur-xl border-b border-slate-200 px-4 py-3 shrink-0 z-20 relative", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
451
|
-
ctx.overrides?.["global-logo"] ? /* @__PURE__ */ jsx(
|
|
765
|
+
ctx.overrides?.["global-logo"] ? /* @__PURE__ */ jsx(
|
|
766
|
+
"img",
|
|
767
|
+
{
|
|
768
|
+
src: String(ctx.overrides["global-logo"]),
|
|
769
|
+
alt: "Logo",
|
|
770
|
+
className: "h-5 w-auto object-contain"
|
|
771
|
+
}
|
|
772
|
+
) : /* @__PURE__ */ jsx("div", { className: "w-2 h-2 rounded-full bg-indigo-500 shadow-[0_0_8px_rgba(99,102,241,0.8)]" }),
|
|
452
773
|
/* @__PURE__ */ jsx("div", { className: "font-bold text-slate-900 tracking-tight", children: "Admin CMS" })
|
|
453
774
|
] }) }),
|
|
454
775
|
/* @__PURE__ */ jsxs("aside", { className: "flex w-full lg:w-64 shrink-0 flex-col border-b lg:border-b-0 lg:border-r border-slate-200 bg-white/80 backdrop-blur-xl shadow-sm z-10 overflow-hidden", children: [
|
|
455
776
|
/* @__PURE__ */ jsxs("div", { className: "hidden lg:block border-b border-slate-200 px-6 py-5 bg-white/50", children: [
|
|
456
777
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mb-1", children: [
|
|
457
|
-
ctx.overrides?.["global-logo"] ? /* @__PURE__ */ jsx(
|
|
778
|
+
ctx.overrides?.["global-logo"] ? /* @__PURE__ */ jsx(
|
|
779
|
+
"img",
|
|
780
|
+
{
|
|
781
|
+
src: String(ctx.overrides["global-logo"]),
|
|
782
|
+
alt: "Logo",
|
|
783
|
+
className: "h-5 w-auto object-contain"
|
|
784
|
+
}
|
|
785
|
+
) : /* @__PURE__ */ jsx("div", { className: "w-2 h-2 rounded-full bg-indigo-500 shadow-[0_0_8px_rgba(99,102,241,0.8)]" }),
|
|
458
786
|
/* @__PURE__ */ jsx("div", { className: "text-xs font-bold uppercase tracking-widest text-slate-500", children: "Admin CMS" })
|
|
459
787
|
] }),
|
|
460
788
|
/* @__PURE__ */ jsx("div", { className: "truncate font-bold text-lg text-slate-900", children: ctx.config.siteName ?? "Site Administration" })
|
|
@@ -591,7 +919,9 @@ function AdminAppContent(props) {
|
|
|
591
919
|
});
|
|
592
920
|
} else {
|
|
593
921
|
const topCustom = (props.customSections || []).filter((cs) => cs.position === "top").map((cs) => cs.id);
|
|
594
|
-
const bottomCustom = (props.customSections || []).filter(
|
|
922
|
+
const bottomCustom = (props.customSections || []).filter(
|
|
923
|
+
(cs) => cs.position === "bottom" || cs.position === "after-collections"
|
|
924
|
+
).map((cs) => cs.id);
|
|
595
925
|
const otherCustom = (props.customSections || []).filter(
|
|
596
926
|
(cs) => cs.position !== "top" && cs.position !== "bottom" && cs.position !== "after-collections"
|
|
597
927
|
).map((cs) => cs.id);
|
|
@@ -612,7 +942,9 @@ function AdminAppContent(props) {
|
|
|
612
942
|
"button",
|
|
613
943
|
{
|
|
614
944
|
onClick: async () => {
|
|
615
|
-
await fetch("/api/admin/auth?action=logout", {
|
|
945
|
+
await fetch("/api/admin/auth?action=logout", {
|
|
946
|
+
method: "POST"
|
|
947
|
+
});
|
|
616
948
|
window.location.href = "/admin/login";
|
|
617
949
|
},
|
|
618
950
|
className: "flex items-center justify-center gap-2 w-full px-3 py-2 text-sm font-medium text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors",
|
|
@@ -699,16 +1031,22 @@ function PageListItem({
|
|
|
699
1031
|
] })
|
|
700
1032
|
}
|
|
701
1033
|
) }),
|
|
702
|
-
hasChildren && expanded && /* @__PURE__ */ jsx(
|
|
703
|
-
|
|
1034
|
+
hasChildren && expanded && /* @__PURE__ */ jsx(
|
|
1035
|
+
"ul",
|
|
704
1036
|
{
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
1037
|
+
className: `mt-1 space-y-1 ${depth === 0 ? "ml-4 border-l-2 border-slate-100 pl-1" : "ml-2"}`,
|
|
1038
|
+
children: p.children.map((child) => /* @__PURE__ */ jsx(
|
|
1039
|
+
PageListItem,
|
|
1040
|
+
{
|
|
1041
|
+
p: child,
|
|
1042
|
+
selected,
|
|
1043
|
+
onSelect,
|
|
1044
|
+
depth: depth + 1
|
|
1045
|
+
},
|
|
1046
|
+
child.id
|
|
1047
|
+
))
|
|
1048
|
+
}
|
|
1049
|
+
)
|
|
712
1050
|
] });
|
|
713
1051
|
}
|
|
714
1052
|
function PagesSection() {
|
|
@@ -743,14 +1081,20 @@ function PagesSection() {
|
|
|
743
1081
|
) : /* @__PURE__ */ jsx("div", { className: "grid h-full place-items-center text-sm text-slate-500", children: "Select a page to edit its content." }) })
|
|
744
1082
|
] });
|
|
745
1083
|
}
|
|
746
|
-
function PageEditor({
|
|
1084
|
+
function PageEditor({
|
|
1085
|
+
page,
|
|
1086
|
+
showList,
|
|
1087
|
+
onToggleList
|
|
1088
|
+
}) {
|
|
747
1089
|
const ctx = useCmsContext();
|
|
748
1090
|
const t = useAdminI18n();
|
|
749
1091
|
const iframeRef = useRef(null);
|
|
750
1092
|
const [registered, setRegistered] = useState([]);
|
|
751
1093
|
const [selectedId, setSelectedId] = useState(null);
|
|
752
1094
|
const [preview, setPreview] = useState(false);
|
|
753
|
-
const [drawerState, setDrawerState] = useState(
|
|
1095
|
+
const [drawerState, setDrawerState] = useState(
|
|
1096
|
+
"half"
|
|
1097
|
+
);
|
|
754
1098
|
const src = useMemo(
|
|
755
1099
|
() => `${page.path}${preview ? "" : "?__cms=edit"}`,
|
|
756
1100
|
[page.path, preview]
|
|
@@ -769,7 +1113,11 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
769
1113
|
}
|
|
770
1114
|
} else if (d.type === "cms:ready") {
|
|
771
1115
|
iframeRef.current?.contentWindow?.postMessage(
|
|
772
|
-
{
|
|
1116
|
+
{
|
|
1117
|
+
__cms: true,
|
|
1118
|
+
type: "cms:set-all-overrides",
|
|
1119
|
+
overrides: ctx.overrides
|
|
1120
|
+
},
|
|
773
1121
|
"*"
|
|
774
1122
|
);
|
|
775
1123
|
}
|
|
@@ -792,20 +1140,54 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
792
1140
|
[ctx]
|
|
793
1141
|
);
|
|
794
1142
|
const selectedMeta = registered.find((r) => r.id === selectedId) ?? null;
|
|
795
|
-
const [viewMode, setViewMode] = useState(
|
|
1143
|
+
const [viewMode, setViewMode] = useState(
|
|
1144
|
+
"desktop"
|
|
1145
|
+
);
|
|
796
1146
|
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col", children: [
|
|
797
1147
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 border-b border-slate-200 bg-white/80 backdrop-blur px-4 py-3 shadow-sm z-10 shrink-0", children: [
|
|
798
1148
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm shrink-0", children: [
|
|
799
|
-
/* @__PURE__ */ jsx(
|
|
1149
|
+
/* @__PURE__ */ jsx(
|
|
1150
|
+
"button",
|
|
1151
|
+
{
|
|
1152
|
+
onClick: onToggleList,
|
|
1153
|
+
className: "text-slate-400 hover:text-slate-700 p-1 hidden lg:block",
|
|
1154
|
+
title: "Toggle Pages Menu",
|
|
1155
|
+
children: showList ? /* @__PURE__ */ jsx(PanelLeftClose, { className: "w-5 h-5" }) : /* @__PURE__ */ jsx(PanelLeftOpen, { className: "w-5 h-5" })
|
|
1156
|
+
}
|
|
1157
|
+
),
|
|
800
1158
|
/* @__PURE__ */ jsx("span", { className: "font-bold text-slate-800 text-sm md:text-base", children: page.name }),
|
|
801
1159
|
/* @__PURE__ */ jsx("span", { className: "text-slate-300 hidden sm:inline", children: "|" }),
|
|
802
1160
|
/* @__PURE__ */ jsx("span", { className: "text-slate-500 font-mono text-[10px] md:text-xs bg-slate-100 px-2 py-1 rounded hidden sm:inline-block", children: page.path })
|
|
803
1161
|
] }),
|
|
804
1162
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 overflow-x-auto w-full sm:w-auto pb-1 sm:pb-0 hide-scrollbar shrink-0", children: [
|
|
805
1163
|
/* @__PURE__ */ jsxs("div", { className: "flex bg-slate-100/80 p-0.5 rounded-lg mr-2 shrink-0", children: [
|
|
806
|
-
/* @__PURE__ */ jsx(
|
|
807
|
-
|
|
808
|
-
|
|
1164
|
+
/* @__PURE__ */ jsx(
|
|
1165
|
+
"button",
|
|
1166
|
+
{
|
|
1167
|
+
onClick: () => setViewMode("desktop"),
|
|
1168
|
+
className: `p-1.5 rounded-md transition-all ${viewMode === "desktop" ? "bg-white shadow-sm text-indigo-600" : "text-slate-500 hover:text-slate-800"}`,
|
|
1169
|
+
title: "Desktop View",
|
|
1170
|
+
children: /* @__PURE__ */ jsx(Monitor, { className: "w-4 h-4" })
|
|
1171
|
+
}
|
|
1172
|
+
),
|
|
1173
|
+
/* @__PURE__ */ jsx(
|
|
1174
|
+
"button",
|
|
1175
|
+
{
|
|
1176
|
+
onClick: () => setViewMode("tablet"),
|
|
1177
|
+
className: `p-1.5 rounded-md transition-all ${viewMode === "tablet" ? "bg-white shadow-sm text-indigo-600" : "text-slate-500 hover:text-slate-800"}`,
|
|
1178
|
+
title: "Tablet View",
|
|
1179
|
+
children: /* @__PURE__ */ jsx(Tablet, { className: "w-4 h-4" })
|
|
1180
|
+
}
|
|
1181
|
+
),
|
|
1182
|
+
/* @__PURE__ */ jsx(
|
|
1183
|
+
"button",
|
|
1184
|
+
{
|
|
1185
|
+
onClick: () => setViewMode("mobile"),
|
|
1186
|
+
className: `p-1.5 rounded-md transition-all ${viewMode === "mobile" ? "bg-white shadow-sm text-indigo-600" : "text-slate-500 hover:text-slate-800"}`,
|
|
1187
|
+
title: "Mobile View",
|
|
1188
|
+
children: /* @__PURE__ */ jsx(Smartphone, { className: "w-4 h-4" })
|
|
1189
|
+
}
|
|
1190
|
+
)
|
|
809
1191
|
] }),
|
|
810
1192
|
/* @__PURE__ */ jsxs(
|
|
811
1193
|
"button",
|
|
@@ -858,100 +1240,133 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
858
1240
|
] })
|
|
859
1241
|
] }),
|
|
860
1242
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col sm:flex-row flex-1 overflow-hidden", children: [
|
|
861
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden bg-slate-100/80 p-2 sm:p-4 flex flex-col items-center", children: /* @__PURE__ */ jsx(
|
|
862
|
-
"
|
|
1243
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden bg-slate-100/80 p-2 sm:p-4 flex flex-col items-center", children: /* @__PURE__ */ jsx(
|
|
1244
|
+
"div",
|
|
863
1245
|
{
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
className: "h-full w-full bg-white",
|
|
868
|
-
allow: "autoplay; encrypted-media; fullscreen"
|
|
869
|
-
},
|
|
870
|
-
src
|
|
871
|
-
) }) }),
|
|
872
|
-
/* @__PURE__ */ jsxs("aside", { className: `w-full sm:w-[320px] lg:w-[360px] shrink-0 overflow-y-auto border-t sm:border-t-0 sm:border-l border-slate-200 bg-white shadow-[-4px_0_15px_-3px_rgba(0,0,0,0.05)] z-10 hide-scrollbar transition-all duration-300 ${drawerState === "min" ? "max-h-[52px] sm:max-h-none" : drawerState === "full" ? "max-h-[85vh] sm:max-h-none" : "max-h-[50vh] sm:max-h-none"}`, children: [
|
|
873
|
-
/* @__PURE__ */ jsxs("div", { className: "sticky top-0 bg-white/90 backdrop-blur border-b border-slate-200 px-5 py-3 md:py-4 z-10 flex items-center justify-between", children: [
|
|
874
|
-
/* @__PURE__ */ jsx("div", { className: "text-xs font-bold uppercase tracking-widest text-slate-500", children: selectedMeta ? "Edit Field" : "Editable Elements" }),
|
|
875
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
876
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 sm:hidden", children: [
|
|
877
|
-
/* @__PURE__ */ jsx(
|
|
878
|
-
"button",
|
|
879
|
-
{
|
|
880
|
-
onClick: () => setDrawerState((prev) => prev === "full" ? "half" : prev === "half" ? "min" : "half"),
|
|
881
|
-
className: "p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded",
|
|
882
|
-
title: "Shrink",
|
|
883
|
-
children: /* @__PURE__ */ jsx(ChevronDown, { className: "w-4 h-4" })
|
|
884
|
-
}
|
|
885
|
-
),
|
|
886
|
-
/* @__PURE__ */ jsx(
|
|
887
|
-
"button",
|
|
888
|
-
{
|
|
889
|
-
onClick: () => setDrawerState((prev) => prev === "min" ? "half" : prev === "half" ? "full" : "half"),
|
|
890
|
-
className: "p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded",
|
|
891
|
-
title: "Expand",
|
|
892
|
-
children: /* @__PURE__ */ jsx(ChevronUp, { className: "w-4 h-4" })
|
|
893
|
-
}
|
|
894
|
-
)
|
|
895
|
-
] }),
|
|
896
|
-
selectedMeta && /* @__PURE__ */ jsx("button", { onClick: () => setSelectedId(null), className: "sm:hidden text-slate-400 hover:text-slate-700 text-xs font-bold uppercase tracking-widest", children: "Close" })
|
|
897
|
-
] })
|
|
898
|
-
] }),
|
|
899
|
-
/* @__PURE__ */ jsxs("div", { className: drawerState === "min" ? "hidden sm:block" : "block", children: [
|
|
900
|
-
!selectedMeta && /* @__PURE__ */ jsx("div", { className: "px-5 mt-1 mb-2", children: /* @__PURE__ */ jsx("p", { className: "text-[10px] md:text-xs text-slate-400", children: "Select an element on the left to edit it." }) }),
|
|
901
|
-
selectedMeta ? /* @__PURE__ */ jsx(
|
|
902
|
-
FieldEditor,
|
|
1246
|
+
className: `flex-1 rounded-xl overflow-hidden border border-slate-200 bg-white shadow-lg ring-1 ring-slate-900/5 min-h-[300px] transition-all duration-300 w-full ${viewMode === "mobile" ? "max-w-[375px]" : viewMode === "tablet" ? "max-w-[768px]" : "w-full"}`,
|
|
1247
|
+
children: /* @__PURE__ */ jsx(
|
|
1248
|
+
"iframe",
|
|
903
1249
|
{
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1250
|
+
ref: iframeRef,
|
|
1251
|
+
src,
|
|
1252
|
+
title: page.name,
|
|
1253
|
+
className: "h-full w-full bg-white",
|
|
1254
|
+
allow: "autoplay; encrypted-media; fullscreen"
|
|
1255
|
+
},
|
|
1256
|
+
src
|
|
1257
|
+
)
|
|
1258
|
+
}
|
|
1259
|
+
) }),
|
|
1260
|
+
/* @__PURE__ */ jsxs(
|
|
1261
|
+
"aside",
|
|
1262
|
+
{
|
|
1263
|
+
className: `w-full sm:w-[320px] lg:w-[360px] shrink-0 overflow-y-auto border-t sm:border-t-0 sm:border-l border-slate-200 bg-white shadow-[-4px_0_15px_-3px_rgba(0,0,0,0.05)] z-10 hide-scrollbar transition-all duration-300 ${drawerState === "min" ? "max-h-[52px] sm:max-h-none" : drawerState === "full" ? "max-h-[85vh] sm:max-h-none" : "max-h-[50vh] sm:max-h-none"}`,
|
|
1264
|
+
children: [
|
|
1265
|
+
/* @__PURE__ */ jsxs("div", { className: "sticky top-0 bg-white/90 backdrop-blur border-b border-slate-200 px-5 py-3 md:py-4 z-10 flex items-center justify-between", children: [
|
|
1266
|
+
/* @__PURE__ */ jsx("div", { className: "text-xs font-bold uppercase tracking-widest text-slate-500", children: selectedMeta ? "Edit Field" : "Editable Elements" }),
|
|
1267
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
1268
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 sm:hidden", children: [
|
|
1269
|
+
/* @__PURE__ */ jsx(
|
|
1270
|
+
"button",
|
|
1271
|
+
{
|
|
1272
|
+
onClick: () => setDrawerState(
|
|
1273
|
+
(prev) => prev === "full" ? "half" : prev === "half" ? "min" : "half"
|
|
1274
|
+
),
|
|
1275
|
+
className: "p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded",
|
|
1276
|
+
title: "Shrink",
|
|
1277
|
+
children: /* @__PURE__ */ jsx(ChevronDown, { className: "w-4 h-4" })
|
|
1278
|
+
}
|
|
1279
|
+
),
|
|
1280
|
+
/* @__PURE__ */ jsx(
|
|
1281
|
+
"button",
|
|
1282
|
+
{
|
|
1283
|
+
onClick: () => setDrawerState(
|
|
1284
|
+
(prev) => prev === "min" ? "half" : prev === "half" ? "full" : "half"
|
|
1285
|
+
),
|
|
1286
|
+
className: "p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded",
|
|
1287
|
+
title: "Expand",
|
|
1288
|
+
children: /* @__PURE__ */ jsx(ChevronUp, { className: "w-4 h-4" })
|
|
1289
|
+
}
|
|
1290
|
+
)
|
|
1291
|
+
] }),
|
|
1292
|
+
selectedMeta && /* @__PURE__ */ jsx(
|
|
1293
|
+
"button",
|
|
910
1294
|
{
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
1295
|
+
onClick: () => setSelectedId(null),
|
|
1296
|
+
className: "sm:hidden text-slate-400 hover:text-slate-700 text-xs font-bold uppercase tracking-widest",
|
|
1297
|
+
children: "Close"
|
|
1298
|
+
}
|
|
1299
|
+
)
|
|
1300
|
+
] })
|
|
1301
|
+
] }),
|
|
1302
|
+
/* @__PURE__ */ jsxs("div", { className: drawerState === "min" ? "hidden sm:block" : "block", children: [
|
|
1303
|
+
!selectedMeta && /* @__PURE__ */ jsx("div", { className: "px-5 mt-1 mb-2", children: /* @__PURE__ */ jsx("p", { className: "text-[10px] md:text-xs text-slate-400", children: "Select an element on the left to edit it." }) }),
|
|
1304
|
+
selectedMeta ? /* @__PURE__ */ jsx(
|
|
1305
|
+
FieldEditor,
|
|
1306
|
+
{
|
|
1307
|
+
meta: selectedMeta,
|
|
1308
|
+
value: ctx.overrides[selectedMeta.id] ?? selectedMeta.defaultValue,
|
|
1309
|
+
onChange: (v) => updateOverride(selectedMeta.id, v),
|
|
1310
|
+
onReset: () => {
|
|
1311
|
+
ctx.reset(selectedMeta.id);
|
|
1312
|
+
iframeRef.current?.contentWindow?.postMessage(
|
|
1313
|
+
{
|
|
1314
|
+
__cms: true,
|
|
1315
|
+
type: "cms:set-override",
|
|
1316
|
+
id: selectedMeta.id,
|
|
1317
|
+
value: selectedMeta.defaultValue
|
|
1318
|
+
},
|
|
1319
|
+
"*"
|
|
1320
|
+
);
|
|
915
1321
|
},
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1322
|
+
onClose: () => setSelectedId(null)
|
|
1323
|
+
}
|
|
1324
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1325
|
+
page.hideable && /* @__PURE__ */ jsxs("div", { className: "px-5 py-4 border-b border-slate-100 bg-slate-50/50", children: [
|
|
1326
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-3", children: [
|
|
1327
|
+
/* @__PURE__ */ jsx(
|
|
1328
|
+
"input",
|
|
1329
|
+
{
|
|
1330
|
+
type: "checkbox",
|
|
1331
|
+
id: `page-visible-toggle-${page.id}`,
|
|
1332
|
+
checked: ctx.overrides[`page-${page.id}-visible`] !== false,
|
|
1333
|
+
onChange: (e) => updateOverride(
|
|
1334
|
+
`page-${page.id}-visible`,
|
|
1335
|
+
e.target.checked
|
|
1336
|
+
),
|
|
1337
|
+
className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-600 focus:ring-offset-0"
|
|
1338
|
+
}
|
|
1339
|
+
),
|
|
1340
|
+
/* @__PURE__ */ jsx(
|
|
1341
|
+
"label",
|
|
1342
|
+
{
|
|
1343
|
+
htmlFor: `page-visible-toggle-${page.id}`,
|
|
1344
|
+
className: "text-sm font-medium text-slate-800 cursor-pointer flex-1",
|
|
1345
|
+
children: "Page is Visible"
|
|
1346
|
+
}
|
|
1347
|
+
)
|
|
1348
|
+
] }),
|
|
1349
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] text-slate-500 mt-1.5 pl-8", children: "If unchecked, this page will be hidden from navigation and URL access." })
|
|
1350
|
+
] }),
|
|
924
1351
|
/* @__PURE__ */ jsx(
|
|
925
|
-
|
|
1352
|
+
SectionAccordion,
|
|
926
1353
|
{
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
1354
|
+
registered,
|
|
1355
|
+
onSelect: (id) => {
|
|
1356
|
+
setSelectedId(id);
|
|
1357
|
+
setDrawerState((prev) => prev === "min" ? "half" : prev);
|
|
1358
|
+
iframeRef.current?.contentWindow?.postMessage(
|
|
1359
|
+
{ __cms: true, type: "cms:select", id },
|
|
1360
|
+
"*"
|
|
1361
|
+
);
|
|
1362
|
+
}
|
|
932
1363
|
}
|
|
933
|
-
)
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
SectionAccordion,
|
|
940
|
-
{
|
|
941
|
-
registered,
|
|
942
|
-
onSelect: (id) => {
|
|
943
|
-
setSelectedId(id);
|
|
944
|
-
setDrawerState((prev) => prev === "min" ? "half" : prev);
|
|
945
|
-
iframeRef.current?.contentWindow?.postMessage(
|
|
946
|
-
{ __cms: true, type: "cms:select", id },
|
|
947
|
-
"*"
|
|
948
|
-
);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
)
|
|
952
|
-
] })
|
|
953
|
-
] })
|
|
954
|
-
] })
|
|
1364
|
+
)
|
|
1365
|
+
] })
|
|
1366
|
+
] })
|
|
1367
|
+
]
|
|
1368
|
+
}
|
|
1369
|
+
)
|
|
955
1370
|
] })
|
|
956
1371
|
] });
|
|
957
1372
|
}
|
|
@@ -980,37 +1395,54 @@ function SectionAccordion({
|
|
|
980
1395
|
sectionNames.map((sectionName) => {
|
|
981
1396
|
const isOpen = expanded[sectionName] ?? false;
|
|
982
1397
|
const fields = groups[sectionName];
|
|
983
|
-
return /* @__PURE__ */ jsxs(
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1398
|
+
return /* @__PURE__ */ jsxs(
|
|
1399
|
+
"div",
|
|
1400
|
+
{
|
|
1401
|
+
className: "rounded-lg border border-slate-200 overflow-hidden",
|
|
1402
|
+
children: [
|
|
1403
|
+
/* @__PURE__ */ jsxs(
|
|
1404
|
+
"button",
|
|
1405
|
+
{
|
|
1406
|
+
onClick: () => toggle(sectionName),
|
|
1407
|
+
className: "flex w-full items-center justify-between px-3 py-2.5 bg-slate-50/80 hover:bg-slate-100 transition-colors text-left",
|
|
1408
|
+
children: [
|
|
1409
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
1410
|
+
/* @__PURE__ */ jsx("span", { className: "font-semibold text-sm text-slate-800", children: sectionName }),
|
|
1411
|
+
/* @__PURE__ */ jsx("span", { className: "text-[10px] font-mono text-slate-400 bg-slate-200/70 px-1.5 py-0.5 rounded-full", children: fields.length })
|
|
1412
|
+
] }),
|
|
1413
|
+
/* @__PURE__ */ jsx(
|
|
1414
|
+
"svg",
|
|
1415
|
+
{
|
|
1416
|
+
className: `h-4 w-4 text-slate-400 transition-transform duration-200 ${isOpen ? "rotate-180" : ""}`,
|
|
1417
|
+
fill: "none",
|
|
1418
|
+
viewBox: "0 0 24 24",
|
|
1419
|
+
stroke: "currentColor",
|
|
1420
|
+
strokeWidth: 2,
|
|
1421
|
+
children: /* @__PURE__ */ jsx(
|
|
1422
|
+
"path",
|
|
1423
|
+
{
|
|
1424
|
+
strokeLinecap: "round",
|
|
1425
|
+
strokeLinejoin: "round",
|
|
1426
|
+
d: "M19 9l-7 7-7-7"
|
|
1427
|
+
}
|
|
1428
|
+
)
|
|
1429
|
+
}
|
|
1430
|
+
)
|
|
1431
|
+
]
|
|
1432
|
+
}
|
|
1433
|
+
),
|
|
1434
|
+
isOpen && /* @__PURE__ */ jsx("ul", { className: "divide-y divide-slate-100 bg-white", children: fields.map((m) => /* @__PURE__ */ jsx(FieldListItem, { meta: m, onSelect }, m.id)) })
|
|
1435
|
+
]
|
|
1436
|
+
},
|
|
1437
|
+
sectionName
|
|
1438
|
+
);
|
|
1010
1439
|
})
|
|
1011
1440
|
] });
|
|
1012
1441
|
}
|
|
1013
|
-
function FieldListItem({
|
|
1442
|
+
function FieldListItem({
|
|
1443
|
+
meta,
|
|
1444
|
+
onSelect
|
|
1445
|
+
}) {
|
|
1014
1446
|
return /* @__PURE__ */ jsx("li", { className: "p-1 list-none", children: /* @__PURE__ */ jsxs(
|
|
1015
1447
|
"button",
|
|
1016
1448
|
{
|
|
@@ -1032,9 +1464,15 @@ function FieldListItem({ meta, onSelect }) {
|
|
|
1032
1464
|
}
|
|
1033
1465
|
) });
|
|
1034
1466
|
}
|
|
1035
|
-
function SidebarReferenceSelect({
|
|
1467
|
+
function SidebarReferenceSelect({
|
|
1468
|
+
meta,
|
|
1469
|
+
value,
|
|
1470
|
+
onChange
|
|
1471
|
+
}) {
|
|
1036
1472
|
const ctx = useCmsContext();
|
|
1037
|
-
const collection = ctx.config.collections?.find(
|
|
1473
|
+
const collection = ctx.config.collections?.find(
|
|
1474
|
+
(c) => c.id === meta.collection
|
|
1475
|
+
);
|
|
1038
1476
|
const [items, setItems] = useState([]);
|
|
1039
1477
|
const [search, setSearch] = useState("");
|
|
1040
1478
|
const [loading, setLoading] = useState(true);
|
|
@@ -1060,7 +1498,9 @@ function SidebarReferenceSelect({ meta, value, onChange }) {
|
|
|
1060
1498
|
}
|
|
1061
1499
|
};
|
|
1062
1500
|
const imgField = collection?.fields.find((f) => f.type === "image");
|
|
1063
|
-
const txtField = collection?.fields.find(
|
|
1501
|
+
const txtField = collection?.fields.find(
|
|
1502
|
+
(f) => f.type === "text" || f.type === "textarea" || f.type === "richtext"
|
|
1503
|
+
);
|
|
1064
1504
|
const filtered = items.filter((it) => {
|
|
1065
1505
|
if (!search) return true;
|
|
1066
1506
|
const q = search.toLowerCase();
|
|
@@ -1088,8 +1528,21 @@ function SidebarReferenceSelect({ meta, value, onChange }) {
|
|
|
1088
1528
|
onClick: () => toggle(it.id),
|
|
1089
1529
|
className: `flex items-center gap-3 p-2 rounded-xl cursor-pointer border ${isSelected ? "border-indigo-500 bg-indigo-50" : "border-slate-100 bg-slate-50 hover:border-slate-300"}`,
|
|
1090
1530
|
children: [
|
|
1091
|
-
!!imgSrc && /* @__PURE__ */ jsx(
|
|
1092
|
-
|
|
1531
|
+
!!imgSrc && /* @__PURE__ */ jsx(
|
|
1532
|
+
"img",
|
|
1533
|
+
{
|
|
1534
|
+
src: Array.isArray(imgSrc) ? String(imgSrc[0]) : String(imgSrc),
|
|
1535
|
+
alt: "",
|
|
1536
|
+
className: "w-10 h-10 rounded-lg object-cover bg-white border border-slate-200"
|
|
1537
|
+
}
|
|
1538
|
+
),
|
|
1539
|
+
/* @__PURE__ */ jsx(
|
|
1540
|
+
"span",
|
|
1541
|
+
{
|
|
1542
|
+
className: `text-sm ${isSelected ? "font-semibold text-indigo-900" : "text-slate-700"}`,
|
|
1543
|
+
children: String(label)
|
|
1544
|
+
}
|
|
1545
|
+
),
|
|
1093
1546
|
isSelected && /* @__PURE__ */ jsx(Check, { className: "w-4 h-4 text-indigo-600 ml-auto" })
|
|
1094
1547
|
]
|
|
1095
1548
|
},
|
|
@@ -1108,7 +1561,9 @@ function FieldEditor({
|
|
|
1108
1561
|
onClose
|
|
1109
1562
|
}) {
|
|
1110
1563
|
const ctx = useCmsContext();
|
|
1111
|
-
const [expandedItems, setExpandedItems] = useState(
|
|
1564
|
+
const [expandedItems, setExpandedItems] = useState(
|
|
1565
|
+
{}
|
|
1566
|
+
);
|
|
1112
1567
|
const [searchQuery, setSearchQuery] = useState("");
|
|
1113
1568
|
const [listDragIdx, setListDragIdx] = useState(null);
|
|
1114
1569
|
const [listDragOverIdx, setListDragOverIdx] = useState(null);
|
|
@@ -1130,7 +1585,14 @@ function FieldEditor({
|
|
|
1130
1585
|
className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-600 focus:ring-offset-0"
|
|
1131
1586
|
}
|
|
1132
1587
|
),
|
|
1133
|
-
/* @__PURE__ */ jsx(
|
|
1588
|
+
/* @__PURE__ */ jsx(
|
|
1589
|
+
"label",
|
|
1590
|
+
{
|
|
1591
|
+
htmlFor: meta.id,
|
|
1592
|
+
className: "text-sm font-medium text-slate-700 cursor-pointer",
|
|
1593
|
+
children: meta.label || "Enabled"
|
|
1594
|
+
}
|
|
1595
|
+
)
|
|
1134
1596
|
] }),
|
|
1135
1597
|
meta.type === "text" && /* @__PURE__ */ jsx(
|
|
1136
1598
|
"input",
|
|
@@ -1352,7 +1814,9 @@ function FieldEditor({
|
|
|
1352
1814
|
] }),
|
|
1353
1815
|
(Array.isArray(value) ? value : []).map((item, idx) => {
|
|
1354
1816
|
if (meta.search && searchQuery) {
|
|
1355
|
-
const title = String(
|
|
1817
|
+
const title = String(
|
|
1818
|
+
item?.title || item?.name || ""
|
|
1819
|
+
).toLowerCase();
|
|
1356
1820
|
if (!title.includes(searchQuery.toLowerCase())) return null;
|
|
1357
1821
|
}
|
|
1358
1822
|
const isExpanded = expandedItems[idx] ?? false;
|
|
@@ -1394,7 +1858,10 @@ function FieldEditor({
|
|
|
1394
1858
|
"div",
|
|
1395
1859
|
{
|
|
1396
1860
|
className: "flex items-center justify-between cursor-pointer py-1 select-none gap-2",
|
|
1397
|
-
onClick: () => setExpandedItems((prev) => ({
|
|
1861
|
+
onClick: () => setExpandedItems((prev) => ({
|
|
1862
|
+
...prev,
|
|
1863
|
+
[idx]: !isExpanded
|
|
1864
|
+
})),
|
|
1398
1865
|
children: [
|
|
1399
1866
|
isReorderable && /* @__PURE__ */ jsxs(
|
|
1400
1867
|
"div",
|
|
@@ -1455,13 +1922,18 @@ function FieldEditor({
|
|
|
1455
1922
|
schemaField.type === "icon" ? /* @__PURE__ */ jsx(
|
|
1456
1923
|
SearchableSelect,
|
|
1457
1924
|
{
|
|
1458
|
-
value: String(
|
|
1925
|
+
value: String(
|
|
1926
|
+
item?.[schemaField.key] ?? (Array.isArray(meta.defaultValue) ? meta.defaultValue[idx]?.[schemaField.key] : "") ?? ""
|
|
1927
|
+
),
|
|
1459
1928
|
options: schemaField.options ?? [],
|
|
1460
1929
|
placeholder: "Search icon...",
|
|
1461
1930
|
iconMap: ctx.iconMap,
|
|
1462
1931
|
onChange: (val) => {
|
|
1463
1932
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1464
|
-
arr[idx] = {
|
|
1933
|
+
arr[idx] = {
|
|
1934
|
+
...arr[idx] || {},
|
|
1935
|
+
[schemaField.key]: val
|
|
1936
|
+
};
|
|
1465
1937
|
onChange(arr);
|
|
1466
1938
|
}
|
|
1467
1939
|
}
|
|
@@ -1469,10 +1941,15 @@ function FieldEditor({
|
|
|
1469
1941
|
"textarea",
|
|
1470
1942
|
{
|
|
1471
1943
|
rows: 3,
|
|
1472
|
-
value: String(
|
|
1944
|
+
value: String(
|
|
1945
|
+
item?.[schemaField.key] ?? ""
|
|
1946
|
+
),
|
|
1473
1947
|
onChange: (e) => {
|
|
1474
1948
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1475
|
-
arr[idx] = {
|
|
1949
|
+
arr[idx] = {
|
|
1950
|
+
...arr[idx] || {},
|
|
1951
|
+
[schemaField.key]: e.target.value
|
|
1952
|
+
};
|
|
1476
1953
|
onChange(arr);
|
|
1477
1954
|
},
|
|
1478
1955
|
className: "w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
|
|
@@ -1485,7 +1962,10 @@ function FieldEditor({
|
|
|
1485
1962
|
checked: !!item?.[schemaField.key],
|
|
1486
1963
|
onChange: (e) => {
|
|
1487
1964
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1488
|
-
arr[idx] = {
|
|
1965
|
+
arr[idx] = {
|
|
1966
|
+
...arr[idx] || {},
|
|
1967
|
+
[schemaField.key]: e.target.checked
|
|
1968
|
+
};
|
|
1489
1969
|
onChange(arr);
|
|
1490
1970
|
},
|
|
1491
1971
|
className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
|
|
@@ -1498,10 +1978,15 @@ function FieldEditor({
|
|
|
1498
1978
|
"input",
|
|
1499
1979
|
{
|
|
1500
1980
|
type: "url",
|
|
1501
|
-
value: String(
|
|
1981
|
+
value: String(
|
|
1982
|
+
item?.[schemaField.key] ?? ""
|
|
1983
|
+
),
|
|
1502
1984
|
onChange: (e) => {
|
|
1503
1985
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1504
|
-
arr[idx] = {
|
|
1986
|
+
arr[idx] = {
|
|
1987
|
+
...arr[idx] || {},
|
|
1988
|
+
[schemaField.key]: e.target.value
|
|
1989
|
+
};
|
|
1505
1990
|
onChange(arr);
|
|
1506
1991
|
},
|
|
1507
1992
|
placeholder: "https://... or upload",
|
|
@@ -1523,7 +2008,10 @@ function FieldEditor({
|
|
|
1523
2008
|
file,
|
|
1524
2009
|
(url) => {
|
|
1525
2010
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1526
|
-
arr[idx] = {
|
|
2011
|
+
arr[idx] = {
|
|
2012
|
+
...arr[idx] || {},
|
|
2013
|
+
[schemaField.key]: url
|
|
2014
|
+
};
|
|
1527
2015
|
onChange(arr);
|
|
1528
2016
|
},
|
|
1529
2017
|
ctx.uploadImage
|
|
@@ -1534,17 +2022,25 @@ function FieldEditor({
|
|
|
1534
2022
|
)
|
|
1535
2023
|
] })
|
|
1536
2024
|
] }),
|
|
1537
|
-
item?.[schemaField.key] ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(
|
|
2025
|
+
item?.[schemaField.key] ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(
|
|
2026
|
+
item?.[schemaField.key]
|
|
2027
|
+
).match(
|
|
2028
|
+
/\.(mp4|webm|ogg|mov)(\?.*)?$/i
|
|
2029
|
+
) || schemaField.type === "video" ? /* @__PURE__ */ jsx(
|
|
1538
2030
|
"video",
|
|
1539
2031
|
{
|
|
1540
|
-
src: String(
|
|
2032
|
+
src: String(
|
|
2033
|
+
item?.[schemaField.key]
|
|
2034
|
+
),
|
|
1541
2035
|
controls: true,
|
|
1542
2036
|
className: "w-full h-auto max-h-32 object-contain rounded-md"
|
|
1543
2037
|
}
|
|
1544
2038
|
) : /* @__PURE__ */ jsx(
|
|
1545
2039
|
"img",
|
|
1546
2040
|
{
|
|
1547
|
-
src: String(
|
|
2041
|
+
src: String(
|
|
2042
|
+
item?.[schemaField.key]
|
|
2043
|
+
),
|
|
1548
2044
|
alt: "",
|
|
1549
2045
|
className: "w-full h-auto max-h-32 object-contain rounded-md"
|
|
1550
2046
|
}
|
|
@@ -1552,10 +2048,15 @@ function FieldEditor({
|
|
|
1552
2048
|
] }) : schemaField.type === "select" ? /* @__PURE__ */ jsx(
|
|
1553
2049
|
"select",
|
|
1554
2050
|
{
|
|
1555
|
-
value: String(
|
|
2051
|
+
value: String(
|
|
2052
|
+
item?.[schemaField.key] ?? ""
|
|
2053
|
+
),
|
|
1556
2054
|
onChange: (e) => {
|
|
1557
2055
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1558
|
-
arr[idx] = {
|
|
2056
|
+
arr[idx] = {
|
|
2057
|
+
...arr[idx] || {},
|
|
2058
|
+
[schemaField.key]: e.target.value
|
|
2059
|
+
};
|
|
1559
2060
|
onChange(arr);
|
|
1560
2061
|
},
|
|
1561
2062
|
className: "w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20 bg-white",
|
|
@@ -1567,7 +2068,10 @@ function FieldEditor({
|
|
|
1567
2068
|
value: item?.[schemaField.key],
|
|
1568
2069
|
onChange: (val) => {
|
|
1569
2070
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1570
|
-
arr[idx] = {
|
|
2071
|
+
arr[idx] = {
|
|
2072
|
+
...arr[idx] || {},
|
|
2073
|
+
[schemaField.key]: val
|
|
2074
|
+
};
|
|
1571
2075
|
onChange(arr);
|
|
1572
2076
|
},
|
|
1573
2077
|
isPrice: schemaField.key.toLowerCase().includes("price") || schemaField.key.toLowerCase().includes("precio"),
|
|
@@ -1577,10 +2081,15 @@ function FieldEditor({
|
|
|
1577
2081
|
"input",
|
|
1578
2082
|
{
|
|
1579
2083
|
type: "text",
|
|
1580
|
-
value: String(
|
|
2084
|
+
value: String(
|
|
2085
|
+
item?.[schemaField.key] ?? ""
|
|
2086
|
+
),
|
|
1581
2087
|
onChange: (e) => {
|
|
1582
2088
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1583
|
-
arr[idx] = {
|
|
2089
|
+
arr[idx] = {
|
|
2090
|
+
...arr[idx] || {},
|
|
2091
|
+
[schemaField.key]: e.target.value
|
|
2092
|
+
};
|
|
1584
2093
|
onChange(arr);
|
|
1585
2094
|
},
|
|
1586
2095
|
className: "w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
|
|
@@ -1652,7 +2161,14 @@ function FieldEditor({
|
|
|
1652
2161
|
}
|
|
1653
2162
|
)
|
|
1654
2163
|
] }),
|
|
1655
|
-
meta.type === "reference" && /* @__PURE__ */ jsx(
|
|
2164
|
+
meta.type === "reference" && /* @__PURE__ */ jsx(
|
|
2165
|
+
SidebarReferenceSelect,
|
|
2166
|
+
{
|
|
2167
|
+
meta,
|
|
2168
|
+
value,
|
|
2169
|
+
onChange
|
|
2170
|
+
}
|
|
2171
|
+
)
|
|
1656
2172
|
] }),
|
|
1657
2173
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between pt-6 mt-6 border-t border-slate-100", children: [
|
|
1658
2174
|
/* @__PURE__ */ jsxs(
|
|
@@ -1692,42 +2208,44 @@ function CollectionsSection() {
|
|
|
1692
2208
|
const list = ctx.config.collections ?? [];
|
|
1693
2209
|
list.filter((c) => !c.isSeparator).forEach((c) => {
|
|
1694
2210
|
ctx.adapter.listEntries(c.id).then((entries) => {
|
|
1695
|
-
setCounts(
|
|
2211
|
+
setCounts(
|
|
2212
|
+
(prev) => prev[c.id] === entries.length ? prev : { ...prev, [c.id]: entries.length }
|
|
2213
|
+
);
|
|
1696
2214
|
});
|
|
1697
2215
|
});
|
|
1698
2216
|
}, [ctx.adapter, colIds, ctx.collectionChangedAt]);
|
|
1699
2217
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col md:flex-row h-full bg-slate-50", children: [
|
|
1700
|
-
/* @__PURE__ */ jsxs("div", { className: "w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-slate-200 bg-white/50 p-4", children: [
|
|
1701
|
-
/* @__PURE__ */ jsx("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Collections" }),
|
|
1702
|
-
/* @__PURE__ */ jsxs("ul", { className: "flex overflow-x-auto gap-
|
|
2218
|
+
/* @__PURE__ */ jsxs("div", { className: "w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-slate-200 bg-white/50 p-2 sm:p-3 md:p-4", children: [
|
|
2219
|
+
/* @__PURE__ */ jsx("div", { className: "hidden md:block mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Collections" }),
|
|
2220
|
+
/* @__PURE__ */ jsxs("ul", { className: "flex items-center md:items-stretch overflow-x-auto gap-1.5 p-1 md:p-0 md:block md:space-x-0 md:space-y-1 md:overflow-visible", children: [
|
|
1703
2221
|
collections.map((c, idx) => {
|
|
1704
2222
|
if (c.isSeparator) {
|
|
1705
2223
|
return /* @__PURE__ */ jsx(
|
|
1706
2224
|
"li",
|
|
1707
2225
|
{
|
|
1708
|
-
className: "my-3 border-t border-slate-200/80 pt-2 px-1 list-none",
|
|
1709
|
-
children: c.name && /* @__PURE__ */ jsx("span", { className: "text-[10px] font-bold uppercase tracking-wider text-slate-400", children: c.name })
|
|
2226
|
+
className: "self-center shrink-0 h-6 w-px bg-slate-200 mx-1 md:h-auto md:w-auto md:mx-0 md:my-3 md:border-t md:border-slate-200/80 md:pt-2 md:px-1 list-none",
|
|
2227
|
+
children: c.name && /* @__PURE__ */ jsx("span", { className: "hidden md:block text-[10px] font-bold uppercase tracking-wider text-slate-400", children: c.name })
|
|
1710
2228
|
},
|
|
1711
2229
|
c.id || `sep-${idx}`
|
|
1712
2230
|
);
|
|
1713
2231
|
}
|
|
1714
|
-
return /* @__PURE__ */ jsx("li", { className: "shrink-0
|
|
2232
|
+
return /* @__PURE__ */ jsx("li", { className: "shrink-0 md:w-full md:min-w-0", children: /* @__PURE__ */ jsxs(
|
|
1715
2233
|
"button",
|
|
1716
2234
|
{
|
|
1717
2235
|
onClick: () => setSelected(c),
|
|
1718
|
-
className: `w-full
|
|
2236
|
+
className: `rounded-xl px-3.5 py-2 md:w-full md:px-3 md:py-2.5 text-left text-xs md:text-sm transition-all duration-200 ${selected?.id === c.id ? "bg-white border border-slate-200/90 shadow-2xs font-semibold" : "text-slate-600 hover:text-slate-900 hover:bg-slate-100/70 border border-transparent"}`,
|
|
1719
2237
|
children: [
|
|
1720
2238
|
/* @__PURE__ */ jsx(
|
|
1721
2239
|
"div",
|
|
1722
2240
|
{
|
|
1723
|
-
className: selected?.id === c.id ? "text-slate-900" : "text-slate-700",
|
|
2241
|
+
className: selected?.id === c.id ? "text-slate-900 font-bold" : "text-slate-700 font-medium",
|
|
1724
2242
|
children: c.name
|
|
1725
2243
|
}
|
|
1726
2244
|
),
|
|
1727
2245
|
/* @__PURE__ */ jsxs(
|
|
1728
2246
|
"div",
|
|
1729
2247
|
{
|
|
1730
|
-
className: `text-xs mt-0.5 ${selected?.id === c.id ? "text-indigo-
|
|
2248
|
+
className: `text-[10px] md:text-xs mt-0.5 ${selected?.id === c.id ? "text-indigo-600 font-medium" : "text-slate-400"}`,
|
|
1731
2249
|
children: [
|
|
1732
2250
|
counts[c.id] ?? 0,
|
|
1733
2251
|
" items"
|
|
@@ -1741,7 +2259,7 @@ function CollectionsSection() {
|
|
|
1741
2259
|
collections.length === 0 && /* @__PURE__ */ jsx("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200", children: "No collections registered." })
|
|
1742
2260
|
] })
|
|
1743
2261
|
] }),
|
|
1744
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-auto p-4 md:p-8 relative", children: [
|
|
2262
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-auto p-2 sm:p-4 md:p-8 relative", children: [
|
|
1745
2263
|
/* @__PURE__ */ jsx("div", { className: "absolute inset-0 bg-grid-slate-100 [mask-image:linear-gradient(0deg,white,rgba(255,255,255,0.6))] -z-10 pointer-events-none" }),
|
|
1746
2264
|
selected ? /* @__PURE__ */ jsx(CollectionEditor, { collection: selected }, selected.id) : /* @__PURE__ */ jsx("div", { className: "grid h-full place-items-center text-sm text-slate-500", children: "Select a collection to manage its entries." })
|
|
1747
2265
|
] })
|
|
@@ -1751,12 +2269,32 @@ function CollectionEditor({ collection }) {
|
|
|
1751
2269
|
const ctx = useCmsContext();
|
|
1752
2270
|
const t = useAdminI18n();
|
|
1753
2271
|
const { message } = App.useApp();
|
|
2272
|
+
const currencyCode = ctx.config.currency ?? "USD";
|
|
2273
|
+
const currencyLocale = ctx.config.currencyLocale ?? ctx.config.locale ?? "en-US";
|
|
2274
|
+
const currencyFormatter = useMemo(
|
|
2275
|
+
() => new Intl.NumberFormat(currencyLocale, {
|
|
2276
|
+
style: "currency",
|
|
2277
|
+
currency: currencyCode,
|
|
2278
|
+
maximumFractionDigits: 0
|
|
2279
|
+
}),
|
|
2280
|
+
[currencyCode, currencyLocale]
|
|
2281
|
+
);
|
|
1754
2282
|
const [entries, setEntries] = useState([]);
|
|
1755
2283
|
const [editing, setEditing] = useState(null);
|
|
1756
2284
|
const [originalId, setOriginalId] = useState(null);
|
|
1757
2285
|
const [duplicateErrors, setDuplicateErrors] = useState({});
|
|
1758
2286
|
const [isCreatingManual, setIsCreatingManual] = useState(false);
|
|
1759
2287
|
const [isViewingDetail, setIsViewingDetail] = useState(false);
|
|
2288
|
+
const [customViewingRecord, setCustomViewingRecord] = useState(null);
|
|
2289
|
+
const [isCustomEditing, setIsCustomEditing] = useState(false);
|
|
2290
|
+
const [customActiveView, setCustomActiveView] = useState(null);
|
|
2291
|
+
const [isCustomCreating, setIsCustomCreating] = useState(false);
|
|
2292
|
+
useEffect(() => {
|
|
2293
|
+
setCustomViewingRecord(null);
|
|
2294
|
+
setIsCustomEditing(false);
|
|
2295
|
+
setCustomActiveView(null);
|
|
2296
|
+
setIsCustomCreating(false);
|
|
2297
|
+
}, [collection.id]);
|
|
1760
2298
|
const [saving, setSaving] = useState(false);
|
|
1761
2299
|
const [deletingId, setDeletingId] = useState(null);
|
|
1762
2300
|
const [loadingEntries, setLoadingEntries] = useState(true);
|
|
@@ -1766,11 +2304,57 @@ function CollectionEditor({ collection }) {
|
|
|
1766
2304
|
const [filters, setFilters] = useState({});
|
|
1767
2305
|
const [page, setPage] = useState(1);
|
|
1768
2306
|
const itemsPerPage = 10;
|
|
1769
|
-
const
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
2307
|
+
const dateFields = useMemo(() => {
|
|
2308
|
+
const list = [];
|
|
2309
|
+
(collection.fields || []).forEach((f) => {
|
|
2310
|
+
if (f.type === "date" || f.type === "datetime" || f.id === "fecha" || f.id.toLowerCase().includes("fecha") || f.id.toLowerCase().includes("date")) {
|
|
2311
|
+
list.push({ id: f.id, label: f.label || f.id });
|
|
2312
|
+
}
|
|
2313
|
+
});
|
|
2314
|
+
const hasCreatedAt = entries.some((e) => e._createdAt);
|
|
2315
|
+
if (hasCreatedAt && !list.some((f) => f.id === "_createdAt")) {
|
|
2316
|
+
list.push({ id: "_createdAt", label: "Fecha de creaci\xF3n (_createdAt)" });
|
|
2317
|
+
}
|
|
2318
|
+
return list;
|
|
2319
|
+
}, [collection.fields, entries]);
|
|
2320
|
+
const [isExportModalOpen, setIsExportModalOpen] = useState(false);
|
|
2321
|
+
const [exportMode, setExportMode] = useState("all");
|
|
2322
|
+
const [exportDateField, setExportDateField] = useState("");
|
|
2323
|
+
const [exportDateRange, setExportDateRange] = useState(null);
|
|
2324
|
+
useEffect(() => {
|
|
2325
|
+
if (dateFields.length > 0 && !exportDateField) {
|
|
2326
|
+
setExportDateField(dateFields[0].id);
|
|
2327
|
+
}
|
|
2328
|
+
}, [dateFields, exportDateField]);
|
|
2329
|
+
const exportTargetEntries = useMemo(() => {
|
|
2330
|
+
if (exportMode === "all" || !exportDateField || !exportDateRange || !exportDateRange[0] || !exportDateRange[1]) {
|
|
2331
|
+
return entries;
|
|
2332
|
+
}
|
|
2333
|
+
return filterEntriesByDateRange(
|
|
2334
|
+
entries,
|
|
2335
|
+
exportDateField,
|
|
2336
|
+
exportDateRange[0].format("YYYY-MM-DD"),
|
|
2337
|
+
exportDateRange[1].format("YYYY-MM-DD")
|
|
2338
|
+
);
|
|
2339
|
+
}, [entries, exportMode, exportDateField, exportDateRange]);
|
|
2340
|
+
const [isImportModalOpen, setIsImportModalOpen] = useState(false);
|
|
2341
|
+
const [importFile, setImportFile] = useState(null);
|
|
2342
|
+
const [importResult, setImportResult] = useState(
|
|
2343
|
+
null
|
|
2344
|
+
);
|
|
2345
|
+
const [isParsingImport, setIsParsingImport] = useState(false);
|
|
2346
|
+
const [isImporting, setIsImporting] = useState(false);
|
|
2347
|
+
const [importExistingAction, setImportExistingAction] = useState("omit");
|
|
2348
|
+
const [importProgress, setImportProgress] = useState({
|
|
2349
|
+
current: 0,
|
|
2350
|
+
total: 0
|
|
2351
|
+
});
|
|
2352
|
+
const fileInputRef = useRef(null);
|
|
2353
|
+
const load = useCallback(() => {
|
|
2354
|
+
setLoadingEntries(true);
|
|
2355
|
+
ctx.adapter.listEntries(collection.id).then((res) => {
|
|
2356
|
+
const sorted = [...res].sort((a, b) => {
|
|
2357
|
+
if (collection.defaultSort) {
|
|
1774
2358
|
if (typeof collection.defaultSort === "function") {
|
|
1775
2359
|
return collection.defaultSort(a, b);
|
|
1776
2360
|
}
|
|
@@ -1801,7 +2385,115 @@ function CollectionEditor({ collection }) {
|
|
|
1801
2385
|
useEffect(() => {
|
|
1802
2386
|
load();
|
|
1803
2387
|
}, [load]);
|
|
2388
|
+
const handleOpenExportModal = () => {
|
|
2389
|
+
if (dateFields.length === 0) {
|
|
2390
|
+
try {
|
|
2391
|
+
exportCollectionToExcel(collection, entries);
|
|
2392
|
+
message.success(t.exportSuccess);
|
|
2393
|
+
} catch (err) {
|
|
2394
|
+
console.error("Error exportando a Excel:", err);
|
|
2395
|
+
message.error("No se pudo exportar a Excel.");
|
|
2396
|
+
}
|
|
2397
|
+
return;
|
|
2398
|
+
}
|
|
2399
|
+
setIsExportModalOpen(true);
|
|
2400
|
+
};
|
|
2401
|
+
const handleConfirmExport = () => {
|
|
2402
|
+
try {
|
|
2403
|
+
let suffix = "";
|
|
2404
|
+
if (exportMode === "byDate" && exportDateRange?.[0] && exportDateRange?.[1]) {
|
|
2405
|
+
suffix = `${(collection.name || collection.id).toLowerCase()}_${exportDateRange[0].format("YYYYMMDD")}_al_${exportDateRange[1].format("YYYYMMDD")}`;
|
|
2406
|
+
}
|
|
2407
|
+
exportCollectionToExcel(collection, exportTargetEntries, suffix);
|
|
2408
|
+
message.success(t.exportSuccess);
|
|
2409
|
+
setIsExportModalOpen(false);
|
|
2410
|
+
} catch (err) {
|
|
2411
|
+
console.error("Error exportando a Excel:", err);
|
|
2412
|
+
message.error("No se pudo exportar a Excel.");
|
|
2413
|
+
}
|
|
2414
|
+
};
|
|
2415
|
+
const handleProcessImportFile = async (file) => {
|
|
2416
|
+
setIsParsingImport(true);
|
|
2417
|
+
setImportFile(file);
|
|
2418
|
+
try {
|
|
2419
|
+
const res = await parseExcelForCollection(file, collection, entries);
|
|
2420
|
+
setImportResult(res);
|
|
2421
|
+
if (res.errors.length > 0) {
|
|
2422
|
+
message.warning(res.errors[0]);
|
|
2423
|
+
}
|
|
2424
|
+
} catch (err) {
|
|
2425
|
+
console.error("Error parseando archivo Excel:", err);
|
|
2426
|
+
message.error(err?.message || "Error al leer el archivo Excel.");
|
|
2427
|
+
setImportResult(null);
|
|
2428
|
+
setImportFile(null);
|
|
2429
|
+
} finally {
|
|
2430
|
+
setIsParsingImport(false);
|
|
2431
|
+
}
|
|
2432
|
+
};
|
|
2433
|
+
const handleExecuteImport = async () => {
|
|
2434
|
+
if (!importResult || !importResult.records.length) return;
|
|
2435
|
+
setIsImporting(true);
|
|
2436
|
+
const total = importResult.records.length;
|
|
2437
|
+
setImportProgress({ current: 0, total });
|
|
2438
|
+
try {
|
|
2439
|
+
let createdCount = 0;
|
|
2440
|
+
let updatedCount = 0;
|
|
2441
|
+
let omittedCount = 0;
|
|
2442
|
+
for (let i = 0; i < total; i++) {
|
|
2443
|
+
const item = { ...importResult.records[i] };
|
|
2444
|
+
const existing = findExistingEntry(item, entries, collection);
|
|
2445
|
+
if (existing) {
|
|
2446
|
+
if (importExistingAction === "omit") {
|
|
2447
|
+
omittedCount++;
|
|
2448
|
+
} else {
|
|
2449
|
+
const merged = { ...existing, ...item, id: existing.id };
|
|
2450
|
+
if (existing._id) merged._id = existing._id;
|
|
2451
|
+
await ctx.adapter.putEntry(collection.id, merged);
|
|
2452
|
+
updatedCount++;
|
|
2453
|
+
}
|
|
2454
|
+
} else {
|
|
2455
|
+
await ctx.adapter.putEntry(collection.id, item);
|
|
2456
|
+
createdCount++;
|
|
2457
|
+
}
|
|
2458
|
+
setImportProgress({ current: i + 1, total });
|
|
2459
|
+
}
|
|
2460
|
+
if (createdCount > 0 && omittedCount > 0) {
|
|
2461
|
+
message.success(
|
|
2462
|
+
`Se importaron ${createdCount} registros nuevos. Se omitieron ${omittedCount} registros ya existentes.`
|
|
2463
|
+
);
|
|
2464
|
+
} else if (createdCount > 0 && updatedCount > 0) {
|
|
2465
|
+
message.success(
|
|
2466
|
+
`Se crearon ${createdCount} registros y se actualizaron ${updatedCount} existentes.`
|
|
2467
|
+
);
|
|
2468
|
+
} else if (createdCount > 0) {
|
|
2469
|
+
message.success(
|
|
2470
|
+
`Se importaron ${createdCount} registros exitosamente.`
|
|
2471
|
+
);
|
|
2472
|
+
} else if (omittedCount > 0) {
|
|
2473
|
+
message.info(
|
|
2474
|
+
`Los ${omittedCount} registros ya se encontraban creados. No se duplic\xF3 ning\xFAn dato.`
|
|
2475
|
+
);
|
|
2476
|
+
} else if (updatedCount > 0) {
|
|
2477
|
+
message.success(
|
|
2478
|
+
`Se actualizaron ${updatedCount} registros existentes.`
|
|
2479
|
+
);
|
|
2480
|
+
}
|
|
2481
|
+
load();
|
|
2482
|
+
setIsImportModalOpen(false);
|
|
2483
|
+
setImportResult(null);
|
|
2484
|
+
setImportFile(null);
|
|
2485
|
+
} catch (err) {
|
|
2486
|
+
console.error("Error importando registros:", err);
|
|
2487
|
+
message.error("Ocurri\xF3 un error al guardar los registros importados.");
|
|
2488
|
+
} finally {
|
|
2489
|
+
setIsImporting(false);
|
|
2490
|
+
}
|
|
2491
|
+
};
|
|
1804
2492
|
const startNew = () => {
|
|
2493
|
+
if (collection.customCreateView) {
|
|
2494
|
+
setIsCustomCreating(true);
|
|
2495
|
+
return;
|
|
2496
|
+
}
|
|
1805
2497
|
setIsCreatingManual(true);
|
|
1806
2498
|
setOriginalId(null);
|
|
1807
2499
|
setDuplicateErrors({});
|
|
@@ -1814,17 +2506,6 @@ function CollectionEditor({ collection }) {
|
|
|
1814
2506
|
if (f.endField) base[f.endField] = "";
|
|
1815
2507
|
} else if (f.defaultValue !== void 0) {
|
|
1816
2508
|
base[f.id] = f.defaultValue;
|
|
1817
|
-
} else if (f.type === "branch-settings") {
|
|
1818
|
-
base[f.id] = {
|
|
1819
|
-
allBranches: true,
|
|
1820
|
-
branches: [],
|
|
1821
|
-
useBranchPricing: false,
|
|
1822
|
-
priceBranches: [],
|
|
1823
|
-
prices: {},
|
|
1824
|
-
useBranchDiscounts: false,
|
|
1825
|
-
discountBranches: [],
|
|
1826
|
-
discounts: {}
|
|
1827
|
-
};
|
|
1828
2509
|
} else if (f.multiple) {
|
|
1829
2510
|
base[f.id] = [];
|
|
1830
2511
|
} else {
|
|
@@ -1915,7 +2596,9 @@ function CollectionEditor({ collection }) {
|
|
|
1915
2596
|
}
|
|
1916
2597
|
}
|
|
1917
2598
|
await ctx.adapter.putEntry(collection.id, finalEditing);
|
|
1918
|
-
message.success(
|
|
2599
|
+
message.success(
|
|
2600
|
+
originalId ? "Guardado correctamente" : "Creado correctamente"
|
|
2601
|
+
);
|
|
1919
2602
|
ctx.notifyCollectionChanged();
|
|
1920
2603
|
setEntries((prev) => {
|
|
1921
2604
|
const next = [...prev];
|
|
@@ -1943,7 +2626,9 @@ function CollectionEditor({ collection }) {
|
|
|
1943
2626
|
try {
|
|
1944
2627
|
await ctx.adapter.deleteEntry(collection.id, id);
|
|
1945
2628
|
setEntries(
|
|
1946
|
-
(prev) => prev.filter(
|
|
2629
|
+
(prev) => prev.filter(
|
|
2630
|
+
(e) => String(e.id || "").trim().toLowerCase() !== String(id).trim().toLowerCase()
|
|
2631
|
+
)
|
|
1947
2632
|
);
|
|
1948
2633
|
ctx.notifyCollectionChanged();
|
|
1949
2634
|
load();
|
|
@@ -1986,25 +2671,86 @@ function CollectionEditor({ collection }) {
|
|
|
1986
2671
|
setDraggedIdx(null);
|
|
1987
2672
|
setDragOverIdx(null);
|
|
1988
2673
|
};
|
|
1989
|
-
const visibleFields = collection.tableFields?.length ? collection.tableFields.map((tf) => collection.fields.find((f) => f.id === tf)).filter(Boolean) : collection.fields.filter(
|
|
1990
|
-
|
|
2674
|
+
const visibleFields = collection.tableFields?.length ? collection.tableFields.map((tf) => collection.fields.find((f) => f.id === tf)).filter(Boolean) : collection.fields.filter(
|
|
2675
|
+
(f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden
|
|
2676
|
+
).slice(0, 6);
|
|
2677
|
+
const isCreatingEntry = isCreatingManual || (editing ? !entries.some(
|
|
2678
|
+
(entry) => entry.id && entry.id === editing.id || entry._id && entry._id === (editing._id || editing.id)
|
|
2679
|
+
) : false);
|
|
2680
|
+
if (isCustomCreating && collection.customCreateView) {
|
|
2681
|
+
return /* @__PURE__ */ jsx("div", { className: "w-full", children: collection.customCreateView({
|
|
2682
|
+
onBack: () => setIsCustomCreating(false),
|
|
2683
|
+
reload: () => {
|
|
2684
|
+
load();
|
|
2685
|
+
}
|
|
2686
|
+
}) });
|
|
2687
|
+
}
|
|
2688
|
+
if (customActiveView) {
|
|
2689
|
+
return /* @__PURE__ */ jsx("div", { className: "w-full", children: customActiveView({
|
|
2690
|
+
onBack: () => setCustomActiveView(null),
|
|
2691
|
+
reload: () => {
|
|
2692
|
+
load();
|
|
2693
|
+
}
|
|
2694
|
+
}) });
|
|
2695
|
+
}
|
|
2696
|
+
if (customViewingRecord && (collection.customDetailView || collection.renderCustomDetail || collection.customEditView)) {
|
|
2697
|
+
const renderFn = isCustomEditing && collection.customEditView ? collection.customEditView : collection.customDetailView || collection.renderCustomDetail;
|
|
2698
|
+
if (renderFn) {
|
|
2699
|
+
return /* @__PURE__ */ jsx("div", { className: "w-full", children: renderFn({
|
|
2700
|
+
record: customViewingRecord,
|
|
2701
|
+
isEditing: isCustomEditing,
|
|
2702
|
+
onBack: () => {
|
|
2703
|
+
setCustomViewingRecord(null);
|
|
2704
|
+
setIsCustomEditing(false);
|
|
2705
|
+
},
|
|
2706
|
+
reload: () => {
|
|
2707
|
+
load();
|
|
2708
|
+
}
|
|
2709
|
+
}) });
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
1991
2712
|
return /* @__PURE__ */ jsxs("div", { className: "mx-auto max-w-5xl", children: [
|
|
1992
|
-
/* @__PURE__ */ jsxs("div", { className: "mb-8 flex items-center justify-between", children: [
|
|
2713
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-8 flex flex-col sm:flex-row sm:items-center justify-between gap-4", children: [
|
|
1993
2714
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
1994
2715
|
/* @__PURE__ */ jsx("h2", { className: "text-2xl font-bold text-slate-900 tracking-tight", children: collection.name }),
|
|
1995
2716
|
collection.description && /* @__PURE__ */ jsx("p", { className: "text-sm text-slate-500 mt-1", children: collection.description })
|
|
1996
2717
|
] }),
|
|
1997
|
-
/* @__PURE__ */
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2718
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
2719
|
+
!collection.disableExport && /* @__PURE__ */ jsx(
|
|
2720
|
+
Button,
|
|
2721
|
+
{
|
|
2722
|
+
size: "large",
|
|
2723
|
+
icon: /* @__PURE__ */ jsx(FileDown, { className: "h-4 w-4 text-emerald-600" }),
|
|
2724
|
+
onClick: handleOpenExportModal,
|
|
2725
|
+
disabled: loadingEntries || entries.length === 0,
|
|
2726
|
+
className: "rounded-xl font-medium border-slate-200 hover:border-emerald-500 hover:text-emerald-600 shadow-sm",
|
|
2727
|
+
title: "Descargar registros en formato Excel (soporta filtro por fechas)",
|
|
2728
|
+
children: t.exportExcel
|
|
2729
|
+
}
|
|
2730
|
+
),
|
|
2731
|
+
!collection.disableImport && /* @__PURE__ */ jsx(
|
|
2732
|
+
Button,
|
|
2733
|
+
{
|
|
2734
|
+
size: "large",
|
|
2735
|
+
icon: /* @__PURE__ */ jsx(FileUp, { className: "h-4 w-4 text-sky-600" }),
|
|
2736
|
+
onClick: () => setIsImportModalOpen(true),
|
|
2737
|
+
className: "rounded-xl font-medium border-slate-200 hover:border-sky-500 hover:text-sky-600 shadow-sm",
|
|
2738
|
+
title: "Cargar registros desde un archivo Excel o CSV",
|
|
2739
|
+
children: t.importExcel
|
|
2740
|
+
}
|
|
2741
|
+
),
|
|
2742
|
+
/* @__PURE__ */ jsx(
|
|
2743
|
+
Button,
|
|
2744
|
+
{
|
|
2745
|
+
type: "primary",
|
|
2746
|
+
size: "large",
|
|
2747
|
+
icon: /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
|
|
2748
|
+
onClick: startNew,
|
|
2749
|
+
className: "rounded-xl font-bold shadow-sm",
|
|
2750
|
+
children: t.newEntry
|
|
2751
|
+
}
|
|
2752
|
+
)
|
|
2753
|
+
] })
|
|
2008
2754
|
] }),
|
|
2009
2755
|
!editing && (collection.searchBy?.length || collection.filterBy?.length) && /* @__PURE__ */ jsxs("div", { className: "mb-6 flex flex-wrap gap-4 items-center p-4 bg-white rounded-2xl border border-slate-200 shadow-sm animate-in fade-in slide-in-from-top-2", children: [
|
|
2010
2756
|
collection.searchBy?.length ? /* @__PURE__ */ jsx("div", { className: "relative flex-1 min-w-[220px]", children: /* @__PURE__ */ jsx(
|
|
@@ -2013,7 +2759,9 @@ function CollectionEditor({ collection }) {
|
|
|
2013
2759
|
size: "large",
|
|
2014
2760
|
prefix: /* @__PURE__ */ jsx(Search, { className: "h-4 w-4 text-slate-400" }),
|
|
2015
2761
|
placeholder: `Buscar por ${collection.searchBy.map((s) => {
|
|
2016
|
-
const f = collection.fields.find(
|
|
2762
|
+
const f = collection.fields.find(
|
|
2763
|
+
(field) => field.id === s
|
|
2764
|
+
);
|
|
2017
2765
|
return f?.label ? f.label.toLowerCase() : s;
|
|
2018
2766
|
}).join(", ")}...`,
|
|
2019
2767
|
value: search,
|
|
@@ -2029,7 +2777,15 @@ function CollectionEditor({ collection }) {
|
|
|
2029
2777
|
const fieldDef = collection.fields.find((cf) => cf.id === f);
|
|
2030
2778
|
if (!fieldDef) return null;
|
|
2031
2779
|
if (fieldDef.type === "date") {
|
|
2032
|
-
const dateVal = filters[f] ?
|
|
2780
|
+
const dateVal = filters[f] ? dayjs2(filters[f], [
|
|
2781
|
+
"YYYY/MM/DD",
|
|
2782
|
+
"YYYY-MM-DD",
|
|
2783
|
+
"YYYY-M-D"
|
|
2784
|
+
]).isValid() ? dayjs2(filters[f], [
|
|
2785
|
+
"YYYY/MM/DD",
|
|
2786
|
+
"YYYY-MM-DD",
|
|
2787
|
+
"YYYY-M-D"
|
|
2788
|
+
]) : null : null;
|
|
2033
2789
|
return /* @__PURE__ */ jsx("div", { className: "min-w-[180px]", children: /* @__PURE__ */ jsx(
|
|
2034
2790
|
DatePicker,
|
|
2035
2791
|
{
|
|
@@ -2050,7 +2806,9 @@ function CollectionEditor({ collection }) {
|
|
|
2050
2806
|
const predefinedOptions = (fieldDef.options || []).map(
|
|
2051
2807
|
(opt) => typeof opt === "string" ? { value: opt, label: opt } : opt
|
|
2052
2808
|
);
|
|
2053
|
-
const entryVals = Array.from(
|
|
2809
|
+
const entryVals = Array.from(
|
|
2810
|
+
new Set(entries.map((e) => String(e[f] || "")))
|
|
2811
|
+
).filter(Boolean);
|
|
2054
2812
|
const combinedOptions = [...predefinedOptions];
|
|
2055
2813
|
for (const ev of entryVals) {
|
|
2056
2814
|
if (!combinedOptions.some((o) => o.value === ev)) {
|
|
@@ -2083,7 +2841,13 @@ function CollectionEditor({ collection }) {
|
|
|
2083
2841
|
isViewingDetail ? /* @__PURE__ */ jsx(Eye, { className: "h-4 w-4 text-indigo-600" }) : isCreatingEntry ? /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4 text-indigo-600" }),
|
|
2084
2842
|
isViewingDetail ? `Detalle de ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}${editing?.numero ? ` #${editing.numero}` : ""}` : isCreatingEntry ? collection.createTitle || `Nueva ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}` : `Editar ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}`
|
|
2085
2843
|
] }),
|
|
2086
|
-
isViewingDetail && editing && editing.estado !== void 0 && /* @__PURE__ */ jsx(
|
|
2844
|
+
isViewingDetail && editing && editing.estado !== void 0 && /* @__PURE__ */ jsx(
|
|
2845
|
+
"span",
|
|
2846
|
+
{
|
|
2847
|
+
className: `px-2.5 py-1 text-xs font-semibold rounded-full ${String(editing.estado).toLowerCase().includes("terminad") ? "bg-emerald-50 text-emerald-700 border border-emerald-200" : String(editing.estado).toLowerCase().includes("proceso") ? "bg-sky-50 text-sky-700 border border-sky-200" : String(editing.estado).toLowerCase().includes("cancelad") ? "bg-rose-50 text-rose-700 border border-rose-200" : String(editing.estado).toLowerCase().includes("vencid") ? "bg-rose-50 text-rose-700 border border-rose-200" : "bg-amber-50 text-amber-700 border border-amber-200"}`,
|
|
2848
|
+
children: String(editing.estado)
|
|
2849
|
+
}
|
|
2850
|
+
),
|
|
2087
2851
|
!isViewingDetail && !isCreatingEntry && editing && editing.estado !== void 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2088
2852
|
/* @__PURE__ */ jsx("span", { className: "text-xs text-slate-400 font-medium", children: "Estado:" }),
|
|
2089
2853
|
/* @__PURE__ */ jsx(
|
|
@@ -2138,14 +2902,15 @@ function CollectionEditor({ collection }) {
|
|
|
2138
2902
|
if (f.dependsOn) {
|
|
2139
2903
|
const targetVal = editing[f.dependsOn.field];
|
|
2140
2904
|
if (Array.isArray(f.dependsOn.value)) {
|
|
2141
|
-
if (!f.dependsOn.value.includes(targetVal))
|
|
2905
|
+
if (!f.dependsOn.value.includes(targetVal))
|
|
2906
|
+
return false;
|
|
2142
2907
|
} else if (targetVal !== f.dependsOn.value) {
|
|
2143
2908
|
return false;
|
|
2144
2909
|
}
|
|
2145
2910
|
}
|
|
2146
2911
|
return true;
|
|
2147
2912
|
}).map((f) => {
|
|
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 === "
|
|
2913
|
+
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 === "time-range";
|
|
2149
2914
|
const colSpanClass = isFullWidth ? "lg:col-span-2 col-span-1" : "col-span-1";
|
|
2150
2915
|
if (isViewingDetail) {
|
|
2151
2916
|
return /* @__PURE__ */ jsxs("div", { className: `block ${colSpanClass}`, children: [
|
|
@@ -2165,14 +2930,16 @@ function CollectionEditor({ collection }) {
|
|
|
2165
2930
|
alt: f.label,
|
|
2166
2931
|
className: "h-28 w-auto max-w-full object-contain"
|
|
2167
2932
|
}
|
|
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(
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2933
|
+
) }) : /* @__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(
|
|
2934
|
+
(item, idx) => /* @__PURE__ */ jsx(
|
|
2935
|
+
"span",
|
|
2936
|
+
{
|
|
2937
|
+
className: "rounded-xl bg-slate-100 text-slate-700 px-3 py-1 text-xs font-medium border border-slate-200",
|
|
2938
|
+
children: String(item)
|
|
2939
|
+
},
|
|
2940
|
+
idx
|
|
2941
|
+
)
|
|
2942
|
+
) }) : 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(
|
|
2176
2943
|
"a",
|
|
2177
2944
|
{
|
|
2178
2945
|
href: String(editing[f.id]),
|
|
@@ -2184,14 +2951,21 @@ function CollectionEditor({ collection }) {
|
|
|
2184
2951
|
String(editing[f.id]).includes("maps") ? "Ver en Google Maps" : String(editing[f.id])
|
|
2185
2952
|
]
|
|
2186
2953
|
}
|
|
2187
|
-
) : /* @__PURE__ */ jsx("span", { className: "text-xs text-slate-400 py-1 block", children: "\u2014" }) : f.type === "textarea" ? /* @__PURE__ */ jsx("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2.5 text-sm text-slate-800 whitespace-pre-line leading-relaxed", children: String(editing[f.id] || "\u2014") }) : f.type === "time" || f.id.toLowerCase().includes("hora") || f.id === "inicioServicio" || f.id === "finServicio" ? /* @__PURE__ */ jsx("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2 text-sm text-slate-800 font-medium", children: formatTo12Hour(editing[f.id]) || String(editing[f.id] ?? "\u2014") }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2 text-sm text-slate-800 font-medium", children: String(editing[f.id] ?? "\u2014") })
|
|
2954
|
+
) : /* @__PURE__ */ jsx("span", { className: "text-xs text-slate-400 py-1 block", children: "\u2014" }) : f.type === "textarea" ? /* @__PURE__ */ jsx("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2.5 text-sm text-slate-800 whitespace-pre-line leading-relaxed", children: String(editing[f.id] || "\u2014") }) : f.type === "time" || f.id.toLowerCase().includes("hora") || f.id === "inicioServicio" || f.id === "finServicio" ? /* @__PURE__ */ jsx("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2 text-sm text-slate-800 font-medium", children: formatTo12Hour(editing[f.id]) || String(editing[f.id] ?? "\u2014") }) : f.renderCell ? /* @__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: f.renderCell(editing[f.id], editing) }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2 text-sm text-slate-800 font-medium", children: String(editing[f.id] ?? "\u2014") })
|
|
2188
2955
|
] }, f.id);
|
|
2189
2956
|
}
|
|
2190
2957
|
return /* @__PURE__ */ jsxs("div", { className: `block ${colSpanClass}`, children: [
|
|
2191
2958
|
/* @__PURE__ */ jsxs("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
|
|
2192
2959
|
/* @__PURE__ */ jsxs("span", { children: [
|
|
2193
2960
|
f.label,
|
|
2194
|
-
(f.required || f.unique) && /* @__PURE__ */ jsx(
|
|
2961
|
+
(f.required || f.unique) && /* @__PURE__ */ jsx(
|
|
2962
|
+
"span",
|
|
2963
|
+
{
|
|
2964
|
+
className: "text-rose-500 ml-1 font-bold",
|
|
2965
|
+
title: "Campo obligatorio",
|
|
2966
|
+
children: "*"
|
|
2967
|
+
}
|
|
2968
|
+
)
|
|
2195
2969
|
] }),
|
|
2196
2970
|
/* @__PURE__ */ jsx("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
|
|
2197
2971
|
] }),
|
|
@@ -2202,16 +2976,7 @@ function CollectionEditor({ collection }) {
|
|
|
2202
2976
|
isCreatingEntry,
|
|
2203
2977
|
isViewingDetail: false,
|
|
2204
2978
|
readOnly: false
|
|
2205
|
-
}) : f.type === "
|
|
2206
|
-
BranchSettingsEditor,
|
|
2207
|
-
{
|
|
2208
|
-
collectionId: f.collection || "",
|
|
2209
|
-
value: editing[f.id],
|
|
2210
|
-
globalPrice: Number(editing.price) || 0,
|
|
2211
|
-
globalDiscount: Number(editing.discountPercent) || 0,
|
|
2212
|
-
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2213
|
-
}
|
|
2214
|
-
) : f.type === "boolean" ? /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-3", children: [
|
|
2979
|
+
}) : f.type === "boolean" ? /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-3", children: [
|
|
2215
2980
|
/* @__PURE__ */ jsx(
|
|
2216
2981
|
Switch,
|
|
2217
2982
|
{
|
|
@@ -2229,14 +2994,25 @@ function CollectionEditor({ collection }) {
|
|
|
2229
2994
|
disabled: f.readOnly,
|
|
2230
2995
|
onChange: (val) => setEditing({ ...editing, [f.id]: val ?? 0 }),
|
|
2231
2996
|
className: "w-full rounded-xl",
|
|
2997
|
+
formatter: f.formatter ? (value) => {
|
|
2998
|
+
if (value === void 0 || value === null) {
|
|
2999
|
+
return "";
|
|
3000
|
+
}
|
|
3001
|
+
const numericValue = Number(value);
|
|
3002
|
+
return Number.isFinite(numericValue) ? currencyFormatter.format(numericValue) : "";
|
|
3003
|
+
} : void 0,
|
|
3004
|
+
parser: f.formatter ? (value) => parseCurrencyInput(value, currencyLocale) : void 0,
|
|
2232
3005
|
placeholder: "0"
|
|
2233
3006
|
}
|
|
2234
3007
|
) : f.type === "date" || f.type === "datetime" ? /* @__PURE__ */ jsx(
|
|
2235
3008
|
DatePicker,
|
|
2236
3009
|
{
|
|
2237
3010
|
size: "large",
|
|
2238
|
-
value: editing[f.id] ?
|
|
2239
|
-
onChange: (date, dateString) => setEditing({
|
|
3011
|
+
value: editing[f.id] ? dayjs2(String(editing[f.id])).isValid() ? dayjs2(String(editing[f.id])) : null : null,
|
|
3012
|
+
onChange: (date, dateString) => setEditing({
|
|
3013
|
+
...editing,
|
|
3014
|
+
[f.id]: (Array.isArray(dateString) ? dateString[0] : dateString) || (date ? date.format("YYYY/MM/DD") : "")
|
|
3015
|
+
}),
|
|
2240
3016
|
format: "YYYY/MM/DD",
|
|
2241
3017
|
placeholder: `Seleccionar ${f.label.toLowerCase()}...`,
|
|
2242
3018
|
className: "w-full rounded-xl"
|
|
@@ -2246,21 +3022,36 @@ function CollectionEditor({ collection }) {
|
|
|
2246
3022
|
AdminTimeRangePicker,
|
|
2247
3023
|
{
|
|
2248
3024
|
value: [
|
|
2249
|
-
toDayjsTime(
|
|
2250
|
-
|
|
3025
|
+
toDayjsTime(
|
|
3026
|
+
f.startField ? editing[f.startField] : ""
|
|
3027
|
+
),
|
|
3028
|
+
toDayjsTime(
|
|
3029
|
+
f.endField ? editing[f.endField] : ""
|
|
3030
|
+
)
|
|
2251
3031
|
],
|
|
2252
3032
|
onChange: (times) => setEditing(
|
|
2253
3033
|
(current) => current ? {
|
|
2254
3034
|
...current,
|
|
2255
|
-
...f.startField ? {
|
|
2256
|
-
|
|
3035
|
+
...f.startField ? {
|
|
3036
|
+
[f.startField]: toStoredTime(
|
|
3037
|
+
times?.[0]
|
|
3038
|
+
)
|
|
3039
|
+
} : {},
|
|
3040
|
+
...f.endField ? {
|
|
3041
|
+
[f.endField]: toStoredTime(
|
|
3042
|
+
times?.[1]
|
|
3043
|
+
)
|
|
3044
|
+
} : {}
|
|
2257
3045
|
} : current
|
|
2258
3046
|
),
|
|
2259
3047
|
allowEmpty: [true, true],
|
|
2260
3048
|
className: "w-full",
|
|
2261
3049
|
format: "h:mm a",
|
|
2262
3050
|
order: false,
|
|
2263
|
-
placeholder: [
|
|
3051
|
+
placeholder: [
|
|
3052
|
+
"Hora de inicio",
|
|
3053
|
+
"Hora de cierre"
|
|
3054
|
+
],
|
|
2264
3055
|
use12Hours: true
|
|
2265
3056
|
}
|
|
2266
3057
|
),
|
|
@@ -2284,7 +3075,10 @@ function CollectionEditor({ collection }) {
|
|
|
2284
3075
|
{
|
|
2285
3076
|
size: "large",
|
|
2286
3077
|
value: String(editing[f.id] ?? ""),
|
|
2287
|
-
onChange: (e) => setEditing({
|
|
3078
|
+
onChange: (e) => setEditing({
|
|
3079
|
+
...editing,
|
|
3080
|
+
[f.id]: e.target.value
|
|
3081
|
+
}),
|
|
2288
3082
|
rows: 4,
|
|
2289
3083
|
placeholder: `Escribe ${f.label.toLowerCase()}...`,
|
|
2290
3084
|
className: "w-full rounded-xl font-sans"
|
|
@@ -2304,7 +3098,10 @@ function CollectionEditor({ collection }) {
|
|
|
2304
3098
|
{
|
|
2305
3099
|
size: "large",
|
|
2306
3100
|
value: String(editing[f.id] ?? ""),
|
|
2307
|
-
onChange: (e) => setEditing({
|
|
3101
|
+
onChange: (e) => setEditing({
|
|
3102
|
+
...editing,
|
|
3103
|
+
[f.id]: e.target.value
|
|
3104
|
+
}),
|
|
2308
3105
|
className: "flex-1 rounded-xl"
|
|
2309
3106
|
}
|
|
2310
3107
|
),
|
|
@@ -2314,7 +3111,9 @@ function CollectionEditor({ collection }) {
|
|
|
2314
3111
|
size: "large",
|
|
2315
3112
|
onClick: () => {
|
|
2316
3113
|
const sourceField = f.source || "title";
|
|
2317
|
-
let val = String(
|
|
3114
|
+
let val = String(
|
|
3115
|
+
editing[sourceField] || editing.id || ""
|
|
3116
|
+
);
|
|
2318
3117
|
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
2319
3118
|
setEditing({ ...editing, [f.id]: val });
|
|
2320
3119
|
},
|
|
@@ -2336,7 +3135,12 @@ function CollectionEditor({ collection }) {
|
|
|
2336
3135
|
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2337
3136
|
onSelectRecord: (rec) => {
|
|
2338
3137
|
if (f.onSelectRecord) {
|
|
2339
|
-
setEditing(
|
|
3138
|
+
setEditing(
|
|
3139
|
+
(prev) => prev ? {
|
|
3140
|
+
...prev,
|
|
3141
|
+
...f.onSelectRecord(rec, prev)
|
|
3142
|
+
} : prev
|
|
3143
|
+
);
|
|
2340
3144
|
}
|
|
2341
3145
|
}
|
|
2342
3146
|
}
|
|
@@ -2350,7 +3154,10 @@ function CollectionEditor({ collection }) {
|
|
|
2350
3154
|
placeholder: f.label,
|
|
2351
3155
|
allowClear: true,
|
|
2352
3156
|
onChange: (val) => {
|
|
2353
|
-
const next = {
|
|
3157
|
+
const next = {
|
|
3158
|
+
...editing,
|
|
3159
|
+
[f.id]: val || ""
|
|
3160
|
+
};
|
|
2354
3161
|
collection.fields.forEach((otherField) => {
|
|
2355
3162
|
if (otherField.dependsOnField === f.id && otherField.optionsMap) {
|
|
2356
3163
|
const newOpts = otherField.optionsMap[String(val || "")];
|
|
@@ -2370,25 +3177,56 @@ function CollectionEditor({ collection }) {
|
|
|
2370
3177
|
}
|
|
2371
3178
|
);
|
|
2372
3179
|
})() : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
2373
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map(
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
"button",
|
|
3180
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map(
|
|
3181
|
+
(url, i) => {
|
|
3182
|
+
const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
|
|
3183
|
+
return /* @__PURE__ */ jsxs(
|
|
3184
|
+
"div",
|
|
2379
3185
|
{
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
3186
|
+
className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32",
|
|
3187
|
+
children: [
|
|
3188
|
+
isVideo ? /* @__PURE__ */ jsx(
|
|
3189
|
+
"video",
|
|
3190
|
+
{
|
|
3191
|
+
src: url,
|
|
3192
|
+
className: "w-full h-full object-cover rounded-lg",
|
|
3193
|
+
autoPlay: true,
|
|
3194
|
+
muted: true,
|
|
3195
|
+
loop: true,
|
|
3196
|
+
playsInline: true
|
|
3197
|
+
}
|
|
3198
|
+
) : /* @__PURE__ */ jsx(
|
|
3199
|
+
"img",
|
|
3200
|
+
{
|
|
3201
|
+
src: url,
|
|
3202
|
+
alt: "",
|
|
3203
|
+
className: "w-full h-full object-cover rounded-lg"
|
|
3204
|
+
}
|
|
3205
|
+
),
|
|
3206
|
+
/* @__PURE__ */ jsx(
|
|
3207
|
+
"button",
|
|
3208
|
+
{
|
|
3209
|
+
type: "button",
|
|
3210
|
+
onClick: () => {
|
|
3211
|
+
const arr = [
|
|
3212
|
+
...editing[f.id] || []
|
|
3213
|
+
];
|
|
3214
|
+
arr.splice(i, 1);
|
|
3215
|
+
setEditing({
|
|
3216
|
+
...editing,
|
|
3217
|
+
[f.id]: arr
|
|
3218
|
+
});
|
|
3219
|
+
},
|
|
3220
|
+
className: "absolute top-2 right-2 bg-red-500/80 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500",
|
|
3221
|
+
children: /* @__PURE__ */ jsx(X, { className: "w-3 h-3" })
|
|
3222
|
+
}
|
|
3223
|
+
)
|
|
3224
|
+
]
|
|
3225
|
+
},
|
|
3226
|
+
i
|
|
3227
|
+
);
|
|
3228
|
+
}
|
|
3229
|
+
) }),
|
|
2392
3230
|
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
2393
3231
|
/* @__PURE__ */ jsx(
|
|
2394
3232
|
"input",
|
|
@@ -2398,8 +3236,14 @@ function CollectionEditor({ collection }) {
|
|
|
2398
3236
|
onKeyDown: (e) => {
|
|
2399
3237
|
if (e.key === "Enter" && e.currentTarget.value) {
|
|
2400
3238
|
e.preventDefault();
|
|
2401
|
-
const arr = [
|
|
2402
|
-
|
|
3239
|
+
const arr = [
|
|
3240
|
+
...editing[f.id] || [],
|
|
3241
|
+
e.currentTarget.value
|
|
3242
|
+
];
|
|
3243
|
+
setEditing({
|
|
3244
|
+
...editing,
|
|
3245
|
+
[f.id]: arr
|
|
3246
|
+
});
|
|
2403
3247
|
e.currentTarget.value = "";
|
|
2404
3248
|
}
|
|
2405
3249
|
},
|
|
@@ -2423,7 +3267,10 @@ function CollectionEditor({ collection }) {
|
|
|
2423
3267
|
if (f.max && current.length >= f.max) {
|
|
2424
3268
|
return prev;
|
|
2425
3269
|
}
|
|
2426
|
-
return {
|
|
3270
|
+
return {
|
|
3271
|
+
...prev,
|
|
3272
|
+
[f.id]: [...current, url]
|
|
3273
|
+
};
|
|
2427
3274
|
});
|
|
2428
3275
|
},
|
|
2429
3276
|
ctx.uploadImage
|
|
@@ -2441,7 +3288,10 @@ function CollectionEditor({ collection }) {
|
|
|
2441
3288
|
{
|
|
2442
3289
|
type: "url",
|
|
2443
3290
|
value: String(editing[f.id] ?? ""),
|
|
2444
|
-
onChange: (e) => setEditing({
|
|
3291
|
+
onChange: (e) => setEditing({
|
|
3292
|
+
...editing,
|
|
3293
|
+
[f.id]: e.target.value
|
|
3294
|
+
}),
|
|
2445
3295
|
placeholder: "https://...",
|
|
2446
3296
|
className: "w-full 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"
|
|
2447
3297
|
}
|
|
@@ -2467,7 +3317,9 @@ function CollectionEditor({ collection }) {
|
|
|
2467
3317
|
}
|
|
2468
3318
|
)
|
|
2469
3319
|
] }),
|
|
2470
|
-
editing[f.id] ? /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(editing[f.id]).match(
|
|
3320
|
+
editing[f.id] ? /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(editing[f.id]).match(
|
|
3321
|
+
/\.(mp4|webm|mov|ogg)$/i
|
|
3322
|
+
) || String(editing[f.id]).includes("video") ? /* @__PURE__ */ jsx(
|
|
2471
3323
|
"video",
|
|
2472
3324
|
{
|
|
2473
3325
|
src: String(editing[f.id]),
|
|
@@ -2500,8 +3352,13 @@ function CollectionEditor({ collection }) {
|
|
|
2500
3352
|
"input",
|
|
2501
3353
|
{
|
|
2502
3354
|
type: "color",
|
|
2503
|
-
value: String(editing[f.id] ?? "#000000").startsWith(
|
|
2504
|
-
|
|
3355
|
+
value: String(editing[f.id] ?? "#000000").startsWith(
|
|
3356
|
+
"#"
|
|
3357
|
+
) && String(editing[f.id] ?? "").length === 7 ? String(editing[f.id]) : "#000000",
|
|
3358
|
+
onChange: (e) => setEditing({
|
|
3359
|
+
...editing,
|
|
3360
|
+
[f.id]: e.target.value
|
|
3361
|
+
}),
|
|
2505
3362
|
className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
|
|
2506
3363
|
}
|
|
2507
3364
|
),
|
|
@@ -2510,7 +3367,10 @@ function CollectionEditor({ collection }) {
|
|
|
2510
3367
|
{
|
|
2511
3368
|
type: "text",
|
|
2512
3369
|
value: String(editing[f.id] ?? ""),
|
|
2513
|
-
onChange: (e) => setEditing({
|
|
3370
|
+
onChange: (e) => setEditing({
|
|
3371
|
+
...editing,
|
|
3372
|
+
[f.id]: e.target.value
|
|
3373
|
+
}),
|
|
2514
3374
|
placeholder: "#000000",
|
|
2515
3375
|
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 font-mono shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2516
3376
|
}
|
|
@@ -2519,62 +3379,75 @@ function CollectionEditor({ collection }) {
|
|
|
2519
3379
|
"div",
|
|
2520
3380
|
{
|
|
2521
3381
|
className: "w-8 h-8 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
|
|
2522
|
-
style: {
|
|
3382
|
+
style: {
|
|
3383
|
+
backgroundColor: String(
|
|
3384
|
+
editing[f.id] ?? "#000000"
|
|
3385
|
+
)
|
|
3386
|
+
}
|
|
2523
3387
|
}
|
|
2524
3388
|
)
|
|
2525
3389
|
] }) : f.type === "color" && f.multiple || f.type === "list" && f.id === "colors" ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
2526
3390
|
(Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : []).map((item, idx) => {
|
|
2527
3391
|
const colorVal = String(item ?? "").trim();
|
|
2528
3392
|
const validHex = colorVal.startsWith("#") && (colorVal.length === 4 || colorVal.length === 7) ? colorVal : "#000000";
|
|
2529
|
-
return /* @__PURE__ */ jsxs(
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
3393
|
+
return /* @__PURE__ */ jsxs(
|
|
3394
|
+
"div",
|
|
3395
|
+
{
|
|
3396
|
+
className: "flex gap-2 items-center",
|
|
3397
|
+
children: [
|
|
3398
|
+
/* @__PURE__ */ jsx(
|
|
3399
|
+
"input",
|
|
3400
|
+
{
|
|
3401
|
+
type: "color",
|
|
3402
|
+
value: validHex.length === 7 ? validHex : "#000000",
|
|
3403
|
+
onChange: (e) => {
|
|
3404
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
3405
|
+
arr[idx] = e.target.value;
|
|
3406
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
3407
|
+
},
|
|
3408
|
+
className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
|
|
3409
|
+
}
|
|
3410
|
+
),
|
|
3411
|
+
/* @__PURE__ */ jsx(
|
|
3412
|
+
"input",
|
|
3413
|
+
{
|
|
3414
|
+
type: "text",
|
|
3415
|
+
value: colorVal,
|
|
3416
|
+
onChange: (e) => {
|
|
3417
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
3418
|
+
arr[idx] = e.target.value;
|
|
3419
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
3420
|
+
},
|
|
3421
|
+
placeholder: "#1c2a44",
|
|
3422
|
+
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-800 font-mono shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
3423
|
+
}
|
|
3424
|
+
),
|
|
3425
|
+
/* @__PURE__ */ jsx(
|
|
3426
|
+
"div",
|
|
3427
|
+
{
|
|
3428
|
+
className: "w-7 h-7 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
|
|
3429
|
+
style: {
|
|
3430
|
+
backgroundColor: colorVal || "#000000"
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
),
|
|
3434
|
+
/* @__PURE__ */ jsx(
|
|
3435
|
+
"button",
|
|
3436
|
+
{
|
|
3437
|
+
type: "button",
|
|
3438
|
+
onClick: () => {
|
|
3439
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
3440
|
+
arr.splice(idx, 1);
|
|
3441
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
3442
|
+
},
|
|
3443
|
+
className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
|
|
3444
|
+
children: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" })
|
|
3445
|
+
}
|
|
3446
|
+
)
|
|
3447
|
+
]
|
|
3448
|
+
},
|
|
3449
|
+
idx
|
|
3450
|
+
);
|
|
2578
3451
|
}),
|
|
2579
3452
|
/* @__PURE__ */ jsxs(
|
|
2580
3453
|
"button",
|
|
@@ -2597,50 +3470,69 @@ function CollectionEditor({ collection }) {
|
|
|
2597
3470
|
const displayArr = currentArr.length > 0 ? currentArr : [""];
|
|
2598
3471
|
const singularLabel = f.label.endsWith("es") ? f.label.slice(0, -2) : f.label.endsWith("s") ? f.label.slice(0, -1) : f.label;
|
|
2599
3472
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-2.5", children: [
|
|
2600
|
-
displayArr.map((item, idx) => /* @__PURE__ */ jsxs(
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
3473
|
+
displayArr.map((item, idx) => /* @__PURE__ */ jsxs(
|
|
3474
|
+
"div",
|
|
3475
|
+
{
|
|
3476
|
+
className: "flex gap-2 items-center",
|
|
3477
|
+
children: [
|
|
3478
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs font-mono font-bold text-slate-400 w-7 text-right shrink-0", children: [
|
|
3479
|
+
"#",
|
|
3480
|
+
idx + 1
|
|
3481
|
+
] }),
|
|
3482
|
+
/* @__PURE__ */ jsx(
|
|
3483
|
+
"input",
|
|
3484
|
+
{
|
|
3485
|
+
type: "text",
|
|
3486
|
+
value: String(item ?? ""),
|
|
3487
|
+
placeholder: `${singularLabel} #${idx + 1}...`,
|
|
3488
|
+
onChange: (e) => {
|
|
3489
|
+
const arr = [...displayArr];
|
|
3490
|
+
arr[idx] = e.target.value;
|
|
3491
|
+
setEditing({
|
|
3492
|
+
...editing,
|
|
3493
|
+
[f.id]: arr
|
|
3494
|
+
});
|
|
3495
|
+
},
|
|
3496
|
+
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"
|
|
3497
|
+
}
|
|
3498
|
+
),
|
|
3499
|
+
displayArr.length > 1 && /* @__PURE__ */ jsx(
|
|
3500
|
+
"button",
|
|
3501
|
+
{
|
|
3502
|
+
type: "button",
|
|
3503
|
+
onClick: () => {
|
|
3504
|
+
const arr = displayArr.filter(
|
|
3505
|
+
(_, i) => i !== idx
|
|
3506
|
+
);
|
|
3507
|
+
setEditing({
|
|
3508
|
+
...editing,
|
|
3509
|
+
[f.id]: arr.length > 0 ? arr : [""]
|
|
3510
|
+
});
|
|
3511
|
+
},
|
|
3512
|
+
className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer shrink-0",
|
|
3513
|
+
title: "Eliminar elemento",
|
|
3514
|
+
children: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" })
|
|
3515
|
+
}
|
|
3516
|
+
)
|
|
3517
|
+
]
|
|
3518
|
+
},
|
|
3519
|
+
idx
|
|
3520
|
+
)),
|
|
2633
3521
|
/* @__PURE__ */ jsxs(
|
|
2634
3522
|
"button",
|
|
2635
3523
|
{
|
|
2636
3524
|
type: "button",
|
|
2637
3525
|
onClick: () => {
|
|
2638
|
-
setEditing({
|
|
3526
|
+
setEditing({
|
|
3527
|
+
...editing,
|
|
3528
|
+
[f.id]: [...displayArr, ""]
|
|
3529
|
+
});
|
|
2639
3530
|
},
|
|
2640
3531
|
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
3532
|
children: [
|
|
2642
3533
|
/* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
|
|
2643
|
-
" Agregar
|
|
3534
|
+
" Agregar",
|
|
3535
|
+
" ",
|
|
2644
3536
|
singularLabel.toLowerCase()
|
|
2645
3537
|
]
|
|
2646
3538
|
}
|
|
@@ -2654,7 +3546,10 @@ function CollectionEditor({ collection }) {
|
|
|
2654
3546
|
value: String(editing[f.id] ?? ""),
|
|
2655
3547
|
readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
|
|
2656
3548
|
disabled: f.readOnly,
|
|
2657
|
-
onChange: (e) => setEditing({
|
|
3549
|
+
onChange: (e) => setEditing({
|
|
3550
|
+
...editing,
|
|
3551
|
+
[f.id]: e.target.value
|
|
3552
|
+
}),
|
|
2658
3553
|
placeholder: f.label,
|
|
2659
3554
|
className: "flex-1 rounded-xl"
|
|
2660
3555
|
}
|
|
@@ -2706,8 +3601,13 @@ function CollectionEditor({ collection }) {
|
|
|
2706
3601
|
if (dup) {
|
|
2707
3602
|
const dupName = dup.nombre ? ` (\xAB${dup.nombre} ${dup.apellido || ""}\xBB)` : "";
|
|
2708
3603
|
const errMsg = `Esta identificaci\xF3n ya est\xE1 registrada${dupName}. No puedes usar una c\xE9dula o NIT repetido.`;
|
|
2709
|
-
setDuplicateErrors((prev) => ({
|
|
2710
|
-
|
|
3604
|
+
setDuplicateErrors((prev) => ({
|
|
3605
|
+
...prev,
|
|
3606
|
+
[f.id]: errMsg
|
|
3607
|
+
}));
|
|
3608
|
+
message.warning(
|
|
3609
|
+
`\u26A0\uFE0F Ya existe un registro con esta identificaci\xF3n: ${e.target.value.trim()}.`
|
|
3610
|
+
);
|
|
2711
3611
|
} else {
|
|
2712
3612
|
setDuplicateErrors((prev) => {
|
|
2713
3613
|
const next = { ...prev };
|
|
@@ -2775,38 +3675,385 @@ function CollectionEditor({ collection }) {
|
|
|
2775
3675
|
] }) })
|
|
2776
3676
|
}
|
|
2777
3677
|
),
|
|
2778
|
-
/* @__PURE__ */ jsx(
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
(
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
3678
|
+
/* @__PURE__ */ jsx(
|
|
3679
|
+
Modal,
|
|
3680
|
+
{
|
|
3681
|
+
open: isExportModalOpen,
|
|
3682
|
+
title: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-slate-900 font-bold text-lg", children: [
|
|
3683
|
+
/* @__PURE__ */ jsx(FileDown, { className: "h-5 w-5 text-emerald-600" }),
|
|
3684
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
3685
|
+
t.exportModalTitle,
|
|
3686
|
+
" - ",
|
|
3687
|
+
collection.name
|
|
3688
|
+
] })
|
|
3689
|
+
] }),
|
|
3690
|
+
onCancel: () => setIsExportModalOpen(false),
|
|
3691
|
+
footer: null,
|
|
3692
|
+
centered: true,
|
|
3693
|
+
width: "min(560px, calc(100vw - 32px))",
|
|
3694
|
+
mask: { blur: true },
|
|
3695
|
+
children: /* @__PURE__ */ jsxs("div", { className: "py-2 space-y-4", children: [
|
|
3696
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-slate-500", children: "Descarga los registros en formato Excel estructurado (.xlsx)." }),
|
|
3697
|
+
/* @__PURE__ */ jsx(
|
|
3698
|
+
Segmented,
|
|
3699
|
+
{
|
|
3700
|
+
size: "large",
|
|
3701
|
+
block: true,
|
|
3702
|
+
value: exportMode,
|
|
3703
|
+
onChange: (val) => setExportMode(val),
|
|
3704
|
+
options: [
|
|
3705
|
+
{
|
|
3706
|
+
label: `${t.exportAllRecords} (${entries.length})`,
|
|
3707
|
+
value: "all"
|
|
3708
|
+
},
|
|
3709
|
+
{ label: t.exportFilterByDate, value: "byDate" }
|
|
3710
|
+
]
|
|
3711
|
+
}
|
|
3712
|
+
),
|
|
3713
|
+
exportMode === "byDate" && /* @__PURE__ */ jsxs("div", { className: "p-4 bg-slate-50 border border-slate-200 rounded-xl space-y-3 animate-in fade-in", children: [
|
|
3714
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
3715
|
+
/* @__PURE__ */ jsxs("label", { className: "text-xs font-semibold text-slate-600", children: [
|
|
3716
|
+
t.exportDateRangeLabel,
|
|
3717
|
+
":"
|
|
3718
|
+
] }),
|
|
3719
|
+
/* @__PURE__ */ jsx(
|
|
3720
|
+
DatePicker.RangePicker,
|
|
3721
|
+
{
|
|
3722
|
+
size: "large",
|
|
3723
|
+
className: "w-full rounded-xl",
|
|
3724
|
+
value: exportDateRange,
|
|
3725
|
+
onChange: (dates) => setExportDateRange(dates),
|
|
3726
|
+
presets: [
|
|
3727
|
+
{
|
|
3728
|
+
label: "Hoy",
|
|
3729
|
+
value: [dayjs2().startOf("day"), dayjs2().endOf("day")]
|
|
3730
|
+
},
|
|
3731
|
+
{
|
|
3732
|
+
label: "Esta semana",
|
|
3733
|
+
value: [dayjs2().startOf("week"), dayjs2().endOf("week")]
|
|
3734
|
+
},
|
|
3735
|
+
{
|
|
3736
|
+
label: "Este mes",
|
|
3737
|
+
value: [dayjs2().startOf("month"), dayjs2().endOf("month")]
|
|
3738
|
+
},
|
|
3739
|
+
{
|
|
3740
|
+
label: "\xDAltimos 30 d\xEDas",
|
|
3741
|
+
value: [dayjs2().subtract(30, "day"), dayjs2()]
|
|
3742
|
+
},
|
|
3743
|
+
{
|
|
3744
|
+
label: "Este a\xF1o",
|
|
3745
|
+
value: [dayjs2().startOf("year"), dayjs2().endOf("year")]
|
|
3746
|
+
}
|
|
3747
|
+
]
|
|
3748
|
+
}
|
|
3749
|
+
)
|
|
3750
|
+
] }),
|
|
3751
|
+
/* @__PURE__ */ jsxs("div", { className: "pt-1 flex items-center justify-between text-xs", children: [
|
|
3752
|
+
/* @__PURE__ */ jsx("span", { className: "text-slate-500 font-medium", children: "Registros coincidentes:" }),
|
|
3753
|
+
/* @__PURE__ */ jsxs(
|
|
3754
|
+
"span",
|
|
3755
|
+
{
|
|
3756
|
+
className: `font-bold ${exportTargetEntries.length > 0 ? "text-emerald-600" : "text-amber-600"}`,
|
|
3757
|
+
children: [
|
|
3758
|
+
exportTargetEntries.length,
|
|
3759
|
+
" de ",
|
|
3760
|
+
entries.length,
|
|
3761
|
+
" registros"
|
|
3762
|
+
]
|
|
3763
|
+
}
|
|
3764
|
+
)
|
|
3765
|
+
] })
|
|
3766
|
+
] }),
|
|
3767
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2 pt-2", children: [
|
|
3768
|
+
/* @__PURE__ */ jsx(Button, { size: "large", onClick: () => setIsExportModalOpen(false), children: t.cancel }),
|
|
3769
|
+
/* @__PURE__ */ jsxs(
|
|
3770
|
+
Button,
|
|
3771
|
+
{
|
|
3772
|
+
type: "primary",
|
|
3773
|
+
size: "large",
|
|
3774
|
+
icon: /* @__PURE__ */ jsx(FileDown, { className: "h-4 w-4" }),
|
|
3775
|
+
onClick: handleConfirmExport,
|
|
3776
|
+
disabled: exportTargetEntries.length === 0,
|
|
3777
|
+
className: "rounded-xl font-bold bg-emerald-600 hover:bg-emerald-500",
|
|
3778
|
+
children: [
|
|
3779
|
+
t.exportDownloadBtn,
|
|
3780
|
+
" (",
|
|
3781
|
+
exportTargetEntries.length,
|
|
3782
|
+
")"
|
|
3783
|
+
]
|
|
3784
|
+
}
|
|
3785
|
+
)
|
|
3786
|
+
] })
|
|
3787
|
+
] })
|
|
3788
|
+
}
|
|
3789
|
+
),
|
|
3790
|
+
/* @__PURE__ */ jsx(
|
|
3791
|
+
Modal,
|
|
3792
|
+
{
|
|
3793
|
+
open: isImportModalOpen,
|
|
3794
|
+
title: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-slate-900 font-bold text-lg", children: [
|
|
3795
|
+
/* @__PURE__ */ jsx(FileSpreadsheet, { className: "h-5 w-5 text-emerald-600" }),
|
|
3796
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
3797
|
+
t.importModalTitle,
|
|
3798
|
+
" - ",
|
|
3799
|
+
collection.name
|
|
3800
|
+
] })
|
|
3801
|
+
] }),
|
|
3802
|
+
onCancel: () => {
|
|
3803
|
+
if (!isImporting) {
|
|
3804
|
+
setIsImportModalOpen(false);
|
|
3805
|
+
setImportResult(null);
|
|
3806
|
+
setImportFile(null);
|
|
3807
|
+
}
|
|
3808
|
+
},
|
|
3809
|
+
footer: null,
|
|
3810
|
+
centered: true,
|
|
3811
|
+
width: "min(800px, calc(100vw - 32px))",
|
|
3812
|
+
mask: { blur: true },
|
|
3813
|
+
children: /* @__PURE__ */ jsxs("div", { className: "py-2 space-y-4", children: [
|
|
3814
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-slate-500", children: t.importModalDesc }),
|
|
3815
|
+
!importResult ? /* @__PURE__ */ jsxs(
|
|
3816
|
+
"div",
|
|
3817
|
+
{
|
|
3818
|
+
onDragOver: (e) => {
|
|
3819
|
+
e.preventDefault();
|
|
3820
|
+
e.stopPropagation();
|
|
3821
|
+
},
|
|
3822
|
+
onDrop: (e) => {
|
|
3823
|
+
e.preventDefault();
|
|
3824
|
+
e.stopPropagation();
|
|
3825
|
+
const file = e.dataTransfer.files?.[0];
|
|
3826
|
+
if (file) handleProcessImportFile(file);
|
|
3827
|
+
},
|
|
3828
|
+
onClick: () => fileInputRef.current?.click(),
|
|
3829
|
+
className: "border-2 border-dashed border-slate-300 hover:border-emerald-500 rounded-2xl p-8 text-center cursor-pointer bg-slate-50 hover:bg-emerald-50/30 transition-all flex flex-col items-center justify-center gap-3",
|
|
3830
|
+
children: [
|
|
3831
|
+
/* @__PURE__ */ jsx(
|
|
3832
|
+
"input",
|
|
3833
|
+
{
|
|
3834
|
+
ref: fileInputRef,
|
|
3835
|
+
type: "file",
|
|
3836
|
+
accept: ".xlsx,.xls,.csv",
|
|
3837
|
+
className: "hidden",
|
|
3838
|
+
onChange: (e) => {
|
|
3839
|
+
const file = e.target.files?.[0];
|
|
3840
|
+
if (file) handleProcessImportFile(file);
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3843
|
+
),
|
|
3844
|
+
/* @__PURE__ */ jsx("div", { className: "size-14 rounded-full bg-emerald-100 flex items-center justify-center text-emerald-600 shadow-sm", children: /* @__PURE__ */ jsx(FileSpreadsheet, { className: "size-7" }) }),
|
|
3845
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3846
|
+
/* @__PURE__ */ jsx("p", { className: "font-semibold text-sm text-slate-700", children: t.importDropzone }),
|
|
3847
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-slate-400 mt-1", children: t.importDropzoneSub })
|
|
3848
|
+
] }),
|
|
3849
|
+
/* @__PURE__ */ jsx(
|
|
3850
|
+
Button,
|
|
3851
|
+
{
|
|
3852
|
+
size: "middle",
|
|
3853
|
+
loading: isParsingImport,
|
|
3854
|
+
className: "mt-2 rounded-lg font-medium",
|
|
3855
|
+
children: isParsingImport ? "Leyendo archivo..." : "Seleccionar archivo"
|
|
3856
|
+
}
|
|
3857
|
+
)
|
|
3858
|
+
]
|
|
3859
|
+
}
|
|
3860
|
+
) : /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
3861
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between p-3.5 bg-emerald-50/60 border border-emerald-200 rounded-xl", children: [
|
|
3862
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
3863
|
+
/* @__PURE__ */ jsx("div", { className: "size-9 rounded-lg bg-emerald-100 text-emerald-700 flex items-center justify-center font-bold", children: /* @__PURE__ */ jsx(FileSpreadsheet, { className: "size-5" }) }),
|
|
3864
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3865
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-bold text-slate-900", children: importFile?.name }),
|
|
3866
|
+
/* @__PURE__ */ jsxs("p", { className: "text-xs text-emerald-700 font-medium", children: [
|
|
3867
|
+
importResult.totalRows,
|
|
3868
|
+
" registros encontrados en el archivo"
|
|
3869
|
+
] })
|
|
3870
|
+
] })
|
|
3871
|
+
] }),
|
|
3872
|
+
/* @__PURE__ */ jsx(
|
|
3873
|
+
Button,
|
|
3874
|
+
{
|
|
3875
|
+
size: "small",
|
|
3876
|
+
onClick: () => {
|
|
3877
|
+
setImportResult(null);
|
|
3878
|
+
setImportFile(null);
|
|
3879
|
+
},
|
|
3880
|
+
disabled: isImporting,
|
|
3881
|
+
children: "Cambiar archivo"
|
|
3882
|
+
}
|
|
3883
|
+
)
|
|
3884
|
+
] }),
|
|
3885
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2 p-3 bg-slate-50 border border-slate-200 rounded-xl", children: [
|
|
3886
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-slate-700", children: "Estado de los registros:" }),
|
|
3887
|
+
/* @__PURE__ */ jsxs(Tag, { color: "green", className: "text-xs font-medium", children: [
|
|
3888
|
+
"\u2713 ",
|
|
3889
|
+
importResult.newRecordsCount,
|
|
3890
|
+
" ",
|
|
3891
|
+
t.importNewDetected
|
|
3892
|
+
] }),
|
|
3893
|
+
importResult.existingRecordsCount > 0 && /* @__PURE__ */ jsxs(Tag, { color: "gold", className: "text-xs font-medium", children: [
|
|
3894
|
+
"\u2139\uFE0F ",
|
|
3895
|
+
importResult.existingRecordsCount,
|
|
3896
|
+
" ",
|
|
3897
|
+
t.importExistingDetected
|
|
3898
|
+
] })
|
|
3899
|
+
] }),
|
|
3900
|
+
importResult.existingRecordsCount > 0 && /* @__PURE__ */ jsxs("div", { className: "p-3.5 bg-slate-50/90 rounded-xl border border-slate-200 space-y-2", children: [
|
|
3901
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold text-slate-700 block", children: t.importOverwritesWarning }),
|
|
3902
|
+
/* @__PURE__ */ jsxs(
|
|
3903
|
+
Radio.Group,
|
|
3904
|
+
{
|
|
3905
|
+
value: importExistingAction,
|
|
3906
|
+
onChange: (e) => setImportExistingAction(e.target.value),
|
|
3907
|
+
disabled: isImporting,
|
|
3908
|
+
className: "flex flex-col gap-2.5",
|
|
3909
|
+
children: [
|
|
3910
|
+
/* @__PURE__ */ jsxs(Radio, { value: "omit", className: "text-xs text-slate-700", children: [
|
|
3911
|
+
/* @__PURE__ */ jsx("span", { className: "font-semibold text-emerald-700 block", children: t.importExistingOmit }),
|
|
3912
|
+
/* @__PURE__ */ jsx("span", { className: "text-[11px] text-slate-500 block", children: "Si ya existe por ID o campo \xFAnico, no se vuelve a crear ni duplicar en la base de datos." })
|
|
3913
|
+
] }),
|
|
3914
|
+
/* @__PURE__ */ jsxs(Radio, { value: "update", className: "text-xs text-slate-700", children: [
|
|
3915
|
+
/* @__PURE__ */ jsx("span", { className: "font-semibold text-sky-700 block", children: t.importExistingUpdate }),
|
|
3916
|
+
/* @__PURE__ */ jsx("span", { className: "text-[11px] text-slate-500 block", children: "Actualiza los campos de los registros ya existentes con los datos del archivo." })
|
|
3917
|
+
] })
|
|
3918
|
+
]
|
|
3919
|
+
}
|
|
3920
|
+
)
|
|
3921
|
+
] }),
|
|
3922
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3923
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs font-bold text-slate-600 uppercase tracking-wider block mb-1.5", children: [
|
|
3924
|
+
"Campos reconocidos (",
|
|
3925
|
+
importResult.matchedFields.length,
|
|
3926
|
+
"):"
|
|
3927
|
+
] }),
|
|
3928
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1.5", children: [
|
|
3929
|
+
importResult.matchedFields.map((m, idx) => /* @__PURE__ */ jsxs(Tag, { color: "green", className: "text-xs py-0.5", children: [
|
|
3930
|
+
"\u2713 ",
|
|
3931
|
+
m.label
|
|
3932
|
+
] }, idx)),
|
|
3933
|
+
importResult.unmatchedHeaders.map((u, idx) => /* @__PURE__ */ jsxs(Tag, { color: "orange", className: "text-xs py-0.5", children: [
|
|
3934
|
+
"\u26A0\uFE0F ",
|
|
3935
|
+
u,
|
|
3936
|
+
" (omitido)"
|
|
3937
|
+
] }, idx))
|
|
3938
|
+
] })
|
|
3939
|
+
] }),
|
|
3940
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3941
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs font-bold text-slate-600 uppercase tracking-wider block mb-1.5", children: [
|
|
3942
|
+
t.importPreviewTitle,
|
|
3943
|
+
" (",
|
|
3944
|
+
Math.min(5, importResult.samplePreview.length),
|
|
3945
|
+
" de",
|
|
3946
|
+
" ",
|
|
3947
|
+
importResult.totalRows,
|
|
3948
|
+
"):"
|
|
3949
|
+
] }),
|
|
3950
|
+
/* @__PURE__ */ jsx("div", { className: "overflow-x-auto border border-slate-200 rounded-xl max-h-48 text-xs", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-left", children: [
|
|
3951
|
+
/* @__PURE__ */ jsx("thead", { className: "bg-slate-100/80 text-slate-700 font-semibold border-b border-slate-200", children: /* @__PURE__ */ jsx("tr", { children: importResult.matchedFields.slice(0, 6).map((m, idx) => /* @__PURE__ */ jsx("th", { className: "p-2 whitespace-nowrap", children: m.label }, idx)) }) }),
|
|
3952
|
+
/* @__PURE__ */ jsx("tbody", { className: "divide-y divide-slate-100", children: importResult.samplePreview.map((row, rIdx) => /* @__PURE__ */ jsx("tr", { className: "hover:bg-slate-50/60", children: importResult.matchedFields.slice(0, 6).map((m, cIdx) => /* @__PURE__ */ jsx(
|
|
3953
|
+
"td",
|
|
3954
|
+
{
|
|
3955
|
+
className: "p-2 whitespace-nowrap max-w-[160px] truncate text-slate-600",
|
|
3956
|
+
children: String(row[m.fieldId] ?? "")
|
|
3957
|
+
},
|
|
3958
|
+
cIdx
|
|
3959
|
+
)) }, rIdx)) })
|
|
3960
|
+
] }) })
|
|
3961
|
+
] }),
|
|
3962
|
+
isImporting && /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
3963
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-between text-xs text-slate-600 font-medium", children: [
|
|
3964
|
+
/* @__PURE__ */ jsx("span", { children: t.importingProgress }),
|
|
3965
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
3966
|
+
importProgress.current,
|
|
3967
|
+
" / ",
|
|
3968
|
+
importProgress.total
|
|
3969
|
+
] })
|
|
3970
|
+
] }),
|
|
3971
|
+
/* @__PURE__ */ jsx(
|
|
3972
|
+
Progress,
|
|
3973
|
+
{
|
|
3974
|
+
percent: Math.round(
|
|
3975
|
+
importProgress.current / (importProgress.total || 1) * 100
|
|
3976
|
+
),
|
|
3977
|
+
status: "active"
|
|
3978
|
+
}
|
|
3979
|
+
)
|
|
3980
|
+
] }),
|
|
3981
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2 pt-2", children: [
|
|
3982
|
+
/* @__PURE__ */ jsx(
|
|
3983
|
+
Button,
|
|
3984
|
+
{
|
|
3985
|
+
size: "large",
|
|
3986
|
+
onClick: () => setIsImportModalOpen(false),
|
|
3987
|
+
disabled: isImporting,
|
|
3988
|
+
children: t.cancel
|
|
3989
|
+
}
|
|
3990
|
+
),
|
|
3991
|
+
/* @__PURE__ */ jsxs(
|
|
3992
|
+
Button,
|
|
3993
|
+
{
|
|
3994
|
+
type: "primary",
|
|
3995
|
+
size: "large",
|
|
3996
|
+
loading: isImporting,
|
|
3997
|
+
onClick: handleExecuteImport,
|
|
3998
|
+
className: "rounded-xl font-bold bg-emerald-600 hover:bg-emerald-500",
|
|
3999
|
+
children: [
|
|
4000
|
+
t.importConfirmBtn,
|
|
4001
|
+
" (",
|
|
4002
|
+
importExistingAction === "omit" && importResult.existingRecordsCount > 0 ? importResult.newRecordsCount : importResult.totalRows,
|
|
4003
|
+
")"
|
|
4004
|
+
]
|
|
4005
|
+
}
|
|
4006
|
+
)
|
|
4007
|
+
] })
|
|
4008
|
+
] })
|
|
4009
|
+
] })
|
|
4010
|
+
}
|
|
4011
|
+
),
|
|
4012
|
+
/* @__PURE__ */ jsx("div", { className: "overflow-x-auto rounded-2xl border border-slate-200 bg-white shadow-sm", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-sm text-left", children: [
|
|
4013
|
+
/* @__PURE__ */ jsx("thead", { className: "bg-slate-50/80 border-b border-slate-200", children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
4014
|
+
visibleFields.map((f) => /* @__PURE__ */ jsx(
|
|
4015
|
+
"th",
|
|
4016
|
+
{
|
|
4017
|
+
className: "px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider",
|
|
4018
|
+
children: f.label
|
|
4019
|
+
},
|
|
4020
|
+
f.id
|
|
4021
|
+
)),
|
|
4022
|
+
/* @__PURE__ */ jsx("th", { className: "px-6 py-4 text-right text-xs font-bold text-slate-500 uppercase tracking-wider sticky right-0 bg-slate-50 border-l border-slate-200 z-10", children: t.actions })
|
|
4023
|
+
] }) }),
|
|
4024
|
+
/* @__PURE__ */ jsx("tbody", { className: "divide-y divide-slate-100", children: loadingEntries ? (
|
|
4025
|
+
// Loading skeleton rows
|
|
4026
|
+
Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
4027
|
+
visibleFields.map((f) => /* @__PURE__ */ jsx("td", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(
|
|
4028
|
+
"div",
|
|
4029
|
+
{
|
|
4030
|
+
className: "h-4 bg-slate-100 rounded animate-pulse",
|
|
4031
|
+
style: { width: `${60 + i * 13 % 30}%` }
|
|
4032
|
+
}
|
|
4033
|
+
) }, f.id)),
|
|
4034
|
+
/* @__PURE__ */ jsx("td", { className: "px-6 py-4 sticky right-0 bg-white border-l border-slate-100", children: /* @__PURE__ */ jsx("div", { className: "h-4 w-16 bg-slate-100 rounded animate-pulse ml-auto" }) })
|
|
4035
|
+
] }, i))
|
|
4036
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4037
|
+
(() => {
|
|
4038
|
+
let res = entries;
|
|
4039
|
+
if (search && collection.searchBy?.length) {
|
|
4040
|
+
const q = search.toLowerCase().trim();
|
|
4041
|
+
res = res.filter((e) => {
|
|
4042
|
+
return collection.searchBy.some((field) => {
|
|
4043
|
+
const val = String(e[field] ?? "").toLowerCase();
|
|
4044
|
+
if (!val) return false;
|
|
4045
|
+
if (val.includes(q)) return true;
|
|
4046
|
+
const normVal = val.replace(/-/g, "/");
|
|
4047
|
+
const normQ = q.replace(/-/g, "/");
|
|
4048
|
+
return normVal.includes(normQ);
|
|
4049
|
+
});
|
|
4050
|
+
});
|
|
4051
|
+
}
|
|
4052
|
+
if (Object.keys(filters).length > 0) {
|
|
4053
|
+
res = res.filter((e) => {
|
|
4054
|
+
for (const [k, v] of Object.entries(filters)) {
|
|
4055
|
+
if (!v) continue;
|
|
4056
|
+
const entryVal = String(e[k] ?? "").trim();
|
|
2810
4057
|
const filterVal = String(v).trim();
|
|
2811
4058
|
const normEntry = entryVal.replace(/-/g, "/");
|
|
2812
4059
|
const normFilter = filterVal.replace(/-/g, "/");
|
|
@@ -2817,7 +4064,10 @@ function CollectionEditor({ collection }) {
|
|
|
2817
4064
|
return true;
|
|
2818
4065
|
});
|
|
2819
4066
|
}
|
|
2820
|
-
const paginatedRes = res.slice(
|
|
4067
|
+
const paginatedRes = res.slice(
|
|
4068
|
+
(page - 1) * itemsPerPage,
|
|
4069
|
+
page * itemsPerPage
|
|
4070
|
+
);
|
|
2821
4071
|
return /* @__PURE__ */ jsx(Fragment, { children: paginatedRes.map((e, idx) => /* @__PURE__ */ jsxs(
|
|
2822
4072
|
"tr",
|
|
2823
4073
|
{
|
|
@@ -2828,50 +4078,159 @@ function CollectionEditor({ collection }) {
|
|
|
2828
4078
|
onDragEnd,
|
|
2829
4079
|
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" : ""}`,
|
|
2830
4080
|
children: [
|
|
2831
|
-
visibleFields.map((f) => /* @__PURE__ */ jsx(
|
|
2832
|
-
"
|
|
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",
|
|
4081
|
+
visibleFields.map((f) => /* @__PURE__ */ jsx(
|
|
4082
|
+
"td",
|
|
2848
4083
|
{
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
4084
|
+
className: "px-6 py-4 text-slate-700 max-w-[200px] truncate",
|
|
4085
|
+
children: f.renderCell ? f.renderCell(e[f.id], e) : 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(
|
|
4086
|
+
"img",
|
|
4087
|
+
{
|
|
4088
|
+
src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]),
|
|
4089
|
+
alt: "",
|
|
4090
|
+
className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200"
|
|
4091
|
+
}
|
|
4092
|
+
) : 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(
|
|
4093
|
+
"svg",
|
|
4094
|
+
{
|
|
4095
|
+
className: "w-4 h-4",
|
|
4096
|
+
fill: "none",
|
|
4097
|
+
stroke: "currentColor",
|
|
4098
|
+
viewBox: "0 0 24 24",
|
|
4099
|
+
children: /* @__PURE__ */ jsx(
|
|
4100
|
+
"path",
|
|
4101
|
+
{
|
|
4102
|
+
strokeLinecap: "round",
|
|
4103
|
+
strokeLinejoin: "round",
|
|
4104
|
+
strokeWidth: "2",
|
|
4105
|
+
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"
|
|
4106
|
+
}
|
|
4107
|
+
)
|
|
4108
|
+
}
|
|
4109
|
+
) }) : (f.id === "status" || f.id === "estado") && e[f.id] ? /* @__PURE__ */ jsx(
|
|
4110
|
+
"span",
|
|
4111
|
+
{
|
|
4112
|
+
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(
|
|
4113
|
+
"Preparaci\xF3n"
|
|
4114
|
+
) ? "bg-amber-50 text-amber-700 border border-amber-200" : String(e[f.id]) === "Cancelado" || String(e[f.id]).includes(
|
|
4115
|
+
"Cancelado"
|
|
4116
|
+
) ? "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"}`,
|
|
4117
|
+
children: String(e[f.id])
|
|
4118
|
+
}
|
|
4119
|
+
) : (f.type === "reference" || f.type === "select" && f.collection) && e[f.id] ? f.onCellClick ? /* @__PURE__ */ jsx(
|
|
4120
|
+
"button",
|
|
4121
|
+
{
|
|
4122
|
+
type: "button",
|
|
4123
|
+
onClick: () => f.onCellClick(e[f.id], e),
|
|
4124
|
+
className: "font-medium text-indigo-600 hover:text-indigo-800 hover:underline cursor-pointer text-left truncate block max-w-full",
|
|
4125
|
+
children: /* @__PURE__ */ jsx(
|
|
4126
|
+
ReferenceTableCell,
|
|
4127
|
+
{
|
|
4128
|
+
collectionId: f.collection,
|
|
4129
|
+
entryId: e[f.id],
|
|
4130
|
+
displayField: f.displayField,
|
|
4131
|
+
valueField: f.valueField,
|
|
4132
|
+
multiple: f.multiple
|
|
4133
|
+
}
|
|
4134
|
+
)
|
|
4135
|
+
}
|
|
4136
|
+
) : /* @__PURE__ */ jsx(
|
|
4137
|
+
ReferenceTableCell,
|
|
4138
|
+
{
|
|
4139
|
+
collectionId: f.collection,
|
|
4140
|
+
entryId: e[f.id],
|
|
4141
|
+
displayField: f.displayField,
|
|
4142
|
+
valueField: f.valueField,
|
|
4143
|
+
multiple: f.multiple
|
|
4144
|
+
}
|
|
4145
|
+
) : (f.type === "list" || f.multiple) && e[f.id] ? Array.isArray(e[f.id]) ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
4146
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: String(e[f.id][0] || "") }),
|
|
4147
|
+
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: [
|
|
4148
|
+
"+",
|
|
4149
|
+
e[f.id].length - 1,
|
|
4150
|
+
" m\xE1s"
|
|
4151
|
+
] })
|
|
4152
|
+
] }) : /* @__PURE__ */ jsx("span", { children: String(e[f.id]) }) : f.onCellClick ? /* @__PURE__ */ jsx(
|
|
4153
|
+
"button",
|
|
4154
|
+
{
|
|
4155
|
+
type: "button",
|
|
4156
|
+
onClick: () => f.onCellClick(e[f.id], e),
|
|
4157
|
+
className: "font-medium text-indigo-600 hover:text-indigo-800 hover:underline cursor-pointer text-left truncate block w-full",
|
|
4158
|
+
children: String(e[f.id] ?? "")
|
|
4159
|
+
}
|
|
4160
|
+
) : f.type === "signature" && e[f.id] ? /* @__PURE__ */ jsx(
|
|
4161
|
+
Image,
|
|
4162
|
+
{
|
|
4163
|
+
src: String(e[f.id]),
|
|
4164
|
+
alt: "Firma",
|
|
4165
|
+
className: "h-7 max-w-[80px] object-contain rounded bg-white border border-slate-200 p-0.5 inline-block shadow-xs cursor-pointer",
|
|
4166
|
+
preview: { mask: "Ver" }
|
|
4167
|
+
}
|
|
4168
|
+
) : 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: [
|
|
4169
|
+
"$ ",
|
|
4170
|
+
Number(e[f.id]).toLocaleString("es-CO")
|
|
4171
|
+
] }) : /* @__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(
|
|
4172
|
+
"a",
|
|
4173
|
+
{
|
|
4174
|
+
href: String(e[f.id]),
|
|
4175
|
+
target: "_blank",
|
|
4176
|
+
rel: "noopener noreferrer",
|
|
4177
|
+
className: "inline-flex items-center gap-1 text-xs text-blue-600 hover:text-blue-800 underline font-medium",
|
|
4178
|
+
children: [
|
|
4179
|
+
/* @__PURE__ */ jsx(ExternalLink, { className: "w-3 h-3" }),
|
|
4180
|
+
String(e[f.id]).includes("maps") ? "Ver mapa" : "Abrir"
|
|
4181
|
+
]
|
|
4182
|
+
}
|
|
4183
|
+
) : 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] ?? "")
|
|
4184
|
+
},
|
|
4185
|
+
f.id
|
|
4186
|
+
)),
|
|
2870
4187
|
/* @__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: [
|
|
2871
|
-
|
|
4188
|
+
collection.customRowActions && collection.customRowActions({
|
|
4189
|
+
record: e,
|
|
4190
|
+
openDetail: () => {
|
|
4191
|
+
if (collection.customDetailView || collection.renderCustomDetail) {
|
|
4192
|
+
setCustomViewingRecord(e);
|
|
4193
|
+
setIsCustomEditing(false);
|
|
4194
|
+
return;
|
|
4195
|
+
}
|
|
4196
|
+
if (collection.onViewRecord) {
|
|
4197
|
+
collection.onViewRecord(e);
|
|
4198
|
+
return;
|
|
4199
|
+
}
|
|
4200
|
+
setIsCreatingManual(false);
|
|
4201
|
+
setIsViewingDetail(true);
|
|
4202
|
+
setOriginalId(String(e.id || ""));
|
|
4203
|
+
setDuplicateErrors({});
|
|
4204
|
+
setEditing({ ...e });
|
|
4205
|
+
},
|
|
4206
|
+
openEdit: () => {
|
|
4207
|
+
if (collection.customEditView) {
|
|
4208
|
+
setCustomViewingRecord(e);
|
|
4209
|
+
setIsCustomEditing(true);
|
|
4210
|
+
return;
|
|
4211
|
+
}
|
|
4212
|
+
setIsCreatingManual(false);
|
|
4213
|
+
setIsViewingDetail(false);
|
|
4214
|
+
setOriginalId(String(e.id || ""));
|
|
4215
|
+
setDuplicateErrors({});
|
|
4216
|
+
setEditing({ ...e });
|
|
4217
|
+
},
|
|
4218
|
+
openCustomView: (renderFn) => {
|
|
4219
|
+
setCustomActiveView(() => renderFn);
|
|
4220
|
+
},
|
|
4221
|
+
reload: () => {
|
|
4222
|
+
load();
|
|
4223
|
+
}
|
|
4224
|
+
}),
|
|
4225
|
+
(collection.enableDetailView || collection.onViewRecord || collection.customDetailView || collection.renderCustomDetail) && /* @__PURE__ */ jsx(
|
|
2872
4226
|
"button",
|
|
2873
4227
|
{
|
|
2874
4228
|
onClick: () => {
|
|
4229
|
+
if (collection.customDetailView || collection.renderCustomDetail) {
|
|
4230
|
+
setCustomViewingRecord(e);
|
|
4231
|
+
setIsCustomEditing(false);
|
|
4232
|
+
return;
|
|
4233
|
+
}
|
|
2875
4234
|
if (collection.onViewRecord) {
|
|
2876
4235
|
collection.onViewRecord(e);
|
|
2877
4236
|
return;
|
|
@@ -2900,6 +4259,11 @@ function CollectionEditor({ collection }) {
|
|
|
2900
4259
|
"button",
|
|
2901
4260
|
{
|
|
2902
4261
|
onClick: () => {
|
|
4262
|
+
if (collection.customEditView) {
|
|
4263
|
+
setCustomViewingRecord(e);
|
|
4264
|
+
setIsCustomEditing(true);
|
|
4265
|
+
return;
|
|
4266
|
+
}
|
|
2903
4267
|
setIsCreatingManual(false);
|
|
2904
4268
|
setIsViewingDetail(false);
|
|
2905
4269
|
setOriginalId(String(e.id || ""));
|
|
@@ -2911,17 +4275,43 @@ function CollectionEditor({ collection }) {
|
|
|
2911
4275
|
children: /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4" })
|
|
2912
4276
|
}
|
|
2913
4277
|
),
|
|
2914
|
-
!collection.disableDelete && /* @__PURE__ */ jsx(
|
|
4278
|
+
!collection.disableDelete && !collection.hideDelete && (!collection.canDelete || collection.canDelete(e)) && /* @__PURE__ */ jsx(
|
|
2915
4279
|
"button",
|
|
2916
4280
|
{
|
|
2917
4281
|
onClick: () => remove(e.id),
|
|
2918
4282
|
disabled: deletingId === e.id,
|
|
2919
4283
|
className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors disabled:opacity-50",
|
|
2920
4284
|
title: t.delete,
|
|
2921
|
-
children: deletingId === e.id ? /* @__PURE__ */ jsxs(
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
4285
|
+
children: deletingId === e.id ? /* @__PURE__ */ jsxs(
|
|
4286
|
+
"svg",
|
|
4287
|
+
{
|
|
4288
|
+
className: "animate-spin h-4 w-4",
|
|
4289
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
4290
|
+
fill: "none",
|
|
4291
|
+
viewBox: "0 0 24 24",
|
|
4292
|
+
children: [
|
|
4293
|
+
/* @__PURE__ */ jsx(
|
|
4294
|
+
"circle",
|
|
4295
|
+
{
|
|
4296
|
+
className: "opacity-25",
|
|
4297
|
+
cx: "12",
|
|
4298
|
+
cy: "12",
|
|
4299
|
+
r: "10",
|
|
4300
|
+
stroke: "currentColor",
|
|
4301
|
+
strokeWidth: "4"
|
|
4302
|
+
}
|
|
4303
|
+
),
|
|
4304
|
+
/* @__PURE__ */ jsx(
|
|
4305
|
+
"path",
|
|
4306
|
+
{
|
|
4307
|
+
className: "opacity-75",
|
|
4308
|
+
fill: "currentColor",
|
|
4309
|
+
d: "M4 12a8 8 0 018-8v8H4z"
|
|
4310
|
+
}
|
|
4311
|
+
)
|
|
4312
|
+
]
|
|
4313
|
+
}
|
|
4314
|
+
) : /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" })
|
|
2925
4315
|
}
|
|
2926
4316
|
)
|
|
2927
4317
|
] }) })
|
|
@@ -2948,7 +4338,11 @@ function CollectionEditor({ collection }) {
|
|
|
2948
4338
|
let res = entries;
|
|
2949
4339
|
if (search && collection.searchBy?.length) {
|
|
2950
4340
|
const q = search.toLowerCase();
|
|
2951
|
-
res = res.filter(
|
|
4341
|
+
res = res.filter(
|
|
4342
|
+
(e) => collection.searchBy.some(
|
|
4343
|
+
(field) => String(e[field] || "").toLowerCase().includes(q)
|
|
4344
|
+
)
|
|
4345
|
+
);
|
|
2952
4346
|
}
|
|
2953
4347
|
if (Object.keys(filters).length > 0) {
|
|
2954
4348
|
res = res.filter((e) => {
|
|
@@ -2964,7 +4358,11 @@ function CollectionEditor({ collection }) {
|
|
|
2964
4358
|
let res = entries;
|
|
2965
4359
|
if (search && collection.searchBy?.length) {
|
|
2966
4360
|
const q = search.toLowerCase();
|
|
2967
|
-
res = res.filter(
|
|
4361
|
+
res = res.filter(
|
|
4362
|
+
(e) => collection.searchBy.some(
|
|
4363
|
+
(field) => String(e[field] || "").toLowerCase().includes(q)
|
|
4364
|
+
)
|
|
4365
|
+
);
|
|
2968
4366
|
}
|
|
2969
4367
|
if (Object.keys(filters).length > 0) {
|
|
2970
4368
|
res = res.filter((e) => {
|
|
@@ -2974,7 +4372,10 @@ function CollectionEditor({ collection }) {
|
|
|
2974
4372
|
return true;
|
|
2975
4373
|
});
|
|
2976
4374
|
}
|
|
2977
|
-
const totalPages = Math.max(
|
|
4375
|
+
const totalPages = Math.max(
|
|
4376
|
+
1,
|
|
4377
|
+
Math.ceil(res.length / itemsPerPage)
|
|
4378
|
+
);
|
|
2978
4379
|
if (totalPages <= 1) return null;
|
|
2979
4380
|
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2980
4381
|
/* @__PURE__ */ jsx(
|
|
@@ -3031,20 +4432,39 @@ function SubmissionsSection() {
|
|
|
3031
4432
|
/* @__PURE__ */ jsxs("div", { className: "w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-slate-200 bg-white/50 p-4", children: [
|
|
3032
4433
|
/* @__PURE__ */ jsx("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Data Collections" }),
|
|
3033
4434
|
/* @__PURE__ */ jsxs("ul", { className: "flex overflow-x-auto gap-2 pb-2 md:block md:space-x-0 md:space-y-1 md:pb-0 md:overflow-visible", children: [
|
|
3034
|
-
formIds.map((id) => /* @__PURE__ */ jsx(
|
|
3035
|
-
"
|
|
4435
|
+
formIds.map((id) => /* @__PURE__ */ jsx(
|
|
4436
|
+
"li",
|
|
3036
4437
|
{
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
4438
|
+
className: "shrink-0 min-w-[140px] md:w-full md:min-w-0",
|
|
4439
|
+
children: /* @__PURE__ */ jsxs(
|
|
4440
|
+
"button",
|
|
4441
|
+
{
|
|
4442
|
+
onClick: () => setSelectedFormId(id),
|
|
4443
|
+
className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selectedFormId === id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
|
|
4444
|
+
children: [
|
|
4445
|
+
/* @__PURE__ */ jsx(
|
|
4446
|
+
"div",
|
|
4447
|
+
{
|
|
4448
|
+
className: selectedFormId === id ? "text-slate-900" : "text-slate-700 capitalize",
|
|
4449
|
+
children: id
|
|
4450
|
+
}
|
|
4451
|
+
),
|
|
4452
|
+
/* @__PURE__ */ jsxs(
|
|
4453
|
+
"div",
|
|
4454
|
+
{
|
|
4455
|
+
className: `text-xs mt-0.5 ${selectedFormId === id ? "text-indigo-500" : "text-slate-400"}`,
|
|
4456
|
+
children: [
|
|
4457
|
+
submissions.filter((s) => s.formId === id).length,
|
|
4458
|
+
" items"
|
|
4459
|
+
]
|
|
4460
|
+
}
|
|
4461
|
+
)
|
|
4462
|
+
]
|
|
4463
|
+
}
|
|
4464
|
+
)
|
|
4465
|
+
},
|
|
4466
|
+
id
|
|
4467
|
+
)),
|
|
3048
4468
|
formIds.length === 0 && /* @__PURE__ */ jsx("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200", children: "No data collected." })
|
|
3049
4469
|
] })
|
|
3050
4470
|
] }),
|
|
@@ -3063,7 +4483,12 @@ function SubmissionsSection() {
|
|
|
3063
4483
|
] })
|
|
3064
4484
|
] });
|
|
3065
4485
|
}
|
|
3066
|
-
function SubmissionsList({
|
|
4486
|
+
function SubmissionsList({
|
|
4487
|
+
formId,
|
|
4488
|
+
submissions,
|
|
4489
|
+
onLoad,
|
|
4490
|
+
loading
|
|
4491
|
+
}) {
|
|
3067
4492
|
const ctx = useCmsContext();
|
|
3068
4493
|
const [search, setSearch] = useState("");
|
|
3069
4494
|
const [page, setPage] = useState(1);
|
|
@@ -3091,7 +4516,10 @@ function SubmissionsList({ formId, submissions, onLoad, loading }) {
|
|
|
3091
4516
|
const unreadCount = submissions.filter((s) => !s.read).length;
|
|
3092
4517
|
const formatDate = (iso) => {
|
|
3093
4518
|
try {
|
|
3094
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
4519
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
4520
|
+
dateStyle: "medium",
|
|
4521
|
+
timeStyle: "short"
|
|
4522
|
+
}).format(new Date(iso));
|
|
3095
4523
|
} catch {
|
|
3096
4524
|
return iso;
|
|
3097
4525
|
}
|
|
@@ -3129,54 +4557,61 @@ function SubmissionsList({ formId, submissions, onLoad, loading }) {
|
|
|
3129
4557
|
const strVal = String(val ?? "\u2014");
|
|
3130
4558
|
const isImage = typeof val === "string" && (val.startsWith("data:image/") || /\.(jpg|jpeg|png|webp|avif|gif|svg)(\?.*)?$/i.test(val) || val.includes("/images/") && val.includes("sanity.io"));
|
|
3131
4559
|
const isUrl = typeof val === "string" && /^https?:\/\//i.test(val);
|
|
3132
|
-
return /* @__PURE__ */ jsxs(
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
{
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
className: "inline-block max-w-sm rounded-lg overflow-hidden border border-slate-200 shadow-sm hover:shadow transition-shadow bg-slate-50 p-1",
|
|
3142
|
-
children: /* @__PURE__ */ jsx(
|
|
3143
|
-
"img",
|
|
4560
|
+
return /* @__PURE__ */ jsxs(
|
|
4561
|
+
"div",
|
|
4562
|
+
{
|
|
4563
|
+
className: "py-4 grid grid-cols-[160px_1fr] gap-4 items-start",
|
|
4564
|
+
children: [
|
|
4565
|
+
/* @__PURE__ */ jsx("dt", { className: "text-xs font-bold uppercase tracking-wide text-slate-400 pt-0.5", children: key }),
|
|
4566
|
+
/* @__PURE__ */ jsx("dd", { className: "text-sm text-slate-800", children: isImage ? /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
4567
|
+
/* @__PURE__ */ jsx(
|
|
4568
|
+
"a",
|
|
3144
4569
|
{
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
4570
|
+
href: strVal,
|
|
4571
|
+
target: "_blank",
|
|
4572
|
+
rel: "noopener noreferrer",
|
|
4573
|
+
className: "inline-block max-w-sm rounded-lg overflow-hidden border border-slate-200 shadow-sm hover:shadow transition-shadow bg-slate-50 p-1",
|
|
4574
|
+
children: /* @__PURE__ */ jsx(
|
|
4575
|
+
"img",
|
|
4576
|
+
{
|
|
4577
|
+
src: strVal,
|
|
4578
|
+
alt: key,
|
|
4579
|
+
className: "max-h-64 w-auto object-contain rounded"
|
|
4580
|
+
}
|
|
4581
|
+
)
|
|
3148
4582
|
}
|
|
3149
|
-
)
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
}
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
4583
|
+
),
|
|
4584
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
4585
|
+
"a",
|
|
4586
|
+
{
|
|
4587
|
+
href: strVal,
|
|
4588
|
+
target: "_blank",
|
|
4589
|
+
rel: "noopener noreferrer",
|
|
4590
|
+
className: "inline-flex items-center gap-1.5 text-xs text-indigo-600 font-semibold hover:underline",
|
|
4591
|
+
children: [
|
|
4592
|
+
/* @__PURE__ */ jsx(ExternalLink, { className: "w-3.5 h-3.5" }),
|
|
4593
|
+
" View / Download file"
|
|
4594
|
+
]
|
|
4595
|
+
}
|
|
4596
|
+
) })
|
|
4597
|
+
] }) : isUrl ? /* @__PURE__ */ jsxs(
|
|
4598
|
+
"a",
|
|
4599
|
+
{
|
|
4600
|
+
href: strVal,
|
|
4601
|
+
target: "_blank",
|
|
4602
|
+
rel: "noopener noreferrer",
|
|
4603
|
+
className: "inline-flex items-center gap-1.5 text-indigo-600 font-medium hover:underline break-all text-sm",
|
|
4604
|
+
children: [
|
|
4605
|
+
/* @__PURE__ */ jsx(ExternalLink, { className: "w-3.5 h-3.5 flex-shrink-0" }),
|
|
4606
|
+
" ",
|
|
4607
|
+
strVal
|
|
4608
|
+
]
|
|
4609
|
+
}
|
|
4610
|
+
) : /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap", children: strVal }) })
|
|
4611
|
+
]
|
|
4612
|
+
},
|
|
4613
|
+
key
|
|
4614
|
+
);
|
|
3180
4615
|
}) })
|
|
3181
4616
|
] })
|
|
3182
4617
|
] });
|
|
@@ -3198,7 +4633,8 @@ function SubmissionsList({ formId, submissions, onLoad, loading }) {
|
|
|
3198
4633
|
className: "inline-flex items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm font-semibold text-slate-700 shadow-sm hover:bg-slate-50 transition-colors disabled:opacity-50",
|
|
3199
4634
|
children: [
|
|
3200
4635
|
/* @__PURE__ */ jsx(RefreshCw, { className: `h-4 w-4 ${loading ? "animate-spin" : ""}` }),
|
|
3201
|
-
"
|
|
4636
|
+
" ",
|
|
4637
|
+
"Refresh"
|
|
3202
4638
|
]
|
|
3203
4639
|
}
|
|
3204
4640
|
)
|
|
@@ -3239,26 +4675,33 @@ function SubmissionsList({ formId, submissions, onLoad, loading }) {
|
|
|
3239
4675
|
!s.read && /* @__PURE__ */ jsx("span", { className: "ml-2 inline-block h-2 w-2 rounded-full bg-indigo-500" })
|
|
3240
4676
|
] }),
|
|
3241
4677
|
/* @__PURE__ */ jsx("td", { className: "px-6 py-4 text-slate-500 whitespace-nowrap", children: formatDate(s.submittedAt) }),
|
|
3242
|
-
/* @__PURE__ */ jsx(
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
4678
|
+
/* @__PURE__ */ jsx(
|
|
4679
|
+
"td",
|
|
4680
|
+
{
|
|
4681
|
+
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",
|
|
4682
|
+
onClick: (e) => e.stopPropagation(),
|
|
4683
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-1", children: [
|
|
4684
|
+
/* @__PURE__ */ jsx(
|
|
4685
|
+
"button",
|
|
4686
|
+
{
|
|
4687
|
+
onClick: () => openDetail(s),
|
|
4688
|
+
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
|
|
4689
|
+
title: "View detail",
|
|
4690
|
+
children: /* @__PURE__ */ jsx(Eye, { className: "h-4 w-4" })
|
|
4691
|
+
}
|
|
4692
|
+
),
|
|
4693
|
+
/* @__PURE__ */ jsx(
|
|
4694
|
+
"button",
|
|
4695
|
+
{
|
|
4696
|
+
onClick: () => deleteOne(s.id),
|
|
4697
|
+
className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors",
|
|
4698
|
+
title: "Delete",
|
|
4699
|
+
children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" })
|
|
4700
|
+
}
|
|
4701
|
+
)
|
|
4702
|
+
] })
|
|
4703
|
+
}
|
|
4704
|
+
)
|
|
3262
4705
|
]
|
|
3263
4706
|
},
|
|
3264
4707
|
s.id
|
|
@@ -3316,7 +4759,13 @@ function SettingsSection() {
|
|
|
3316
4759
|
/* @__PURE__ */ jsx("div", { className: "px-6 py-4 border-b border-slate-100 bg-slate-50/50", children: /* @__PURE__ */ jsx("h3", { className: "font-bold text-slate-800", children: "Configuration Snapshot" }) }),
|
|
3317
4760
|
/* @__PURE__ */ jsxs("dl", { className: "divide-y divide-slate-100 text-sm", children: [
|
|
3318
4761
|
/* @__PURE__ */ jsx(Row, { label: "Site Name", value: ctx.config.siteName ?? "\u2014" }),
|
|
3319
|
-
/* @__PURE__ */ jsx(
|
|
4762
|
+
/* @__PURE__ */ jsx(
|
|
4763
|
+
Row,
|
|
4764
|
+
{
|
|
4765
|
+
label: "Registered Pages",
|
|
4766
|
+
value: String(ctx.config.pages.length)
|
|
4767
|
+
}
|
|
4768
|
+
),
|
|
3320
4769
|
/* @__PURE__ */ jsx(
|
|
3321
4770
|
Row,
|
|
3322
4771
|
{
|
|
@@ -3365,7 +4814,13 @@ function ConfigSection() {
|
|
|
3365
4814
|
{
|
|
3366
4815
|
onClick: () => setSelectedGroupId(g.id),
|
|
3367
4816
|
className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selectedGroupId === g.id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
|
|
3368
|
-
children: /* @__PURE__ */ jsx(
|
|
4817
|
+
children: /* @__PURE__ */ jsx(
|
|
4818
|
+
"div",
|
|
4819
|
+
{
|
|
4820
|
+
className: `truncate ${selectedGroupId === g.id ? "text-slate-900" : "text-slate-700"}`,
|
|
4821
|
+
children: g.label
|
|
4822
|
+
}
|
|
4823
|
+
)
|
|
3369
4824
|
}
|
|
3370
4825
|
) }, g.id)),
|
|
3371
4826
|
globals.length === 0 && /* @__PURE__ */ jsx("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200 w-full", children: "No global configurations." })
|
|
@@ -3432,10 +4887,22 @@ function Row({
|
|
|
3432
4887
|
}) {
|
|
3433
4888
|
return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4 hover:bg-slate-50/50 transition-colors", children: [
|
|
3434
4889
|
/* @__PURE__ */ jsx("dt", { className: "text-slate-500 font-medium", children: label }),
|
|
3435
|
-
/* @__PURE__ */ jsx(
|
|
4890
|
+
/* @__PURE__ */ jsx(
|
|
4891
|
+
"dd",
|
|
4892
|
+
{
|
|
4893
|
+
className: `font-semibold ${highlight ? "text-indigo-600 bg-indigo-50 px-2 py-0.5 rounded" : status === "warning" ? "text-amber-600" : status === "success" ? "text-emerald-600" : "text-slate-900"}`,
|
|
4894
|
+
children: value
|
|
4895
|
+
}
|
|
4896
|
+
)
|
|
3436
4897
|
] });
|
|
3437
4898
|
}
|
|
3438
|
-
function SearchableSelect({
|
|
4899
|
+
function SearchableSelect({
|
|
4900
|
+
value,
|
|
4901
|
+
onChange,
|
|
4902
|
+
options,
|
|
4903
|
+
placeholder,
|
|
4904
|
+
iconMap
|
|
4905
|
+
}) {
|
|
3439
4906
|
const [open, setOpen] = useState(false);
|
|
3440
4907
|
const [search, setSearch] = useState("");
|
|
3441
4908
|
const btnRef = useRef(null);
|
|
@@ -3452,7 +4919,10 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
3452
4919
|
const opensUp = spaceBelow < dropdownHeight && rect.top > dropdownHeight;
|
|
3453
4920
|
setCoords({
|
|
3454
4921
|
top: opensUp ? Math.max(10, rect.top - dropdownHeight - 6) : rect.bottom + 6,
|
|
3455
|
-
left: Math.max(
|
|
4922
|
+
left: Math.max(
|
|
4923
|
+
10,
|
|
4924
|
+
Math.min(rect.left, window.innerWidth - rect.width - 10)
|
|
4925
|
+
),
|
|
3456
4926
|
width: rect.width
|
|
3457
4927
|
});
|
|
3458
4928
|
}
|
|
@@ -3577,7 +5047,10 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
3577
5047
|
)
|
|
3578
5048
|
] });
|
|
3579
5049
|
}
|
|
3580
|
-
function PasswordField({
|
|
5050
|
+
function PasswordField({
|
|
5051
|
+
value,
|
|
5052
|
+
onChange
|
|
5053
|
+
}) {
|
|
3581
5054
|
const [show, setShow] = useState(false);
|
|
3582
5055
|
const hasExisting = Boolean(value && String(value).trim().length > 0);
|
|
3583
5056
|
const [displayValue, setDisplayValue] = useState("");
|
|
@@ -3763,8 +5236,24 @@ function SignatureInput({
|
|
|
3763
5236
|
centered: true,
|
|
3764
5237
|
width: 560,
|
|
3765
5238
|
footer: [
|
|
3766
|
-
/* @__PURE__ */ jsx(
|
|
3767
|
-
|
|
5239
|
+
/* @__PURE__ */ jsx(
|
|
5240
|
+
Button,
|
|
5241
|
+
{
|
|
5242
|
+
onClick: clearCanvas,
|
|
5243
|
+
className: "rounded-xl font-medium",
|
|
5244
|
+
children: t.clear
|
|
5245
|
+
},
|
|
5246
|
+
"clear"
|
|
5247
|
+
),
|
|
5248
|
+
/* @__PURE__ */ jsx(
|
|
5249
|
+
Button,
|
|
5250
|
+
{
|
|
5251
|
+
onClick: () => setModalOpen(false),
|
|
5252
|
+
className: "rounded-xl font-medium",
|
|
5253
|
+
children: t.cancel
|
|
5254
|
+
},
|
|
5255
|
+
"cancel"
|
|
5256
|
+
),
|
|
3768
5257
|
/* @__PURE__ */ jsx(
|
|
3769
5258
|
Button,
|
|
3770
5259
|
{
|
|
@@ -3815,7 +5304,9 @@ function FormattedNumberInput({
|
|
|
3815
5304
|
if (!cleanDigits) return "";
|
|
3816
5305
|
return cleanDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
3817
5306
|
};
|
|
3818
|
-
const [displayVal, setDisplayVal] = useState(
|
|
5307
|
+
const [displayVal, setDisplayVal] = useState(
|
|
5308
|
+
() => formatWithDots(value)
|
|
5309
|
+
);
|
|
3819
5310
|
useEffect(() => {
|
|
3820
5311
|
setDisplayVal(formatWithDots(value));
|
|
3821
5312
|
}, [value]);
|
|
@@ -3857,440 +5348,6 @@ function FormattedNumberInput({
|
|
|
3857
5348
|
)
|
|
3858
5349
|
] });
|
|
3859
5350
|
}
|
|
3860
|
-
function BranchSettingsEditor({
|
|
3861
|
-
collectionId,
|
|
3862
|
-
value,
|
|
3863
|
-
globalPrice,
|
|
3864
|
-
globalDiscount,
|
|
3865
|
-
onChange
|
|
3866
|
-
}) {
|
|
3867
|
-
const ctx = useCmsContext();
|
|
3868
|
-
const [branches, setBranches] = useState([]);
|
|
3869
|
-
const [loading, setLoading] = useState(true);
|
|
3870
|
-
const [loadError, setLoadError] = useState("");
|
|
3871
|
-
const settings = value && typeof value === "object" ? value : {};
|
|
3872
|
-
const selectedBranches = Array.isArray(settings.branches) ? settings.branches.map(String) : [];
|
|
3873
|
-
const prices = settings.prices && typeof settings.prices === "object" ? settings.prices : {};
|
|
3874
|
-
const selectedPriceBranches = [
|
|
3875
|
-
.../* @__PURE__ */ new Set([
|
|
3876
|
-
...Array.isArray(settings.priceBranches) ? settings.priceBranches.map(String) : [],
|
|
3877
|
-
...Object.keys(prices)
|
|
3878
|
-
])
|
|
3879
|
-
];
|
|
3880
|
-
const discounts = settings.discounts && typeof settings.discounts === "object" ? settings.discounts : {};
|
|
3881
|
-
const selectedDiscountBranches = [
|
|
3882
|
-
.../* @__PURE__ */ new Set([
|
|
3883
|
-
...Array.isArray(settings.discountBranches) ? settings.discountBranches.map(String) : [],
|
|
3884
|
-
...Object.keys(discounts)
|
|
3885
|
-
])
|
|
3886
|
-
];
|
|
3887
|
-
const branchAvailability = settings.branchAvailability && typeof settings.branchAvailability === "object" ? settings.branchAvailability : {};
|
|
3888
|
-
const selectedAvailabilityBranches = Object.keys(branchAvailability);
|
|
3889
|
-
const allBranches = settings.allBranches !== false;
|
|
3890
|
-
const useBranchPricing = settings.useBranchPricing === true;
|
|
3891
|
-
const useBranchDiscounts = settings.useBranchDiscounts === true;
|
|
3892
|
-
useEffect(() => {
|
|
3893
|
-
let active = true;
|
|
3894
|
-
setLoading(true);
|
|
3895
|
-
setLoadError("");
|
|
3896
|
-
ctx.adapter.listEntries(collectionId).then((entries) => {
|
|
3897
|
-
if (active) setBranches(entries);
|
|
3898
|
-
}).catch((error) => {
|
|
3899
|
-
console.error("Could not load branches for product settings:", error);
|
|
3900
|
-
if (active) setLoadError("No se pudieron cargar las sedes.");
|
|
3901
|
-
}).finally(() => {
|
|
3902
|
-
if (active) setLoading(false);
|
|
3903
|
-
});
|
|
3904
|
-
return () => {
|
|
3905
|
-
active = false;
|
|
3906
|
-
};
|
|
3907
|
-
}, [collectionId, ctx.adapter]);
|
|
3908
|
-
const getBranchName = (branch) => String(branch.name || branch.id);
|
|
3909
|
-
const updateSettings = (patch) => {
|
|
3910
|
-
onChange({
|
|
3911
|
-
allBranches,
|
|
3912
|
-
branches: selectedBranches,
|
|
3913
|
-
useBranchPricing,
|
|
3914
|
-
priceBranches: selectedPriceBranches,
|
|
3915
|
-
prices: { ...prices },
|
|
3916
|
-
useBranchDiscounts,
|
|
3917
|
-
discountBranches: selectedDiscountBranches,
|
|
3918
|
-
discounts: { ...discounts },
|
|
3919
|
-
branchAvailability: { ...branchAvailability },
|
|
3920
|
-
...patch
|
|
3921
|
-
});
|
|
3922
|
-
};
|
|
3923
|
-
const updateBranchAvailability = (name, start, end) => {
|
|
3924
|
-
updateSettings({
|
|
3925
|
-
branchAvailability: {
|
|
3926
|
-
...branchAvailability,
|
|
3927
|
-
[name]: {
|
|
3928
|
-
start: toStoredTime(start),
|
|
3929
|
-
end: toStoredTime(end)
|
|
3930
|
-
}
|
|
3931
|
-
}
|
|
3932
|
-
});
|
|
3933
|
-
};
|
|
3934
|
-
const updateBranchPrice = (name, value2) => {
|
|
3935
|
-
const nextPrices = { ...prices };
|
|
3936
|
-
if (value2.trim() === "") {
|
|
3937
|
-
delete nextPrices[name];
|
|
3938
|
-
} else {
|
|
3939
|
-
const parsed = Number(value2);
|
|
3940
|
-
if (Number.isFinite(parsed) && parsed >= 0) nextPrices[name] = parsed;
|
|
3941
|
-
}
|
|
3942
|
-
updateSettings({ prices: nextPrices });
|
|
3943
|
-
};
|
|
3944
|
-
const updateBranchDiscount = (name, value2) => {
|
|
3945
|
-
const nextDiscounts = { ...discounts };
|
|
3946
|
-
if (value2.trim() === "") {
|
|
3947
|
-
delete nextDiscounts[name];
|
|
3948
|
-
} else {
|
|
3949
|
-
const parsed = Number(value2);
|
|
3950
|
-
if (Number.isFinite(parsed) && parsed >= 0 && parsed <= 100) {
|
|
3951
|
-
nextDiscounts[name] = parsed;
|
|
3952
|
-
}
|
|
3953
|
-
}
|
|
3954
|
-
updateSettings({ discounts: nextDiscounts });
|
|
3955
|
-
};
|
|
3956
|
-
return /* @__PURE__ */ jsxs("div", { className: "space-y-4 rounded-xl border border-slate-200 bg-slate-50/50 p-4", children: [
|
|
3957
|
-
/* @__PURE__ */ jsxs("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
|
|
3958
|
-
/* @__PURE__ */ jsx(
|
|
3959
|
-
"input",
|
|
3960
|
-
{
|
|
3961
|
-
type: "checkbox",
|
|
3962
|
-
checked: allBranches,
|
|
3963
|
-
onChange: (event) => updateSettings({ allBranches: event.target.checked }),
|
|
3964
|
-
className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
3965
|
-
}
|
|
3966
|
-
),
|
|
3967
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
3968
|
-
/* @__PURE__ */ jsx("span", { className: "block font-semibold", children: "Disponible en todas las sedes" }),
|
|
3969
|
-
/* @__PURE__ */ jsx("span", { className: "mt-0.5 block text-xs text-slate-500", children: "Desactiva esta opci\xF3n para elegir una o varias sedes." })
|
|
3970
|
-
] })
|
|
3971
|
-
] }),
|
|
3972
|
-
!allBranches && /* @__PURE__ */ jsx(
|
|
3973
|
-
SearchableMultiSelect,
|
|
3974
|
-
{
|
|
3975
|
-
options: branches.map((branch) => ({
|
|
3976
|
-
value: getBranchName(branch),
|
|
3977
|
-
label: getBranchName(branch)
|
|
3978
|
-
})),
|
|
3979
|
-
value: selectedBranches,
|
|
3980
|
-
onChange: (next) => updateSettings({ branches: next }),
|
|
3981
|
-
loading,
|
|
3982
|
-
error: loadError,
|
|
3983
|
-
placeholder: "Seleccionar sedes...",
|
|
3984
|
-
searchPlaceholder: "Buscar sede...",
|
|
3985
|
-
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
3986
|
-
}
|
|
3987
|
-
),
|
|
3988
|
-
/* @__PURE__ */ jsxs("div", { className: "border-t border-slate-200 pt-4", children: [
|
|
3989
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-slate-700", children: "Horario diferente por sede (opcional)" }),
|
|
3990
|
-
/* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-slate-500", children: "Deja ambas horas vac\xEDas para heredar el horario general. Si defines una hora, el horario de esa sede reemplaza por completo al general." }),
|
|
3991
|
-
/* @__PURE__ */ jsx("div", { className: "mt-3", children: /* @__PURE__ */ jsx(
|
|
3992
|
-
SearchableMultiSelect,
|
|
3993
|
-
{
|
|
3994
|
-
options: branches.map((branch) => ({
|
|
3995
|
-
value: getBranchName(branch),
|
|
3996
|
-
label: getBranchName(branch)
|
|
3997
|
-
})),
|
|
3998
|
-
value: selectedAvailabilityBranches,
|
|
3999
|
-
onChange: (next) => {
|
|
4000
|
-
const nextSchedules = Object.fromEntries(
|
|
4001
|
-
next.map((name) => [
|
|
4002
|
-
name,
|
|
4003
|
-
branchAvailability[name] ?? { start: "", end: "" }
|
|
4004
|
-
])
|
|
4005
|
-
);
|
|
4006
|
-
updateSettings({ branchAvailability: nextSchedules });
|
|
4007
|
-
},
|
|
4008
|
-
loading,
|
|
4009
|
-
error: loadError,
|
|
4010
|
-
placeholder: "Buscar sedes para configurar su horario...",
|
|
4011
|
-
searchPlaceholder: "Buscar sede...",
|
|
4012
|
-
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
4013
|
-
}
|
|
4014
|
-
) }),
|
|
4015
|
-
/* @__PURE__ */ jsx("div", { className: "mt-3 space-y-2", children: branches.filter(
|
|
4016
|
-
(branch) => selectedAvailabilityBranches.includes(getBranchName(branch))
|
|
4017
|
-
).map((branch) => {
|
|
4018
|
-
const name = getBranchName(branch);
|
|
4019
|
-
const schedule = branchAvailability[name] ?? {};
|
|
4020
|
-
return /* @__PURE__ */ jsxs(
|
|
4021
|
-
"div",
|
|
4022
|
-
{
|
|
4023
|
-
className: "space-y-3 rounded-lg border border-slate-200 bg-white p-3",
|
|
4024
|
-
children: [
|
|
4025
|
-
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
|
|
4026
|
-
/* @__PURE__ */ jsx("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
|
|
4027
|
-
/* @__PURE__ */ jsx(
|
|
4028
|
-
"button",
|
|
4029
|
-
{
|
|
4030
|
-
type: "button",
|
|
4031
|
-
onClick: () => {
|
|
4032
|
-
const nextSchedules = { ...branchAvailability };
|
|
4033
|
-
delete nextSchedules[name];
|
|
4034
|
-
updateSettings({ branchAvailability: nextSchedules });
|
|
4035
|
-
},
|
|
4036
|
-
"aria-label": `Quitar horario de ${name}`,
|
|
4037
|
-
title: `Quitar horario de ${name}`,
|
|
4038
|
-
className: "inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:border-red-200 hover:bg-red-50 hover:text-red-700",
|
|
4039
|
-
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
4040
|
-
}
|
|
4041
|
-
)
|
|
4042
|
-
] }),
|
|
4043
|
-
/* @__PURE__ */ jsx(
|
|
4044
|
-
AdminTimeRangePicker,
|
|
4045
|
-
{
|
|
4046
|
-
value: [
|
|
4047
|
-
toDayjsTime(schedule.start),
|
|
4048
|
-
toDayjsTime(schedule.end)
|
|
4049
|
-
],
|
|
4050
|
-
onChange: (times) => updateBranchAvailability(
|
|
4051
|
-
name,
|
|
4052
|
-
times?.[0] ?? null,
|
|
4053
|
-
times?.[1] ?? null
|
|
4054
|
-
),
|
|
4055
|
-
allowEmpty: [true, true],
|
|
4056
|
-
className: "w-full",
|
|
4057
|
-
format: TIME_DISPLAY_FORMAT,
|
|
4058
|
-
order: false,
|
|
4059
|
-
placeholder: ["Hora de inicio", "Hora de cierre"],
|
|
4060
|
-
use12Hours: true
|
|
4061
|
-
}
|
|
4062
|
-
)
|
|
4063
|
-
]
|
|
4064
|
-
},
|
|
4065
|
-
branch.id
|
|
4066
|
-
);
|
|
4067
|
-
}) })
|
|
4068
|
-
] }),
|
|
4069
|
-
/* @__PURE__ */ jsxs("div", { className: "border-t border-slate-200 pt-4", children: [
|
|
4070
|
-
/* @__PURE__ */ jsxs("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
|
|
4071
|
-
/* @__PURE__ */ jsx(
|
|
4072
|
-
"input",
|
|
4073
|
-
{
|
|
4074
|
-
type: "checkbox",
|
|
4075
|
-
checked: useBranchPricing,
|
|
4076
|
-
onChange: (event) => updateSettings({ useBranchPricing: event.target.checked }),
|
|
4077
|
-
className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
4078
|
-
}
|
|
4079
|
-
),
|
|
4080
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
4081
|
-
/* @__PURE__ */ jsx("span", { className: "block font-semibold", children: "Usar precio diferente por sede" }),
|
|
4082
|
-
/* @__PURE__ */ jsx("span", { className: "mt-0.5 block text-xs text-slate-500", children: "El precio global se usa como base; deja una sede vac\xEDa para conservarlo." })
|
|
4083
|
-
] })
|
|
4084
|
-
] }),
|
|
4085
|
-
useBranchPricing && /* @__PURE__ */ jsx("div", { className: "mt-3 space-y-2", children: loading ? /* @__PURE__ */ jsx("p", { className: "py-2 text-center text-xs text-slate-400", children: "Cargando sedes..." }) : loadError ? /* @__PURE__ */ jsx("p", { role: "alert", className: "py-2 text-center text-xs text-red-600", children: loadError }) : branches.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-2 text-center text-xs text-slate-400", children: "Agrega sedes a la colecci\xF3n antes de definir precios." }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4086
|
-
/* @__PURE__ */ jsxs("p", { className: "text-xs text-slate-500", children: [
|
|
4087
|
-
"Precio global actual: $",
|
|
4088
|
-
globalPrice.toLocaleString("es-CO")
|
|
4089
|
-
] }),
|
|
4090
|
-
/* @__PURE__ */ jsx(
|
|
4091
|
-
SearchableMultiSelect,
|
|
4092
|
-
{
|
|
4093
|
-
options: branches.map((branch) => ({
|
|
4094
|
-
value: getBranchName(branch),
|
|
4095
|
-
label: getBranchName(branch)
|
|
4096
|
-
})),
|
|
4097
|
-
value: selectedPriceBranches,
|
|
4098
|
-
onChange: (next) => {
|
|
4099
|
-
const removed = selectedPriceBranches.filter(
|
|
4100
|
-
(name) => !next.includes(name)
|
|
4101
|
-
);
|
|
4102
|
-
const nextPrices = { ...prices };
|
|
4103
|
-
removed.forEach((name) => delete nextPrices[name]);
|
|
4104
|
-
updateSettings({
|
|
4105
|
-
priceBranches: next,
|
|
4106
|
-
prices: nextPrices
|
|
4107
|
-
});
|
|
4108
|
-
},
|
|
4109
|
-
loading,
|
|
4110
|
-
error: loadError,
|
|
4111
|
-
placeholder: "Buscar y agregar sedes...",
|
|
4112
|
-
searchPlaceholder: "Buscar sede...",
|
|
4113
|
-
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
4114
|
-
}
|
|
4115
|
-
),
|
|
4116
|
-
branches.filter(
|
|
4117
|
-
(branch) => selectedPriceBranches.includes(getBranchName(branch))
|
|
4118
|
-
).map((branch) => {
|
|
4119
|
-
const name = getBranchName(branch);
|
|
4120
|
-
return /* @__PURE__ */ jsxs(
|
|
4121
|
-
"div",
|
|
4122
|
-
{
|
|
4123
|
-
className: "space-y-2 rounded-lg border border-slate-200 bg-white p-3",
|
|
4124
|
-
children: [
|
|
4125
|
-
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
|
|
4126
|
-
/* @__PURE__ */ jsx("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
|
|
4127
|
-
/* @__PURE__ */ jsx(
|
|
4128
|
-
"button",
|
|
4129
|
-
{
|
|
4130
|
-
type: "button",
|
|
4131
|
-
onClick: () => {
|
|
4132
|
-
const nextPrices = { ...prices };
|
|
4133
|
-
delete nextPrices[name];
|
|
4134
|
-
updateSettings({
|
|
4135
|
-
priceBranches: selectedPriceBranches.filter(
|
|
4136
|
-
(selected) => selected !== name
|
|
4137
|
-
),
|
|
4138
|
-
prices: nextPrices
|
|
4139
|
-
});
|
|
4140
|
-
},
|
|
4141
|
-
"aria-label": `Quitar ${name} de precios por sede`,
|
|
4142
|
-
title: `Quitar ${name}`,
|
|
4143
|
-
className: "inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:border-red-200 hover:bg-red-50 hover:text-red-700",
|
|
4144
|
-
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
4145
|
-
}
|
|
4146
|
-
)
|
|
4147
|
-
] }),
|
|
4148
|
-
/* @__PURE__ */ jsxs("label", { className: "block w-full", children: [
|
|
4149
|
-
/* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
|
|
4150
|
-
"Precio para ",
|
|
4151
|
-
name
|
|
4152
|
-
] }),
|
|
4153
|
-
/* @__PURE__ */ jsx(
|
|
4154
|
-
FormattedNumberInput,
|
|
4155
|
-
{
|
|
4156
|
-
value: prices[name] ?? "",
|
|
4157
|
-
onChange: (price) => updateBranchPrice(
|
|
4158
|
-
name,
|
|
4159
|
-
price === null ? "" : String(price)
|
|
4160
|
-
),
|
|
4161
|
-
isPrice: true,
|
|
4162
|
-
allowEmpty: true,
|
|
4163
|
-
placeholder: String(globalPrice),
|
|
4164
|
-
className: "bg-white text-right",
|
|
4165
|
-
containerClassName: "w-full"
|
|
4166
|
-
}
|
|
4167
|
-
)
|
|
4168
|
-
] })
|
|
4169
|
-
]
|
|
4170
|
-
},
|
|
4171
|
-
branch.id
|
|
4172
|
-
);
|
|
4173
|
-
})
|
|
4174
|
-
] }) })
|
|
4175
|
-
] }),
|
|
4176
|
-
/* @__PURE__ */ jsxs("div", { className: "border-t border-slate-200 pt-4", children: [
|
|
4177
|
-
/* @__PURE__ */ jsxs("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
|
|
4178
|
-
/* @__PURE__ */ jsx(
|
|
4179
|
-
"input",
|
|
4180
|
-
{
|
|
4181
|
-
type: "checkbox",
|
|
4182
|
-
checked: useBranchDiscounts,
|
|
4183
|
-
onChange: (event) => updateSettings({ useBranchDiscounts: event.target.checked }),
|
|
4184
|
-
className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
4185
|
-
}
|
|
4186
|
-
),
|
|
4187
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
4188
|
-
/* @__PURE__ */ jsx("span", { className: "block font-semibold", children: "Usar descuento diferente por sede" }),
|
|
4189
|
-
/* @__PURE__ */ jsx("span", { className: "mt-0.5 block text-xs text-slate-500", children: "El descuento global aplica como base; una sede vac\xEDa hereda ese porcentaje." })
|
|
4190
|
-
] })
|
|
4191
|
-
] }),
|
|
4192
|
-
useBranchDiscounts && /* @__PURE__ */ jsx("div", { className: "mt-3 space-y-2", children: loading ? /* @__PURE__ */ jsx("p", { className: "py-2 text-center text-xs text-slate-400", children: "Cargando sedes..." }) : loadError ? /* @__PURE__ */ jsx("p", { role: "alert", className: "py-2 text-center text-xs text-red-600", children: loadError }) : branches.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-2 text-center text-xs text-slate-400", children: "Agrega sedes a la colecci\xF3n antes de definir descuentos." }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4193
|
-
/* @__PURE__ */ jsxs("p", { className: "text-xs text-slate-500", children: [
|
|
4194
|
-
"Descuento global actual: ",
|
|
4195
|
-
globalDiscount,
|
|
4196
|
-
"%"
|
|
4197
|
-
] }),
|
|
4198
|
-
/* @__PURE__ */ jsx(
|
|
4199
|
-
SearchableMultiSelect,
|
|
4200
|
-
{
|
|
4201
|
-
options: branches.map((branch) => ({
|
|
4202
|
-
value: getBranchName(branch),
|
|
4203
|
-
label: getBranchName(branch)
|
|
4204
|
-
})),
|
|
4205
|
-
value: selectedDiscountBranches,
|
|
4206
|
-
onChange: (next) => {
|
|
4207
|
-
const removed = selectedDiscountBranches.filter(
|
|
4208
|
-
(name) => !next.includes(name)
|
|
4209
|
-
);
|
|
4210
|
-
const nextDiscounts = { ...discounts };
|
|
4211
|
-
removed.forEach((name) => delete nextDiscounts[name]);
|
|
4212
|
-
updateSettings({
|
|
4213
|
-
discountBranches: next,
|
|
4214
|
-
discounts: nextDiscounts
|
|
4215
|
-
});
|
|
4216
|
-
},
|
|
4217
|
-
loading,
|
|
4218
|
-
error: loadError,
|
|
4219
|
-
placeholder: "Buscar y agregar sedes...",
|
|
4220
|
-
searchPlaceholder: "Buscar sede...",
|
|
4221
|
-
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
4222
|
-
}
|
|
4223
|
-
),
|
|
4224
|
-
branches.filter(
|
|
4225
|
-
(branch) => selectedDiscountBranches.includes(getBranchName(branch))
|
|
4226
|
-
).map((branch) => {
|
|
4227
|
-
const name = getBranchName(branch);
|
|
4228
|
-
return /* @__PURE__ */ jsxs(
|
|
4229
|
-
"div",
|
|
4230
|
-
{
|
|
4231
|
-
className: "space-y-2 rounded-lg border border-slate-200 bg-white p-3",
|
|
4232
|
-
children: [
|
|
4233
|
-
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
|
|
4234
|
-
/* @__PURE__ */ jsx("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
|
|
4235
|
-
/* @__PURE__ */ jsx(
|
|
4236
|
-
"button",
|
|
4237
|
-
{
|
|
4238
|
-
type: "button",
|
|
4239
|
-
onClick: () => {
|
|
4240
|
-
const nextDiscounts = { ...discounts };
|
|
4241
|
-
delete nextDiscounts[name];
|
|
4242
|
-
updateSettings({
|
|
4243
|
-
discountBranches: selectedDiscountBranches.filter(
|
|
4244
|
-
(selected) => selected !== name
|
|
4245
|
-
),
|
|
4246
|
-
discounts: nextDiscounts
|
|
4247
|
-
});
|
|
4248
|
-
},
|
|
4249
|
-
"aria-label": `Quitar descuento de ${name}`,
|
|
4250
|
-
title: `Quitar ${name}`,
|
|
4251
|
-
className: "inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:border-red-200 hover:bg-red-50 hover:text-red-700",
|
|
4252
|
-
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
4253
|
-
}
|
|
4254
|
-
)
|
|
4255
|
-
] }),
|
|
4256
|
-
/* @__PURE__ */ jsxs("label", { className: "block w-full", children: [
|
|
4257
|
-
/* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
|
|
4258
|
-
"Descuento para ",
|
|
4259
|
-
name
|
|
4260
|
-
] }),
|
|
4261
|
-
/* @__PURE__ */ jsx(
|
|
4262
|
-
FormattedNumberInput,
|
|
4263
|
-
{
|
|
4264
|
-
value: discounts[name] ?? "",
|
|
4265
|
-
onChange: (discount) => updateBranchDiscount(
|
|
4266
|
-
name,
|
|
4267
|
-
discount === null ? "" : String(discount)
|
|
4268
|
-
),
|
|
4269
|
-
isPercent: true,
|
|
4270
|
-
allowEmpty: true,
|
|
4271
|
-
placeholder: String(globalDiscount),
|
|
4272
|
-
className: "bg-white text-right",
|
|
4273
|
-
containerClassName: "w-full"
|
|
4274
|
-
}
|
|
4275
|
-
)
|
|
4276
|
-
] })
|
|
4277
|
-
]
|
|
4278
|
-
},
|
|
4279
|
-
branch.id
|
|
4280
|
-
);
|
|
4281
|
-
})
|
|
4282
|
-
] }) })
|
|
4283
|
-
] })
|
|
4284
|
-
] });
|
|
4285
|
-
}
|
|
4286
|
-
function BranchSettingsSummary({ value }) {
|
|
4287
|
-
if (!value || typeof value !== "object") return /* @__PURE__ */ jsx("span", { children: "Todas las sedes" });
|
|
4288
|
-
const settings = value;
|
|
4289
|
-
const names = Array.isArray(settings.branches) ? settings.branches : [];
|
|
4290
|
-
const locationSummary = settings.allBranches === false ? names.length > 0 ? names.join(", ") : "Sin sedes" : "Todas las sedes";
|
|
4291
|
-
const pricingSummary = settings.useBranchPricing ? " \xB7 Precio por sede" : " \xB7 Precio global";
|
|
4292
|
-
return /* @__PURE__ */ jsx("span", { children: locationSummary + pricingSummary });
|
|
4293
|
-
}
|
|
4294
5351
|
function SearchableMultiSelect({
|
|
4295
5352
|
options,
|
|
4296
5353
|
value,
|
|
@@ -4443,32 +5500,40 @@ function SearchableMultiSelect({
|
|
|
4443
5500
|
] })
|
|
4444
5501
|
] })
|
|
4445
5502
|
] }),
|
|
4446
|
-
/* @__PURE__ */ jsx(
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
"
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
"
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
5503
|
+
/* @__PURE__ */ jsx(
|
|
5504
|
+
"div",
|
|
5505
|
+
{
|
|
5506
|
+
role: "listbox",
|
|
5507
|
+
"aria-multiselectable": "true",
|
|
5508
|
+
className: "max-h-56 overflow-y-auto p-2",
|
|
5509
|
+
children: loading ? /* @__PURE__ */ jsx("p", { className: "py-4 text-center text-xs text-slate-400", children: "Cargando opciones..." }) : error ? /* @__PURE__ */ jsx("p", { role: "alert", className: "py-4 text-center text-xs text-red-600", children: error }) : visibleOptions.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-4 text-center text-xs text-slate-400", children: options.length === 0 ? emptyMessage : "No hay resultados para la b\xFAsqueda." }) : /* @__PURE__ */ jsx("div", { className: "space-y-1", children: visibleOptions.map((option) => {
|
|
5510
|
+
const isSelected = value.includes(option.value);
|
|
5511
|
+
const isAtMax = !!max && value.length >= max && !isSelected;
|
|
5512
|
+
return /* @__PURE__ */ jsxs(
|
|
5513
|
+
"button",
|
|
5514
|
+
{
|
|
5515
|
+
type: "button",
|
|
5516
|
+
role: "option",
|
|
5517
|
+
"aria-selected": isSelected,
|
|
5518
|
+
disabled: isAtMax,
|
|
5519
|
+
onClick: () => toggleOption(option.value),
|
|
5520
|
+
className: `flex w-full items-center gap-2.5 rounded-lg px-3 py-2.5 text-left text-sm transition-colors ${isSelected ? "bg-indigo-50 font-semibold text-indigo-900" : "text-slate-700 hover:bg-slate-50"} disabled:cursor-not-allowed disabled:opacity-50`,
|
|
5521
|
+
children: [
|
|
5522
|
+
/* @__PURE__ */ jsx(
|
|
5523
|
+
"span",
|
|
5524
|
+
{
|
|
5525
|
+
className: `flex h-4 w-4 shrink-0 items-center justify-center rounded border ${isSelected ? "border-indigo-600 bg-indigo-600 text-white" : "border-slate-300 bg-white"}`,
|
|
5526
|
+
children: isSelected && /* @__PURE__ */ jsx(Check, { className: "h-3 w-3" })
|
|
5527
|
+
}
|
|
5528
|
+
),
|
|
5529
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: option.label })
|
|
5530
|
+
]
|
|
5531
|
+
},
|
|
5532
|
+
option.value
|
|
5533
|
+
);
|
|
5534
|
+
}) })
|
|
5535
|
+
}
|
|
5536
|
+
)
|
|
4472
5537
|
] })
|
|
4473
5538
|
] });
|
|
4474
5539
|
}
|
|
@@ -4494,19 +5559,29 @@ function ReferenceSelect({
|
|
|
4494
5559
|
const [formError, setFormError] = useState("");
|
|
4495
5560
|
const [newRecord, setNewRecord] = useState({});
|
|
4496
5561
|
const targetCol = ctx.config.collections?.find((c) => c.id === collectionId);
|
|
5562
|
+
const normalizeSearchValue = (field, value2) => {
|
|
5563
|
+
const text = String(value2 ?? "").normalize("NFD").replace(/[\u0300-\u036f]/g, "").trim().toLocaleLowerCase();
|
|
5564
|
+
return /phone|telefono|teléfono/i.test(field) ? text.replace(/\D/g, "") : text.replace(/\s+/g, " ");
|
|
5565
|
+
};
|
|
4497
5566
|
const handleSaveRecord = async () => {
|
|
4498
5567
|
setFormError("");
|
|
4499
5568
|
if (!targetCol) return;
|
|
4500
|
-
const uniqueFields = targetCol.fields.filter(
|
|
5569
|
+
const uniqueFields = targetCol.fields.filter(
|
|
5570
|
+
(f) => f.unique || f.id === "id" && !f.hideOnCreate
|
|
5571
|
+
);
|
|
4501
5572
|
for (const uf of uniqueFields) {
|
|
4502
5573
|
const val = String(newRecord[uf.id] || "").trim();
|
|
4503
5574
|
if (!val) {
|
|
4504
5575
|
setFormError(`El campo "${uf.label || uf.id}" es obligatorio.`);
|
|
4505
5576
|
return;
|
|
4506
5577
|
}
|
|
4507
|
-
const isDup = options.some(
|
|
5578
|
+
const isDup = options.some(
|
|
5579
|
+
(opt) => String(opt.value || "").trim().toLowerCase() === val.toLowerCase()
|
|
5580
|
+
);
|
|
4508
5581
|
if (isDup) {
|
|
4509
|
-
setFormError(
|
|
5582
|
+
setFormError(
|
|
5583
|
+
`Ya existe un registro con este ${uf.label.toLowerCase()} (\xAB${val}\xBB).`
|
|
5584
|
+
);
|
|
4510
5585
|
return;
|
|
4511
5586
|
}
|
|
4512
5587
|
}
|
|
@@ -4533,21 +5608,35 @@ function ReferenceSelect({
|
|
|
4533
5608
|
const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
|
|
4534
5609
|
const fullName = r.apellido ? `${r.nombre || r.name || ""} ${r.apellido}`.trim() : "";
|
|
4535
5610
|
const lab = fullName || String(r[displayField] || r.name || r.id);
|
|
5611
|
+
const searchText = [
|
|
5612
|
+
lab,
|
|
5613
|
+
val,
|
|
5614
|
+
...(targetCol.searchBy || []).map((field) => String(r[field] ?? ""))
|
|
5615
|
+
].filter(Boolean).join(" ");
|
|
4536
5616
|
return {
|
|
4537
5617
|
value: val,
|
|
4538
|
-
label: val && val !== lab ? `${lab} (${val})` : lab,
|
|
5618
|
+
label: val && val !== lab && val.length < 20 ? `${lab} (${val})` : lab,
|
|
5619
|
+
searchText,
|
|
4539
5620
|
raw: r
|
|
4540
5621
|
};
|
|
4541
5622
|
});
|
|
4542
5623
|
setOptions(fromCollection);
|
|
4543
|
-
const
|
|
5624
|
+
const persistedEntry = (res || []).find((record) => record.id === entryToSave.id) || (res || []).find(
|
|
5625
|
+
(record) => (targetCol.searchBy || []).some((field) => {
|
|
5626
|
+
const requested = normalizeSearchValue(field, entryToSave[field]);
|
|
5627
|
+
return requested && requested === normalizeSearchValue(field, record[field]);
|
|
5628
|
+
})
|
|
5629
|
+
) || entryToSave;
|
|
5630
|
+
const selectedVal = valueField && persistedEntry[valueField] !== void 0 ? String(persistedEntry[valueField]) : persistedEntry.id;
|
|
4544
5631
|
onChange(selectedVal);
|
|
4545
5632
|
if (onSelectRecord) {
|
|
4546
|
-
onSelectRecord(
|
|
5633
|
+
onSelectRecord(persistedEntry);
|
|
4547
5634
|
}
|
|
4548
5635
|
setModalOpen(false);
|
|
4549
5636
|
setNewRecord({});
|
|
4550
|
-
message.success(
|
|
5637
|
+
message.success(
|
|
5638
|
+
t.recordCreatedSuccess || "Registro creado y seleccionado exitosamente."
|
|
5639
|
+
);
|
|
4551
5640
|
} catch (err) {
|
|
4552
5641
|
setFormError(err?.message || "Error al crear registro.");
|
|
4553
5642
|
} finally {
|
|
@@ -4557,7 +5646,11 @@ function ReferenceSelect({
|
|
|
4557
5646
|
useEffect(() => {
|
|
4558
5647
|
if (!collectionId) {
|
|
4559
5648
|
if (fallbackOptions && fallbackOptions.length > 0) {
|
|
4560
|
-
setOptions(
|
|
5649
|
+
setOptions(
|
|
5650
|
+
fallbackOptions.map(
|
|
5651
|
+
(opt) => typeof opt === "string" ? { value: opt, label: opt } : opt
|
|
5652
|
+
)
|
|
5653
|
+
);
|
|
4561
5654
|
}
|
|
4562
5655
|
setLoading(false);
|
|
4563
5656
|
return;
|
|
@@ -4568,18 +5661,31 @@ function ReferenceSelect({
|
|
|
4568
5661
|
const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
|
|
4569
5662
|
const fullName = r.apellido ? `${r.nombre || r.name || ""} ${r.apellido}`.trim() : "";
|
|
4570
5663
|
const lab = fullName || String(r[displayField] || r.name || r.id);
|
|
5664
|
+
const searchText = [
|
|
5665
|
+
lab,
|
|
5666
|
+
val,
|
|
5667
|
+
...(targetCol?.searchBy || []).map((field) => String(r[field] ?? ""))
|
|
5668
|
+
].filter(Boolean).join(" ");
|
|
4571
5669
|
return {
|
|
4572
5670
|
value: val,
|
|
4573
|
-
label: val && val !== lab ? `${lab} (${val})` : lab,
|
|
5671
|
+
label: val && val !== lab && val.length < 20 ? `${lab} (${val})` : lab,
|
|
5672
|
+
searchText,
|
|
4574
5673
|
raw: r
|
|
4575
5674
|
};
|
|
4576
5675
|
});
|
|
4577
5676
|
setOptions(fromCollection);
|
|
4578
5677
|
setLoading(false);
|
|
4579
5678
|
}).catch((err) => {
|
|
4580
|
-
console.error(
|
|
5679
|
+
console.error(
|
|
5680
|
+
`Failed to load reference entries for ${collectionId}:`,
|
|
5681
|
+
err
|
|
5682
|
+
);
|
|
4581
5683
|
if (fallbackOptions && fallbackOptions.length > 0) {
|
|
4582
|
-
setOptions(
|
|
5684
|
+
setOptions(
|
|
5685
|
+
fallbackOptions.map(
|
|
5686
|
+
(opt) => typeof opt === "string" ? { value: opt, label: opt } : opt
|
|
5687
|
+
)
|
|
5688
|
+
);
|
|
4583
5689
|
}
|
|
4584
5690
|
setLoading(false);
|
|
4585
5691
|
});
|
|
@@ -4593,85 +5699,67 @@ function ReferenceSelect({
|
|
|
4593
5699
|
}
|
|
4594
5700
|
return list;
|
|
4595
5701
|
}, [options, singleVal]);
|
|
4596
|
-
const canQuickCreate = Boolean(
|
|
5702
|
+
const canQuickCreate = Boolean(
|
|
5703
|
+
targetCol && targetCol.enableQuickCreate !== false
|
|
5704
|
+
);
|
|
4597
5705
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4598
|
-
/* @__PURE__ */
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
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
|
-
|
|
4651
|
-
}
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
{
|
|
4656
|
-
type: "primary",
|
|
4657
|
-
size: "large",
|
|
4658
|
-
icon: /* @__PURE__ */ jsx(Plus, { className: "w-4 h-4" }),
|
|
4659
|
-
onClick: () => {
|
|
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);
|
|
4669
|
-
},
|
|
4670
|
-
className: "bg-blue-600 hover:bg-blue-700 font-bold rounded-xl shrink-0 h-10 px-4 text-xs uppercase tracking-wider",
|
|
4671
|
-
children: targetCol.submitLabel || t.newBtn
|
|
4672
|
-
}
|
|
4673
|
-
)
|
|
4674
|
-
] }),
|
|
5706
|
+
/* @__PURE__ */ jsx("div", { className: "w-full", children: /* @__PURE__ */ jsx(
|
|
5707
|
+
Select,
|
|
5708
|
+
{
|
|
5709
|
+
size: "large",
|
|
5710
|
+
loading,
|
|
5711
|
+
showSearch: searchable,
|
|
5712
|
+
placeholder: loading ? t.loadingOptions : t.selectOption,
|
|
5713
|
+
allowClear: true,
|
|
5714
|
+
filterOption: (input, option) => {
|
|
5715
|
+
if (!input) return true;
|
|
5716
|
+
const q = input.toLowerCase();
|
|
5717
|
+
const label = String(option?.label ?? "").toLowerCase();
|
|
5718
|
+
const val = String(option?.value ?? "").toLowerCase();
|
|
5719
|
+
const searchText = String(option?.searchText ?? "").toLowerCase();
|
|
5720
|
+
return label.includes(q) || val.includes(q) || searchText.includes(q);
|
|
5721
|
+
},
|
|
5722
|
+
value: singleVal,
|
|
5723
|
+
onChange: (v) => {
|
|
5724
|
+
onChange(v || "");
|
|
5725
|
+
if (onSelectRecord) {
|
|
5726
|
+
const found = options.find((o) => o.value === v);
|
|
5727
|
+
if (found?.raw) onSelectRecord(found.raw);
|
|
5728
|
+
}
|
|
5729
|
+
},
|
|
5730
|
+
options: displayOptions,
|
|
5731
|
+
dropdownRender: (menu) => /* @__PURE__ */ jsxs("div", { children: [
|
|
5732
|
+
menu,
|
|
5733
|
+
canQuickCreate && /* @__PURE__ */ jsxs("div", { className: "p-2 border-t border-slate-100 flex items-center justify-between bg-slate-50", children: [
|
|
5734
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-slate-500 font-medium", children: t.cantFindOption || "\xBFNo encuentras la opci\xF3n?" }),
|
|
5735
|
+
/* @__PURE__ */ jsx(
|
|
5736
|
+
Button,
|
|
5737
|
+
{
|
|
5738
|
+
type: "primary",
|
|
5739
|
+
size: "small",
|
|
5740
|
+
icon: /* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
|
|
5741
|
+
onClick: () => {
|
|
5742
|
+
setFormError("");
|
|
5743
|
+
const init = {};
|
|
5744
|
+
targetCol.fields.forEach((f) => {
|
|
5745
|
+
if (f.defaultValue !== void 0)
|
|
5746
|
+
init[f.id] = f.defaultValue;
|
|
5747
|
+
else if (f.type === "list" || f.multiple)
|
|
5748
|
+
init[f.id] = [""];
|
|
5749
|
+
else init[f.id] = "";
|
|
5750
|
+
});
|
|
5751
|
+
setNewRecord(init);
|
|
5752
|
+
setModalOpen(true);
|
|
5753
|
+
},
|
|
5754
|
+
className: "bg-blue-600 hover:bg-blue-700 text-xs font-semibold rounded-lg shadow-sm",
|
|
5755
|
+
children: t.createNewOption || `Crear ${targetCol.name}`
|
|
5756
|
+
}
|
|
5757
|
+
)
|
|
5758
|
+
] })
|
|
5759
|
+
] }),
|
|
5760
|
+
className: "w-full"
|
|
5761
|
+
}
|
|
5762
|
+
) }),
|
|
4675
5763
|
canQuickCreate && /* @__PURE__ */ jsx(
|
|
4676
5764
|
Modal,
|
|
4677
5765
|
{
|
|
@@ -4682,7 +5770,9 @@ function ReferenceSelect({
|
|
|
4682
5770
|
width: 650,
|
|
4683
5771
|
footer: null,
|
|
4684
5772
|
children: /* @__PURE__ */ jsxs("div", { className: "pt-2 space-y-4", children: [
|
|
4685
|
-
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: targetCol.fields.filter(
|
|
5773
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: targetCol.fields.filter(
|
|
5774
|
+
(f) => !f.hideOnCreate && !f.readOnly && f.type !== "signature"
|
|
5775
|
+
).map((f) => {
|
|
4686
5776
|
if (f.dependsOn && newRecord[f.dependsOn.field] !== void 0) {
|
|
4687
5777
|
const targetVal = f.dependsOn.value;
|
|
4688
5778
|
const currentVal = newRecord[f.dependsOn.field];
|
|
@@ -4711,7 +5801,10 @@ function ReferenceSelect({
|
|
|
4711
5801
|
onChange: (e) => {
|
|
4712
5802
|
const updated = [...currentList];
|
|
4713
5803
|
updated[idx] = e.target.value;
|
|
4714
|
-
setNewRecord((prev) => ({
|
|
5804
|
+
setNewRecord((prev) => ({
|
|
5805
|
+
...prev,
|
|
5806
|
+
[f.id]: updated
|
|
5807
|
+
}));
|
|
4715
5808
|
}
|
|
4716
5809
|
}
|
|
4717
5810
|
),
|
|
@@ -4720,7 +5813,9 @@ function ReferenceSelect({
|
|
|
4720
5813
|
{
|
|
4721
5814
|
type: "button",
|
|
4722
5815
|
onClick: () => {
|
|
4723
|
-
const updated = currentList.filter(
|
|
5816
|
+
const updated = currentList.filter(
|
|
5817
|
+
(_, i) => i !== idx
|
|
5818
|
+
);
|
|
4724
5819
|
setNewRecord((prev) => ({
|
|
4725
5820
|
...prev,
|
|
4726
5821
|
[f.id]: updated.length > 0 ? updated : [""]
|
|
@@ -4753,7 +5848,9 @@ function ReferenceSelect({
|
|
|
4753
5848
|
}
|
|
4754
5849
|
if (f.type === "select") {
|
|
4755
5850
|
const opts = f.optionsMap && f.dependsOnField ? f.optionsMap[String(newRecord[f.dependsOnField] || "")] || f.options || [] : f.options || [];
|
|
4756
|
-
const formattedOpts = opts.map(
|
|
5851
|
+
const formattedOpts = opts.map(
|
|
5852
|
+
(o) => typeof o === "string" ? { label: o, value: o } : o
|
|
5853
|
+
);
|
|
4757
5854
|
return /* @__PURE__ */ jsxs("div", { className: colSpanClass, children: [
|
|
4758
5855
|
/* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: f.label }),
|
|
4759
5856
|
/* @__PURE__ */ jsx(
|
|
@@ -4788,7 +5885,10 @@ function ReferenceSelect({
|
|
|
4788
5885
|
{
|
|
4789
5886
|
rows: 3,
|
|
4790
5887
|
value: newRecord[f.id] || "",
|
|
4791
|
-
onChange: (e) => setNewRecord((prev) => ({
|
|
5888
|
+
onChange: (e) => setNewRecord((prev) => ({
|
|
5889
|
+
...prev,
|
|
5890
|
+
[f.id]: e.target.value
|
|
5891
|
+
}))
|
|
4792
5892
|
}
|
|
4793
5893
|
)
|
|
4794
5894
|
] }, f.id);
|
|
@@ -4806,17 +5906,26 @@ function ReferenceSelect({
|
|
|
4806
5906
|
value: newRecord[f.id] || "",
|
|
4807
5907
|
placeholder: f.label,
|
|
4808
5908
|
onChange: (e) => {
|
|
4809
|
-
setNewRecord((prev) => ({
|
|
5909
|
+
setNewRecord((prev) => ({
|
|
5910
|
+
...prev,
|
|
5911
|
+
[f.id]: e.target.value
|
|
5912
|
+
}));
|
|
4810
5913
|
if (formError) setFormError("");
|
|
4811
5914
|
},
|
|
4812
5915
|
onBlur: (e) => {
|
|
4813
5916
|
if (f.unique) {
|
|
4814
5917
|
const clean = (e.target.value || "").trim().toLowerCase();
|
|
4815
5918
|
if (clean) {
|
|
4816
|
-
const dup = options.find(
|
|
5919
|
+
const dup = options.find(
|
|
5920
|
+
(opt) => String(opt.value || "").trim().toLowerCase() === clean
|
|
5921
|
+
);
|
|
4817
5922
|
if (dup) {
|
|
4818
|
-
setFormError(
|
|
4819
|
-
|
|
5923
|
+
setFormError(
|
|
5924
|
+
`Ya existe un registro con este ${f.label.toLowerCase()} (\xAB${dup.label || clean}\xBB).`
|
|
5925
|
+
);
|
|
5926
|
+
message.warning(
|
|
5927
|
+
`\u26A0\uFE0F Ya existe un registro con este ${f.label.toLowerCase()}: ${clean}.`
|
|
5928
|
+
);
|
|
4820
5929
|
}
|
|
4821
5930
|
}
|
|
4822
5931
|
}
|
|
@@ -4868,11 +5977,24 @@ function ReferenceTableCell({
|
|
|
4868
5977
|
}).catch(() => {
|
|
4869
5978
|
setLabels(ids);
|
|
4870
5979
|
});
|
|
4871
|
-
}, [
|
|
5980
|
+
}, [
|
|
5981
|
+
collectionId,
|
|
5982
|
+
displayField,
|
|
5983
|
+
valueField,
|
|
5984
|
+
JSON.stringify(ids),
|
|
5985
|
+
ctx.adapter
|
|
5986
|
+
]);
|
|
4872
5987
|
if (labels.length === 0) return /* @__PURE__ */ jsx("span", { children: "-" });
|
|
4873
5988
|
if (multiple || labels.length > 1) {
|
|
4874
5989
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1 max-w-[260px]", children: [
|
|
4875
|
-
labels.slice(0, 3).map((lbl, idx) => /* @__PURE__ */ jsx(
|
|
5990
|
+
labels.slice(0, 3).map((lbl, idx) => /* @__PURE__ */ jsx(
|
|
5991
|
+
"span",
|
|
5992
|
+
{
|
|
5993
|
+
className: "inline-flex px-1.5 py-0.5 rounded bg-slate-100 text-slate-700 text-[11px] font-medium truncate max-w-[120px]",
|
|
5994
|
+
children: lbl
|
|
5995
|
+
},
|
|
5996
|
+
idx
|
|
5997
|
+
)),
|
|
4876
5998
|
labels.length > 3 && /* @__PURE__ */ jsxs("span", { className: "inline-flex px-1.5 py-0.5 rounded bg-slate-200 text-slate-600 text-[10px] font-bold", children: [
|
|
4877
5999
|
"+",
|
|
4878
6000
|
labels.length - 3
|
|
@@ -4991,6 +6113,7 @@ function AdminLogin({
|
|
|
4991
6113
|
export {
|
|
4992
6114
|
AdminApp,
|
|
4993
6115
|
AdminLogin,
|
|
6116
|
+
AdminTimeRangePicker,
|
|
4994
6117
|
CmsProvider,
|
|
4995
6118
|
EditableFile,
|
|
4996
6119
|
EditableImage,
|
|
@@ -4998,6 +6121,8 @@ export {
|
|
|
4998
6121
|
EditableList,
|
|
4999
6122
|
EditableReference,
|
|
5000
6123
|
EditableText,
|
|
6124
|
+
FormattedNumberInput,
|
|
6125
|
+
SearchableMultiSelect,
|
|
5001
6126
|
SubscriptionPage,
|
|
5002
6127
|
SubscriptionProvider,
|
|
5003
6128
|
generateDefaultTemplate,
|