@adatechnology/conversations-ui 0.1.0-rc.12 → 0.1.0-rc.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-3RKFU46R.js → chunk-SOWV4264.js} +270 -109
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -1
- package/dist/preview/index.d.ts +3 -37
- package/dist/preview/index.js +37 -125
- package/dist/{types-B5C1DLu1.d.ts → types-O7kMP1Yn.d.ts} +52 -1
- package/package.json +1 -1
- package/src/AudioRecorderButton.test.tsx +30 -0
- package/src/AudioRecorderButton.tsx +241 -0
- package/src/{preview/audioRecorderFormat.test.ts → audioRecorderFormat.test.ts} +1 -1
- package/src/index.ts +6 -0
- package/src/preview/ConversationPreview.tsx +2 -2
- package/src/preview/index.ts +2 -2
- package/src/preview/AudioRecorderButton.tsx +0 -155
|
@@ -1081,11 +1081,169 @@ var MessageComposer = ({
|
|
|
1081
1081
|
);
|
|
1082
1082
|
};
|
|
1083
1083
|
|
|
1084
|
+
// src/AudioRecorderButton.tsx
|
|
1085
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useRef as useRef3, useState as useState7 } from "react";
|
|
1086
|
+
import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1087
|
+
var DEFAULT_AUDIO_RECORDER_BUTTON_LABELS = {
|
|
1088
|
+
start: "Gravar \xE1udio",
|
|
1089
|
+
stop: "Parar grava\xE7\xE3o",
|
|
1090
|
+
unsupported: "Este navegador n\xE3o grava \xE1udio.",
|
|
1091
|
+
denied: "Sem permiss\xE3o para usar o microfone.",
|
|
1092
|
+
review: "Ou\xE7a antes de enviar",
|
|
1093
|
+
send: "Enviar \xE1udio",
|
|
1094
|
+
discard: "Descartar \xE1udio",
|
|
1095
|
+
empty: "Nada foi captado pelo microfone."
|
|
1096
|
+
};
|
|
1097
|
+
var DEFAULT_MAX_RECORDING_MILLISECONDS = 5 * 60 * 1e3;
|
|
1098
|
+
var RECORDING_FORMATS = [
|
|
1099
|
+
{ mimeType: "audio/ogg;codecs=opus", uploadMimeType: "audio/ogg", extension: "ogg" },
|
|
1100
|
+
{ mimeType: "audio/mp4", uploadMimeType: "audio/mp4", extension: "m4a" },
|
|
1101
|
+
{ mimeType: "audio/webm", uploadMimeType: "audio/webm", extension: "webm" }
|
|
1102
|
+
];
|
|
1103
|
+
function resolveRecordingFormat() {
|
|
1104
|
+
if (typeof MediaRecorder === "undefined") return void 0;
|
|
1105
|
+
if (typeof MediaRecorder.isTypeSupported !== "function") return RECORDING_FORMATS[0];
|
|
1106
|
+
return RECORDING_FORMATS.find((format) => MediaRecorder.isTypeSupported(format.mimeType));
|
|
1107
|
+
}
|
|
1108
|
+
function AudioRecorderButton({
|
|
1109
|
+
onRecorded,
|
|
1110
|
+
onFailure,
|
|
1111
|
+
onRecordingChange,
|
|
1112
|
+
reviewBeforeSend = true,
|
|
1113
|
+
maxDurationMilliseconds = DEFAULT_MAX_RECORDING_MILLISECONDS,
|
|
1114
|
+
labels,
|
|
1115
|
+
disabled
|
|
1116
|
+
}) {
|
|
1117
|
+
const labelOf = (key) => labels?.[key] ?? DEFAULT_AUDIO_RECORDER_BUTTON_LABELS[key];
|
|
1118
|
+
const [isRecording, setIsRecording] = useState7(false);
|
|
1119
|
+
const [pending, setPending] = useState7(void 0);
|
|
1120
|
+
const recorderRef = useRef3(null);
|
|
1121
|
+
const autoStopRef = useRef3(void 0);
|
|
1122
|
+
const discard = useCallback3(() => {
|
|
1123
|
+
setPending((current) => {
|
|
1124
|
+
if (current) URL.revokeObjectURL(current.objectURL);
|
|
1125
|
+
return void 0;
|
|
1126
|
+
});
|
|
1127
|
+
}, []);
|
|
1128
|
+
useEffect2(() => discard, [discard]);
|
|
1129
|
+
const confirm = useCallback3(() => {
|
|
1130
|
+
if (!pending) return;
|
|
1131
|
+
void onRecorded(pending.file);
|
|
1132
|
+
discard();
|
|
1133
|
+
}, [discard, onRecorded, pending]);
|
|
1134
|
+
const stop = useCallback3(() => {
|
|
1135
|
+
recorderRef.current?.stop();
|
|
1136
|
+
}, []);
|
|
1137
|
+
const start = useCallback3(async () => {
|
|
1138
|
+
const format = resolveRecordingFormat();
|
|
1139
|
+
if (!format || !navigator.mediaDevices?.getUserMedia) {
|
|
1140
|
+
onFailure?.(labels?.unsupported ?? DEFAULT_AUDIO_RECORDER_BUTTON_LABELS.unsupported);
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
try {
|
|
1144
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1145
|
+
const recorder = new MediaRecorder(stream, { mimeType: format.mimeType });
|
|
1146
|
+
const chunks = [];
|
|
1147
|
+
recorder.addEventListener("dataavailable", (event) => {
|
|
1148
|
+
if (event.data.size > 0) chunks.push(event.data);
|
|
1149
|
+
});
|
|
1150
|
+
recorder.addEventListener("stop", () => {
|
|
1151
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
1152
|
+
clearTimeout(autoStopRef.current);
|
|
1153
|
+
setIsRecording(false);
|
|
1154
|
+
onRecordingChange?.(false);
|
|
1155
|
+
recorderRef.current = null;
|
|
1156
|
+
const blob = new Blob(chunks, { type: format.uploadMimeType });
|
|
1157
|
+
const file = new File([blob], `audio-${Date.now()}.${format.extension}`, {
|
|
1158
|
+
type: format.uploadMimeType
|
|
1159
|
+
});
|
|
1160
|
+
if (blob.size === 0) {
|
|
1161
|
+
onFailure?.(labelOf("empty"));
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
if (!reviewBeforeSend) {
|
|
1165
|
+
void onRecorded(file);
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
setPending({ file, objectURL: URL.createObjectURL(blob) });
|
|
1169
|
+
});
|
|
1170
|
+
recorderRef.current = recorder;
|
|
1171
|
+
recorder.start();
|
|
1172
|
+
autoStopRef.current = setTimeout(() => recorder.stop(), maxDurationMilliseconds);
|
|
1173
|
+
setIsRecording(true);
|
|
1174
|
+
onRecordingChange?.(true);
|
|
1175
|
+
} catch {
|
|
1176
|
+
onFailure?.(labels?.denied ?? DEFAULT_AUDIO_RECORDER_BUTTON_LABELS.denied);
|
|
1177
|
+
}
|
|
1178
|
+
}, [maxDurationMilliseconds, onFailure, onRecorded, onRecordingChange, reviewBeforeSend]);
|
|
1179
|
+
const toggleLabel = isRecording ? labelOf("stop") : labelOf("start");
|
|
1180
|
+
return (
|
|
1181
|
+
/* O painel de revisão flutua sobre o botão em vez de ocupar espaço na barra: o microfone mora
|
|
1182
|
+
na caixa do botão de enviar, e empurrar o composer para cima a cada gravação faria a
|
|
1183
|
+
conversa saltar. */
|
|
1184
|
+
/* @__PURE__ */ jsxs9("div", { className: "relative flex-shrink-0", children: [
|
|
1185
|
+
pending && /* @__PURE__ */ jsxs9(
|
|
1186
|
+
"div",
|
|
1187
|
+
{
|
|
1188
|
+
role: "group",
|
|
1189
|
+
"aria-label": labelOf("review"),
|
|
1190
|
+
className: "absolute bottom-full right-0 z-20 mb-2 flex w-64 items-center gap-2 rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-gray-700 dark:bg-gray-800",
|
|
1191
|
+
children: [
|
|
1192
|
+
/* @__PURE__ */ jsx13("audio", { src: pending.objectURL, controls: true, className: "h-8 min-w-0 flex-1" }),
|
|
1193
|
+
/* @__PURE__ */ jsx13(
|
|
1194
|
+
"button",
|
|
1195
|
+
{
|
|
1196
|
+
type: "button",
|
|
1197
|
+
onClick: discard,
|
|
1198
|
+
title: labelOf("discard"),
|
|
1199
|
+
"aria-label": labelOf("discard"),
|
|
1200
|
+
className: "flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full text-gray-500 transition-colors hover:bg-gray-100 hover:text-red-500 dark:hover:bg-gray-700",
|
|
1201
|
+
children: /* @__PURE__ */ jsxs9("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: [
|
|
1202
|
+
/* @__PURE__ */ jsx13("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
1203
|
+
/* @__PURE__ */ jsx13("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
1204
|
+
] })
|
|
1205
|
+
}
|
|
1206
|
+
),
|
|
1207
|
+
/* @__PURE__ */ jsx13(
|
|
1208
|
+
"button",
|
|
1209
|
+
{
|
|
1210
|
+
type: "button",
|
|
1211
|
+
onClick: confirm,
|
|
1212
|
+
title: labelOf("send"),
|
|
1213
|
+
"aria-label": labelOf("send"),
|
|
1214
|
+
className: "flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-emerald-500 text-white transition-colors hover:bg-emerald-600",
|
|
1215
|
+
children: /* @__PURE__ */ jsx13("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx13("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) })
|
|
1216
|
+
}
|
|
1217
|
+
)
|
|
1218
|
+
]
|
|
1219
|
+
}
|
|
1220
|
+
),
|
|
1221
|
+
/* @__PURE__ */ jsx13(
|
|
1222
|
+
"button",
|
|
1223
|
+
{
|
|
1224
|
+
type: "button",
|
|
1225
|
+
disabled: disabled || pending !== void 0,
|
|
1226
|
+
onClick: () => isRecording ? stop() : void start(),
|
|
1227
|
+
title: toggleLabel,
|
|
1228
|
+
"aria-label": toggleLabel,
|
|
1229
|
+
"aria-pressed": isRecording,
|
|
1230
|
+
className: `flex h-10 w-10 items-center justify-center rounded-full transition-colors disabled:opacity-50 ${isRecording ? "animate-pulse bg-red-500 text-white ring-4 ring-red-500/30 hover:bg-red-600" : "text-gray-500 hover:bg-gray-200 dark:hover:bg-gray-700"}`,
|
|
1231
|
+
children: isRecording ? /* @__PURE__ */ jsx13("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx13("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2" }) }) : /* @__PURE__ */ jsxs9("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: [
|
|
1232
|
+
/* @__PURE__ */ jsx13("path", { d: "M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z" }),
|
|
1233
|
+
/* @__PURE__ */ jsx13("path", { d: "M19 11a7 7 0 0 1-14 0" }),
|
|
1234
|
+
/* @__PURE__ */ jsx13("line", { x1: "12", y1: "18", x2: "12", y2: "22" })
|
|
1235
|
+
] })
|
|
1236
|
+
}
|
|
1237
|
+
)
|
|
1238
|
+
] })
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1084
1242
|
// src/DateDivider.tsx
|
|
1085
|
-
import { jsx as
|
|
1243
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
1086
1244
|
function DateDivider({ iso, className, classNames }) {
|
|
1087
1245
|
const { dateDivider } = useConversationLocales();
|
|
1088
|
-
return /* @__PURE__ */
|
|
1246
|
+
return /* @__PURE__ */ jsx14("div", { className: cn("flex justify-center sticky top-0 z-10 my-2 pointer-events-none", classNames?.root, className), children: /* @__PURE__ */ jsx14(
|
|
1089
1247
|
"span",
|
|
1090
1248
|
{
|
|
1091
1249
|
className: cn(
|
|
@@ -1152,13 +1310,13 @@ function phoneInitials(number) {
|
|
|
1152
1310
|
}
|
|
1153
1311
|
|
|
1154
1312
|
// src/hooks/useAsyncResource.ts
|
|
1155
|
-
import { useCallback as
|
|
1313
|
+
import { useCallback as useCallback4, useEffect as useEffect3, useRef as useRef4, useState as useState8 } from "react";
|
|
1156
1314
|
function useAsyncResource(fetcher, deps) {
|
|
1157
|
-
const [data, setData] =
|
|
1158
|
-
const [loading, setLoading] =
|
|
1159
|
-
const [error, setError] =
|
|
1160
|
-
const requestIdRef =
|
|
1161
|
-
const load =
|
|
1315
|
+
const [data, setData] = useState8(void 0);
|
|
1316
|
+
const [loading, setLoading] = useState8(false);
|
|
1317
|
+
const [error, setError] = useState8(void 0);
|
|
1318
|
+
const requestIdRef = useRef4(0);
|
|
1319
|
+
const load = useCallback4(async () => {
|
|
1162
1320
|
const requestId = ++requestIdRef.current;
|
|
1163
1321
|
setLoading(true);
|
|
1164
1322
|
setError(void 0);
|
|
@@ -1171,7 +1329,7 @@ function useAsyncResource(fetcher, deps) {
|
|
|
1171
1329
|
if (requestId === requestIdRef.current) setLoading(false);
|
|
1172
1330
|
}
|
|
1173
1331
|
}, deps);
|
|
1174
|
-
|
|
1332
|
+
useEffect3(() => {
|
|
1175
1333
|
load();
|
|
1176
1334
|
}, [load]);
|
|
1177
1335
|
return { data, loading, error, refetch: load };
|
|
@@ -1206,9 +1364,9 @@ function useConversationDocuments(conversationId, params) {
|
|
|
1206
1364
|
}
|
|
1207
1365
|
|
|
1208
1366
|
// src/ConversationDocumentsPanel.tsx
|
|
1209
|
-
import { useState as
|
|
1367
|
+
import { useState as useState9 } from "react";
|
|
1210
1368
|
import { ArrowUpDown, Bot, Download, Eye, Users } from "lucide-react";
|
|
1211
|
-
import { jsx as
|
|
1369
|
+
import { jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1212
1370
|
var DOCUMENT_SOURCE_FILTER = {
|
|
1213
1371
|
ALL: "all",
|
|
1214
1372
|
CUSTOMER: "customer",
|
|
@@ -1248,12 +1406,12 @@ function ConversationDocumentsPanel({
|
|
|
1248
1406
|
}) {
|
|
1249
1407
|
const labels = { ...DEFAULT_CONVERSATION_DOCUMENTS_LABELS, ...labelsOverride };
|
|
1250
1408
|
const context = useConversations();
|
|
1251
|
-
const [search, setSearch] =
|
|
1252
|
-
const [sourceFilter, setSourceFilter] =
|
|
1253
|
-
const [sortDirection, setSortDirection] =
|
|
1254
|
-
const [page, setPage] =
|
|
1255
|
-
const [selectedIds, setSelectedIds] =
|
|
1256
|
-
const [archiveError, setArchiveError] =
|
|
1409
|
+
const [search, setSearch] = useState9("");
|
|
1410
|
+
const [sourceFilter, setSourceFilter] = useState9(DOCUMENT_SOURCE_FILTER.ALL);
|
|
1411
|
+
const [sortDirection, setSortDirection] = useState9("desc");
|
|
1412
|
+
const [page, setPage] = useState9(1);
|
|
1413
|
+
const [selectedIds, setSelectedIds] = useState9([]);
|
|
1414
|
+
const [archiveError, setArchiveError] = useState9(false);
|
|
1257
1415
|
const hasFilters = search !== "" || sourceFilter !== DOCUMENT_SOURCE_FILTER.ALL || sortDirection !== "desc";
|
|
1258
1416
|
const { documents, total, loading, error } = useConversationDocuments(open ? conversationId : void 0, {
|
|
1259
1417
|
search,
|
|
@@ -1304,10 +1462,10 @@ function ConversationDocumentsPanel({
|
|
|
1304
1462
|
}
|
|
1305
1463
|
}
|
|
1306
1464
|
if (!open) return null;
|
|
1307
|
-
return /* @__PURE__ */
|
|
1308
|
-
/* @__PURE__ */
|
|
1309
|
-
/* @__PURE__ */
|
|
1310
|
-
/* @__PURE__ */
|
|
1465
|
+
return /* @__PURE__ */ jsx15("div", { className: cn("border-b", classNames?.root, className), children: /* @__PURE__ */ jsxs10("section", { className: cn("px-4 py-3", classNames?.body), children: [
|
|
1466
|
+
/* @__PURE__ */ jsx15("p", { className: cn("mb-2 text-sm font-medium", classNames?.title), children: labels.title }),
|
|
1467
|
+
/* @__PURE__ */ jsxs10("div", { className: cn("mb-2 flex flex-wrap items-center gap-2 border-b pb-2", classNames?.filters), children: [
|
|
1468
|
+
/* @__PURE__ */ jsx15(
|
|
1311
1469
|
"input",
|
|
1312
1470
|
{
|
|
1313
1471
|
type: "search",
|
|
@@ -1318,7 +1476,7 @@ function ConversationDocumentsPanel({
|
|
|
1318
1476
|
className: cn("w-full rounded-md border px-3 py-2 text-sm sm:w-52", classNames?.search)
|
|
1319
1477
|
}
|
|
1320
1478
|
),
|
|
1321
|
-
/* @__PURE__ */
|
|
1479
|
+
/* @__PURE__ */ jsxs10(
|
|
1322
1480
|
"select",
|
|
1323
1481
|
{
|
|
1324
1482
|
value: sourceFilter,
|
|
@@ -1326,25 +1484,25 @@ function ConversationDocumentsPanel({
|
|
|
1326
1484
|
"aria-label": labels.sourceFilterAll,
|
|
1327
1485
|
className: cn("w-full rounded-md border px-2 py-2 text-sm sm:w-36", classNames?.sourceSelect),
|
|
1328
1486
|
children: [
|
|
1329
|
-
/* @__PURE__ */
|
|
1330
|
-
/* @__PURE__ */
|
|
1331
|
-
/* @__PURE__ */
|
|
1487
|
+
/* @__PURE__ */ jsx15("option", { value: DOCUMENT_SOURCE_FILTER.ALL, children: labels.sourceFilterAll }),
|
|
1488
|
+
/* @__PURE__ */ jsx15("option", { value: DOCUMENT_SOURCE_FILTER.CUSTOMER, children: labels.sourceFilterCustomer }),
|
|
1489
|
+
/* @__PURE__ */ jsx15("option", { value: DOCUMENT_SOURCE_FILTER.TEAM, children: labels.sourceFilterTeam })
|
|
1332
1490
|
]
|
|
1333
1491
|
}
|
|
1334
1492
|
),
|
|
1335
|
-
/* @__PURE__ */
|
|
1493
|
+
/* @__PURE__ */ jsxs10(
|
|
1336
1494
|
"button",
|
|
1337
1495
|
{
|
|
1338
1496
|
type: "button",
|
|
1339
1497
|
onClick: () => applyFilter(() => setSortDirection(sortDirection === "desc" ? "asc" : "desc")),
|
|
1340
1498
|
className: cn("cv-header-action inline-flex items-center gap-1", classNames?.sortButton),
|
|
1341
1499
|
children: [
|
|
1342
|
-
/* @__PURE__ */
|
|
1500
|
+
/* @__PURE__ */ jsx15(ArrowUpDown, { size: 14 }),
|
|
1343
1501
|
sortDirection === "desc" ? labels.sortMostRecent : labels.sortOldest
|
|
1344
1502
|
]
|
|
1345
1503
|
}
|
|
1346
1504
|
),
|
|
1347
|
-
hasFilters ? /* @__PURE__ */
|
|
1505
|
+
hasFilters ? /* @__PURE__ */ jsx15(
|
|
1348
1506
|
"button",
|
|
1349
1507
|
{
|
|
1350
1508
|
type: "button",
|
|
@@ -1358,12 +1516,12 @@ function ConversationDocumentsPanel({
|
|
|
1358
1516
|
}
|
|
1359
1517
|
) : null
|
|
1360
1518
|
] }),
|
|
1361
|
-
loading ? /* @__PURE__ */
|
|
1362
|
-
error ? /* @__PURE__ */
|
|
1363
|
-
!loading && !error && documents.length === 0 ? /* @__PURE__ */
|
|
1364
|
-
canArchive && documents.length > 0 ? /* @__PURE__ */
|
|
1365
|
-
/* @__PURE__ */
|
|
1366
|
-
/* @__PURE__ */
|
|
1519
|
+
loading ? /* @__PURE__ */ jsx15("p", { className: cn("text-xs text-gray-500", classNames?.status), children: labels.loading }) : null,
|
|
1520
|
+
error ? /* @__PURE__ */ jsx15("p", { role: "alert", className: cn("text-xs text-red-600 dark:text-red-400", classNames?.status), children: labels.failure }) : null,
|
|
1521
|
+
!loading && !error && documents.length === 0 ? /* @__PURE__ */ jsx15("p", { className: cn("text-xs text-gray-500", classNames?.status), children: hasFilters ? labels.noResults : labels.empty }) : null,
|
|
1522
|
+
canArchive && documents.length > 0 ? /* @__PURE__ */ jsxs10("div", { className: cn("mb-2 flex flex-wrap items-center gap-3 text-xs", classNames?.selectionBar), children: [
|
|
1523
|
+
/* @__PURE__ */ jsxs10("label", { className: "inline-flex items-center gap-1.5", children: [
|
|
1524
|
+
/* @__PURE__ */ jsx15(
|
|
1367
1525
|
"input",
|
|
1368
1526
|
{
|
|
1369
1527
|
type: "checkbox",
|
|
@@ -1374,13 +1532,13 @@ function ConversationDocumentsPanel({
|
|
|
1374
1532
|
),
|
|
1375
1533
|
labels.selectAll
|
|
1376
1534
|
] }),
|
|
1377
|
-
selectedIds.length > 0 ? /* @__PURE__ */
|
|
1378
|
-
archiveError ? /* @__PURE__ */
|
|
1535
|
+
selectedIds.length > 0 ? /* @__PURE__ */ jsx15("button", { type: "button", onClick: () => void handleDownloadSelected(), className: "cv-header-action", children: labels.downloadSelected(selectedIds.length) }) : null,
|
|
1536
|
+
archiveError ? /* @__PURE__ */ jsx15("span", { role: "alert", className: "text-red-600 dark:text-red-400", children: labels.archiveFailed }) : null
|
|
1379
1537
|
] }) : null,
|
|
1380
|
-
/* @__PURE__ */
|
|
1538
|
+
/* @__PURE__ */ jsx15("ul", { className: cn("space-y-2", classNames?.list), children: documents.map((document2) => {
|
|
1381
1539
|
const isFromCustomer = !TEAM_SOURCES.has(document2.source);
|
|
1382
1540
|
const SourceIcon = isFromCustomer ? Users : Bot;
|
|
1383
|
-
return /* @__PURE__ */
|
|
1541
|
+
return /* @__PURE__ */ jsxs10(
|
|
1384
1542
|
"li",
|
|
1385
1543
|
{
|
|
1386
1544
|
className: cn(
|
|
@@ -1388,8 +1546,8 @@ function ConversationDocumentsPanel({
|
|
|
1388
1546
|
classNames?.item
|
|
1389
1547
|
),
|
|
1390
1548
|
children: [
|
|
1391
|
-
/* @__PURE__ */
|
|
1392
|
-
canArchive ? /* @__PURE__ */
|
|
1549
|
+
/* @__PURE__ */ jsxs10("div", { className: "flex min-w-0 flex-1 items-center gap-2", children: [
|
|
1550
|
+
canArchive ? /* @__PURE__ */ jsx15(
|
|
1393
1551
|
"input",
|
|
1394
1552
|
{
|
|
1395
1553
|
type: "checkbox",
|
|
@@ -1399,9 +1557,9 @@ function ConversationDocumentsPanel({
|
|
|
1399
1557
|
className: cn("shrink-0", classNames?.checkbox)
|
|
1400
1558
|
}
|
|
1401
1559
|
) : null,
|
|
1402
|
-
/* @__PURE__ */
|
|
1403
|
-
/* @__PURE__ */
|
|
1404
|
-
/* @__PURE__ */
|
|
1560
|
+
/* @__PURE__ */ jsx15(FileIcon, { filename: document2.filename, mimeType: document2.mimeType }),
|
|
1561
|
+
/* @__PURE__ */ jsxs10("div", { className: "min-w-0 flex-1", children: [
|
|
1562
|
+
/* @__PURE__ */ jsxs10(
|
|
1405
1563
|
"div",
|
|
1406
1564
|
{
|
|
1407
1565
|
className: cn(
|
|
@@ -1410,12 +1568,12 @@ function ConversationDocumentsPanel({
|
|
|
1410
1568
|
classNames?.sourceBadge
|
|
1411
1569
|
),
|
|
1412
1570
|
children: [
|
|
1413
|
-
/* @__PURE__ */
|
|
1571
|
+
/* @__PURE__ */ jsx15(SourceIcon, { size: 11 }),
|
|
1414
1572
|
isFromCustomer ? labels.sourceFilterCustomer : labels.sourceFilterTeam
|
|
1415
1573
|
]
|
|
1416
1574
|
}
|
|
1417
1575
|
),
|
|
1418
|
-
/* @__PURE__ */
|
|
1576
|
+
/* @__PURE__ */ jsx15(
|
|
1419
1577
|
"div",
|
|
1420
1578
|
{
|
|
1421
1579
|
className: cn("truncate text-sm font-medium", classNames?.filename),
|
|
@@ -1423,15 +1581,15 @@ function ConversationDocumentsPanel({
|
|
|
1423
1581
|
children: document2.filename
|
|
1424
1582
|
}
|
|
1425
1583
|
),
|
|
1426
|
-
/* @__PURE__ */
|
|
1584
|
+
/* @__PURE__ */ jsxs10("div", { className: cn("text-xs text-gray-500 dark:text-gray-400", classNames?.meta), children: [
|
|
1427
1585
|
formatDateTime(document2.linkedAt),
|
|
1428
1586
|
" \xB7 ",
|
|
1429
1587
|
formatFileSize(document2.sizeBytes)
|
|
1430
1588
|
] })
|
|
1431
1589
|
] })
|
|
1432
1590
|
] }),
|
|
1433
|
-
/* @__PURE__ */
|
|
1434
|
-
/* @__PURE__ */
|
|
1591
|
+
/* @__PURE__ */ jsxs10("div", { className: "flex shrink-0 gap-1", children: [
|
|
1592
|
+
/* @__PURE__ */ jsx15(
|
|
1435
1593
|
"button",
|
|
1436
1594
|
{
|
|
1437
1595
|
type: "button",
|
|
@@ -1439,10 +1597,10 @@ function ConversationDocumentsPanel({
|
|
|
1439
1597
|
title: labels.view,
|
|
1440
1598
|
"aria-label": `${labels.view}: ${document2.filename}`,
|
|
1441
1599
|
className: cn("cv-header-icon", classNames?.viewButton),
|
|
1442
|
-
children: /* @__PURE__ */
|
|
1600
|
+
children: /* @__PURE__ */ jsx15(Eye, { size: 14 })
|
|
1443
1601
|
}
|
|
1444
1602
|
),
|
|
1445
|
-
/* @__PURE__ */
|
|
1603
|
+
/* @__PURE__ */ jsx15(
|
|
1446
1604
|
"button",
|
|
1447
1605
|
{
|
|
1448
1606
|
type: "button",
|
|
@@ -1450,7 +1608,7 @@ function ConversationDocumentsPanel({
|
|
|
1450
1608
|
title: labels.download,
|
|
1451
1609
|
"aria-label": `${labels.download}: ${document2.filename}`,
|
|
1452
1610
|
className: cn("cv-header-icon", classNames?.downloadButton),
|
|
1453
|
-
children: /* @__PURE__ */
|
|
1611
|
+
children: /* @__PURE__ */ jsx15(Download, { size: 14 })
|
|
1454
1612
|
}
|
|
1455
1613
|
)
|
|
1456
1614
|
] })
|
|
@@ -1459,7 +1617,7 @@ function ConversationDocumentsPanel({
|
|
|
1459
1617
|
document2.id
|
|
1460
1618
|
);
|
|
1461
1619
|
}) }),
|
|
1462
|
-
total > perPage ? /* @__PURE__ */
|
|
1620
|
+
total > perPage ? /* @__PURE__ */ jsxs10(
|
|
1463
1621
|
"div",
|
|
1464
1622
|
{
|
|
1465
1623
|
className: cn(
|
|
@@ -1467,9 +1625,9 @@ function ConversationDocumentsPanel({
|
|
|
1467
1625
|
classNames?.pagination
|
|
1468
1626
|
),
|
|
1469
1627
|
children: [
|
|
1470
|
-
/* @__PURE__ */
|
|
1471
|
-
/* @__PURE__ */
|
|
1472
|
-
/* @__PURE__ */
|
|
1628
|
+
/* @__PURE__ */ jsx15("span", { className: "text-gray-400", children: labels.total(total) }),
|
|
1629
|
+
/* @__PURE__ */ jsxs10("div", { className: "flex items-center gap-2", children: [
|
|
1630
|
+
/* @__PURE__ */ jsx15(
|
|
1473
1631
|
"button",
|
|
1474
1632
|
{
|
|
1475
1633
|
type: "button",
|
|
@@ -1480,8 +1638,8 @@ function ConversationDocumentsPanel({
|
|
|
1480
1638
|
children: "\u2039"
|
|
1481
1639
|
}
|
|
1482
1640
|
),
|
|
1483
|
-
/* @__PURE__ */
|
|
1484
|
-
/* @__PURE__ */
|
|
1641
|
+
/* @__PURE__ */ jsx15("span", { className: "text-gray-500", children: labels.page(page, lastPage) }),
|
|
1642
|
+
/* @__PURE__ */ jsx15(
|
|
1485
1643
|
"button",
|
|
1486
1644
|
{
|
|
1487
1645
|
type: "button",
|
|
@@ -1500,9 +1658,9 @@ function ConversationDocumentsPanel({
|
|
|
1500
1658
|
}
|
|
1501
1659
|
|
|
1502
1660
|
// src/DocumentsLibrary.tsx
|
|
1503
|
-
import { useEffect as
|
|
1661
|
+
import { useEffect as useEffect4, useState as useState10 } from "react";
|
|
1504
1662
|
import { ArrowUpDown as ArrowUpDown2, Bot as Bot2, Download as Download2, Eye as Eye2, MessageSquare, Users as Users2 } from "lucide-react";
|
|
1505
|
-
import { jsx as
|
|
1663
|
+
import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1506
1664
|
var DEFAULT_DOCUMENTS_LIBRARY_LABELS = {
|
|
1507
1665
|
title: "Documentos",
|
|
1508
1666
|
searchPlaceholder: "Buscar por nome do arquivo ou telefone",
|
|
@@ -1533,18 +1691,18 @@ function DocumentsLibrary({
|
|
|
1533
1691
|
}) {
|
|
1534
1692
|
const labels = { ...DEFAULT_DOCUMENTS_LIBRARY_LABELS, ...labelsOverride };
|
|
1535
1693
|
const context = useConversations();
|
|
1536
|
-
const [search, setSearch] =
|
|
1537
|
-
const [sourceFilter, setSourceFilter] =
|
|
1538
|
-
const [sortDirection, setSortDirection] =
|
|
1539
|
-
const [page, setPage] =
|
|
1540
|
-
const [documents, setDocuments] =
|
|
1541
|
-
const [total, setTotal] =
|
|
1542
|
-
const [loading, setLoading] =
|
|
1543
|
-
const [failed, setFailed] =
|
|
1694
|
+
const [search, setSearch] = useState10("");
|
|
1695
|
+
const [sourceFilter, setSourceFilter] = useState10(DOCUMENT_SOURCE_FILTER.ALL);
|
|
1696
|
+
const [sortDirection, setSortDirection] = useState10("desc");
|
|
1697
|
+
const [page, setPage] = useState10(1);
|
|
1698
|
+
const [documents, setDocuments] = useState10([]);
|
|
1699
|
+
const [total, setTotal] = useState10(0);
|
|
1700
|
+
const [loading, setLoading] = useState10(false);
|
|
1701
|
+
const [failed, setFailed] = useState10(false);
|
|
1544
1702
|
const hasFilters = search !== "" || sourceFilter !== DOCUMENT_SOURCE_FILTER.ALL || sortDirection !== "desc";
|
|
1545
1703
|
const lastPage = Math.max(1, Math.ceil(total / perPage));
|
|
1546
1704
|
const fetchAll = context?.api.getAllDocuments;
|
|
1547
|
-
|
|
1705
|
+
useEffect4(() => {
|
|
1548
1706
|
if (!fetchAll) return;
|
|
1549
1707
|
let active = true;
|
|
1550
1708
|
setLoading(true);
|
|
@@ -1577,10 +1735,10 @@ function DocumentsLibrary({
|
|
|
1577
1735
|
if (url) window.open(url, "_blank", "noopener,noreferrer");
|
|
1578
1736
|
}
|
|
1579
1737
|
if (!fetchAll) return null;
|
|
1580
|
-
return /* @__PURE__ */
|
|
1581
|
-
/* @__PURE__ */
|
|
1582
|
-
/* @__PURE__ */
|
|
1583
|
-
/* @__PURE__ */
|
|
1738
|
+
return /* @__PURE__ */ jsxs11("div", { className: cn("space-y-3", classNames?.root, className), children: [
|
|
1739
|
+
/* @__PURE__ */ jsx16("h2", { className: cn("text-lg font-semibold", classNames?.title), children: labels.title }),
|
|
1740
|
+
/* @__PURE__ */ jsxs11("div", { className: cn("flex flex-wrap items-center gap-2", classNames?.filters), children: [
|
|
1741
|
+
/* @__PURE__ */ jsx16(
|
|
1584
1742
|
"input",
|
|
1585
1743
|
{
|
|
1586
1744
|
type: "search",
|
|
@@ -1591,7 +1749,7 @@ function DocumentsLibrary({
|
|
|
1591
1749
|
className: cn("w-full rounded-md border px-3 py-2 text-sm sm:w-64", classNames?.search)
|
|
1592
1750
|
}
|
|
1593
1751
|
),
|
|
1594
|
-
/* @__PURE__ */
|
|
1752
|
+
/* @__PURE__ */ jsxs11(
|
|
1595
1753
|
"select",
|
|
1596
1754
|
{
|
|
1597
1755
|
value: sourceFilter,
|
|
@@ -1599,25 +1757,25 @@ function DocumentsLibrary({
|
|
|
1599
1757
|
"aria-label": labels.sourceFilterAll,
|
|
1600
1758
|
className: cn("w-full rounded-md border px-2 py-2 text-sm sm:w-40", classNames?.sourceSelect),
|
|
1601
1759
|
children: [
|
|
1602
|
-
/* @__PURE__ */
|
|
1603
|
-
/* @__PURE__ */
|
|
1604
|
-
/* @__PURE__ */
|
|
1760
|
+
/* @__PURE__ */ jsx16("option", { value: DOCUMENT_SOURCE_FILTER.ALL, children: labels.sourceFilterAll }),
|
|
1761
|
+
/* @__PURE__ */ jsx16("option", { value: DOCUMENT_SOURCE_FILTER.CUSTOMER, children: labels.sourceFilterCustomer }),
|
|
1762
|
+
/* @__PURE__ */ jsx16("option", { value: DOCUMENT_SOURCE_FILTER.TEAM, children: labels.sourceFilterTeam })
|
|
1605
1763
|
]
|
|
1606
1764
|
}
|
|
1607
1765
|
),
|
|
1608
|
-
/* @__PURE__ */
|
|
1766
|
+
/* @__PURE__ */ jsxs11(
|
|
1609
1767
|
"button",
|
|
1610
1768
|
{
|
|
1611
1769
|
type: "button",
|
|
1612
1770
|
onClick: () => applyFilter(() => setSortDirection(sortDirection === "desc" ? "asc" : "desc")),
|
|
1613
1771
|
className: cn("cv-header-action inline-flex items-center gap-1", classNames?.sortButton),
|
|
1614
1772
|
children: [
|
|
1615
|
-
/* @__PURE__ */
|
|
1773
|
+
/* @__PURE__ */ jsx16(ArrowUpDown2, { size: 14 }),
|
|
1616
1774
|
sortDirection === "desc" ? labels.sortMostRecent : labels.sortOldest
|
|
1617
1775
|
]
|
|
1618
1776
|
}
|
|
1619
1777
|
),
|
|
1620
|
-
hasFilters ? /* @__PURE__ */
|
|
1778
|
+
hasFilters ? /* @__PURE__ */ jsx16(
|
|
1621
1779
|
"button",
|
|
1622
1780
|
{
|
|
1623
1781
|
type: "button",
|
|
@@ -1631,13 +1789,13 @@ function DocumentsLibrary({
|
|
|
1631
1789
|
}
|
|
1632
1790
|
) : null
|
|
1633
1791
|
] }),
|
|
1634
|
-
loading ? /* @__PURE__ */
|
|
1635
|
-
failed ? /* @__PURE__ */
|
|
1636
|
-
!loading && !failed && documents.length === 0 ? /* @__PURE__ */
|
|
1637
|
-
/* @__PURE__ */
|
|
1792
|
+
loading ? /* @__PURE__ */ jsx16("p", { className: cn("text-sm text-gray-500", classNames?.status), children: labels.loading }) : null,
|
|
1793
|
+
failed ? /* @__PURE__ */ jsx16("p", { role: "alert", className: cn("text-sm text-red-600 dark:text-red-400", classNames?.status), children: labels.failure }) : null,
|
|
1794
|
+
!loading && !failed && documents.length === 0 ? /* @__PURE__ */ jsx16("p", { className: cn("text-sm text-gray-500", classNames?.status), children: hasFilters ? labels.noResults : labels.empty }) : null,
|
|
1795
|
+
/* @__PURE__ */ jsx16("ul", { className: cn("space-y-2", classNames?.list), children: documents.map((document2) => {
|
|
1638
1796
|
const isFromCustomer = !TEAM_SOURCES2.has(document2.source);
|
|
1639
1797
|
const SourceIcon = isFromCustomer ? Users2 : Bot2;
|
|
1640
|
-
return /* @__PURE__ */
|
|
1798
|
+
return /* @__PURE__ */ jsxs11(
|
|
1641
1799
|
"li",
|
|
1642
1800
|
{
|
|
1643
1801
|
className: cn(
|
|
@@ -1645,23 +1803,23 @@ function DocumentsLibrary({
|
|
|
1645
1803
|
classNames?.item
|
|
1646
1804
|
),
|
|
1647
1805
|
children: [
|
|
1648
|
-
/* @__PURE__ */
|
|
1649
|
-
/* @__PURE__ */
|
|
1650
|
-
/* @__PURE__ */
|
|
1651
|
-
/* @__PURE__ */
|
|
1652
|
-
/* @__PURE__ */
|
|
1653
|
-
/* @__PURE__ */
|
|
1654
|
-
/* @__PURE__ */
|
|
1806
|
+
/* @__PURE__ */ jsxs11("div", { className: "flex min-w-0 flex-1 items-center gap-3", children: [
|
|
1807
|
+
/* @__PURE__ */ jsx16(FileIcon, { filename: document2.filename, mimeType: document2.mimeType }),
|
|
1808
|
+
/* @__PURE__ */ jsxs11("div", { className: "min-w-0 flex-1", children: [
|
|
1809
|
+
/* @__PURE__ */ jsx16("div", { className: cn("truncate text-sm font-medium", classNames?.filename), title: document2.filename, children: document2.filename }),
|
|
1810
|
+
/* @__PURE__ */ jsxs11("div", { className: cn("flex flex-wrap items-center gap-x-2 text-xs text-gray-500", classNames?.meta), children: [
|
|
1811
|
+
/* @__PURE__ */ jsxs11("span", { className: "inline-flex items-center gap-1", children: [
|
|
1812
|
+
/* @__PURE__ */ jsx16(SourceIcon, { size: 11 }),
|
|
1655
1813
|
isFromCustomer ? labels.sourceFilterCustomer : labels.sourceFilterTeam
|
|
1656
1814
|
] }),
|
|
1657
|
-
/* @__PURE__ */
|
|
1658
|
-
/* @__PURE__ */
|
|
1659
|
-
/* @__PURE__ */
|
|
1660
|
-
/* @__PURE__ */
|
|
1815
|
+
/* @__PURE__ */ jsx16("span", { children: "\xB7" }),
|
|
1816
|
+
/* @__PURE__ */ jsx16("span", { children: formatDateTime(document2.linkedAt) }),
|
|
1817
|
+
/* @__PURE__ */ jsx16("span", { children: "\xB7" }),
|
|
1818
|
+
/* @__PURE__ */ jsx16("span", { children: formatFileSize(document2.sizeBytes) })
|
|
1661
1819
|
] })
|
|
1662
1820
|
] })
|
|
1663
1821
|
] }),
|
|
1664
|
-
onOpenConversation ? /* @__PURE__ */
|
|
1822
|
+
onOpenConversation ? /* @__PURE__ */ jsxs11(
|
|
1665
1823
|
"button",
|
|
1666
1824
|
{
|
|
1667
1825
|
type: "button",
|
|
@@ -1669,13 +1827,13 @@ function DocumentsLibrary({
|
|
|
1669
1827
|
title: labels.openConversation,
|
|
1670
1828
|
className: cn("cv-header-action inline-flex shrink-0 items-center gap-1", classNames?.conversationLink),
|
|
1671
1829
|
children: [
|
|
1672
|
-
/* @__PURE__ */
|
|
1830
|
+
/* @__PURE__ */ jsx16(MessageSquare, { size: 12 }),
|
|
1673
1831
|
formatPhone(document2.conversationId)
|
|
1674
1832
|
]
|
|
1675
1833
|
}
|
|
1676
|
-
) : /* @__PURE__ */
|
|
1677
|
-
/* @__PURE__ */
|
|
1678
|
-
/* @__PURE__ */
|
|
1834
|
+
) : /* @__PURE__ */ jsx16("span", { className: cn("shrink-0 text-xs text-gray-500", classNames?.conversationLink), children: formatPhone(document2.conversationId) }),
|
|
1835
|
+
/* @__PURE__ */ jsxs11("div", { className: "flex shrink-0 gap-1", children: [
|
|
1836
|
+
/* @__PURE__ */ jsx16(
|
|
1679
1837
|
"button",
|
|
1680
1838
|
{
|
|
1681
1839
|
type: "button",
|
|
@@ -1683,10 +1841,10 @@ function DocumentsLibrary({
|
|
|
1683
1841
|
title: labels.view,
|
|
1684
1842
|
"aria-label": `${labels.view}: ${document2.filename}`,
|
|
1685
1843
|
className: "cv-header-icon",
|
|
1686
|
-
children: /* @__PURE__ */
|
|
1844
|
+
children: /* @__PURE__ */ jsx16(Eye2, { size: 14 })
|
|
1687
1845
|
}
|
|
1688
1846
|
),
|
|
1689
|
-
/* @__PURE__ */
|
|
1847
|
+
/* @__PURE__ */ jsx16(
|
|
1690
1848
|
"button",
|
|
1691
1849
|
{
|
|
1692
1850
|
type: "button",
|
|
@@ -1694,7 +1852,7 @@ function DocumentsLibrary({
|
|
|
1694
1852
|
title: labels.download,
|
|
1695
1853
|
"aria-label": `${labels.download}: ${document2.filename}`,
|
|
1696
1854
|
className: "cv-header-icon",
|
|
1697
|
-
children: /* @__PURE__ */
|
|
1855
|
+
children: /* @__PURE__ */ jsx16(Download2, { size: 14 })
|
|
1698
1856
|
}
|
|
1699
1857
|
)
|
|
1700
1858
|
] })
|
|
@@ -1703,10 +1861,10 @@ function DocumentsLibrary({
|
|
|
1703
1861
|
`${document2.conversationId}:${document2.id}`
|
|
1704
1862
|
);
|
|
1705
1863
|
}) }),
|
|
1706
|
-
total > perPage ? /* @__PURE__ */
|
|
1707
|
-
/* @__PURE__ */
|
|
1708
|
-
/* @__PURE__ */
|
|
1709
|
-
/* @__PURE__ */
|
|
1864
|
+
total > perPage ? /* @__PURE__ */ jsxs11("div", { className: cn("flex items-center justify-between border-t pt-2 text-xs dark:border-gray-700", classNames?.pagination), children: [
|
|
1865
|
+
/* @__PURE__ */ jsx16("span", { className: "text-gray-400", children: labels.total(total) }),
|
|
1866
|
+
/* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-2", children: [
|
|
1867
|
+
/* @__PURE__ */ jsx16(
|
|
1710
1868
|
"button",
|
|
1711
1869
|
{
|
|
1712
1870
|
type: "button",
|
|
@@ -1716,8 +1874,8 @@ function DocumentsLibrary({
|
|
|
1716
1874
|
children: "\u2039"
|
|
1717
1875
|
}
|
|
1718
1876
|
),
|
|
1719
|
-
/* @__PURE__ */
|
|
1720
|
-
/* @__PURE__ */
|
|
1877
|
+
/* @__PURE__ */ jsx16("span", { className: "text-gray-500", children: labels.page(page, lastPage) }),
|
|
1878
|
+
/* @__PURE__ */ jsx16(
|
|
1721
1879
|
"button",
|
|
1722
1880
|
{
|
|
1723
1881
|
type: "button",
|
|
@@ -1762,6 +1920,9 @@ export {
|
|
|
1762
1920
|
DEFAULT_MESSAGE_COMPOSER_LABELS,
|
|
1763
1921
|
DEFAULT_ACCEPTED_FILE_TYPES,
|
|
1764
1922
|
MessageComposer,
|
|
1923
|
+
DEFAULT_AUDIO_RECORDER_BUTTON_LABELS,
|
|
1924
|
+
DEFAULT_MAX_RECORDING_MILLISECONDS,
|
|
1925
|
+
AudioRecorderButton,
|
|
1765
1926
|
DateDivider,
|
|
1766
1927
|
formatPhone,
|
|
1767
1928
|
phoneCountryFlag,
|