@wealthx/shadcn 1.5.23 → 1.5.25

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.
Files changed (72) hide show
  1. package/.turbo/turbo-build.log +147 -147
  2. package/CHANGELOG.md +12 -0
  3. package/dist/{chunk-K4GJTP6N.mjs → chunk-4FJC64FV.mjs} +467 -386
  4. package/dist/{chunk-FGHM34AV.mjs → chunk-7JVKSZ4O.mjs} +1 -1
  5. package/dist/{chunk-6HTE24TP.mjs → chunk-EY5YPFKX.mjs} +1 -1
  6. package/dist/{chunk-3HFOSFOM.mjs → chunk-IG7DEIWU.mjs} +4 -4
  7. package/dist/{chunk-2VTOF7PW.mjs → chunk-K2KX3NX7.mjs} +1 -1
  8. package/dist/{chunk-NXZ2F4JA.mjs → chunk-KGBLORCQ.mjs} +1 -1
  9. package/dist/{chunk-2SDEURIQ.mjs → chunk-PX2B3Q3A.mjs} +7 -7
  10. package/dist/{chunk-66NM4AX2.mjs → chunk-QM7LU2BR.mjs} +10 -10
  11. package/dist/{chunk-4UCRTTVL.mjs → chunk-RNLIZRAK.mjs} +1 -1
  12. package/dist/{chunk-BWG7AX6X.mjs → chunk-SQ54W3JH.mjs} +1 -1
  13. package/dist/{chunk-RJHE3V4M.mjs → chunk-UMR3HVZF.mjs} +4 -4
  14. package/dist/{chunk-JGUC3KCA.mjs → chunk-VNB5E7SI.mjs} +5 -5
  15. package/dist/{chunk-ETT5JAXF.mjs → chunk-Z5QI7CW2.mjs} +1 -1
  16. package/dist/components/ui/about-you-form.mjs +4 -4
  17. package/dist/components/ui/ai-assistant-drawer.mjs +2 -2
  18. package/dist/components/ui/{ai-conversations.js → ai-conversations/index.js} +818 -740
  19. package/dist/components/ui/ai-conversations/index.mjs +42 -0
  20. package/dist/components/ui/appointment-action-dialogs.mjs +1 -1
  21. package/dist/components/ui/appointment-availability-settings.mjs +5 -5
  22. package/dist/components/ui/appointment-book-dialog.mjs +4 -4
  23. package/dist/components/ui/appointment-detail-sheet.mjs +3 -3
  24. package/dist/components/ui/appointment-upcoming-card.mjs +1 -1
  25. package/dist/components/ui/assets-liabilities-side-card.mjs +6 -6
  26. package/dist/components/ui/backoffice-signup-steps.mjs +4 -4
  27. package/dist/components/ui/bank-statement-generate-dialog.mjs +6 -6
  28. package/dist/components/ui/contact-alert-dialog/index.mjs +2 -2
  29. package/dist/components/ui/create-contact-modal.mjs +3 -3
  30. package/dist/components/ui/date-picker.mjs +2 -2
  31. package/dist/components/ui/expense-detail-item.mjs +3 -3
  32. package/dist/components/ui/expense-work-details.mjs +9 -9
  33. package/dist/components/ui/file-preview-dialog.mjs +2 -2
  34. package/dist/components/ui/financial-drawers.mjs +2 -2
  35. package/dist/components/ui/form-primitives.mjs +2 -2
  36. package/dist/components/ui/frontend-signup-steps.mjs +5 -5
  37. package/dist/components/ui/income-work-details.mjs +3 -3
  38. package/dist/components/ui/kanban-column.mjs +4 -4
  39. package/dist/components/ui/opportunity-card.mjs +1 -1
  40. package/dist/components/ui/opportunity-edit-modals.mjs +6 -6
  41. package/dist/components/ui/opportunity-summary-tab.mjs +8 -8
  42. package/dist/components/ui/pipeline-board.mjs +6 -6
  43. package/dist/components/ui/pipeline-dialogs.mjs +5 -5
  44. package/dist/components/ui/property-report-dialog.mjs +4 -4
  45. package/dist/components/ui/savings-goal-modal.mjs +4 -4
  46. package/dist/components/ui/share-details-dialog.mjs +2 -2
  47. package/dist/components/ui/signup-form-primitives.mjs +1 -1
  48. package/dist/index.js +4912 -4834
  49. package/dist/index.mjs +160 -160
  50. package/dist/styles.css +1 -1
  51. package/package.json +4 -4
  52. package/src/components/index.tsx +1 -0
  53. package/src/components/ui/ai-conversations/helpers.tsx +31 -0
  54. package/src/components/ui/ai-conversations/index.tsx +468 -0
  55. package/src/components/ui/ai-conversations/lead-panel.tsx +517 -0
  56. package/src/components/ui/ai-conversations/list.tsx +335 -0
  57. package/src/components/ui/ai-conversations/thread.tsx +919 -0
  58. package/src/components/ui/ai-conversations/types.ts +83 -0
  59. package/src/styles/styles-css.ts +1 -1
  60. package/tsup.config.ts +1 -1
  61. package/dist/components/ui/ai-conversations.mjs +0 -42
  62. package/src/components/ui/ai-conversations.tsx +0 -2213
  63. package/dist/{chunk-A43XIVO6.mjs → chunk-2PWTXE66.mjs} +3 -3
  64. package/dist/{chunk-PSBQ4I3M.mjs → chunk-53ZB2JWT.mjs} +6 -6
  65. package/dist/{chunk-G6RCC2SF.mjs → chunk-5ST6BK7R.mjs} +3 -3
  66. package/dist/{chunk-H5NI6ZIU.mjs → chunk-734FOOJC.mjs} +3 -3
  67. package/dist/{chunk-ONYADWSO.mjs → chunk-ABVCQWDY.mjs} +3 -3
  68. package/dist/{chunk-AADJ5IT6.mjs → chunk-ECC2LLZM.mjs} +3 -3
  69. package/dist/{chunk-DK55HZPN.mjs → chunk-KENLXFJ7.mjs} +6 -6
  70. package/dist/{chunk-ET4MTPIY.mjs → chunk-LDC6V6DJ.mjs} +3 -3
  71. package/dist/{chunk-3S4XQTAL.mjs → chunk-SO4RB3XB.mjs} +9 -9
  72. package/dist/{chunk-UMF6LLQK.mjs → chunk-TRM3KIHT.mjs} +3 -3
@@ -1,2213 +0,0 @@
1
- import React, { useState } from "react";
2
- import { useEditor, EditorContent } from "@tiptap/react";
3
- import StarterKit from "@tiptap/starter-kit";
4
- import TiptapUnderline from "@tiptap/extension-underline";
5
- import TiptapLink from "@tiptap/extension-link";
6
- import ReactMarkdown from "react-markdown";
7
- import rehypeRaw from "rehype-raw";
8
- import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
9
- import {
10
- Archive,
11
- ArrowLeft,
12
- Bold,
13
- Bot,
14
- Briefcase,
15
- Calendar,
16
- CheckCircle2,
17
- ChevronLeft,
18
- ChevronRight,
19
- ChevronDown,
20
- Flag,
21
- HelpCircle,
22
- Italic,
23
- Link2,
24
- Lock,
25
- Mail,
26
- MapPin,
27
- MessageSquare,
28
- MoreHorizontal,
29
- Navigation,
30
- Paperclip,
31
- Phone,
32
- PhoneCall,
33
- Plus,
34
- Search,
35
- Send,
36
- Underline,
37
- UserCheck,
38
- UserPlus,
39
- Video,
40
- } from "lucide-react";
41
- import { cn, getInitials } from "@/lib/utils";
42
- import { Avatar, AvatarFallback } from "@/components/ui/avatar";
43
- import { Badge } from "@/components/ui/badge";
44
- import { Button, buttonVariants } from "@/components/ui/button";
45
- import { Input } from "@/components/ui/input";
46
- import {
47
- DropdownMenu,
48
- DropdownMenuContent,
49
- DropdownMenuItem,
50
- DropdownMenuSeparator,
51
- DropdownMenuTrigger,
52
- } from "@/components/ui/dropdown-menu";
53
- import {
54
- Dialog,
55
- DialogContent,
56
- DialogDescription,
57
- DialogFooter,
58
- DialogHeader,
59
- DialogTitle,
60
- } from "@/components/ui/dialog";
61
- import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
62
- import { Separator } from "@/components/ui/separator";
63
- import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
64
- import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
65
- import { Textarea } from "@/components/ui/textarea";
66
- import {
67
- Tooltip,
68
- TooltipContent,
69
- TooltipProvider,
70
- TooltipTrigger,
71
- } from "@/components/ui/tooltip";
72
-
73
- /**
74
- * AI Conversations — WealthX Backoffice
75
- *
76
- * 3-panel inbox for managing AI + advisor conversations from website chatbot leads.
77
- *
78
- * Component hierarchy:
79
- * Atom → ConversationStatusChip
80
- * Molecule → ConversationListItem, ChatBubble
81
- * Organism → ConversationList, ChatThread, ChatComposer, AICollectedDataSection, LeadInfoPanel
82
- * Template → ConversationsPage
83
- */
84
-
85
- // ---------------------------------------------------------------------------
86
- // Types
87
- // ---------------------------------------------------------------------------
88
-
89
- export type AiConvStatus =
90
- | "ai-active"
91
- | "manual"
92
- | "needs-attention"
93
- | "closed";
94
-
95
- export type AiConvMessageRole = "bot" | "visitor" | "advisor" | "system";
96
-
97
- export type AiConvFieldConfidence = "confirmed" | "estimated";
98
-
99
- export type AiConvFilterTab =
100
- | "all"
101
- | "open"
102
- | "ai-active"
103
- | "needs-attention"
104
- | "closed";
105
-
106
- export type AiConvMode = "ai" | "manual";
107
-
108
- export type AiConvChannel = "chat" | "email";
109
-
110
- export type AiConvChannelFilter = "all" | AiConvChannel;
111
-
112
- export type AiConvMeetingType = "video" | "phone" | "in-person";
113
-
114
- export interface AiConvContact {
115
- id: string;
116
- name: string;
117
- email?: string;
118
- phone?: string;
119
- }
120
-
121
- export interface AiConvAdvisor {
122
- id: string;
123
- name: string;
124
- initials: string;
125
- role?: string;
126
- }
127
-
128
- export interface AiConvListItemData {
129
- id: string;
130
- contact: AiConvContact;
131
- status: AiConvStatus;
132
- lastMessage: string;
133
- lastMessageRole?: AiConvMessageRole;
134
- timestamp: string;
135
- unreadCount?: number;
136
- /** Assigned advisor display name. */
137
- assignedTo?: string;
138
- /**
139
- * Conversation topic tag — e.g. "Buy a Home", "Refinance", "Investment".
140
- * Shown as a small secondary badge so the broker can categorise conversations
141
- * at a glance without opening each thread.
142
- */
143
- topic?: string;
144
- /** Channel this conversation is using — "chat" (default) or "email". */
145
- channel?: AiConvChannel;
146
- }
147
-
148
- export interface AiConvMessage {
149
- id: string;
150
- role: AiConvMessageRole;
151
- content: string;
152
- timestamp?: string;
153
- /** Display name shown above the bubble. */
154
- senderName?: string;
155
- }
156
-
157
- export interface AiConvDataField {
158
- label: string;
159
- value: string;
160
- confidence: AiConvFieldConfidence;
161
- }
162
-
163
- export interface AiConvAppointmentData {
164
- datetime: string;
165
- meetingType: AiConvMeetingType;
166
- /** Meeting link (video), phone number (phone), or address (in-person). */
167
- meetingDetail?: string;
168
- status: "requested" | "confirmed" | "pending" | "cancelled";
169
- }
170
-
171
- // ---------------------------------------------------------------------------
172
- // Internal helpers & shared constants
173
- // ---------------------------------------------------------------------------
174
-
175
- function displayContactName(name: string): string {
176
- return name.trim() || "Website User";
177
- }
178
-
179
- /** Shared fixed height for all three panel top-bar sections so bottom dividers align. */
180
- const PANEL_HEADER_HEIGHT = "h-[94px]";
181
-
182
- const APPOINTMENT_STATUS_LABEL: Record<
183
- AiConvAppointmentData["status"],
184
- string
185
- > = {
186
- requested: "Lead requested",
187
- confirmed: "Confirmed",
188
- pending: "Pending confirmation",
189
- cancelled: "Cancelled",
190
- };
191
-
192
- // ---------------------------------------------------------------------------
193
- // ConversationStatusChip
194
- // ---------------------------------------------------------------------------
195
-
196
- type BadgeVariant = "success" | "default" | "warning" | "secondary";
197
-
198
- const STATUS_CONFIG: Record<
199
- AiConvStatus,
200
- { label: string; variant: BadgeVariant; dotClass: string }
201
- > = {
202
- "ai-active": {
203
- label: "AI Active",
204
- variant: "success",
205
- dotClass: "bg-success",
206
- },
207
- manual: {
208
- label: "Manual",
209
- variant: "default",
210
- dotClass: "bg-primary",
211
- },
212
- "needs-attention": {
213
- label: "Needs Attention",
214
- variant: "warning",
215
- dotClass: "bg-warning",
216
- },
217
- closed: {
218
- label: "Closed",
219
- variant: "secondary",
220
- dotClass: "bg-muted-foreground/50",
221
- },
222
- };
223
-
224
- export interface ConversationStatusChipProps {
225
- status: AiConvStatus;
226
- showDot?: boolean;
227
- className?: string;
228
- }
229
-
230
- export function ConversationStatusChip({
231
- status,
232
- showDot = false,
233
- className,
234
- }: ConversationStatusChipProps) {
235
- const { label, variant, dotClass } = STATUS_CONFIG[status];
236
- return (
237
- <Badge variant={variant} className={className}>
238
- {showDot && (
239
- <span className={cn("size-1.5 shrink-0 rounded-full", dotClass)} />
240
- )}
241
- {label}
242
- </Badge>
243
- );
244
- }
245
-
246
- // ---------------------------------------------------------------------------
247
- // ContactAvatar — internal
248
- // ---------------------------------------------------------------------------
249
-
250
- interface ContactAvatarProps {
251
- name: string;
252
- size?: "sm" | "md" | "lg";
253
- className?: string;
254
- }
255
-
256
- function ContactAvatar({ name, size = "md", className }: ContactAvatarProps) {
257
- const avatarSize = size === "sm" ? "sm" : size === "lg" ? "lg" : "default";
258
- return (
259
- <Avatar size={avatarSize} className={className}>
260
- <AvatarFallback className="font-semibold">
261
- {getInitials(name)}
262
- </AvatarFallback>
263
- </Avatar>
264
- );
265
- }
266
-
267
- // ---------------------------------------------------------------------------
268
- // ConversationListItem
269
- // ---------------------------------------------------------------------------
270
-
271
- export interface ConversationListItemProps {
272
- data: AiConvListItemData;
273
- isActive?: boolean;
274
- onClick?: (id: string) => void;
275
- onRead?: (id: string) => void;
276
- }
277
-
278
- export function ConversationListItem({
279
- data,
280
- isActive,
281
- onClick,
282
- onRead,
283
- }: ConversationListItemProps) {
284
- return (
285
- <button
286
- type="button"
287
- onClick={() => {
288
- onClick?.(data.id);
289
- onRead?.(data.id);
290
- }}
291
- className={cn(
292
- "w-full flex items-start gap-3 px-3 py-3 text-left transition-colors",
293
- "border-b border-border last:border-b-0",
294
- isActive ? "bg-muted" : "hover:bg-muted/40",
295
- )}
296
- >
297
- <ContactAvatar name={data.contact.name} />
298
- <div className="min-w-0 flex-1">
299
- {/* Row 1 — name + icons + timestamp */}
300
- <div className="mb-1 flex items-center justify-between gap-2">
301
- <span className="truncate text-sm font-semibold text-foreground">
302
- {displayContactName(data.contact.name)}
303
- </span>
304
- <div className="flex shrink-0 items-center gap-1">
305
- {data.status === "needs-attention" && (
306
- <Flag className="size-3 text-warning-text" />
307
- )}
308
- {data.channel === "email" ? (
309
- <Mail className="size-3 text-muted-foreground" />
310
- ) : (
311
- <MessageSquare className="size-3 text-muted-foreground" />
312
- )}
313
- <span className="whitespace-nowrap text-xs text-muted-foreground">
314
- {data.timestamp}
315
- </span>
316
- </div>
317
- </div>
318
- {/* Row 2 — status chip + assigned advisor + unread badge */}
319
- <div className="mb-1.5 flex items-center justify-between gap-2">
320
- <div className="flex min-w-0 items-center gap-1.5">
321
- <ConversationStatusChip status={data.status} showDot />
322
- {data.assignedTo && (
323
- <span className="truncate text-xs text-muted-foreground">
324
- → {data.assignedTo}
325
- </span>
326
- )}
327
- </div>
328
- {data.unreadCount ? (
329
- <Badge
330
- variant="default"
331
- className="size-4 shrink-0 justify-center px-0 text-[10px]"
332
- >
333
- {data.unreadCount}
334
- </Badge>
335
- ) : null}
336
- </div>
337
- {/* Row 3 — last message preview */}
338
- <p className="line-clamp-2 text-sm leading-relaxed text-muted-foreground">
339
- {data.lastMessageRole === "bot" ? (
340
- <span className="font-medium text-foreground/60">AI: </span>
341
- ) : data.lastMessageRole === "advisor" ? (
342
- <span className="font-medium text-foreground/60">You: </span>
343
- ) : data.lastMessageRole === "visitor" ? (
344
- <span className="font-medium text-foreground/60">
345
- {displayContactName(data.contact.name).split(" ")[0]}:{" "}
346
- </span>
347
- ) : null}
348
- {data.lastMessage}
349
- </p>
350
- </div>
351
- </button>
352
- );
353
- }
354
-
355
- // ---------------------------------------------------------------------------
356
- // ConversationList
357
- // ---------------------------------------------------------------------------
358
-
359
- function filterConversations(
360
- conversations: AiConvListItemData[],
361
- query: string,
362
- filter: AiConvFilterTab,
363
- channelFilter: AiConvChannelFilter,
364
- ): AiConvListItemData[] {
365
- const q = query.toLowerCase();
366
- return conversations.filter((c) => {
367
- const matchesFilter =
368
- filter === "all" ||
369
- (filter === "open" ? c.status !== "closed" : c.status === filter);
370
- const matchesChannel =
371
- channelFilter === "all" || (c.channel ?? "chat") === channelFilter;
372
- const matchesSearch =
373
- !q ||
374
- c.contact.name.toLowerCase().includes(q) ||
375
- c.lastMessage.toLowerCase().includes(q);
376
- return matchesFilter && matchesChannel && matchesSearch;
377
- });
378
- }
379
-
380
- const FILTER_TABS: { id: AiConvFilterTab; label: string }[] = [
381
- { id: "all", label: "All" },
382
- { id: "open", label: "Open" },
383
- { id: "ai-active", label: "AI Active" },
384
- { id: "needs-attention", label: "Urgent" },
385
- { id: "closed", label: "Archived" },
386
- ];
387
-
388
- export interface ConversationListProps {
389
- conversations: AiConvListItemData[];
390
- activeId?: string;
391
- searchQuery?: string;
392
- activeFilter?: AiConvFilterTab;
393
- channelFilter?: AiConvChannelFilter;
394
- hasMore?: boolean;
395
- isLoadingMore?: boolean;
396
- onSearchChange?: (v: string) => void;
397
- onFilterChange?: (f: AiConvFilterTab) => void;
398
- onChannelFilterChange?: (f: AiConvChannelFilter) => void;
399
- onSelect?: (id: string) => void;
400
- onRead?: (id: string) => void;
401
- onLoadMore?: () => void;
402
- className?: string;
403
- }
404
-
405
- export function ConversationList({
406
- conversations,
407
- activeId,
408
- searchQuery = "",
409
- activeFilter = "all",
410
- channelFilter: channelFilterProp = "all",
411
- hasMore,
412
- isLoadingMore,
413
- onSearchChange,
414
- onFilterChange,
415
- onChannelFilterChange,
416
- onSelect,
417
- onRead,
418
- onLoadMore,
419
- className,
420
- }: ConversationListProps) {
421
- const [channelFilter, setChannelFilter] =
422
- useState<AiConvChannelFilter>(channelFilterProp);
423
-
424
- function handleChannelFilterChange(vals: string[]) {
425
- const v = vals[0] as AiConvChannelFilter | undefined;
426
- if (v) {
427
- setChannelFilter(v);
428
- onChannelFilterChange?.(v);
429
- }
430
- }
431
-
432
- return (
433
- <div
434
- className={cn(
435
- "flex flex-col border-r border-border bg-background",
436
- className,
437
- )}
438
- >
439
- <div className={cn(PANEL_HEADER_HEIGHT, "flex shrink-0 flex-col")}>
440
- <div className="flex shrink-0 items-center gap-2 border-b border-border px-3 py-2.5">
441
- <div className="relative flex-1">
442
- <Search className="absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" />
443
- <Input
444
- value={searchQuery}
445
- onChange={(e) => onSearchChange?.(e.target.value)}
446
- placeholder="Search conversations..."
447
- className="h-8 pl-8 text-sm"
448
- />
449
- </div>
450
- <ToggleGroup
451
- type="single"
452
- variant="outline"
453
- size="sm"
454
- spacing={0}
455
- value={[channelFilter]}
456
- onValueChange={handleChannelFilterChange}
457
- className="shrink-0"
458
- >
459
- <ToggleGroupItem value="all" aria-label="All channels">
460
- All
461
- </ToggleGroupItem>
462
- <ToggleGroupItem value="chat" aria-label="Chat">
463
- <MessageSquare className="size-3.5" />
464
- </ToggleGroupItem>
465
- <ToggleGroupItem value="email" aria-label="Email">
466
- <Mail className="size-3.5" />
467
- </ToggleGroupItem>
468
- </ToggleGroup>
469
- </div>
470
-
471
- <div className="flex flex-1 items-center border-b border-border">
472
- <Tabs
473
- value={activeFilter}
474
- onValueChange={(v) => v && onFilterChange?.(v as AiConvFilterTab)}
475
- className="w-full"
476
- >
477
- <TabsList
478
- variant="line"
479
- className="w-full justify-start gap-0 h-auto"
480
- >
481
- {FILTER_TABS.map((tab) => (
482
- <TabsTrigger
483
- key={tab.id}
484
- value={tab.id}
485
- className="flex-none px-3 py-2 text-xs"
486
- >
487
- {tab.label}
488
- </TabsTrigger>
489
- ))}
490
- </TabsList>
491
- </Tabs>
492
- </div>
493
- </div>
494
-
495
- {/* List */}
496
- <div className="flex-1 overflow-y-auto" tabIndex={0}>
497
- {(() => {
498
- const filtered = filterConversations(
499
- conversations,
500
- searchQuery,
501
- activeFilter,
502
- channelFilter,
503
- );
504
- return filtered.length === 0 ? (
505
- <div className="flex flex-col items-center justify-center gap-2 p-8 text-muted-foreground">
506
- <MessageSquare className="size-8 opacity-30" />
507
- <p className="text-sm">No conversations</p>
508
- {searchQuery && (
509
- <Button
510
- variant="outline"
511
- size="sm"
512
- onClick={() => onSearchChange?.("")}
513
- >
514
- Clear search
515
- </Button>
516
- )}
517
- {!searchQuery && activeFilter !== "all" && (
518
- <Button
519
- variant="outline"
520
- size="sm"
521
- onClick={() => onFilterChange?.("all")}
522
- >
523
- Clear filter
524
- </Button>
525
- )}
526
- </div>
527
- ) : (
528
- <>
529
- {filtered.map((item) => (
530
- <ConversationListItem
531
- key={item.id}
532
- data={item}
533
- isActive={activeId === item.id}
534
- onClick={onSelect}
535
- onRead={onRead}
536
- />
537
- ))}
538
- {hasMore && (
539
- <div className="border-t border-border p-3">
540
- <Button
541
- variant="outline"
542
- size="sm"
543
- className="w-full"
544
- disabled={isLoadingMore}
545
- onClick={onLoadMore}
546
- >
547
- {isLoadingMore ? "Loading..." : "Load more"}
548
- </Button>
549
- </div>
550
- )}
551
- </>
552
- );
553
- })()}
554
- </div>
555
- </div>
556
- );
557
- }
558
-
559
- // ---------------------------------------------------------------------------
560
- // ChatBubble
561
- // ---------------------------------------------------------------------------
562
-
563
- export interface ChatBubbleProps {
564
- message: AiConvMessage;
565
- className?: string;
566
- }
567
-
568
- function BubbleAvatar({
569
- role,
570
- senderName,
571
- }: {
572
- role: AiConvMessageRole;
573
- senderName?: string;
574
- }) {
575
- if (role === "bot") {
576
- return (
577
- <Avatar size="sm">
578
- <AvatarFallback className="border border-border bg-muted">
579
- <Bot className="size-3.5 text-muted-foreground" />
580
- </AvatarFallback>
581
- </Avatar>
582
- );
583
- }
584
- if (role === "advisor") {
585
- return (
586
- <Avatar size="sm">
587
- <AvatarFallback className="font-semibold">
588
- {getInitials(senderName ?? "Advisor")}
589
- </AvatarFallback>
590
- </Avatar>
591
- );
592
- }
593
- return (
594
- <Avatar size="sm">
595
- <AvatarFallback>{getInitials(senderName ?? "?")}</AvatarFallback>
596
- </Avatar>
597
- );
598
- }
599
-
600
- export function ChatBubble({ message, className }: ChatBubbleProps) {
601
- const { role, content, timestamp, senderName } = message;
602
-
603
- if (role === "system") {
604
- return (
605
- <div className={cn("my-2 flex items-center gap-3 px-2", className)}>
606
- <Separator className="flex-1" />
607
- <span className="shrink-0 text-caption text-muted-foreground">
608
- {content}
609
- </span>
610
- <Separator className="flex-1" />
611
- </div>
612
- );
613
- }
614
-
615
- const isAdvisor = role === "advisor";
616
- const isBot = role === "bot";
617
- const isVisitor = role === "visitor";
618
-
619
- const displayName = isBot
620
- ? "AI Assistant"
621
- : isAdvisor
622
- ? (senderName ?? "Advisor")
623
- : (senderName ?? "Lead");
624
-
625
- return (
626
- <div
627
- className={cn(
628
- "flex gap-2.5",
629
- isAdvisor ? "flex-row-reverse" : "flex-row",
630
- className,
631
- )}
632
- >
633
- <BubbleAvatar role={role} senderName={senderName} />
634
-
635
- {/* Bubble + label */}
636
- <div
637
- className={cn(
638
- "flex max-w-[70%] flex-col gap-1",
639
- isAdvisor && "items-end",
640
- )}
641
- >
642
- {/* Sender label — always shown for context */}
643
- <span className="text-caption text-muted-foreground">
644
- {displayName}
645
- </span>
646
-
647
- {/* Bubble */}
648
- <div
649
- className={cn(
650
- "px-3 py-2 text-sm leading-relaxed break-words [&_a]:underline [&_p]:m-0",
651
- isBot && "border border-border bg-muted/60 text-foreground [&_a]:text-primary",
652
- isVisitor && "border border-border bg-background text-foreground [&_a]:text-primary",
653
- isAdvisor && "bg-primary text-primary-foreground [&_a]:text-primary-foreground",
654
- )}
655
- >
656
- <ReactMarkdown rehypePlugins={[rehypeRaw, [rehypeSanitize, defaultSchema]]}>
657
- {content}
658
- </ReactMarkdown>
659
- </div>
660
-
661
- {timestamp && (
662
- <span className="text-caption text-muted-foreground">
663
- {timestamp}
664
- </span>
665
- )}
666
- </div>
667
- </div>
668
- );
669
- }
670
-
671
- // ---------------------------------------------------------------------------
672
- // ChatComposer
673
- // ---------------------------------------------------------------------------
674
-
675
- export interface AiConvEmailPayload {
676
- content: string;
677
- to: string;
678
- cc: string;
679
- subject: string;
680
- }
681
-
682
- export interface ChatComposerProps {
683
- mode: AiConvMode;
684
- /** Active reply channel. Defaults to "chat". */
685
- channel?: AiConvChannel;
686
- onChannelChange?: (channel: AiConvChannel) => void;
687
- /**
688
- * When true, the Email tab is shown in the composer. Defaults to false —
689
- * consumers must opt in once their tenant's email integration is wired up.
690
- */
691
- isEmailIntegrated?: boolean;
692
- /** Lead's email address — pre-fills the To field in email compose. */
693
- contactEmail?: string;
694
- inputValue?: string;
695
- onInputChange?: (v: string) => void;
696
- /** Fired when the user sends a chat message. */
697
- onSend?: (content: string) => void;
698
- /** Fired when the user sends an email. */
699
- onSendEmail?: (payload: AiConvEmailPayload) => void;
700
- onTakeOver?: () => void;
701
- onLetAiHandle?: () => void;
702
- className?: string;
703
- }
704
-
705
- function ComposerToolbarButton({
706
- label,
707
- icon: Icon,
708
- pressed,
709
- onToggle,
710
- }: {
711
- label: string;
712
- icon: React.ElementType;
713
- pressed?: boolean;
714
- onToggle?: () => void;
715
- }) {
716
- return (
717
- <button
718
- type="button"
719
- aria-label={label}
720
- aria-pressed={pressed}
721
- onClick={onToggle}
722
- className={cn(
723
- "flex size-7 items-center justify-center transition-colors",
724
- pressed
725
- ? "bg-foreground text-background"
726
- : "text-muted-foreground hover:bg-muted hover:text-foreground",
727
- )}
728
- >
729
- <Icon className="size-3.5" />
730
- </button>
731
- );
732
- }
733
-
734
- function ComposerLinkPopover({ editor }: { editor: ReturnType<typeof useEditor> }) {
735
- const [open, setOpen] = React.useState(false);
736
- const [url, setUrl] = React.useState("");
737
-
738
- const handleApply = () => {
739
- if (url.trim()) {
740
- editor?.chain().focus().setLink({ href: url.trim() }).run();
741
- }
742
- setOpen(false);
743
- setUrl("");
744
- };
745
-
746
- return (
747
- <Popover
748
- open={open}
749
- onOpenChange={(newOpen) => {
750
- if (newOpen && editor?.isActive("link")) {
751
- editor.chain().focus().unsetLink().run();
752
- return;
753
- }
754
- if (newOpen) setUrl("");
755
- setOpen(newOpen);
756
- }}
757
- >
758
- <PopoverTrigger
759
- aria-label="Insert link"
760
- className={cn(
761
- "flex size-7 items-center justify-center transition-colors",
762
- editor?.isActive("link")
763
- ? "bg-foreground text-background"
764
- : "text-muted-foreground hover:bg-muted hover:text-foreground",
765
- )}
766
- >
767
- <Link2 className="size-3.5" />
768
- </PopoverTrigger>
769
- <PopoverContent className="w-72 p-2" align="start">
770
- <div className="flex items-center gap-1.5">
771
- <input
772
- type="url"
773
- value={url}
774
- onChange={(e) => setUrl(e.target.value)}
775
- onKeyDown={(e) => e.key === "Enter" && handleApply()}
776
- placeholder="https://"
777
- className="min-w-0 flex-1 border border-border bg-transparent px-2 py-1.5 text-sm text-foreground outline-none placeholder:text-muted-foreground focus:border-primary"
778
- autoFocus
779
- />
780
- <Button size="sm" className="h-8 px-3" onClick={handleApply}>
781
- Apply
782
- </Button>
783
- </div>
784
- </PopoverContent>
785
- </Popover>
786
- );
787
- }
788
-
789
- function ComposerEmailFieldRow({
790
- label,
791
- children,
792
- }: {
793
- label: string;
794
- children: React.ReactNode;
795
- }) {
796
- return (
797
- <div className="flex items-center gap-3 border-b border-border px-4 py-2.5">
798
- <span className="w-14 shrink-0 text-sm text-muted-foreground">
799
- {label}
800
- </span>
801
- {children}
802
- </div>
803
- );
804
- }
805
-
806
- export function ChatComposer({
807
- mode,
808
- channel: channelProp = "chat",
809
- onChannelChange,
810
- isEmailIntegrated = false,
811
- contactEmail = "",
812
- inputValue = "",
813
- onInputChange,
814
- onSend,
815
- onSendEmail,
816
- onTakeOver,
817
- onLetAiHandle,
818
- className,
819
- }: ChatComposerProps) {
820
- // Semi-controlled: owns channel state for uncontrolled usage, notifies parent on change.
821
- // Force chat when email isn't integrated so the panel never lands on a hidden tab.
822
- const [channel, setChannel] = React.useState<AiConvChannel>(
823
- isEmailIntegrated ? channelProp : "chat",
824
- );
825
- const [emailTo, setEmailTo] = React.useState(contactEmail);
826
- const [emailCc, setEmailCc] = React.useState("");
827
- const [showCc, setShowCc] = React.useState(false);
828
- const [emailSubject, setEmailSubject] = React.useState("");
829
-
830
- const [, forceUpdate] = React.useReducer((x: number) => x + 1, 0);
831
-
832
- const editor = useEditor({
833
- extensions: [
834
- StarterKit,
835
- TiptapUnderline,
836
- TiptapLink.configure({ openOnClick: false }),
837
- ],
838
- content: "",
839
- onTransaction: () => forceUpdate(),
840
- editorProps: {
841
- attributes: {
842
- class:
843
- "min-h-[150px] px-4 py-3 text-base text-foreground outline-none prose prose-sm max-w-none [&_p]:m-0 [&_a]:text-primary [&_a]:underline [&_a]:cursor-pointer",
844
- },
845
- },
846
- });
847
-
848
- const handleChannelChange = (c: AiConvChannel) => {
849
- setChannel(c);
850
- onChannelChange?.(c);
851
- };
852
-
853
- return (
854
- <div
855
- className={cn(
856
- "flex flex-col border-t border-border bg-background",
857
- className,
858
- )}
859
- >
860
- {isEmailIntegrated && (
861
- <div className="border-b border-border px-3 py-2">
862
- <Tabs
863
- value={channel}
864
- onValueChange={(v) => v && handleChannelChange(v as AiConvChannel)}
865
- >
866
- <TabsList variant="default" className="w-full">
867
- <TabsTrigger value="chat" className="flex-1 gap-1.5">
868
- <MessageSquare className="size-3.5" />
869
- Chat
870
- </TabsTrigger>
871
- <TabsTrigger value="email" className="flex-1 gap-1.5">
872
- <Mail className="size-3.5" />
873
- Email
874
- </TabsTrigger>
875
- </TabsList>
876
- </Tabs>
877
- </div>
878
- )}
879
-
880
- {mode === "ai" ? (
881
- <div className="flex items-center gap-2 bg-muted/30 px-4 py-2.5 text-[12px] text-muted-foreground">
882
- <Bot className="size-3.5 shrink-0 text-muted-foreground" />
883
- <span>AI is handling this conversation.</span>
884
- <Button
885
- variant="link"
886
- size="sm"
887
- className="h-auto p-0 text-[12px] font-medium text-foreground"
888
- onClick={onTakeOver}
889
- >
890
- Take Over
891
- </Button>
892
- <span>to reply directly.</span>
893
- </div>
894
- ) : (
895
- /* Email panel stays in normal flow to anchor container height;
896
- chat panel is an absolute overlay so both tabs share identical dimensions */
897
- <div className="relative">
898
- <div
899
- className={cn(
900
- "flex flex-col",
901
- channel !== "email" && "invisible pointer-events-none",
902
- )}
903
- aria-hidden={channel !== "email"}
904
- >
905
- <ComposerEmailFieldRow label="To">
906
- <input
907
- type="email"
908
- value={emailTo}
909
- onChange={(e) => setEmailTo(e.target.value)}
910
- placeholder="Recipient email"
911
- className="min-w-0 flex-1 bg-transparent text-base text-foreground outline-none placeholder:text-muted-foreground"
912
- />
913
- <button
914
- type="button"
915
- onClick={() => setShowCc((v) => !v)}
916
- className="flex shrink-0 items-center gap-0.5 text-sm text-muted-foreground hover:text-foreground"
917
- >
918
- CC
919
- <ChevronDown className="size-3.5" />
920
- </button>
921
- </ComposerEmailFieldRow>
922
- {showCc && (
923
- <ComposerEmailFieldRow label="CC">
924
- <input
925
- type="email"
926
- value={emailCc}
927
- onChange={(e) => setEmailCc(e.target.value)}
928
- placeholder="CC email"
929
- className="min-w-0 flex-1 bg-transparent text-base text-foreground outline-none placeholder:text-muted-foreground"
930
- />
931
- </ComposerEmailFieldRow>
932
- )}
933
- <ComposerEmailFieldRow label="Subject">
934
- <input
935
- type="text"
936
- value={emailSubject}
937
- onChange={(e) => setEmailSubject(e.target.value)}
938
- placeholder="Email subject"
939
- className="min-w-0 flex-1 bg-transparent text-base text-foreground outline-none placeholder:text-muted-foreground"
940
- />
941
- </ComposerEmailFieldRow>
942
- <EditorContent editor={editor} />
943
- <div className="flex items-center justify-between border-t border-border px-3 py-2">
944
- <div className="flex items-center gap-0.5">
945
- <ComposerToolbarButton
946
- label="Bold"
947
- icon={Bold}
948
- pressed={editor?.isActive("bold")}
949
- onToggle={() => editor?.chain().focus().toggleBold().run()}
950
- />
951
- <ComposerToolbarButton
952
- label="Italic"
953
- icon={Italic}
954
- pressed={editor?.isActive("italic")}
955
- onToggle={() => editor?.chain().focus().toggleItalic().run()}
956
- />
957
- <ComposerToolbarButton
958
- label="Underline"
959
- icon={Underline}
960
- pressed={editor?.isActive("underline")}
961
- onToggle={() =>
962
- editor?.chain().focus().toggleUnderline().run()
963
- }
964
- />
965
- <Separator orientation="vertical" className="mx-1.5 h-4" />
966
- <ComposerLinkPopover editor={editor} />
967
- <ComposerToolbarButton label="Attach file" icon={Paperclip} />
968
- </div>
969
- <Button
970
- size="sm"
971
- onClick={() => {
972
- const html = editor?.getHTML() ?? "";
973
- onSendEmail?.({
974
- content: html,
975
- to: emailTo,
976
- cc: emailCc,
977
- subject: emailSubject,
978
- });
979
- editor?.commands.clearContent();
980
- }}
981
- disabled={!editor || editor.isEmpty || !emailTo.trim()}
982
- >
983
- <Send className="mr-1.5 size-3.5" />
984
- Send Email
985
- </Button>
986
- </div>
987
- </div>
988
-
989
- {/* Chat compose — absolute overlay, fills exact same height as email panel */}
990
- {channel === "chat" && (
991
- <div className="absolute inset-0 flex flex-col gap-3 p-4">
992
- <Textarea
993
- value={inputValue}
994
- onChange={(e) => onInputChange?.(e.target.value)}
995
- placeholder="Reply to lead..."
996
- className="min-h-0 flex-1 resize-none text-base"
997
- />
998
- <div className="flex items-center justify-between">
999
- <Button variant="outline" size="sm" onClick={onLetAiHandle}>
1000
- <Bot className="mr-1.5 size-3.5" />
1001
- Let AI Handle
1002
- </Button>
1003
- <Button
1004
- size="sm"
1005
- onClick={() => onSend?.(inputValue)}
1006
- disabled={!inputValue.trim()}
1007
- >
1008
- <Send className="mr-1.5 size-3.5" />
1009
- Send
1010
- </Button>
1011
- </div>
1012
- </div>
1013
- )}
1014
- </div>
1015
- )}
1016
- </div>
1017
- );
1018
- }
1019
-
1020
- // ---------------------------------------------------------------------------
1021
- // ChatThread
1022
- // ---------------------------------------------------------------------------
1023
-
1024
- export interface ChatThreadProps {
1025
- contact: AiConvContact;
1026
- status: AiConvStatus;
1027
- mode: AiConvMode;
1028
- messages: AiConvMessage[];
1029
- isAiTyping?: boolean;
1030
- /** Active reply channel — "chat" (default) or "email". */
1031
- channel?: AiConvChannel;
1032
- onChannelChange?: (channel: AiConvChannel) => void;
1033
- /**
1034
- * When true, the Email tab is shown in the composer. Defaults to false.
1035
- */
1036
- isEmailIntegrated?: boolean;
1037
- inputValue?: string;
1038
- onInputChange?: (v: string) => void;
1039
- /** Fired when the user sends a chat message. */
1040
- onSend?: (content: string) => void;
1041
- /** Fired when the user sends an email. */
1042
- onSendEmail?: (payload: AiConvEmailPayload) => void;
1043
- onTakeOver?: () => void;
1044
- onLetAiHandle?: () => void;
1045
- onReopen?: () => void;
1046
- onMarkUrgent?: () => void;
1047
- onUnmarkUrgent?: () => void;
1048
- onArchive?: () => void;
1049
- onAssignToAdvisor?: () => void;
1050
- /** True when older messages can be loaded (e.g. paginated history). */
1051
- hasMoreMessages?: boolean;
1052
- /** True while a `onLoadMoreMessages` request is in-flight. */
1053
- isLoadingMoreMessages?: boolean;
1054
- /** Fired when the consumer should fetch older messages. */
1055
- onLoadMoreMessages?: () => void;
1056
- /** Mobile only — back to conversation list. */
1057
- onBack?: () => void;
1058
- /** Mobile only — show lead info panel. */
1059
- onShowLeadInfo?: () => void;
1060
- className?: string;
1061
- }
1062
-
1063
- export function ChatThread({
1064
- contact,
1065
- status,
1066
- mode,
1067
- messages,
1068
- isAiTyping = false,
1069
- channel,
1070
- onChannelChange,
1071
- isEmailIntegrated,
1072
- inputValue,
1073
- onInputChange,
1074
- onSend,
1075
- onSendEmail,
1076
- onTakeOver,
1077
- onLetAiHandle,
1078
- onReopen,
1079
- onMarkUrgent,
1080
- onUnmarkUrgent,
1081
- onArchive,
1082
- onAssignToAdvisor,
1083
- hasMoreMessages,
1084
- isLoadingMoreMessages,
1085
- onLoadMoreMessages,
1086
- onBack,
1087
- onShowLeadInfo,
1088
- className,
1089
- }: ChatThreadProps) {
1090
- const aiIsHandling = mode === "ai";
1091
- const isClosed = status === "closed";
1092
-
1093
- const scrollRef = React.useRef<HTMLDivElement>(null);
1094
- // Captures scrollHeight just before older messages are prepended, so we can
1095
- // restore the user's visible scroll offset once the new nodes render.
1096
- const preLoadScrollHeightRef = React.useRef<number | null>(null);
1097
-
1098
- const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
1099
- if (!hasMoreMessages || isLoadingMoreMessages || !onLoadMoreMessages) {
1100
- return;
1101
- }
1102
- if (e.currentTarget.scrollTop <= 80) {
1103
- preLoadScrollHeightRef.current = e.currentTarget.scrollHeight;
1104
- onLoadMoreMessages();
1105
- }
1106
- };
1107
-
1108
- // Tracks the last "tail" message id so we can tell an append (new message,
1109
- // tail changed) apart from a prepend (older history loaded, tail unchanged).
1110
- const prevLastMessageIdRef = React.useRef<string | undefined>(undefined);
1111
- const prevContactIdRef = React.useRef<string>(contact.id);
1112
-
1113
- React.useLayoutEffect(() => {
1114
- const el = scrollRef.current;
1115
- if (!el) return;
1116
-
1117
- // Prepend (older messages just loaded) — restore scroll so the user
1118
- // stays anchored to the message they were reading.
1119
- if (preLoadScrollHeightRef.current !== null) {
1120
- el.scrollTop = el.scrollHeight - preLoadScrollHeightRef.current;
1121
- preLoadScrollHeightRef.current = null;
1122
- prevLastMessageIdRef.current = messages[messages.length - 1]?.id;
1123
- prevContactIdRef.current = contact.id;
1124
- return;
1125
- }
1126
-
1127
- const currentLastId = messages[messages.length - 1]?.id;
1128
- const contactChanged = prevContactIdRef.current !== contact.id;
1129
- const tailChanged = prevLastMessageIdRef.current !== currentLastId;
1130
-
1131
- // Opening a conversation or appending a new message (sent, received,
1132
- // or system) — pin to the bottom.
1133
- if (contactChanged || tailChanged) {
1134
- el.scrollTop = el.scrollHeight;
1135
- }
1136
-
1137
- prevLastMessageIdRef.current = currentLastId;
1138
- prevContactIdRef.current = contact.id;
1139
- }, [contact.id, messages]);
1140
-
1141
- // Typing indicator adds DOM height — keep the view pinned to bottom.
1142
- React.useLayoutEffect(() => {
1143
- if (!isAiTyping) return;
1144
- const el = scrollRef.current;
1145
- if (el) el.scrollTop = el.scrollHeight;
1146
- }, [isAiTyping]);
1147
-
1148
- return (
1149
- <div className={cn("flex flex-col bg-background", className)}>
1150
- {/* Header */}
1151
- <div
1152
- className={cn(
1153
- PANEL_HEADER_HEIGHT,
1154
- "flex items-center gap-3 border-b border-border px-4",
1155
- )}
1156
- >
1157
- {/* Mobile back button */}
1158
- {onBack && (
1159
- <Button
1160
- variant="ghost"
1161
- size="icon"
1162
- className="size-8 shrink-0 md:hidden"
1163
- onClick={onBack}
1164
- aria-label="Back to conversations"
1165
- >
1166
- <ArrowLeft className="size-4" />
1167
- </Button>
1168
- )}
1169
-
1170
- <ContactAvatar name={contact.name} size="md" />
1171
-
1172
- <div className="min-w-0 flex-1">
1173
- <div className="flex items-center gap-2">
1174
- <span className="text-sm font-semibold text-foreground">
1175
- {displayContactName(contact.name)}
1176
- </span>
1177
- <ConversationStatusChip status={status} showDot />
1178
- </div>
1179
- {contact.email && (
1180
- <p className="text-sm text-muted-foreground">{contact.email}</p>
1181
- )}
1182
- </div>
1183
-
1184
- <div className="flex shrink-0 items-center gap-2">
1185
- {/* Action buttons — desktop only (mobile: already in bottom bar) */}
1186
- <div className="hidden items-center gap-2 md:flex">
1187
- {isClosed && (
1188
- <Button variant="outline" size="sm" onClick={onReopen}>
1189
- Reopen
1190
- </Button>
1191
- )}
1192
- {!isClosed && aiIsHandling && (
1193
- <Button size="sm" onClick={onTakeOver}>
1194
- Take Over
1195
- </Button>
1196
- )}
1197
- {!isClosed && !aiIsHandling && (
1198
- <Button variant="outline" size="sm" onClick={onLetAiHandle}>
1199
- <Bot className="mr-1.5 size-3.5" />
1200
- Let AI Handle
1201
- </Button>
1202
- )}
1203
- </div>
1204
-
1205
- {/* More actions dropdown */}
1206
- <DropdownMenu>
1207
- <DropdownMenuTrigger
1208
- className={cn(
1209
- buttonVariants({ variant: "ghost", size: "icon" }),
1210
- "size-8",
1211
- )}
1212
- aria-label="More actions"
1213
- >
1214
- <MoreHorizontal className="size-4" />
1215
- </DropdownMenuTrigger>
1216
- <DropdownMenuContent>
1217
- {/* Lead Info — mobile only */}
1218
- {onShowLeadInfo && (
1219
- <>
1220
- <DropdownMenuItem
1221
- className="md:hidden"
1222
- onClick={onShowLeadInfo}
1223
- >
1224
- <ChevronRight className="mr-2 size-4" />
1225
- Lead Info
1226
- </DropdownMenuItem>
1227
- <DropdownMenuSeparator className="md:hidden" />
1228
- </>
1229
- )}
1230
- {status === "needs-attention" ? (
1231
- <DropdownMenuItem onClick={onUnmarkUrgent}>
1232
- <Flag className="mr-2 size-4" />
1233
- Unmark Urgent
1234
- </DropdownMenuItem>
1235
- ) : (
1236
- <DropdownMenuItem onClick={onMarkUrgent}>
1237
- <Flag className="mr-2 size-4" />
1238
- Mark as Urgent
1239
- </DropdownMenuItem>
1240
- )}
1241
- <DropdownMenuItem onClick={onAssignToAdvisor}>
1242
- <UserCheck className="mr-2 size-4" />
1243
- Assign to advisor
1244
- </DropdownMenuItem>
1245
- <DropdownMenuSeparator />
1246
- <DropdownMenuItem onClick={onArchive}>
1247
- <Archive className="mr-2 size-4" />
1248
- Archive
1249
- </DropdownMenuItem>
1250
- </DropdownMenuContent>
1251
- </DropdownMenu>
1252
- </div>
1253
- </div>
1254
-
1255
- {/* Messages */}
1256
- <div
1257
- ref={scrollRef}
1258
- onScroll={handleScroll}
1259
- className="flex flex-1 flex-col gap-4 overflow-y-auto p-4"
1260
- tabIndex={0}
1261
- >
1262
- {isLoadingMoreMessages && (
1263
- <div className="flex justify-center py-1 text-caption text-muted-foreground">
1264
- Loading older messages...
1265
- </div>
1266
- )}
1267
- {messages.length === 0 ? (
1268
- <div className="flex flex-1 flex-col items-center justify-center gap-2 text-muted-foreground">
1269
- <MessageSquare className="size-8 opacity-30" />
1270
- <p className="text-sm">No messages yet</p>
1271
- </div>
1272
- ) : (
1273
- messages.map((msg) => <ChatBubble key={msg.id} message={msg} />)
1274
- )}
1275
-
1276
- {/* AI typing indicator */}
1277
- {isAiTyping && !isClosed && (
1278
- <div className="flex gap-2.5">
1279
- <BubbleAvatar role="bot" />
1280
- <div className="flex flex-col gap-1">
1281
- <span className="text-caption text-muted-foreground">
1282
- AI Assistant
1283
- </span>
1284
- <div className="flex items-center gap-1 border border-border bg-muted/60 px-3 py-2.5">
1285
- <span className="size-1.5 animate-bounce rounded-full bg-muted-foreground [animation-delay:0ms]" />
1286
- <span className="size-1.5 animate-bounce rounded-full bg-muted-foreground [animation-delay:150ms]" />
1287
- <span className="size-1.5 animate-bounce rounded-full bg-muted-foreground [animation-delay:300ms]" />
1288
- </div>
1289
- </div>
1290
- </div>
1291
- )}
1292
- </div>
1293
-
1294
- {/* Composer / locked banner */}
1295
- {isClosed ? (
1296
- <div className="flex items-center gap-3 border-t border-border bg-muted/30 px-4 py-3 text-sm text-muted-foreground">
1297
- <Lock className="size-3.5 shrink-0" />
1298
- <span>This conversation is closed.</span>
1299
- <Button
1300
- variant="outline"
1301
- size="sm"
1302
- className="ml-auto"
1303
- onClick={onReopen}
1304
- >
1305
- Reopen
1306
- </Button>
1307
- </div>
1308
- ) : (
1309
- <ChatComposer
1310
- mode={mode}
1311
- channel={channel}
1312
- onChannelChange={onChannelChange}
1313
- isEmailIntegrated={isEmailIntegrated}
1314
- contactEmail={contact.email}
1315
- inputValue={inputValue}
1316
- onInputChange={onInputChange}
1317
- onSend={onSend}
1318
- onSendEmail={onSendEmail}
1319
- onTakeOver={onTakeOver}
1320
- onLetAiHandle={onLetAiHandle}
1321
- />
1322
- )}
1323
- </div>
1324
- );
1325
- }
1326
-
1327
- // ---------------------------------------------------------------------------
1328
- // AICollectedDataSection
1329
- // ---------------------------------------------------------------------------
1330
-
1331
- export interface AICollectedDataSectionProps {
1332
- fields: AiConvDataField[];
1333
- className?: string;
1334
- }
1335
-
1336
- export function AICollectedDataSection({
1337
- fields,
1338
- className,
1339
- }: AICollectedDataSectionProps) {
1340
- return (
1341
- <div className={cn("flex flex-col", className)}>
1342
- {fields.map((field, i) => (
1343
- <div
1344
- key={i}
1345
- className="flex items-center justify-between gap-2 border-b border-border/40 py-1.5 last:border-b-0"
1346
- >
1347
- <span className="shrink-0 text-sm text-muted-foreground">
1348
- {field.label}
1349
- </span>
1350
- <div className="flex items-center gap-1.5">
1351
- <span className="text-right text-sm font-medium text-foreground">
1352
- {field.value}
1353
- </span>
1354
- {field.confidence === "confirmed" ? (
1355
- <CheckCircle2 className="size-3 shrink-0 text-success-text" />
1356
- ) : (
1357
- <HelpCircle className="size-3 shrink-0 text-warning-text" />
1358
- )}
1359
- </div>
1360
- </div>
1361
- ))}
1362
- </div>
1363
- );
1364
- }
1365
-
1366
- // ---------------------------------------------------------------------------
1367
- // LeadInfoPanel
1368
- // ---------------------------------------------------------------------------
1369
-
1370
- const MEETING_ICON: Record<AiConvMeetingType, React.ElementType> = {
1371
- video: Video,
1372
- phone: Phone,
1373
- "in-person": MapPin,
1374
- };
1375
-
1376
- const MEETING_LABEL: Record<AiConvMeetingType, string> = {
1377
- video: "Video Call",
1378
- phone: "Phone Call",
1379
- "in-person": "In Person",
1380
- };
1381
-
1382
- const MEETING_DETAIL_ICON: Record<AiConvMeetingType, React.ElementType> = {
1383
- video: Link2,
1384
- phone: PhoneCall,
1385
- "in-person": Navigation,
1386
- };
1387
-
1388
- interface AppointmentSectionProps {
1389
- appointment: AiConvAppointmentData;
1390
- contactId: string;
1391
- isAnonymous: boolean;
1392
- onApproveAppointment?: () => void;
1393
- onDeclineAppointment?: () => void;
1394
- onRescheduleAppointment?: (contactId: string) => void;
1395
- }
1396
-
1397
- function MeetingDetailRow({
1398
- meetingType,
1399
- detail,
1400
- }: {
1401
- meetingType: AiConvMeetingType;
1402
- detail: string;
1403
- }) {
1404
- const DetailIcon = MEETING_DETAIL_ICON[meetingType];
1405
- const isLink = detail.startsWith("http");
1406
- return (
1407
- <div className="flex items-center gap-2">
1408
- <DetailIcon className="size-4 shrink-0 text-muted-foreground" />
1409
- {isLink ? (
1410
- <a
1411
- href={detail}
1412
- target="_blank"
1413
- rel="noopener noreferrer"
1414
- className="text-sm text-primary underline underline-offset-2 break-all hover:text-primary/80"
1415
- >
1416
- {detail}
1417
- </a>
1418
- ) : (
1419
- <span className="text-sm text-muted-foreground break-all">
1420
- {detail}
1421
- </span>
1422
- )}
1423
- </div>
1424
- );
1425
- }
1426
-
1427
- function AppointmentSection({
1428
- appointment,
1429
- contactId,
1430
- isAnonymous,
1431
- onApproveAppointment,
1432
- onDeclineAppointment,
1433
- onRescheduleAppointment,
1434
- }: AppointmentSectionProps) {
1435
- const AppointmentIcon = MEETING_ICON[appointment.meetingType];
1436
- const canReschedule = !isAnonymous && !!onRescheduleAppointment;
1437
-
1438
- return (
1439
- <div className="flex flex-col gap-2">
1440
- <div className="flex items-center gap-2">
1441
- <Calendar className="size-3.5 shrink-0 text-muted-foreground" />
1442
- <span className="text-sm font-medium text-foreground">
1443
- {appointment.datetime}
1444
- </span>
1445
- </div>
1446
- <div className="flex items-center gap-2">
1447
- <AppointmentIcon className="size-4 shrink-0 text-muted-foreground" />
1448
- <span className="text-sm text-muted-foreground">
1449
- {MEETING_LABEL[appointment.meetingType]}
1450
- </span>
1451
- </div>
1452
- {appointment.meetingDetail && (
1453
- <MeetingDetailRow
1454
- meetingType={appointment.meetingType}
1455
- detail={appointment.meetingDetail}
1456
- />
1457
- )}
1458
- <span
1459
- className={cn("text-sm font-medium", {
1460
- "text-warning-text": appointment.status === "requested",
1461
- "text-success-text": appointment.status === "confirmed",
1462
- "text-muted-foreground": appointment.status === "pending",
1463
- "text-destructive line-through": appointment.status === "cancelled",
1464
- })}
1465
- >
1466
- {APPOINTMENT_STATUS_LABEL[appointment.status]}
1467
- </span>
1468
-
1469
- {appointment.status === "requested" && (
1470
- <div className="flex gap-2 pt-1">
1471
- <Button size="sm" className="flex-1" onClick={onApproveAppointment}>
1472
- Approve
1473
- </Button>
1474
- <Button
1475
- variant="outline"
1476
- size="sm"
1477
- className="flex-1"
1478
- onClick={onDeclineAppointment}
1479
- >
1480
- Decline
1481
- </Button>
1482
- {canReschedule && (
1483
- <Button
1484
- variant="ghost"
1485
- size="sm"
1486
- className="flex-1"
1487
- onClick={() => onRescheduleAppointment!(contactId)}
1488
- >
1489
- Reschedule
1490
- </Button>
1491
- )}
1492
- </div>
1493
- )}
1494
-
1495
- {(appointment.status === "confirmed" ||
1496
- appointment.status === "cancelled") &&
1497
- canReschedule && (
1498
- <Button
1499
- variant="outline"
1500
- size="sm"
1501
- className="mt-1 w-full justify-start"
1502
- onClick={() => onRescheduleAppointment!(contactId)}
1503
- >
1504
- Reschedule
1505
- </Button>
1506
- )}
1507
- </div>
1508
- );
1509
- }
1510
-
1511
- function PanelSectionHeader({ children }: { children: React.ReactNode }) {
1512
- return (
1513
- <p className="mb-2.5 text-overline text-muted-foreground">{children}</p>
1514
- );
1515
- }
1516
-
1517
- function PanelSection({
1518
- children,
1519
- last = false,
1520
- }: {
1521
- children: React.ReactNode;
1522
- last?: boolean;
1523
- }) {
1524
- return (
1525
- <div className={cn("px-4 py-4", !last && "border-b border-border")}>
1526
- {children}
1527
- </div>
1528
- );
1529
- }
1530
-
1531
- export interface LeadInfoPanelProps {
1532
- contact: AiConvContact;
1533
- firstSeen?: string;
1534
- source?: string;
1535
- /** Conversation topic tag — e.g. "Buy a Home", "Refinance", "Investment". */
1536
- topic?: string;
1537
- aiFields?: AiConvDataField[];
1538
- appointment?: AiConvAppointmentData;
1539
- internalNotes?: string;
1540
- notesSaveStatus?: "idle" | "saving" | "saved";
1541
- isCollapsed?: boolean;
1542
- /** True when this lead's contact info already exists in the system. Disables Add to Contacts. */
1543
- isKnownContact?: boolean;
1544
- onAddToContacts?: () => void;
1545
- onCreateOpportunity?: () => void;
1546
- onBookAppointment?: () => void;
1547
- onApproveAppointment?: () => void;
1548
- onDeclineAppointment?: () => void;
1549
- onRescheduleAppointment?: (contactId: string) => void;
1550
- onNotesChange?: (v: string) => void;
1551
- onToggleCollapse?: () => void;
1552
- /** Mobile only — back to chat thread. */
1553
- onBack?: () => void;
1554
- className?: string;
1555
- }
1556
-
1557
- export function LeadInfoPanel({
1558
- contact,
1559
- firstSeen,
1560
- source = "Website Chatbot",
1561
- topic,
1562
- aiFields = [],
1563
- appointment,
1564
- internalNotes = "",
1565
- notesSaveStatus = "idle",
1566
- isCollapsed = false,
1567
- isKnownContact = false,
1568
- onAddToContacts,
1569
- onCreateOpportunity,
1570
- onBookAppointment,
1571
- onApproveAppointment,
1572
- onDeclineAppointment,
1573
- onRescheduleAppointment,
1574
- onNotesChange,
1575
- onToggleCollapse,
1576
- onBack,
1577
- className,
1578
- }: LeadInfoPanelProps) {
1579
- const isAnonymous = !contact.name.trim();
1580
- const addToContactsDisabled = isAnonymous || isKnownContact;
1581
-
1582
- return (
1583
- <div className={cn("flex flex-col bg-background", className)}>
1584
- {/* Panel header */}
1585
- <div
1586
- className={cn(
1587
- PANEL_HEADER_HEIGHT,
1588
- "flex items-center justify-between border-b border-border px-4",
1589
- )}
1590
- >
1591
- {/* Mobile back button */}
1592
- {onBack && (
1593
- <Button
1594
- variant="ghost"
1595
- size="icon"
1596
- className="size-8 shrink-0 md:hidden"
1597
- onClick={onBack}
1598
- aria-label="Back to conversation"
1599
- >
1600
- <ArrowLeft className="size-4" />
1601
- </Button>
1602
- )}
1603
- <span className="text-sm font-semibold text-foreground">Lead Info</span>
1604
- {onToggleCollapse && (
1605
- <Tooltip>
1606
- <TooltipTrigger
1607
- render={
1608
- <Button
1609
- variant="ghost"
1610
- size="icon"
1611
- className="size-7"
1612
- onClick={onToggleCollapse}
1613
- aria-label={isCollapsed ? "Expand panel" : "Collapse panel"}
1614
- >
1615
- <ChevronRight
1616
- className={cn(
1617
- "size-4 transition-transform duration-150",
1618
- isCollapsed && "-rotate-180",
1619
- )}
1620
- />
1621
- </Button>
1622
- }
1623
- />
1624
- <TooltipContent>
1625
- {isCollapsed ? "Expand panel" : "Collapse panel"}
1626
- </TooltipContent>
1627
- </Tooltip>
1628
- )}
1629
- </div>
1630
-
1631
- {!isCollapsed && (
1632
- <div className="flex-1 overflow-y-auto" tabIndex={0}>
1633
- <PanelSection>
1634
- <PanelSectionHeader>Contact</PanelSectionHeader>
1635
- <div className="flex items-center gap-3">
1636
- <ContactAvatar name={contact.name} size="lg" />
1637
- <div className="min-w-0 flex-1">
1638
- <p className="truncate text-sm font-semibold text-foreground">
1639
- {displayContactName(contact.name)}
1640
- </p>
1641
- <p className="text-sm text-muted-foreground">{source}</p>
1642
- {topic && (
1643
- <Badge variant="secondary" className="mt-1 text-xs">
1644
- {topic}
1645
- </Badge>
1646
- )}
1647
- </div>
1648
- </div>
1649
- {(contact.email || contact.phone || firstSeen) && (
1650
- <div className="mt-3 flex flex-col gap-1.5">
1651
- {contact.email && (
1652
- <div className="flex items-center gap-2 text-sm text-muted-foreground">
1653
- <Mail className="size-4 shrink-0" />
1654
- <a
1655
- href={`mailto:${contact.email}`}
1656
- className="truncate hover:underline"
1657
- >
1658
- {contact.email}
1659
- </a>
1660
- </div>
1661
- )}
1662
- {contact.phone && (
1663
- <div className="flex items-center gap-2 text-sm text-muted-foreground">
1664
- <PhoneCall className="size-4 shrink-0" />
1665
- <a
1666
- href={`tel:${contact.phone}`}
1667
- className="hover:underline"
1668
- >
1669
- {contact.phone}
1670
- </a>
1671
- </div>
1672
- )}
1673
- {firstSeen && (
1674
- <p className="text-sm text-muted-foreground">
1675
- First seen: {firstSeen}
1676
- </p>
1677
- )}
1678
- </div>
1679
- )}
1680
- </PanelSection>
1681
-
1682
- <PanelSection>
1683
- <PanelSectionHeader>AI-Collected Data</PanelSectionHeader>
1684
- {aiFields.length > 0 ? (
1685
- <>
1686
- <AICollectedDataSection fields={aiFields} />
1687
- <div className="mt-2.5 flex items-center gap-3 text-xs text-muted-foreground">
1688
- <span className="flex items-center gap-1">
1689
- <CheckCircle2 className="size-3 text-success-text" />
1690
- confirmed
1691
- </span>
1692
- <span className="flex items-center gap-1">
1693
- <HelpCircle className="size-3 text-warning-text" />
1694
- estimated
1695
- </span>
1696
- </div>
1697
- </>
1698
- ) : (
1699
- <p className="text-sm text-muted-foreground">
1700
- AI is still gathering information...
1701
- </p>
1702
- )}
1703
- </PanelSection>
1704
-
1705
- <PanelSection>
1706
- <PanelSectionHeader>Appointment</PanelSectionHeader>
1707
- {appointment ? (
1708
- <AppointmentSection
1709
- appointment={appointment}
1710
- contactId={contact.id}
1711
- isAnonymous={isAnonymous}
1712
- onApproveAppointment={onApproveAppointment}
1713
- onDeclineAppointment={onDeclineAppointment}
1714
- onRescheduleAppointment={onRescheduleAppointment}
1715
- />
1716
- ) : (
1717
- <Button
1718
- variant="outline"
1719
- size="sm"
1720
- className="w-full justify-start"
1721
- disabled={isAnonymous}
1722
- onClick={onBookAppointment}
1723
- >
1724
- <Plus className="mr-1.5 size-3.5" />
1725
- Book Appointment
1726
- </Button>
1727
- )}
1728
- </PanelSection>
1729
-
1730
- <PanelSection>
1731
- <PanelSectionHeader>CRM Actions</PanelSectionHeader>
1732
- <div className="flex flex-col gap-2">
1733
- <Tooltip>
1734
- <TooltipTrigger
1735
- render={
1736
- <Button
1737
- variant="outline"
1738
- size="sm"
1739
- className="w-full justify-start"
1740
- disabled={addToContactsDisabled}
1741
- onClick={onAddToContacts}
1742
- >
1743
- <UserPlus className="mr-1.5 size-3.5" />
1744
- Add to Contacts
1745
- </Button>
1746
- }
1747
- />
1748
- {isKnownContact && (
1749
- <TooltipContent>Already in contacts</TooltipContent>
1750
- )}
1751
- </Tooltip>
1752
- <Button
1753
- variant="outline"
1754
- size="sm"
1755
- className="w-full justify-start"
1756
- disabled={isAnonymous}
1757
- onClick={onCreateOpportunity}
1758
- >
1759
- <Briefcase className="mr-1.5 size-3.5" />
1760
- Add to CRM
1761
- </Button>
1762
- </div>
1763
- </PanelSection>
1764
-
1765
- <PanelSection last>
1766
- <div className="mb-2.5 flex items-center justify-between">
1767
- <p className="text-overline text-muted-foreground">
1768
- Internal Notes
1769
- </p>
1770
- {notesSaveStatus === "saving" && (
1771
- <span className="text-xs text-muted-foreground">Saving...</span>
1772
- )}
1773
- {notesSaveStatus === "saved" && (
1774
- <span className="flex items-center gap-1 text-xs text-success-text">
1775
- <CheckCircle2 className="size-3" />
1776
- Saved
1777
- </span>
1778
- )}
1779
- </div>
1780
- <Textarea
1781
- value={internalNotes}
1782
- onChange={(e) => onNotesChange?.(e.target.value)}
1783
- placeholder="Private notes — not visible to lead..."
1784
- rows={4}
1785
- className="resize-none text-sm"
1786
- />
1787
- </PanelSection>
1788
- </div>
1789
- )}
1790
- </div>
1791
- );
1792
- }
1793
-
1794
- // ---------------------------------------------------------------------------
1795
- // ConversationsPage
1796
- // ---------------------------------------------------------------------------
1797
-
1798
- export interface ConversationsPageProps {
1799
- conversations: AiConvListItemData[];
1800
- activeConversationId?: string;
1801
- /** Contact for the currently-selected conversation. */
1802
- contact?: AiConvContact;
1803
- status?: AiConvStatus;
1804
- mode?: AiConvMode;
1805
- messages?: AiConvMessage[];
1806
- aiFields?: AiConvDataField[];
1807
- appointment?: AiConvAppointmentData;
1808
- /** When the lead first contacted via the chatbot. */
1809
- leadFirstSeen?: string;
1810
- /** Traffic source label (e.g. "Website Chatbot"). */
1811
- leadSource?: string;
1812
- /** Conversation topic tag — e.g. "Buy a Home", "Refinance", "Investment". */
1813
- leadTopic?: string;
1814
- searchQuery?: string;
1815
- activeFilter?: AiConvFilterTab;
1816
- /** Filter conversation list by channel type. */
1817
- channelFilter?: AiConvChannelFilter;
1818
- /** Active reply channel — "chat" (default) or "email". */
1819
- channel?: AiConvChannel;
1820
- onChannelChange?: (channel: AiConvChannel) => void;
1821
- /**
1822
- * When true, the Email tab is shown in the composer. Defaults to false.
1823
- */
1824
- isEmailIntegrated?: boolean;
1825
- inputValue?: string;
1826
- internalNotes?: string;
1827
- showLeadPanel?: boolean;
1828
- hasMore?: boolean;
1829
- isLoadingMore?: boolean;
1830
- /** True when older messages can be loaded for the active conversation. */
1831
- hasMoreMessages?: boolean;
1832
- /** True while a `onLoadMoreMessages` request is in-flight. */
1833
- isLoadingMoreMessages?: boolean;
1834
- /** Fired when the consumer should fetch older messages for the active conversation. */
1835
- onLoadMoreMessages?: () => void;
1836
- onSelectConversation?: (id: string) => void;
1837
- onRead?: (id: string) => void;
1838
- onSearchChange?: (v: string) => void;
1839
- onFilterChange?: (f: AiConvFilterTab) => void;
1840
- onChannelFilterChange?: (f: AiConvChannelFilter) => void;
1841
- onInputChange?: (v: string) => void;
1842
- /** Fired when the user sends a chat message. */
1843
- onSend?: (content: string) => void;
1844
- /** Fired when the user sends an email. */
1845
- onSendEmail?: (payload: AiConvEmailPayload) => void;
1846
- onTakeOver?: () => void;
1847
- onLetAiHandle?: () => void;
1848
- onReopen?: () => void;
1849
- onMarkUrgent?: () => void;
1850
- onUnmarkUrgent?: () => void;
1851
- onArchive?: () => void;
1852
- onAssignToAdvisor?: () => void;
1853
- /** True when this lead is already a contact in the system. Disables Add to Contacts. */
1854
- isKnownContact?: boolean;
1855
- onAddToContacts?: () => void;
1856
- onCreateOpportunity?: () => void;
1857
- onBookAppointment?: () => void;
1858
- onApproveAppointment?: () => void;
1859
- onDeclineAppointment?: () => void;
1860
- onRescheduleAppointment?: (contactId: string) => void;
1861
- onNotesChange?: (v: string) => void;
1862
- onToggleLeadPanel?: () => void;
1863
- onLoadMore?: () => void;
1864
- isAiTyping?: boolean;
1865
- notesSaveStatus?: "idle" | "saving" | "saved";
1866
- className?: string;
1867
- }
1868
-
1869
- export function ConversationsPage({
1870
- conversations,
1871
- activeConversationId,
1872
- contact,
1873
- status = "ai-active",
1874
- mode = "ai",
1875
- messages = [],
1876
- aiFields = [],
1877
- appointment,
1878
- leadFirstSeen,
1879
- leadSource,
1880
- leadTopic,
1881
- searchQuery,
1882
- activeFilter,
1883
- channelFilter,
1884
- onChannelFilterChange,
1885
- channel,
1886
- onChannelChange,
1887
- isEmailIntegrated,
1888
- inputValue,
1889
- internalNotes,
1890
- showLeadPanel = true,
1891
- hasMore,
1892
- isLoadingMore,
1893
- hasMoreMessages,
1894
- isLoadingMoreMessages,
1895
- onLoadMoreMessages,
1896
- isAiTyping,
1897
- notesSaveStatus,
1898
- onSelectConversation,
1899
- onRead,
1900
- onSearchChange,
1901
- onFilterChange,
1902
- onInputChange,
1903
- onSend,
1904
- onSendEmail,
1905
- onTakeOver,
1906
- onLetAiHandle,
1907
- onReopen,
1908
- onMarkUrgent,
1909
- onUnmarkUrgent,
1910
- onArchive,
1911
- onAssignToAdvisor,
1912
- isKnownContact,
1913
- onAddToContacts,
1914
- onCreateOpportunity,
1915
- onBookAppointment,
1916
- onApproveAppointment,
1917
- onDeclineAppointment,
1918
- onRescheduleAppointment,
1919
- onNotesChange,
1920
- onToggleLeadPanel,
1921
- onLoadMore,
1922
- className,
1923
- }: ConversationsPageProps) {
1924
- // Mobile panel state — "list" | "chat" | "lead"
1925
- const [mobilePanel, setMobilePanel] = useState<"list" | "chat" | "lead">(
1926
- "list",
1927
- );
1928
-
1929
- const handleSelectConversation = (id: string) => {
1930
- onSelectConversation?.(id);
1931
- setMobilePanel("chat");
1932
- };
1933
-
1934
- const handleToggleLeadPanel = () => {
1935
- onToggleLeadPanel?.();
1936
- // When expanding lead panel → go to lead on mobile; collapsing → back to chat
1937
- setMobilePanel(showLeadPanel ? "chat" : "lead");
1938
- };
1939
-
1940
- return (
1941
- <TooltipProvider>
1942
- <div
1943
- className={cn("flex h-full overflow-hidden bg-background", className)}
1944
- >
1945
- {/* Left — Conversation List */}
1946
- <ConversationList
1947
- conversations={conversations}
1948
- activeId={activeConversationId}
1949
- searchQuery={searchQuery}
1950
- activeFilter={activeFilter}
1951
- channelFilter={channelFilter}
1952
- hasMore={hasMore}
1953
- isLoadingMore={isLoadingMore}
1954
- onSearchChange={onSearchChange}
1955
- onFilterChange={onFilterChange}
1956
- onChannelFilterChange={onChannelFilterChange}
1957
- onSelect={handleSelectConversation}
1958
- onRead={onRead}
1959
- onLoadMore={onLoadMore}
1960
- className={cn(
1961
- "shrink-0 md:w-[320px]",
1962
- // Mobile: full width, visible only on list panel
1963
- mobilePanel === "list" ? "flex w-full md:flex" : "hidden md:flex",
1964
- )}
1965
- />
1966
-
1967
- {/* Center — Chat Thread */}
1968
- {contact ? (
1969
- <ChatThread
1970
- key={contact.id}
1971
- contact={contact}
1972
- status={status}
1973
- mode={mode}
1974
- messages={messages}
1975
- isAiTyping={isAiTyping}
1976
- channel={channel}
1977
- onChannelChange={onChannelChange}
1978
- isEmailIntegrated={isEmailIntegrated}
1979
- inputValue={inputValue}
1980
- onInputChange={onInputChange}
1981
- onSend={onSend}
1982
- onSendEmail={onSendEmail}
1983
- onTakeOver={onTakeOver}
1984
- onLetAiHandle={onLetAiHandle}
1985
- onReopen={onReopen}
1986
- onMarkUrgent={onMarkUrgent}
1987
- onUnmarkUrgent={onUnmarkUrgent}
1988
- onArchive={onArchive}
1989
- onAssignToAdvisor={onAssignToAdvisor}
1990
- hasMoreMessages={hasMoreMessages}
1991
- isLoadingMoreMessages={isLoadingMoreMessages}
1992
- onLoadMoreMessages={onLoadMoreMessages}
1993
- onBack={() => setMobilePanel("list")}
1994
- onShowLeadInfo={() => setMobilePanel("lead")}
1995
- className={cn(
1996
- "min-w-0 flex-1 border-r border-border",
1997
- mobilePanel === "chat"
1998
- ? "flex flex-col md:flex"
1999
- : "hidden md:flex",
2000
- )}
2001
- />
2002
- ) : (
2003
- <div
2004
- className={cn(
2005
- "min-w-0 flex-1 items-center justify-center border-r border-border bg-muted/10",
2006
- mobilePanel === "chat" ? "flex md:flex" : "hidden md:flex",
2007
- )}
2008
- >
2009
- <div className="flex flex-col items-center gap-2 text-muted-foreground">
2010
- <MessageSquare className="size-10 opacity-30" />
2011
- <p className="text-sm">Select a conversation</p>
2012
- </div>
2013
- </div>
2014
- )}
2015
-
2016
- {/* Right — Lead Info Panel */}
2017
- {contact && (
2018
- <>
2019
- {/* Desktop: always in DOM, width-animated. Mobile: show/hide by mobilePanel. */}
2020
- <div
2021
- className={cn(
2022
- // Mobile: full-width, instant show/hide based on mobilePanel
2023
- mobilePanel === "lead"
2024
- ? "flex w-full shrink-0 flex-col"
2025
- : "hidden",
2026
- // Desktop: always rendered, animate width open/close
2027
- "md:block md:shrink-0 md:overflow-hidden md:transition-[width] md:duration-200 md:ease-in-out",
2028
- showLeadPanel ? "md:w-[320px]" : "md:w-0",
2029
- )}
2030
- >
2031
- <LeadInfoPanel
2032
- contact={contact}
2033
- firstSeen={leadFirstSeen}
2034
- source={leadSource}
2035
- topic={leadTopic}
2036
- aiFields={aiFields}
2037
- appointment={appointment}
2038
- internalNotes={internalNotes}
2039
- notesSaveStatus={notesSaveStatus}
2040
- isKnownContact={isKnownContact}
2041
- onAddToContacts={onAddToContacts}
2042
- onCreateOpportunity={onCreateOpportunity}
2043
- onBookAppointment={onBookAppointment}
2044
- onApproveAppointment={onApproveAppointment}
2045
- onDeclineAppointment={onDeclineAppointment}
2046
- onRescheduleAppointment={onRescheduleAppointment}
2047
- onNotesChange={onNotesChange}
2048
- onToggleCollapse={handleToggleLeadPanel}
2049
- onBack={() => setMobilePanel("chat")}
2050
- className="flex h-full w-full flex-col border-l border-border md:w-[320px]"
2051
- />
2052
- </div>
2053
-
2054
- {/* Collapsed expand button — desktop only, shown when panel is closed */}
2055
- {!showLeadPanel && onToggleLeadPanel && (
2056
- <div className="hidden shrink-0 items-start border-l border-border pt-[29px] md:flex">
2057
- <Tooltip>
2058
- <TooltipTrigger
2059
- render={
2060
- <Button
2061
- variant="ghost"
2062
- size="icon"
2063
- className="size-8"
2064
- aria-label="Show lead info"
2065
- onClick={handleToggleLeadPanel}
2066
- >
2067
- <ChevronLeft className="size-4" />
2068
- </Button>
2069
- }
2070
- />
2071
- <TooltipContent>Show lead info</TooltipContent>
2072
- </Tooltip>
2073
- </div>
2074
- )}
2075
- </>
2076
- )}
2077
- </div>
2078
- </TooltipProvider>
2079
- );
2080
- }
2081
-
2082
- // ---------------------------------------------------------------------------
2083
- // AiConvAssignAdvisorDialog
2084
- // ---------------------------------------------------------------------------
2085
-
2086
- export interface AiConvAssignAdvisorDialogProps {
2087
- open: boolean;
2088
- onOpenChange: (open: boolean) => void;
2089
- advisors: AiConvAdvisor[];
2090
- /** Currently selected advisor id */
2091
- value: string;
2092
- onValueChange: (id: string) => void;
2093
- onConfirm: () => void;
2094
- }
2095
-
2096
- export function AiConvAssignAdvisorDialog({
2097
- open,
2098
- onOpenChange,
2099
- advisors,
2100
- value,
2101
- onValueChange,
2102
- onConfirm,
2103
- }: AiConvAssignAdvisorDialogProps) {
2104
- const [search, setSearch] = useState("");
2105
- const [roleFilter, setRoleFilter] = useState("");
2106
-
2107
- const roles = Array.from(
2108
- new Set(advisors.map((a) => a.role).filter(Boolean)),
2109
- ) as string[];
2110
-
2111
- const filtered = advisors.filter(
2112
- (a) =>
2113
- a.name.toLowerCase().includes(search.toLowerCase()) &&
2114
- (!roleFilter || a.role === roleFilter),
2115
- );
2116
-
2117
- const handleOpenChange = (v: boolean) => {
2118
- onOpenChange(v);
2119
- if (!v) {
2120
- setSearch("");
2121
- setRoleFilter("");
2122
- }
2123
- };
2124
-
2125
- return (
2126
- <Dialog open={open} onOpenChange={handleOpenChange}>
2127
- <DialogContent>
2128
- <DialogHeader>
2129
- <DialogTitle>Assign to advisor</DialogTitle>
2130
- <DialogDescription>
2131
- Choose an advisor to handle this conversation.
2132
- </DialogDescription>
2133
- </DialogHeader>
2134
- <div className="flex flex-col gap-0">
2135
- {/* Role filter */}
2136
- {roles.length > 0 && (
2137
- <div className="pb-3">
2138
- <ToggleGroup
2139
- type="single"
2140
- variant="outline"
2141
- spacing={1.5}
2142
- size="sm"
2143
- value={roleFilter ? [roleFilter] : ["__all__"]}
2144
- onValueChange={(values) => {
2145
- const v = values[0];
2146
- setRoleFilter(!v || v === "__all__" ? "" : v);
2147
- }}
2148
- >
2149
- <ToggleGroupItem value="__all__">All</ToggleGroupItem>
2150
- {roles.map((role) => (
2151
- <ToggleGroupItem key={role} value={role}>
2152
- {role}
2153
- </ToggleGroupItem>
2154
- ))}
2155
- </ToggleGroup>
2156
- </div>
2157
- )}
2158
- {/* Search */}
2159
- <div className="flex items-center gap-2 border border-input px-3">
2160
- <Search className="size-4 shrink-0 text-muted-foreground" />
2161
- <input
2162
- type="text"
2163
- placeholder="Search advisors..."
2164
- value={search}
2165
- onChange={(e) => setSearch(e.target.value)}
2166
- className="h-9 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground"
2167
- />
2168
- </div>
2169
- {/* List */}
2170
- <div className="max-h-52 overflow-y-auto border border-t-0 border-input">
2171
- {filtered.length === 0 ? (
2172
- <p className="py-6 text-center text-sm text-muted-foreground">
2173
- No advisors found.
2174
- </p>
2175
- ) : (
2176
- filtered.map((advisor) => (
2177
- <button
2178
- key={advisor.id}
2179
- type="button"
2180
- onClick={() => onValueChange(advisor.id)}
2181
- className={cn(
2182
- "flex w-full items-center gap-3 px-3 py-2.5 text-left text-sm transition-colors hover:bg-muted",
2183
- value === advisor.id && "bg-muted font-medium",
2184
- )}
2185
- >
2186
- <Avatar size="sm">
2187
- <AvatarFallback className="font-semibold">
2188
- {advisor.initials}
2189
- </AvatarFallback>
2190
- </Avatar>
2191
- <div className="min-w-0 flex-1">
2192
- <p className="truncate text-sm">{advisor.name}</p>
2193
- {advisor.role && (
2194
- <p className="truncate text-xs text-muted-foreground">
2195
- {advisor.role}
2196
- </p>
2197
- )}
2198
- </div>
2199
- </button>
2200
- ))
2201
- )}
2202
- </div>
2203
- </div>
2204
- <DialogFooter>
2205
- <Button variant="outline" onClick={() => onOpenChange(false)}>
2206
- Cancel
2207
- </Button>
2208
- <Button onClick={onConfirm}>Assign</Button>
2209
- </DialogFooter>
2210
- </DialogContent>
2211
- </Dialog>
2212
- );
2213
- }