import { Metadata } from "next"; import { notFound, redirect } from "next/navigation"; import Link from "next/link"; import { auth } from "@/auth"; import { db } from "@/lib/db"; import { Building2, Mail, User2, Phone, ArrowLeft, ExternalLink, Copy } from "lucide-react"; import { Button } from "@/components/ui/button"; import { ShareReviewDialog } from "@/components/clients/ShareReviewDialog"; import { ReviewSessionList } from "@/components/clients/ReviewSessionList"; import { cn } from "@/lib/utils"; export const metadata: Metadata = { title: "Client Detail" }; async function getClient(clientId: string) { return db.client.findUnique({ where: { id: clientId }, include: { projects: { orderBy: { createdAt: "desc" }, include: { _count: { select: { shots: true } }, }, }, }, }); } async function getReviewSessions(projectIds: string[]) { if (projectIds.length === 0) return []; return db.reviewSession.findMany({ where: { projectId: { in: projectIds }, isActive: true }, orderBy: { createdAt: "desc" }, include: { project: { select: { name: true } } }, }); } export default async function ClientDetailPage({ params, }: { params: Promise<{ clientId: string }>; }) { const { clientId } = await params; const session = await auth(); if (!session || !["ADMIN", "PRODUCER"].includes(session.user.role as string)) { redirect("/dashboard"); } const client = await getClient(clientId); if (!client) notFound(); const projectIds = client.projects.map((p) => p.id); const reviewSessions = await getReviewSessions(projectIds); const PROJECT_STATUS_COLORS: Record = { ACTIVE: "text-emerald-400 bg-emerald-500/10", COMPLETED: "text-zinc-400 bg-zinc-700", ON_HOLD: "text-amber-400 bg-amber-500/10", CANCELLED: "text-red-400 bg-red-500/10", }; return (
{/* Back */} All Clients {/* Client header */}

{client.company}

{client.isActive ? "Active" : "Inactive"}
{client.contactPerson && (
{client.contactPerson}
)} {client.email && ( )} {client.phone && (
{client.phone}
)}
{client.notes && (

{client.notes}

)}
{/* Projects */}

Projects ({client.projects.length})

{client.projects.length === 0 ? (

No projects assigned to this client.

) : (
{client.projects.map((project) => (

{project.name}

{project.code}

{project._count.shots} shots {project.status}
))}
)}
{/* Review sessions */}
); }