import { format } from "date-fns" import type { ComponentType } from "react" import { ptBR } from "date-fns/locale" import { IconClockHour4, IconNote, IconSquareCheck, IconUserCircle, } from "@tabler/icons-react" import type { TicketWithDetails } from "@/lib/schemas/ticket" import { cn } from "@/lib/utils" import { Card, CardContent } from "@/components/ui/card" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Separator } from "@/components/ui/separator" const timelineIcons: Record> = { CREATED: IconUserCircle, STATUS_CHANGED: IconSquareCheck, ASSIGNEE_CHANGED: IconUserCircle, COMMENT_ADDED: IconNote, } const timelineLabels: Record = { CREATED: "Criado", STATUS_CHANGED: "Status alterado", ASSIGNEE_CHANGED: "Responsável alterado", COMMENT_ADDED: "Comentário adicionado", QUEUE_CHANGED: "Fila alterada", } interface TicketTimelineProps { ticket: TicketWithDetails } export function TicketTimeline({ ticket }: TicketTimelineProps) { return ( {ticket.timeline.map((entry, index) => { const Icon = timelineIcons[entry.type] ?? IconClockHour4 const isLast = index === ticket.timeline.length - 1 return (
{!isLast && ( )}
{timelineLabels[entry.type] ?? entry.type} {entry.payload?.actorName ? ( {entry.payload.actorName.split(' ').slice(0,2).map((p:string)=>p[0]).join('').toUpperCase()} por {entry.payload.actorName} ) : null} {format(entry.createdAt, "dd MMM yyyy HH:mm", { locale: ptBR })}
{(() => { const p: any = entry.payload || {} let message: string | null = null if (entry.type === "STATUS_CHANGED" && (p.toLabel || p.to)) message = `Status alterado para ${p.toLabel || p.to}` if (entry.type === "ASSIGNEE_CHANGED" && (p.assigneeName || p.assigneeId)) message = `Responsável alterado${p.assigneeName ? ` para ${p.assigneeName}` : ""}` if (entry.type === "QUEUE_CHANGED" && (p.queueName || p.queueId)) message = `Fila alterada${p.queueName ? ` para ${p.queueName}` : ""}` if (entry.type === "CREATED" && (p.requesterName)) message = `Criado por ${p.requesterName}` if (entry.type === "COMMENT_ADDED" && (p.authorName || p.authorId)) message = `Comentário adicionado${p.authorName ? ` por ${p.authorName}` : ""}` if (!message) return null return (
{message}
) })()}
) })}
) }