@fayz-ai/plugin-conversations 0.33.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.
@@ -1,4 +1,4 @@
1
- import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, MessagePreview, mediaPreviewKind } from './chunk-XOMWIVPC.js';
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,11 +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
193
  // Waiting on us stays pinned on top (newest first among them): a red thread
190
194
  // is a contact to make, and it must not sink under newer chatter.
191
- () => conversations.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),
192
- [conversations, archived]
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]
193
197
  );
194
198
  const donos = React7__default.useMemo(() => {
195
199
  const vistos = /* @__PURE__ */ new Map();
@@ -199,6 +203,25 @@ function ConversationList({ className }) {
199
203
  return [...vistos].map(([value, label]) => ({ value, label }));
200
204
  }, [conversations]);
201
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
+ }) }),
202
225
  /* @__PURE__ */ jsxs("div", { className: "border-b border-border px-3 py-3", children: [
203
226
  /* @__PURE__ */ jsxs("div", { className: "relative", children: [
204
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" }),
@@ -357,8 +380,9 @@ function ConversationList({ className }) {
357
380
  /* @__PURE__ */ jsx(WhatsAppConnectionFooter, {})
358
381
  ] });
359
382
  }
360
- function useSendWindow(conversationId) {
383
+ function useSendWindow(conversationId, contactHandle) {
361
384
  const [row, setRow] = React7__default.useState(null);
385
+ const [optedOut, setOptedOut] = React7__default.useState(false);
362
386
  const [providers, setProviders] = React7__default.useState(null);
363
387
  React7__default.useEffect(() => {
364
388
  let alive = true;
@@ -391,8 +415,23 @@ function useSendWindow(conversationId) {
391
415
  alive = false;
392
416
  };
393
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]);
394
432
  const provider = (providers ?? []).find((p) => p.isActive);
395
433
  const mode = React7__default.useMemo(() => {
434
+ if (optedOut) return { kind: "blocked", reason: "opted_out" };
396
435
  if (!provider) return { kind: "blocked", reason: "no_provider" };
397
436
  if (!provider.capabilities?.requires_template) {
398
437
  return { kind: "free", until: null, minutesLeft: null };
@@ -401,7 +440,7 @@ function useSendWindow(conversationId) {
401
440
  return { kind: "free", until: row.window_expires_at, minutesLeft: row.minutes_left };
402
441
  }
403
442
  return { kind: "template", reason: row?.last_inbound_at ? "window_closed" : "never_replied" };
404
- }, [row, provider]);
443
+ }, [row, provider, optedOut]);
405
444
  return { loading: providers === null, mode, provider };
406
445
  }
407
446
  function humanLeft(minutes) {
@@ -421,6 +460,12 @@ function SendWindowBanner({ state }) {
421
460
  humanLeft(mode.minutesLeft)
422
461
  ] });
423
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
+ }
424
469
  if (mode.kind === "blocked") {
425
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: [
426
471
  /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-destructive" }),
@@ -838,7 +883,7 @@ function Composer({ canType, placeholder, sending, onSendText, onSendMedia }) {
838
883
  ] }),
839
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" }) })
840
885
  ] }),
841
- /* @__PURE__ */ jsxs("div", { className: "flex items-end gap-2 px-4 py-3", children: [
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: [
842
887
  /* @__PURE__ */ jsx(
843
888
  "input",
844
889
  {
@@ -1126,7 +1171,7 @@ function buildRows(messages) {
1126
1171
  function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways, className }) {
1127
1172
  const t = useTranslation();
1128
1173
  const { messages, sending, send, sendMedia, setStatus, refreshMessages } = useConversationsStore((s) => s);
1129
- const win = useSendWindow(selected.id);
1174
+ const win = useSendWindow(selected.id, selected.channel === "whatsapp" ? selected.contactHandle : void 0);
1130
1175
  const canType = win.mode.kind === "free";
1131
1176
  const threadRef = React7__default.useRef(null);
1132
1177
  React7__default.useEffect(() => {
@@ -1285,7 +1330,7 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
1285
1330
  {
1286
1331
  canType,
1287
1332
  sending,
1288
- 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",
1289
1334
  onSendText: (text) => send(text),
1290
1335
  onSendMedia: (input) => sendMedia(input)
1291
1336
  }
@@ -1848,5 +1893,5 @@ function ConversationsPage({ store, config }) {
1848
1893
  }
1849
1894
 
1850
1895
  export { ConversationsPage, conversationIdFromPath };
1851
- //# sourceMappingURL=ConversationsPage-6DVS3C2L.js.map
1852
- //# sourceMappingURL=ConversationsPage-6DVS3C2L.js.map
1896
+ //# sourceMappingURL=ConversationsPage-32XXQKCP.js.map
1897
+ //# sourceMappingURL=ConversationsPage-32XXQKCP.js.map