"use client"; import * as React from "react"; import Link from "next/link"; import { format } from "date-fns"; import { formatDistanceToNow } from "date-fns"; import { Activity, ArrowRight, Bot, Calendar, CheckCircle2, Clock, LayoutDashboard, MoreHorizontal, Play, PlayCircle, Plus, Settings, Users, } from "lucide-react"; import { Button } from "~/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "~/components/ui/card"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "~/components/ui/dropdown-menu"; import { Progress } from "~/components/ui/progress"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "~/components/ui/select"; import { Badge } from "~/components/ui/badge"; import { ScrollArea } from "~/components/ui/scroll-area"; import { api } from "~/trpc/react"; export default function DashboardPage() { const [studyFilter, setStudyFilter] = React.useState(null); // --- Data Fetching --- const { data: userStudiesData } = api.studies.list.useQuery({ memberOnly: true, limit: 100, }); const userStudies = userStudiesData?.studies ?? []; const { data: stats } = api.dashboard.getStats.useQuery({ studyId: studyFilter ?? undefined, }); const { data: scheduledTrials } = api.trials.list.useQuery({ studyId: studyFilter ?? undefined, status: "scheduled", limit: 5, }); const { data: recentActivity } = api.dashboard.getRecentActivity.useQuery({ limit: 10, studyId: studyFilter ?? undefined, }); const { data: studyProgress } = api.dashboard.getStudyProgress.useQuery({ limit: 5, studyId: studyFilter ?? undefined, }); return (
{/* Header Section */}

Dashboard

Overview of your research activities and upcoming tasks.

{/* Stats Cards */}
{/* Main Column: Scheduled Trials & Study Progress */}
{/* Scheduled Trials */}
Upcoming Sessions You have {scheduledTrials?.length ?? 0} scheduled trials coming up.
{!scheduledTrials?.length ? (

No scheduled trials found.

) : (
{scheduledTrials.map((trial) => (

{trial.participant.participantCode} • {trial.experiment.name}

{trial.scheduledAt ? format(trial.scheduledAt, "MMM d, h:mm a") : "Unscheduled"}
))}
)}
{/* Study Progress */} Study Progress Completion tracking for active studies {studyProgress?.map((study) => (
{study.name}
{study.participants} / {study.totalParticipants} Participants
))} {!studyProgress?.length && (

No active studies to track.

)}
{/* Side Column: Recent Activity & Quick Actions */}
{/* Quick Actions */}
{/* Recent Activity */} Recent Activity
{recentActivity?.map((activity) => (
{activity.title}
{activity.description}
{formatDistanceToNow(activity.time, { addSuffix: true })}
))} {!recentActivity?.length && (

No recent activity.

)}
); } function StatsCard({ title, value, icon: Icon, description, trend, }: { title: string; value: string | number; icon: React.ElementType; description: string; trend?: string; }) { return ( {title}
{value}

{description} {trend && {trend}}

); }