"use client"; import { useParams } from "next/navigation"; import { Suspense, useEffect } from "react"; import Link from "next/link"; import { Play, Zap, ArrowLeft, User, FlaskConical, LineChart } from "lucide-react"; import { PageHeader } from "~/components/ui/page-header"; import { Button } from "~/components/ui/button"; import { Badge } from "~/components/ui/badge"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "~/components/ui/card"; import { useBreadcrumbsEffect } from "~/components/ui/breadcrumb-provider"; import { useStudyContext } from "~/lib/study-context"; import { useSelectedStudyDetails } from "~/hooks/useSelectedStudyDetails"; import { api } from "~/trpc/react"; import { formatDistanceToNow } from "date-fns"; function TrialDetailContent() { const params = useParams(); const studyId: string = typeof params.id === "string" ? params.id : ""; const trialId: string = typeof params.trialId === "string" ? params.trialId : ""; const { setSelectedStudyId, selectedStudyId } = useStudyContext(); const { study } = useSelectedStudyDetails(); // Get trial data const { data: trial, isLoading, error, } = api.trials.get.useQuery({ id: trialId }, { enabled: !!trialId }); // Set breadcrumbs useBreadcrumbsEffect([ { label: "Dashboard", href: "/dashboard" }, { label: "Studies", href: "/studies" }, { label: study?.name ?? "Study", href: `/studies/${studyId}` }, { label: "Trials", href: `/studies/${studyId}/trials` }, { label: trial?.participant.participantCode ?? "Trial" }, ]); // Sync selected study (unified study-context) useEffect(() => { if (studyId && selectedStudyId !== studyId) { setSelectedStudyId(studyId); } }, [studyId, selectedStudyId, setSelectedStudyId]); const getStatusBadgeVariant = (status: string) => { switch (status) { case "completed": return "default"; case "in_progress": return "secondary"; case "scheduled": return "outline"; case "failed": case "aborted": return "destructive"; default: return "outline"; } }; if (isLoading) { return (
{error.message || "Failed to load trial data"}
The requested trial could not be found.