@channelhub/widget 0.1.11 → 0.1.13
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/README.md +168 -0
- package/dist/ChannelHubInbox.d.ts.map +1 -1
- package/dist/ChannelHubSettings.d.ts +3 -0
- package/dist/ChannelHubSettings.d.ts.map +1 -0
- package/dist/api.d.ts +16 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +104 -29
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4903 -2820
- package/dist/types.d.ts +224 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ChannelHubInbox.tsx +360 -67
- package/src/ChannelHubSettings.tsx +1654 -0
- package/src/api.ts +163 -2
- package/src/index.ts +18 -2
- package/src/types.ts +223 -2
package/src/ChannelHubInbox.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Component, FormEvent, createContext, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
|
-
import { AlertCircle, Check, CheckCheck, ChevronDown, ChevronRight, Image, Inbox, Info, Loader2, MoreHorizontal, Paperclip, Play, Search, Send, SlidersHorizontal, Smile, UserCheck, UserPlus, X, Zap } from 'lucide-react';
|
|
5
|
-
import { ChannelHubClient } from './api.js';
|
|
6
|
-
import
|
|
4
|
+
import { AlertCircle, ArrowLeft, Bot, Check, CheckCheck, ChevronDown, ChevronRight, Image, Inbox, Info, Loader2, MoreHorizontal, Paperclip, Play, Search, Send, Settings, SlidersHorizontal, Smile, Sparkles, UserCheck, UserPlus, X, Zap } from 'lucide-react';
|
|
5
|
+
import { ChannelHubClient, DEFAULT_TENANT_SETTINGS } from './api.js';
|
|
6
|
+
import { ChannelHubSettings } from './ChannelHubSettings.js';
|
|
7
|
+
import type { ChannelHubAgent, ChannelHubInboxHandle, ChannelHubSettingsTab, ChannelHubTenantSettings, Connection, Conversation, ContactInfoRow, Extension, ExtensionContact, ExtensionContext, Message, MessageAttachment, Page, Provider, WidgetProps } from './types.js';
|
|
7
8
|
|
|
8
9
|
type WidgetTranslations = { today: string; loadOlder: string; loading: string; noMessages: string; searchPlaceholder: string; unreadOnly: string; sendPlaceholder: string; send: string; all: string };
|
|
9
10
|
import { Avatar as UiAvatar, Button, Input, ScrollArea, Textarea } from './components/ui/index.js';
|
|
@@ -122,6 +123,7 @@ function StatusIcon({ status }: { status?: Message['status'] }) {
|
|
|
122
123
|
|
|
123
124
|
type ActiveFilters = { provider: Provider | 'all'; unreadOnly: boolean };
|
|
124
125
|
type AssignmentScope = 'all' | 'mine' | 'unassigned';
|
|
126
|
+
type LayoutMode = 'mobile' | 'tablet' | 'desktop';
|
|
125
127
|
|
|
126
128
|
function shortAgentName(name: string): string {
|
|
127
129
|
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
@@ -130,7 +132,7 @@ function shortAgentName(name: string): string {
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(function ChannelHubInbox(
|
|
133
|
-
{ apiUrl, token, theme, height, defaultConversationId, disableAttachments, disableNotificationSound, hideKeyboardHint, locale = 'vi', extensions, currentAgent, teamAgents, onNewMessage, onConversationSelect },
|
|
135
|
+
{ apiUrl, token, theme, height, defaultConversationId, disableAttachments, disableNotificationSound, hideKeyboardHint, hideSettingsButton, settingsConfig, locale = 'vi', extensions, currentAgent, teamAgents, onNewMessage, onConversationSelect },
|
|
134
136
|
ref
|
|
135
137
|
) {
|
|
136
138
|
const client = useRef(new ChannelHubClient(apiUrl, token));
|
|
@@ -139,13 +141,22 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
139
141
|
const [query, setQuery] = useState('');
|
|
140
142
|
const [assignmentScope, setAssignmentScope] = useState<AssignmentScope>('all');
|
|
141
143
|
const [sessionAgent, setSessionAgent] = useState<ChannelHubAgent | null>(null);
|
|
144
|
+
const [tenantSettings, setTenantSettings] = useState<ChannelHubTenantSettings>(DEFAULT_TENANT_SETTINGS);
|
|
145
|
+
const tenantSettingsRef = useRef<ChannelHubTenantSettings>(DEFAULT_TENANT_SETTINGS);
|
|
146
|
+
const [settingsModalTab, setSettingsModalTab] = useState<ChannelHubSettingsTab | null>(null);
|
|
147
|
+
const [templateRefreshKey, setTemplateRefreshKey] = useState(0);
|
|
142
148
|
const [activeFilters, setActiveFilters] = useState<ActiveFilters>({ provider: 'all', unreadOnly: false });
|
|
143
149
|
const [filterOpen, setFilterOpen] = useState(false);
|
|
144
150
|
const filterBtnRef = useRef<HTMLButtonElement>(null);
|
|
145
151
|
const filterPopoverRef = useRef<HTMLDivElement>(null);
|
|
146
152
|
const [popoverAnchor, setPopoverAnchor] = useState<{ top: number; left: number } | null>(null);
|
|
147
153
|
const [loading, setLoading] = useState(true); const [error, setError] = useState('');
|
|
148
|
-
const
|
|
154
|
+
const frameRef = useRef<HTMLDivElement>(null);
|
|
155
|
+
const [containerWidth, setContainerWidth] = useState<number>(() => (typeof window !== 'undefined' ? window.innerWidth : 1200));
|
|
156
|
+
const layoutMode: LayoutMode = containerWidth < 640 ? 'mobile' : containerWidth < 1024 ? 'tablet' : 'desktop';
|
|
157
|
+
const [mobileView, setMobileView] = useState<'list' | 'chat'>(() => (defaultConversationId ? 'chat' : 'list'));
|
|
158
|
+
const [infoOpen, setInfoOpen] = useState(() => (typeof window !== 'undefined' && window.innerWidth < 1024 ? false : Boolean(extensions?.length)));
|
|
159
|
+
const prevLayoutModeRef = useRef<LayoutMode>(layoutMode);
|
|
149
160
|
const [infoPanelWidth, setInfoPanelWidth] = useState(280);
|
|
150
161
|
const [isResizing, setIsResizing] = useState(false);
|
|
151
162
|
const [extRefreshKey, setExtRefreshKey] = useState(0);
|
|
@@ -154,10 +165,38 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
154
165
|
const appendMessageRef = useRef<((msg: Message) => void) | null>(null);
|
|
155
166
|
const [msgRefreshKey, setMsgRefreshKey] = useState(0);
|
|
156
167
|
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
const el = frameRef.current;
|
|
170
|
+
if (!el || typeof ResizeObserver === 'undefined') return;
|
|
171
|
+
const ro = new ResizeObserver(entries => {
|
|
172
|
+
for (const entry of entries) {
|
|
173
|
+
const w = entry.contentRect.width;
|
|
174
|
+
if (w > 0) setContainerWidth(w);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
ro.observe(el);
|
|
178
|
+
return () => ro.disconnect();
|
|
179
|
+
}, [loading, error]);
|
|
180
|
+
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (prevLayoutModeRef.current === 'desktop' && layoutMode !== 'desktop') {
|
|
183
|
+
setInfoOpen(false);
|
|
184
|
+
}
|
|
185
|
+
prevLayoutModeRef.current = layoutMode;
|
|
186
|
+
}, [layoutMode]);
|
|
187
|
+
|
|
188
|
+
const totalUnreadCount = useMemo(() => {
|
|
189
|
+
return items.filter(x => x.id !== selected?.id && (x.unreadCount ?? 0) > 0).length;
|
|
190
|
+
}, [items, selected?.id]);
|
|
191
|
+
|
|
157
192
|
const effectiveCurrentAgent = currentAgent ?? sessionAgent ?? null;
|
|
158
193
|
|
|
159
194
|
useEffect(() => {
|
|
160
195
|
client.current = new ChannelHubClient(apiUrl, token);
|
|
196
|
+
void client.current.getSettings().then(s => {
|
|
197
|
+
setTenantSettings(s);
|
|
198
|
+
tenantSettingsRef.current = s;
|
|
199
|
+
}).catch(() => undefined);
|
|
161
200
|
if (!currentAgent) {
|
|
162
201
|
void client.current.getSessionMe().then(res => {
|
|
163
202
|
if (res?.agent) setSessionAgent(res.agent);
|
|
@@ -165,6 +204,10 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
165
204
|
}
|
|
166
205
|
}, [apiUrl, token, currentAgent]);
|
|
167
206
|
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
tenantSettingsRef.current = tenantSettings;
|
|
209
|
+
}, [tenantSettings]);
|
|
210
|
+
|
|
168
211
|
const mergedTeamAgents = useMemo(() => {
|
|
169
212
|
const map = new Map<string, ChannelHubAgent>();
|
|
170
213
|
if (effectiveCurrentAgent?.id) map.set(effectiveCurrentAgent.id, effectiveCurrentAgent);
|
|
@@ -238,7 +281,7 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
238
281
|
document.addEventListener('mouseup', onUp);
|
|
239
282
|
}
|
|
240
283
|
const load = useCallback(async (next?: string) => { try { const page: Page<Conversation> = await client.current.listConversations(next); setItems(old => next ? [...old, ...page.items] : page.items); setCursor(page.nextCursor); if (!next && page.items.length) setSelected(old => old ?? (defaultConversationId ? (page.items.find(c => c.id === defaultConversationId) ?? page.items[0]) : page.items[0])); setError(''); } catch (e) { setError(e instanceof Error ? e.message : 'Không tải được hội thoại'); } finally { setLoading(false); } }, [defaultConversationId]);
|
|
241
|
-
useEffect(() => { void client.current.listConnections().then(setConnections).catch(() => undefined); void load(); const stop = client.current.connectSSE((type, data) => { if (type === 'message.new' || type === 'conversation.updated') { void load(); if (type === 'message.new') { const evtData = typeof data === 'object' && data ? data as Record<string, unknown> : {}; const evtConvId = evtData['conversationId'] ? String(evtData['conversationId']) : ''; const evtMsgId = evtData['messageId'] ? String(evtData['messageId']) : ''; const evtDirection = evtData['direction'] ? String(evtData['direction']) : ''; if (evtDirection === 'inbound' && !disableNotificationSound) playNotificationSound(); if (evtConvId && evtConvId === selectedId.current && evtMsgId && appendMessageRef.current) { const appendFn = appendMessageRef.current; void client.current.getMessage(evtMsgId).then(msg => { appendFn(msg); }).catch(() => undefined); } onNewMessage?.(evtConvId || selectedId.current || ''); } } else if (type === 'message.status_updated') { setMsgRefreshKey(k => k + 1); } }); return stop; }, [load, onNewMessage]);
|
|
284
|
+
useEffect(() => { void client.current.listConnections().then(setConnections).catch(() => undefined); void load(); const stop = client.current.connectSSE((type, data) => { if (type === 'message.new' || type === 'conversation.updated') { void load(); if (type === 'message.new') { const evtData = typeof data === 'object' && data ? data as Record<string, unknown> : {}; const evtConvId = evtData['conversationId'] ? String(evtData['conversationId']) : ''; const evtMsgId = evtData['messageId'] ? String(evtData['messageId']) : ''; const evtDirection = evtData['direction'] ? String(evtData['direction']) : ''; if (evtDirection === 'inbound' && !disableNotificationSound && tenantSettingsRef.current.inbox.soundNotification) playNotificationSound(); if (evtConvId && evtConvId === selectedId.current && evtMsgId && appendMessageRef.current) { const appendFn = appendMessageRef.current; void client.current.getMessage(evtMsgId).then(msg => { appendFn(msg); }).catch(() => undefined); } onNewMessage?.(evtConvId || selectedId.current || ''); } } else if (type === 'message.status_updated') { setMsgRefreshKey(k => k + 1); } }); return stop; }, [load, onNewMessage]);
|
|
242
285
|
useEffect(() => { selectedId.current = selected?.id; }, [selected]);
|
|
243
286
|
useEffect(() => { if (selected?.unreadCount) void client.current.markRead(selected.id).then(() => load()).catch(() => undefined); }, [selected?.id]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
244
287
|
|
|
@@ -288,28 +331,39 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
288
331
|
};
|
|
289
332
|
|
|
290
333
|
useImperativeHandle(ref, () => ({
|
|
291
|
-
openConversation: (id: string) => { const conv = items.find(c => c.id === id); if (conv) setSelected(conv); },
|
|
334
|
+
openConversation: (id: string) => { const conv = items.find(c => c.id === id); if (conv) { setSelected(conv); setMobileView('chat'); } },
|
|
292
335
|
refresh: () => void load(),
|
|
293
336
|
}), [items, load]);
|
|
294
337
|
|
|
338
|
+
const gridTemplateColumns =
|
|
339
|
+
layoutMode === 'mobile'
|
|
340
|
+
? 'minmax(0, 1fr)'
|
|
341
|
+
: layoutMode === 'tablet'
|
|
342
|
+
? 'minmax(240px, 270px) minmax(0, 1fr)'
|
|
343
|
+
: infoOpen
|
|
344
|
+
? `minmax(260px, 300px) minmax(0, 1fr) ${infoPanelWidth}px`
|
|
345
|
+
: 'minmax(260px, 300px) minmax(0, 1fr)';
|
|
346
|
+
|
|
295
347
|
const frame: React.CSSProperties = {
|
|
296
348
|
...css.frame,
|
|
349
|
+
position: 'relative',
|
|
297
350
|
height: height ?? 620,
|
|
298
351
|
...(height ? { maxHeight: 'none' } : {}),
|
|
299
352
|
fontFamily: theme?.fontFamily ?? 'Inter, ui-sans-serif, system-ui, sans-serif',
|
|
300
353
|
borderRadius: theme?.borderRadius ?? '16px',
|
|
301
|
-
gridTemplateColumns
|
|
302
|
-
? `minmax(260px, 300px) minmax(0, 1fr) ${infoPanelWidth}px`
|
|
303
|
-
: 'minmax(260px, 300px) minmax(0, 1fr)',
|
|
354
|
+
gridTemplateColumns,
|
|
304
355
|
transition: isResizing ? 'none' : 'grid-template-columns 220ms ease',
|
|
305
356
|
};
|
|
306
357
|
if (loading) return <div style={{ ...css.state, borderRadius: theme?.borderRadius ?? '16px' }}><Spinner /> Đang tải hộp thư…</div>;
|
|
307
358
|
if (error && !items.length) return <div style={{ ...css.state, color: '#b42318', borderRadius: theme?.borderRadius ?? '16px' }}><AlertCircle size={16} strokeWidth={2} /> {error}<button style={css.retry} onClick={() => { setLoading(true); void load(); }}>Thử lại</button></div>;
|
|
359
|
+
const showSidebar = layoutMode !== 'mobile' || mobileView === 'list' || !selected;
|
|
360
|
+
const showMain = layoutMode !== 'mobile' || (mobileView === 'chat' && Boolean(selected));
|
|
308
361
|
return (
|
|
309
362
|
<ApiUrlCtx.Provider value={apiUrl}>
|
|
310
363
|
<TokenCtx.Provider value={token}>
|
|
311
|
-
<div style={frame} onFocusCapture={() => { const y = window.scrollY; requestAnimationFrame(() => { if (window.scrollY !== y) window.scrollTo({ top: y, behavior: 'instant' }); }); }}>
|
|
312
|
-
|
|
364
|
+
<div ref={frameRef} style={frame} onFocusCapture={() => { const y = window.scrollY; requestAnimationFrame(() => { if (window.scrollY !== y) window.scrollTo({ top: y, behavior: 'instant' }); }); }}>
|
|
365
|
+
{showSidebar && (
|
|
366
|
+
<aside style={{ ...css.sidebar, ...(layoutMode === 'mobile' ? { borderRight: 0 } : {}) }}>
|
|
313
367
|
<div style={css.brand}>
|
|
314
368
|
<div style={{ ...css.brandMark, background: primary, overflow: 'hidden', padding: 0 }}>
|
|
315
369
|
{theme?.branding?.logoUrl
|
|
@@ -320,9 +374,18 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
320
374
|
<strong>{theme?.branding?.name ?? 'Hộp thư'}</strong>
|
|
321
375
|
{!theme?.branding?.name && <span style={css.eyebrow}>CHANNELHUB</span>}
|
|
322
376
|
</div>
|
|
323
|
-
|
|
377
|
+
{!hideSettingsButton && (
|
|
378
|
+
<Button
|
|
379
|
+
aria-label="Cài đặt"
|
|
380
|
+
title="Cài đặt Hộp thư & Trợ lý AI"
|
|
381
|
+
style={css.iconButton}
|
|
382
|
+
onClick={() => setSettingsModalTab('ai')}
|
|
383
|
+
>
|
|
384
|
+
<Settings size={16} strokeWidth={2} />
|
|
385
|
+
</Button>
|
|
386
|
+
)}
|
|
324
387
|
</div>
|
|
325
|
-
<div style={css.search}><Search size={16} strokeWidth={2} /><Input aria-label={t.searchPlaceholder} value={query} onChange={e => setQuery(e.target.value)} placeholder={t.searchPlaceholder} />{query && <button style={css.clear} onClick={() => setQuery('')} aria-label="Xóa tìm kiếm">×</button>}</div>
|
|
388
|
+
<div style={css.search}><Search size={16} strokeWidth={2} /><Input aria-label={t.searchPlaceholder} value={query} onChange={e => setQuery(e.target.value)} placeholder={t.searchPlaceholder} style={{ fontSize: layoutMode === 'mobile' ? 16 : 12 }} />{query && <button style={css.clear} onClick={() => setQuery('')} aria-label="Xóa tìm kiếm">×</button>}</div>
|
|
326
389
|
|
|
327
390
|
{/* 3-Tab Assignment Scope Bar (Tất cả | Của tôi | Chưa nhận) */}
|
|
328
391
|
<div
|
|
@@ -416,7 +479,7 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
416
479
|
{filterOpen && popoverAnchor && createPortal(
|
|
417
480
|
<div
|
|
418
481
|
ref={filterPopoverRef}
|
|
419
|
-
style={{ position: 'fixed', top: popoverAnchor.top, left: popoverAnchor.left, zIndex: 9999, background: c.white, border: `1px solid ${c.line}`, borderRadius: 10, padding: '12px 14px', boxShadow: '0 8px 24px rgba(23,32,51,.14)', minWidth: 210, fontFamily: theme?.fontFamily ?? 'Inter, ui-sans-serif, system-ui, sans-serif', fontSize: 13 }}
|
|
482
|
+
style={{ position: 'fixed', top: popoverAnchor.top, left: Math.min(popoverAnchor.left, (typeof window !== 'undefined' ? window.innerWidth : 1200) - 230), zIndex: 9999, background: c.white, border: `1px solid ${c.line}`, borderRadius: 10, padding: '12px 14px', boxShadow: '0 8px 24px rgba(23,32,51,.14)', minWidth: 210, fontFamily: theme?.fontFamily ?? 'Inter, ui-sans-serif, system-ui, sans-serif', fontSize: 13 }}
|
|
420
483
|
>
|
|
421
484
|
<div style={{ fontSize: 10, fontWeight: 700, color: c.muted, letterSpacing: 1, textTransform: 'uppercase' as const, marginBottom: 8 }}>Kênh</div>
|
|
422
485
|
{(['all', ...availableProviders] as const).map(p => (
|
|
@@ -437,11 +500,13 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
437
500
|
)}
|
|
438
501
|
|
|
439
502
|
<ScrollArea style={css.conversationList}>
|
|
440
|
-
{visible.map(x => <ConversationRow key={x.id} conversation={x} provider={connectionById.get(x.connectionId)?.provider} selected={selected?.id === x.id} primary={primary} currentAgent={effectiveCurrentAgent} onSelect={() => { setSelected(x); onConversationSelect?.(x.id); void client.current.markRead(x.id).then(() => load()).catch(() => undefined); }} />)}
|
|
503
|
+
{visible.map(x => <ConversationRow key={x.id} conversation={x} provider={connectionById.get(x.connectionId)?.provider} selected={selected?.id === x.id} primary={primary} currentAgent={effectiveCurrentAgent} onSelect={() => { setSelected(x); setMobileView('chat'); onConversationSelect?.(x.id); void client.current.markRead(x.id).then(() => load()).catch(() => undefined); }} />)}
|
|
441
504
|
{!visible.length && <div style={css.emptySmall}><div style={css.emptyIcon}><Search size={16} strokeWidth={2} /></div><strong>Không tìm thấy</strong><span>Thử từ khóa hoặc bộ lọc khác.</span></div>}
|
|
442
505
|
{cursor && <button style={css.loadMore} onClick={() => void load(cursor)}>Xem thêm hội thoại</button>}
|
|
443
506
|
</ScrollArea>
|
|
444
507
|
</aside>
|
|
508
|
+
)}
|
|
509
|
+
{showMain && (
|
|
445
510
|
<main style={css.main}>
|
|
446
511
|
{selected ? (
|
|
447
512
|
<MessagePanel
|
|
@@ -465,22 +530,123 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
|
|
|
465
530
|
onAssignAgent={(agent) => handleAssignConversation(selected, agent)}
|
|
466
531
|
onLinkContact={(extId) => handleLinkContact(selected, extId)}
|
|
467
532
|
onRefreshContactInfo={handleRefreshContactInfo}
|
|
533
|
+
layoutMode={layoutMode}
|
|
534
|
+
onBackToList={() => setMobileView('list')}
|
|
535
|
+
totalUnreadCount={totalUnreadCount}
|
|
536
|
+
tenantSettings={tenantSettings}
|
|
537
|
+
templateRefreshKey={templateRefreshKey}
|
|
538
|
+
onOpenSettings={!hideSettingsButton ? (tab) => setSettingsModalTab(tab) : undefined}
|
|
468
539
|
/>
|
|
469
540
|
) : <EmptyConversation />}
|
|
470
541
|
</main>
|
|
542
|
+
)}
|
|
471
543
|
{infoOpen && selected && (
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
544
|
+
layoutMode === 'desktop' ? (
|
|
545
|
+
<ContactInfoPanel
|
|
546
|
+
conversation={selected}
|
|
547
|
+
connection={connectionById.get(selected.connectionId)}
|
|
548
|
+
primary={primary}
|
|
549
|
+
onClose={() => setInfoOpen(false)}
|
|
550
|
+
client={client.current}
|
|
551
|
+
onStartResize={startInfoResize}
|
|
552
|
+
extensions={extensions}
|
|
553
|
+
extRefreshKey={extRefreshKey}
|
|
554
|
+
onLinkContact={(extId) => handleLinkContact(selected, extId)}
|
|
555
|
+
onRefreshContactInfo={handleRefreshContactInfo}
|
|
556
|
+
layoutMode={layoutMode}
|
|
557
|
+
/>
|
|
558
|
+
) : (
|
|
559
|
+
<div
|
|
560
|
+
onClick={() => setInfoOpen(false)}
|
|
561
|
+
style={{
|
|
562
|
+
position: 'absolute',
|
|
563
|
+
inset: 0,
|
|
564
|
+
zIndex: 50,
|
|
565
|
+
background: 'rgba(15, 23, 42, 0.32)',
|
|
566
|
+
display: 'flex',
|
|
567
|
+
justifyContent: 'flex-end',
|
|
568
|
+
}}
|
|
569
|
+
>
|
|
570
|
+
<div
|
|
571
|
+
onClick={e => e.stopPropagation()}
|
|
572
|
+
style={{
|
|
573
|
+
width: layoutMode === 'mobile' ? '100%' : 'min(320px, 85%)',
|
|
574
|
+
height: '100%',
|
|
575
|
+
background: c.white,
|
|
576
|
+
boxShadow: '-8px 0 24px rgba(15, 23, 42, 0.14)',
|
|
577
|
+
display: 'flex',
|
|
578
|
+
flexDirection: 'column',
|
|
579
|
+
}}
|
|
580
|
+
>
|
|
581
|
+
<ContactInfoPanel
|
|
582
|
+
conversation={selected}
|
|
583
|
+
connection={connectionById.get(selected.connectionId)}
|
|
584
|
+
primary={primary}
|
|
585
|
+
onClose={() => setInfoOpen(false)}
|
|
586
|
+
client={client.current}
|
|
587
|
+
onStartResize={undefined}
|
|
588
|
+
extensions={extensions}
|
|
589
|
+
extRefreshKey={extRefreshKey}
|
|
590
|
+
onLinkContact={(extId) => handleLinkContact(selected, extId)}
|
|
591
|
+
onRefreshContactInfo={handleRefreshContactInfo}
|
|
592
|
+
layoutMode={layoutMode}
|
|
593
|
+
/>
|
|
594
|
+
</div>
|
|
595
|
+
</div>
|
|
596
|
+
)
|
|
597
|
+
)}
|
|
598
|
+
|
|
599
|
+
{settingsModalTab && (
|
|
600
|
+
<div
|
|
601
|
+
onClick={() => {
|
|
602
|
+
setSettingsModalTab(null);
|
|
603
|
+
setTemplateRefreshKey(k => k + 1);
|
|
604
|
+
}}
|
|
605
|
+
style={{
|
|
606
|
+
position: 'absolute',
|
|
607
|
+
inset: 0,
|
|
608
|
+
zIndex: 80,
|
|
609
|
+
background: 'rgba(15, 23, 42, 0.45)',
|
|
610
|
+
display: 'flex',
|
|
611
|
+
alignItems: 'center',
|
|
612
|
+
justifyContent: 'center',
|
|
613
|
+
padding: layoutMode === 'mobile' ? 0 : 18,
|
|
614
|
+
}}
|
|
615
|
+
>
|
|
616
|
+
<div
|
|
617
|
+
onClick={e => e.stopPropagation()}
|
|
618
|
+
style={{
|
|
619
|
+
width: layoutMode === 'mobile' ? '100%' : 'min(840px, 100%)',
|
|
620
|
+
height: layoutMode === 'mobile' ? '100%' : 'min(620px, 100%)',
|
|
621
|
+
boxShadow: '0 24px 60px rgba(15, 23, 42, 0.25)',
|
|
622
|
+
borderRadius: layoutMode === 'mobile' ? 0 : (theme?.borderRadius ?? '16px'),
|
|
623
|
+
overflow: 'hidden',
|
|
624
|
+
display: 'flex',
|
|
625
|
+
}}
|
|
626
|
+
>
|
|
627
|
+
<ChannelHubSettings
|
|
628
|
+
apiUrl={apiUrl}
|
|
629
|
+
token={token}
|
|
630
|
+
theme={{
|
|
631
|
+
...theme,
|
|
632
|
+
borderRadius: layoutMode === 'mobile' ? '0px' : (theme?.borderRadius ?? '16px'),
|
|
633
|
+
}}
|
|
634
|
+
initialTab={settingsModalTab}
|
|
635
|
+
tabs={settingsConfig?.tabs}
|
|
636
|
+
hideTechnicalAiConfig={settingsConfig?.hideTechnicalAiConfig}
|
|
637
|
+
customParameters={settingsConfig?.customParameters}
|
|
638
|
+
starterTemplates={settingsConfig?.starterTemplates}
|
|
639
|
+
onSettingsChange={s => {
|
|
640
|
+
setTenantSettings(s);
|
|
641
|
+
tenantSettingsRef.current = s;
|
|
642
|
+
}}
|
|
643
|
+
onClose={() => {
|
|
644
|
+
setSettingsModalTab(null);
|
|
645
|
+
setTemplateRefreshKey(k => k + 1);
|
|
646
|
+
}}
|
|
647
|
+
/>
|
|
648
|
+
</div>
|
|
649
|
+
</div>
|
|
484
650
|
)}
|
|
485
651
|
</div>
|
|
486
652
|
</TokenCtx.Provider>
|
|
@@ -599,7 +765,7 @@ function ConversationRow({ conversation, provider, selected, primary, currentAge
|
|
|
599
765
|
|
|
600
766
|
type PendingAttachment = { file: File; uploading: boolean; url?: string; mimeType?: string; attachmentType?: string; objectUrl?: string };
|
|
601
767
|
|
|
602
|
-
function MessagePanel({ conversation, provider, connection, client, primary, error, onRegisterAppend, refreshKey, infoOpen, onToggleInfo, t, disableAttachments, hideKeyboardHint, extensions, currentAgent, teamAgents, onAssignAgent, onLinkContact, onRefreshContactInfo }: { conversation: Conversation; provider?: Provider; connection?: Connection; client: ChannelHubClient; primary: string; error: string; onRegisterAppend?: (fn: ((msg: Message) => void) | null) => void; refreshKey?: number; infoOpen: boolean; onToggleInfo: () => void; t: WidgetTranslations; disableAttachments?: boolean; hideKeyboardHint?: boolean; extensions?: Extension[]; currentAgent?: ChannelHubAgent | null; teamAgents?: ChannelHubAgent[]; onAssignAgent: (agent: ChannelHubAgent | null) => Promise<void>; onLinkContact: (externalId: string | null) => Promise<void>; onRefreshContactInfo: () => void }) {
|
|
768
|
+
function MessagePanel({ conversation, provider, connection, client, primary, error, onRegisterAppend, refreshKey, infoOpen, onToggleInfo, t, disableAttachments, hideKeyboardHint, extensions, currentAgent, teamAgents, onAssignAgent, onLinkContact, onRefreshContactInfo, layoutMode = 'desktop', onBackToList, totalUnreadCount = 0, tenantSettings = DEFAULT_TENANT_SETTINGS, templateRefreshKey = 0, onOpenSettings }: { conversation: Conversation; provider?: Provider; connection?: Connection; client: ChannelHubClient; primary: string; error: string; onRegisterAppend?: (fn: ((msg: Message) => void) | null) => void; refreshKey?: number; infoOpen: boolean; onToggleInfo: () => void; t: WidgetTranslations; disableAttachments?: boolean; hideKeyboardHint?: boolean; extensions?: Extension[]; currentAgent?: ChannelHubAgent | null; teamAgents?: ChannelHubAgent[]; onAssignAgent: (agent: ChannelHubAgent | null) => Promise<void>; onLinkContact: (externalId: string | null) => Promise<void>; onRefreshContactInfo: () => void; layoutMode?: LayoutMode; onBackToList?: () => void; totalUnreadCount?: number; tenantSettings?: ChannelHubTenantSettings; templateRefreshKey?: number; onOpenSettings?: (tab: ChannelHubSettingsTab) => void }) {
|
|
603
769
|
const [messages, setMessages] = useState<Message[]>([]); const [cursor, setCursor] = useState<string>(); const [text, setText] = useState(''); const [loading, setLoading] = useState(true); const [sending, setSending] = useState(false); const [sendError, setSendError] = useState(''); const messageAreaRef = useRef<HTMLDivElement>(null); const name = conversation.contactName ?? conversation.subject ?? conversation.providerConversationKey;
|
|
604
770
|
const fileImageRef = useRef<HTMLInputElement>(null);
|
|
605
771
|
const fileDocRef = useRef<HTMLInputElement>(null);
|
|
@@ -648,7 +814,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
648
814
|
|
|
649
815
|
useEffect(() => {
|
|
650
816
|
void client.listCannedResponses().then(setTemplates).catch(() => undefined);
|
|
651
|
-
}, [client]);
|
|
817
|
+
}, [client, templateRefreshKey]);
|
|
652
818
|
|
|
653
819
|
useEffect(() => {
|
|
654
820
|
if (!templateOpen) return;
|
|
@@ -718,7 +884,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
718
884
|
: [];
|
|
719
885
|
if (!value && !attachments.length || sending) return;
|
|
720
886
|
setSending(true); setSendError('');
|
|
721
|
-
if (!conversation.assignedAgent && currentAgent) {
|
|
887
|
+
if (!conversation.assignedAgent && currentAgent && tenantSettings.inbox.autoAssignOnFirstReply) {
|
|
722
888
|
void onAssignAgent(currentAgent);
|
|
723
889
|
}
|
|
724
890
|
const optimisticId = `optimistic-${Date.now()}`;
|
|
@@ -784,10 +950,53 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
784
950
|
}
|
|
785
951
|
|
|
786
952
|
const canSend = !sending && (text.trim().length > 0 || (pendingAttachment?.url != null && !pendingAttachment.uploading));
|
|
953
|
+
const toolbarBtnStyle: React.CSSProperties = layoutMode === 'desktop'
|
|
954
|
+
? css.toolbarBtn
|
|
955
|
+
: { ...css.toolbarBtn, width: 32, height: 32 };
|
|
787
956
|
|
|
788
957
|
return (
|
|
789
958
|
<section style={css.chat}>
|
|
790
|
-
<header style={css.chatHeader}>
|
|
959
|
+
<header style={{ ...css.chatHeader, ...(layoutMode === 'mobile' ? { padding: '0 10px 0 8px', gap: 8 } : {}) }}>
|
|
960
|
+
{layoutMode === 'mobile' && (
|
|
961
|
+
<button
|
|
962
|
+
type="button"
|
|
963
|
+
onClick={onBackToList}
|
|
964
|
+
aria-label="Quay lại danh sách"
|
|
965
|
+
style={{
|
|
966
|
+
...css.iconButton,
|
|
967
|
+
width: 36,
|
|
968
|
+
height: 36,
|
|
969
|
+
marginLeft: 0,
|
|
970
|
+
position: 'relative',
|
|
971
|
+
flexShrink: 0,
|
|
972
|
+
color: c.ink,
|
|
973
|
+
}}
|
|
974
|
+
>
|
|
975
|
+
<ArrowLeft size={18} strokeWidth={2.2} />
|
|
976
|
+
{totalUnreadCount > 0 && (
|
|
977
|
+
<span
|
|
978
|
+
style={{
|
|
979
|
+
position: 'absolute',
|
|
980
|
+
top: 3,
|
|
981
|
+
right: 3,
|
|
982
|
+
minWidth: 15,
|
|
983
|
+
height: 15,
|
|
984
|
+
borderRadius: 999,
|
|
985
|
+
background: '#ef4444',
|
|
986
|
+
color: '#fff',
|
|
987
|
+
fontSize: 9,
|
|
988
|
+
fontWeight: 800,
|
|
989
|
+
display: 'inline-grid',
|
|
990
|
+
placeItems: 'center',
|
|
991
|
+
padding: '0 3px',
|
|
992
|
+
border: `1.5px solid ${c.white}`,
|
|
993
|
+
}}
|
|
994
|
+
>
|
|
995
|
+
{totalUnreadCount > 99 ? '99+' : totalUnreadCount}
|
|
996
|
+
</span>
|
|
997
|
+
)}
|
|
998
|
+
</button>
|
|
999
|
+
)}
|
|
791
1000
|
<ContactAvatar name={name} color={primary} image={conversation.contactPictureUrl} provider={provider} />
|
|
792
1001
|
<div style={css.contact}>
|
|
793
1002
|
<strong style={css.contactName}>{name}</strong>
|
|
@@ -816,7 +1025,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
816
1025
|
}}
|
|
817
1026
|
>
|
|
818
1027
|
<UserPlus size={12} strokeWidth={2.2} />
|
|
819
|
-
<span
|
|
1028
|
+
<span>{layoutMode === 'mobile' ? '+ Nhận' : '+ Nhận phụ trách'}</span>
|
|
820
1029
|
</button>
|
|
821
1030
|
{(teamAgents?.length ?? 0) > 1 && (
|
|
822
1031
|
<button
|
|
@@ -878,8 +1087,8 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
878
1087
|
? <img src={conversation.assignedAgent.avatarUrl} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
|
|
879
1088
|
: initials(conversation.assignedAgent.name)}
|
|
880
1089
|
</span>
|
|
881
|
-
<span style={{ color: c.muted, fontWeight: 500 }}>Phụ trách:</span>
|
|
882
|
-
<span style={{ maxWidth: 110, overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
|
1090
|
+
{layoutMode !== 'mobile' && <span style={{ color: c.muted, fontWeight: 500 }}>Phụ trách:</span>}
|
|
1091
|
+
<span style={{ maxWidth: layoutMode === 'mobile' ? 76 : 110, overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
|
883
1092
|
{shortAgentName(conversation.assignedAgent.name)}
|
|
884
1093
|
</span>
|
|
885
1094
|
</>
|
|
@@ -1040,9 +1249,11 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1040
1249
|
)}
|
|
1041
1250
|
</div>
|
|
1042
1251
|
|
|
1043
|
-
|
|
1044
|
-
<
|
|
1045
|
-
|
|
1252
|
+
{layoutMode !== 'mobile' && (
|
|
1253
|
+
<button style={css.iconButton} aria-label="Thêm tùy chọn">
|
|
1254
|
+
<MoreHorizontal size={16} strokeWidth={2} />
|
|
1255
|
+
</button>
|
|
1256
|
+
)}
|
|
1046
1257
|
<button
|
|
1047
1258
|
style={{
|
|
1048
1259
|
...css.iconButton,
|
|
@@ -1097,9 +1308,37 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1097
1308
|
);
|
|
1098
1309
|
})}
|
|
1099
1310
|
</ScrollArea>
|
|
1100
|
-
{/* Quick reply chips */}
|
|
1101
|
-
<div style={{ display: 'flex', gap: 6, flexWrap: '
|
|
1102
|
-
{
|
|
1311
|
+
{/* Quick reply chips & AI Mode Status Badge */}
|
|
1312
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'nowrap', overflowX: 'auto', WebkitOverflowScrolling: 'touch', scrollbarWidth: 'none', padding: '6px 14px 2px', borderTop: `1px solid ${c.line}` }}>
|
|
1313
|
+
{tenantSettings.ai.mode !== 'off' && (
|
|
1314
|
+
<button
|
|
1315
|
+
type="button"
|
|
1316
|
+
onClick={() => onOpenSettings?.('ai')}
|
|
1317
|
+
title="Cấu hình Trợ lý AI"
|
|
1318
|
+
style={{
|
|
1319
|
+
display: 'inline-flex',
|
|
1320
|
+
alignItems: 'center',
|
|
1321
|
+
gap: 4,
|
|
1322
|
+
fontSize: 10.5,
|
|
1323
|
+
fontWeight: 700,
|
|
1324
|
+
padding: '3px 9px',
|
|
1325
|
+
borderRadius: 999,
|
|
1326
|
+
background: tenantSettings.ai.mode === 'autopilot' ? '#ecfdf5' : '#f5f3ff',
|
|
1327
|
+
color: tenantSettings.ai.mode === 'autopilot' ? '#059669' : '#7c3aed',
|
|
1328
|
+
border: tenantSettings.ai.mode === 'autopilot' ? '1px solid #a7f3d0' : '1px solid #ddd6fe',
|
|
1329
|
+
cursor: onOpenSettings ? 'pointer' : 'default',
|
|
1330
|
+
whiteSpace: 'nowrap' as const,
|
|
1331
|
+
flexShrink: 0,
|
|
1332
|
+
}}
|
|
1333
|
+
>
|
|
1334
|
+
{tenantSettings.ai.mode === 'autopilot' ? <Bot size={11} /> : <Sparkles size={11} />}
|
|
1335
|
+
<span>{tenantSettings.ai.mode === 'autopilot' ? 'AI Autopilot' : 'AI Copilot'}</span>
|
|
1336
|
+
</button>
|
|
1337
|
+
)}
|
|
1338
|
+
{(tenantSettings.inbox.quickReplies?.length
|
|
1339
|
+
? tenantSettings.inbox.quickReplies
|
|
1340
|
+
: ['Cảm ơn bạn đã liên hệ 🙏', 'Mình sẽ kiểm tra ngay', 'Vui lòng chờ 1-2 phút']
|
|
1341
|
+
).map(chip => (
|
|
1103
1342
|
<button
|
|
1104
1343
|
key={chip}
|
|
1105
1344
|
type="button"
|
|
@@ -1109,6 +1348,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1109
1348
|
background: `${primary}0f`, color: primary,
|
|
1110
1349
|
border: `1px solid ${primary}33`,
|
|
1111
1350
|
cursor: 'pointer', whiteSpace: 'nowrap' as const,
|
|
1351
|
+
flexShrink: 0,
|
|
1112
1352
|
}}
|
|
1113
1353
|
>
|
|
1114
1354
|
{chip}
|
|
@@ -1130,6 +1370,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1130
1370
|
borderRadius: 12,
|
|
1131
1371
|
boxShadow: '0 8px 24px rgba(23,32,51,.14)',
|
|
1132
1372
|
width: 280,
|
|
1373
|
+
maxWidth: 'calc(100vw - 28px)',
|
|
1133
1374
|
overflow: 'hidden',
|
|
1134
1375
|
fontFamily: 'inherit',
|
|
1135
1376
|
}}
|
|
@@ -1187,19 +1428,43 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1187
1428
|
borderRadius: 12,
|
|
1188
1429
|
boxShadow: '0 8px 24px rgba(23,32,51,.14)',
|
|
1189
1430
|
width: 300,
|
|
1431
|
+
maxWidth: 'calc(100vw - 28px)',
|
|
1190
1432
|
overflow: 'hidden',
|
|
1191
1433
|
fontFamily: 'inherit',
|
|
1192
1434
|
}}
|
|
1193
1435
|
>
|
|
1194
|
-
<div style={{ padding: '8px 10px', borderBottom: `1px solid ${c.line}
|
|
1436
|
+
<div style={{ padding: '8px 10px', borderBottom: `1px solid ${c.line}`, display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
1195
1437
|
<input
|
|
1196
1438
|
autoFocus
|
|
1197
1439
|
type="text"
|
|
1198
1440
|
placeholder="Tìm template…"
|
|
1199
1441
|
value={templateSearch}
|
|
1200
1442
|
onChange={e => setTemplateSearch(e.target.value)}
|
|
1201
|
-
style={{
|
|
1443
|
+
style={{ flex: 1, minWidth: 0, boxSizing: 'border-box' as const, border: `1px solid ${c.line}`, borderRadius: 7, padding: '5px 8px', fontSize: 12, outline: 'none', fontFamily: 'inherit', color: c.ink }}
|
|
1202
1444
|
/>
|
|
1445
|
+
{onOpenSettings && (
|
|
1446
|
+
<button
|
|
1447
|
+
type="button"
|
|
1448
|
+
onClick={() => {
|
|
1449
|
+
setTemplateOpen(false);
|
|
1450
|
+
onOpenSettings('templates');
|
|
1451
|
+
}}
|
|
1452
|
+
style={{
|
|
1453
|
+
border: `1px solid ${primary}33`,
|
|
1454
|
+
background: `${primary}0f`,
|
|
1455
|
+
color: primary,
|
|
1456
|
+
borderRadius: 7,
|
|
1457
|
+
padding: '5px 8px',
|
|
1458
|
+
fontSize: 11,
|
|
1459
|
+
fontWeight: 600,
|
|
1460
|
+
cursor: 'pointer',
|
|
1461
|
+
whiteSpace: 'nowrap' as const,
|
|
1462
|
+
flexShrink: 0,
|
|
1463
|
+
}}
|
|
1464
|
+
>
|
|
1465
|
+
+ Quản lý mẫu câu
|
|
1466
|
+
</button>
|
|
1467
|
+
)}
|
|
1203
1468
|
</div>
|
|
1204
1469
|
<div style={{ maxHeight: 220, overflowY: 'auto' }}>
|
|
1205
1470
|
{(() => {
|
|
@@ -1255,19 +1520,19 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1255
1520
|
type="button"
|
|
1256
1521
|
title="Chèn emoji"
|
|
1257
1522
|
onClick={() => setEmojiOpen(o => !o)}
|
|
1258
|
-
style={{ ...
|
|
1523
|
+
style={{ ...toolbarBtnStyle, background: emojiOpen ? `${primary}18` : 'transparent', color: emojiOpen ? primary : '#9ca3af' }}
|
|
1259
1524
|
>
|
|
1260
1525
|
<Smile size={13} strokeWidth={2} />
|
|
1261
1526
|
</button>
|
|
1262
1527
|
{/* Image/Video button */}
|
|
1263
1528
|
{!disableAttachments && (
|
|
1264
|
-
<button type="button" title="Gửi ảnh / video" aria-label="Gửi ảnh hoặc video" style={
|
|
1529
|
+
<button type="button" title="Gửi ảnh / video" aria-label="Gửi ảnh hoặc video" style={toolbarBtnStyle} onClick={() => fileImageRef.current?.click()}>
|
|
1265
1530
|
<Image size={13} strokeWidth={2} />
|
|
1266
1531
|
</button>
|
|
1267
1532
|
)}
|
|
1268
1533
|
{/* File button */}
|
|
1269
1534
|
{!disableAttachments && (
|
|
1270
|
-
<button type="button" title="Gửi tệp đính kèm" aria-label="Gửi tệp đính kèm" style={
|
|
1535
|
+
<button type="button" title="Gửi tệp đính kèm" aria-label="Gửi tệp đính kèm" style={toolbarBtnStyle} onClick={() => fileDocRef.current?.click()}>
|
|
1271
1536
|
<Paperclip size={13} strokeWidth={2} />
|
|
1272
1537
|
</button>
|
|
1273
1538
|
)}
|
|
@@ -1283,7 +1548,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1283
1548
|
type="button"
|
|
1284
1549
|
title="Template nhanh"
|
|
1285
1550
|
onClick={() => { setTemplateOpen(o => !o); setTemplateSearch(''); }}
|
|
1286
|
-
style={{ ...
|
|
1551
|
+
style={{ ...toolbarBtnStyle, background: templateOpen ? `${primary}18` : 'transparent', color: templateOpen ? primary : '#9ca3af' }}
|
|
1287
1552
|
>
|
|
1288
1553
|
<Zap size={13} strokeWidth={2} />
|
|
1289
1554
|
</button>
|
|
@@ -1291,12 +1556,12 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1291
1556
|
<span style={{ width: 1, height: 14, background: '#e5e7eb', margin: '0 2px' }} />
|
|
1292
1557
|
{/* Bold */}
|
|
1293
1558
|
<button type="button" title="In đậm" onClick={() => setBoldActive(b => !b)}
|
|
1294
|
-
style={{ ...
|
|
1559
|
+
style={{ ...toolbarBtnStyle, fontWeight: 700, fontSize: 12, background: boldActive ? `${primary}18` : 'transparent', color: boldActive ? primary : '#9ca3af', border: boldActive ? `1px solid ${primary}33` : '1px solid transparent' }}>
|
|
1295
1560
|
B
|
|
1296
1561
|
</button>
|
|
1297
1562
|
{/* Italic */}
|
|
1298
1563
|
<button type="button" title="Nghiêng" onClick={() => setItalicActive(i => !i)}
|
|
1299
|
-
style={{ ...
|
|
1564
|
+
style={{ ...toolbarBtnStyle, fontStyle: 'italic', fontSize: 12, background: italicActive ? `${primary}18` : 'transparent', color: italicActive ? primary : '#9ca3af', border: italicActive ? `1px solid ${primary}33` : '1px solid transparent' }}>
|
|
1300
1565
|
I
|
|
1301
1566
|
</button>
|
|
1302
1567
|
{Boolean(extensions?.some(e => (e.toolbarActions?.length ?? 0) > 0)) && (
|
|
@@ -1324,7 +1589,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1324
1589
|
lineHeight: 1.2,
|
|
1325
1590
|
whiteSpace: 'nowrap',
|
|
1326
1591
|
}
|
|
1327
|
-
:
|
|
1592
|
+
: toolbarBtnStyle
|
|
1328
1593
|
}
|
|
1329
1594
|
onClick={() => {
|
|
1330
1595
|
const insertText = (snippet: string) => {
|
|
@@ -1365,7 +1630,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1365
1630
|
background: 'transparent',
|
|
1366
1631
|
color: c.ink,
|
|
1367
1632
|
padding: '8px 12px 4px',
|
|
1368
|
-
font: 'inherit', fontSize: 13, lineHeight: 1.45,
|
|
1633
|
+
font: 'inherit', fontSize: layoutMode === 'mobile' ? 16 : 13, lineHeight: 1.45,
|
|
1369
1634
|
fontStyle: italicActive ? 'italic' : 'normal',
|
|
1370
1635
|
fontWeight: boldActive ? 700 : 400,
|
|
1371
1636
|
}}
|
|
@@ -1381,7 +1646,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
|
|
|
1381
1646
|
{text.length}/1000
|
|
1382
1647
|
</span>
|
|
1383
1648
|
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
1384
|
-
{!hideKeyboardHint && <span style={{ fontSize: 10, color: '#9ca3af' }}>↵ Gửi · ⇧↵ Xuống dòng</span>}
|
|
1649
|
+
{!hideKeyboardHint && layoutMode === 'desktop' && <span style={{ fontSize: 10, color: '#9ca3af' }}>↵ Gửi · ⇧↵ Xuống dòng</span>}
|
|
1385
1650
|
<button
|
|
1386
1651
|
disabled={!canSend}
|
|
1387
1652
|
aria-label="Gửi tin nhắn"
|
|
@@ -1541,6 +1806,7 @@ function ContactInfoPanel({
|
|
|
1541
1806
|
extRefreshKey,
|
|
1542
1807
|
onLinkContact,
|
|
1543
1808
|
onRefreshContactInfo,
|
|
1809
|
+
layoutMode = 'desktop',
|
|
1544
1810
|
}: {
|
|
1545
1811
|
conversation: Conversation;
|
|
1546
1812
|
connection?: Connection;
|
|
@@ -1552,6 +1818,7 @@ function ContactInfoPanel({
|
|
|
1552
1818
|
extRefreshKey?: number;
|
|
1553
1819
|
onLinkContact: (externalId: string | null) => Promise<void>;
|
|
1554
1820
|
onRefreshContactInfo: () => void;
|
|
1821
|
+
layoutMode?: LayoutMode;
|
|
1555
1822
|
}) {
|
|
1556
1823
|
const name = conversation.contactName ?? conversation.subject ?? conversation.providerConversationKey;
|
|
1557
1824
|
const provider = connection?.provider;
|
|
@@ -1559,6 +1826,7 @@ function ContactInfoPanel({
|
|
|
1559
1826
|
const [expanded, setExpanded] = useState<Record<string, boolean>>({ channel: true, stats: false, extra: true });
|
|
1560
1827
|
const toggle = (key: string) => setExpanded(e => ({ ...e, [key]: !e[key] }));
|
|
1561
1828
|
const [noteText, setNoteText] = useState('');
|
|
1829
|
+
const [savedNoteText, setSavedNoteText] = useState('');
|
|
1562
1830
|
const [noteSaving, setNoteSaving] = useState(false);
|
|
1563
1831
|
const [noteSaved, setNoteSaved] = useState(false);
|
|
1564
1832
|
const [noteError, setNoteError] = useState('');
|
|
@@ -1567,10 +1835,16 @@ function ContactInfoPanel({
|
|
|
1567
1835
|
|
|
1568
1836
|
useEffect(() => {
|
|
1569
1837
|
setNoteText('');
|
|
1838
|
+
setSavedNoteText('');
|
|
1570
1839
|
setNoteSaved(false);
|
|
1571
1840
|
setNoteError('');
|
|
1572
1841
|
client.getNote(conversation.id)
|
|
1573
|
-
.then(note => {
|
|
1842
|
+
.then(note => {
|
|
1843
|
+
if (note) {
|
|
1844
|
+
setNoteText(note.content);
|
|
1845
|
+
setSavedNoteText(note.content);
|
|
1846
|
+
}
|
|
1847
|
+
})
|
|
1574
1848
|
.catch(() => undefined);
|
|
1575
1849
|
}, [conversation.id, client]);
|
|
1576
1850
|
|
|
@@ -1599,12 +1873,16 @@ function ContactInfoPanel({
|
|
|
1599
1873
|
return () => { cancelled = true; };
|
|
1600
1874
|
}, [conversation.id, conversation.contactExternalId, extensions, extRefreshKey, hasExtContactRows, provider, onLinkContact, onRefreshContactInfo, client]);
|
|
1601
1875
|
|
|
1876
|
+
const isNoteDirty = noteText.trim() !== savedNoteText.trim() && noteText.trim().length > 0;
|
|
1877
|
+
|
|
1602
1878
|
async function saveNote() {
|
|
1603
|
-
if (!
|
|
1879
|
+
if (!isNoteDirty || noteSaving) return;
|
|
1604
1880
|
setNoteSaving(true);
|
|
1605
1881
|
setNoteError('');
|
|
1606
1882
|
try {
|
|
1607
|
-
|
|
1883
|
+
const trimmed = noteText.trim();
|
|
1884
|
+
await client.upsertNote(conversation.id, trimmed);
|
|
1885
|
+
setSavedNoteText(trimmed);
|
|
1608
1886
|
setNoteSaved(true);
|
|
1609
1887
|
setTimeout(() => setNoteSaved(false), 2000);
|
|
1610
1888
|
} catch {
|
|
@@ -1615,13 +1893,15 @@ function ContactInfoPanel({
|
|
|
1615
1893
|
}
|
|
1616
1894
|
|
|
1617
1895
|
return (
|
|
1618
|
-
<aside style={{ ...css.infoPanel, position: 'relative' }}>
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1896
|
+
<aside style={{ ...css.infoPanel, position: 'relative', ...(layoutMode !== 'desktop' ? { flex: 1, borderLeft: 0 } : {}) }}>
|
|
1897
|
+
{onStartResize && (
|
|
1898
|
+
<div
|
|
1899
|
+
onMouseDown={onStartResize}
|
|
1900
|
+
style={{ position: 'absolute', left: 0, top: 0, bottom: 0, width: 4, cursor: 'col-resize', zIndex: 1 }}
|
|
1901
|
+
onMouseEnter={e => { (e.currentTarget as HTMLElement).style.background = 'rgba(0,0,0,0.07)'; }}
|
|
1902
|
+
onMouseLeave={e => { (e.currentTarget as HTMLElement).style.background = ''; }}
|
|
1903
|
+
/>
|
|
1904
|
+
)}
|
|
1625
1905
|
<div style={css.infoPanelHeader}>
|
|
1626
1906
|
<span style={{ fontWeight: 600, fontSize: 13, color: c.ink }}>Thông tin liên hệ</span>
|
|
1627
1907
|
<button style={css.iconButton} onClick={onClose} aria-label="Đóng">
|
|
@@ -1761,8 +2041,8 @@ function ContactInfoPanel({
|
|
|
1761
2041
|
</button>
|
|
1762
2042
|
);
|
|
1763
2043
|
})}
|
|
1764
|
-
<div style={{ border: `1px solid ${c.line}`, borderRadius: 10, background:
|
|
1765
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '7px 10px', borderBottom:
|
|
2044
|
+
<div style={{ border: `1px solid ${c.line}`, borderRadius: 10, background: c.white, overflow: 'hidden' }}>
|
|
2045
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '7px 10px', borderBottom: `1px solid ${c.line}`, background: c.surface, fontSize: 11, fontWeight: 600, color: c.muted }}>
|
|
1766
2046
|
Ghi chú nội bộ
|
|
1767
2047
|
</div>
|
|
1768
2048
|
<textarea
|
|
@@ -1770,7 +2050,7 @@ function ContactInfoPanel({
|
|
|
1770
2050
|
onChange={e => setNoteText(e.target.value)}
|
|
1771
2051
|
placeholder="Nhập ghi chú..."
|
|
1772
2052
|
rows={3}
|
|
1773
|
-
style={{ display: 'block', width: '100%', boxSizing: 'border-box' as const, border: 0, outline: 0, background:
|
|
2053
|
+
style={{ display: 'block', width: '100%', boxSizing: 'border-box' as const, border: 0, outline: 0, background: c.white, resize: 'none' as const, padding: '8px 10px', font: 'inherit', fontSize: layoutMode === 'mobile' ? 16 : 12, color: c.ink, lineHeight: 1.5 }}
|
|
1774
2054
|
/>
|
|
1775
2055
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 10px 6px' }}>
|
|
1776
2056
|
{noteSaved
|
|
@@ -1779,8 +2059,21 @@ function ContactInfoPanel({
|
|
|
1779
2059
|
? <span style={{ fontSize: 11, color: '#ef4444' }}>{noteError}</span>
|
|
1780
2060
|
: <span />
|
|
1781
2061
|
}
|
|
1782
|
-
<button
|
|
1783
|
-
|
|
2062
|
+
<button
|
|
2063
|
+
type="button"
|
|
2064
|
+
onClick={() => { void saveNote(); }}
|
|
2065
|
+
disabled={!isNoteDirty || noteSaving}
|
|
2066
|
+
style={{
|
|
2067
|
+
padding: '4px 12px',
|
|
2068
|
+
border: 0,
|
|
2069
|
+
borderRadius: 7,
|
|
2070
|
+
fontSize: 12,
|
|
2071
|
+
fontWeight: 600,
|
|
2072
|
+
background: isNoteDirty && !noteSaving ? primary : '#f1f5f9',
|
|
2073
|
+
color: isNoteDirty && !noteSaving ? '#fff' : '#94a3b8',
|
|
2074
|
+
cursor: isNoteDirty && !noteSaving ? 'pointer' : 'not-allowed',
|
|
2075
|
+
}}
|
|
2076
|
+
>
|
|
1784
2077
|
{noteSaving ? 'Đang lưu…' : 'Lưu ghi chú'}
|
|
1785
2078
|
</button>
|
|
1786
2079
|
</div>
|