@adatechnology/conversations-ui 0.1.0-rc.4 → 0.1.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-LITPZCWW.js +1465 -0
- package/dist/index.d.ts +223 -29
- package/dist/index.js +316 -366
- package/dist/preview/index.d.ts +92 -3
- package/dist/preview/index.js +627 -103
- package/dist/types-CeixG2Z9.d.ts +324 -0
- package/package.json +2 -2
- package/src/Avatar.tsx +13 -2
- package/src/ConversationDocumentsPanel.tsx +342 -24
- package/src/ConversationListItem.tsx +18 -2
- package/src/DocumentsLibrary.tsx +322 -0
- package/src/FileIcon.test.ts +83 -0
- package/src/FileIcon.tsx +88 -11
- package/src/Lightbox.tsx +18 -3
- package/src/MediaRenderer.tsx +5 -2
- package/src/MessageBubble.tsx +18 -2
- package/src/MessageComposer.tsx +20 -3
- package/src/WhatsAppMessageEditor.tsx +28 -4
- package/src/hooks/useConversationActions.ts +56 -0
- package/src/hooks/useConversationDocuments.ts +11 -7
- package/src/hooks/useConversationList.ts +15 -9
- package/src/hooks/useConversationMessages.ts +2 -2
- package/src/index.ts +32 -11
- package/src/lib/cn.test.ts +29 -0
- package/src/lib/createMediaUrlResolver.ts +33 -0
- package/src/lib/paginated.test.ts +33 -0
- package/src/lib/paginated.ts +26 -0
- package/src/preview/MediaTypesPreview.tsx +87 -0
- package/src/preview/createMockConversationsApi.ts +175 -15
- package/src/preview/index.ts +6 -1
- package/src/preview/mockDocumentsSearch.test.ts +57 -0
- package/src/preview/preview.test.ts +5 -3
- package/src/preview/previewFileSamples.test.ts +151 -0
- package/src/preview/previewFileSamples.ts +74 -0
- package/src/preview/previewFixtures.ts +288 -1
- package/src/preview/previewMediaSource.test.ts +62 -0
- package/src/preview/previewMediaSource.ts +91 -0
- package/src/providers/types.ts +127 -9
- package/src/settings/WhatsAppCreateTemplateForm.tsx +3 -1
- package/src/useWaitingNotifications.ts +74 -29
- package/dist/chunk-4R6Y43DQ.js +0 -726
- package/dist/types-C0PtaO7S.d.ts +0 -207
|
@@ -8,49 +8,120 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { useState } from 'react'
|
|
11
|
+
import { ArrowUpDown, Bot, Download, Eye, Users } from 'lucide-react'
|
|
11
12
|
import { useConversationDocuments } from './hooks/useConversationDocuments'
|
|
12
13
|
import { useConversations } from './providers/ConversationsProvider'
|
|
13
14
|
import { FileIcon } from './FileIcon'
|
|
14
15
|
import { cn } from './lib/cn'
|
|
15
|
-
import {
|
|
16
|
+
import { formatDateTime, formatFileSize } from './lib/format'
|
|
17
|
+
|
|
18
|
+
/** Origens que o filtro oferece. `all` não é origem — é a ausência de filtro. */
|
|
19
|
+
export const DOCUMENT_SOURCE_FILTER = {
|
|
20
|
+
ALL: 'all',
|
|
21
|
+
CUSTOMER: 'customer',
|
|
22
|
+
TEAM: 'team',
|
|
23
|
+
} as const
|
|
24
|
+
export type DocumentSourceFilter = (typeof DOCUMENT_SOURCE_FILTER)[keyof typeof DOCUMENT_SOURCE_FILTER]
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `bot` e `agent` caem em "Equipe": para quem procura um comprovante, o que importa é se veio do
|
|
28
|
+
* cliente ou saiu da loja — não se foi o robô ou a pessoa que apertou enviar.
|
|
29
|
+
*/
|
|
30
|
+
const TEAM_SOURCES = new Set(['agent', 'bot'])
|
|
16
31
|
|
|
17
32
|
export interface ConversationDocumentsPanelLabels {
|
|
18
33
|
toggle: string
|
|
19
34
|
title: string
|
|
20
35
|
searchPlaceholder: string
|
|
21
36
|
empty: string
|
|
37
|
+
/** Distinto de `empty`: sem resultado POR CAUSA do filtro, e não conversa sem anexo nenhum. */
|
|
38
|
+
noResults: string
|
|
22
39
|
loading: string
|
|
23
40
|
failure: string
|
|
24
41
|
download: string
|
|
42
|
+
view: string
|
|
43
|
+
sourceFilterAll: string
|
|
44
|
+
sourceFilterCustomer: string
|
|
45
|
+
sourceFilterTeam: string
|
|
46
|
+
sortMostRecent: string
|
|
47
|
+
sortOldest: string
|
|
48
|
+
clearFilters: string
|
|
49
|
+
selectAll: string
|
|
50
|
+
downloadSelected: (count: number) => string
|
|
51
|
+
archiveFailed: string
|
|
52
|
+
total: (count: number) => string
|
|
53
|
+
page: (current: number, last: number) => string
|
|
25
54
|
}
|
|
26
55
|
|
|
27
56
|
export const DEFAULT_CONVERSATION_DOCUMENTS_LABELS: ConversationDocumentsPanelLabels = {
|
|
28
57
|
toggle: '📎 Arquivos',
|
|
29
58
|
title: 'Arquivos da conversa',
|
|
30
|
-
|
|
59
|
+
noResults: 'Nenhum arquivo encontrado para os filtros aplicados',
|
|
60
|
+
view: 'Visualizar',
|
|
61
|
+
sourceFilterAll: 'Todas as origens',
|
|
62
|
+
sourceFilterCustomer: 'Cliente',
|
|
63
|
+
sourceFilterTeam: 'Equipe',
|
|
64
|
+
sortMostRecent: 'Mais recentes',
|
|
65
|
+
sortOldest: 'Mais antigos',
|
|
66
|
+
clearFilters: 'Limpar filtros',
|
|
67
|
+
selectAll: 'Selecionar todos desta página',
|
|
68
|
+
downloadSelected: (count: number) => `Baixar ${count} selecionado${count === 1 ? '' : 's'} (.zip)`,
|
|
69
|
+
archiveFailed: 'Não foi possível montar o arquivo compactado.',
|
|
70
|
+
total: (count: number) => `${count} arquivo${count === 1 ? '' : 's'}`,
|
|
71
|
+
page: (current: number, last: number) => `${current} / ${last}`,
|
|
72
|
+
searchPlaceholder: 'Buscar por nome do arquivo',
|
|
31
73
|
empty: 'Nenhum arquivo nesta conversa.',
|
|
32
74
|
loading: 'Carregando arquivos…',
|
|
33
75
|
failure: 'Não foi possível carregar os arquivos.',
|
|
34
76
|
download: 'Baixar',
|
|
35
77
|
}
|
|
36
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Partes estilizáveis do painel, no mesmo contrato do `ConversationHeader`: `cn` funde por cima da
|
|
81
|
+
* base e conflito de utilitário (padding, tamanho de fonte, borda) fica com o valor do produto.
|
|
82
|
+
*
|
|
83
|
+
* `status` cobre carregando/erro/vazio de uma vez — são a mesma linha de texto auxiliar, e slots
|
|
84
|
+
* separados só multiplicariam chave para quem quer mudar a cor de aviso.
|
|
85
|
+
*/
|
|
37
86
|
export interface ConversationDocumentsPanelClassNames {
|
|
38
87
|
root: string
|
|
39
88
|
body: string
|
|
89
|
+
title: string
|
|
90
|
+
filters: string
|
|
91
|
+
search: string
|
|
92
|
+
sourceSelect: string
|
|
93
|
+
sortButton: string
|
|
94
|
+
clearButton: string
|
|
95
|
+
status: string
|
|
96
|
+
list: string
|
|
97
|
+
item: string
|
|
98
|
+
sourceBadge: string
|
|
99
|
+
filename: string
|
|
100
|
+
meta: string
|
|
101
|
+
viewButton: string
|
|
102
|
+
downloadButton: string
|
|
103
|
+
pagination: string
|
|
104
|
+
selectionBar: string
|
|
105
|
+
checkbox: string
|
|
40
106
|
}
|
|
41
107
|
|
|
42
108
|
export interface ConversationDocumentsPanelProps {
|
|
43
109
|
conversationId: string
|
|
44
110
|
/** Controlado de fora porque o gatilho vive no cabeçalho, junto das outras ações da conversa. */
|
|
45
111
|
open: boolean
|
|
112
|
+
/** Itens por página. O total vem do servidor; sem paginação no host, a barra não aparece. */
|
|
113
|
+
perPage?: number
|
|
46
114
|
labels?: Partial<ConversationDocumentsPanelLabels>
|
|
47
115
|
className?: string
|
|
48
116
|
classNames?: Partial<ConversationDocumentsPanelClassNames>
|
|
49
117
|
}
|
|
50
118
|
|
|
119
|
+
const DEFAULT_PER_PAGE = 10
|
|
120
|
+
|
|
51
121
|
export function ConversationDocumentsPanel({
|
|
52
122
|
conversationId,
|
|
53
123
|
open,
|
|
124
|
+
perPage = DEFAULT_PER_PAGE,
|
|
54
125
|
labels: labelsOverride,
|
|
55
126
|
className,
|
|
56
127
|
classNames,
|
|
@@ -58,49 +129,296 @@ export function ConversationDocumentsPanel({
|
|
|
58
129
|
const labels = { ...DEFAULT_CONVERSATION_DOCUMENTS_LABELS, ...labelsOverride }
|
|
59
130
|
const context = useConversations()
|
|
60
131
|
const [search, setSearch] = useState('')
|
|
132
|
+
const [sourceFilter, setSourceFilter] = useState<DocumentSourceFilter>(DOCUMENT_SOURCE_FILTER.ALL)
|
|
133
|
+
const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('desc')
|
|
134
|
+
const [page, setPage] = useState(1)
|
|
135
|
+
const [selectedIds, setSelectedIds] = useState<readonly string[]>([])
|
|
136
|
+
const [archiveError, setArchiveError] = useState(false)
|
|
137
|
+
|
|
138
|
+
const hasFilters = search !== '' || sourceFilter !== DOCUMENT_SOURCE_FILTER.ALL || sortDirection !== 'desc'
|
|
61
139
|
|
|
62
140
|
// Só busca quando o painel abre: a lista de anexos é consulta extra e não deve pesar em toda
|
|
63
141
|
// conversa aberta.
|
|
64
|
-
const { documents, loading, error } = useConversationDocuments(open ? conversationId : undefined, {
|
|
142
|
+
const { documents, total, loading, error } = useConversationDocuments(open ? conversationId : undefined, {
|
|
143
|
+
search,
|
|
144
|
+
page,
|
|
145
|
+
limit: perPage,
|
|
146
|
+
sortDirection,
|
|
147
|
+
...(sourceFilter === DOCUMENT_SOURCE_FILTER.ALL ? {} : { source: sourceFilter }),
|
|
148
|
+
})
|
|
65
149
|
|
|
66
|
-
|
|
67
|
-
|
|
150
|
+
const lastPage = Math.max(1, Math.ceil(total / perPage))
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Toda mudança de filtro volta para a página 1. Sem isso, filtrar na página 3 pede ao servidor
|
|
154
|
+
* uma fatia que o novo resultado talvez não tenha, e o painel aparece vazio como se não houvesse
|
|
155
|
+
* arquivo — o mesmo motivo do `setDocumentsPage(1)` em cada handler do financiamento.
|
|
156
|
+
*/
|
|
157
|
+
function applyFilter(change: () => void): void {
|
|
158
|
+
change()
|
|
159
|
+
setPage(1)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function handleOpen(uploadId: string, disposition: 'inline' | 'attachment'): Promise<void> {
|
|
163
|
+
const url = await context?.api.getDocumentUrl(uploadId, disposition)
|
|
68
164
|
if (url) window.open(url, '_blank', 'noopener,noreferrer')
|
|
69
165
|
}
|
|
70
166
|
|
|
167
|
+
// Ausente = host não sabe montar zip (só assina URL). Esconder é melhor que oferecer e falhar.
|
|
168
|
+
const canArchive = typeof context?.api.downloadDocumentsArchive === 'function'
|
|
169
|
+
const pageIds = documents.map((document) => document.id)
|
|
170
|
+
const allOnPageSelected = pageIds.length > 0 && pageIds.every((id) => selectedIds.includes(id))
|
|
171
|
+
|
|
172
|
+
function toggleSelected(uploadId: string): void {
|
|
173
|
+
setArchiveError(false)
|
|
174
|
+
setSelectedIds((current) =>
|
|
175
|
+
current.includes(uploadId) ? current.filter((id) => id !== uploadId) : [...current, uploadId],
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function toggleAllOnPage(): void {
|
|
180
|
+
setArchiveError(false)
|
|
181
|
+
// Só mexe nos itens DESTA página: quem selecionou algo na página 1, foi para a 2 e marcou
|
|
182
|
+
// "todos" não deve perder a seleção anterior.
|
|
183
|
+
setSelectedIds((current) =>
|
|
184
|
+
allOnPageSelected
|
|
185
|
+
? current.filter((id) => !pageIds.includes(id))
|
|
186
|
+
: [...current, ...pageIds.filter((id) => !current.includes(id))],
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function handleDownloadSelected(): Promise<void> {
|
|
191
|
+
const archive = context?.api.downloadDocumentsArchive
|
|
192
|
+
if (!archive || selectedIds.length === 0) return
|
|
193
|
+
|
|
194
|
+
setArchiveError(false)
|
|
195
|
+
try {
|
|
196
|
+
const blob = await archive(conversationId, selectedIds)
|
|
197
|
+
// Âncora temporária com objectURL: é o que faz o navegador salvar um Blob com nome. O
|
|
198
|
+
// revoke é obrigatório — sem ele o blob fica na memória da aba até recarregar.
|
|
199
|
+
const url = URL.createObjectURL(blob)
|
|
200
|
+
const anchor = document.createElement('a')
|
|
201
|
+
anchor.href = url
|
|
202
|
+
anchor.download = `conversa-${conversationId}.zip`
|
|
203
|
+
anchor.click()
|
|
204
|
+
URL.revokeObjectURL(url)
|
|
205
|
+
setSelectedIds([])
|
|
206
|
+
} catch {
|
|
207
|
+
setArchiveError(true)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
71
211
|
if (!open) return null
|
|
72
212
|
|
|
73
213
|
return (
|
|
74
214
|
<div className={cn('border-b', classNames?.root, className)}>
|
|
75
215
|
<section className={cn('px-4 py-3', classNames?.body)}>
|
|
76
|
-
|
|
216
|
+
<p className={cn('mb-2 text-sm font-medium', classNames?.title)}>{labels.title}</p>
|
|
217
|
+
|
|
218
|
+
{/* Barra de filtros com wrap: em tela estreita os quatro controles empilham em vez de
|
|
219
|
+
estourar a largura do painel. */}
|
|
220
|
+
<div className={cn('mb-2 flex flex-wrap items-center gap-2 border-b pb-2', classNames?.filters)}>
|
|
77
221
|
<input
|
|
78
222
|
type="search"
|
|
79
223
|
value={search}
|
|
80
|
-
onChange={(event) => setSearch(event.target.value)}
|
|
224
|
+
onChange={(event) => applyFilter(() => setSearch(event.target.value))}
|
|
81
225
|
placeholder={labels.searchPlaceholder}
|
|
82
|
-
|
|
226
|
+
aria-label={labels.searchPlaceholder}
|
|
227
|
+
className={cn('w-full rounded-md border px-3 py-2 text-sm sm:w-52', classNames?.search)}
|
|
83
228
|
/>
|
|
84
229
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
230
|
+
<select
|
|
231
|
+
value={sourceFilter}
|
|
232
|
+
onChange={(event) => applyFilter(() => setSourceFilter(event.target.value as DocumentSourceFilter))}
|
|
233
|
+
aria-label={labels.sourceFilterAll}
|
|
234
|
+
className={cn('w-full rounded-md border px-2 py-2 text-sm sm:w-36', classNames?.sourceSelect)}
|
|
235
|
+
>
|
|
236
|
+
<option value={DOCUMENT_SOURCE_FILTER.ALL}>{labels.sourceFilterAll}</option>
|
|
237
|
+
<option value={DOCUMENT_SOURCE_FILTER.CUSTOMER}>{labels.sourceFilterCustomer}</option>
|
|
238
|
+
<option value={DOCUMENT_SOURCE_FILTER.TEAM}>{labels.sourceFilterTeam}</option>
|
|
239
|
+
</select>
|
|
240
|
+
|
|
241
|
+
<button
|
|
242
|
+
type="button"
|
|
243
|
+
onClick={() => applyFilter(() => setSortDirection(sortDirection === 'desc' ? 'asc' : 'desc'))}
|
|
244
|
+
className={cn('cv-header-action inline-flex items-center gap-1', classNames?.sortButton)}
|
|
245
|
+
>
|
|
246
|
+
<ArrowUpDown size={14} />
|
|
247
|
+
{sortDirection === 'desc' ? labels.sortMostRecent : labels.sortOldest}
|
|
248
|
+
</button>
|
|
249
|
+
|
|
250
|
+
{/* Só aparece com filtro ativo: botão que não faz nada visível é ruído. */}
|
|
251
|
+
{hasFilters ? (
|
|
252
|
+
<button
|
|
253
|
+
type="button"
|
|
254
|
+
onClick={() =>
|
|
255
|
+
applyFilter(() => {
|
|
256
|
+
setSearch('')
|
|
257
|
+
setSourceFilter(DOCUMENT_SOURCE_FILTER.ALL)
|
|
258
|
+
setSortDirection('desc')
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
className={cn('cv-header-action', classNames?.clearButton)}
|
|
262
|
+
>
|
|
263
|
+
{labels.clearFilters}
|
|
264
|
+
</button>
|
|
89
265
|
) : null}
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
|
+
{loading ? <p className={cn('text-xs text-gray-500', classNames?.status)}>{labels.loading}</p> : null}
|
|
269
|
+
{error ? (
|
|
270
|
+
<p role="alert" className={cn('text-xs text-red-600 dark:text-red-400', classNames?.status)}>
|
|
271
|
+
{labels.failure}
|
|
272
|
+
</p>
|
|
273
|
+
) : null}
|
|
274
|
+
{!loading && !error && documents.length === 0 ? (
|
|
275
|
+
<p className={cn('text-xs text-gray-500', classNames?.status)}>
|
|
276
|
+
{/* Distinguir os dois evita o mal-entendido de "a conversa não tem anexo" quando o
|
|
277
|
+
filtro é que não casou. */}
|
|
278
|
+
{hasFilters ? labels.noResults : labels.empty}
|
|
279
|
+
</p>
|
|
280
|
+
) : null}
|
|
281
|
+
|
|
282
|
+
{canArchive && documents.length > 0 ? (
|
|
283
|
+
<div className={cn('mb-2 flex flex-wrap items-center gap-3 text-xs', classNames?.selectionBar)}>
|
|
284
|
+
<label className="inline-flex items-center gap-1.5">
|
|
285
|
+
<input
|
|
286
|
+
type="checkbox"
|
|
287
|
+
checked={allOnPageSelected}
|
|
288
|
+
onChange={toggleAllOnPage}
|
|
289
|
+
className={cn(classNames?.checkbox)}
|
|
290
|
+
/>
|
|
291
|
+
{labels.selectAll}
|
|
292
|
+
</label>
|
|
293
|
+
{selectedIds.length > 0 ? (
|
|
294
|
+
<button type="button" onClick={() => void handleDownloadSelected()} className="cv-header-action">
|
|
295
|
+
{labels.downloadSelected(selectedIds.length)}
|
|
296
|
+
</button>
|
|
297
|
+
) : null}
|
|
298
|
+
{archiveError ? (
|
|
299
|
+
<span role="alert" className="text-red-600 dark:text-red-400">
|
|
300
|
+
{labels.archiveFailed}
|
|
301
|
+
</span>
|
|
302
|
+
) : null}
|
|
303
|
+
</div>
|
|
304
|
+
) : null}
|
|
90
305
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
306
|
+
<ul className={cn('space-y-2', classNames?.list)}>
|
|
307
|
+
{documents.map((document) => {
|
|
308
|
+
const isFromCustomer = !TEAM_SOURCES.has(document.source)
|
|
309
|
+
const SourceIcon = isFromCustomer ? Users : Bot
|
|
310
|
+
|
|
311
|
+
return (
|
|
312
|
+
<li
|
|
313
|
+
key={document.id}
|
|
314
|
+
className={cn(
|
|
315
|
+
'flex items-center justify-between gap-2 rounded-lg border px-3 py-2 dark:border-gray-700',
|
|
316
|
+
classNames?.item,
|
|
317
|
+
)}
|
|
318
|
+
>
|
|
319
|
+
<div className="flex min-w-0 flex-1 items-center gap-2">
|
|
320
|
+
{canArchive ? (
|
|
321
|
+
<input
|
|
322
|
+
type="checkbox"
|
|
323
|
+
checked={selectedIds.includes(document.id)}
|
|
324
|
+
onChange={() => toggleSelected(document.id)}
|
|
325
|
+
aria-label={`${labels.download}: ${document.filename}`}
|
|
326
|
+
className={cn('shrink-0', classNames?.checkbox)}
|
|
327
|
+
/>
|
|
328
|
+
) : null}
|
|
329
|
+
{/* `filename` junto do mimeType, e não só o mimeType: o mapa de ícones é indexado
|
|
330
|
+
por extensão curta, e o mimeType do Office é longo
|
|
331
|
+
(`…wordprocessingml.document`), então docx/doc/xlsx/xls caíam todos no ícone
|
|
332
|
+
genérico cinza. Com o nome, a extensão resolve primeiro. */}
|
|
333
|
+
<FileIcon filename={document.filename} mimeType={document.mimeType} />
|
|
334
|
+
<div className="min-w-0 flex-1">
|
|
335
|
+
<div
|
|
336
|
+
className={cn(
|
|
337
|
+
'mb-0.5 flex items-center gap-1 text-[11px] font-medium',
|
|
338
|
+
isFromCustomer
|
|
339
|
+
? 'text-blue-600 dark:text-blue-400'
|
|
340
|
+
: 'text-emerald-600 dark:text-emerald-400',
|
|
341
|
+
classNames?.sourceBadge,
|
|
342
|
+
)}
|
|
343
|
+
>
|
|
344
|
+
<SourceIcon size={11} />
|
|
345
|
+
{isFromCustomer ? labels.sourceFilterCustomer : labels.sourceFilterTeam}
|
|
346
|
+
</div>
|
|
347
|
+
{/* `title` no nome: truncado, o atendente não tem outro jeito de ler inteiro. */}
|
|
348
|
+
<div
|
|
349
|
+
className={cn('truncate text-sm font-medium', classNames?.filename)}
|
|
350
|
+
title={document.filename}
|
|
351
|
+
>
|
|
352
|
+
{document.filename}
|
|
353
|
+
</div>
|
|
354
|
+
<div className={cn('text-xs text-gray-500 dark:text-gray-400', classNames?.meta)}>
|
|
355
|
+
{formatDateTime(document.linkedAt)}
|
|
356
|
+
{' · '}
|
|
357
|
+
{formatFileSize(document.sizeBytes)}
|
|
358
|
+
</div>
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
|
|
362
|
+
{/* Ver e baixar são ações distintas, não a mesma com nome diferente: o
|
|
363
|
+
`disposition` viaja na assinatura da URL, e depois de assinada não há como o
|
|
364
|
+
cliente mudar entre abrir no navegador e salvar. */}
|
|
365
|
+
<div className="flex shrink-0 gap-1">
|
|
366
|
+
<button
|
|
367
|
+
type="button"
|
|
368
|
+
onClick={() => void handleOpen(document.id, 'inline')}
|
|
369
|
+
title={labels.view}
|
|
370
|
+
aria-label={`${labels.view}: ${document.filename}`}
|
|
371
|
+
className={cn('cv-header-icon', classNames?.viewButton)}
|
|
372
|
+
>
|
|
373
|
+
<Eye size={14} />
|
|
374
|
+
</button>
|
|
375
|
+
<button
|
|
376
|
+
type="button"
|
|
377
|
+
onClick={() => void handleOpen(document.id, 'attachment')}
|
|
378
|
+
title={labels.download}
|
|
379
|
+
aria-label={`${labels.download}: ${document.filename}`}
|
|
380
|
+
className={cn('cv-header-icon', classNames?.downloadButton)}
|
|
381
|
+
>
|
|
382
|
+
<Download size={14} />
|
|
383
|
+
</button>
|
|
384
|
+
</div>
|
|
101
385
|
</li>
|
|
102
|
-
)
|
|
103
|
-
|
|
386
|
+
)
|
|
387
|
+
})}
|
|
388
|
+
</ul>
|
|
389
|
+
|
|
390
|
+
{/* Só com mais de uma página: barra de paginação numa lista de três anexos é ruído. */}
|
|
391
|
+
{total > perPage ? (
|
|
392
|
+
<div
|
|
393
|
+
className={cn(
|
|
394
|
+
'mt-2 flex items-center justify-between border-t pt-2 text-xs dark:border-gray-700',
|
|
395
|
+
classNames?.pagination,
|
|
396
|
+
)}
|
|
397
|
+
>
|
|
398
|
+
<span className="text-gray-400">{labels.total(total)}</span>
|
|
399
|
+
<div className="flex items-center gap-2">
|
|
400
|
+
<button
|
|
401
|
+
type="button"
|
|
402
|
+
onClick={() => setPage(page - 1)}
|
|
403
|
+
disabled={page <= 1}
|
|
404
|
+
aria-label={labels.sortOldest}
|
|
405
|
+
className="cv-header-icon disabled:opacity-40"
|
|
406
|
+
>
|
|
407
|
+
‹
|
|
408
|
+
</button>
|
|
409
|
+
<span className="text-gray-500">{labels.page(page, lastPage)}</span>
|
|
410
|
+
<button
|
|
411
|
+
type="button"
|
|
412
|
+
onClick={() => setPage(page + 1)}
|
|
413
|
+
disabled={page >= lastPage}
|
|
414
|
+
aria-label={labels.sortMostRecent}
|
|
415
|
+
className="cv-header-icon disabled:opacity-40"
|
|
416
|
+
>
|
|
417
|
+
›
|
|
418
|
+
</button>
|
|
419
|
+
</div>
|
|
420
|
+
</div>
|
|
421
|
+
) : null}
|
|
104
422
|
</section>
|
|
105
423
|
</div>
|
|
106
424
|
)
|
|
@@ -3,8 +3,21 @@ import { Avatar } from './Avatar'
|
|
|
3
3
|
import { contactFlag, formatContactHandle } from './conversationChannel'
|
|
4
4
|
import type { ConversationSummary } from './providers/types'
|
|
5
5
|
|
|
6
|
+
export interface ConversationListItemLabels {
|
|
7
|
+
/** Tooltip do ponto vermelho: a janela de atendimento de 24h já fechou. */
|
|
8
|
+
expiredWindow: string
|
|
9
|
+
/** Tooltip do ponto laranja: a janela de atendimento está perto de fechar. */
|
|
10
|
+
warningWindow: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_CONVERSATION_LIST_ITEM_LABELS: ConversationListItemLabels = {
|
|
14
|
+
expiredWindow: 'Janela expirada',
|
|
15
|
+
warningWindow: 'Janela próxima do fim',
|
|
16
|
+
}
|
|
17
|
+
|
|
6
18
|
export interface ConversationListItemProps {
|
|
7
19
|
conversation: ConversationSummary
|
|
20
|
+
labels?: Partial<ConversationListItemLabels>
|
|
8
21
|
active?: boolean
|
|
9
22
|
selected?: boolean
|
|
10
23
|
onClick?: () => void
|
|
@@ -92,7 +105,10 @@ export const ConversationListItem = ({
|
|
|
92
105
|
onSelect,
|
|
93
106
|
showDivider = true,
|
|
94
107
|
highlightActive = true,
|
|
108
|
+
labels,
|
|
95
109
|
}: ConversationListItemProps) => {
|
|
110
|
+
const expiredWindowLabel = labels?.expiredWindow ?? DEFAULT_CONVERSATION_LIST_ITEM_LABELS.expiredWindow
|
|
111
|
+
const warningWindowLabel = labels?.warningWindow ?? DEFAULT_CONVERSATION_LIST_ITEM_LABELS.warningWindow
|
|
96
112
|
const isActive = active || selected
|
|
97
113
|
const windowStatus = useMemo(() => getWindowStatus(conversation.lastInboundAt), [conversation.lastInboundAt])
|
|
98
114
|
const preview = useMemo(() => lastMessagePreview(conversation), [conversation.lastContent])
|
|
@@ -134,10 +150,10 @@ export const ConversationListItem = ({
|
|
|
134
150
|
{!conversation.clientName && flag ? <span aria-hidden>{flag}</span> : null}
|
|
135
151
|
<span className="text-[16px] text-[#111b21] truncate">{name}</span>
|
|
136
152
|
{windowStatus && windowStatus.label === 'expired' && (
|
|
137
|
-
<span className="w-2 h-2 rounded-full bg-red-500 flex-shrink-0" title=
|
|
153
|
+
<span className="w-2 h-2 rounded-full bg-red-500 flex-shrink-0" title={expiredWindowLabel} />
|
|
138
154
|
)}
|
|
139
155
|
{windowStatus && windowStatus.label === 'warning' && (
|
|
140
|
-
<span className="w-2 h-2 rounded-full bg-orange-500 flex-shrink-0" title=
|
|
156
|
+
<span className="w-2 h-2 rounded-full bg-orange-500 flex-shrink-0" title={warningWindowLabel} />
|
|
141
157
|
)}
|
|
142
158
|
</div>
|
|
143
159
|
{timestamp && (
|