import { useState } from 'react'; import { format, formatDistanceToNow } from 'date-fns'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { ChevronDown, ChevronRight } from 'lucide-react'; import { AUDIT_LABELS, AUDIT_COLORS } from '../../../../shared/constants/labels'; import { injectMentionLinks } from '../../lib/mentions'; import type { AuditLog, User } from '../../types'; const COMMENT_ACTIONS = new Set(['COMMENT_ADDED', 'COMMENT_DELETED']); interface TicketAuditLogProps { auditLogs: AuditLog[]; users: User[]; } export default function TicketAuditLog({ auditLogs, users }: TicketAuditLogProps) { const [expandedLogs, setExpandedLogs] = useState>(new Set()); const toggleLog = (logId: string) => { setExpandedLogs((prev) => { const next = new Set(prev); if (next.has(logId)) next.delete(logId); else next.add(logId); return next; }); }; if (auditLogs.length === 0) { return (
No activity yet
); } return (
{auditLogs.map((log, i) => { const hasDetail = !!log.detail; const isExpanded = expandedLogs.has(log.id); const isComment = COMMENT_ACTIONS.has(log.action); return (
{i < auditLogs.length - 1 && (
)}
hasDetail && toggleLog(log.id)} >

{log.user.displayName} {' '} {AUDIT_LABELS[log.action] ?? log.action.toLowerCase()} {hasDetail && ( {isExpanded ? ( ) : ( )} )}

{formatDistanceToNow(new Date(log.createdAt), { addSuffix: true })}
{hasDetail && isExpanded && (
{isComment ? (
{injectMentionLinks(log.detail!, users)}
) : (

{log.detail}

)}
)}
); })}
); }