From 300179279a72d0c2b8f17dbdc6edfc39a93326e3 Mon Sep 17 00:00:00 2001 From: rever-tecnologia Date: Mon, 15 Dec 2025 10:10:04 -0300 Subject: [PATCH] feat(chat): adiciona separador de dias e melhora layout do header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Adiciona separador de data entre mensagens de dias diferentes (estilo WhatsApp) - Mostra "Hoje", "Ontem" ou data completa (ex: "segunda-feira, 15 de dezembro") - Separa hostname da maquina em linha propria no header - Hostname com truncate e tooltip para nomes longos 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/components/chat/chat-widget.tsx | 75 +++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/src/components/chat/chat-widget.tsx b/src/components/chat/chat-widget.tsx index ace0ddd..5083ab5 100644 --- a/src/components/chat/chat-widget.tsx +++ b/src/components/chat/chat-widget.tsx @@ -53,6 +53,40 @@ function formatTime(timestamp: number) { }) } +function formatDateSeparator(timestamp: number) { + const date = new Date(timestamp) + const today = new Date() + const yesterday = new Date(today) + yesterday.setDate(yesterday.getDate() - 1) + + const isToday = date.toDateString() === today.toDateString() + const isYesterday = date.toDateString() === yesterday.toDateString() + + if (isToday) return "Hoje" + if (isYesterday) return "Ontem" + + return date.toLocaleDateString("pt-BR", { + weekday: "long", + day: "2-digit", + month: "long", + }) +} + +function getDateKey(timestamp: number) { + return new Date(timestamp).toDateString() +} + +// Componente separador de data (estilo WhatsApp) +function DateSeparator({ timestamp }: { timestamp: number }) { + return ( +
+
+ {formatDateSeparator(timestamp)} +
+
+ ) +} + type ChatSession = { ticketId: string ticketRef: number @@ -661,16 +695,22 @@ export function ChatWidget() { )} {activeSession && ( - - #{activeSession.ticketRef} - {machineHostname && - {machineHostname}} - - +
+ + #{activeSession.ticketRef} + + + {machineHostname && ( + + {machineHostname} + + )} +
)} @@ -757,16 +797,22 @@ export function ChatWidget() { ) : (
- {messages.map((msg) => { + {messages.map((msg, index) => { const isOwn = String(msg.authorId) === String(viewerId) const bodyText = msg.body?.trim() ?? "" const shouldShowBody = bodyText.length > 0 && !(bodyText === "[Anexo]" && (msg.attachments?.length ?? 0) > 0) + + // Verificar se precisa mostrar separador de data + const prevMsg = index > 0 ? messages[index - 1] : null + const showDateSeparator = !prevMsg || getDateKey(msg.createdAt) !== getDateKey(prevMsg.createdAt) + return ( -
+ {showDateSeparator && } +
+
) })}