'use client'
import Link from 'next/link'
import type { Route } from 'next'
import { trpc } from '@/lib/trpc/client'
import { Card, CardContent } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import {
CircleDot,
AlertTriangle,
Upload,
UserPlus,
Settings,
ClipboardCheck,
Users,
Send,
FileDown,
Calendar,
Eye,
Presentation,
Vote,
Play,
Lock,
} from 'lucide-react'
import { GeographicSummaryCard } from '@/components/charts'
import { AnimatedCard } from '@/components/shared/animated-container'
import { motion } from 'motion/react'
import { CompetitionPipeline } from '@/components/dashboard/competition-pipeline'
import { RoundStats } from '@/components/dashboard/round-stats'
import { ActiveRoundPanel } from '@/components/dashboard/active-round-panel'
import { SmartActions } from '@/components/dashboard/smart-actions'
import { ProjectListCompact } from '@/components/dashboard/project-list-compact'
import { ActivityFeed } from '@/components/dashboard/activity-feed'
import { CategoryBreakdown } from '@/components/dashboard/category-breakdown'
import { DashboardSkeleton } from '@/components/dashboard/dashboard-skeleton'
import { RecentEvaluations } from '@/components/dashboard/recent-evaluations'
import { SemiFinalistTracker } from '@/components/dashboard/semi-finalist-tracker'
type DashboardContentProps = {
editionId: string
sessionName: string
}
type QuickAction = {
label: string
href: string
icon: React.ElementType
}
function getContextualActions(
activeRound: { id: string; roundType: string } | null
): QuickAction[] {
if (!activeRound) {
return [
{ label: 'Rounds', href: '/admin/rounds', icon: CircleDot },
{ label: 'Import', href: '/admin/projects/new', icon: Upload },
{ label: 'Invite', href: '/admin/members', icon: UserPlus },
]
}
const roundHref = `/admin/rounds/${activeRound.id}`
switch (activeRound.roundType) {
case 'INTAKE':
return [
{ label: 'Import Projects', href: '/admin/projects/new', icon: Upload },
{ label: 'Review', href: roundHref, icon: ClipboardCheck },
{ label: 'Configure', href: `${roundHref}?tab=config`, icon: Settings },
]
case 'FILTERING':
return [
{ label: 'Run Screening', href: roundHref, icon: ClipboardCheck },
{ label: 'Review Results', href: `${roundHref}?tab=filtering`, icon: Eye },
{ label: 'Configure', href: `${roundHref}?tab=config`, icon: Settings },
]
case 'EVALUATION':
return [
{ label: 'Assignments', href: `${roundHref}?tab=assignments`, icon: Users },
{ label: 'Send Reminders', href: `${roundHref}?tab=assignments`, icon: Send },
{ label: 'Export', href: roundHref, icon: FileDown },
]
case 'SUBMISSION':
return [
{ label: 'Submissions', href: roundHref, icon: ClipboardCheck },
{ label: 'Deadlines', href: `${roundHref}?tab=config`, icon: Calendar },
{ label: 'Status', href: `${roundHref}?tab=projects`, icon: Eye },
]
case 'MENTORING':
return [
{ label: 'Mentors', href: `${roundHref}?tab=projects`, icon: Users },
{ label: 'Progress', href: roundHref, icon: Eye },
{ label: 'Configure', href: `${roundHref}?tab=config`, icon: Settings },
]
case 'LIVE_FINAL':
return [
{ label: 'Live Control', href: roundHref, icon: Presentation },
{ label: 'Results', href: `${roundHref}?tab=projects`, icon: Vote },
{ label: 'Configure', href: `${roundHref}?tab=config`, icon: Settings },
]
case 'DELIBERATION':
return [
{ label: 'Sessions', href: roundHref, icon: Play },
{ label: 'Results', href: `${roundHref}?tab=projects`, icon: Eye },
{ label: 'Lock Results', href: roundHref, icon: Lock },
]
default:
return [
{ label: 'Rounds', href: '/admin/rounds', icon: CircleDot },
{ label: 'Import', href: '/admin/projects/new', icon: Upload },
{ label: 'Invite', href: '/admin/members', icon: UserPlus },
]
}
}
export function DashboardContent({ editionId, sessionName }: DashboardContentProps) {
const { data, isLoading, error } = trpc.dashboard.getStats.useQuery(
{ editionId },
{ enabled: !!editionId, refetchInterval: 60_000 }
)
const { data: recentEvals } = trpc.dashboard.getRecentEvaluations.useQuery(
{ editionId, limit: 8 },
{ enabled: !!editionId, refetchInterval: 60_000 }
)
const { data: liveActivity } = trpc.dashboard.getRecentActivity.useQuery(
{ limit: 8 },
{ enabled: !!editionId, refetchInterval: 30_000 }
)
const { data: semiFinalistStats } = trpc.dashboard.getSemiFinalistStats.useQuery(
{ editionId },
{ enabled: !!editionId, refetchInterval: 120_000 }
)
const { data: featureFlags } = trpc.settings.getFeatureFlags.useQuery()
if (isLoading) {
return Failed to load dashboard
{error.message || 'An unexpected error occurred. Please try refreshing the page.'}
Edition not found
The selected edition could not be found
Welcome back, {sessionName}
{edition.name} {edition.year}