@fayz-ai/plugin-conversations 0.32.0 → 0.34.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/dist/{ConversationsPage-C6FMGA72.js → ConversationsPage-32XXQKCP.js} +57 -10
- package/dist/ConversationsPage-32XXQKCP.js.map +1 -0
- package/dist/{chunk-XOMWIVPC.js → chunk-OJ3Q4S5Y.js} +2 -2
- package/dist/chunk-OJ3Q4S5Y.js.map +1 -0
- package/dist/components/Composer.d.ts.map +1 -1
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/main.browser.js +2 -1
- package/dist/migrations/main.browser.js.map +1 -1
- package/dist/migrations/main.js +121 -2
- package/dist/migrations/main.js.map +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/views/ConversationList.d.ts.map +1 -1
- package/dist/views/SendWindow.d.ts +2 -2
- package/dist/views/SendWindow.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/ConversationsPage-C6FMGA72.js.map +0 -1
- package/dist/chunk-XOMWIVPC.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, MessagePreview, mediaPreviewKind } from './chunk-
|
|
1
|
+
import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, MessagePreview, mediaPreviewKind } from './chunk-OJ3Q4S5Y.js';
|
|
2
2
|
import { providersApi } from './chunk-HMWUU5O7.js';
|
|
3
3
|
import * as React7 from 'react';
|
|
4
4
|
import React7__default from 'react';
|
|
@@ -185,9 +185,15 @@ function ConversationList({ className }) {
|
|
|
185
185
|
setSearch
|
|
186
186
|
} = useConversationsStore((s) => s);
|
|
187
187
|
const [archived, setArchived] = React7__default.useState(false);
|
|
188
|
+
const [inbox, setInbox] = React7__default.useState("commercial");
|
|
189
|
+
const inboxes = React7__default.useMemo(() => new Set(conversations.map((c) => c.inbox ?? "commercial")), [conversations]);
|
|
190
|
+
const bothInboxes = inboxes.size > 1;
|
|
191
|
+
const waitingIn = (which) => conversations.filter((c) => (c.inbox ?? "commercial") === which && c.status !== "closed" && isWaitingOnUs(c)).length;
|
|
188
192
|
const shown = React7__default.useMemo(
|
|
189
|
-
|
|
190
|
-
|
|
193
|
+
// Waiting on us stays pinned on top (newest first among them): a red thread
|
|
194
|
+
// is a contact to make, and it must not sink under newer chatter.
|
|
195
|
+
() => conversations.filter((c) => !bothInboxes || (c.inbox ?? "commercial") === inbox).filter((c) => archived ? c.status === "closed" : c.status !== "closed").map((c, i) => ({ c, i, waiting: isWaitingOnUs(c) })).sort((a, b) => a.waiting === b.waiting ? a.i - b.i : a.waiting ? -1 : 1).map(({ c }) => c),
|
|
196
|
+
[conversations, archived, bothInboxes, inbox]
|
|
191
197
|
);
|
|
192
198
|
const donos = React7__default.useMemo(() => {
|
|
193
199
|
const vistos = /* @__PURE__ */ new Map();
|
|
@@ -197,6 +203,25 @@ function ConversationList({ className }) {
|
|
|
197
203
|
return [...vistos].map(([value, label]) => ({ value, label }));
|
|
198
204
|
}, [conversations]);
|
|
199
205
|
return /* @__PURE__ */ jsxs("aside", { className: cn("w-full shrink-0 flex-col border-r border-border bg-card lg:w-[320px]", className), children: [
|
|
206
|
+
bothInboxes && /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 border-b border-border text-sm", children: ["commercial", "support"].map((which) => {
|
|
207
|
+
const n = waitingIn(which);
|
|
208
|
+
return /* @__PURE__ */ jsxs(
|
|
209
|
+
"button",
|
|
210
|
+
{
|
|
211
|
+
type: "button",
|
|
212
|
+
onClick: () => setInbox(which),
|
|
213
|
+
className: cn(
|
|
214
|
+
"flex items-center justify-center gap-1.5 py-2.5 font-medium transition-colors",
|
|
215
|
+
inbox === which ? "border-b-2 border-primary text-foreground" : "text-muted-foreground hover:text-foreground"
|
|
216
|
+
),
|
|
217
|
+
children: [
|
|
218
|
+
which === "commercial" ? "Comercial" : "Suporte",
|
|
219
|
+
n > 0 && /* @__PURE__ */ jsx("span", { className: "rounded-full bg-destructive px-1.5 text-[10px] font-semibold text-destructive-foreground", children: n })
|
|
220
|
+
]
|
|
221
|
+
},
|
|
222
|
+
which
|
|
223
|
+
);
|
|
224
|
+
}) }),
|
|
200
225
|
/* @__PURE__ */ jsxs("div", { className: "border-b border-border px-3 py-3", children: [
|
|
201
226
|
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
202
227
|
/* @__PURE__ */ jsx(Search, { className: "pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
|
|
@@ -355,8 +380,9 @@ function ConversationList({ className }) {
|
|
|
355
380
|
/* @__PURE__ */ jsx(WhatsAppConnectionFooter, {})
|
|
356
381
|
] });
|
|
357
382
|
}
|
|
358
|
-
function useSendWindow(conversationId) {
|
|
383
|
+
function useSendWindow(conversationId, contactHandle) {
|
|
359
384
|
const [row, setRow] = React7__default.useState(null);
|
|
385
|
+
const [optedOut, setOptedOut] = React7__default.useState(false);
|
|
360
386
|
const [providers, setProviders] = React7__default.useState(null);
|
|
361
387
|
React7__default.useEffect(() => {
|
|
362
388
|
let alive = true;
|
|
@@ -389,8 +415,23 @@ function useSendWindow(conversationId) {
|
|
|
389
415
|
alive = false;
|
|
390
416
|
};
|
|
391
417
|
}, [conversationId]);
|
|
418
|
+
React7__default.useEffect(() => {
|
|
419
|
+
let alive = true;
|
|
420
|
+
setOptedOut(false);
|
|
421
|
+
const last8 = String(contactHandle ?? "").replace(/\D/gu, "").slice(-8);
|
|
422
|
+
const sb = getSupabaseClientOptional();
|
|
423
|
+
if (!sb || last8.length < 8) return;
|
|
424
|
+
sb.from("plg_conversations_optouts").select("id").eq("tenant_id", getActiveTenantId()).eq("channel", "whatsapp").eq("active", true).like("phone_e164", `%${last8}`).limit(1).then(({ data }) => {
|
|
425
|
+
if (alive) setOptedOut((data ?? []).length > 0);
|
|
426
|
+
}).catch(() => {
|
|
427
|
+
});
|
|
428
|
+
return () => {
|
|
429
|
+
alive = false;
|
|
430
|
+
};
|
|
431
|
+
}, [contactHandle]);
|
|
392
432
|
const provider = (providers ?? []).find((p) => p.isActive);
|
|
393
433
|
const mode = React7__default.useMemo(() => {
|
|
434
|
+
if (optedOut) return { kind: "blocked", reason: "opted_out" };
|
|
394
435
|
if (!provider) return { kind: "blocked", reason: "no_provider" };
|
|
395
436
|
if (!provider.capabilities?.requires_template) {
|
|
396
437
|
return { kind: "free", until: null, minutesLeft: null };
|
|
@@ -399,7 +440,7 @@ function useSendWindow(conversationId) {
|
|
|
399
440
|
return { kind: "free", until: row.window_expires_at, minutesLeft: row.minutes_left };
|
|
400
441
|
}
|
|
401
442
|
return { kind: "template", reason: row?.last_inbound_at ? "window_closed" : "never_replied" };
|
|
402
|
-
}, [row, provider]);
|
|
443
|
+
}, [row, provider, optedOut]);
|
|
403
444
|
return { loading: providers === null, mode, provider };
|
|
404
445
|
}
|
|
405
446
|
function humanLeft(minutes) {
|
|
@@ -419,6 +460,12 @@ function SendWindowBanner({ state }) {
|
|
|
419
460
|
humanLeft(mode.minutesLeft)
|
|
420
461
|
] });
|
|
421
462
|
}
|
|
463
|
+
if (mode.kind === "blocked" && mode.reason === "opted_out") {
|
|
464
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 bg-muted px-4 py-2 text-[11px] text-muted-foreground", children: [
|
|
465
|
+
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-muted-foreground" }),
|
|
466
|
+
"Esta pessoa pediu para n\xE3o receber mais mensagens (SAIR). N\xE3o \xE9 poss\xEDvel responder por aqui."
|
|
467
|
+
] });
|
|
468
|
+
}
|
|
422
469
|
if (mode.kind === "blocked") {
|
|
423
470
|
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 bg-destructive-soft px-4 py-2 text-[11px] text-destructive-soft-foreground", children: [
|
|
424
471
|
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-destructive" }),
|
|
@@ -836,7 +883,7 @@ function Composer({ canType, placeholder, sending, onSendText, onSendMedia }) {
|
|
|
836
883
|
] }),
|
|
837
884
|
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", onClick: () => setFile(null), "aria-label": t("conversations.composer.removeFile"), children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" }) })
|
|
838
885
|
] }),
|
|
839
|
-
/* @__PURE__ */ jsxs("div", { className:
|
|
886
|
+
/* @__PURE__ */ jsxs("div", { className: `flex items-end gap-2 py-3 pl-4 pr-4 md:pr-20 ${canType ? "" : "bg-muted/40 opacity-60"}`, children: [
|
|
840
887
|
/* @__PURE__ */ jsx(
|
|
841
888
|
"input",
|
|
842
889
|
{
|
|
@@ -1124,7 +1171,7 @@ function buildRows(messages) {
|
|
|
1124
1171
|
function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways, className }) {
|
|
1125
1172
|
const t = useTranslation();
|
|
1126
1173
|
const { messages, sending, send, sendMedia, setStatus, refreshMessages } = useConversationsStore((s) => s);
|
|
1127
|
-
const win = useSendWindow(selected.id);
|
|
1174
|
+
const win = useSendWindow(selected.id, selected.channel === "whatsapp" ? selected.contactHandle : void 0);
|
|
1128
1175
|
const canType = win.mode.kind === "free";
|
|
1129
1176
|
const threadRef = React7__default.useRef(null);
|
|
1130
1177
|
React7__default.useEffect(() => {
|
|
@@ -1283,7 +1330,7 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1283
1330
|
{
|
|
1284
1331
|
canType,
|
|
1285
1332
|
sending,
|
|
1286
|
-
placeholder: canType ? t("conversations.thread.reply", { channel: channelLabel(selected.channel) }) : win.mode.kind === "blocked" ? "Envio bloqueado" : "Fora da janela \u2014 envie um template",
|
|
1333
|
+
placeholder: canType ? t("conversations.thread.reply", { channel: channelLabel(selected.channel) }) : win.mode.kind === "blocked" ? win.mode.reason === "opted_out" ? "Esta pessoa pediu para sair" : "Envio bloqueado" : "Fora da janela \u2014 envie um template",
|
|
1287
1334
|
onSendText: (text) => send(text),
|
|
1288
1335
|
onSendMedia: (input) => sendMedia(input)
|
|
1289
1336
|
}
|
|
@@ -1846,5 +1893,5 @@ function ConversationsPage({ store, config }) {
|
|
|
1846
1893
|
}
|
|
1847
1894
|
|
|
1848
1895
|
export { ConversationsPage, conversationIdFromPath };
|
|
1849
|
-
//# sourceMappingURL=ConversationsPage-
|
|
1850
|
-
//# sourceMappingURL=ConversationsPage-
|
|
1896
|
+
//# sourceMappingURL=ConversationsPage-32XXQKCP.js.map
|
|
1897
|
+
//# sourceMappingURL=ConversationsPage-32XXQKCP.js.map
|