'use client'; import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { api } from '@/lib/api'; import { Card, CardContent } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Skeleton } from '@/components/ui/skeleton'; import { Search, Plus, ChevronRight } from 'lucide-react'; import { format } from 'date-fns'; interface Ticket { id: string; subject: string; type: string; status: string; priority: string; createdAt: string; client?: { firstName: string; lastName: string; accountNumber: string }; assignedTo?: { firstName: string; lastName: string }; } const statusColors: Record = { OPEN: 'bg-blue-100 text-blue-700', IN_PROGRESS: 'bg-yellow-100 text-yellow-700', RESOLVED: 'bg-green-100 text-green-700', CLOSED: 'bg-gray-100 text-gray-500', }; const priorityColors: Record = { HIGH: 'bg-red-100 text-red-700', NORMAL: 'bg-slate-100 text-slate-600', }; const typeColors: Record = { INSTALLATION: 'bg-cyan-100 text-cyan-700', SUPPORT: 'bg-purple-100 text-purple-700', BILLING: 'bg-orange-100 text-orange-700', }; export default function TicketsPage() { const [search, setSearch] = useState(''); const [statusFilter, setStatusFilter] = useState(''); const [typeFilter, setTypeFilter] = useState(''); const [page, setPage] = useState(1); const { data, isLoading } = useQuery<{ data: Ticket[]; total: number }>({ queryKey: ['tickets', search, statusFilter, typeFilter, page], queryFn: async () => { const params = new URLSearchParams({ page: String(page), limit: '20' }); if (statusFilter) params.set('status', statusFilter); if (typeFilter) params.set('type', typeFilter); const res = await api.get(`/api/v1/tickets?${params}`); return res.data; }, staleTime: 30_000, }); const tickets = data?.data ?? []; const total = data?.total ?? 0; return (

Tickets

{total} tickets

{ setSearch(e.target.value); setPage(1); }} />
{isLoading ? Array.from({ length: 8 }).map((_, i) => ( {Array.from({ length: 8 }).map((_, j) => ( ))} )) : tickets.map((t) => ( ))}
Subject Client Type Priority Status Assigned Created
{t.subject} {t.client ? `${t.client.firstName} ${t.client.lastName}` : '—'}
{t.client?.accountNumber}
{t.type} {t.priority} {t.status?.replace('_', ' ')} {t.assignedTo ? `${t.assignedTo.firstName} ${t.assignedTo.lastName}` : 'Unassigned'} {t.createdAt ? format(new Date(t.createdAt), 'MMM d') : '—'}
{!isLoading && tickets.length === 0 && (
No tickets found
)}
); }