@channelhub/widget 0.1.11 → 0.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@channelhub/widget",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Embeddable chat inbox widget for ChannelHub",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,7 +1,7 @@
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';
4
+ import { AlertCircle, ArrowLeft, Check, CheckCheck, ChevronDown, ChevronRight, Image, Inbox, Info, Loader2, MoreHorizontal, Paperclip, Play, Search, Send, SlidersHorizontal, Smile, UserCheck, UserPlus, X, Zap } from 'lucide-react';
5
5
  import { ChannelHubClient } from './api.js';
6
6
  import type { ChannelHubAgent, ChannelHubInboxHandle, Connection, Conversation, ContactInfoRow, Extension, ExtensionContact, ExtensionContext, Message, MessageAttachment, Page, Provider, WidgetProps } from './types.js';
7
7
 
@@ -122,6 +122,7 @@ function StatusIcon({ status }: { status?: Message['status'] }) {
122
122
 
123
123
  type ActiveFilters = { provider: Provider | 'all'; unreadOnly: boolean };
124
124
  type AssignmentScope = 'all' | 'mine' | 'unassigned';
125
+ type LayoutMode = 'mobile' | 'tablet' | 'desktop';
125
126
 
126
127
  function shortAgentName(name: string): string {
127
128
  const parts = name.trim().split(/\s+/).filter(Boolean);
@@ -145,7 +146,12 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
145
146
  const filterPopoverRef = useRef<HTMLDivElement>(null);
146
147
  const [popoverAnchor, setPopoverAnchor] = useState<{ top: number; left: number } | null>(null);
147
148
  const [loading, setLoading] = useState(true); const [error, setError] = useState('');
148
- const [infoOpen, setInfoOpen] = useState(() => Boolean(extensions?.length));
149
+ const frameRef = useRef<HTMLDivElement>(null);
150
+ const [containerWidth, setContainerWidth] = useState<number>(() => (typeof window !== 'undefined' ? window.innerWidth : 1200));
151
+ const layoutMode: LayoutMode = containerWidth < 640 ? 'mobile' : containerWidth < 1024 ? 'tablet' : 'desktop';
152
+ const [mobileView, setMobileView] = useState<'list' | 'chat'>(() => (defaultConversationId ? 'chat' : 'list'));
153
+ const [infoOpen, setInfoOpen] = useState(() => (typeof window !== 'undefined' && window.innerWidth < 1024 ? false : Boolean(extensions?.length)));
154
+ const prevLayoutModeRef = useRef<LayoutMode>(layoutMode);
149
155
  const [infoPanelWidth, setInfoPanelWidth] = useState(280);
150
156
  const [isResizing, setIsResizing] = useState(false);
151
157
  const [extRefreshKey, setExtRefreshKey] = useState(0);
@@ -154,6 +160,30 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
154
160
  const appendMessageRef = useRef<((msg: Message) => void) | null>(null);
155
161
  const [msgRefreshKey, setMsgRefreshKey] = useState(0);
156
162
 
163
+ useEffect(() => {
164
+ const el = frameRef.current;
165
+ if (!el || typeof ResizeObserver === 'undefined') return;
166
+ const ro = new ResizeObserver(entries => {
167
+ for (const entry of entries) {
168
+ const w = entry.contentRect.width;
169
+ if (w > 0) setContainerWidth(w);
170
+ }
171
+ });
172
+ ro.observe(el);
173
+ return () => ro.disconnect();
174
+ }, [loading, error]);
175
+
176
+ useEffect(() => {
177
+ if (prevLayoutModeRef.current === 'desktop' && layoutMode !== 'desktop') {
178
+ setInfoOpen(false);
179
+ }
180
+ prevLayoutModeRef.current = layoutMode;
181
+ }, [layoutMode]);
182
+
183
+ const totalUnreadCount = useMemo(() => {
184
+ return items.filter(x => x.id !== selected?.id && (x.unreadCount ?? 0) > 0).length;
185
+ }, [items, selected?.id]);
186
+
157
187
  const effectiveCurrentAgent = currentAgent ?? sessionAgent ?? null;
158
188
 
159
189
  useEffect(() => {
@@ -288,28 +318,39 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
288
318
  };
289
319
 
290
320
  useImperativeHandle(ref, () => ({
291
- openConversation: (id: string) => { const conv = items.find(c => c.id === id); if (conv) setSelected(conv); },
321
+ openConversation: (id: string) => { const conv = items.find(c => c.id === id); if (conv) { setSelected(conv); setMobileView('chat'); } },
292
322
  refresh: () => void load(),
293
323
  }), [items, load]);
294
324
 
325
+ const gridTemplateColumns =
326
+ layoutMode === 'mobile'
327
+ ? 'minmax(0, 1fr)'
328
+ : layoutMode === 'tablet'
329
+ ? 'minmax(240px, 270px) minmax(0, 1fr)'
330
+ : infoOpen
331
+ ? `minmax(260px, 300px) minmax(0, 1fr) ${infoPanelWidth}px`
332
+ : 'minmax(260px, 300px) minmax(0, 1fr)';
333
+
295
334
  const frame: React.CSSProperties = {
296
335
  ...css.frame,
336
+ position: 'relative',
297
337
  height: height ?? 620,
298
338
  ...(height ? { maxHeight: 'none' } : {}),
299
339
  fontFamily: theme?.fontFamily ?? 'Inter, ui-sans-serif, system-ui, sans-serif',
300
340
  borderRadius: theme?.borderRadius ?? '16px',
301
- gridTemplateColumns: infoOpen
302
- ? `minmax(260px, 300px) minmax(0, 1fr) ${infoPanelWidth}px`
303
- : 'minmax(260px, 300px) minmax(0, 1fr)',
341
+ gridTemplateColumns,
304
342
  transition: isResizing ? 'none' : 'grid-template-columns 220ms ease',
305
343
  };
306
344
  if (loading) return <div style={{ ...css.state, borderRadius: theme?.borderRadius ?? '16px' }}><Spinner /> Đang tải hộp thư…</div>;
307
345
  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>;
346
+ const showSidebar = layoutMode !== 'mobile' || mobileView === 'list' || !selected;
347
+ const showMain = layoutMode !== 'mobile' || (mobileView === 'chat' && Boolean(selected));
308
348
  return (
309
349
  <ApiUrlCtx.Provider value={apiUrl}>
310
350
  <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
- <aside style={css.sidebar}>
351
+ <div ref={frameRef} style={frame} onFocusCapture={() => { const y = window.scrollY; requestAnimationFrame(() => { if (window.scrollY !== y) window.scrollTo({ top: y, behavior: 'instant' }); }); }}>
352
+ {showSidebar && (
353
+ <aside style={{ ...css.sidebar, ...(layoutMode === 'mobile' ? { borderRight: 0 } : {}) }}>
313
354
  <div style={css.brand}>
314
355
  <div style={{ ...css.brandMark, background: primary, overflow: 'hidden', padding: 0 }}>
315
356
  {theme?.branding?.logoUrl
@@ -322,7 +363,7 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
322
363
  </div>
323
364
  <Button aria-label="Tùy chọn" style={css.iconButton}><MoreHorizontal size={16} strokeWidth={2} /></Button>
324
365
  </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>
366
+ <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
367
 
327
368
  {/* 3-Tab Assignment Scope Bar (Tất cả | Của tôi | Chưa nhận) */}
328
369
  <div
@@ -416,7 +457,7 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
416
457
  {filterOpen && popoverAnchor && createPortal(
417
458
  <div
418
459
  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 }}
460
+ 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
461
  >
421
462
  <div style={{ fontSize: 10, fontWeight: 700, color: c.muted, letterSpacing: 1, textTransform: 'uppercase' as const, marginBottom: 8 }}>Kênh</div>
422
463
  {(['all', ...availableProviders] as const).map(p => (
@@ -437,11 +478,13 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
437
478
  )}
438
479
 
439
480
  <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); }} />)}
481
+ {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
482
  {!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
483
  {cursor && <button style={css.loadMore} onClick={() => void load(cursor)}>Xem thêm hội thoại</button>}
443
484
  </ScrollArea>
444
485
  </aside>
486
+ )}
487
+ {showMain && (
445
488
  <main style={css.main}>
446
489
  {selected ? (
447
490
  <MessagePanel
@@ -465,22 +508,67 @@ export const ChannelHubInbox = forwardRef<ChannelHubInboxHandle, WidgetProps>(fu
465
508
  onAssignAgent={(agent) => handleAssignConversation(selected, agent)}
466
509
  onLinkContact={(extId) => handleLinkContact(selected, extId)}
467
510
  onRefreshContactInfo={handleRefreshContactInfo}
511
+ layoutMode={layoutMode}
512
+ onBackToList={() => setMobileView('list')}
513
+ totalUnreadCount={totalUnreadCount}
468
514
  />
469
515
  ) : <EmptyConversation />}
470
516
  </main>
517
+ )}
471
518
  {infoOpen && selected && (
472
- <ContactInfoPanel
473
- conversation={selected}
474
- connection={connectionById.get(selected.connectionId)}
475
- primary={primary}
476
- onClose={() => setInfoOpen(false)}
477
- client={client.current}
478
- onStartResize={startInfoResize}
479
- extensions={extensions}
480
- extRefreshKey={extRefreshKey}
481
- onLinkContact={(extId) => handleLinkContact(selected, extId)}
482
- onRefreshContactInfo={handleRefreshContactInfo}
483
- />
519
+ layoutMode === 'desktop' ? (
520
+ <ContactInfoPanel
521
+ conversation={selected}
522
+ connection={connectionById.get(selected.connectionId)}
523
+ primary={primary}
524
+ onClose={() => setInfoOpen(false)}
525
+ client={client.current}
526
+ onStartResize={startInfoResize}
527
+ extensions={extensions}
528
+ extRefreshKey={extRefreshKey}
529
+ onLinkContact={(extId) => handleLinkContact(selected, extId)}
530
+ onRefreshContactInfo={handleRefreshContactInfo}
531
+ layoutMode={layoutMode}
532
+ />
533
+ ) : (
534
+ <div
535
+ onClick={() => setInfoOpen(false)}
536
+ style={{
537
+ position: 'absolute',
538
+ inset: 0,
539
+ zIndex: 50,
540
+ background: 'rgba(15, 23, 42, 0.32)',
541
+ display: 'flex',
542
+ justifyContent: 'flex-end',
543
+ }}
544
+ >
545
+ <div
546
+ onClick={e => e.stopPropagation()}
547
+ style={{
548
+ width: layoutMode === 'mobile' ? '100%' : 'min(320px, 85%)',
549
+ height: '100%',
550
+ background: c.white,
551
+ boxShadow: '-8px 0 24px rgba(15, 23, 42, 0.14)',
552
+ display: 'flex',
553
+ flexDirection: 'column',
554
+ }}
555
+ >
556
+ <ContactInfoPanel
557
+ conversation={selected}
558
+ connection={connectionById.get(selected.connectionId)}
559
+ primary={primary}
560
+ onClose={() => setInfoOpen(false)}
561
+ client={client.current}
562
+ onStartResize={undefined}
563
+ extensions={extensions}
564
+ extRefreshKey={extRefreshKey}
565
+ onLinkContact={(extId) => handleLinkContact(selected, extId)}
566
+ onRefreshContactInfo={handleRefreshContactInfo}
567
+ layoutMode={layoutMode}
568
+ />
569
+ </div>
570
+ </div>
571
+ )
484
572
  )}
485
573
  </div>
486
574
  </TokenCtx.Provider>
@@ -599,7 +687,7 @@ function ConversationRow({ conversation, provider, selected, primary, currentAge
599
687
 
600
688
  type PendingAttachment = { file: File; uploading: boolean; url?: string; mimeType?: string; attachmentType?: string; objectUrl?: string };
601
689
 
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 }) {
690
+ 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 }: { 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 }) {
603
691
  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
692
  const fileImageRef = useRef<HTMLInputElement>(null);
605
693
  const fileDocRef = useRef<HTMLInputElement>(null);
@@ -784,10 +872,53 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
784
872
  }
785
873
 
786
874
  const canSend = !sending && (text.trim().length > 0 || (pendingAttachment?.url != null && !pendingAttachment.uploading));
875
+ const toolbarBtnStyle: React.CSSProperties = layoutMode === 'desktop'
876
+ ? css.toolbarBtn
877
+ : { ...css.toolbarBtn, width: 32, height: 32 };
787
878
 
788
879
  return (
789
880
  <section style={css.chat}>
790
- <header style={css.chatHeader}>
881
+ <header style={{ ...css.chatHeader, ...(layoutMode === 'mobile' ? { padding: '0 10px 0 8px', gap: 8 } : {}) }}>
882
+ {layoutMode === 'mobile' && (
883
+ <button
884
+ type="button"
885
+ onClick={onBackToList}
886
+ aria-label="Quay lại danh sách"
887
+ style={{
888
+ ...css.iconButton,
889
+ width: 36,
890
+ height: 36,
891
+ marginLeft: 0,
892
+ position: 'relative',
893
+ flexShrink: 0,
894
+ color: c.ink,
895
+ }}
896
+ >
897
+ <ArrowLeft size={18} strokeWidth={2.2} />
898
+ {totalUnreadCount > 0 && (
899
+ <span
900
+ style={{
901
+ position: 'absolute',
902
+ top: 3,
903
+ right: 3,
904
+ minWidth: 15,
905
+ height: 15,
906
+ borderRadius: 999,
907
+ background: '#ef4444',
908
+ color: '#fff',
909
+ fontSize: 9,
910
+ fontWeight: 800,
911
+ display: 'inline-grid',
912
+ placeItems: 'center',
913
+ padding: '0 3px',
914
+ border: `1.5px solid ${c.white}`,
915
+ }}
916
+ >
917
+ {totalUnreadCount > 99 ? '99+' : totalUnreadCount}
918
+ </span>
919
+ )}
920
+ </button>
921
+ )}
791
922
  <ContactAvatar name={name} color={primary} image={conversation.contactPictureUrl} provider={provider} />
792
923
  <div style={css.contact}>
793
924
  <strong style={css.contactName}>{name}</strong>
@@ -816,7 +947,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
816
947
  }}
817
948
  >
818
949
  <UserPlus size={12} strokeWidth={2.2} />
819
- <span>+ Nhận phụ trách</span>
950
+ <span>{layoutMode === 'mobile' ? '+ Nhận' : '+ Nhận phụ trách'}</span>
820
951
  </button>
821
952
  {(teamAgents?.length ?? 0) > 1 && (
822
953
  <button
@@ -878,8 +1009,8 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
878
1009
  ? <img src={conversation.assignedAgent.avatarUrl} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
879
1010
  : initials(conversation.assignedAgent.name)}
880
1011
  </span>
881
- <span style={{ color: c.muted, fontWeight: 500 }}>Phụ trách:</span>
882
- <span style={{ maxWidth: 110, overflow: 'hidden', textOverflow: 'ellipsis' }}>
1012
+ {layoutMode !== 'mobile' && <span style={{ color: c.muted, fontWeight: 500 }}>Phụ trách:</span>}
1013
+ <span style={{ maxWidth: layoutMode === 'mobile' ? 76 : 110, overflow: 'hidden', textOverflow: 'ellipsis' }}>
883
1014
  {shortAgentName(conversation.assignedAgent.name)}
884
1015
  </span>
885
1016
  </>
@@ -1040,9 +1171,11 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1040
1171
  )}
1041
1172
  </div>
1042
1173
 
1043
- <button style={css.iconButton} aria-label="Thêm tùy chọn">
1044
- <MoreHorizontal size={16} strokeWidth={2} />
1045
- </button>
1174
+ {layoutMode !== 'mobile' && (
1175
+ <button style={css.iconButton} aria-label="Thêm tùy chọn">
1176
+ <MoreHorizontal size={16} strokeWidth={2} />
1177
+ </button>
1178
+ )}
1046
1179
  <button
1047
1180
  style={{
1048
1181
  ...css.iconButton,
@@ -1098,7 +1231,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1098
1231
  })}
1099
1232
  </ScrollArea>
1100
1233
  {/* Quick reply chips */}
1101
- <div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', padding: '6px 14px 2px', borderTop: `1px solid ${c.line}` }}>
1234
+ <div style={{ display: 'flex', gap: 6, flexWrap: 'nowrap', overflowX: 'auto', WebkitOverflowScrolling: 'touch', scrollbarWidth: 'none', padding: '6px 14px 2px', borderTop: `1px solid ${c.line}` }}>
1102
1235
  {['Cảm ơn bạn đã liên hệ 🙏', 'Mình sẽ kiểm tra ngay', 'Vui lòng chờ 1-2 phút'].map(chip => (
1103
1236
  <button
1104
1237
  key={chip}
@@ -1109,6 +1242,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1109
1242
  background: `${primary}0f`, color: primary,
1110
1243
  border: `1px solid ${primary}33`,
1111
1244
  cursor: 'pointer', whiteSpace: 'nowrap' as const,
1245
+ flexShrink: 0,
1112
1246
  }}
1113
1247
  >
1114
1248
  {chip}
@@ -1130,6 +1264,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1130
1264
  borderRadius: 12,
1131
1265
  boxShadow: '0 8px 24px rgba(23,32,51,.14)',
1132
1266
  width: 280,
1267
+ maxWidth: 'calc(100vw - 28px)',
1133
1268
  overflow: 'hidden',
1134
1269
  fontFamily: 'inherit',
1135
1270
  }}
@@ -1187,6 +1322,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1187
1322
  borderRadius: 12,
1188
1323
  boxShadow: '0 8px 24px rgba(23,32,51,.14)',
1189
1324
  width: 300,
1325
+ maxWidth: 'calc(100vw - 28px)',
1190
1326
  overflow: 'hidden',
1191
1327
  fontFamily: 'inherit',
1192
1328
  }}
@@ -1255,19 +1391,19 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1255
1391
  type="button"
1256
1392
  title="Chèn emoji"
1257
1393
  onClick={() => setEmojiOpen(o => !o)}
1258
- style={{ ...css.toolbarBtn, background: emojiOpen ? `${primary}18` : 'transparent', color: emojiOpen ? primary : '#9ca3af' }}
1394
+ style={{ ...toolbarBtnStyle, background: emojiOpen ? `${primary}18` : 'transparent', color: emojiOpen ? primary : '#9ca3af' }}
1259
1395
  >
1260
1396
  <Smile size={13} strokeWidth={2} />
1261
1397
  </button>
1262
1398
  {/* Image/Video button */}
1263
1399
  {!disableAttachments && (
1264
- <button type="button" title="Gửi ảnh / video" aria-label="Gửi ảnh hoặc video" style={css.toolbarBtn} onClick={() => fileImageRef.current?.click()}>
1400
+ <button type="button" title="Gửi ảnh / video" aria-label="Gửi ảnh hoặc video" style={toolbarBtnStyle} onClick={() => fileImageRef.current?.click()}>
1265
1401
  <Image size={13} strokeWidth={2} />
1266
1402
  </button>
1267
1403
  )}
1268
1404
  {/* File button */}
1269
1405
  {!disableAttachments && (
1270
- <button type="button" title="Gửi tệp đính kèm" aria-label="Gửi tệp đính kèm" style={css.toolbarBtn} onClick={() => fileDocRef.current?.click()}>
1406
+ <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
1407
  <Paperclip size={13} strokeWidth={2} />
1272
1408
  </button>
1273
1409
  )}
@@ -1283,7 +1419,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1283
1419
  type="button"
1284
1420
  title="Template nhanh"
1285
1421
  onClick={() => { setTemplateOpen(o => !o); setTemplateSearch(''); }}
1286
- style={{ ...css.toolbarBtn, background: templateOpen ? `${primary}18` : 'transparent', color: templateOpen ? primary : '#9ca3af' }}
1422
+ style={{ ...toolbarBtnStyle, background: templateOpen ? `${primary}18` : 'transparent', color: templateOpen ? primary : '#9ca3af' }}
1287
1423
  >
1288
1424
  <Zap size={13} strokeWidth={2} />
1289
1425
  </button>
@@ -1291,12 +1427,12 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1291
1427
  <span style={{ width: 1, height: 14, background: '#e5e7eb', margin: '0 2px' }} />
1292
1428
  {/* Bold */}
1293
1429
  <button type="button" title="In đậm" onClick={() => setBoldActive(b => !b)}
1294
- style={{ ...css.toolbarBtn, fontWeight: 700, fontSize: 12, background: boldActive ? `${primary}18` : 'transparent', color: boldActive ? primary : '#9ca3af', border: boldActive ? `1px solid ${primary}33` : '1px solid transparent' }}>
1430
+ 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
1431
  B
1296
1432
  </button>
1297
1433
  {/* Italic */}
1298
1434
  <button type="button" title="Nghiêng" onClick={() => setItalicActive(i => !i)}
1299
- style={{ ...css.toolbarBtn, fontStyle: 'italic', fontSize: 12, background: italicActive ? `${primary}18` : 'transparent', color: italicActive ? primary : '#9ca3af', border: italicActive ? `1px solid ${primary}33` : '1px solid transparent' }}>
1435
+ 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
1436
  I
1301
1437
  </button>
1302
1438
  {Boolean(extensions?.some(e => (e.toolbarActions?.length ?? 0) > 0)) && (
@@ -1324,7 +1460,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1324
1460
  lineHeight: 1.2,
1325
1461
  whiteSpace: 'nowrap',
1326
1462
  }
1327
- : css.toolbarBtn
1463
+ : toolbarBtnStyle
1328
1464
  }
1329
1465
  onClick={() => {
1330
1466
  const insertText = (snippet: string) => {
@@ -1365,7 +1501,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1365
1501
  background: 'transparent',
1366
1502
  color: c.ink,
1367
1503
  padding: '8px 12px 4px',
1368
- font: 'inherit', fontSize: 13, lineHeight: 1.45,
1504
+ font: 'inherit', fontSize: layoutMode === 'mobile' ? 16 : 13, lineHeight: 1.45,
1369
1505
  fontStyle: italicActive ? 'italic' : 'normal',
1370
1506
  fontWeight: boldActive ? 700 : 400,
1371
1507
  }}
@@ -1381,7 +1517,7 @@ function MessagePanel({ conversation, provider, connection, client, primary, err
1381
1517
  {text.length}/1000
1382
1518
  </span>
1383
1519
  <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
1384
- {!hideKeyboardHint && <span style={{ fontSize: 10, color: '#9ca3af' }}>↵ Gửi · ⇧↵ Xuống dòng</span>}
1520
+ {!hideKeyboardHint && layoutMode === 'desktop' && <span style={{ fontSize: 10, color: '#9ca3af' }}>↵ Gửi · ⇧↵ Xuống dòng</span>}
1385
1521
  <button
1386
1522
  disabled={!canSend}
1387
1523
  aria-label="Gửi tin nhắn"
@@ -1541,6 +1677,7 @@ function ContactInfoPanel({
1541
1677
  extRefreshKey,
1542
1678
  onLinkContact,
1543
1679
  onRefreshContactInfo,
1680
+ layoutMode = 'desktop',
1544
1681
  }: {
1545
1682
  conversation: Conversation;
1546
1683
  connection?: Connection;
@@ -1552,6 +1689,7 @@ function ContactInfoPanel({
1552
1689
  extRefreshKey?: number;
1553
1690
  onLinkContact: (externalId: string | null) => Promise<void>;
1554
1691
  onRefreshContactInfo: () => void;
1692
+ layoutMode?: LayoutMode;
1555
1693
  }) {
1556
1694
  const name = conversation.contactName ?? conversation.subject ?? conversation.providerConversationKey;
1557
1695
  const provider = connection?.provider;
@@ -1559,6 +1697,7 @@ function ContactInfoPanel({
1559
1697
  const [expanded, setExpanded] = useState<Record<string, boolean>>({ channel: true, stats: false, extra: true });
1560
1698
  const toggle = (key: string) => setExpanded(e => ({ ...e, [key]: !e[key] }));
1561
1699
  const [noteText, setNoteText] = useState('');
1700
+ const [savedNoteText, setSavedNoteText] = useState('');
1562
1701
  const [noteSaving, setNoteSaving] = useState(false);
1563
1702
  const [noteSaved, setNoteSaved] = useState(false);
1564
1703
  const [noteError, setNoteError] = useState('');
@@ -1567,10 +1706,16 @@ function ContactInfoPanel({
1567
1706
 
1568
1707
  useEffect(() => {
1569
1708
  setNoteText('');
1709
+ setSavedNoteText('');
1570
1710
  setNoteSaved(false);
1571
1711
  setNoteError('');
1572
1712
  client.getNote(conversation.id)
1573
- .then(note => { if (note) setNoteText(note.content); })
1713
+ .then(note => {
1714
+ if (note) {
1715
+ setNoteText(note.content);
1716
+ setSavedNoteText(note.content);
1717
+ }
1718
+ })
1574
1719
  .catch(() => undefined);
1575
1720
  }, [conversation.id, client]);
1576
1721
 
@@ -1599,12 +1744,16 @@ function ContactInfoPanel({
1599
1744
  return () => { cancelled = true; };
1600
1745
  }, [conversation.id, conversation.contactExternalId, extensions, extRefreshKey, hasExtContactRows, provider, onLinkContact, onRefreshContactInfo, client]);
1601
1746
 
1747
+ const isNoteDirty = noteText.trim() !== savedNoteText.trim() && noteText.trim().length > 0;
1748
+
1602
1749
  async function saveNote() {
1603
- if (!noteText.trim() || noteSaving) return;
1750
+ if (!isNoteDirty || noteSaving) return;
1604
1751
  setNoteSaving(true);
1605
1752
  setNoteError('');
1606
1753
  try {
1607
- await client.upsertNote(conversation.id, noteText.trim());
1754
+ const trimmed = noteText.trim();
1755
+ await client.upsertNote(conversation.id, trimmed);
1756
+ setSavedNoteText(trimmed);
1608
1757
  setNoteSaved(true);
1609
1758
  setTimeout(() => setNoteSaved(false), 2000);
1610
1759
  } catch {
@@ -1615,13 +1764,15 @@ function ContactInfoPanel({
1615
1764
  }
1616
1765
 
1617
1766
  return (
1618
- <aside style={{ ...css.infoPanel, position: 'relative' }}>
1619
- <div
1620
- onMouseDown={onStartResize}
1621
- style={{ position: 'absolute', left: 0, top: 0, bottom: 0, width: 4, cursor: 'col-resize', zIndex: 1 }}
1622
- onMouseEnter={e => { (e.currentTarget as HTMLElement).style.background = 'rgba(0,0,0,0.07)'; }}
1623
- onMouseLeave={e => { (e.currentTarget as HTMLElement).style.background = ''; }}
1624
- />
1767
+ <aside style={{ ...css.infoPanel, position: 'relative', ...(layoutMode !== 'desktop' ? { flex: 1, borderLeft: 0 } : {}) }}>
1768
+ {onStartResize && (
1769
+ <div
1770
+ onMouseDown={onStartResize}
1771
+ style={{ position: 'absolute', left: 0, top: 0, bottom: 0, width: 4, cursor: 'col-resize', zIndex: 1 }}
1772
+ onMouseEnter={e => { (e.currentTarget as HTMLElement).style.background = 'rgba(0,0,0,0.07)'; }}
1773
+ onMouseLeave={e => { (e.currentTarget as HTMLElement).style.background = ''; }}
1774
+ />
1775
+ )}
1625
1776
  <div style={css.infoPanelHeader}>
1626
1777
  <span style={{ fontWeight: 600, fontSize: 13, color: c.ink }}>Thông tin liên hệ</span>
1627
1778
  <button style={css.iconButton} onClick={onClose} aria-label="Đóng">
@@ -1761,8 +1912,8 @@ function ContactInfoPanel({
1761
1912
  </button>
1762
1913
  );
1763
1914
  })}
1764
- <div style={{ border: `1px solid ${c.line}`, borderRadius: 10, background: '#fff', overflow: 'hidden' }}>
1765
- <div style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '7px 10px', borderBottom: '1px solid #fde68a', background: '#fffbeb', fontSize: 11, fontWeight: 600, color: '#92400e' }}>
1915
+ <div style={{ border: `1px solid ${c.line}`, borderRadius: 10, background: c.white, overflow: 'hidden' }}>
1916
+ <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
1917
  Ghi chú nội bộ
1767
1918
  </div>
1768
1919
  <textarea
@@ -1770,7 +1921,7 @@ function ContactInfoPanel({
1770
1921
  onChange={e => setNoteText(e.target.value)}
1771
1922
  placeholder="Nhập ghi chú..."
1772
1923
  rows={3}
1773
- style={{ display: 'block', width: '100%', boxSizing: 'border-box' as const, border: 0, outline: 0, background: 'transparent', resize: 'none' as const, padding: '8px 10px', font: 'inherit', fontSize: 12, color: c.ink, lineHeight: 1.5 }}
1924
+ 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
1925
  />
1775
1926
  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 10px 6px' }}>
1776
1927
  {noteSaved
@@ -1779,8 +1930,21 @@ function ContactInfoPanel({
1779
1930
  ? <span style={{ fontSize: 11, color: '#ef4444' }}>{noteError}</span>
1780
1931
  : <span />
1781
1932
  }
1782
- <button type="button" onClick={() => { void saveNote(); }} disabled={!noteText.trim() || noteSaving}
1783
- style={{ padding: '4px 12px', border: 0, borderRadius: 7, fontSize: 12, fontWeight: 600, background: noteText.trim() && !noteSaving ? 'linear-gradient(135deg,#f59e0b,#fbbf24)' : '#e5e7eb', color: noteText.trim() && !noteSaving ? '#fff' : '#9ca3af', cursor: noteText.trim() && !noteSaving ? 'pointer' : 'not-allowed' }}>
1933
+ <button
1934
+ type="button"
1935
+ onClick={() => { void saveNote(); }}
1936
+ disabled={!isNoteDirty || noteSaving}
1937
+ style={{
1938
+ padding: '4px 12px',
1939
+ border: 0,
1940
+ borderRadius: 7,
1941
+ fontSize: 12,
1942
+ fontWeight: 600,
1943
+ background: isNoteDirty && !noteSaving ? primary : '#f1f5f9',
1944
+ color: isNoteDirty && !noteSaving ? '#fff' : '#94a3b8',
1945
+ cursor: isNoteDirty && !noteSaving ? 'pointer' : 'not-allowed',
1946
+ }}
1947
+ >
1784
1948
  {noteSaving ? 'Đang lưu…' : 'Lưu ghi chú'}
1785
1949
  </button>
1786
1950
  </div>