import { redirect } from "next/navigation"; import Link from "next/link"; import { getTranslations, getFormatter } from "next-intl/server"; import { getSessionUser } from "@/lib/session"; import { listSupportTicketsForUser, listAllSupportTickets, } from "@/lib/db"; import { Card } from "@/components/ui/card"; import { formatRelative } from "@/lib/format"; import { TicketStatusBadge } from "@/components/support/ticket-status-badge"; import { TicketCategoryLabel } from "@/components/support/ticket-category-label"; /** * /support — ticket list. * * Customers see their own tickets only (per Feature 5: per-user * scope, NOT per-org). Platform admins see the global queue. Same * UI shell, different list source — the rendering logic is * identical because the per-row data is the same shape. * * Sorting: newest activity first (the DB query already orders by * updated_at DESC). Open tickets bubble to the top by virtue of * having recent activity, but we don't sort by status; that's a * filter the admin can add later if the queue grows. */ export default async function SupportListPage() { const user = await getSessionUser(); if (!user) redirect("/login"); const t = await getTranslations("support"); const f = await getFormatter(); const tickets = user.isPlatform ? await listAllSupportTickets() : await listSupportTicketsForUser(user.id); return (

{user.isPlatform ? t("titleAdmin") : t("title")}

{user.isPlatform ? t("subtitleAdmin") : t("subtitle")}

{!user.isPlatform && ( {t("newTicket")} )}
{tickets.length === 0 ? (

{user.isPlatform ? t("emptyAdmin") : t("empty")}

) : (
{tickets.map((tk) => (
{tk.title}
· {formatRelative(tk.updatedAt, f)} {user.isPlatform && ( <> · {tk.contactEmail} )}
))}
)}
); }