diff --git a/src/components/chat/chat-widget.tsx b/src/components/chat/chat-widget.tsx index 37d2d80..bc0b004 100644 --- a/src/components/chat/chat-widget.tsx +++ b/src/components/chat/chat-widget.tsx @@ -1,5 +1,6 @@ "use client" +import Image from "next/image" import { useCallback, useEffect, useRef, useState } from "react" import { useAction, useMutation, useQuery } from "convex/react" import type { Id } from "@/convex/_generated/dataModel" @@ -30,6 +31,8 @@ import { Image as ImageIcon, Download, ExternalLink, + Eye, + Check, } from "lucide-react" const MAX_MESSAGE_LENGTH = 4000 @@ -122,9 +125,17 @@ function MessageAttachment({ attachment }: { attachment: ChatAttachment }) { }, [attachment.storageId, getFileUrl]) const isImage = attachment.type?.startsWith("image/") + const [downloading, setDownloading] = useState(false) + const [downloaded, setDownloaded] = useState(false) + + const handleView = () => { + if (!url) return + window.open(url, "_blank", "noopener,noreferrer") + } const handleDownload = async () => { - if (!url) return + if (!url || downloading) return + setDownloading(true) try { const response = await fetch(url) const blob = await response.blob() @@ -136,8 +147,12 @@ function MessageAttachment({ attachment }: { attachment: ChatAttachment }) { a.click() document.body.removeChild(a) URL.revokeObjectURL(downloadUrl) + setDownloaded(true) + setTimeout(() => setDownloaded(false), 2000) } catch (error) { toast.error("Erro ao baixar arquivo") + } finally { + setDownloading(false) } } @@ -151,31 +166,67 @@ function MessageAttachment({ attachment }: { attachment: ChatAttachment }) { if (isImage && url) { return ( - + - + ) } return ( - + + + ) } @@ -598,6 +649,7 @@ export function ChatWidget() { {attachments.map((file, index) => (
{file.type?.startsWith("image/") && file.previewUrl ? ( + /* eslint-disable-next-line @next/next/no-img-element */ {file.name} - {isAgent ? : } + {isAgent ? : }
- Historico de Chat + Histórico de chat - {chatHistory.sessions.length} {chatHistory.sessions.length === 1 ? "sessao" : "sessoes"} - {chatHistory.totalMessages} mensagens + {chatHistory.sessions.length} {chatHistory.sessions.length === 1 ? "sessão" : "sessões"} - {chatHistory.totalMessages} mensagens diff --git a/src/components/tickets/ticket-timeline.tsx b/src/components/tickets/ticket-timeline.tsx index 211014f..658f8ee 100644 --- a/src/components/tickets/ticket-timeline.tsx +++ b/src/components/tickets/ticket-timeline.tsx @@ -58,6 +58,9 @@ const timelineIcons: Record> = { const timelineLabels: Record = TICKET_TIMELINE_LABELS +// Tipos de eventos que não devem aparecer na timeline +const HIDDEN_EVENT_TYPES = ["CHAT_MESSAGE_ADDED"] + interface TicketTimelineProps { ticket: TicketWithDetails } @@ -82,9 +85,6 @@ export function TicketTimeline({ ticket }: TicketTimelineProps) { const [page, setPage] = useState(1) - // Tipos de eventos que não devem aparecer na timeline - const HIDDEN_EVENT_TYPES = ["CHAT_MESSAGE_ADDED"] - const sortedTimeline = useMemo( () => [...ticket.timeline] .filter((event) => !HIDDEN_EVENT_TYPES.includes(event.type))