@fayz-ai/plugin-conversations 0.32.0-canary.20261028142749 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CampaignsSurface-5XQSH5CZ.js → CampaignsSurface-2LT24KSS.js} +78 -39
- package/dist/CampaignsSurface-2LT24KSS.js.map +1 -0
- package/dist/{chunk-JZZ3D3SP.js → ConversationsPage-C6FMGA72.js} +670 -288
- package/dist/ConversationsPage-C6FMGA72.js.map +1 -0
- package/dist/{ConversationsSettings-4UUJD6IC.js → ConversationsSettings-GORCWUHD.js} +5 -6
- package/dist/ConversationsSettings-GORCWUHD.js.map +1 -0
- package/dist/{TemplatesSurface-AI2HXALZ.js → TemplatesSurface-D6UMF5XE.js} +3 -3
- package/dist/{TemplatesSurface-AI2HXALZ.js.map → TemplatesSurface-D6UMF5XE.js.map} +1 -1
- package/dist/{chunk-GDB5UCPB.js → chunk-HAIIYFKK.js} +6 -2
- package/dist/chunk-HAIIYFKK.js.map +1 -0
- package/dist/{chunk-R65GJLBC.js → chunk-W5VV6G35.js} +16 -4
- package/dist/chunk-W5VV6G35.js.map +1 -0
- package/dist/{chunk-DFA42ZEP.js → chunk-XOMWIVPC.js} +36 -38
- package/dist/chunk-XOMWIVPC.js.map +1 -0
- package/dist/components/Composer.d.ts +1 -3
- package/dist/components/Composer.d.ts.map +1 -1
- package/dist/context.d.ts +0 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/data/accents.d.ts.map +1 -1
- package/dist/data/journeys.d.ts +13 -0
- package/dist/data/journeys.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 +0 -6
- package/dist/data/types.d.ts.map +1 -1
- package/dist/index.d.ts +0 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +486 -42
- package/dist/index.js.map +1 -1
- package/dist/lib/channel.d.ts +5 -0
- package/dist/lib/channel.d.ts.map +1 -1
- package/dist/lib/onboarding.d.ts +4 -3
- package/dist/lib/onboarding.d.ts.map +1 -1
- 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 +0 -2
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/main.browser.js +1 -3
- package/dist/migrations/main.browser.js.map +1 -1
- package/dist/migrations/main.js +2 -191
- 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 +0 -6
- package/dist/store.d.ts.map +1 -1
- package/dist/types.d.ts +0 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/views/CampaignsView.d.ts.map +1 -1
- package/dist/views/ContactPanel.d.ts +1 -3
- package/dist/views/ContactPanel.d.ts.map +1 -1
- package/dist/views/ConversationList.d.ts.map +1 -1
- package/dist/views/ConversationsPage.d.ts +1 -6
- package/dist/views/ConversationsPage.d.ts.map +1 -1
- package/dist/views/MessageInspector.d.ts.map +1 -1
- package/dist/views/MessageThread.d.ts +1 -7
- package/dist/views/MessageThread.d.ts.map +1 -1
- package/dist/views/NewConversationPanel.d.ts.map +1 -1
- package/dist/views/SendWindow.d.ts +1 -2
- package/dist/views/SendWindow.d.ts.map +1 -1
- package/dist/views/TemplatesView.d.ts.map +1 -1
- package/dist/views/campaigns/CampaignWizard.d.ts.map +1 -1
- package/dist/views/campaigns/CampaignsSurface.d.ts.map +1 -1
- package/dist/views/campaigns/OfficialBalance.d.ts +5 -0
- package/dist/views/campaigns/OfficialBalance.d.ts.map +1 -0
- package/package.json +4 -4
- package/dist/CampaignsSurface-5XQSH5CZ.js.map +0 -1
- package/dist/ConversationThreadSurface-N2WL2LV3.js +0 -111
- package/dist/ConversationThreadSurface-N2WL2LV3.js.map +0 -1
- package/dist/ConversationsPage-R45MSX53.js +0 -587
- package/dist/ConversationsPage-R45MSX53.js.map +0 -1
- package/dist/ConversationsSettings-4UUJD6IC.js.map +0 -1
- package/dist/chunk-D5LCYNUN.js +0 -500
- package/dist/chunk-D5LCYNUN.js.map +0 -1
- package/dist/chunk-DFA42ZEP.js.map +0 -1
- package/dist/chunk-GDB5UCPB.js.map +0 -1
- package/dist/chunk-IH7XSR4A.js +0 -13
- package/dist/chunk-IH7XSR4A.js.map +0 -1
- package/dist/chunk-JZZ3D3SP.js.map +0 -1
- package/dist/chunk-R65GJLBC.js.map +0 -1
- package/dist/lib/ao-vivo.d.ts +0 -32
- package/dist/lib/ao-vivo.d.ts.map +0 -1
- package/dist/lib/runtime.d.ts +0 -10
- package/dist/lib/runtime.d.ts.map +0 -1
- package/dist/views/ConversationThreadSurface.d.ts +0 -12
- package/dist/views/ConversationThreadSurface.d.ts.map +0 -1
- package/dist/views/RecordLinks.d.ts +0 -53
- package/dist/views/RecordLinks.d.ts.map +0 -1
- package/dist/views/useConversaAoVivo.d.ts +0 -17
- package/dist/views/useConversaAoVivo.d.ts.map +0 -1
|
@@ -1,13 +1,361 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, MessagePreview, mediaPreviewKind } from './chunk-XOMWIVPC.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 {
|
|
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';
|
|
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';
|
|
9
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
var CHANNEL_ICON = {
|
|
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 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
|
+
var FILTERS = ["all", "whatsapp", "instagram", "email"];
|
|
171
|
+
function ConversationList({ className }) {
|
|
172
|
+
const t = useTranslation();
|
|
173
|
+
const connected = useChannelConnections();
|
|
174
|
+
const {
|
|
175
|
+
conversations,
|
|
176
|
+
selectedId,
|
|
177
|
+
channelFilter,
|
|
178
|
+
leadOwnerFilter,
|
|
179
|
+
search,
|
|
180
|
+
loading,
|
|
181
|
+
select,
|
|
182
|
+
markRead,
|
|
183
|
+
setChannelFilter,
|
|
184
|
+
setLeadOwnerFilter,
|
|
185
|
+
setSearch
|
|
186
|
+
} = useConversationsStore((s) => s);
|
|
187
|
+
const [archived, setArchived] = React7__default.useState(false);
|
|
188
|
+
const shown = React7__default.useMemo(
|
|
189
|
+
() => conversations.filter((c) => archived ? c.status === "closed" : c.status !== "closed"),
|
|
190
|
+
[conversations, archived]
|
|
191
|
+
);
|
|
192
|
+
const donos = React7__default.useMemo(() => {
|
|
193
|
+
const vistos = /* @__PURE__ */ new Map();
|
|
194
|
+
for (const c of conversations) {
|
|
195
|
+
if (c.leadOwnerId) vistos.set(c.leadOwnerId, c.leadOwnerName ?? c.leadOwnerId);
|
|
196
|
+
}
|
|
197
|
+
return [...vistos].map(([value, label]) => ({ value, label }));
|
|
198
|
+
}, [conversations]);
|
|
199
|
+
return /* @__PURE__ */ jsxs("aside", { className: cn("w-full shrink-0 flex-col border-r border-border bg-card lg:w-[320px]", className), children: [
|
|
200
|
+
/* @__PURE__ */ jsxs("div", { className: "border-b border-border px-3 py-3", children: [
|
|
201
|
+
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
202
|
+
/* @__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" }),
|
|
203
|
+
/* @__PURE__ */ jsx(
|
|
204
|
+
Input,
|
|
205
|
+
{
|
|
206
|
+
value: search,
|
|
207
|
+
onChange: (e) => setSearch(e.target.value),
|
|
208
|
+
placeholder: t("conversations.list.search"),
|
|
209
|
+
className: "pl-8"
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
] }),
|
|
213
|
+
/* @__PURE__ */ jsx("div", { className: "mt-2 flex flex-wrap gap-1", children: FILTERS.map((id) => {
|
|
214
|
+
const off = id !== "all" && connected !== void 0 && !connected[id];
|
|
215
|
+
return /* @__PURE__ */ jsx(
|
|
216
|
+
Button,
|
|
217
|
+
{
|
|
218
|
+
variant: "bare",
|
|
219
|
+
size: "bare",
|
|
220
|
+
onClick: () => setChannelFilter(id),
|
|
221
|
+
title: off ? t("conversations.filter.notConnected") : void 0,
|
|
222
|
+
className: cn(
|
|
223
|
+
"rounded-full border px-2.5 py-1 text-xs font-medium transition-colors",
|
|
224
|
+
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"
|
|
225
|
+
),
|
|
226
|
+
children: t(`conversations.filter.${id}`)
|
|
227
|
+
},
|
|
228
|
+
id
|
|
229
|
+
);
|
|
230
|
+
}) }),
|
|
231
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-2 flex flex-wrap items-center gap-1", children: [
|
|
232
|
+
donos.length > 0 && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
233
|
+
FilterChip,
|
|
234
|
+
{
|
|
235
|
+
label: t("conversations.contact.leadOwner"),
|
|
236
|
+
icon: User,
|
|
237
|
+
allLabel: t("conversations.filter.anyOwner"),
|
|
238
|
+
options: [{ value: "none", label: t("conversations.filter.noOwner") }, ...donos],
|
|
239
|
+
value: leadOwnerFilter,
|
|
240
|
+
onChange: (v) => {
|
|
241
|
+
void setLeadOwnerFilter(v);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
) }),
|
|
245
|
+
/* @__PURE__ */ jsxs(
|
|
246
|
+
Button,
|
|
247
|
+
{
|
|
248
|
+
variant: "bare",
|
|
249
|
+
size: "bare",
|
|
250
|
+
type: "button",
|
|
251
|
+
"aria-pressed": archived,
|
|
252
|
+
onClick: () => setArchived((v) => !v),
|
|
253
|
+
className: cn(
|
|
254
|
+
"inline-flex items-center gap-1 rounded-full border px-2.5 py-1 text-xs font-medium transition-colors",
|
|
255
|
+
archived ? "border-transparent bg-primary text-primary-foreground" : "border-transparent bg-muted text-muted-foreground hover:bg-muted/70"
|
|
256
|
+
),
|
|
257
|
+
children: [
|
|
258
|
+
/* @__PURE__ */ jsx(Archive, { className: "h-3 w-3" }),
|
|
259
|
+
" ",
|
|
260
|
+
t("conversations.filter.archived")
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
)
|
|
264
|
+
] })
|
|
265
|
+
] }),
|
|
266
|
+
/* @__PURE__ */ jsxs("div", { className: "min-h-0 flex-1 overflow-y-auto", children: [
|
|
267
|
+
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: [
|
|
268
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-10 shrink-0 rounded-full" }),
|
|
269
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
270
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
271
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-28" }),
|
|
272
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-8" })
|
|
273
|
+
] }),
|
|
274
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "mt-1.5 h-4 w-16 rounded-full" }),
|
|
275
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "mt-1.5 h-3 w-3/4" })
|
|
276
|
+
] })
|
|
277
|
+
] }, i)),
|
|
278
|
+
!loading && shown.length === 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 p-8 text-center text-muted-foreground", children: [
|
|
279
|
+
/* @__PURE__ */ jsx(Inbox, { className: "h-6 w-6" }),
|
|
280
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm", children: archived ? t("conversations.list.emptyArchived") : t("conversations.list.empty") })
|
|
281
|
+
] }),
|
|
282
|
+
shown.map((c) => {
|
|
283
|
+
const active = c.id === selectedId;
|
|
284
|
+
const unread = isWaitingOnUs(c);
|
|
285
|
+
return (
|
|
286
|
+
// `div` em volta e não um botão dentro de outro: HTML não permite
|
|
287
|
+
// aninhar, e o navegador resolve isso silenciosamente movendo o
|
|
288
|
+
// interno para fora — a linha inteira deixa de ser clicável e
|
|
289
|
+
// ninguém entende por quê.
|
|
290
|
+
/* @__PURE__ */ jsxs("div", { className: "group relative", children: [
|
|
291
|
+
/* @__PURE__ */ jsxs(
|
|
292
|
+
Button,
|
|
293
|
+
{
|
|
294
|
+
variant: "bare",
|
|
295
|
+
size: "bare",
|
|
296
|
+
onClick: () => select(c.id),
|
|
297
|
+
className: cn(
|
|
298
|
+
"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",
|
|
299
|
+
// Um TOM da cor de marca, e não `bg-accent`.
|
|
300
|
+
//
|
|
301
|
+
// `bg-accent` resolve para quase preto neste tema, e a linha da
|
|
302
|
+
// conversa aberta ficava escura sobre escura. Trocar junto o
|
|
303
|
+
// `text-accent-foreground` deixava legível, mas pintava de
|
|
304
|
+
// preto a única linha que se está a ler — chamava mais atenção
|
|
305
|
+
// que a conversa.
|
|
306
|
+
//
|
|
307
|
+
// `bg-primary/10` é um véu: o texto continua com as cores dele,
|
|
308
|
+
// a seleção se lê como seleção e não como bloco, e funciona nos
|
|
309
|
+
// dois temas porque não presume nada sobre o fundo.
|
|
310
|
+
active ? "bg-primary/10" : "hover:bg-muted/50"
|
|
311
|
+
),
|
|
312
|
+
children: [
|
|
313
|
+
/* @__PURE__ */ jsx(Avatar, { name: c.contactName, accent: c.accent, channel: c.channel }),
|
|
314
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
315
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
316
|
+
/* @__PURE__ */ jsx("span", { className: cn("truncate text-sm text-foreground", unread ? "font-semibold" : "font-medium"), children: c.contactName }),
|
|
317
|
+
/* @__PURE__ */ jsx("span", { className: cn("shrink-0 text-[11px]", unread ? "font-semibold text-primary" : "text-muted-foreground"), children: relativeTime(c.lastMessageAt) })
|
|
318
|
+
] }),
|
|
319
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-2", children: [
|
|
320
|
+
/* @__PURE__ */ jsx(ChannelBadge, { channel: c.channel }),
|
|
321
|
+
c.status !== "open" && /* @__PURE__ */ jsx("span", { className: "text-[10px] uppercase tracking-wide text-muted-foreground/70", children: t(`conversations.status.${c.status}`) }),
|
|
322
|
+
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: [
|
|
323
|
+
/* @__PURE__ */ jsx(User, { className: "h-2.5 w-2.5" }),
|
|
324
|
+
c.leadOwnerName.split(" ")[0]
|
|
325
|
+
] })
|
|
326
|
+
] }),
|
|
327
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center justify-between gap-2", children: [
|
|
328
|
+
/* @__PURE__ */ jsx("span", { className: cn("truncate text-xs", unread ? "text-foreground" : "text-muted-foreground"), children: /* @__PURE__ */ jsx(MessagePreview, { text: c.lastMessagePreview }) }),
|
|
329
|
+
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" })
|
|
330
|
+
] })
|
|
331
|
+
] })
|
|
332
|
+
]
|
|
333
|
+
}
|
|
334
|
+
),
|
|
335
|
+
unread && /* @__PURE__ */ jsx(
|
|
336
|
+
Button,
|
|
337
|
+
{
|
|
338
|
+
variant: "bare",
|
|
339
|
+
size: "bare",
|
|
340
|
+
type: "button",
|
|
341
|
+
title: t("conversations.markRead"),
|
|
342
|
+
"aria-label": t("conversations.markRead"),
|
|
343
|
+
onClick: (e) => {
|
|
344
|
+
e.stopPropagation();
|
|
345
|
+
void markRead(c.id);
|
|
346
|
+
},
|
|
347
|
+
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",
|
|
348
|
+
children: /* @__PURE__ */ jsx(CheckCheck, { className: "h-3.5 w-3.5" })
|
|
349
|
+
}
|
|
350
|
+
)
|
|
351
|
+
] }, c.id)
|
|
352
|
+
);
|
|
353
|
+
})
|
|
354
|
+
] }),
|
|
355
|
+
/* @__PURE__ */ jsx(WhatsAppConnectionFooter, {})
|
|
356
|
+
] });
|
|
357
|
+
}
|
|
358
|
+
function useSendWindow(conversationId) {
|
|
11
359
|
const [row, setRow] = React7__default.useState(null);
|
|
12
360
|
const [providers, setProviders] = React7__default.useState(null);
|
|
13
361
|
React7__default.useEffect(() => {
|
|
@@ -43,7 +391,6 @@ function useSendWindow(conversationId, channel) {
|
|
|
43
391
|
}, [conversationId]);
|
|
44
392
|
const provider = (providers ?? []).find((p) => p.isActive);
|
|
45
393
|
const mode = React7__default.useMemo(() => {
|
|
46
|
-
if (channel === "support") return { kind: "free", until: null, minutesLeft: null };
|
|
47
394
|
if (!provider) return { kind: "blocked", reason: "no_provider" };
|
|
48
395
|
if (!provider.capabilities?.requires_template) {
|
|
49
396
|
return { kind: "free", until: null, minutesLeft: null };
|
|
@@ -52,8 +399,8 @@ function useSendWindow(conversationId, channel) {
|
|
|
52
399
|
return { kind: "free", until: row.window_expires_at, minutesLeft: row.minutes_left };
|
|
53
400
|
}
|
|
54
401
|
return { kind: "template", reason: row?.last_inbound_at ? "window_closed" : "never_replied" };
|
|
55
|
-
}, [row, provider
|
|
56
|
-
return { loading:
|
|
402
|
+
}, [row, provider]);
|
|
403
|
+
return { loading: providers === null, mode, provider };
|
|
57
404
|
}
|
|
58
405
|
function humanLeft(minutes) {
|
|
59
406
|
if (minutes == null) return "";
|
|
@@ -102,7 +449,6 @@ var STATUS = {
|
|
|
102
449
|
var BAD = /* @__PURE__ */ new Set(["failed", "expired", "cancelled", "opted_out", "delivery_timeout"]);
|
|
103
450
|
function isFailed(m) {
|
|
104
451
|
if (m.direction !== "outbound") return false;
|
|
105
|
-
if (m.channel === "support") return false;
|
|
106
452
|
if (m.deliveryStatus) return BAD.has(m.deliveryStatus);
|
|
107
453
|
if (m.providerMessageId) return false;
|
|
108
454
|
const age = Date.now() - new Date(m.at).getTime();
|
|
@@ -195,192 +541,6 @@ function MessageMenu({ m }) {
|
|
|
195
541
|
] }) })
|
|
196
542
|
] });
|
|
197
543
|
}
|
|
198
|
-
var CHANNEL_ICON = {
|
|
199
|
-
sms: Phone,
|
|
200
|
-
whatsapp: MessageSquare,
|
|
201
|
-
instagram: Instagram,
|
|
202
|
-
email: Mail,
|
|
203
|
-
webchat: Globe,
|
|
204
|
-
support: LifeBuoy
|
|
205
|
-
};
|
|
206
|
-
var CHANNEL_ACCENT = {
|
|
207
|
-
whatsapp: { color: "#22c55e", badge: "bg-[#22c55e]/12 text-[#15803d] dark:text-[#4ade80]" },
|
|
208
|
-
sms: { color: "#6366f1", badge: "bg-[#6366f1]/12 text-[#4338ca] dark:text-[#a5b4fc]" },
|
|
209
|
-
instagram: { color: "#ec4899", badge: "bg-[#ec4899]/12 text-[#be185d] dark:text-[#f9a8d4]" },
|
|
210
|
-
email: { color: "#0ea5e9", badge: "bg-[#0ea5e9]/12 text-[#0369a1] dark:text-[#7dd3fc]" },
|
|
211
|
-
webchat: { color: "#f59e0b", badge: "bg-[#f59e0b]/12 text-[#b45309] dark:text-[#fcd34d]" },
|
|
212
|
-
support: { color: "#8b5cf6", badge: "bg-[#8b5cf6]/12 text-[#6d28d9] dark:text-[#c4b5fd]" }
|
|
213
|
-
};
|
|
214
|
-
var REGISTRO = /* @__PURE__ */ Symbol.for("fayz.conversa-ao-vivo");
|
|
215
|
-
var EVENTOS = ["message", "changed", "typing", "chat"];
|
|
216
|
-
function registro() {
|
|
217
|
-
const g = globalThis;
|
|
218
|
-
return g[REGISTRO] ?? (g[REGISTRO] = /* @__PURE__ */ new Map());
|
|
219
|
-
}
|
|
220
|
-
var topicoDaConversa = (conversationId) => `conversa:${conversationId}`;
|
|
221
|
-
function ouvirConversa(conversationId, ouvinte) {
|
|
222
|
-
const supabase = getSupabaseClientOptional();
|
|
223
|
-
if (!supabase?.channel || !conversationId) return () => {
|
|
224
|
-
};
|
|
225
|
-
const topico = topicoDaConversa(conversationId);
|
|
226
|
-
const reg = registro();
|
|
227
|
-
let e = reg.get(topico);
|
|
228
|
-
if (!e) {
|
|
229
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
230
|
-
let channel = supabase.channel(topico, { config: { broadcast: { self: false } } });
|
|
231
|
-
for (const ev of EVENTOS) {
|
|
232
|
-
channel = channel.on("broadcast", { event: ev }, (msg) => {
|
|
233
|
-
const evento = { event: ev, payload: msg?.payload ?? {} };
|
|
234
|
-
for (const f of [...listeners]) {
|
|
235
|
-
try {
|
|
236
|
-
f(evento);
|
|
237
|
-
} catch {
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
channel.subscribe();
|
|
243
|
-
e = { channel, listeners };
|
|
244
|
-
reg.set(topico, e);
|
|
245
|
-
}
|
|
246
|
-
e.listeners.add(ouvinte);
|
|
247
|
-
return () => {
|
|
248
|
-
const atual = reg.get(topico);
|
|
249
|
-
if (!atual) return;
|
|
250
|
-
atual.listeners.delete(ouvinte);
|
|
251
|
-
if (atual.listeners.size === 0) {
|
|
252
|
-
reg.delete(topico);
|
|
253
|
-
void getSupabaseClientOptional()?.removeChannel?.(atual.channel);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
function avisarDigitando(conversationId, from) {
|
|
258
|
-
const e = registro().get(topicoDaConversa(conversationId));
|
|
259
|
-
if (!e) return;
|
|
260
|
-
try {
|
|
261
|
-
void e.channel.send({ type: "broadcast", event: "typing", payload: { from } });
|
|
262
|
-
} catch {
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
function conversaAoVivo(channel) {
|
|
266
|
-
return channel === "support" || channel === "webchat";
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// src/views/useConversaAoVivo.ts
|
|
270
|
-
var MOSTRA_MS = 4e3;
|
|
271
|
-
var AVISA_A_CADA_MS = 2e3;
|
|
272
|
-
function useConversaAoVivo(conversationId, channel, aoMudar) {
|
|
273
|
-
const ativo = !!conversationId && conversaAoVivo(channel);
|
|
274
|
-
const [outroDigitando, setOutroDigitando] = React7.useState(false);
|
|
275
|
-
const ultimo = React7.useRef(0);
|
|
276
|
-
const timer = React7.useRef(null);
|
|
277
|
-
const mudou = React7.useRef(aoMudar);
|
|
278
|
-
mudou.current = aoMudar;
|
|
279
|
-
React7.useEffect(() => {
|
|
280
|
-
setOutroDigitando(false);
|
|
281
|
-
if (!ativo || !conversationId) return;
|
|
282
|
-
const sair = ouvirConversa(conversationId, (e) => {
|
|
283
|
-
if (e.event === "typing") {
|
|
284
|
-
if (e.payload.from !== "customer") return;
|
|
285
|
-
setOutroDigitando(true);
|
|
286
|
-
if (timer.current) clearTimeout(timer.current);
|
|
287
|
-
timer.current = setTimeout(() => setOutroDigitando(false), MOSTRA_MS);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
if (e.event === "message" && e.payload.direction === "inbound") setOutroDigitando(false);
|
|
291
|
-
if (e.event === "message" || e.event === "changed") mudou.current();
|
|
292
|
-
});
|
|
293
|
-
return () => {
|
|
294
|
-
sair();
|
|
295
|
-
if (timer.current) clearTimeout(timer.current);
|
|
296
|
-
};
|
|
297
|
-
}, [ativo, conversationId]);
|
|
298
|
-
const avisar = React7.useCallback(() => {
|
|
299
|
-
if (!ativo || !conversationId) return;
|
|
300
|
-
const agora = Date.now();
|
|
301
|
-
if (agora - ultimo.current < AVISA_A_CADA_MS) return;
|
|
302
|
-
ultimo.current = agora;
|
|
303
|
-
avisarDigitando(conversationId, "agent");
|
|
304
|
-
}, [ativo, conversationId]);
|
|
305
|
-
return { outroDigitando: ativo && outroDigitando, avisar };
|
|
306
|
-
}
|
|
307
|
-
function useMediaQuery(query) {
|
|
308
|
-
const [matches, setMatches] = React7__default.useState(
|
|
309
|
-
() => typeof window !== "undefined" && window.matchMedia(query).matches
|
|
310
|
-
);
|
|
311
|
-
React7__default.useEffect(() => {
|
|
312
|
-
if (typeof window === "undefined") return;
|
|
313
|
-
const mql = window.matchMedia(query);
|
|
314
|
-
const onChange = () => setMatches(mql.matches);
|
|
315
|
-
onChange();
|
|
316
|
-
mql.addEventListener("change", onChange);
|
|
317
|
-
return () => mql.removeEventListener("change", onChange);
|
|
318
|
-
}, [query]);
|
|
319
|
-
return matches;
|
|
320
|
-
}
|
|
321
|
-
function initialsOf(name) {
|
|
322
|
-
return name.replace("@", "").split(/\s+/).filter(Boolean).map((w) => w[0]).slice(0, 2).join("").toUpperCase();
|
|
323
|
-
}
|
|
324
|
-
function Avatar({ name, accent, size = "md", channel }) {
|
|
325
|
-
const dims = size === "lg" ? "h-14 w-14 text-lg" : size === "sm" ? "h-9 w-9 text-xs" : "h-10 w-10 text-sm";
|
|
326
|
-
const Icon = channel ? CHANNEL_ICON[channel] : null;
|
|
327
|
-
return /* @__PURE__ */ jsxs("div", { className: "relative shrink-0", children: [
|
|
328
|
-
/* @__PURE__ */ jsx(
|
|
329
|
-
"div",
|
|
330
|
-
{
|
|
331
|
-
className: cn("flex items-center justify-center rounded-full font-semibold text-white", dims),
|
|
332
|
-
style: { backgroundColor: accent },
|
|
333
|
-
children: initialsOf(name)
|
|
334
|
-
}
|
|
335
|
-
),
|
|
336
|
-
Icon && /* @__PURE__ */ jsx(
|
|
337
|
-
"span",
|
|
338
|
-
{
|
|
339
|
-
className: "absolute -bottom-0.5 -right-0.5 flex h-4 w-4 items-center justify-center rounded-full ring-2 ring-card",
|
|
340
|
-
style: { backgroundColor: CHANNEL_ACCENT[channel].color },
|
|
341
|
-
children: /* @__PURE__ */ jsx(Icon, { className: "h-2.5 w-2.5 text-white" })
|
|
342
|
-
}
|
|
343
|
-
)
|
|
344
|
-
] });
|
|
345
|
-
}
|
|
346
|
-
function ChannelBadge({ channel, className }) {
|
|
347
|
-
const Icon = CHANNEL_ICON[channel];
|
|
348
|
-
return /* @__PURE__ */ jsxs(
|
|
349
|
-
"span",
|
|
350
|
-
{
|
|
351
|
-
className: cn(
|
|
352
|
-
"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[10px] font-medium",
|
|
353
|
-
CHANNEL_ACCENT[channel].badge,
|
|
354
|
-
className
|
|
355
|
-
),
|
|
356
|
-
children: [
|
|
357
|
-
/* @__PURE__ */ jsx(Icon, { className: "h-2.5 w-2.5" }),
|
|
358
|
-
CHANNEL_LABELS[channel]
|
|
359
|
-
]
|
|
360
|
-
}
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
function relativeTime(iso) {
|
|
364
|
-
const diff = Date.now() - new Date(iso).getTime();
|
|
365
|
-
const mins = Math.round(diff / 6e4);
|
|
366
|
-
if (mins < 1) return "now";
|
|
367
|
-
if (mins < 60) return `${mins}m`;
|
|
368
|
-
const hours = Math.round(mins / 60);
|
|
369
|
-
if (hours < 24) return `${hours}h`;
|
|
370
|
-
const days = Math.round(hours / 24);
|
|
371
|
-
if (days < 7) return `${days}d`;
|
|
372
|
-
return `${Math.round(days / 7)}w`;
|
|
373
|
-
}
|
|
374
|
-
function dayLabel(iso) {
|
|
375
|
-
const d = new Date(iso);
|
|
376
|
-
const now = /* @__PURE__ */ new Date();
|
|
377
|
-
const startOf = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
378
|
-
const dayDiff = Math.round((startOf(now) - startOf(d)) / 864e5);
|
|
379
|
-
if (dayDiff <= 0) return "Today";
|
|
380
|
-
if (dayDiff === 1) return "Yesterday";
|
|
381
|
-
if (dayDiff < 7) return d.toLocaleDateString([], { weekday: "long" });
|
|
382
|
-
return d.toLocaleDateString([], { month: "short", day: "numeric", year: now.getFullYear() === d.getFullYear() ? void 0 : "numeric" });
|
|
383
|
-
}
|
|
384
544
|
|
|
385
545
|
// src/lib/media-cache.ts
|
|
386
546
|
var CACHE = "fayz-wa-media-v1";
|
|
@@ -561,49 +721,6 @@ function MediaBubble({ m, outbound }) {
|
|
|
561
721
|
legenda ? /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap break-words", children: legenda }) : null
|
|
562
722
|
] });
|
|
563
723
|
}
|
|
564
|
-
function useRecordLinks(conversation) {
|
|
565
|
-
const { recordLinks } = useConversationsConfig();
|
|
566
|
-
const [items, setItems] = React7__default.useState([]);
|
|
567
|
-
const [tick, setTick] = React7__default.useState(0);
|
|
568
|
-
const id = conversation?.id;
|
|
569
|
-
React7__default.useEffect(() => {
|
|
570
|
-
let alive = true;
|
|
571
|
-
if (!conversation || !recordLinks?.length) {
|
|
572
|
-
setItems([]);
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
void Promise.all(recordLinks.map(async (source) => {
|
|
576
|
-
try {
|
|
577
|
-
const r = await source.load(conversation);
|
|
578
|
-
return { source, links: r.links ?? [], canAct: !!r.canAct };
|
|
579
|
-
} catch {
|
|
580
|
-
return { source, links: [], canAct: false };
|
|
581
|
-
}
|
|
582
|
-
})).then((loaded) => {
|
|
583
|
-
if (alive) setItems(loaded);
|
|
584
|
-
});
|
|
585
|
-
return () => {
|
|
586
|
-
alive = false;
|
|
587
|
-
};
|
|
588
|
-
}, [id, recordLinks, tick]);
|
|
589
|
-
return { items, reload: React7__default.useCallback(() => setTick((n) => n + 1), []) };
|
|
590
|
-
}
|
|
591
|
-
function RecordLinkChip({ link, className }) {
|
|
592
|
-
return /* @__PURE__ */ jsxs(
|
|
593
|
-
"button",
|
|
594
|
-
{
|
|
595
|
-
type: "button",
|
|
596
|
-
onClick: () => navigateApp(link.href),
|
|
597
|
-
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),
|
|
598
|
-
title: link.hint ? `${link.label} \xB7 ${link.hint}` : link.label,
|
|
599
|
-
children: [
|
|
600
|
-
/* @__PURE__ */ jsx(Link2, { className: "h-3 w-3 text-muted-foreground" }),
|
|
601
|
-
/* @__PURE__ */ jsx("span", { className: "truncate", children: link.label }),
|
|
602
|
-
link.hint && /* @__PURE__ */ jsx(Badge, { variant: link.tone ?? "secondary", className: "px-1.5 py-0 text-[10px]", children: link.hint })
|
|
603
|
-
]
|
|
604
|
-
}
|
|
605
|
-
);
|
|
606
|
-
}
|
|
607
724
|
function recordingMime() {
|
|
608
725
|
if (typeof MediaRecorder === "undefined") return void 0;
|
|
609
726
|
for (const m of ["audio/ogg;codecs=opus", "audio/webm;codecs=opus", "audio/webm", "audio/mp4"]) {
|
|
@@ -614,7 +731,7 @@ function recordingMime() {
|
|
|
614
731
|
function clock(seconds) {
|
|
615
732
|
return `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
|
|
616
733
|
}
|
|
617
|
-
function Composer({ canType, placeholder, sending, onSendText, onSendMedia
|
|
734
|
+
function Composer({ canType, placeholder, sending, onSendText, onSendMedia }) {
|
|
618
735
|
const t = useTranslation();
|
|
619
736
|
const [draft, setDraft] = React7.useState("");
|
|
620
737
|
const [file, setFile] = React7.useState(null);
|
|
@@ -745,10 +862,7 @@ function Composer({ canType, placeholder, sending, onSendText, onSendMedia, onTy
|
|
|
745
862
|
Textarea,
|
|
746
863
|
{
|
|
747
864
|
value: draft,
|
|
748
|
-
onChange: (e) =>
|
|
749
|
-
setDraft(e.target.value);
|
|
750
|
-
onTyping?.(e.target.value);
|
|
751
|
-
},
|
|
865
|
+
onChange: (e) => setDraft(e.target.value),
|
|
752
866
|
onKeyDown: (e) => {
|
|
753
867
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
754
868
|
e.preventDefault();
|
|
@@ -1007,18 +1121,15 @@ function buildRows(messages) {
|
|
|
1007
1121
|
});
|
|
1008
1122
|
return rows;
|
|
1009
1123
|
}
|
|
1010
|
-
function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
1124
|
+
function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways, className }) {
|
|
1011
1125
|
const t = useTranslation();
|
|
1012
1126
|
const { messages, sending, send, sendMedia, setStatus, refreshMessages } = useConversationsStore((s) => s);
|
|
1013
|
-
const win = useSendWindow(selected.id
|
|
1127
|
+
const win = useSendWindow(selected.id);
|
|
1014
1128
|
const canType = win.mode.kind === "free";
|
|
1015
1129
|
const threadRef = React7__default.useRef(null);
|
|
1016
|
-
const aoVivo = useConversaAoVivo(selected.id, selected.channel, () => {
|
|
1017
|
-
void refreshMessages();
|
|
1018
|
-
});
|
|
1019
1130
|
React7__default.useEffect(() => {
|
|
1020
1131
|
threadRef.current?.scrollTo({ top: threadRef.current.scrollHeight, behavior: "smooth" });
|
|
1021
|
-
}, [messages.length, selected.id
|
|
1132
|
+
}, [messages.length, selected.id]);
|
|
1022
1133
|
React7__default.useEffect(() => {
|
|
1023
1134
|
if (!selected.id) return;
|
|
1024
1135
|
let timer = null;
|
|
@@ -1041,9 +1152,7 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1041
1152
|
document.removeEventListener("visibilitychange", onVis);
|
|
1042
1153
|
};
|
|
1043
1154
|
}, [selected.id, refreshMessages]);
|
|
1044
|
-
const accent =
|
|
1045
|
-
const { items: linked } = useRecordLinks(hideRecordLinks ? null : selected);
|
|
1046
|
-
const chips = linked.flatMap((i) => i.links);
|
|
1155
|
+
const accent = channelAccent(selected.channel);
|
|
1047
1156
|
const rows = React7__default.useMemo(() => buildRows(messages.filter((m) => !isFoldedRow(m))), [messages]);
|
|
1048
1157
|
const jumpTo = React7__default.useCallback((providerId) => {
|
|
1049
1158
|
const el = threadRef.current?.querySelector(`[data-provider-id="${CSS.escape(providerId)}"]`);
|
|
@@ -1093,8 +1202,7 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1093
1202
|
/* @__PURE__ */ jsx(ChannelBadge, { channel: selected.channel }),
|
|
1094
1203
|
/* @__PURE__ */ jsx("span", { className: "truncate", children: selected.contactHandle })
|
|
1095
1204
|
] })
|
|
1096
|
-
] })
|
|
1097
|
-
chips.slice(0, 2).map((link) => /* @__PURE__ */ jsx(RecordLinkChip, { link, className: "hidden shrink-0 md:inline-flex" }, link.id))
|
|
1205
|
+
] })
|
|
1098
1206
|
] }),
|
|
1099
1207
|
/* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-center gap-1.5", onClick: (e) => e.stopPropagation(), onKeyDown: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxs(Dropdown, { children: [
|
|
1100
1208
|
/* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", "aria-label": t("conversations.thread.more"), children: /* @__PURE__ */ jsx(MoreHorizontal, { className: "h-4 w-4" }) }) }),
|
|
@@ -1112,7 +1220,6 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1112
1220
|
}
|
|
1113
1221
|
),
|
|
1114
1222
|
/* @__PURE__ */ jsxs("div", { ref: threadRef, className: "min-h-0 flex-1 overflow-y-auto px-5 py-4", children: [
|
|
1115
|
-
before,
|
|
1116
1223
|
rows.map((row) => {
|
|
1117
1224
|
if (row.kind === "day") {
|
|
1118
1225
|
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);
|
|
@@ -1164,8 +1271,7 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1164
1271
|
row.id
|
|
1165
1272
|
);
|
|
1166
1273
|
}),
|
|
1167
|
-
|
|
1168
|
-
rows.length === 0 && !before && /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col items-center justify-center text-muted-foreground", children: [
|
|
1274
|
+
rows.length === 0 && /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col items-center justify-center text-muted-foreground", children: [
|
|
1169
1275
|
/* @__PURE__ */ jsx(MessageSquare, { className: "h-7 w-7" }),
|
|
1170
1276
|
/* @__PURE__ */ jsx("p", { className: "mt-2 text-sm", children: t("conversations.thread.empty") })
|
|
1171
1277
|
] })
|
|
@@ -1177,12 +1283,9 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1177
1283
|
{
|
|
1178
1284
|
canType,
|
|
1179
1285
|
sending,
|
|
1180
|
-
placeholder: canType ? t("conversations.thread.reply", { channel:
|
|
1286
|
+
placeholder: canType ? t("conversations.thread.reply", { channel: channelLabel(selected.channel) }) : win.mode.kind === "blocked" ? "Envio bloqueado" : "Fora da janela \u2014 envie um template",
|
|
1181
1287
|
onSendText: (text) => send(text),
|
|
1182
|
-
onSendMedia: (input) => sendMedia(input)
|
|
1183
|
-
onTyping: (text) => {
|
|
1184
|
-
if (text.trim()) aoVivo.avisar();
|
|
1185
|
-
}
|
|
1288
|
+
onSendMedia: (input) => sendMedia(input)
|
|
1186
1289
|
}
|
|
1187
1290
|
)
|
|
1188
1291
|
] })
|
|
@@ -1348,20 +1451,7 @@ function day(iso) {
|
|
|
1348
1451
|
const d = new Date(iso.length === 10 ? `${iso}T12:00:00` : iso);
|
|
1349
1452
|
return Number.isNaN(d.getTime()) ? iso : d.toLocaleDateString("pt-BR");
|
|
1350
1453
|
}
|
|
1351
|
-
function
|
|
1352
|
-
const t = useTranslation();
|
|
1353
|
-
const { items, reload } = useRecordLinks(contact);
|
|
1354
|
-
const links = items.flatMap((i) => i.links);
|
|
1355
|
-
const actions = withActions ? items.filter((i) => i.canAct && i.source.Action) : [];
|
|
1356
|
-
return /* @__PURE__ */ jsx(Section, { title: t("conversations.contact.linkedRecords"), children: /* @__PURE__ */ jsxs("div", { className: "px-3 py-2", children: [
|
|
1357
|
-
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") }),
|
|
1358
|
-
actions.map(({ source }) => {
|
|
1359
|
-
const Action = source.Action;
|
|
1360
|
-
return /* @__PURE__ */ jsx("div", { className: "mt-2", children: /* @__PURE__ */ jsx(Action, { conversation: contact, onDone: reload }) }, source.id);
|
|
1361
|
-
})
|
|
1362
|
-
] }) });
|
|
1363
|
-
}
|
|
1364
|
-
function ContactPanel({ contact, onClose, linkActions = true, className }) {
|
|
1454
|
+
function ContactPanel({ contact, onClose, className }) {
|
|
1365
1455
|
const t = useTranslation();
|
|
1366
1456
|
const profile = useContactProfile(contact.contactPersonId, contact.contactHandle);
|
|
1367
1457
|
return /* @__PURE__ */ jsxs("aside", { className: cn("flex shrink-0 flex-col overflow-y-auto border-l border-border bg-muted/20 pb-4", className), children: [
|
|
@@ -1381,15 +1471,11 @@ function ContactPanel({ contact, onClose, linkActions = true, className }) {
|
|
|
1381
1471
|
] }),
|
|
1382
1472
|
/* @__PURE__ */ jsx(ChannelBadge, { channel: contact.channel })
|
|
1383
1473
|
] }),
|
|
1384
|
-
profile === void 0 && /* @__PURE__ */
|
|
1385
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-24" }),
|
|
1386
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-16 w-full" }),
|
|
1387
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-32" })
|
|
1388
|
-
] }),
|
|
1474
|
+
profile === void 0 && /* @__PURE__ */ jsx("p", { className: "px-4 pt-4 text-xs text-muted-foreground", children: t("conversations.profile.loading") }),
|
|
1389
1475
|
profile === null && /* @__PURE__ */ jsx("p", { className: "px-4 pt-4 text-xs text-muted-foreground", children: t("conversations.profile.notInCrm") }),
|
|
1390
1476
|
profile && /* @__PURE__ */ jsx(ProfileSections, { profile }),
|
|
1391
1477
|
/* @__PURE__ */ jsx(Section, { title: t("conversations.profile.conversation"), children: /* @__PURE__ */ jsx(Rows, { rows: [
|
|
1392
|
-
[t("conversations.contact.channel"),
|
|
1478
|
+
[t("conversations.contact.channel"), channelLabel(contact.channel)],
|
|
1393
1479
|
[t("conversations.contact.status"), t(`conversations.status.${contact.status}`)],
|
|
1394
1480
|
[t("conversations.contact.assignedTo"), contact.assignedTo],
|
|
1395
1481
|
// Who answers this conversation may not be who follows the lead up:
|
|
@@ -1397,8 +1483,7 @@ function ContactPanel({ contact, onClose, linkActions = true, className }) {
|
|
|
1397
1483
|
[t("conversations.contact.leadOwner"), contact.leadOwnerName],
|
|
1398
1484
|
[t("conversations.contact.location"), contact.location],
|
|
1399
1485
|
[t("conversations.contact.note"), contact.note]
|
|
1400
|
-
] }) })
|
|
1401
|
-
/* @__PURE__ */ jsx(LinkedRecords, { contact, withActions: linkActions })
|
|
1486
|
+
] }) })
|
|
1402
1487
|
] });
|
|
1403
1488
|
}
|
|
1404
1489
|
function ProfileSections({ profile }) {
|
|
@@ -1462,7 +1547,304 @@ function ProfileSections({ profile }) {
|
|
|
1462
1547
|
] }, i)) }) })
|
|
1463
1548
|
] });
|
|
1464
1549
|
}
|
|
1550
|
+
var CHANNELS = ["whatsapp", "sms", "instagram", "email", "webchat"];
|
|
1551
|
+
function personHandleFor(channel, contact) {
|
|
1552
|
+
if (!contact) return "";
|
|
1553
|
+
if (channel === "email") return contact.email ?? "";
|
|
1554
|
+
if (channel === "sms" || channel === "whatsapp") return contact.phone ?? "";
|
|
1555
|
+
return "";
|
|
1556
|
+
}
|
|
1557
|
+
var HANDLE_LABEL_KEY = {
|
|
1558
|
+
whatsapp: "conversations.new.handleLabel.phone",
|
|
1559
|
+
sms: "conversations.new.handleLabel.phone",
|
|
1560
|
+
email: "conversations.new.handleLabel.email",
|
|
1561
|
+
instagram: "conversations.new.handleLabel.instagram",
|
|
1562
|
+
webchat: "conversations.new.handleLabel.webchat",
|
|
1563
|
+
support: "conversations.new.handleLabel.email"
|
|
1564
|
+
};
|
|
1565
|
+
function NewConversationPanel({
|
|
1566
|
+
open,
|
|
1567
|
+
onOpenChange
|
|
1568
|
+
}) {
|
|
1569
|
+
const t = useTranslation();
|
|
1570
|
+
const create = useConversationsStore((s) => s.create);
|
|
1571
|
+
const config = useConversationsConfig();
|
|
1572
|
+
const guardConversations = useLimitGuard("conversations_month");
|
|
1573
|
+
const [channel, setChannel] = React7__default.useState("whatsapp");
|
|
1574
|
+
const [contact, setContact] = React7__default.useState(null);
|
|
1575
|
+
const [typedHandle, setTypedHandle] = React7__default.useState("");
|
|
1576
|
+
const [creatingContact, setCreatingContact] = React7__default.useState(false);
|
|
1577
|
+
const [firstMessage, setFirstMessage] = React7__default.useState("");
|
|
1578
|
+
const [submitting, setSubmitting] = React7__default.useState(false);
|
|
1579
|
+
const [pickerKey, setPickerKey] = React7__default.useState(0);
|
|
1580
|
+
React7__default.useEffect(() => {
|
|
1581
|
+
if (open) {
|
|
1582
|
+
setChannel("whatsapp");
|
|
1583
|
+
setContact(null);
|
|
1584
|
+
setTypedHandle("");
|
|
1585
|
+
setCreatingContact(false);
|
|
1586
|
+
setFirstMessage("");
|
|
1587
|
+
setSubmitting(false);
|
|
1588
|
+
setPickerKey((k) => k + 1);
|
|
1589
|
+
}
|
|
1590
|
+
}, [open]);
|
|
1591
|
+
const derivedHandle = personHandleFor(channel, contact);
|
|
1592
|
+
const effectiveHandle = derivedHandle || typedHandle;
|
|
1593
|
+
const handleLabel = t(HANDLE_LABEL_KEY[channel]);
|
|
1594
|
+
const canSubmit = (contact?.name.trim().length ?? 0) > 0 && !submitting;
|
|
1595
|
+
async function handleSubmit(e) {
|
|
1596
|
+
e.preventDefault();
|
|
1597
|
+
if (!canSubmit) return;
|
|
1598
|
+
setSubmitting(true);
|
|
1599
|
+
try {
|
|
1600
|
+
if (await guardConversations() === "blocked") return;
|
|
1601
|
+
await create({
|
|
1602
|
+
channel,
|
|
1603
|
+
contactName: contact.name.trim(),
|
|
1604
|
+
contactPersonId: contact?.id,
|
|
1605
|
+
contactHandle: effectiveHandle.trim() || void 0,
|
|
1606
|
+
firstMessage: firstMessage.trim() || void 0
|
|
1607
|
+
});
|
|
1608
|
+
invalidateLimit("conversations_month");
|
|
1609
|
+
onOpenChange(false);
|
|
1610
|
+
} catch (err) {
|
|
1611
|
+
const message = errorMessage(err);
|
|
1612
|
+
toast.error(t("conversations.new.createFailed"), { description: message });
|
|
1613
|
+
} finally {
|
|
1614
|
+
setSubmitting(false);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
return /* @__PURE__ */ jsx(Modal, { open, onOpenChange, children: /* @__PURE__ */ jsxs(ModalContent, { className: "max-w-md", children: [
|
|
1618
|
+
/* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(ModalTitle, { children: t("conversations.new.title") }) }),
|
|
1619
|
+
/* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "flex min-h-0 flex-1 flex-col overflow-hidden", children: [
|
|
1620
|
+
/* @__PURE__ */ jsxs(ModalBody, { className: "space-y-4", children: [
|
|
1621
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1622
|
+
/* @__PURE__ */ jsx("label", { className: "mb-1.5 block text-xs font-medium text-muted-foreground", children: t("conversations.new.channel") }),
|
|
1623
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: CHANNELS.map((ch) => {
|
|
1624
|
+
const Icon = CHANNEL_ICON[ch];
|
|
1625
|
+
const active = channel === ch;
|
|
1626
|
+
return /* @__PURE__ */ jsxs(
|
|
1627
|
+
Button,
|
|
1628
|
+
{
|
|
1629
|
+
variant: "bare",
|
|
1630
|
+
size: "bare",
|
|
1631
|
+
type: "button",
|
|
1632
|
+
onClick: () => setChannel(ch),
|
|
1633
|
+
"aria-pressed": active,
|
|
1634
|
+
className: cn(
|
|
1635
|
+
"inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium transition-colors",
|
|
1636
|
+
active ? "text-white" : "bg-muted text-muted-foreground hover:bg-muted/70"
|
|
1637
|
+
),
|
|
1638
|
+
style: active ? { backgroundColor: CHANNEL_ACCENT[ch].color } : void 0,
|
|
1639
|
+
children: [
|
|
1640
|
+
/* @__PURE__ */ jsx(Icon, { className: "h-3 w-3" }),
|
|
1641
|
+
CHANNEL_LABELS[ch]
|
|
1642
|
+
]
|
|
1643
|
+
},
|
|
1644
|
+
ch
|
|
1645
|
+
);
|
|
1646
|
+
}) })
|
|
1647
|
+
] }),
|
|
1648
|
+
/* @__PURE__ */ jsx(
|
|
1649
|
+
ContactPicker,
|
|
1650
|
+
{
|
|
1651
|
+
value: contact,
|
|
1652
|
+
onChange: setContact,
|
|
1653
|
+
kind: config.contactKind,
|
|
1654
|
+
lookup: config.contactLookup,
|
|
1655
|
+
createEntityDef: config.contactEntityDef,
|
|
1656
|
+
allowFreeText: true,
|
|
1657
|
+
onCreatingChange: setCreatingContact,
|
|
1658
|
+
autoFocus: true,
|
|
1659
|
+
label: t("conversations.new.contactName"),
|
|
1660
|
+
placeholder: t("conversations.new.contactNamePlaceholder"),
|
|
1661
|
+
secondaryText: derivedHandle || void 0,
|
|
1662
|
+
handleField: {
|
|
1663
|
+
label: handleLabel,
|
|
1664
|
+
derived: derivedHandle || void 0,
|
|
1665
|
+
value: typedHandle,
|
|
1666
|
+
onChange: setTypedHandle,
|
|
1667
|
+
fieldLabel: t("conversations.new.handle"),
|
|
1668
|
+
placeholder: t("conversations.new.handlePlaceholder")
|
|
1669
|
+
}
|
|
1670
|
+
},
|
|
1671
|
+
pickerKey
|
|
1672
|
+
),
|
|
1673
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1674
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "conv-first-message", className: "mb-1.5 block text-xs font-medium text-muted-foreground", children: t("conversations.new.firstMessage") }),
|
|
1675
|
+
/* @__PURE__ */ jsx(
|
|
1676
|
+
Textarea,
|
|
1677
|
+
{
|
|
1678
|
+
id: "conv-first-message",
|
|
1679
|
+
value: firstMessage,
|
|
1680
|
+
onChange: (e) => setFirstMessage(e.target.value),
|
|
1681
|
+
rows: 3,
|
|
1682
|
+
placeholder: t("conversations.new.firstMessagePlaceholder"),
|
|
1683
|
+
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"
|
|
1684
|
+
}
|
|
1685
|
+
)
|
|
1686
|
+
] })
|
|
1687
|
+
] }),
|
|
1688
|
+
/* @__PURE__ */ jsx(ModalFooter, { children: /* @__PURE__ */ jsx(Button, { type: "submit", disabled: !canSubmit, className: "w-full", children: submitting ? t("conversations.new.creating") : t("conversations.new.create") }) })
|
|
1689
|
+
] })
|
|
1690
|
+
] }) });
|
|
1691
|
+
}
|
|
1692
|
+
function useCaixaAoVivo() {
|
|
1693
|
+
const tenantId = useActiveTenantId();
|
|
1694
|
+
const load = useConversationsStore((s) => s.load);
|
|
1695
|
+
const refreshMessages = useConversationsStore((s) => s.refreshMessages);
|
|
1696
|
+
const selectedId = useConversationsStore((s) => s.selectedId);
|
|
1697
|
+
const abertoRef = React7.useRef(selectedId);
|
|
1698
|
+
abertoRef.current = selectedId;
|
|
1699
|
+
React7.useEffect(() => {
|
|
1700
|
+
if (!tenantId) return;
|
|
1701
|
+
return assinarChegada(tenantId, ({ conversationId }) => {
|
|
1702
|
+
void load();
|
|
1703
|
+
if (conversationId && conversationId === abertoRef.current) {
|
|
1704
|
+
void refreshMessages();
|
|
1705
|
+
}
|
|
1706
|
+
});
|
|
1707
|
+
}, [tenantId, load, refreshMessages]);
|
|
1708
|
+
}
|
|
1709
|
+
function InboxView({ layout = "page", newSignal = 0 } = {}) {
|
|
1710
|
+
const t = useTranslation();
|
|
1711
|
+
const dock = layout !== "page";
|
|
1712
|
+
const { conversations, selectedId, deselect } = useConversationsStore((s) => s);
|
|
1713
|
+
useCaixaAoVivo();
|
|
1714
|
+
const isWideViewport = useMediaQuery("(min-width: 1280px)");
|
|
1715
|
+
const isWidePanel = isWideViewport && !dock;
|
|
1716
|
+
const railOpen = useRightRailStore((s) => s.open);
|
|
1717
|
+
const [panelOpen, setPanelOpen] = React7__default.useState(false);
|
|
1718
|
+
const [newOpen, setNewOpen] = React7__default.useState(false);
|
|
1719
|
+
const selected = conversations.find((c) => c.id === selectedId) ?? null;
|
|
1720
|
+
React7__default.useEffect(() => {
|
|
1721
|
+
if (newSignal > 0) setNewOpen(true);
|
|
1722
|
+
}, [newSignal]);
|
|
1723
|
+
React7__default.useEffect(() => {
|
|
1724
|
+
setPanelOpen(isWidePanel && !railOpen);
|
|
1725
|
+
}, [isWidePanel, railOpen]);
|
|
1726
|
+
const newActions = React7__default.useMemo(() => [{
|
|
1727
|
+
id: "new-conversation",
|
|
1728
|
+
label: t("conversations.list.new"),
|
|
1729
|
+
icon: SquarePen,
|
|
1730
|
+
intent: "primary",
|
|
1731
|
+
// Starting a conversation creates a thread — the FAB is a "+".
|
|
1732
|
+
creates: true,
|
|
1733
|
+
testId: "conversations-new",
|
|
1734
|
+
permission: { feature: "conversations", action: "create" },
|
|
1735
|
+
onSelect: () => setNewOpen(true)
|
|
1736
|
+
}], [t]);
|
|
1737
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1738
|
+
!dock && /* @__PURE__ */ jsx(PageHeaderActions, { children: /* @__PURE__ */ jsx(PageActions, { actions: newActions }) }),
|
|
1739
|
+
/* @__PURE__ */ jsx(NewConversationPanel, { open: newOpen, onOpenChange: setNewOpen }),
|
|
1740
|
+
/* @__PURE__ */ jsxs("div", { className: "relative flex h-full min-h-0 overflow-hidden bg-background", children: [
|
|
1741
|
+
/* @__PURE__ */ jsx(ConversationList, { className: cn(
|
|
1742
|
+
layout === "page" && (selected ? "hidden lg:flex" : "flex"),
|
|
1743
|
+
layout === "dock" && (selected ? "hidden" : "flex lg:w-full border-r-0"),
|
|
1744
|
+
layout === "dock-wide" && "flex lg:w-[300px]"
|
|
1745
|
+
) }),
|
|
1746
|
+
selected ? /* @__PURE__ */ jsx(
|
|
1747
|
+
MessageThread,
|
|
1748
|
+
{
|
|
1749
|
+
selected,
|
|
1750
|
+
panelOpen,
|
|
1751
|
+
onTogglePanel: () => setPanelOpen((v) => !v),
|
|
1752
|
+
onBack: deselect,
|
|
1753
|
+
backAlways: layout === "dock",
|
|
1754
|
+
className: "flex"
|
|
1755
|
+
}
|
|
1756
|
+
) : 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: [
|
|
1757
|
+
/* @__PURE__ */ jsx(MessageSquare, { className: "h-9 w-9" }),
|
|
1758
|
+
/* @__PURE__ */ jsx("p", { className: "mt-2 text-sm", children: t("conversations.empty.select") })
|
|
1759
|
+
] }),
|
|
1760
|
+
selected && panelOpen && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1761
|
+
/* @__PURE__ */ jsx(
|
|
1762
|
+
Button,
|
|
1763
|
+
{
|
|
1764
|
+
variant: "bare",
|
|
1765
|
+
size: "bare",
|
|
1766
|
+
className: cn("absolute inset-0 z-10 rounded-none bg-black/40", !dock && "xl:hidden"),
|
|
1767
|
+
"aria-label": "Close details",
|
|
1768
|
+
onClick: () => setPanelOpen(false)
|
|
1769
|
+
}
|
|
1770
|
+
),
|
|
1771
|
+
/* @__PURE__ */ jsx(
|
|
1772
|
+
ContactPanel,
|
|
1773
|
+
{
|
|
1774
|
+
contact: selected,
|
|
1775
|
+
onClose: () => setPanelOpen(false),
|
|
1776
|
+
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:shadow-none")
|
|
1777
|
+
}
|
|
1778
|
+
)
|
|
1779
|
+
] })
|
|
1780
|
+
] })
|
|
1781
|
+
] });
|
|
1782
|
+
}
|
|
1783
|
+
var CHANNELS2 = ["sms", "whatsapp", "instagram", "email", "webchat"];
|
|
1784
|
+
function requestedContact() {
|
|
1785
|
+
try {
|
|
1786
|
+
const hash = currentAppPath();
|
|
1787
|
+
const qs = hash.includes("?") ? hash.slice(hash.indexOf("?") + 1) : "";
|
|
1788
|
+
if (!qs) return null;
|
|
1789
|
+
const p = new URLSearchParams(qs);
|
|
1790
|
+
const handle = (p.get("handle") ?? "").trim();
|
|
1791
|
+
const name = (p.get("name") ?? "").trim();
|
|
1792
|
+
const personId = (p.get("personId") ?? "").trim() || void 0;
|
|
1793
|
+
if (!handle) return null;
|
|
1794
|
+
const raw = (p.get("channel") ?? "whatsapp").toLowerCase();
|
|
1795
|
+
const channel = CHANNELS2.includes(raw) ? raw : "whatsapp";
|
|
1796
|
+
return { personId, name: name || handle, handle, channel };
|
|
1797
|
+
} catch {
|
|
1798
|
+
return null;
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
function conversationIdFromPath(path) {
|
|
1802
|
+
const m = /^\/conversations\/([^/?#]+)/.exec(path);
|
|
1803
|
+
return m ? decodeURIComponent(m[1]) : null;
|
|
1804
|
+
}
|
|
1805
|
+
function ConversationsPage({ store, config }) {
|
|
1806
|
+
React7__default.useEffect(() => {
|
|
1807
|
+
const wanted = requestedContact();
|
|
1808
|
+
if (!wanted) {
|
|
1809
|
+
const fromPath = conversationIdFromPath(currentAppPath());
|
|
1810
|
+
if (fromPath) store.setState({ selectedId: fromPath });
|
|
1811
|
+
void store.getState().load();
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1814
|
+
void store.getState().openForPerson(wanted).catch(() => {
|
|
1815
|
+
void store.getState().load();
|
|
1816
|
+
});
|
|
1817
|
+
try {
|
|
1818
|
+
const hash = currentAppPath();
|
|
1819
|
+
const clean = hash.includes("?") ? hash.slice(0, hash.indexOf("?")) : hash;
|
|
1820
|
+
window.history.replaceState(null, "", appHref(clean || "/conversations"));
|
|
1821
|
+
} catch {
|
|
1822
|
+
}
|
|
1823
|
+
}, []);
|
|
1824
|
+
React7__default.useEffect(() => {
|
|
1825
|
+
const write = (id) => {
|
|
1826
|
+
const path = currentAppPath();
|
|
1827
|
+
if (!path.startsWith("/conversations")) return;
|
|
1828
|
+
if (path.includes("?")) return;
|
|
1829
|
+
if (conversationIdFromPath(path) === id) return;
|
|
1830
|
+
replaceApp(id ? `/conversations/${encodeURIComponent(id)}` : "/conversations");
|
|
1831
|
+
};
|
|
1832
|
+
write(store.getState().selectedId);
|
|
1833
|
+
const unsubscribe = store.subscribe((state, previous) => {
|
|
1834
|
+
if (state.selectedId !== previous.selectedId) write(state.selectedId);
|
|
1835
|
+
});
|
|
1836
|
+
const off = onAppPathChange((path) => {
|
|
1837
|
+
const id = conversationIdFromPath(path || "/");
|
|
1838
|
+
if (id && id !== store.getState().selectedId) void store.getState().select(id);
|
|
1839
|
+
});
|
|
1840
|
+
return () => {
|
|
1841
|
+
unsubscribe();
|
|
1842
|
+
off();
|
|
1843
|
+
};
|
|
1844
|
+
}, [store]);
|
|
1845
|
+
return /* @__PURE__ */ jsx(ConversationsContextProvider, { store, config, children: /* @__PURE__ */ jsx(InboxView, {}) });
|
|
1846
|
+
}
|
|
1465
1847
|
|
|
1466
|
-
export {
|
|
1467
|
-
//# sourceMappingURL=
|
|
1468
|
-
//# sourceMappingURL=
|
|
1848
|
+
export { ConversationsPage, conversationIdFromPath };
|
|
1849
|
+
//# sourceMappingURL=ConversationsPage-C6FMGA72.js.map
|
|
1850
|
+
//# sourceMappingURL=ConversationsPage-C6FMGA72.js.map
|