@fayz-ai/plugin-conversations 0.34.0 → 0.35.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,11 +1,11 @@
1
- import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, MessagePreview, mediaPreviewKind } from './chunk-OJ3Q4S5Y.js';
1
+ import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, currentUserId, isWaitingOnUs, MessagePreview, mediaPreviewKind } from './chunk-NWH5AIUH.js';
2
2
  import { providersApi } from './chunk-HMWUU5O7.js';
3
3
  import * as React7 from 'react';
4
4
  import React7__default from 'react';
5
- import { SquarePen, MessageSquare, LifeBuoy, Globe, Mail, Instagram, Phone, Search, User, Archive, Inbox, CheckCheck, ChevronLeft, MoreHorizontal, ArchiveRestore, X, Building2, CheckCircle2, MoreVertical, Loader2, Forward, AlertTriangle, Check, Clock, ExternalLink, Reply, FileText, Trash2, Paperclip, Square, Mic, Send, Snowflake, Sun, Flame, Ban, BarChart3, MapPin, UserRound, Copy, Download } from 'lucide-react';
5
+ import { SquarePen, MessageSquare, LifeBuoy, Globe, Mail, Instagram, Phone, Search, Inbox, User, Archive, CheckCheck, ChevronLeft, MoreHorizontal, ArchiveRestore, X, Building2, MoreVertical, Loader2, Forward, AlertTriangle, Check, Clock, ExternalLink, Reply, FileText, Trash2, Paperclip, Square, Mic, Send, Snowflake, Sun, Flame, Ban, BarChart3, MapPin, UserRound, Copy, Download } from 'lucide-react';
6
6
  import { PageHeaderActions, cn, Button, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Textarea, ModalFooter, Input, FilterChip, Skeleton, Dropdown, DropdownTrigger, DropdownContent, DropdownItem, toast } from '@fayz-ai/ui';
7
- import { useRightRailStore, PageActions, useLimitGuard, ContactPicker, invalidateLimit, useConnectors, adminNavigateTo } from '@fayz-ai/admin';
8
- import { currentAppPath, appHref, onAppPathChange, replaceApp, useTranslation, useActiveTenantId, errorMessage, tl, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
7
+ import { useRightRailStore, PageActions, useLimitGuard, ContactPicker, invalidateLimit, useConnectors } from '@fayz-ai/admin';
8
+ import { currentAppPath, appHref, onAppPathChange, replaceApp, useTranslation, useActiveTenantId, errorMessage, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
 
11
11
  var CHANNEL_ICON = {
@@ -131,42 +131,6 @@ function useChannelConnections() {
131
131
  return { whatsapp: whatsapp || live("whatsapp"), email: live("mail"), instagram: live("instagram") };
132
132
  }, [whatsapp, connectors]);
133
133
  }
134
- var CONNECTORS_ROUTE = "/settings/conversations/connectors";
135
- function WhatsAppConnectionFooter() {
136
- const connected = useChannelConnections();
137
- return /* @__PURE__ */ jsx("div", { className: "shrink-0 border-t border-border p-3", children: connected === void 0 ? /* @__PURE__ */ jsx("div", { className: "h-10", "aria-hidden": true }) : connected.whatsapp ? /* @__PURE__ */ jsxs(
138
- Button,
139
- {
140
- variant: "bare",
141
- size: "bare",
142
- type: "button",
143
- onClick: () => adminNavigateTo(CONNECTORS_ROUTE),
144
- className: "font-normal whitespace-normal justify-start fz-tap flex h-10 w-full items-center gap-2 rounded-button px-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",
145
- children: [
146
- /* @__PURE__ */ jsx(CheckCircle2, { className: "h-4 w-4 text-[#25D366]", "aria-hidden": true }),
147
- /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-left", children: tl("WhatsApp connected", "WhatsApp conectado") }),
148
- /* @__PURE__ */ jsx("span", { className: "text-xs text-primary", children: tl("Manage", "Gerenciar") })
149
- ]
150
- }
151
- ) : /* @__PURE__ */ jsxs(
152
- Button,
153
- {
154
- variant: "bare",
155
- size: "bare",
156
- type: "button",
157
- onClick: () => adminNavigateTo(CONNECTORS_ROUTE),
158
- "data-testid": "inbox-connect-whatsapp",
159
- className: "font-normal whitespace-normal fz-tap flex h-11 w-full items-center justify-center gap-2 rounded-button bg-[#25D366] text-sm font-semibold text-white shadow-sm transition-colors hover:bg-[#1EBE5A] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#25D366] focus-visible:ring-offset-2",
160
- children: [
161
- /* @__PURE__ */ jsx(WhatsAppMark, { className: "h-[18px] w-[18px]" }),
162
- tl("Connect WhatsApp", "Conectar WhatsApp")
163
- ]
164
- }
165
- ) });
166
- }
167
- function WhatsAppMark({ className }) {
168
- return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "currentColor", className, "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M17.47 14.38c-.3-.15-1.76-.87-2.03-.97-.27-.1-.47-.15-.67.15-.2.3-.77.96-.94 1.16-.17.2-.35.22-.65.07-.3-.15-1.26-.46-2.4-1.48-.89-.79-1.49-1.77-1.66-2.07-.17-.3-.02-.46.13-.61.13-.13.3-.35.45-.52.15-.17.2-.3.3-.5.1-.2.05-.37-.02-.52-.08-.15-.67-1.61-.92-2.2-.24-.58-.49-.5-.67-.51h-.57c-.2 0-.52.07-.79.37-.27.3-1.04 1.02-1.04 2.48s1.07 2.88 1.21 3.08c.15.2 2.1 3.2 5.08 4.49.71.31 1.26.49 1.69.63.71.22 1.36.19 1.87.12.57-.09 1.76-.72 2.01-1.41.25-.7.25-1.29.17-1.41-.07-.13-.27-.2-.57-.35zM12.05 21.5h-.01a9.4 9.4 0 0 1-4.8-1.32l-.34-.2-3.56.93.95-3.47-.22-.36a9.4 9.4 0 0 1-1.44-5.02c0-5.2 4.23-9.43 9.43-9.43 2.52 0 4.89.98 6.67 2.77a9.37 9.37 0 0 1 2.76 6.67c0 5.2-4.23 9.43-9.44 9.43zm8.03-17.46A11.3 11.3 0 0 0 12.05.72C5.79.72.7 5.81.7 12.07c0 2 .52 3.95 1.52 5.67L.6 23.6l6-1.57a11.32 11.32 0 0 0 5.44 1.39h.01c6.26 0 11.35-5.1 11.35-11.35 0-3.03-1.18-5.88-3.32-8.03z" }) });
169
- }
170
134
  var FILTERS = ["all", "whatsapp", "instagram", "email"];
171
135
  function ConversationList({ className }) {
172
136
  const t = useTranslation();
@@ -185,6 +149,16 @@ function ConversationList({ className }) {
185
149
  setSearch
186
150
  } = useConversationsStore((s) => s);
187
151
  const [archived, setArchived] = React7__default.useState(false);
152
+ const [mineOnly, setMineOnly] = React7__default.useState(false);
153
+ const [me, setMe] = React7__default.useState(null);
154
+ React7__default.useEffect(() => {
155
+ void currentUserId().then(setMe);
156
+ }, []);
157
+ const isMineWaiting = React7__default.useCallback(
158
+ (c) => Boolean(me) && c.leadOwnerId === me && c.status !== "closed" && isWaitingOnUs(c),
159
+ [me]
160
+ );
161
+ const mineCount = React7__default.useMemo(() => conversations.filter(isMineWaiting).length, [conversations, isMineWaiting]);
188
162
  const [inbox, setInbox] = React7__default.useState("commercial");
189
163
  const inboxes = React7__default.useMemo(() => new Set(conversations.map((c) => c.inbox ?? "commercial")), [conversations]);
190
164
  const bothInboxes = inboxes.size > 1;
@@ -192,8 +166,8 @@ function ConversationList({ className }) {
192
166
  const shown = React7__default.useMemo(
193
167
  // Waiting on us stays pinned on top (newest first among them): a red thread
194
168
  // 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]
169
+ () => conversations.filter((c) => !bothInboxes || (c.inbox ?? "commercial") === inbox).filter((c) => !mineOnly || isMineWaiting(c)).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),
170
+ [conversations, archived, bothInboxes, inbox, mineOnly, isMineWaiting]
197
171
  );
198
172
  const donos = React7__default.useMemo(() => {
199
173
  const vistos = /* @__PURE__ */ new Map();
@@ -235,24 +209,44 @@ function ConversationList({ className }) {
235
209
  }
236
210
  )
237
211
  ] }),
238
- /* @__PURE__ */ jsx("div", { className: "mt-2 flex flex-wrap gap-1", children: FILTERS.map((id) => {
239
- const off = id !== "all" && connected !== void 0 && !connected[id];
240
- return /* @__PURE__ */ jsx(
212
+ /* @__PURE__ */ jsxs("div", { className: "mt-2 flex flex-wrap gap-1", children: [
213
+ /* @__PURE__ */ jsxs(
241
214
  Button,
242
215
  {
243
216
  variant: "bare",
244
217
  size: "bare",
245
- onClick: () => setChannelFilter(id),
246
- title: off ? t("conversations.filter.notConnected") : void 0,
218
+ onClick: () => setMineOnly((v) => !v),
219
+ title: "S\xF3 os meus leads esperando resposta",
247
220
  className: cn(
248
- "rounded-full border px-2.5 py-1 text-xs font-medium transition-colors",
249
- channelFilter === id ? "border-transparent bg-primary text-primary-foreground" : off ? "border-dashed border-muted-foreground/40 bg-transparent text-muted-foreground hover:bg-muted/50" : "border-transparent bg-muted text-muted-foreground hover:bg-muted/70"
221
+ "inline-flex items-center gap-1 rounded-full border px-2.5 py-1 text-xs font-medium transition-colors",
222
+ mineOnly ? "border-transparent bg-primary text-primary-foreground" : "border-transparent bg-muted text-muted-foreground hover:bg-muted/70"
250
223
  ),
251
- children: t(`conversations.filter.${id}`)
252
- },
253
- id
254
- );
255
- }) }),
224
+ children: [
225
+ /* @__PURE__ */ jsx(Inbox, { className: "h-3 w-3" }),
226
+ " Inbox",
227
+ mineCount > 0 && /* @__PURE__ */ jsx("span", { className: "rounded-full bg-destructive px-1.5 text-[10px] font-semibold text-destructive-foreground", children: mineCount })
228
+ ]
229
+ }
230
+ ),
231
+ FILTERS.map((id) => {
232
+ const off = id !== "all" && connected !== void 0 && !connected[id];
233
+ return /* @__PURE__ */ jsx(
234
+ Button,
235
+ {
236
+ variant: "bare",
237
+ size: "bare",
238
+ onClick: () => setChannelFilter(id),
239
+ title: off ? t("conversations.filter.notConnected") : void 0,
240
+ className: cn(
241
+ "rounded-full border px-2.5 py-1 text-xs font-medium transition-colors",
242
+ channelFilter === id ? "border-transparent bg-primary text-primary-foreground" : off ? "border-dashed border-muted-foreground/40 bg-transparent text-muted-foreground hover:bg-muted/50" : "border-transparent bg-muted text-muted-foreground hover:bg-muted/70"
243
+ ),
244
+ children: t(`conversations.filter.${id}`)
245
+ },
246
+ id
247
+ );
248
+ })
249
+ ] }),
256
250
  /* @__PURE__ */ jsxs("div", { className: "mt-2 flex flex-wrap items-center gap-1", children: [
257
251
  donos.length > 0 && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
258
252
  FilterChip,
@@ -376,8 +370,7 @@ function ConversationList({ className }) {
376
370
  ] }, c.id)
377
371
  );
378
372
  })
379
- ] }),
380
- /* @__PURE__ */ jsx(WhatsAppConnectionFooter, {})
373
+ ] })
381
374
  ] });
382
375
  }
383
376
  function useSendWindow(conversationId, contactHandle) {
@@ -778,7 +771,7 @@ function recordingMime() {
778
771
  function clock(seconds) {
779
772
  return `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
780
773
  }
781
- function Composer({ canType, placeholder, sending, onSendText, onSendMedia }) {
774
+ function Composer({ canType, placeholder, sending, onSendText, onSendMedia, clearAssistant = false }) {
782
775
  const t = useTranslation();
783
776
  const [draft, setDraft] = React7.useState("");
784
777
  const [file, setFile] = React7.useState(null);
@@ -870,6 +863,13 @@ function Composer({ canType, placeholder, sending, onSendText, onSendMedia }) {
870
863
  recorder.current = null;
871
864
  }
872
865
  const empty = !draft.trim() && !file;
866
+ const boxRef = React7.useRef(null);
867
+ React7.useLayoutEffect(() => {
868
+ const el = boxRef.current;
869
+ if (!el) return;
870
+ el.style.height = "auto";
871
+ el.style.height = `${Math.min(el.scrollHeight, 128)}px`;
872
+ }, [draft]);
873
873
  return /* @__PURE__ */ jsxs("div", { children: [
874
874
  file && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 border-b border-border bg-muted/30 px-4 py-2", children: [
875
875
  preview && file.type.startsWith("image/") ? /* @__PURE__ */ jsx("img", { src: preview, alt: "", className: "h-14 w-14 rounded-md object-cover" }) : preview && file.type.startsWith("video/") ? /* @__PURE__ */ jsx("video", { src: preview, className: "h-14 w-20 rounded-md object-cover" }) : /* @__PURE__ */ jsx("span", { className: "flex h-14 w-14 items-center justify-center rounded-md bg-card", children: /* @__PURE__ */ jsx(FileText, { className: "h-6 w-6 text-muted-foreground" }) }),
@@ -883,7 +883,7 @@ function Composer({ canType, placeholder, sending, onSendText, onSendMedia }) {
883
883
  ] }),
884
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" }) })
885
885
  ] }),
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: [
886
+ /* @__PURE__ */ jsxs("div", { className: cn("flex items-end gap-1.5 bg-muted/30 py-2 pl-2 pr-3", clearAssistant && "md:pr-20", !canType && "opacity-60"), children: [
887
887
  /* @__PURE__ */ jsx(
888
888
  "input",
889
889
  {
@@ -898,16 +898,17 @@ function Composer({ canType, placeholder, sending, onSendText, onSendMedia }) {
898
898
  }
899
899
  }
900
900
  ),
901
- recording ? /* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center gap-3 rounded-md border border-destructive/40 bg-destructive-soft/40 px-3 py-2", children: [
901
+ recording ? /* @__PURE__ */ jsxs("div", { className: "flex h-9 flex-1 items-center gap-3 rounded-full border border-destructive/40 bg-destructive-soft/40 px-4", children: [
902
902
  /* @__PURE__ */ jsx("span", { className: "h-2.5 w-2.5 animate-pulse rounded-full bg-destructive" }),
903
903
  /* @__PURE__ */ jsx("span", { className: "text-sm tabular-nums", children: clock(seconds) }),
904
904
  /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("conversations.composer.recording") }),
905
905
  /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "ml-auto h-8 w-8", onClick: () => stopRecording(false), "aria-label": t("conversations.composer.discard"), children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" }) })
906
906
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
907
- /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "shrink-0", disabled: !canType || busy, onClick: () => inputRef.current?.click(), "aria-label": t("conversations.composer.attach"), children: /* @__PURE__ */ jsx(Paperclip, { className: "h-4 w-4" }) }),
907
+ /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "h-9 w-9 shrink-0 rounded-full text-muted-foreground", disabled: !canType || busy, onClick: () => inputRef.current?.click(), "aria-label": t("conversations.composer.attach"), children: /* @__PURE__ */ jsx(Paperclip, { className: "h-4 w-4" }) }),
908
908
  /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
909
909
  Textarea,
910
910
  {
911
+ ref: boxRef,
911
912
  value: draft,
912
913
  onChange: (e) => setDraft(e.target.value),
913
914
  onKeyDown: (e) => {
@@ -926,11 +927,11 @@ function Composer({ canType, placeholder, sending, onSendText, onSendMedia }) {
926
927
  rows: 1,
927
928
  disabled: !canType,
928
929
  placeholder: file ? t("conversations.composer.caption") : placeholder,
929
- className: "max-h-32 min-h-[40px] resize-none rounded-md border-border bg-background shadow-none focus:border-primary focus-visible:ring-0 focus-visible:ring-offset-0 disabled:bg-muted/40 disabled:text-muted-foreground disabled:opacity-100"
930
+ className: "block h-9 max-h-32 min-h-9 resize-none overflow-y-auto rounded-[18px] border-border bg-background px-4 py-[7px] text-sm leading-5 shadow-none focus:border-primary focus-visible:ring-0 focus-visible:ring-offset-0 disabled:bg-muted/40 disabled:text-muted-foreground disabled:opacity-100"
930
931
  }
931
932
  ) })
932
933
  ] }),
933
- recording ? /* @__PURE__ */ jsx(Button, { onClick: () => stopRecording(true), "aria-label": t("conversations.thread.send"), children: /* @__PURE__ */ jsx(Square, { className: "h-3.5 w-3.5 fill-current" }) }) : empty ? /* @__PURE__ */ jsx(Button, { onClick: () => void startRecording(), disabled: !canType || busy || sending, "aria-label": t("conversations.composer.record"), className: cn(busy && "opacity-70"), children: busy ? /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" }) }) : /* @__PURE__ */ jsx(Button, { onClick: () => void send(), disabled: !canType || busy || sending, "aria-label": t("conversations.thread.send"), children: busy ? /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Send, { className: "h-4 w-4" }) })
934
+ recording ? /* @__PURE__ */ jsx(Button, { size: "icon", className: "h-9 w-9 shrink-0 rounded-full", onClick: () => stopRecording(true), "aria-label": t("conversations.thread.send"), children: /* @__PURE__ */ jsx(Square, { className: "h-3.5 w-3.5 fill-current" }) }) : empty ? /* @__PURE__ */ jsx(Button, { size: "icon", onClick: () => void startRecording(), disabled: !canType || busy || sending, "aria-label": t("conversations.composer.record"), className: cn("h-9 w-9 shrink-0 rounded-full", busy && "opacity-70"), children: busy ? /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" }) }) : /* @__PURE__ */ jsx(Button, { size: "icon", className: "h-9 w-9 shrink-0 rounded-full", onClick: () => void send(), disabled: !canType || busy || sending, "aria-label": t("conversations.thread.send"), children: busy ? /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Send, { className: "h-4 w-4" }) })
934
935
  ] })
935
936
  ] });
936
937
  }
@@ -1328,6 +1329,7 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
1328
1329
  /* @__PURE__ */ jsx(
1329
1330
  Composer,
1330
1331
  {
1332
+ clearAssistant: !panelOpen,
1331
1333
  canType,
1332
1334
  sending,
1333
1335
  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",
@@ -1893,5 +1895,5 @@ function ConversationsPage({ store, config }) {
1893
1895
  }
1894
1896
 
1895
1897
  export { ConversationsPage, conversationIdFromPath };
1896
- //# sourceMappingURL=ConversationsPage-32XXQKCP.js.map
1897
- //# sourceMappingURL=ConversationsPage-32XXQKCP.js.map
1898
+ //# sourceMappingURL=ConversationsPage-AV34J5DY.js.map
1899
+ //# sourceMappingURL=ConversationsPage-AV34J5DY.js.map