import { useQuery, useQueryClient } from "@tanstack/react-query"; import { apiRequest, getQueryFn } from "@/lib/queryClient"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { toast } from "@/hooks/use-toast"; type Ticket = { ticket_id: string; name: string; email: string; subject: string; message: string; status: string; created_at?: string | null; updated_at?: string | null; }; type TicketsResponse = { page: number; page_size: number; total: number; tickets: Ticket[]; }; export default function AdminSupportTickets() { const queryClient = useQueryClient(); const { data, isLoading } = useQuery({ queryKey: ["admin/support-tickets"], queryFn: getQueryFn({ on401: "throw" }), }); const handleDelete = async (ticketId: string) => { const confirmed = window.confirm("Delete this ticket? This cannot be undone."); if (!confirmed) return; try { await apiRequest("DELETE", `admin/support-tickets/${ticketId}`); toast({ title: "Ticket deleted" }); queryClient.invalidateQueries({ queryKey: ["admin/support-tickets"] }); } catch (err: any) { toast({ title: "Delete failed", description: err?.message || "Try again." }); } }; if (isLoading) { return
Loading tickets...
; } return (

Support Tickets

All customer support requests.

{data?.total ?? 0} total
Ticket ID Name Email Details Status Created Action {data?.tickets?.length ? ( data.tickets.map((ticket) => ( {ticket.ticket_id} {ticket.name} {ticket.email}
{ticket.subject}
View message
{ticket.message}
{ticket.status} {ticket.created_at ? new Date(ticket.created_at).toLocaleString() : "-"}
)) ) : ( No tickets yet. )}
); }