@liftitapp/wa-conversations 0.10.0 → 0.11.0
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 +137 -0
- package/dist/element/index.js +306 -12
- package/dist/react/index.d.ts +107 -3
- package/dist/react/index.js +886 -10
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -1745,6 +1745,143 @@ function ConversationList({ fetcher, selectedPhone, onSelect, refreshIntervalMs,
|
|
|
1745
1745
|
});
|
|
1746
1746
|
}
|
|
1747
1747
|
//#endregion
|
|
1748
|
+
//#region src/core/contract/save-document.ts
|
|
1749
|
+
/** El mensaje genérico de D-5: el visor no conoce los códigos de error del backoffice. */
|
|
1750
|
+
const GENERIC_SAVE_ERROR = "No se pudo guardar el documento. Intenta de nuevo.";
|
|
1751
|
+
/** Un alcance es válido si trae el dato que su `kind` exige (placa o nombre, no vacíos). */
|
|
1752
|
+
function isValidScope(scope) {
|
|
1753
|
+
if (scope.kind === "vehicle") return typeof scope.plate === "string" && scope.plate.trim() !== "";
|
|
1754
|
+
if (scope.kind === "person") return typeof scope.name === "string" && scope.name.trim() !== "";
|
|
1755
|
+
return false;
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Un tipo es válido si trae `code`/`name` no vacíos y al menos un alcance reconocido
|
|
1759
|
+
* (`vehicle`/`person`) en `scopes` — lo demás del cable es basura de la property JS del elemento,
|
|
1760
|
+
* que puede traer cualquier cosa, y se descarta en silencio (D-4).
|
|
1761
|
+
*/
|
|
1762
|
+
function isValidType(type) {
|
|
1763
|
+
if (typeof type.code !== "string" || type.code.trim() === "") return false;
|
|
1764
|
+
if (typeof type.name !== "string" || type.name.trim() === "") return false;
|
|
1765
|
+
if (!Array.isArray(type.scopes)) return false;
|
|
1766
|
+
return type.scopes.some((kind) => kind === "vehicle" || kind === "person");
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Elegibilidad de la burbuja (D-3, T-no6-02): `direction === 'in'` EXACTO (fail-closed — una
|
|
1770
|
+
* dirección desconocida no ofrece la acción, aunque se pinte como entrante); `media_format`
|
|
1771
|
+
* `'image'` o `'pdf'` y NADA más — nunca la extensión de `file_name` ni `message_type`, el mismo
|
|
1772
|
+
* gate que `MediaAttachment` (T-05-01); `id` (wamid) y `media_id` no vacíos; el host tiene que
|
|
1773
|
+
* haber pasado al menos un tipo y un alcance válidos; y el mensaje no puede estar ya en `saved`
|
|
1774
|
+
* (ahí va la marca, no el botón).
|
|
1775
|
+
*/
|
|
1776
|
+
function canSaveAsDocument(message, input) {
|
|
1777
|
+
if (input === void 0) return false;
|
|
1778
|
+
if (message.direction !== "in") return false;
|
|
1779
|
+
if (message.media_format !== "image" && message.media_format !== "pdf") return false;
|
|
1780
|
+
if (typeof message.id !== "string" || message.id === "") return false;
|
|
1781
|
+
if (typeof message.media_id !== "string" || message.media_id === "") return false;
|
|
1782
|
+
if (!Array.isArray(input.types) || !input.types.some(isValidType)) return false;
|
|
1783
|
+
if (!Array.isArray(input.scopes) || !input.scopes.some(isValidScope)) return false;
|
|
1784
|
+
const saved = input.saved;
|
|
1785
|
+
if (saved !== void 0 && saved !== null && message.id in saved) return false;
|
|
1786
|
+
return true;
|
|
1787
|
+
}
|
|
1788
|
+
/** Normaliza para la búsqueda del catálogo: sin tildes ni mayúsculas (D-4). */
|
|
1789
|
+
function normalizeSearch(value) {
|
|
1790
|
+
return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().trim();
|
|
1791
|
+
}
|
|
1792
|
+
/**
|
|
1793
|
+
* Los `requested` primero (en el orden del host), con el resto como catálogo filtrado por
|
|
1794
|
+
* `query` (sin tildes ni mayúsculas, sobre `name` y `code`). Descarta tipos inválidos y
|
|
1795
|
+
* duplicados por `code` — gana el PRIMERO en el orden del host (D-4).
|
|
1796
|
+
*/
|
|
1797
|
+
function documentTypeOptions(types, query) {
|
|
1798
|
+
const valid = Array.isArray(types) ? types.filter(isValidType) : [];
|
|
1799
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1800
|
+
const deduped = [];
|
|
1801
|
+
for (const type of valid) {
|
|
1802
|
+
if (seen.has(type.code)) continue;
|
|
1803
|
+
seen.add(type.code);
|
|
1804
|
+
deduped.push(type);
|
|
1805
|
+
}
|
|
1806
|
+
const requested = deduped.filter((type) => type.requested === true);
|
|
1807
|
+
const rest = deduped.filter((type) => type.requested !== true);
|
|
1808
|
+
const normalizedQuery = normalizeSearch(query);
|
|
1809
|
+
return {
|
|
1810
|
+
requested,
|
|
1811
|
+
catalog: normalizedQuery === "" ? rest : rest.filter((type) => normalizeSearch(`${type.name} ${type.code}`).includes(normalizedQuery)),
|
|
1812
|
+
selected: requested.length === 1 ? requested[0] : null
|
|
1813
|
+
};
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* El tipo define el alcance (D-4): las opciones son los alcances VÁLIDOS del host (se descartan
|
|
1817
|
+
* los que no traen el dato que su `kind` exige); habilitadas sólo las que el tipo admite;
|
|
1818
|
+
* seleccionada la actual si sigue permitida, si no la primera permitida en el orden del host. Con
|
|
1819
|
+
* `type` null no se selecciona nada — no hay de qué derivar el alcance.
|
|
1820
|
+
*/
|
|
1821
|
+
function resolveScope(type, scopes, current) {
|
|
1822
|
+
const options = (Array.isArray(scopes) ? scopes.filter(isValidScope) : []).map((scope) => ({
|
|
1823
|
+
scope,
|
|
1824
|
+
allowed: type !== null && type.scopes.includes(scope.kind)
|
|
1825
|
+
}));
|
|
1826
|
+
if (type === null) return {
|
|
1827
|
+
options,
|
|
1828
|
+
selected: null
|
|
1829
|
+
};
|
|
1830
|
+
const keepsCurrent = options.find((option) => option.scope === current && option.allowed);
|
|
1831
|
+
if (keepsCurrent !== void 0) return {
|
|
1832
|
+
options,
|
|
1833
|
+
selected: keepsCurrent.scope
|
|
1834
|
+
};
|
|
1835
|
+
const firstAllowed = options.find((option) => option.allowed);
|
|
1836
|
+
return {
|
|
1837
|
+
options,
|
|
1838
|
+
selected: firstAllowed !== void 0 ? firstAllowed.scope : null
|
|
1839
|
+
};
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* La marca de la burbuja (D-6): sólo lee `saved[messageId]` — el visor no AFIRMA el guardado, lo
|
|
1843
|
+
* LEE (mismo principio que la barra de takeover, DEV-5190). Un `messageId` ausente o una entrada
|
|
1844
|
+
* sin `typeName` útil no pinta marca: es mejor no mostrar nada que inventar un «Guardado como».
|
|
1845
|
+
*/
|
|
1846
|
+
function savedDocumentMark(message, input) {
|
|
1847
|
+
if (input === void 0) return null;
|
|
1848
|
+
const saved = input.saved;
|
|
1849
|
+
if (saved === void 0 || saved === null) return null;
|
|
1850
|
+
if (typeof message.id !== "string" || message.id === "") return null;
|
|
1851
|
+
const mark = saved[message.id];
|
|
1852
|
+
if (mark === void 0 || mark === null) return null;
|
|
1853
|
+
if (typeof mark.typeName !== "string" || mark.typeName.trim() === "") return null;
|
|
1854
|
+
return mark;
|
|
1855
|
+
}
|
|
1856
|
+
/** La hora HH:MM local de la marca (DEC-O: sin `Intl`, mismo criterio que `formatHour`). */
|
|
1857
|
+
function formatMarkHour(at) {
|
|
1858
|
+
if (typeof at !== "string") return null;
|
|
1859
|
+
const date = new Date(at);
|
|
1860
|
+
if (Number.isNaN(date.getTime())) return null;
|
|
1861
|
+
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* «Guardado como {tipo} · {quién}, {hora}» (D-6). Sin `savedBy` cae el bloque «· …» entero —la
|
|
1865
|
+
* hora sola, sin quién, no cuenta la misma historia—; con `savedBy` pero sin `savedAt` que parsee,
|
|
1866
|
+
* cae sólo la hora.
|
|
1867
|
+
*/
|
|
1868
|
+
function savedMarkLabel(mark) {
|
|
1869
|
+
const by = typeof mark.savedBy === "string" && mark.savedBy.trim() !== "" ? mark.savedBy.trim() : null;
|
|
1870
|
+
if (by === null) return `Guardado como ${mark.typeName}`;
|
|
1871
|
+
const hour = formatMarkHour(mark.savedAt);
|
|
1872
|
+
return hour !== null ? `Guardado como ${mark.typeName} · ${by}, ${hour}` : `Guardado como ${mark.typeName} · ${by}`;
|
|
1873
|
+
}
|
|
1874
|
+
/**
|
|
1875
|
+
* El texto del modal cuando el host rechaza (D-5): `Error.message` o un string no vacío,
|
|
1876
|
+
* VERBATIM — el visor no conoce los códigos de error del backoffice y no les inventa traducción;
|
|
1877
|
+
* eso es decisión del host (DEV-7665). Cualquier otra cosa cae al genérico.
|
|
1878
|
+
*/
|
|
1879
|
+
function saveErrorMessage(reason) {
|
|
1880
|
+
if (reason instanceof Error && typeof reason.message === "string" && reason.message.trim() !== "") return reason.message;
|
|
1881
|
+
if (typeof reason === "string" && reason.trim() !== "") return reason;
|
|
1882
|
+
return GENERIC_SAVE_ERROR;
|
|
1883
|
+
}
|
|
1884
|
+
//#endregion
|
|
1748
1885
|
//#region src/core/thread/Composer.tsx
|
|
1749
1886
|
/**
|
|
1750
1887
|
* El composer del operador — la mitad visible del takeover humano (DEV-4995).
|
|
@@ -2251,10 +2388,12 @@ function ImageAttachment({ message, fetcher, mediaId }) {
|
|
|
2251
2388
|
useEffect(() => {
|
|
2252
2389
|
if (!open) return;
|
|
2253
2390
|
const handleKeyDown = (event) => {
|
|
2254
|
-
if (event.key
|
|
2391
|
+
if (event.key !== "Escape") return;
|
|
2392
|
+
event.stopPropagation();
|
|
2393
|
+
setOpen(false);
|
|
2255
2394
|
};
|
|
2256
|
-
|
|
2257
|
-
return () =>
|
|
2395
|
+
window.addEventListener("keydown", handleKeyDown, true);
|
|
2396
|
+
return () => window.removeEventListener("keydown", handleKeyDown, true);
|
|
2258
2397
|
}, [open]);
|
|
2259
2398
|
const handleImageError = () => {
|
|
2260
2399
|
if (retriedRef.current) {
|
|
@@ -2345,7 +2484,10 @@ function DownloadAttachment({ message, fetcher, mediaId, variant = "label" }) {
|
|
|
2345
2484
|
return;
|
|
2346
2485
|
}
|
|
2347
2486
|
event.preventDefault();
|
|
2348
|
-
loadMedia(fetcher, {
|
|
2487
|
+
loadMedia(fetcher, {
|
|
2488
|
+
mediaId,
|
|
2489
|
+
download: true
|
|
2490
|
+
}).then((descriptor) => {
|
|
2349
2491
|
if (!mountedRef.current) return;
|
|
2350
2492
|
const anchor = anchorRef.current;
|
|
2351
2493
|
if (anchor === null) return;
|
|
@@ -2525,7 +2667,7 @@ function formatHour(at) {
|
|
|
2525
2667
|
if (Number.isNaN(date.getTime())) return null;
|
|
2526
2668
|
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
2527
2669
|
}
|
|
2528
|
-
function MessageBubble({ message, optimistic = false, fetcher }) {
|
|
2670
|
+
function MessageBubble({ message, optimistic = false, fetcher, savedDocument = null, onSaveAsDocument }) {
|
|
2529
2671
|
const direction = message.direction === "out" ? "out" : "in";
|
|
2530
2672
|
const hour = formatHour(message.at);
|
|
2531
2673
|
const ctas = threadCtas(message);
|
|
@@ -2566,6 +2708,35 @@ function MessageBubble({ message, optimistic = false, fetcher }) {
|
|
|
2566
2708
|
message,
|
|
2567
2709
|
fetcher
|
|
2568
2710
|
}),
|
|
2711
|
+
savedDocument !== null ? /* @__PURE__ */ jsxs("span", {
|
|
2712
|
+
className: "wa-thread__saved-document",
|
|
2713
|
+
children: [/* @__PURE__ */ jsx("svg", {
|
|
2714
|
+
width: 13,
|
|
2715
|
+
height: 13,
|
|
2716
|
+
viewBox: "0 0 16 16",
|
|
2717
|
+
fill: "none",
|
|
2718
|
+
stroke: "currentColor",
|
|
2719
|
+
strokeWidth: 1.8,
|
|
2720
|
+
strokeLinecap: "round",
|
|
2721
|
+
strokeLinejoin: "round",
|
|
2722
|
+
"aria-hidden": "true",
|
|
2723
|
+
children: /* @__PURE__ */ jsx("polyline", { points: "2.5,8.5 6,12 13.5,4" })
|
|
2724
|
+
}), savedMarkLabel(savedDocument)]
|
|
2725
|
+
}) : onSaveAsDocument !== void 0 && /* @__PURE__ */ jsxs("button", {
|
|
2726
|
+
type: "button",
|
|
2727
|
+
className: "wa-thread__save-action",
|
|
2728
|
+
onClick: onSaveAsDocument,
|
|
2729
|
+
children: [/* @__PURE__ */ jsxs("svg", {
|
|
2730
|
+
width: 13,
|
|
2731
|
+
height: 13,
|
|
2732
|
+
viewBox: "0 0 16 16",
|
|
2733
|
+
fill: "none",
|
|
2734
|
+
stroke: "currentColor",
|
|
2735
|
+
strokeWidth: 1.3,
|
|
2736
|
+
"aria-hidden": "true",
|
|
2737
|
+
children: [/* @__PURE__ */ jsx("path", { d: "M4 1.5h5.5L12.5 4.5V14a.5.5 0 0 1-.5.5H4a.5.5 0 0 1-.5-.5v-12a.5.5 0 0 1 .5-.5Z" }), /* @__PURE__ */ jsx("path", { d: "M9.3 1.5V4.5h3" })]
|
|
2738
|
+
}), "Guardar como documento"]
|
|
2739
|
+
}),
|
|
2569
2740
|
ctas.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
2570
2741
|
className: "wa-thread__ctas",
|
|
2571
2742
|
children: ctas.map((cta, index) => isCtaLink(cta) ? /* @__PURE__ */ jsx("a", {
|
|
@@ -2604,6 +2775,386 @@ function MessageBubble({ message, optimistic = false, fetcher }) {
|
|
|
2604
2775
|
});
|
|
2605
2776
|
}
|
|
2606
2777
|
//#endregion
|
|
2778
|
+
//#region src/core/thread/SaveDocumentDialog.tsx
|
|
2779
|
+
/**
|
|
2780
|
+
* El modal «Guardar como documento» (DEV-7664, tablero 21zzc). Interno del hilo — NO sale al
|
|
2781
|
+
* barrel, mismo criterio que `MessageBubble`. Controlado por `ConversationThread`: la decisión de
|
|
2782
|
+
* CUÁNDO se pinta vive en el padre (D-1, D-2, D-3); este componente sólo sabe guardar UN mensaje.
|
|
2783
|
+
*
|
|
2784
|
+
* Ganchos estables (no se tocan entre tareas, los usa `src/element/save-document.test.ts`):
|
|
2785
|
+
* `.wa-thread__save-dialog` con `role="dialog"`; radios de tipo `input[type=radio]` con `value` =
|
|
2786
|
+
* `code`; radios de alcance con `data-scope-kind`; envío `.wa-thread__save-submit`; error
|
|
2787
|
+
* `[role="alert"]`.
|
|
2788
|
+
*
|
|
2789
|
+
* 🔴 Todo texto que origina el host o el lifter (nombres de tipo, `detail`, placa, nombre,
|
|
2790
|
+
* `file_name`, el mensaje de error) entra como hijo de texto, que React escapa — nunca
|
|
2791
|
+
* `dangerouslySetInnerHTML` (T-no6-04).
|
|
2792
|
+
*/
|
|
2793
|
+
/** `'image'` o `'pdf'` — lo que ya validó `canSaveAsDocument` antes de ofrecer la acción. */
|
|
2794
|
+
function mediaFormatOf(message) {
|
|
2795
|
+
return message.media_format === "image" ? "image" : "pdf";
|
|
2796
|
+
}
|
|
2797
|
+
/** El nombre del archivo o, sin él, un genérico según el formato (21zzc: «Imagen adjunta»). */
|
|
2798
|
+
function attachmentName(message) {
|
|
2799
|
+
if (typeof message.file_name === "string" && message.file_name !== "") return message.file_name;
|
|
2800
|
+
return mediaFormatOf(message) === "image" ? "Imagen adjunta" : "Documento PDF";
|
|
2801
|
+
}
|
|
2802
|
+
/** La hora HH:MM local (DEC-O, sin `Intl`) — mismo criterio que `formatHour` de `MessageBubble`. */
|
|
2803
|
+
function formatDialogHour(at) {
|
|
2804
|
+
const date = new Date(at);
|
|
2805
|
+
if (Number.isNaN(date.getTime())) return null;
|
|
2806
|
+
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
2807
|
+
}
|
|
2808
|
+
/** «Lo mandó el lifter por WhatsApp · hoy 09:09» / «· 15 de agosto de 2026 09:09» (21zzc). */
|
|
2809
|
+
function sentWhenLabel(at) {
|
|
2810
|
+
if (typeof at !== "string") return null;
|
|
2811
|
+
const hour = formatDialogHour(at);
|
|
2812
|
+
const key = dayKey(at);
|
|
2813
|
+
if (key === null) return hour;
|
|
2814
|
+
const day = key === dayKey((/* @__PURE__ */ new Date()).toISOString()) ? "hoy" : dayLabel(at);
|
|
2815
|
+
return hour !== null ? `${day} ${hour}` : day;
|
|
2816
|
+
}
|
|
2817
|
+
function DocumentGlyph() {
|
|
2818
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
2819
|
+
width: 20,
|
|
2820
|
+
height: 20,
|
|
2821
|
+
viewBox: "0 0 16 16",
|
|
2822
|
+
fill: "none",
|
|
2823
|
+
stroke: "currentColor",
|
|
2824
|
+
strokeWidth: 1.3,
|
|
2825
|
+
"aria-hidden": "true",
|
|
2826
|
+
children: [/* @__PURE__ */ jsx("path", { d: "M4 1.5h5.5L12.5 4.5V14a.5.5 0 0 1-.5.5H4a.5.5 0 0 1-.5-.5v-12a.5.5 0 0 1 .5-.5Z" }), /* @__PURE__ */ jsx("path", { d: "M9.3 1.5V4.5h3" })]
|
|
2827
|
+
});
|
|
2828
|
+
}
|
|
2829
|
+
function SearchGlyph() {
|
|
2830
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
2831
|
+
width: 14,
|
|
2832
|
+
height: 14,
|
|
2833
|
+
viewBox: "0 0 16 16",
|
|
2834
|
+
fill: "none",
|
|
2835
|
+
stroke: "currentColor",
|
|
2836
|
+
strokeWidth: 1.5,
|
|
2837
|
+
"aria-hidden": "true",
|
|
2838
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
2839
|
+
cx: "7",
|
|
2840
|
+
cy: "7",
|
|
2841
|
+
r: "4.5"
|
|
2842
|
+
}), /* @__PURE__ */ jsx("path", { d: "M13.5 13.5 10.4 10.4" })]
|
|
2843
|
+
});
|
|
2844
|
+
}
|
|
2845
|
+
function VehicleGlyph() {
|
|
2846
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
2847
|
+
width: 16,
|
|
2848
|
+
height: 16,
|
|
2849
|
+
viewBox: "0 0 16 16",
|
|
2850
|
+
fill: "none",
|
|
2851
|
+
stroke: "currentColor",
|
|
2852
|
+
strokeWidth: 1.3,
|
|
2853
|
+
"aria-hidden": "true",
|
|
2854
|
+
children: [
|
|
2855
|
+
/* @__PURE__ */ jsx("path", { d: "M2 10.5V7l1.3-3.2A1 1 0 0 1 4.2 3.2h7.6a1 1 0 0 1 .9.6L14 7v3.5" }),
|
|
2856
|
+
/* @__PURE__ */ jsx("path", { d: "M2 10.5h12v1.8a.7.7 0 0 1-.7.7h-.6a.7.7 0 0 1-.7-.7v-.8H4v.8a.7.7 0 0 1-.7.7h-.6a.7.7 0 0 1-.7-.7v-1.8Z" }),
|
|
2857
|
+
/* @__PURE__ */ jsx("circle", {
|
|
2858
|
+
cx: "4.6",
|
|
2859
|
+
cy: "10.5",
|
|
2860
|
+
r: "1"
|
|
2861
|
+
}),
|
|
2862
|
+
/* @__PURE__ */ jsx("circle", {
|
|
2863
|
+
cx: "11.4",
|
|
2864
|
+
cy: "10.5",
|
|
2865
|
+
r: "1"
|
|
2866
|
+
})
|
|
2867
|
+
]
|
|
2868
|
+
});
|
|
2869
|
+
}
|
|
2870
|
+
function PersonGlyph() {
|
|
2871
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
2872
|
+
width: 16,
|
|
2873
|
+
height: 16,
|
|
2874
|
+
viewBox: "0 0 16 16",
|
|
2875
|
+
fill: "none",
|
|
2876
|
+
stroke: "currentColor",
|
|
2877
|
+
strokeWidth: 1.3,
|
|
2878
|
+
"aria-hidden": "true",
|
|
2879
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
2880
|
+
cx: "8",
|
|
2881
|
+
cy: "5.2",
|
|
2882
|
+
r: "2.7"
|
|
2883
|
+
}), /* @__PURE__ */ jsx("path", { d: "M2.8 13.5c.6-2.5 2.7-4 5.2-4s4.6 1.5 5.2 4" })]
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
function InfoGlyph() {
|
|
2887
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
2888
|
+
width: 16,
|
|
2889
|
+
height: 16,
|
|
2890
|
+
viewBox: "0 0 16 16",
|
|
2891
|
+
fill: "none",
|
|
2892
|
+
stroke: "currentColor",
|
|
2893
|
+
strokeWidth: 1.3,
|
|
2894
|
+
"aria-hidden": "true",
|
|
2895
|
+
children: [
|
|
2896
|
+
/* @__PURE__ */ jsx("circle", {
|
|
2897
|
+
cx: "8",
|
|
2898
|
+
cy: "8",
|
|
2899
|
+
r: "6.5"
|
|
2900
|
+
}),
|
|
2901
|
+
/* @__PURE__ */ jsx("path", { d: "M8 7.3v4" }),
|
|
2902
|
+
/* @__PURE__ */ jsx("circle", {
|
|
2903
|
+
cx: "8",
|
|
2904
|
+
cy: "5.1",
|
|
2905
|
+
r: "0.25",
|
|
2906
|
+
fill: "currentColor",
|
|
2907
|
+
stroke: "none"
|
|
2908
|
+
})
|
|
2909
|
+
]
|
|
2910
|
+
});
|
|
2911
|
+
}
|
|
2912
|
+
function SaveGlyph() {
|
|
2913
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
2914
|
+
width: 15,
|
|
2915
|
+
height: 15,
|
|
2916
|
+
viewBox: "0 0 16 16",
|
|
2917
|
+
fill: "none",
|
|
2918
|
+
stroke: "currentColor",
|
|
2919
|
+
strokeWidth: 1.6,
|
|
2920
|
+
"aria-hidden": "true",
|
|
2921
|
+
children: [/* @__PURE__ */ jsx("path", { d: "M3 2.5h8l2 2V13a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V3a.5.5 0 0 1 .5-.5Z" }), /* @__PURE__ */ jsx("path", { d: "M5.3 2.5V6h4.4V2.5M5.3 13v-3.5h5.4V13" })]
|
|
2922
|
+
});
|
|
2923
|
+
}
|
|
2924
|
+
function SaveDocumentDialog({ message, phone, input, onClose }) {
|
|
2925
|
+
const [type, setType] = useState(() => documentTypeOptions(input.types, "").selected);
|
|
2926
|
+
const [scope, setScope] = useState(null);
|
|
2927
|
+
const [search, setSearch] = useState("");
|
|
2928
|
+
const [submitting, setSubmitting] = useState(false);
|
|
2929
|
+
const [error, setError] = useState(null);
|
|
2930
|
+
const mountedRef = useRef(true);
|
|
2931
|
+
const containerRef = useRef(null);
|
|
2932
|
+
useEffect(() => {
|
|
2933
|
+
return () => {
|
|
2934
|
+
mountedRef.current = false;
|
|
2935
|
+
};
|
|
2936
|
+
}, []);
|
|
2937
|
+
useEffect(() => {
|
|
2938
|
+
containerRef.current?.focus();
|
|
2939
|
+
}, []);
|
|
2940
|
+
useEffect(() => {
|
|
2941
|
+
if (submitting) return;
|
|
2942
|
+
const handleKeyDown = (event) => {
|
|
2943
|
+
if (event.key !== "Escape") return;
|
|
2944
|
+
event.stopPropagation();
|
|
2945
|
+
onClose();
|
|
2946
|
+
};
|
|
2947
|
+
window.addEventListener("keydown", handleKeyDown, true);
|
|
2948
|
+
return () => window.removeEventListener("keydown", handleKeyDown, true);
|
|
2949
|
+
}, [submitting, onClose]);
|
|
2950
|
+
const { requested, catalog } = documentTypeOptions(input.types, search);
|
|
2951
|
+
const showCatalog = search.trim() !== "" || requested.length === 0;
|
|
2952
|
+
const { options: scopeOptions, selected: resolvedScope } = resolveScope(type, input.scopes, scope);
|
|
2953
|
+
const allowedScopeCount = scopeOptions.filter((option) => option.allowed).length;
|
|
2954
|
+
const handleTypeChange = (next) => {
|
|
2955
|
+
setType(next);
|
|
2956
|
+
};
|
|
2957
|
+
const handleSubmit = () => {
|
|
2958
|
+
if (type === null || resolvedScope === null || submitting) return;
|
|
2959
|
+
const request = {
|
|
2960
|
+
phone,
|
|
2961
|
+
messageId: message.id,
|
|
2962
|
+
mediaId: message.media_id,
|
|
2963
|
+
mediaFormat: mediaFormatOf(message),
|
|
2964
|
+
fileName: typeof message.file_name === "string" ? message.file_name : null,
|
|
2965
|
+
documentType: type,
|
|
2966
|
+
scope: resolvedScope
|
|
2967
|
+
};
|
|
2968
|
+
setSubmitting(true);
|
|
2969
|
+
setError(null);
|
|
2970
|
+
Promise.resolve().then(() => input.onSave(request)).then(() => {
|
|
2971
|
+
if (!mountedRef.current) return;
|
|
2972
|
+
onClose();
|
|
2973
|
+
}).catch((reason) => {
|
|
2974
|
+
if (!mountedRef.current) return;
|
|
2975
|
+
setSubmitting(false);
|
|
2976
|
+
setError(saveErrorMessage(reason));
|
|
2977
|
+
});
|
|
2978
|
+
};
|
|
2979
|
+
const handleOverlayClick = () => {
|
|
2980
|
+
if (submitting) return;
|
|
2981
|
+
onClose();
|
|
2982
|
+
};
|
|
2983
|
+
const sentWhen = sentWhenLabel(message.at);
|
|
2984
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2985
|
+
className: "wa-thread__save-overlay",
|
|
2986
|
+
onClick: handleOverlayClick,
|
|
2987
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
2988
|
+
ref: containerRef,
|
|
2989
|
+
className: "wa-thread__save-dialog",
|
|
2990
|
+
role: "dialog",
|
|
2991
|
+
"aria-modal": "true",
|
|
2992
|
+
"aria-labelledby": "wa-thread-save-title",
|
|
2993
|
+
tabIndex: -1,
|
|
2994
|
+
onClick: (event) => event.stopPropagation(),
|
|
2995
|
+
children: [
|
|
2996
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2997
|
+
className: "wa-thread__save-header",
|
|
2998
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
2999
|
+
id: "wa-thread-save-title",
|
|
3000
|
+
className: "wa-thread__save-title",
|
|
3001
|
+
children: "Guardar como documento"
|
|
3002
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
3003
|
+
type: "button",
|
|
3004
|
+
className: "wa-thread__save-close",
|
|
3005
|
+
onClick: onClose,
|
|
3006
|
+
disabled: submitting,
|
|
3007
|
+
"aria-label": "Cerrar",
|
|
3008
|
+
children: "×"
|
|
3009
|
+
})]
|
|
3010
|
+
}),
|
|
3011
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3012
|
+
className: "wa-thread__save-file",
|
|
3013
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3014
|
+
className: "wa-thread__save-file-icon",
|
|
3015
|
+
"aria-hidden": "true",
|
|
3016
|
+
children: /* @__PURE__ */ jsx(DocumentGlyph, {})
|
|
3017
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
3018
|
+
className: "wa-thread__save-file-text",
|
|
3019
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3020
|
+
className: "wa-thread__save-file-name",
|
|
3021
|
+
children: attachmentName(message)
|
|
3022
|
+
}), sentWhen !== null && /* @__PURE__ */ jsxs("span", {
|
|
3023
|
+
className: "wa-thread__save-file-meta",
|
|
3024
|
+
children: ["Lo mandó el lifter por WhatsApp · ", sentWhen]
|
|
3025
|
+
})]
|
|
3026
|
+
})]
|
|
3027
|
+
}),
|
|
3028
|
+
/* @__PURE__ */ jsxs("fieldset", {
|
|
3029
|
+
className: "wa-thread__save-types",
|
|
3030
|
+
children: [
|
|
3031
|
+
/* @__PURE__ */ jsx("legend", { children: "Tipo de documento" }),
|
|
3032
|
+
requested.map((option) => /* @__PURE__ */ jsxs("label", {
|
|
3033
|
+
className: "wa-thread__save-type-option",
|
|
3034
|
+
"data-selected": type?.code === option.code || void 0,
|
|
3035
|
+
children: [
|
|
3036
|
+
/* @__PURE__ */ jsx("input", {
|
|
3037
|
+
type: "radio",
|
|
3038
|
+
name: "wa-save-document-type",
|
|
3039
|
+
value: option.code,
|
|
3040
|
+
checked: type?.code === option.code,
|
|
3041
|
+
onChange: () => handleTypeChange(option),
|
|
3042
|
+
disabled: submitting
|
|
3043
|
+
}),
|
|
3044
|
+
/* @__PURE__ */ jsxs("span", {
|
|
3045
|
+
className: "wa-thread__save-type-text",
|
|
3046
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3047
|
+
className: "wa-thread__save-type-name",
|
|
3048
|
+
children: option.name
|
|
3049
|
+
}), typeof option.detail === "string" && option.detail !== "" && /* @__PURE__ */ jsx("span", {
|
|
3050
|
+
className: "wa-thread__save-type-detail",
|
|
3051
|
+
children: option.detail
|
|
3052
|
+
})]
|
|
3053
|
+
}),
|
|
3054
|
+
/* @__PURE__ */ jsx("span", {
|
|
3055
|
+
className: "wa-thread__save-badge",
|
|
3056
|
+
children: "Pedido · abierto"
|
|
3057
|
+
})
|
|
3058
|
+
]
|
|
3059
|
+
}, option.code)),
|
|
3060
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3061
|
+
className: "wa-thread__save-search",
|
|
3062
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3063
|
+
"aria-hidden": "true",
|
|
3064
|
+
children: /* @__PURE__ */ jsx(SearchGlyph, {})
|
|
3065
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
3066
|
+
type: "search",
|
|
3067
|
+
placeholder: "Otro tipo del catálogo…",
|
|
3068
|
+
value: search,
|
|
3069
|
+
onChange: (event) => setSearch(event.target.value),
|
|
3070
|
+
disabled: submitting
|
|
3071
|
+
})]
|
|
3072
|
+
}),
|
|
3073
|
+
showCatalog && catalog.map((option) => /* @__PURE__ */ jsxs("label", {
|
|
3074
|
+
className: "wa-thread__save-type-option",
|
|
3075
|
+
"data-selected": type?.code === option.code || void 0,
|
|
3076
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
3077
|
+
type: "radio",
|
|
3078
|
+
name: "wa-save-document-type",
|
|
3079
|
+
value: option.code,
|
|
3080
|
+
checked: type?.code === option.code,
|
|
3081
|
+
onChange: () => handleTypeChange(option),
|
|
3082
|
+
disabled: submitting
|
|
3083
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
3084
|
+
className: "wa-thread__save-type-text",
|
|
3085
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3086
|
+
className: "wa-thread__save-type-name",
|
|
3087
|
+
children: option.name
|
|
3088
|
+
}), typeof option.detail === "string" && option.detail !== "" && /* @__PURE__ */ jsx("span", {
|
|
3089
|
+
className: "wa-thread__save-type-detail",
|
|
3090
|
+
children: option.detail
|
|
3091
|
+
})]
|
|
3092
|
+
})]
|
|
3093
|
+
}, option.code))
|
|
3094
|
+
]
|
|
3095
|
+
}),
|
|
3096
|
+
/* @__PURE__ */ jsxs("fieldset", {
|
|
3097
|
+
className: "wa-thread__save-scopes",
|
|
3098
|
+
children: [
|
|
3099
|
+
/* @__PURE__ */ jsx("legend", { children: "De quién es" }),
|
|
3100
|
+
scopeOptions.map(({ scope: scopeOption, allowed }, index) => /* @__PURE__ */ jsxs("label", {
|
|
3101
|
+
className: "wa-thread__save-scope-option",
|
|
3102
|
+
"data-selected": resolvedScope === scopeOption || void 0,
|
|
3103
|
+
children: [
|
|
3104
|
+
/* @__PURE__ */ jsx("input", {
|
|
3105
|
+
type: "radio",
|
|
3106
|
+
name: "wa-save-document-scope",
|
|
3107
|
+
"data-scope-kind": scopeOption.kind,
|
|
3108
|
+
checked: resolvedScope === scopeOption,
|
|
3109
|
+
disabled: !allowed || submitting,
|
|
3110
|
+
onChange: () => setScope(scopeOption)
|
|
3111
|
+
}),
|
|
3112
|
+
/* @__PURE__ */ jsx("span", {
|
|
3113
|
+
"aria-hidden": "true",
|
|
3114
|
+
children: scopeOption.kind === "vehicle" ? /* @__PURE__ */ jsx(VehicleGlyph, {}) : /* @__PURE__ */ jsx(PersonGlyph, {})
|
|
3115
|
+
}),
|
|
3116
|
+
scopeOption.kind === "vehicle" ? `Vehículo · ${scopeOption.plate}` : `Persona · ${scopeOption.name}`
|
|
3117
|
+
]
|
|
3118
|
+
}, index)),
|
|
3119
|
+
type !== null && /* @__PURE__ */ jsx("p", {
|
|
3120
|
+
className: "wa-thread__save-scope-explain",
|
|
3121
|
+
children: allowedScopeCount <= 1 ? `El tipo define el alcance: ${type.name} es ${resolvedScope?.kind === "person" ? "de la persona" : "del vehículo"}. Solo se puede cambiar en los tipos que admiten los dos.` : `${type.name} admite los dos alcances — elige de quién es este documento.`
|
|
3122
|
+
})
|
|
3123
|
+
]
|
|
3124
|
+
}),
|
|
3125
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3126
|
+
className: "wa-thread__save-notice",
|
|
3127
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3128
|
+
"aria-hidden": "true",
|
|
3129
|
+
children: /* @__PURE__ */ jsx(InfoGlyph, {})
|
|
3130
|
+
}), /* @__PURE__ */ jsxs("span", { children: ["Se guarda en el expediente como carga manual, sin OCR, y queda pendiente de decisión.", type !== null && (type.requested === true ? ` Cumple la solicitud abierta de ${type.name} y queda a tu nombre.` : " Queda a tu nombre.")] })]
|
|
3131
|
+
}),
|
|
3132
|
+
error !== null && /* @__PURE__ */ jsx("p", {
|
|
3133
|
+
role: "alert",
|
|
3134
|
+
className: "wa-thread__save-error",
|
|
3135
|
+
children: error
|
|
3136
|
+
}),
|
|
3137
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3138
|
+
className: "wa-thread__save-actions",
|
|
3139
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
3140
|
+
type: "button",
|
|
3141
|
+
className: "wa-thread__save-cancel",
|
|
3142
|
+
onClick: onClose,
|
|
3143
|
+
disabled: submitting,
|
|
3144
|
+
children: "Cancelar"
|
|
3145
|
+
}), /* @__PURE__ */ jsxs("button", {
|
|
3146
|
+
type: "button",
|
|
3147
|
+
className: "wa-thread__save-submit",
|
|
3148
|
+
onClick: handleSubmit,
|
|
3149
|
+
disabled: type === null || resolvedScope === null || submitting,
|
|
3150
|
+
children: [/* @__PURE__ */ jsx(SaveGlyph, {}), submitting ? "Guardando…" : "Guardar documento"]
|
|
3151
|
+
})]
|
|
3152
|
+
})
|
|
3153
|
+
]
|
|
3154
|
+
})
|
|
3155
|
+
});
|
|
3156
|
+
}
|
|
3157
|
+
//#endregion
|
|
2607
3158
|
//#region src/core/thread/service-state-labels.ts
|
|
2608
3159
|
/**
|
|
2609
3160
|
* Las etiquetas humanas de `service_state` para el HILO (DEV-5053 / P3, completada en DEV-5144).
|
|
@@ -3580,6 +4131,300 @@ const THREAD_CSS = `
|
|
|
3580
4131
|
border-radius: 999px;
|
|
3581
4132
|
color: #D93025;
|
|
3582
4133
|
}
|
|
4134
|
+
|
|
4135
|
+
/* ─── «Guardar como documento» (DEV-7664, tableros 21zzc/21zzd) ──────────────────────────────
|
|
4136
|
+
Paleta reusada del archivo: índigo #4F5AED/#EEF1FE del acento y los CTAs, ámbar de la barra de
|
|
4137
|
+
takeover para el badge «Pedido · abierto», verde para la marca confirmada. Cero tokens nuevos. */
|
|
4138
|
+
|
|
4139
|
+
/* El botón de la burbuja: pill índigo suave, debajo del adjunto y antes de los CTAs (D-10). */
|
|
4140
|
+
.wa-thread__save-action {
|
|
4141
|
+
display: inline-flex;
|
|
4142
|
+
align-self: flex-start;
|
|
4143
|
+
align-items: center;
|
|
4144
|
+
gap: 6px;
|
|
4145
|
+
margin-top: 2px;
|
|
4146
|
+
padding: 5px 12px;
|
|
4147
|
+
border: 1px solid #C9D2F5;
|
|
4148
|
+
border-radius: 999px;
|
|
4149
|
+
font: inherit;
|
|
4150
|
+
font-size: 11.5px;
|
|
4151
|
+
font-weight: 600;
|
|
4152
|
+
color: #4F5AED;
|
|
4153
|
+
background: #EEF1FE;
|
|
4154
|
+
cursor: pointer;
|
|
4155
|
+
}
|
|
4156
|
+
.wa-thread__save-action:hover {
|
|
4157
|
+
background: #E2E7FD;
|
|
4158
|
+
}
|
|
4159
|
+
|
|
4160
|
+
/* La marca confirmada: pill verde, con check — reemplaza al botón (D-6). */
|
|
4161
|
+
.wa-thread__saved-document {
|
|
4162
|
+
display: inline-flex;
|
|
4163
|
+
align-self: flex-start;
|
|
4164
|
+
align-items: center;
|
|
4165
|
+
gap: 6px;
|
|
4166
|
+
margin-top: 2px;
|
|
4167
|
+
padding: 5px 12px;
|
|
4168
|
+
border: 1px solid #BFE3C9;
|
|
4169
|
+
border-radius: 999px;
|
|
4170
|
+
font-size: 11.5px;
|
|
4171
|
+
font-weight: 600;
|
|
4172
|
+
color: #1E7F43;
|
|
4173
|
+
background: #EAF7EE;
|
|
4174
|
+
}
|
|
4175
|
+
|
|
4176
|
+
/* El overlay y el modal: mismo molde que \`.wa-thread__lightbox\`, para que convivan sin pisarse
|
|
4177
|
+
(ninguno de los dos vive dentro de \`.wa-thread__messages\`, así que no compiten por z-index real;
|
|
4178
|
+
se repite el valor por claridad y porque los dos pueden coexistir en teoría — el lightbox se
|
|
4179
|
+
cierra solo al abrir el modal de guardado, nunca al revés). */
|
|
4180
|
+
.wa-thread__save-overlay {
|
|
4181
|
+
position: fixed;
|
|
4182
|
+
inset: 0;
|
|
4183
|
+
z-index: 1000;
|
|
4184
|
+
display: flex;
|
|
4185
|
+
align-items: center;
|
|
4186
|
+
justify-content: center;
|
|
4187
|
+
padding: 16px;
|
|
4188
|
+
background: rgba(31, 41, 51, 0.55);
|
|
4189
|
+
}
|
|
4190
|
+
.wa-thread__save-dialog {
|
|
4191
|
+
display: flex;
|
|
4192
|
+
width: min(560px, calc(100% - 32px));
|
|
4193
|
+
max-height: calc(100% - 32px);
|
|
4194
|
+
flex-direction: column;
|
|
4195
|
+
gap: 14px;
|
|
4196
|
+
overflow-y: auto;
|
|
4197
|
+
padding: 20px;
|
|
4198
|
+
border-radius: 16px;
|
|
4199
|
+
background: #ffffff;
|
|
4200
|
+
box-shadow: 0 20px 48px rgba(17, 24, 39, 0.28);
|
|
4201
|
+
}
|
|
4202
|
+
.wa-thread__save-dialog:focus {
|
|
4203
|
+
outline: none;
|
|
4204
|
+
}
|
|
4205
|
+
.wa-thread__save-header {
|
|
4206
|
+
display: flex;
|
|
4207
|
+
align-items: flex-start;
|
|
4208
|
+
justify-content: space-between;
|
|
4209
|
+
gap: 12px;
|
|
4210
|
+
}
|
|
4211
|
+
.wa-thread__save-title {
|
|
4212
|
+
margin: 0;
|
|
4213
|
+
font-size: 16px;
|
|
4214
|
+
font-weight: 700;
|
|
4215
|
+
color: #1f2933;
|
|
4216
|
+
}
|
|
4217
|
+
.wa-thread__save-close {
|
|
4218
|
+
flex: 0 0 auto;
|
|
4219
|
+
padding: 0 4px;
|
|
4220
|
+
border: none;
|
|
4221
|
+
font-size: 20px;
|
|
4222
|
+
line-height: 1;
|
|
4223
|
+
color: #8A91A0;
|
|
4224
|
+
background: none;
|
|
4225
|
+
cursor: pointer;
|
|
4226
|
+
}
|
|
4227
|
+
.wa-thread__save-close:hover {
|
|
4228
|
+
color: #2D3340;
|
|
4229
|
+
}
|
|
4230
|
+
|
|
4231
|
+
/* La tarjeta del archivo: icono + nombre + «Lo mandó el lifter por WhatsApp · …». */
|
|
4232
|
+
.wa-thread__save-file {
|
|
4233
|
+
display: flex;
|
|
4234
|
+
align-items: center;
|
|
4235
|
+
gap: 10px;
|
|
4236
|
+
padding: 10px 12px;
|
|
4237
|
+
border: 1px solid #EEF0F3;
|
|
4238
|
+
border-radius: 10px;
|
|
4239
|
+
background: #F7F6F2;
|
|
4240
|
+
}
|
|
4241
|
+
.wa-thread__save-file-icon {
|
|
4242
|
+
display: flex;
|
|
4243
|
+
flex: 0 0 auto;
|
|
4244
|
+
color: #6B7280;
|
|
4245
|
+
}
|
|
4246
|
+
.wa-thread__save-file-text {
|
|
4247
|
+
display: flex;
|
|
4248
|
+
min-width: 0;
|
|
4249
|
+
flex-direction: column;
|
|
4250
|
+
gap: 2px;
|
|
4251
|
+
}
|
|
4252
|
+
.wa-thread__save-file-name {
|
|
4253
|
+
overflow: hidden;
|
|
4254
|
+
font-size: 13px;
|
|
4255
|
+
font-weight: 600;
|
|
4256
|
+
color: #2D3340;
|
|
4257
|
+
text-overflow: ellipsis;
|
|
4258
|
+
white-space: nowrap;
|
|
4259
|
+
}
|
|
4260
|
+
.wa-thread__save-file-meta {
|
|
4261
|
+
font-size: 11.5px;
|
|
4262
|
+
color: #8A91A0;
|
|
4263
|
+
}
|
|
4264
|
+
|
|
4265
|
+
/* Los dos \`fieldset\` — tipo y alcance — comparten el mismo molde de tarjetas-radio. */
|
|
4266
|
+
.wa-thread__save-types,
|
|
4267
|
+
.wa-thread__save-scopes {
|
|
4268
|
+
display: flex;
|
|
4269
|
+
margin: 0;
|
|
4270
|
+
flex-direction: column;
|
|
4271
|
+
gap: 8px;
|
|
4272
|
+
padding: 0;
|
|
4273
|
+
border: 0;
|
|
4274
|
+
}
|
|
4275
|
+
.wa-thread__save-types legend,
|
|
4276
|
+
.wa-thread__save-scopes legend {
|
|
4277
|
+
padding: 0 0 2px;
|
|
4278
|
+
font-size: 11px;
|
|
4279
|
+
font-weight: 700;
|
|
4280
|
+
letter-spacing: 0.04em;
|
|
4281
|
+
text-transform: uppercase;
|
|
4282
|
+
color: #6B7280;
|
|
4283
|
+
}
|
|
4284
|
+
.wa-thread__save-type-option,
|
|
4285
|
+
.wa-thread__save-scope-option {
|
|
4286
|
+
display: flex;
|
|
4287
|
+
align-items: center;
|
|
4288
|
+
gap: 10px;
|
|
4289
|
+
padding: 10px 12px;
|
|
4290
|
+
border: 1px solid #E4E7EE;
|
|
4291
|
+
border-radius: 10px;
|
|
4292
|
+
cursor: pointer;
|
|
4293
|
+
}
|
|
4294
|
+
.wa-thread__save-type-option[data-selected='true'],
|
|
4295
|
+
.wa-thread__save-scope-option[data-selected='true'] {
|
|
4296
|
+
border-color: #4F5AED;
|
|
4297
|
+
background: #F4F5FF;
|
|
4298
|
+
}
|
|
4299
|
+
.wa-thread__save-type-option:has(input:disabled),
|
|
4300
|
+
.wa-thread__save-scope-option:has(input:disabled) {
|
|
4301
|
+
cursor: default;
|
|
4302
|
+
opacity: 0.55;
|
|
4303
|
+
}
|
|
4304
|
+
.wa-thread__save-type-text {
|
|
4305
|
+
display: flex;
|
|
4306
|
+
min-width: 0;
|
|
4307
|
+
flex: 1 1 auto;
|
|
4308
|
+
flex-direction: column;
|
|
4309
|
+
gap: 2px;
|
|
4310
|
+
}
|
|
4311
|
+
.wa-thread__save-type-name {
|
|
4312
|
+
font-size: 13px;
|
|
4313
|
+
font-weight: 600;
|
|
4314
|
+
color: #2D3340;
|
|
4315
|
+
}
|
|
4316
|
+
.wa-thread__save-type-detail {
|
|
4317
|
+
font-size: 11.5px;
|
|
4318
|
+
color: #8A91A0;
|
|
4319
|
+
}
|
|
4320
|
+
/* El badge «Pedido · abierto» (ámbar, misma paleta que la barra de takeover ajena). */
|
|
4321
|
+
.wa-thread__save-badge {
|
|
4322
|
+
flex: 0 0 auto;
|
|
4323
|
+
padding: 3px 9px;
|
|
4324
|
+
border-radius: 999px;
|
|
4325
|
+
font-size: 10.5px;
|
|
4326
|
+
font-weight: 700;
|
|
4327
|
+
color: #b7791f;
|
|
4328
|
+
background: #fff7e8;
|
|
4329
|
+
}
|
|
4330
|
+
.wa-thread__save-search {
|
|
4331
|
+
display: flex;
|
|
4332
|
+
align-items: center;
|
|
4333
|
+
gap: 8px;
|
|
4334
|
+
padding: 8px 12px;
|
|
4335
|
+
border: 1px solid #E4E7EE;
|
|
4336
|
+
border-radius: 10px;
|
|
4337
|
+
color: #8A91A0;
|
|
4338
|
+
background: #ffffff;
|
|
4339
|
+
}
|
|
4340
|
+
.wa-thread__save-search input {
|
|
4341
|
+
flex: 1 1 auto;
|
|
4342
|
+
border: none;
|
|
4343
|
+
font: inherit;
|
|
4344
|
+
font-size: 13px;
|
|
4345
|
+
color: #2D3340;
|
|
4346
|
+
background: none;
|
|
4347
|
+
outline: none;
|
|
4348
|
+
}
|
|
4349
|
+
.wa-thread__save-scope-explain {
|
|
4350
|
+
margin: 2px 0 0;
|
|
4351
|
+
font-size: 11.5px;
|
|
4352
|
+
color: #6B7280;
|
|
4353
|
+
}
|
|
4354
|
+
|
|
4355
|
+
/* El aviso informativo: carga manual, sin OCR, pendiente de decisión. */
|
|
4356
|
+
.wa-thread__save-notice {
|
|
4357
|
+
display: flex;
|
|
4358
|
+
align-items: flex-start;
|
|
4359
|
+
gap: 8px;
|
|
4360
|
+
padding: 10px 12px;
|
|
4361
|
+
border-radius: 10px;
|
|
4362
|
+
font-size: 11.5px;
|
|
4363
|
+
color: #4B5262;
|
|
4364
|
+
background: #F4F5FF;
|
|
4365
|
+
}
|
|
4366
|
+
.wa-thread__save-notice svg {
|
|
4367
|
+
flex: 0 0 auto;
|
|
4368
|
+
margin-top: 1px;
|
|
4369
|
+
color: #4F5AED;
|
|
4370
|
+
}
|
|
4371
|
+
|
|
4372
|
+
.wa-thread__save-error {
|
|
4373
|
+
margin: 0;
|
|
4374
|
+
padding: 8px 10px;
|
|
4375
|
+
border: 1px solid #F0C9C5;
|
|
4376
|
+
border-radius: 8px;
|
|
4377
|
+
font-size: 12px;
|
|
4378
|
+
color: #B3261E;
|
|
4379
|
+
background: #FDF6F6;
|
|
4380
|
+
}
|
|
4381
|
+
|
|
4382
|
+
.wa-thread__save-actions {
|
|
4383
|
+
display: flex;
|
|
4384
|
+
justify-content: flex-end;
|
|
4385
|
+
gap: 8px;
|
|
4386
|
+
}
|
|
4387
|
+
.wa-thread__save-cancel {
|
|
4388
|
+
padding: 8px 16px;
|
|
4389
|
+
border: 1px solid #cbd2d9;
|
|
4390
|
+
border-radius: 999px;
|
|
4391
|
+
font: inherit;
|
|
4392
|
+
font-size: 13px;
|
|
4393
|
+
color: #2D3340;
|
|
4394
|
+
background: #ffffff;
|
|
4395
|
+
cursor: pointer;
|
|
4396
|
+
}
|
|
4397
|
+
.wa-thread__save-cancel:hover:not(:disabled) {
|
|
4398
|
+
background: #f5f7fa;
|
|
4399
|
+
}
|
|
4400
|
+
.wa-thread__save-cancel:disabled {
|
|
4401
|
+
color: #9aa5b1;
|
|
4402
|
+
cursor: default;
|
|
4403
|
+
}
|
|
4404
|
+
.wa-thread__save-submit {
|
|
4405
|
+
display: inline-flex;
|
|
4406
|
+
align-items: center;
|
|
4407
|
+
gap: 6px;
|
|
4408
|
+
padding: 8px 18px;
|
|
4409
|
+
border: 1px solid #4F5AED;
|
|
4410
|
+
border-radius: 999px;
|
|
4411
|
+
font: inherit;
|
|
4412
|
+
font-size: 13px;
|
|
4413
|
+
font-weight: 600;
|
|
4414
|
+
color: #ffffff;
|
|
4415
|
+
background: #4F5AED;
|
|
4416
|
+
cursor: pointer;
|
|
4417
|
+
}
|
|
4418
|
+
.wa-thread__save-submit:hover:not(:disabled) {
|
|
4419
|
+
border-color: #3F49D6;
|
|
4420
|
+
background: #3F49D6;
|
|
4421
|
+
}
|
|
4422
|
+
.wa-thread__save-submit:disabled {
|
|
4423
|
+
border-color: #cbd2d9;
|
|
4424
|
+
color: #9aa5b1;
|
|
4425
|
+
background: #f5f7fa;
|
|
4426
|
+
cursor: default;
|
|
4427
|
+
}
|
|
3583
4428
|
`;
|
|
3584
4429
|
//#endregion
|
|
3585
4430
|
//#region src/core/thread/useComposer.ts
|
|
@@ -4546,7 +5391,7 @@ function firstName(takenBy) {
|
|
|
4546
5391
|
const first = typeof takenBy === "string" ? takenBy.trim().split(/\s+/)[0] : "";
|
|
4547
5392
|
return first !== void 0 && first !== "" ? first : "Otra persona";
|
|
4548
5393
|
}
|
|
4549
|
-
function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, className }) {
|
|
5394
|
+
function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, saveDocument, className }) {
|
|
4550
5395
|
const { messages: serverMessages, status, error, windowState, canReply, takenBy, takenUntil, takenByMe, takenAt, takenByRole, hasOlder, loadOlder, retry, refresh } = useThread({
|
|
4551
5396
|
fetcher,
|
|
4552
5397
|
phone,
|
|
@@ -4624,6 +5469,14 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, cl
|
|
|
4624
5469
|
*/
|
|
4625
5470
|
const visible = messages.filter((message) => !isSuggestion(message) || message === suggestion.suggestion);
|
|
4626
5471
|
/**
|
|
5472
|
+
* El mensaje que se está guardando (DEV-7664): estado LOCAL de este hilo, igual que
|
|
5473
|
+
* `writeAnyway` — guarda DE QUÉ conversación vino (DEC-G). El modal se pinta sólo si
|
|
5474
|
+
* `saveDocument` existe Y `saveTarget.phone === phone`: un cambio de conversación lo cierra SIN
|
|
5475
|
+
* efecto, derivado en el render.
|
|
5476
|
+
*/
|
|
5477
|
+
const [saveTarget, setSaveTarget] = useState(null);
|
|
5478
|
+
const showSaveDialog = saveDocument !== void 0 && saveTarget !== null && saveTarget.phone === phone;
|
|
5479
|
+
/**
|
|
4627
5480
|
* «Escribir igual» (DEV-6309): el operador eligió escribir encima de la toma de otra persona.
|
|
4628
5481
|
*
|
|
4629
5482
|
* Es estado LOCAL de este hilo y guarda **de qué consulta vino** (DEC-G, el patrón de
|
|
@@ -4805,7 +5658,12 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, cl
|
|
|
4805
5658
|
}) : /* @__PURE__ */ jsx(MessageBubble, {
|
|
4806
5659
|
message,
|
|
4807
5660
|
optimistic: optimistic.has(message),
|
|
4808
|
-
fetcher
|
|
5661
|
+
fetcher,
|
|
5662
|
+
savedDocument: savedDocumentMark(message, saveDocument),
|
|
5663
|
+
onSaveAsDocument: canSaveAsDocument(message, saveDocument) ? () => setSaveTarget({
|
|
5664
|
+
message,
|
|
5665
|
+
phone
|
|
5666
|
+
}) : void 0
|
|
4809
5667
|
})] }, message.id ?? `sin-wamid-${position}`))]
|
|
4810
5668
|
}, group.key ?? `sin-dia-${groupIndex}`))]
|
|
4811
5669
|
}),
|
|
@@ -4828,6 +5686,12 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, cl
|
|
|
4828
5686
|
locked: foreignLive && !unlocked,
|
|
4829
5687
|
takeoverNotice: foreignLive && unlocked ? `${firstName(takenBy)} está atendiendo · el lifter verá a dos personas` : null,
|
|
4830
5688
|
focusRequest: unlocked && writeAnyway !== null ? writeAnyway.focus : null
|
|
5689
|
+
}),
|
|
5690
|
+
showSaveDialog && saveDocument !== void 0 && saveTarget !== null && /* @__PURE__ */ jsx(SaveDocumentDialog, {
|
|
5691
|
+
message: saveTarget.message,
|
|
5692
|
+
phone,
|
|
5693
|
+
input: saveDocument,
|
|
5694
|
+
onClose: () => setSaveTarget(null)
|
|
4831
5695
|
})
|
|
4832
5696
|
]
|
|
4833
5697
|
});
|
|
@@ -4916,7 +5780,7 @@ const SHELL_CSS = `
|
|
|
4916
5780
|
color: #8A91A0;
|
|
4917
5781
|
}
|
|
4918
5782
|
`;
|
|
4919
|
-
function WaConversations({ fetcher, initialPhone, pinned = false, refreshIntervalMs, className }) {
|
|
5783
|
+
function WaConversations({ fetcher, initialPhone, pinned = false, refreshIntervalMs, saveDocument, className }) {
|
|
4920
5784
|
/**
|
|
4921
5785
|
* El layout lo decide el ancho de ESTE contenedor, no el del viewport: el visor va embebido
|
|
4922
5786
|
* (en lms-web-app vive dentro del layout del LMS, no a pantalla completa).
|
|
@@ -4973,7 +5837,8 @@ function WaConversations({ fetcher, initialPhone, pinned = false, refreshInterva
|
|
|
4973
5837
|
fetcher,
|
|
4974
5838
|
phone: selectedPhone,
|
|
4975
5839
|
displayName: selectedName,
|
|
4976
|
-
refreshIntervalMs
|
|
5840
|
+
refreshIntervalMs,
|
|
5841
|
+
saveDocument: anchored ? saveDocument : void 0
|
|
4977
5842
|
})]
|
|
4978
5843
|
}) : layout === "wide" && /* @__PURE__ */ jsx("p", {
|
|
4979
5844
|
className: "wa-conversations__empty",
|
|
@@ -4991,5 +5856,16 @@ function WaConversations({ fetcher, initialPhone, pinned = false, refreshInterva
|
|
|
4991
5856
|
* comparten: un tag hardcodeado en dos lugares es un tag que se desincroniza.
|
|
4992
5857
|
*/
|
|
4993
5858
|
const WA_CONVERSATIONS_TAG = "wa-conversations";
|
|
5859
|
+
/**
|
|
5860
|
+
* «Guardar como documento» (DEV-7664): el contrato host↔visor para que la analista guarde en el
|
|
5861
|
+
* expediente la imagen o el PDF que mandó el lifter, sin que el visor llegue a conocer al
|
|
5862
|
+
* backoffice. Esto ES la API pública de `./react` (el tipo `SaveDocumentConfig`, vía la prop
|
|
5863
|
+
* `saveDocument` de `WaConversations`) y la del `CustomEvent` que despacha `./element`.
|
|
5864
|
+
*
|
|
5865
|
+
* Las funciones puras (`canSaveAsDocument`, `documentTypeOptions`, `resolveScope`,
|
|
5866
|
+
* `savedDocumentMark`, `savedMarkLabel`, `saveErrorMessage`) NO salen al barrel: son detalle de
|
|
5867
|
+
* `SaveDocumentDialog`/`MessageBubble`, y toda superficie pública se paga después.
|
|
5868
|
+
*/
|
|
5869
|
+
const SAVE_DOCUMENT_EVENT = "wa-conversations:save-document";
|
|
4994
5870
|
//#endregion
|
|
4995
|
-
export { ConversationList, ConversationThread, DEFAULT_REFRESH_INTERVAL_MS, NARROW_MAX_WIDTH, REPLY_TEXT_MAX_LENGTH, SUGGESTION_STATUS, WA_CONVERSATIONS_TAG, WaConversations, WaFetchError, dedupeByWamid, discardSuggestion, isCtaLink, isSuggestion, loadConversations, loadThread, mergeThread, mergeThreadPage, newClientMessageId, normalizeReplyMessage, normalizeWindowState, readSendError, releaseConversation, sendFailureCopy, sendReply, threadCtas, useComposer, useContainerLayout, useConversations, useSuggestion, useThread };
|
|
5871
|
+
export { ConversationList, ConversationThread, DEFAULT_REFRESH_INTERVAL_MS, NARROW_MAX_WIDTH, REPLY_TEXT_MAX_LENGTH, SAVE_DOCUMENT_EVENT, SUGGESTION_STATUS, WA_CONVERSATIONS_TAG, WaConversations, WaFetchError, dedupeByWamid, discardSuggestion, isCtaLink, isSuggestion, loadConversations, loadThread, mergeThread, mergeThreadPage, newClientMessageId, normalizeReplyMessage, normalizeWindowState, readSendError, releaseConversation, sendFailureCopy, sendReply, threadCtas, useComposer, useContainerLayout, useConversations, useSuggestion, useThread };
|