import Link from "next/link"; import type { Ticket } from "@/payload-types"; import { Item, ItemContent, ItemHeader, ItemTitle } from "@/components/ui/item"; import { ChevronRightIcon, LifeBuoyIcon } from "lucide-react"; import { CLOSING_STATUSES, STATUS_STYLES, statusLabel, } from "@/lib/tickets/ticketMeta"; interface MyTicketsProps { readonly tickets: Ticket[]; readonly openCount: number; } function timeAgo(dateStr: string): string { const now = new Date(); const date = new Date(dateStr); const diffMs = now.getTime() - date.getTime(); const diffMins = Math.floor(diffMs / 60000); if (diffMins < 1) return "just now"; if (diffMins < 60) return `${diffMins}m ago`; const diffHours = Math.floor(diffMins / 60); if (diffHours < 24) return `${diffHours}h ago`; const diffDays = Math.floor(diffHours / 24); return `${diffDays}d ago`; } export function MyTickets({ tickets, openCount }: MyTicketsProps) { return (
My Tickets {openCount > 0 && ( {openCount} open )}
View all
{tickets.length === 0 ? (

No tickets yet.

) : (
{tickets.map((ticket) => ( {statusLabel(ticket.status)}
{ticket.title} Updated {timeAgo(ticket.updatedAt)}
))}
)}
); }