@fayz-ai/plugin-conversations 0.42.1 → 0.43.1
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/{CampaignsSurface-X2LPJEKF.js → CampaignsSurface-F4JE2VF4.js} +43 -78
- package/dist/CampaignsSurface-F4JE2VF4.js.map +1 -0
- package/dist/ConversationThreadSurface-O6MQVLOO.js +111 -0
- package/dist/ConversationThreadSurface-O6MQVLOO.js.map +1 -0
- package/dist/ConversationsPage-ZYMNPRSI.js +621 -0
- package/dist/ConversationsPage-ZYMNPRSI.js.map +1 -0
- package/dist/{ConversationsSettings-GORCWUHD.js → ConversationsSettings-4UUJD6IC.js} +6 -5
- package/dist/ConversationsSettings-4UUJD6IC.js.map +1 -0
- package/dist/chunk-27Z3U4CN.js +290 -0
- package/dist/chunk-27Z3U4CN.js.map +1 -0
- package/dist/{chunk-GYEAIN3O.js → chunk-B6ACT265.js} +49 -36
- package/dist/chunk-B6ACT265.js.map +1 -0
- package/dist/chunk-IH7XSR4A.js +13 -0
- package/dist/chunk-IH7XSR4A.js.map +1 -0
- package/dist/chunk-KCGMJBZY.js +47 -0
- package/dist/chunk-KCGMJBZY.js.map +1 -0
- package/dist/{ConversationsPage-Z3YKLAOJ.js → chunk-KTYFNZ2V.js} +289 -701
- package/dist/chunk-KTYFNZ2V.js.map +1 -0
- package/dist/{chunk-W5VV6G35.js → chunk-R65GJLBC.js} +4 -16
- package/dist/chunk-R65GJLBC.js.map +1 -0
- package/dist/components/Composer.d.ts +3 -1
- package/dist/components/Composer.d.ts.map +1 -1
- package/dist/context.d.ts +3 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/data/accents.d.ts.map +1 -1
- package/dist/data/mock.d.ts.map +1 -1
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/data/types.d.ts +6 -0
- package/dist/data/types.d.ts.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -285
- package/dist/index.js.map +1 -1
- package/dist/integrations/tyxter/connectorDef.d.ts.map +1 -1
- package/dist/lib/ao-vivo.d.ts +32 -0
- package/dist/lib/ao-vivo.d.ts.map +1 -0
- package/dist/lib/onboarding.d.ts +3 -4
- package/dist/lib/onboarding.d.ts.map +1 -1
- package/dist/lib/runtime.d.ts +10 -0
- package/dist/lib/runtime.d.ts.map +1 -0
- package/dist/locales/en.d.ts.map +1 -1
- package/dist/locales/pt-BR.d.ts.map +1 -1
- package/dist/migrations/index.d.ts +2 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/main.browser.js +3 -1
- package/dist/migrations/main.browser.js.map +1 -1
- package/dist/migrations/main.js +191 -2
- package/dist/migrations/main.js.map +1 -1
- package/dist/settings/ConversationsSettings.d.ts.map +1 -1
- package/dist/settings/WhatsAppProviders.d.ts.map +1 -1
- package/dist/store.d.ts +6 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/views/CampaignsView.d.ts.map +1 -1
- package/dist/views/ContactPanel.d.ts +3 -1
- package/dist/views/ContactPanel.d.ts.map +1 -1
- package/dist/views/ConversationList.d.ts.map +1 -1
- package/dist/views/ConversationThreadSurface.d.ts +12 -0
- package/dist/views/ConversationThreadSurface.d.ts.map +1 -0
- package/dist/views/ConversationsPage.d.ts +6 -1
- package/dist/views/ConversationsPage.d.ts.map +1 -1
- package/dist/views/MessageInspector.d.ts.map +1 -1
- package/dist/views/MessageThread.d.ts +7 -1
- package/dist/views/MessageThread.d.ts.map +1 -1
- package/dist/views/NewConversationPanel.d.ts.map +1 -1
- package/dist/views/RecordLinks.d.ts +53 -0
- package/dist/views/RecordLinks.d.ts.map +1 -0
- package/dist/views/SendWindow.d.ts +2 -1
- package/dist/views/SendWindow.d.ts.map +1 -1
- package/dist/views/TemplatesView.d.ts.map +1 -1
- package/dist/views/campaigns/OfficialBalance.d.ts +2 -1
- package/dist/views/campaigns/OfficialBalance.d.ts.map +1 -1
- package/dist/views/useConversaAoVivo.d.ts +17 -0
- package/dist/views/useConversaAoVivo.d.ts.map +1 -0
- package/package.json +4 -4
- package/dist/CampaignsSurface-X2LPJEKF.js.map +0 -1
- package/dist/ConversationsPage-Z3YKLAOJ.js.map +0 -1
- package/dist/ConversationsSettings-GORCWUHD.js.map +0 -1
- package/dist/chunk-GYEAIN3O.js.map +0 -1
- package/dist/chunk-W5VV6G35.js.map +0 -1
|
@@ -1,395 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useConversationsStore, CHANNEL_LABELS, useConversationsConfig, mediaPreviewKind, MessagePreview } from './chunk-B6ACT265.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 {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
import { useTranslation, getSupabaseClientOptional, getActiveTenantId, navigateApp, appHref } from '@fayz-ai/core';
|
|
6
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
7
|
+
import { LifeBuoy, Globe, Mail, Instagram, MessageSquare, Phone, ChevronLeft, MoreHorizontal, MailWarning, ArchiveRestore, Archive, X, Building2, Snowflake, Sun, Flame, Link2, Tag, Ban, ThumbsDown, PhoneMissed, MessageSquareOff, PhoneOff, MoreVertical, Loader2, Forward, AlertTriangle, CheckCheck, Check, Clock, ExternalLink, Reply, FileText, Trash2, Paperclip, Square, Mic, Send, BarChart3, MapPin, UserRound, Copy, Download } from 'lucide-react';
|
|
8
|
+
import { cn, Button, Dropdown, DropdownTrigger, DropdownContent, DropdownItem, Skeleton, Badge, DropdownSub, DropdownSubTrigger, DropdownSubContent, Modal, ModalContent, ModalHeader, ModalTitle, ModalDescription, ModalBody, Textarea, ModalFooter, toast } from '@fayz-ai/ui';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
sms: Phone,
|
|
13
|
-
whatsapp: MessageSquare,
|
|
14
|
-
instagram: Instagram,
|
|
15
|
-
email: Mail,
|
|
16
|
-
webchat: Globe,
|
|
17
|
-
support: LifeBuoy
|
|
18
|
-
};
|
|
19
|
-
var CHANNEL_ACCENT = {
|
|
20
|
-
whatsapp: { color: "#22c55e", badge: "bg-[#22c55e]/12 text-[#15803d] dark:text-[#4ade80]" },
|
|
21
|
-
sms: { color: "#6366f1", badge: "bg-[#6366f1]/12 text-[#4338ca] dark:text-[#a5b4fc]" },
|
|
22
|
-
instagram: { color: "#ec4899", badge: "bg-[#ec4899]/12 text-[#be185d] dark:text-[#f9a8d4]" },
|
|
23
|
-
email: { color: "#0ea5e9", badge: "bg-[#0ea5e9]/12 text-[#0369a1] dark:text-[#7dd3fc]" },
|
|
24
|
-
webchat: { color: "#f59e0b", badge: "bg-[#f59e0b]/12 text-[#b45309] dark:text-[#fcd34d]" },
|
|
25
|
-
support: { color: "#64748b", badge: "bg-[#64748b]/12 text-[#334155] dark:text-[#cbd5e1]" }
|
|
26
|
-
};
|
|
27
|
-
var UNKNOWN_ACCENT = { color: "#64748b", badge: "bg-muted text-muted-foreground" };
|
|
28
|
-
var channelAccent = (ch) => CHANNEL_ACCENT[ch] ?? UNKNOWN_ACCENT;
|
|
29
|
-
var channelIcon = (ch) => CHANNEL_ICON[ch] ?? MessageSquare;
|
|
30
|
-
var channelLabel = (ch) => CHANNEL_LABELS[ch] ?? String(ch ?? "");
|
|
31
|
-
function useMediaQuery(query) {
|
|
32
|
-
const [matches, setMatches] = React7__default.useState(
|
|
33
|
-
() => typeof window !== "undefined" && window.matchMedia(query).matches
|
|
34
|
-
);
|
|
35
|
-
React7__default.useEffect(() => {
|
|
36
|
-
if (typeof window === "undefined") return;
|
|
37
|
-
const mql = window.matchMedia(query);
|
|
38
|
-
const onChange = () => setMatches(mql.matches);
|
|
39
|
-
onChange();
|
|
40
|
-
mql.addEventListener("change", onChange);
|
|
41
|
-
return () => mql.removeEventListener("change", onChange);
|
|
42
|
-
}, [query]);
|
|
43
|
-
return matches;
|
|
44
|
-
}
|
|
45
|
-
function initialsOf(name) {
|
|
46
|
-
return name.replace("@", "").split(/\s+/).filter(Boolean).map((w) => w[0]).slice(0, 2).join("").toUpperCase();
|
|
47
|
-
}
|
|
48
|
-
function Avatar({ name, accent, size = "md", channel }) {
|
|
49
|
-
const dims = size === "lg" ? "h-14 w-14 text-lg" : size === "sm" ? "h-9 w-9 text-xs" : "h-10 w-10 text-sm";
|
|
50
|
-
const Icon = channel ? channelIcon(channel) : null;
|
|
51
|
-
return /* @__PURE__ */ jsxs("div", { className: "relative shrink-0", children: [
|
|
52
|
-
/* @__PURE__ */ jsx(
|
|
53
|
-
"div",
|
|
54
|
-
{
|
|
55
|
-
className: cn("flex items-center justify-center rounded-full font-semibold text-white", dims),
|
|
56
|
-
style: { backgroundColor: accent },
|
|
57
|
-
children: initialsOf(name)
|
|
58
|
-
}
|
|
59
|
-
),
|
|
60
|
-
Icon && /* @__PURE__ */ jsx(
|
|
61
|
-
"span",
|
|
62
|
-
{
|
|
63
|
-
className: "absolute -bottom-0.5 -right-0.5 flex h-4 w-4 items-center justify-center rounded-full ring-2 ring-card",
|
|
64
|
-
style: { backgroundColor: channelAccent(channel).color },
|
|
65
|
-
children: /* @__PURE__ */ jsx(Icon, { className: "h-2.5 w-2.5 text-white" })
|
|
66
|
-
}
|
|
67
|
-
)
|
|
68
|
-
] });
|
|
69
|
-
}
|
|
70
|
-
function ChannelBadge({ channel, className }) {
|
|
71
|
-
const Icon = channelIcon(channel);
|
|
72
|
-
return /* @__PURE__ */ jsxs(
|
|
73
|
-
"span",
|
|
74
|
-
{
|
|
75
|
-
className: cn(
|
|
76
|
-
"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[10px] font-medium",
|
|
77
|
-
channelAccent(channel).badge,
|
|
78
|
-
className
|
|
79
|
-
),
|
|
80
|
-
children: [
|
|
81
|
-
/* @__PURE__ */ jsx(Icon, { className: "h-2.5 w-2.5" }),
|
|
82
|
-
channelLabel(channel)
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
function relativeTime(iso) {
|
|
88
|
-
const diff = Date.now() - new Date(iso).getTime();
|
|
89
|
-
const mins = Math.round(diff / 6e4);
|
|
90
|
-
if (mins < 1) return "now";
|
|
91
|
-
if (mins < 60) return `${mins}m`;
|
|
92
|
-
const hours = Math.round(mins / 60);
|
|
93
|
-
if (hours < 24) return `${hours}h`;
|
|
94
|
-
const days = Math.round(hours / 24);
|
|
95
|
-
if (days < 7) return `${days}d`;
|
|
96
|
-
return `${Math.round(days / 7)}w`;
|
|
97
|
-
}
|
|
98
|
-
function dayLabel(iso) {
|
|
99
|
-
const d = new Date(iso);
|
|
100
|
-
const now = /* @__PURE__ */ new Date();
|
|
101
|
-
const startOf = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
102
|
-
const dayDiff = Math.round((startOf(now) - startOf(d)) / 864e5);
|
|
103
|
-
if (dayDiff <= 0) return "Today";
|
|
104
|
-
if (dayDiff === 1) return "Yesterday";
|
|
105
|
-
if (dayDiff < 7) return d.toLocaleDateString([], { weekday: "long" });
|
|
106
|
-
return d.toLocaleDateString([], { month: "short", day: "numeric", year: now.getFullYear() === d.getFullYear() ? void 0 : "numeric" });
|
|
107
|
-
}
|
|
108
|
-
var whatsappCache = null;
|
|
109
|
-
var whatsappConnected = () => {
|
|
110
|
-
whatsappCache ?? (whatsappCache = providersApi.list().then((rows) => rows.some((r) => r.isActive || r.hasCredential)).catch(() => {
|
|
111
|
-
whatsappCache = null;
|
|
112
|
-
return false;
|
|
113
|
-
}));
|
|
114
|
-
return whatsappCache;
|
|
115
|
-
};
|
|
116
|
-
function useChannelConnections() {
|
|
117
|
-
const [whatsapp, setWhatsapp] = React7.useState(void 0);
|
|
118
|
-
const { connectors } = useConnectors({ hostPluginId: "conversations", includeGrants: false });
|
|
119
|
-
React7.useEffect(() => {
|
|
120
|
-
let cancelled = false;
|
|
121
|
-
void whatsappConnected().then((v) => {
|
|
122
|
-
if (!cancelled) setWhatsapp(v);
|
|
123
|
-
});
|
|
124
|
-
return () => {
|
|
125
|
-
cancelled = true;
|
|
126
|
-
};
|
|
127
|
-
}, []);
|
|
128
|
-
return React7.useMemo(() => {
|
|
129
|
-
if (whatsapp === void 0) return void 0;
|
|
130
|
-
const live = (needle) => (connectors ?? []).some((c) => c.state === "connected" && c.slug.toLowerCase().includes(needle));
|
|
131
|
-
return { whatsapp: whatsapp || live("whatsapp"), email: live("mail"), instagram: live("instagram") };
|
|
132
|
-
}, [whatsapp, connectors]);
|
|
133
|
-
}
|
|
134
|
-
var FILTERS = ["all", "whatsapp", "instagram", "email"];
|
|
135
|
-
function ConversationList({ className }) {
|
|
136
|
-
const t = useTranslation();
|
|
137
|
-
const connected = useChannelConnections();
|
|
138
|
-
const {
|
|
139
|
-
conversations,
|
|
140
|
-
selectedId,
|
|
141
|
-
channelFilter,
|
|
142
|
-
leadOwnerFilter,
|
|
143
|
-
search,
|
|
144
|
-
loading,
|
|
145
|
-
select,
|
|
146
|
-
markRead,
|
|
147
|
-
setChannelFilter,
|
|
148
|
-
setLeadOwnerFilter,
|
|
149
|
-
setSearch
|
|
150
|
-
} = useConversationsStore((s) => s);
|
|
151
|
-
const [archived, setArchived] = React7__default.useState(false);
|
|
152
|
-
const [me, setMe] = React7__default.useState(null);
|
|
153
|
-
React7__default.useEffect(() => {
|
|
154
|
-
void currentUserId().then(setMe);
|
|
155
|
-
}, []);
|
|
156
|
-
const mine = Boolean(me) && leadOwnerFilter === me;
|
|
157
|
-
const decided = React7__default.useRef(false);
|
|
158
|
-
React7__default.useEffect(() => {
|
|
159
|
-
if (decided.current || !me || loading || conversations.length === 0) return;
|
|
160
|
-
decided.current = true;
|
|
161
|
-
let pref = null;
|
|
162
|
-
try {
|
|
163
|
-
pref = localStorage.getItem("conversas.owner");
|
|
164
|
-
} catch {
|
|
165
|
-
}
|
|
166
|
-
const ownsAny = conversations.some((c) => c.leadOwnerId === me);
|
|
167
|
-
if (leadOwnerFilter === void 0 && (pref === "me" || pref === null && ownsAny)) void setLeadOwnerFilter(me);
|
|
168
|
-
}, [me, loading, conversations, leadOwnerFilter, setLeadOwnerFilter]);
|
|
169
|
-
const pickOwner = (v) => {
|
|
170
|
-
try {
|
|
171
|
-
localStorage.setItem("conversas.owner", v && v === me ? "me" : "any");
|
|
172
|
-
} catch {
|
|
173
|
-
}
|
|
174
|
-
void setLeadOwnerFilter(v);
|
|
175
|
-
};
|
|
176
|
-
const mineCount = React7__default.useMemo(
|
|
177
|
-
() => mine ? conversations.filter((c) => c.status !== "closed" && isWaitingOnUs(c)).length : 0,
|
|
178
|
-
[conversations, mine]
|
|
179
|
-
);
|
|
180
|
-
const [inbox, setInbox] = React7__default.useState("commercial");
|
|
181
|
-
const inboxes = React7__default.useMemo(() => new Set(conversations.map((c) => c.inbox ?? "commercial")), [conversations]);
|
|
182
|
-
const bothInboxes = inboxes.size > 1;
|
|
183
|
-
const waitingIn = (which) => conversations.filter((c) => (c.inbox ?? "commercial") === which && c.status !== "closed" && isWaitingOnUs(c)).length;
|
|
184
|
-
const shown = React7__default.useMemo(
|
|
185
|
-
// Waiting on us stays pinned on top (newest first among them): a red thread
|
|
186
|
-
// is a contact to make, and it must not sink under newer chatter.
|
|
187
|
-
() => 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),
|
|
188
|
-
[conversations, archived, bothInboxes, inbox]
|
|
189
|
-
);
|
|
190
|
-
const donos = React7__default.useMemo(() => {
|
|
191
|
-
const vistos = /* @__PURE__ */ new Map();
|
|
192
|
-
for (const c of conversations) {
|
|
193
|
-
if (c.leadOwnerId) vistos.set(c.leadOwnerId, c.leadOwnerName ?? c.leadOwnerId);
|
|
194
|
-
}
|
|
195
|
-
return [...vistos].map(([value, label]) => ({ value, label }));
|
|
196
|
-
}, [conversations]);
|
|
197
|
-
return /* @__PURE__ */ jsxs("aside", { className: cn("w-full shrink-0 flex-col border-r border-border bg-card lg:w-[320px]", className), children: [
|
|
198
|
-
bothInboxes && /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 border-b border-border text-sm", children: ["commercial", "support"].map((which) => {
|
|
199
|
-
const n = waitingIn(which);
|
|
200
|
-
return /* @__PURE__ */ jsxs(
|
|
201
|
-
"button",
|
|
202
|
-
{
|
|
203
|
-
type: "button",
|
|
204
|
-
onClick: () => setInbox(which),
|
|
205
|
-
className: cn(
|
|
206
|
-
"flex items-center justify-center gap-1.5 py-2.5 font-medium transition-colors",
|
|
207
|
-
inbox === which ? "border-b-2 border-primary text-foreground" : "text-muted-foreground hover:text-foreground"
|
|
208
|
-
),
|
|
209
|
-
children: [
|
|
210
|
-
which === "commercial" ? "Comercial" : "Suporte",
|
|
211
|
-
n > 0 && /* @__PURE__ */ jsx("span", { className: "rounded-full bg-destructive px-1.5 text-[10px] font-semibold text-destructive-foreground", children: n })
|
|
212
|
-
]
|
|
213
|
-
},
|
|
214
|
-
which
|
|
215
|
-
);
|
|
216
|
-
}) }),
|
|
217
|
-
/* @__PURE__ */ jsxs("div", { className: "border-b border-border px-3 py-3", children: [
|
|
218
|
-
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
219
|
-
/* @__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" }),
|
|
220
|
-
/* @__PURE__ */ jsx(
|
|
221
|
-
Input,
|
|
222
|
-
{
|
|
223
|
-
value: search,
|
|
224
|
-
onChange: (e) => setSearch(e.target.value),
|
|
225
|
-
placeholder: t("conversations.list.search"),
|
|
226
|
-
className: "pl-8"
|
|
227
|
-
}
|
|
228
|
-
)
|
|
229
|
-
] }),
|
|
230
|
-
/* @__PURE__ */ jsx("div", { className: "mt-2 flex flex-wrap gap-1", children: FILTERS.map((id) => {
|
|
231
|
-
const off = id !== "all" && connected !== void 0 && !connected[id];
|
|
232
|
-
return /* @__PURE__ */ jsx(
|
|
233
|
-
Button,
|
|
234
|
-
{
|
|
235
|
-
variant: "bare",
|
|
236
|
-
size: "bare",
|
|
237
|
-
onClick: () => setChannelFilter(id),
|
|
238
|
-
title: off ? t("conversations.filter.notConnected") : void 0,
|
|
239
|
-
className: cn(
|
|
240
|
-
"rounded-full border px-2.5 py-1 text-xs font-medium transition-colors",
|
|
241
|
-
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"
|
|
242
|
-
),
|
|
243
|
-
children: t(`conversations.filter.${id}`)
|
|
244
|
-
},
|
|
245
|
-
id
|
|
246
|
-
);
|
|
247
|
-
}) }),
|
|
248
|
-
/* @__PURE__ */ jsxs("div", { className: "mt-2 flex flex-wrap items-center gap-1", children: [
|
|
249
|
-
(donos.length > 0 || mine) && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
250
|
-
FilterChip,
|
|
251
|
-
{
|
|
252
|
-
label: t("conversations.contact.leadOwner"),
|
|
253
|
-
icon: User,
|
|
254
|
-
allLabel: t("conversations.filter.anyOwner"),
|
|
255
|
-
options: [
|
|
256
|
-
...me ? [{ value: me, label: mine && mineCount > 0 ? `Meus leads \xB7 ${mineCount} esperando` : "Meus leads" }] : [],
|
|
257
|
-
{ value: "none", label: t("conversations.filter.noOwner") },
|
|
258
|
-
...donos.filter((d) => d.value !== me)
|
|
259
|
-
],
|
|
260
|
-
value: leadOwnerFilter,
|
|
261
|
-
onChange: (v) => pickOwner(v)
|
|
262
|
-
}
|
|
263
|
-
) }),
|
|
264
|
-
/* @__PURE__ */ jsxs(
|
|
265
|
-
Button,
|
|
266
|
-
{
|
|
267
|
-
variant: "bare",
|
|
268
|
-
size: "bare",
|
|
269
|
-
type: "button",
|
|
270
|
-
"aria-pressed": archived,
|
|
271
|
-
onClick: () => setArchived((v) => !v),
|
|
272
|
-
className: cn(
|
|
273
|
-
"inline-flex items-center gap-1 rounded-full border px-2.5 py-1 text-xs font-medium transition-colors",
|
|
274
|
-
archived ? "border-transparent bg-primary text-primary-foreground" : "border-transparent bg-muted text-muted-foreground hover:bg-muted/70"
|
|
275
|
-
),
|
|
276
|
-
children: [
|
|
277
|
-
/* @__PURE__ */ jsx(Archive, { className: "h-3 w-3" }),
|
|
278
|
-
" ",
|
|
279
|
-
t("conversations.filter.archived")
|
|
280
|
-
]
|
|
281
|
-
}
|
|
282
|
-
)
|
|
283
|
-
] })
|
|
284
|
-
] }),
|
|
285
|
-
/* @__PURE__ */ jsxs("div", { className: "min-h-0 flex-1 overflow-y-auto", children: [
|
|
286
|
-
loading && conversations.length === 0 && Array.from({ length: 6 }, (_, i) => /* @__PURE__ */ jsxs("div", { className: "flex w-full items-start gap-3 border-b border-border/50 px-3 py-3", children: [
|
|
287
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-10 shrink-0 rounded-full" }),
|
|
288
|
-
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
289
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
290
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-28" }),
|
|
291
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-8" })
|
|
292
|
-
] }),
|
|
293
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "mt-1.5 h-4 w-16 rounded-full" }),
|
|
294
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "mt-1.5 h-3 w-3/4" })
|
|
295
|
-
] })
|
|
296
|
-
] }, i)),
|
|
297
|
-
!loading && mine && !archived && shown.length === 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 p-8 text-center text-muted-foreground", children: [
|
|
298
|
-
/* @__PURE__ */ jsx(Inbox, { className: "h-6 w-6" }),
|
|
299
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm", children: "Voc\xEA ainda n\xE3o tem leads nas conversas." }),
|
|
300
|
-
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "outline", onClick: () => pickOwner(void 0), children: "Ver todas as conversas" })
|
|
301
|
-
] }),
|
|
302
|
-
!loading && !(mine && !archived) && shown.length === 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 p-8 text-center text-muted-foreground", children: [
|
|
303
|
-
/* @__PURE__ */ jsx(Inbox, { className: "h-6 w-6" }),
|
|
304
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm", children: archived ? t("conversations.list.emptyArchived") : t("conversations.list.empty") })
|
|
305
|
-
] }),
|
|
306
|
-
!loading && mine && !archived && shown.length > 0 && !isWaitingOnUs(shown[0]) && /* @__PURE__ */ jsxs("div", { className: "m-3 flex items-center gap-2 rounded-lg border border-success/30 bg-success-soft px-3 py-2.5 text-sm text-success-soft-foreground", children: [
|
|
307
|
-
/* @__PURE__ */ jsx(CheckCheck, { className: "h-4 w-4 shrink-0" }),
|
|
308
|
-
" Nenhum lead esperando sua resposta."
|
|
309
|
-
] }),
|
|
310
|
-
shown.map((c, idx) => {
|
|
311
|
-
const sectionHeader = mine && !archived ? idx === 0 && isWaitingOnUs(c) ? /* @__PURE__ */ jsxs("p", { className: "sticky top-0 z-[1] bg-destructive-soft px-3 py-1.5 text-xs font-semibold text-destructive-soft-foreground", children: [
|
|
312
|
-
"Esperando sua resposta \xB7 ",
|
|
313
|
-
shown.filter(isWaitingOnUs).length
|
|
314
|
-
] }, `h-wait`) : idx > 0 && isWaitingOnUs(shown[idx - 1]) && !isWaitingOnUs(c) ? /* @__PURE__ */ jsx("p", { className: "bg-muted/60 px-3 py-1.5 text-xs font-medium text-muted-foreground", children: "Em dia" }, `h-ok`) : null : null;
|
|
315
|
-
const active = c.id === selectedId;
|
|
316
|
-
const unread = isWaitingOnUs(c);
|
|
317
|
-
return (
|
|
318
|
-
// `div` em volta e não um botão dentro de outro: HTML não permite
|
|
319
|
-
// aninhar, e o navegador resolve isso silenciosamente movendo o
|
|
320
|
-
// interno para fora — a linha inteira deixa de ser clicável e
|
|
321
|
-
// ninguém entende por quê.
|
|
322
|
-
/* @__PURE__ */ jsxs(React7__default.Fragment, { children: [
|
|
323
|
-
sectionHeader,
|
|
324
|
-
/* @__PURE__ */ jsxs("div", { className: "group relative", children: [
|
|
325
|
-
/* @__PURE__ */ jsxs(
|
|
326
|
-
Button,
|
|
327
|
-
{
|
|
328
|
-
variant: "bare",
|
|
329
|
-
size: "bare",
|
|
330
|
-
onClick: () => select(c.id),
|
|
331
|
-
className: cn(
|
|
332
|
-
"flex w-full items-start justify-start gap-3 rounded-none border-b border-border/50 px-3 py-3 text-left font-normal transition-colors",
|
|
333
|
-
// Um TOM da cor de marca, e não `bg-accent`.
|
|
334
|
-
//
|
|
335
|
-
// `bg-accent` resolve para quase preto neste tema, e a linha da
|
|
336
|
-
// conversa aberta ficava escura sobre escura. Trocar junto o
|
|
337
|
-
// `text-accent-foreground` deixava legível, mas pintava de
|
|
338
|
-
// preto a única linha que se está a ler — chamava mais atenção
|
|
339
|
-
// que a conversa.
|
|
340
|
-
//
|
|
341
|
-
// `bg-primary/10` é um véu: o texto continua com as cores dele,
|
|
342
|
-
// a seleção se lê como seleção e não como bloco, e funciona nos
|
|
343
|
-
// dois temas porque não presume nada sobre o fundo.
|
|
344
|
-
active ? "bg-primary/10" : "hover:bg-muted/50"
|
|
345
|
-
),
|
|
346
|
-
children: [
|
|
347
|
-
/* @__PURE__ */ jsx(Avatar, { name: c.contactName, accent: c.accent, channel: c.channel }),
|
|
348
|
-
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
349
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
350
|
-
/* @__PURE__ */ jsx("span", { className: cn("truncate text-sm text-foreground", unread ? "font-semibold" : "font-medium"), children: c.contactName }),
|
|
351
|
-
/* @__PURE__ */ jsx("span", { className: cn("shrink-0 text-[11px]", unread ? "font-semibold text-primary" : "text-muted-foreground"), children: relativeTime(c.lastMessageAt) })
|
|
352
|
-
] }),
|
|
353
|
-
/* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-2", children: [
|
|
354
|
-
/* @__PURE__ */ jsx(ChannelBadge, { channel: c.channel }),
|
|
355
|
-
c.status !== "open" && /* @__PURE__ */ jsx("span", { className: "text-[10px] uppercase tracking-wide text-muted-foreground/70", children: t(`conversations.status.${c.status}`) }),
|
|
356
|
-
c.leadOwnerName && /* @__PURE__ */ jsxs("span", { className: "inline-flex shrink-0 items-center gap-0.5 rounded-full bg-muted px-1.5 text-[10px] text-muted-foreground", children: [
|
|
357
|
-
/* @__PURE__ */ jsx(User, { className: "h-2.5 w-2.5" }),
|
|
358
|
-
c.leadOwnerName.split(" ")[0]
|
|
359
|
-
] })
|
|
360
|
-
] }),
|
|
361
|
-
/* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center justify-between gap-2", children: [
|
|
362
|
-
/* @__PURE__ */ jsx("span", { className: cn("truncate text-xs", unread ? "text-foreground" : "text-muted-foreground"), children: /* @__PURE__ */ jsx(MessagePreview, { text: c.lastMessagePreview }) }),
|
|
363
|
-
unread && /* @__PURE__ */ jsx("span", { className: "flex h-[18px] min-w-[18px] shrink-0 items-center justify-center rounded-full bg-destructive px-1.5 text-[10px] font-semibold text-destructive-foreground group-hover:invisible", children: c.unreadCount > 0 ? c.unreadCount : "\xB7" })
|
|
364
|
-
] })
|
|
365
|
-
] })
|
|
366
|
-
]
|
|
367
|
-
}
|
|
368
|
-
),
|
|
369
|
-
unread && /* @__PURE__ */ jsx(
|
|
370
|
-
Button,
|
|
371
|
-
{
|
|
372
|
-
variant: "bare",
|
|
373
|
-
size: "bare",
|
|
374
|
-
type: "button",
|
|
375
|
-
title: t("conversations.markRead"),
|
|
376
|
-
"aria-label": t("conversations.markRead"),
|
|
377
|
-
onClick: (e) => {
|
|
378
|
-
e.stopPropagation();
|
|
379
|
-
void markRead(c.id);
|
|
380
|
-
},
|
|
381
|
-
className: "absolute bottom-2.5 right-2.5 hidden rounded-full p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground group-hover:block",
|
|
382
|
-
children: /* @__PURE__ */ jsx(CheckCheck, { className: "h-3.5 w-3.5" })
|
|
383
|
-
}
|
|
384
|
-
)
|
|
385
|
-
] })
|
|
386
|
-
] }, c.id)
|
|
387
|
-
);
|
|
388
|
-
})
|
|
389
|
-
] })
|
|
390
|
-
] });
|
|
391
|
-
}
|
|
392
|
-
function useSendWindow(conversationId, contactHandle) {
|
|
10
|
+
function useSendWindow(conversationId, contactHandle, channel) {
|
|
393
11
|
const [row, setRow] = React7__default.useState(null);
|
|
394
12
|
const [optedOut, setOptedOut] = React7__default.useState(false);
|
|
395
13
|
const [providers, setProviders] = React7__default.useState(null);
|
|
@@ -440,6 +58,7 @@ function useSendWindow(conversationId, contactHandle) {
|
|
|
440
58
|
}, [contactHandle]);
|
|
441
59
|
const provider = (providers ?? []).find((p) => p.isActive);
|
|
442
60
|
const mode = React7__default.useMemo(() => {
|
|
61
|
+
if (channel === "support") return { kind: "free", until: null, minutesLeft: null };
|
|
443
62
|
if (optedOut) return { kind: "blocked", reason: "opted_out" };
|
|
444
63
|
if (!provider) return { kind: "blocked", reason: "no_provider" };
|
|
445
64
|
if (!provider.capabilities?.requires_template) {
|
|
@@ -449,8 +68,8 @@ function useSendWindow(conversationId, contactHandle) {
|
|
|
449
68
|
return { kind: "free", until: row.window_expires_at, minutesLeft: row.minutes_left };
|
|
450
69
|
}
|
|
451
70
|
return { kind: "template", reason: row?.last_inbound_at ? "window_closed" : "never_replied" };
|
|
452
|
-
}, [row, provider, optedOut]);
|
|
453
|
-
return { loading: providers === null, mode, provider };
|
|
71
|
+
}, [row, provider, optedOut, channel]);
|
|
72
|
+
return { loading: channel === "support" ? false : providers === null, mode, provider };
|
|
454
73
|
}
|
|
455
74
|
function humanLeft(minutes) {
|
|
456
75
|
if (minutes == null) return "";
|
|
@@ -505,6 +124,7 @@ var STATUS = {
|
|
|
505
124
|
var BAD = /* @__PURE__ */ new Set(["failed", "expired", "cancelled", "opted_out", "delivery_timeout"]);
|
|
506
125
|
function isFailed(m) {
|
|
507
126
|
if (m.direction !== "outbound") return false;
|
|
127
|
+
if (m.channel === "support") return false;
|
|
508
128
|
if (m.deliveryStatus) return BAD.has(m.deliveryStatus);
|
|
509
129
|
if (m.providerMessageId) return false;
|
|
510
130
|
const age = Date.now() - new Date(m.at).getTime();
|
|
@@ -597,6 +217,196 @@ function MessageMenu({ m }) {
|
|
|
597
217
|
] }) })
|
|
598
218
|
] });
|
|
599
219
|
}
|
|
220
|
+
var CHANNEL_ICON = {
|
|
221
|
+
sms: Phone,
|
|
222
|
+
whatsapp: MessageSquare,
|
|
223
|
+
instagram: Instagram,
|
|
224
|
+
email: Mail,
|
|
225
|
+
webchat: Globe,
|
|
226
|
+
support: LifeBuoy
|
|
227
|
+
};
|
|
228
|
+
var CHANNEL_ACCENT = {
|
|
229
|
+
whatsapp: { color: "#22c55e", badge: "bg-[#22c55e]/12 text-[#15803d] dark:text-[#4ade80]" },
|
|
230
|
+
sms: { color: "#6366f1", badge: "bg-[#6366f1]/12 text-[#4338ca] dark:text-[#a5b4fc]" },
|
|
231
|
+
instagram: { color: "#ec4899", badge: "bg-[#ec4899]/12 text-[#be185d] dark:text-[#f9a8d4]" },
|
|
232
|
+
email: { color: "#0ea5e9", badge: "bg-[#0ea5e9]/12 text-[#0369a1] dark:text-[#7dd3fc]" },
|
|
233
|
+
webchat: { color: "#f59e0b", badge: "bg-[#f59e0b]/12 text-[#b45309] dark:text-[#fcd34d]" },
|
|
234
|
+
support: { color: "#8b5cf6", badge: "bg-[#8b5cf6]/12 text-[#6d28d9] dark:text-[#c4b5fd]" }
|
|
235
|
+
};
|
|
236
|
+
var UNKNOWN_ACCENT = { color: "#64748b", badge: "bg-muted text-muted-foreground" };
|
|
237
|
+
var channelAccent = (ch) => CHANNEL_ACCENT[ch] ?? UNKNOWN_ACCENT;
|
|
238
|
+
var channelIcon = (ch) => CHANNEL_ICON[ch] ?? MessageSquare;
|
|
239
|
+
var channelLabel = (ch) => CHANNEL_LABELS[ch] ?? String(ch ?? "");
|
|
240
|
+
var REGISTRO = /* @__PURE__ */ Symbol.for("fayz.conversa-ao-vivo");
|
|
241
|
+
var EVENTOS = ["message", "changed", "typing", "chat"];
|
|
242
|
+
function registro() {
|
|
243
|
+
const g = globalThis;
|
|
244
|
+
return g[REGISTRO] ?? (g[REGISTRO] = /* @__PURE__ */ new Map());
|
|
245
|
+
}
|
|
246
|
+
var topicoDaConversa = (conversationId) => `conversa:${conversationId}`;
|
|
247
|
+
function ouvirConversa(conversationId, ouvinte) {
|
|
248
|
+
const supabase = getSupabaseClientOptional();
|
|
249
|
+
if (!supabase?.channel || !conversationId) return () => {
|
|
250
|
+
};
|
|
251
|
+
const topico = topicoDaConversa(conversationId);
|
|
252
|
+
const reg = registro();
|
|
253
|
+
let e = reg.get(topico);
|
|
254
|
+
if (!e) {
|
|
255
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
256
|
+
let channel = supabase.channel(topico, { config: { broadcast: { self: false } } });
|
|
257
|
+
for (const ev of EVENTOS) {
|
|
258
|
+
channel = channel.on("broadcast", { event: ev }, (msg) => {
|
|
259
|
+
const evento = { event: ev, payload: msg?.payload ?? {} };
|
|
260
|
+
for (const f of [...listeners]) {
|
|
261
|
+
try {
|
|
262
|
+
f(evento);
|
|
263
|
+
} catch {
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
channel.subscribe();
|
|
269
|
+
e = { channel, listeners };
|
|
270
|
+
reg.set(topico, e);
|
|
271
|
+
}
|
|
272
|
+
e.listeners.add(ouvinte);
|
|
273
|
+
return () => {
|
|
274
|
+
const atual = reg.get(topico);
|
|
275
|
+
if (!atual) return;
|
|
276
|
+
atual.listeners.delete(ouvinte);
|
|
277
|
+
if (atual.listeners.size === 0) {
|
|
278
|
+
reg.delete(topico);
|
|
279
|
+
void getSupabaseClientOptional()?.removeChannel?.(atual.channel);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function avisarDigitando(conversationId, from) {
|
|
284
|
+
const e = registro().get(topicoDaConversa(conversationId));
|
|
285
|
+
if (!e) return;
|
|
286
|
+
try {
|
|
287
|
+
void e.channel.send({ type: "broadcast", event: "typing", payload: { from } });
|
|
288
|
+
} catch {
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function conversaAoVivo(channel) {
|
|
292
|
+
return channel === "support" || channel === "webchat";
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// src/views/useConversaAoVivo.ts
|
|
296
|
+
var MOSTRA_MS = 4e3;
|
|
297
|
+
var AVISA_A_CADA_MS = 2e3;
|
|
298
|
+
function useConversaAoVivo(conversationId, channel, aoMudar) {
|
|
299
|
+
const ativo = !!conversationId && conversaAoVivo(channel);
|
|
300
|
+
const [outroDigitando, setOutroDigitando] = React7.useState(false);
|
|
301
|
+
const ultimo = React7.useRef(0);
|
|
302
|
+
const timer = React7.useRef(null);
|
|
303
|
+
const mudou = React7.useRef(aoMudar);
|
|
304
|
+
mudou.current = aoMudar;
|
|
305
|
+
React7.useEffect(() => {
|
|
306
|
+
setOutroDigitando(false);
|
|
307
|
+
if (!ativo || !conversationId) return;
|
|
308
|
+
const sair = ouvirConversa(conversationId, (e) => {
|
|
309
|
+
if (e.event === "typing") {
|
|
310
|
+
if (e.payload.from !== "customer") return;
|
|
311
|
+
setOutroDigitando(true);
|
|
312
|
+
if (timer.current) clearTimeout(timer.current);
|
|
313
|
+
timer.current = setTimeout(() => setOutroDigitando(false), MOSTRA_MS);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (e.event === "message" && e.payload.direction === "inbound") setOutroDigitando(false);
|
|
317
|
+
if (e.event === "message" || e.event === "changed") mudou.current();
|
|
318
|
+
});
|
|
319
|
+
return () => {
|
|
320
|
+
sair();
|
|
321
|
+
if (timer.current) clearTimeout(timer.current);
|
|
322
|
+
};
|
|
323
|
+
}, [ativo, conversationId]);
|
|
324
|
+
const avisar = React7.useCallback(() => {
|
|
325
|
+
if (!ativo || !conversationId) return;
|
|
326
|
+
const agora = Date.now();
|
|
327
|
+
if (agora - ultimo.current < AVISA_A_CADA_MS) return;
|
|
328
|
+
ultimo.current = agora;
|
|
329
|
+
avisarDigitando(conversationId, "agent");
|
|
330
|
+
}, [ativo, conversationId]);
|
|
331
|
+
return { outroDigitando: ativo && outroDigitando, avisar };
|
|
332
|
+
}
|
|
333
|
+
function useMediaQuery(query) {
|
|
334
|
+
const [matches, setMatches] = React7__default.useState(
|
|
335
|
+
() => typeof window !== "undefined" && window.matchMedia(query).matches
|
|
336
|
+
);
|
|
337
|
+
React7__default.useEffect(() => {
|
|
338
|
+
if (typeof window === "undefined") return;
|
|
339
|
+
const mql = window.matchMedia(query);
|
|
340
|
+
const onChange = () => setMatches(mql.matches);
|
|
341
|
+
onChange();
|
|
342
|
+
mql.addEventListener("change", onChange);
|
|
343
|
+
return () => mql.removeEventListener("change", onChange);
|
|
344
|
+
}, [query]);
|
|
345
|
+
return matches;
|
|
346
|
+
}
|
|
347
|
+
function initialsOf(name) {
|
|
348
|
+
return name.replace("@", "").split(/\s+/).filter(Boolean).map((w) => w[0]).slice(0, 2).join("").toUpperCase();
|
|
349
|
+
}
|
|
350
|
+
function Avatar({ name, accent, size = "md", channel }) {
|
|
351
|
+
const dims = size === "lg" ? "h-14 w-14 text-lg" : size === "sm" ? "h-9 w-9 text-xs" : "h-10 w-10 text-sm";
|
|
352
|
+
const Icon = channel ? channelIcon(channel) : null;
|
|
353
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative shrink-0", children: [
|
|
354
|
+
/* @__PURE__ */ jsx(
|
|
355
|
+
"div",
|
|
356
|
+
{
|
|
357
|
+
className: cn("flex items-center justify-center rounded-full font-semibold text-white", dims),
|
|
358
|
+
style: { backgroundColor: accent },
|
|
359
|
+
children: initialsOf(name)
|
|
360
|
+
}
|
|
361
|
+
),
|
|
362
|
+
Icon && /* @__PURE__ */ jsx(
|
|
363
|
+
"span",
|
|
364
|
+
{
|
|
365
|
+
className: "absolute -bottom-0.5 -right-0.5 flex h-4 w-4 items-center justify-center rounded-full ring-2 ring-card",
|
|
366
|
+
style: { backgroundColor: channelAccent(channel).color },
|
|
367
|
+
children: /* @__PURE__ */ jsx(Icon, { className: "h-2.5 w-2.5 text-white" })
|
|
368
|
+
}
|
|
369
|
+
)
|
|
370
|
+
] });
|
|
371
|
+
}
|
|
372
|
+
function ChannelBadge({ channel, className }) {
|
|
373
|
+
const Icon = channelIcon(channel);
|
|
374
|
+
return /* @__PURE__ */ jsxs(
|
|
375
|
+
"span",
|
|
376
|
+
{
|
|
377
|
+
className: cn(
|
|
378
|
+
"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[10px] font-medium",
|
|
379
|
+
channelAccent(channel).badge,
|
|
380
|
+
className
|
|
381
|
+
),
|
|
382
|
+
children: [
|
|
383
|
+
/* @__PURE__ */ jsx(Icon, { className: "h-2.5 w-2.5" }),
|
|
384
|
+
channelLabel(channel)
|
|
385
|
+
]
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
function relativeTime(iso) {
|
|
390
|
+
const diff = Date.now() - new Date(iso).getTime();
|
|
391
|
+
const mins = Math.round(diff / 6e4);
|
|
392
|
+
if (mins < 1) return "now";
|
|
393
|
+
if (mins < 60) return `${mins}m`;
|
|
394
|
+
const hours = Math.round(mins / 60);
|
|
395
|
+
if (hours < 24) return `${hours}h`;
|
|
396
|
+
const days = Math.round(hours / 24);
|
|
397
|
+
if (days < 7) return `${days}d`;
|
|
398
|
+
return `${Math.round(days / 7)}w`;
|
|
399
|
+
}
|
|
400
|
+
function dayLabel(iso) {
|
|
401
|
+
const d = new Date(iso);
|
|
402
|
+
const now = /* @__PURE__ */ new Date();
|
|
403
|
+
const startOf = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
404
|
+
const dayDiff = Math.round((startOf(now) - startOf(d)) / 864e5);
|
|
405
|
+
if (dayDiff <= 0) return "Today";
|
|
406
|
+
if (dayDiff === 1) return "Yesterday";
|
|
407
|
+
if (dayDiff < 7) return d.toLocaleDateString([], { weekday: "long" });
|
|
408
|
+
return d.toLocaleDateString([], { month: "short", day: "numeric", year: now.getFullYear() === d.getFullYear() ? void 0 : "numeric" });
|
|
409
|
+
}
|
|
600
410
|
|
|
601
411
|
// src/lib/media-cache.ts
|
|
602
412
|
var CACHE = "fayz-wa-media-v1";
|
|
@@ -777,6 +587,49 @@ function MediaBubble({ m, outbound }) {
|
|
|
777
587
|
legenda ? /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap break-words", children: legenda }) : null
|
|
778
588
|
] });
|
|
779
589
|
}
|
|
590
|
+
function useRecordLinks(conversation) {
|
|
591
|
+
const { recordLinks } = useConversationsConfig();
|
|
592
|
+
const [items, setItems] = React7__default.useState([]);
|
|
593
|
+
const [tick, setTick] = React7__default.useState(0);
|
|
594
|
+
const id = conversation?.id;
|
|
595
|
+
React7__default.useEffect(() => {
|
|
596
|
+
let alive = true;
|
|
597
|
+
if (!conversation || !recordLinks?.length) {
|
|
598
|
+
setItems([]);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
void Promise.all(recordLinks.map(async (source) => {
|
|
602
|
+
try {
|
|
603
|
+
const r = await source.load(conversation);
|
|
604
|
+
return { source, links: r.links ?? [], canAct: !!r.canAct };
|
|
605
|
+
} catch {
|
|
606
|
+
return { source, links: [], canAct: false };
|
|
607
|
+
}
|
|
608
|
+
})).then((loaded) => {
|
|
609
|
+
if (alive) setItems(loaded);
|
|
610
|
+
});
|
|
611
|
+
return () => {
|
|
612
|
+
alive = false;
|
|
613
|
+
};
|
|
614
|
+
}, [id, recordLinks, tick]);
|
|
615
|
+
return { items, reload: React7__default.useCallback(() => setTick((n) => n + 1), []) };
|
|
616
|
+
}
|
|
617
|
+
function RecordLinkChip({ link, className }) {
|
|
618
|
+
return /* @__PURE__ */ jsxs(
|
|
619
|
+
"button",
|
|
620
|
+
{
|
|
621
|
+
type: "button",
|
|
622
|
+
onClick: () => navigateApp(link.href),
|
|
623
|
+
className: cn("inline-flex items-center gap-1.5 rounded-full border border-border bg-background px-2 py-0.5 text-xs font-medium text-foreground transition-colors hover:border-primary/40 hover:bg-accent", className),
|
|
624
|
+
title: link.hint ? `${link.label} \xB7 ${link.hint}` : link.label,
|
|
625
|
+
children: [
|
|
626
|
+
/* @__PURE__ */ jsx(Link2, { className: "h-3 w-3 text-muted-foreground" }),
|
|
627
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: link.label }),
|
|
628
|
+
link.hint && /* @__PURE__ */ jsx(Badge, { variant: link.tone ?? "secondary", className: "px-1.5 py-0 text-[10px]", children: link.hint })
|
|
629
|
+
]
|
|
630
|
+
}
|
|
631
|
+
);
|
|
632
|
+
}
|
|
780
633
|
function recordingMime() {
|
|
781
634
|
if (typeof MediaRecorder === "undefined") return void 0;
|
|
782
635
|
for (const m of ["audio/ogg;codecs=opus", "audio/webm;codecs=opus", "audio/webm", "audio/mp4"]) {
|
|
@@ -787,7 +640,7 @@ function recordingMime() {
|
|
|
787
640
|
function clock(seconds) {
|
|
788
641
|
return `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
|
|
789
642
|
}
|
|
790
|
-
function Composer({ canType, placeholder, sending, onSendText, onSendMedia, clearAssistant = false }) {
|
|
643
|
+
function Composer({ canType, placeholder, sending, onSendText, onSendMedia, clearAssistant = false, onTyping }) {
|
|
791
644
|
const t = useTranslation();
|
|
792
645
|
const [draft, setDraft] = React7.useState("");
|
|
793
646
|
const [file, setFile] = React7.useState(null);
|
|
@@ -926,7 +779,10 @@ function Composer({ canType, placeholder, sending, onSendText, onSendMedia, clea
|
|
|
926
779
|
{
|
|
927
780
|
ref: boxRef,
|
|
928
781
|
value: draft,
|
|
929
|
-
onChange: (e) =>
|
|
782
|
+
onChange: (e) => {
|
|
783
|
+
setDraft(e.target.value);
|
|
784
|
+
onTyping?.(e.target.value);
|
|
785
|
+
},
|
|
930
786
|
onKeyDown: (e) => {
|
|
931
787
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
932
788
|
e.preventDefault();
|
|
@@ -1392,18 +1248,21 @@ function buildRows(messages) {
|
|
|
1392
1248
|
});
|
|
1393
1249
|
return rows;
|
|
1394
1250
|
}
|
|
1395
|
-
function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways, className }) {
|
|
1251
|
+
function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways, before, hideRecordLinks, className }) {
|
|
1396
1252
|
const t = useTranslation();
|
|
1397
1253
|
const { messages, sending, send, sendMedia, setStatus, refreshMessages, markUnread } = useConversationsStore((s) => s);
|
|
1398
|
-
const win = useSendWindow(selected.id, selected.channel === "whatsapp" ? selected.contactHandle : void 0);
|
|
1254
|
+
const win = useSendWindow(selected.id, selected.channel === "whatsapp" ? selected.contactHandle : void 0, selected.channel);
|
|
1399
1255
|
const canType = win.mode.kind === "free";
|
|
1400
1256
|
const threadRef = React7__default.useRef(null);
|
|
1401
1257
|
const contactPhone = selected.channel === "whatsapp" ? selected.contactHandle : null;
|
|
1402
1258
|
const disposition = useContactDisposition(selected.contactPersonId, contactPhone);
|
|
1403
1259
|
const [dispositionAction, setDispositionAction] = React7__default.useState(null);
|
|
1260
|
+
const aoVivo = useConversaAoVivo(selected.id, selected.channel, () => {
|
|
1261
|
+
void refreshMessages();
|
|
1262
|
+
});
|
|
1404
1263
|
React7__default.useEffect(() => {
|
|
1405
1264
|
threadRef.current?.scrollTo({ top: threadRef.current.scrollHeight, behavior: "smooth" });
|
|
1406
|
-
}, [messages.length, selected.id]);
|
|
1265
|
+
}, [messages.length, selected.id, aoVivo.outroDigitando]);
|
|
1407
1266
|
React7__default.useEffect(() => {
|
|
1408
1267
|
if (!selected.id) return;
|
|
1409
1268
|
let timer = null;
|
|
@@ -1427,6 +1286,8 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1427
1286
|
};
|
|
1428
1287
|
}, [selected.id, refreshMessages]);
|
|
1429
1288
|
const accent = channelAccent(selected.channel);
|
|
1289
|
+
const { items: linked } = useRecordLinks(hideRecordLinks ? null : selected);
|
|
1290
|
+
const chips = linked.flatMap((i) => i.links);
|
|
1430
1291
|
const rows = React7__default.useMemo(() => buildRows(messages.filter((m) => !isFoldedRow(m))), [messages]);
|
|
1431
1292
|
const jumpTo = React7__default.useCallback((providerId) => {
|
|
1432
1293
|
const el = threadRef.current?.querySelector(`[data-provider-id="${CSS.escape(providerId)}"]`);
|
|
@@ -1483,7 +1344,8 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1483
1344
|
/* @__PURE__ */ jsx(ChannelBadge, { channel: selected.channel }),
|
|
1484
1345
|
/* @__PURE__ */ jsx("span", { className: "truncate", children: selected.contactHandle })
|
|
1485
1346
|
] })
|
|
1486
|
-
] })
|
|
1347
|
+
] }),
|
|
1348
|
+
chips.slice(0, 2).map((link) => /* @__PURE__ */ jsx(RecordLinkChip, { link, className: "hidden shrink-0 md:inline-flex" }, link.id))
|
|
1487
1349
|
] }),
|
|
1488
1350
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1.5", onClick: (e) => e.stopPropagation(), onKeyDown: (e) => e.stopPropagation(), children: [
|
|
1489
1351
|
/* @__PURE__ */ jsxs(Dropdown, { children: [
|
|
@@ -1519,6 +1381,7 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1519
1381
|
}
|
|
1520
1382
|
),
|
|
1521
1383
|
/* @__PURE__ */ jsxs("div", { ref: threadRef, className: "min-h-0 flex-1 overflow-y-auto px-5 py-4", children: [
|
|
1384
|
+
before,
|
|
1522
1385
|
rows.map((row) => {
|
|
1523
1386
|
if (row.kind === "day") {
|
|
1524
1387
|
return /* @__PURE__ */ jsx("div", { className: "my-3 flex items-center justify-center", children: /* @__PURE__ */ jsx("span", { className: "rounded-full bg-muted px-3 py-0.5 text-[11px] font-medium text-muted-foreground", children: row.label }) }, row.id);
|
|
@@ -1570,7 +1433,8 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1570
1433
|
row.id
|
|
1571
1434
|
);
|
|
1572
1435
|
}),
|
|
1573
|
-
|
|
1436
|
+
aoVivo.outroDigitando && /* @__PURE__ */ jsx("p", { className: "mt-2 text-xs italic text-muted-foreground", "data-testid": "conversation-contact-typing", children: selected.contactName ? `${selected.contactName.split(/\s+/)[0]} est\xE1 digitando\u2026` : "Cliente est\xE1 digitando\u2026" }),
|
|
1437
|
+
rows.length === 0 && !before && /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col items-center justify-center text-muted-foreground", children: [
|
|
1574
1438
|
/* @__PURE__ */ jsx(MessageSquare, { className: "h-7 w-7" }),
|
|
1575
1439
|
/* @__PURE__ */ jsx("p", { className: "mt-2 text-sm", children: t("conversations.thread.empty") })
|
|
1576
1440
|
] })
|
|
@@ -1585,7 +1449,10 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1585
1449
|
sending,
|
|
1586
1450
|
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",
|
|
1587
1451
|
onSendText: (text) => send(text),
|
|
1588
|
-
onSendMedia: (input) => sendMedia(input)
|
|
1452
|
+
onSendMedia: (input) => sendMedia(input),
|
|
1453
|
+
onTyping: (text) => {
|
|
1454
|
+
if (text.trim()) aoVivo.avisar();
|
|
1455
|
+
}
|
|
1589
1456
|
}
|
|
1590
1457
|
)
|
|
1591
1458
|
] })
|
|
@@ -1751,7 +1618,20 @@ function day(iso) {
|
|
|
1751
1618
|
const d = new Date(iso.length === 10 ? `${iso}T12:00:00` : iso);
|
|
1752
1619
|
return Number.isNaN(d.getTime()) ? iso : d.toLocaleDateString("pt-BR");
|
|
1753
1620
|
}
|
|
1754
|
-
function
|
|
1621
|
+
function LinkedRecords({ contact, withActions = true }) {
|
|
1622
|
+
const t = useTranslation();
|
|
1623
|
+
const { items, reload } = useRecordLinks(contact);
|
|
1624
|
+
const links = items.flatMap((i) => i.links);
|
|
1625
|
+
const actions = withActions ? items.filter((i) => i.canAct && i.source.Action) : [];
|
|
1626
|
+
return /* @__PURE__ */ jsx(Section, { title: t("conversations.contact.linkedRecords"), children: /* @__PURE__ */ jsxs("div", { className: "px-3 py-2", children: [
|
|
1627
|
+
links.length > 0 ? /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: links.map((link) => /* @__PURE__ */ jsx(RecordLinkChip, { link }, link.id)) }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("conversations.contact.noLinkedRecords") }),
|
|
1628
|
+
actions.map(({ source }) => {
|
|
1629
|
+
const Action = source.Action;
|
|
1630
|
+
return /* @__PURE__ */ jsx("div", { className: "mt-2", children: /* @__PURE__ */ jsx(Action, { conversation: contact, onDone: reload }) }, source.id);
|
|
1631
|
+
})
|
|
1632
|
+
] }) });
|
|
1633
|
+
}
|
|
1634
|
+
function ContactPanel({ contact, onClose, linkActions = true, className }) {
|
|
1755
1635
|
const t = useTranslation();
|
|
1756
1636
|
const profile = useContactProfile(contact.contactPersonId, contact.contactHandle);
|
|
1757
1637
|
const disposition = useContactDisposition(
|
|
@@ -1779,7 +1659,11 @@ function ContactPanel({ contact, onClose, className }) {
|
|
|
1779
1659
|
] }),
|
|
1780
1660
|
/* @__PURE__ */ jsx(ChannelBadge, { channel: contact.channel })
|
|
1781
1661
|
] }),
|
|
1782
|
-
profile === void 0 && /* @__PURE__ */
|
|
1662
|
+
profile === void 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-2 px-4 pt-4", "aria-busy": "true", "aria-label": t("conversations.profile.loading"), children: [
|
|
1663
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-24" }),
|
|
1664
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-16 w-full" }),
|
|
1665
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-32" })
|
|
1666
|
+
] }),
|
|
1783
1667
|
profile === null && /* @__PURE__ */ jsx("p", { className: "px-4 pt-4 text-xs text-muted-foreground", children: t("conversations.profile.notInCrm") }),
|
|
1784
1668
|
profile && /* @__PURE__ */ jsx(ProfileSections, { profile }),
|
|
1785
1669
|
(disposition.phone || disposition.stopped) && /* @__PURE__ */ jsx(Section, { title: t("conversations.disposition.section"), children: /* @__PURE__ */ jsx(Rows, { rows: [
|
|
@@ -1795,7 +1679,8 @@ function ContactPanel({ contact, onClose, className }) {
|
|
|
1795
1679
|
[t("conversations.contact.leadOwner"), contact.leadOwnerName],
|
|
1796
1680
|
[t("conversations.contact.location"), contact.location],
|
|
1797
1681
|
[t("conversations.contact.note"), contact.note]
|
|
1798
|
-
] }) })
|
|
1682
|
+
] }) }),
|
|
1683
|
+
/* @__PURE__ */ jsx(LinkedRecords, { contact, withActions: linkActions })
|
|
1799
1684
|
] })
|
|
1800
1685
|
);
|
|
1801
1686
|
}
|
|
@@ -1860,304 +1745,7 @@ function ProfileSections({ profile }) {
|
|
|
1860
1745
|
] }, i)) }) })
|
|
1861
1746
|
] });
|
|
1862
1747
|
}
|
|
1863
|
-
var CHANNELS = ["whatsapp", "sms", "instagram", "email", "webchat"];
|
|
1864
|
-
function personHandleFor(channel, contact) {
|
|
1865
|
-
if (!contact) return "";
|
|
1866
|
-
if (channel === "email") return contact.email ?? "";
|
|
1867
|
-
if (channel === "sms" || channel === "whatsapp") return contact.phone ?? "";
|
|
1868
|
-
return "";
|
|
1869
|
-
}
|
|
1870
|
-
var HANDLE_LABEL_KEY = {
|
|
1871
|
-
whatsapp: "conversations.new.handleLabel.phone",
|
|
1872
|
-
sms: "conversations.new.handleLabel.phone",
|
|
1873
|
-
email: "conversations.new.handleLabel.email",
|
|
1874
|
-
instagram: "conversations.new.handleLabel.instagram",
|
|
1875
|
-
webchat: "conversations.new.handleLabel.webchat",
|
|
1876
|
-
support: "conversations.new.handleLabel.email"
|
|
1877
|
-
};
|
|
1878
|
-
function NewConversationPanel({
|
|
1879
|
-
open,
|
|
1880
|
-
onOpenChange
|
|
1881
|
-
}) {
|
|
1882
|
-
const t = useTranslation();
|
|
1883
|
-
const create = useConversationsStore((s) => s.create);
|
|
1884
|
-
const config = useConversationsConfig();
|
|
1885
|
-
const guardConversations = useLimitGuard("conversations_month");
|
|
1886
|
-
const [channel, setChannel] = React7__default.useState("whatsapp");
|
|
1887
|
-
const [contact, setContact] = React7__default.useState(null);
|
|
1888
|
-
const [typedHandle, setTypedHandle] = React7__default.useState("");
|
|
1889
|
-
const [creatingContact, setCreatingContact] = React7__default.useState(false);
|
|
1890
|
-
const [firstMessage, setFirstMessage] = React7__default.useState("");
|
|
1891
|
-
const [submitting, setSubmitting] = React7__default.useState(false);
|
|
1892
|
-
const [pickerKey, setPickerKey] = React7__default.useState(0);
|
|
1893
|
-
React7__default.useEffect(() => {
|
|
1894
|
-
if (open) {
|
|
1895
|
-
setChannel("whatsapp");
|
|
1896
|
-
setContact(null);
|
|
1897
|
-
setTypedHandle("");
|
|
1898
|
-
setCreatingContact(false);
|
|
1899
|
-
setFirstMessage("");
|
|
1900
|
-
setSubmitting(false);
|
|
1901
|
-
setPickerKey((k) => k + 1);
|
|
1902
|
-
}
|
|
1903
|
-
}, [open]);
|
|
1904
|
-
const derivedHandle = personHandleFor(channel, contact);
|
|
1905
|
-
const effectiveHandle = derivedHandle || typedHandle;
|
|
1906
|
-
const handleLabel = t(HANDLE_LABEL_KEY[channel]);
|
|
1907
|
-
const canSubmit = (contact?.name.trim().length ?? 0) > 0 && !submitting;
|
|
1908
|
-
async function handleSubmit(e) {
|
|
1909
|
-
e.preventDefault();
|
|
1910
|
-
if (!canSubmit) return;
|
|
1911
|
-
setSubmitting(true);
|
|
1912
|
-
try {
|
|
1913
|
-
if (await guardConversations() === "blocked") return;
|
|
1914
|
-
await create({
|
|
1915
|
-
channel,
|
|
1916
|
-
contactName: contact.name.trim(),
|
|
1917
|
-
contactPersonId: contact?.id,
|
|
1918
|
-
contactHandle: effectiveHandle.trim() || void 0,
|
|
1919
|
-
firstMessage: firstMessage.trim() || void 0
|
|
1920
|
-
});
|
|
1921
|
-
invalidateLimit("conversations_month");
|
|
1922
|
-
onOpenChange(false);
|
|
1923
|
-
} catch (err) {
|
|
1924
|
-
const message = errorMessage(err);
|
|
1925
|
-
toast.error(t("conversations.new.createFailed"), { description: message });
|
|
1926
|
-
} finally {
|
|
1927
|
-
setSubmitting(false);
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
return /* @__PURE__ */ jsx(Modal, { open, onOpenChange, children: /* @__PURE__ */ jsxs(ModalContent, { className: "max-w-md", children: [
|
|
1931
|
-
/* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(ModalTitle, { children: t("conversations.new.title") }) }),
|
|
1932
|
-
/* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "flex min-h-0 flex-1 flex-col overflow-hidden", children: [
|
|
1933
|
-
/* @__PURE__ */ jsxs(ModalBody, { className: "space-y-4", children: [
|
|
1934
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
1935
|
-
/* @__PURE__ */ jsx("label", { className: "mb-1.5 block text-xs font-medium text-muted-foreground", children: t("conversations.new.channel") }),
|
|
1936
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: CHANNELS.map((ch) => {
|
|
1937
|
-
const Icon = CHANNEL_ICON[ch];
|
|
1938
|
-
const active = channel === ch;
|
|
1939
|
-
return /* @__PURE__ */ jsxs(
|
|
1940
|
-
Button,
|
|
1941
|
-
{
|
|
1942
|
-
variant: "bare",
|
|
1943
|
-
size: "bare",
|
|
1944
|
-
type: "button",
|
|
1945
|
-
onClick: () => setChannel(ch),
|
|
1946
|
-
"aria-pressed": active,
|
|
1947
|
-
className: cn(
|
|
1948
|
-
"inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium transition-colors",
|
|
1949
|
-
active ? "text-white" : "bg-muted text-muted-foreground hover:bg-muted/70"
|
|
1950
|
-
),
|
|
1951
|
-
style: active ? { backgroundColor: CHANNEL_ACCENT[ch].color } : void 0,
|
|
1952
|
-
children: [
|
|
1953
|
-
/* @__PURE__ */ jsx(Icon, { className: "h-3 w-3" }),
|
|
1954
|
-
CHANNEL_LABELS[ch]
|
|
1955
|
-
]
|
|
1956
|
-
},
|
|
1957
|
-
ch
|
|
1958
|
-
);
|
|
1959
|
-
}) })
|
|
1960
|
-
] }),
|
|
1961
|
-
/* @__PURE__ */ jsx(
|
|
1962
|
-
ContactPicker,
|
|
1963
|
-
{
|
|
1964
|
-
value: contact,
|
|
1965
|
-
onChange: setContact,
|
|
1966
|
-
kind: config.contactKind,
|
|
1967
|
-
lookup: config.contactLookup,
|
|
1968
|
-
createEntityDef: config.contactEntityDef,
|
|
1969
|
-
allowFreeText: true,
|
|
1970
|
-
onCreatingChange: setCreatingContact,
|
|
1971
|
-
autoFocus: true,
|
|
1972
|
-
label: t("conversations.new.contactName"),
|
|
1973
|
-
placeholder: t("conversations.new.contactNamePlaceholder"),
|
|
1974
|
-
secondaryText: derivedHandle || void 0,
|
|
1975
|
-
handleField: {
|
|
1976
|
-
label: handleLabel,
|
|
1977
|
-
derived: derivedHandle || void 0,
|
|
1978
|
-
value: typedHandle,
|
|
1979
|
-
onChange: setTypedHandle,
|
|
1980
|
-
fieldLabel: t("conversations.new.handle"),
|
|
1981
|
-
placeholder: t("conversations.new.handlePlaceholder")
|
|
1982
|
-
}
|
|
1983
|
-
},
|
|
1984
|
-
pickerKey
|
|
1985
|
-
),
|
|
1986
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
1987
|
-
/* @__PURE__ */ jsx("label", { htmlFor: "conv-first-message", className: "mb-1.5 block text-xs font-medium text-muted-foreground", children: t("conversations.new.firstMessage") }),
|
|
1988
|
-
/* @__PURE__ */ jsx(
|
|
1989
|
-
Textarea,
|
|
1990
|
-
{
|
|
1991
|
-
id: "conv-first-message",
|
|
1992
|
-
value: firstMessage,
|
|
1993
|
-
onChange: (e) => setFirstMessage(e.target.value),
|
|
1994
|
-
rows: 3,
|
|
1995
|
-
placeholder: t("conversations.new.firstMessagePlaceholder"),
|
|
1996
|
-
className: "max-h-40 min-h-[64px] resize-none rounded-md border-border bg-background shadow-none focus:border-primary focus-visible:ring-0 focus-visible:ring-offset-0"
|
|
1997
|
-
}
|
|
1998
|
-
)
|
|
1999
|
-
] })
|
|
2000
|
-
] }),
|
|
2001
|
-
/* @__PURE__ */ jsx(ModalFooter, { children: /* @__PURE__ */ jsx(Button, { type: "submit", disabled: !canSubmit, className: "w-full", children: submitting ? t("conversations.new.creating") : t("conversations.new.create") }) })
|
|
2002
|
-
] })
|
|
2003
|
-
] }) });
|
|
2004
|
-
}
|
|
2005
|
-
function useCaixaAoVivo() {
|
|
2006
|
-
const tenantId = useActiveTenantId();
|
|
2007
|
-
const load = useConversationsStore((s) => s.load);
|
|
2008
|
-
const refreshMessages = useConversationsStore((s) => s.refreshMessages);
|
|
2009
|
-
const selectedId = useConversationsStore((s) => s.selectedId);
|
|
2010
|
-
const abertoRef = React7.useRef(selectedId);
|
|
2011
|
-
abertoRef.current = selectedId;
|
|
2012
|
-
React7.useEffect(() => {
|
|
2013
|
-
if (!tenantId) return;
|
|
2014
|
-
return assinarChegada(tenantId, ({ conversationId }) => {
|
|
2015
|
-
void load({ autoSelect: false });
|
|
2016
|
-
if (conversationId && conversationId === abertoRef.current) {
|
|
2017
|
-
void refreshMessages();
|
|
2018
|
-
}
|
|
2019
|
-
});
|
|
2020
|
-
}, [tenantId, load, refreshMessages]);
|
|
2021
|
-
}
|
|
2022
|
-
function InboxView({ layout = "page", newSignal = 0 } = {}) {
|
|
2023
|
-
const t = useTranslation();
|
|
2024
|
-
const dock = layout !== "page";
|
|
2025
|
-
const { conversations, selectedId, deselect } = useConversationsStore((s) => s);
|
|
2026
|
-
useCaixaAoVivo();
|
|
2027
|
-
const isWideViewport = useMediaQuery("(min-width: 1280px)");
|
|
2028
|
-
const isWidePanel = isWideViewport && !dock;
|
|
2029
|
-
const railOpen = useRightRailStore((s) => s.open);
|
|
2030
|
-
const [panelOpen, setPanelOpen] = React7__default.useState(false);
|
|
2031
|
-
const [newOpen, setNewOpen] = React7__default.useState(false);
|
|
2032
|
-
const selected = conversations.find((c) => c.id === selectedId) ?? null;
|
|
2033
|
-
React7__default.useEffect(() => {
|
|
2034
|
-
if (newSignal > 0) setNewOpen(true);
|
|
2035
|
-
}, [newSignal]);
|
|
2036
|
-
React7__default.useEffect(() => {
|
|
2037
|
-
setPanelOpen(isWidePanel && !railOpen);
|
|
2038
|
-
}, [isWidePanel, railOpen]);
|
|
2039
|
-
const newActions = React7__default.useMemo(() => [{
|
|
2040
|
-
id: "new-conversation",
|
|
2041
|
-
label: t("conversations.list.new"),
|
|
2042
|
-
icon: SquarePen,
|
|
2043
|
-
intent: "primary",
|
|
2044
|
-
// Starting a conversation creates a thread — the FAB is a "+".
|
|
2045
|
-
creates: true,
|
|
2046
|
-
testId: "conversations-new",
|
|
2047
|
-
permission: { feature: "conversations", action: "create" },
|
|
2048
|
-
onSelect: () => setNewOpen(true)
|
|
2049
|
-
}], [t]);
|
|
2050
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2051
|
-
!dock && /* @__PURE__ */ jsx(PageHeaderActions, { children: /* @__PURE__ */ jsx(PageActions, { actions: newActions }) }),
|
|
2052
|
-
/* @__PURE__ */ jsx(NewConversationPanel, { open: newOpen, onOpenChange: setNewOpen }),
|
|
2053
|
-
/* @__PURE__ */ jsxs("div", { className: "relative flex h-full min-h-0 overflow-hidden bg-background", children: [
|
|
2054
|
-
/* @__PURE__ */ jsx(ConversationList, { className: cn(
|
|
2055
|
-
layout === "page" && (selected ? "hidden lg:flex" : "flex"),
|
|
2056
|
-
layout === "dock" && (selected ? "hidden" : "flex lg:w-full border-r-0"),
|
|
2057
|
-
layout === "dock-wide" && "flex lg:w-[300px]"
|
|
2058
|
-
) }),
|
|
2059
|
-
selected ? /* @__PURE__ */ jsx(
|
|
2060
|
-
MessageThread,
|
|
2061
|
-
{
|
|
2062
|
-
selected,
|
|
2063
|
-
panelOpen,
|
|
2064
|
-
onTogglePanel: () => setPanelOpen((v) => !v),
|
|
2065
|
-
onBack: deselect,
|
|
2066
|
-
backAlways: layout === "dock",
|
|
2067
|
-
className: "flex"
|
|
2068
|
-
}
|
|
2069
|
-
) : layout === "dock" ? null : /* @__PURE__ */ jsxs("section", { className: cn("min-w-0 flex-1 flex-col items-center justify-center bg-muted/20 text-muted-foreground", dock ? "flex" : "hidden lg:flex"), children: [
|
|
2070
|
-
/* @__PURE__ */ jsx(MessageSquare, { className: "h-9 w-9" }),
|
|
2071
|
-
/* @__PURE__ */ jsx("p", { className: "mt-2 text-sm", children: t("conversations.empty.select") })
|
|
2072
|
-
] }),
|
|
2073
|
-
selected && panelOpen && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2074
|
-
/* @__PURE__ */ jsx(
|
|
2075
|
-
Button,
|
|
2076
|
-
{
|
|
2077
|
-
variant: "bare",
|
|
2078
|
-
size: "bare",
|
|
2079
|
-
className: cn("absolute inset-0 z-10 rounded-none bg-black/40", !dock && "xl:hidden"),
|
|
2080
|
-
"aria-label": "Close details",
|
|
2081
|
-
onClick: () => setPanelOpen(false)
|
|
2082
|
-
}
|
|
2083
|
-
),
|
|
2084
|
-
/* @__PURE__ */ jsx(
|
|
2085
|
-
ContactPanel,
|
|
2086
|
-
{
|
|
2087
|
-
contact: selected,
|
|
2088
|
-
onClose: () => setPanelOpen(false),
|
|
2089
|
-
className: cn("absolute inset-y-0 right-0 z-20 w-[340px] max-w-[88%] shadow-2xl", !dock && "xl:static xl:z-auto xl:w-[300px] xl:max-w-none xl:bg-muted/20 xl:shadow-none")
|
|
2090
|
-
}
|
|
2091
|
-
)
|
|
2092
|
-
] })
|
|
2093
|
-
] })
|
|
2094
|
-
] });
|
|
2095
|
-
}
|
|
2096
|
-
var CHANNELS2 = ["sms", "whatsapp", "instagram", "email", "webchat"];
|
|
2097
|
-
function requestedContact() {
|
|
2098
|
-
try {
|
|
2099
|
-
const hash = currentAppPath();
|
|
2100
|
-
const qs = hash.includes("?") ? hash.slice(hash.indexOf("?") + 1) : "";
|
|
2101
|
-
if (!qs) return null;
|
|
2102
|
-
const p = new URLSearchParams(qs);
|
|
2103
|
-
const handle = (p.get("handle") ?? "").trim();
|
|
2104
|
-
const name = (p.get("name") ?? "").trim();
|
|
2105
|
-
const personId = (p.get("personId") ?? "").trim() || void 0;
|
|
2106
|
-
if (!handle) return null;
|
|
2107
|
-
const raw = (p.get("channel") ?? "whatsapp").toLowerCase();
|
|
2108
|
-
const channel = CHANNELS2.includes(raw) ? raw : "whatsapp";
|
|
2109
|
-
return { personId, name: name || handle, handle, channel };
|
|
2110
|
-
} catch {
|
|
2111
|
-
return null;
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
function conversationIdFromPath(path) {
|
|
2115
|
-
const m = /^\/conversations\/([^/?#]+)/.exec(path);
|
|
2116
|
-
return m ? decodeURIComponent(m[1]) : null;
|
|
2117
|
-
}
|
|
2118
|
-
function ConversationsPage({ store, config }) {
|
|
2119
|
-
React7__default.useEffect(() => {
|
|
2120
|
-
const wanted = requestedContact();
|
|
2121
|
-
if (!wanted) {
|
|
2122
|
-
const fromPath = conversationIdFromPath(currentAppPath());
|
|
2123
|
-
if (fromPath) store.setState({ selectedId: fromPath });
|
|
2124
|
-
void store.getState().load();
|
|
2125
|
-
return;
|
|
2126
|
-
}
|
|
2127
|
-
void store.getState().openForPerson(wanted).catch(() => {
|
|
2128
|
-
void store.getState().load();
|
|
2129
|
-
});
|
|
2130
|
-
try {
|
|
2131
|
-
const hash = currentAppPath();
|
|
2132
|
-
const clean = hash.includes("?") ? hash.slice(0, hash.indexOf("?")) : hash;
|
|
2133
|
-
window.history.replaceState(null, "", appHref(clean || "/conversations"));
|
|
2134
|
-
} catch {
|
|
2135
|
-
}
|
|
2136
|
-
}, []);
|
|
2137
|
-
React7__default.useEffect(() => {
|
|
2138
|
-
const write = (id) => {
|
|
2139
|
-
const path = currentAppPath();
|
|
2140
|
-
if (!path.startsWith("/conversations")) return;
|
|
2141
|
-
if (path.includes("?")) return;
|
|
2142
|
-
if (conversationIdFromPath(path) === id) return;
|
|
2143
|
-
replaceApp(id ? `/conversations/${encodeURIComponent(id)}` : "/conversations");
|
|
2144
|
-
};
|
|
2145
|
-
write(store.getState().selectedId);
|
|
2146
|
-
const unsubscribe = store.subscribe((state, previous) => {
|
|
2147
|
-
if (state.selectedId !== previous.selectedId) write(state.selectedId);
|
|
2148
|
-
});
|
|
2149
|
-
const off = onAppPathChange((path) => {
|
|
2150
|
-
const id = conversationIdFromPath(path || "/");
|
|
2151
|
-
if (id && id !== store.getState().selectedId) void store.getState().select(id);
|
|
2152
|
-
});
|
|
2153
|
-
return () => {
|
|
2154
|
-
unsubscribe();
|
|
2155
|
-
off();
|
|
2156
|
-
};
|
|
2157
|
-
}, [store]);
|
|
2158
|
-
return /* @__PURE__ */ jsx(ConversationsContextProvider, { store, config, children: /* @__PURE__ */ jsx(InboxView, {}) });
|
|
2159
|
-
}
|
|
2160
1748
|
|
|
2161
|
-
export {
|
|
2162
|
-
//# sourceMappingURL=
|
|
2163
|
-
//# sourceMappingURL=
|
|
1749
|
+
export { Avatar, CHANNEL_ACCENT, CHANNEL_ICON, ChannelBadge, ContactPanel, MessageThread, relativeTime, useMediaQuery };
|
|
1750
|
+
//# sourceMappingURL=chunk-KTYFNZ2V.js.map
|
|
1751
|
+
//# sourceMappingURL=chunk-KTYFNZ2V.js.map
|