Apply full refactor updates plus pipeline/email UX confirmations
All checks were successful
Build and Push Docker Image / build (push) Successful in 10m33s

This commit is contained in:
Matt
2026-02-14 15:26:42 +01:00
parent e56e143a40
commit b5425e705e
374 changed files with 116737 additions and 111969 deletions

View File

@@ -1,213 +1,213 @@
'use client'
import { useSession } from 'next-auth/react'
import { trpc } from '@/lib/trpc/client'
import { Badge } from '@/components/ui/badge'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Skeleton } from '@/components/ui/skeleton'
import { RequirementUploadList } from '@/components/shared/requirement-upload-slot'
import {
FileText,
Upload,
AlertTriangle,
Clock,
Video,
File,
Download,
} from 'lucide-react'
const fileTypeIcons: Record<string, typeof FileText> = {
EXEC_SUMMARY: FileText,
BUSINESS_PLAN: FileText,
PRESENTATION: FileText,
VIDEO_PITCH: Video,
VIDEO: Video,
OTHER: File,
SUPPORTING_DOC: File,
}
const fileTypeLabels: Record<string, string> = {
EXEC_SUMMARY: 'Executive Summary',
BUSINESS_PLAN: 'Business Plan',
PRESENTATION: 'Presentation',
VIDEO_PITCH: 'Video Pitch',
VIDEO: 'Video',
OTHER: 'Other Document',
SUPPORTING_DOC: 'Supporting Document',
}
export default function ApplicantDocumentsPage() {
const { status: sessionStatus } = useSession()
const isAuthenticated = sessionStatus === 'authenticated'
const { data, isLoading } = trpc.applicant.getMyDashboard.useQuery(undefined, {
enabled: isAuthenticated,
})
if (isLoading) {
return (
<div className="space-y-6">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-64" />
</div>
<Skeleton className="h-64 w-full" />
<Skeleton className="h-48 w-full" />
</div>
)
}
if (!data?.project) {
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Documents</h1>
</div>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12">
<FileText className="h-12 w-12 text-muted-foreground/50 mb-4" />
<h2 className="text-xl font-semibold mb-2">No Project</h2>
<p className="text-muted-foreground text-center">
Submit a project first to upload documents.
</p>
</CardContent>
</Card>
</div>
)
}
const { project, openStages } = data
const isDraft = !project.submittedAt
return (
<div className="space-y-6">
{/* Header */}
<div>
<h1 className="text-2xl font-semibold tracking-tight flex items-center gap-2">
<Upload className="h-6 w-6" />
Documents
</h1>
<p className="text-muted-foreground">
Upload and manage documents for your project: {project.title}
</p>
</div>
{/* Per-stage upload sections */}
{openStages.length > 0 && (
<div className="space-y-6">
{openStages.map((stage) => {
const now = new Date()
const hasDeadline = !!stage.windowCloseAt
const deadlinePassed = hasDeadline && now > new Date(stage.windowCloseAt!)
const isLate = deadlinePassed
return (
<Card key={stage.id}>
<CardHeader>
<div className="flex items-center justify-between">
<div>
<CardTitle className="text-lg">{stage.name}</CardTitle>
<CardDescription>
Upload documents for this stage
</CardDescription>
</div>
<div className="flex items-center gap-2">
{isLate && (
<Badge variant="warning" className="gap-1">
<AlertTriangle className="h-3 w-3" />
Late submission
</Badge>
)}
{hasDeadline && !deadlinePassed && (
<Badge variant="outline" className="gap-1">
<Clock className="h-3 w-3" />
Due {new Date(stage.windowCloseAt!).toLocaleDateString()}
</Badge>
)}
</div>
</div>
</CardHeader>
<CardContent>
<RequirementUploadList
projectId={project.id}
stageId={stage.id}
disabled={false}
/>
</CardContent>
</Card>
)
})}
</div>
)}
{/* Uploaded files list */}
<Card>
<CardHeader>
<CardTitle>All Uploaded Documents</CardTitle>
<CardDescription>
All files associated with your project
</CardDescription>
</CardHeader>
<CardContent>
{project.files.length === 0 ? (
<p className="text-muted-foreground text-center py-4">
No documents uploaded yet
</p>
) : (
<div className="space-y-2">
{project.files.map((file) => {
const Icon = fileTypeIcons[file.fileType] || File
const fileRecord = file as typeof file & { isLate?: boolean; stageId?: string | null }
return (
<div
key={file.id}
className="flex items-center justify-between p-3 rounded-lg border"
>
<div className="flex items-center gap-3">
<Icon className="h-5 w-5 text-muted-foreground" />
<div>
<div className="flex items-center gap-2">
<p className="font-medium text-sm">{file.fileName}</p>
{fileRecord.isLate && (
<Badge variant="warning" className="text-xs gap-1">
<AlertTriangle className="h-3 w-3" />
Late
</Badge>
)}
</div>
<p className="text-xs text-muted-foreground">
{fileTypeLabels[file.fileType] || file.fileType}
{' - '}
{new Date(file.createdAt).toLocaleDateString()}
</p>
</div>
</div>
</div>
)
})}
</div>
)}
</CardContent>
</Card>
{/* No open stages message */}
{openStages.length === 0 && project.files.length === 0 && (
<Card className="bg-muted/50">
<CardContent className="p-6 text-center">
<Clock className="h-10 w-10 mx-auto text-muted-foreground/50 mb-3" />
<p className="text-muted-foreground">
No stages are currently open for document submissions.
</p>
</CardContent>
</Card>
)}
</div>
)
}
'use client'
import { useSession } from 'next-auth/react'
import { trpc } from '@/lib/trpc/client'
import { Badge } from '@/components/ui/badge'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Skeleton } from '@/components/ui/skeleton'
import { RequirementUploadList } from '@/components/shared/requirement-upload-slot'
import {
FileText,
Upload,
AlertTriangle,
Clock,
Video,
File,
Download,
} from 'lucide-react'
const fileTypeIcons: Record<string, typeof FileText> = {
EXEC_SUMMARY: FileText,
BUSINESS_PLAN: FileText,
PRESENTATION: FileText,
VIDEO_PITCH: Video,
VIDEO: Video,
OTHER: File,
SUPPORTING_DOC: File,
}
const fileTypeLabels: Record<string, string> = {
EXEC_SUMMARY: 'Executive Summary',
BUSINESS_PLAN: 'Business Plan',
PRESENTATION: 'Presentation',
VIDEO_PITCH: 'Video Pitch',
VIDEO: 'Video',
OTHER: 'Other Document',
SUPPORTING_DOC: 'Supporting Document',
}
export default function ApplicantDocumentsPage() {
const { status: sessionStatus } = useSession()
const isAuthenticated = sessionStatus === 'authenticated'
const { data, isLoading } = trpc.applicant.getMyDashboard.useQuery(undefined, {
enabled: isAuthenticated,
})
if (isLoading) {
return (
<div className="space-y-6">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-64" />
</div>
<Skeleton className="h-64 w-full" />
<Skeleton className="h-48 w-full" />
</div>
)
}
if (!data?.project) {
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Documents</h1>
</div>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12">
<FileText className="h-12 w-12 text-muted-foreground/50 mb-4" />
<h2 className="text-xl font-semibold mb-2">No Project</h2>
<p className="text-muted-foreground text-center">
Submit a project first to upload documents.
</p>
</CardContent>
</Card>
</div>
)
}
const { project, openStages } = data
const isDraft = !project.submittedAt
return (
<div className="space-y-6">
{/* Header */}
<div>
<h1 className="text-2xl font-semibold tracking-tight flex items-center gap-2">
<Upload className="h-6 w-6" />
Documents
</h1>
<p className="text-muted-foreground">
Upload and manage documents for your project: {project.title}
</p>
</div>
{/* Per-stage upload sections */}
{openStages.length > 0 && (
<div className="space-y-6">
{openStages.map((stage) => {
const now = new Date()
const hasDeadline = !!stage.windowCloseAt
const deadlinePassed = hasDeadline && now > new Date(stage.windowCloseAt!)
const isLate = deadlinePassed
return (
<Card key={stage.id}>
<CardHeader>
<div className="flex items-center justify-between">
<div>
<CardTitle className="text-lg">{stage.name}</CardTitle>
<CardDescription>
Upload documents for this stage
</CardDescription>
</div>
<div className="flex items-center gap-2">
{isLate && (
<Badge variant="warning" className="gap-1">
<AlertTriangle className="h-3 w-3" />
Late submission
</Badge>
)}
{hasDeadline && !deadlinePassed && (
<Badge variant="outline" className="gap-1">
<Clock className="h-3 w-3" />
Due {new Date(stage.windowCloseAt!).toLocaleDateString()}
</Badge>
)}
</div>
</div>
</CardHeader>
<CardContent>
<RequirementUploadList
projectId={project.id}
stageId={stage.id}
disabled={false}
/>
</CardContent>
</Card>
)
})}
</div>
)}
{/* Uploaded files list */}
<Card>
<CardHeader>
<CardTitle>All Uploaded Documents</CardTitle>
<CardDescription>
All files associated with your project
</CardDescription>
</CardHeader>
<CardContent>
{project.files.length === 0 ? (
<p className="text-muted-foreground text-center py-4">
No documents uploaded yet
</p>
) : (
<div className="space-y-2">
{project.files.map((file) => {
const Icon = fileTypeIcons[file.fileType] || File
const fileRecord = file as typeof file & { isLate?: boolean; stageId?: string | null }
return (
<div
key={file.id}
className="flex items-center justify-between p-3 rounded-lg border"
>
<div className="flex items-center gap-3">
<Icon className="h-5 w-5 text-muted-foreground" />
<div>
<div className="flex items-center gap-2">
<p className="font-medium text-sm">{file.fileName}</p>
{fileRecord.isLate && (
<Badge variant="warning" className="text-xs gap-1">
<AlertTriangle className="h-3 w-3" />
Late
</Badge>
)}
</div>
<p className="text-xs text-muted-foreground">
{fileTypeLabels[file.fileType] || file.fileType}
{' - '}
{new Date(file.createdAt).toLocaleDateString()}
</p>
</div>
</div>
</div>
)
})}
</div>
)}
</CardContent>
</Card>
{/* No open stages message */}
{openStages.length === 0 && project.files.length === 0 && (
<Card className="bg-muted/50">
<CardContent className="p-6 text-center">
<Clock className="h-10 w-10 mx-auto text-muted-foreground/50 mb-3" />
<p className="text-muted-foreground">
No stages are currently open for document submissions.
</p>
</CardContent>
</Card>
)}
</div>
)
}

View File

@@ -1,138 +1,138 @@
'use client'
import { useSession } from 'next-auth/react'
import { trpc } from '@/lib/trpc/client'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Skeleton } from '@/components/ui/skeleton'
import { MentorChat } from '@/components/shared/mentor-chat'
import {
MessageSquare,
UserCircle,
FileText,
} from 'lucide-react'
export default function ApplicantMentorPage() {
const { data: session, status: sessionStatus } = useSession()
const isAuthenticated = sessionStatus === 'authenticated'
const { data: dashboardData, isLoading: dashLoading } = trpc.applicant.getMyDashboard.useQuery(
undefined,
{ enabled: isAuthenticated }
)
const projectId = dashboardData?.project?.id
const { data: mentorMessages, isLoading: messagesLoading } = trpc.applicant.getMentorMessages.useQuery(
{ projectId: projectId! },
{ enabled: !!projectId }
)
const utils = trpc.useUtils()
const sendMessage = trpc.applicant.sendMentorMessage.useMutation({
onSuccess: () => {
utils.applicant.getMentorMessages.invalidate({ projectId: projectId! })
},
})
if (dashLoading) {
return (
<div className="space-y-6">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-64" />
</div>
<Skeleton className="h-96 w-full" />
</div>
)
}
if (!projectId) {
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Mentor</h1>
</div>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12">
<FileText className="h-12 w-12 text-muted-foreground/50 mb-4" />
<h2 className="text-xl font-semibold mb-2">No Project</h2>
<p className="text-muted-foreground text-center">
Submit a project first to communicate with your mentor.
</p>
</CardContent>
</Card>
</div>
)
}
const mentor = dashboardData?.project?.mentorAssignment?.mentor
return (
<div className="space-y-6">
{/* Header */}
<div>
<h1 className="text-2xl font-semibold tracking-tight flex items-center gap-2">
<MessageSquare className="h-6 w-6" />
Mentor Communication
</h1>
<p className="text-muted-foreground">
Chat with your assigned mentor
</p>
</div>
{/* Mentor info */}
{mentor ? (
<Card className="bg-muted/50">
<CardContent className="p-4">
<div className="flex items-center gap-3">
<UserCircle className="h-10 w-10 text-muted-foreground" />
<div>
<p className="font-medium">{mentor.name || 'Mentor'}</p>
<p className="text-sm text-muted-foreground">{mentor.email}</p>
</div>
</div>
</CardContent>
</Card>
) : (
<Card className="bg-muted/50">
<CardContent className="flex flex-col items-center justify-center py-8">
<UserCircle className="h-12 w-12 text-muted-foreground/50 mb-3" />
<p className="text-muted-foreground text-center">
No mentor has been assigned to your project yet.
You&apos;ll be notified when a mentor is assigned.
</p>
</CardContent>
</Card>
)}
{/* Chat */}
{mentor && (
<Card>
<CardHeader>
<CardTitle>Messages</CardTitle>
<CardDescription>
Your conversation history with {mentor.name || 'your mentor'}
</CardDescription>
</CardHeader>
<CardContent>
<MentorChat
messages={mentorMessages || []}
currentUserId={session?.user?.id || ''}
onSendMessage={async (message) => {
await sendMessage.mutateAsync({ projectId: projectId!, message })
}}
isLoading={messagesLoading}
isSending={sendMessage.isPending}
/>
</CardContent>
</Card>
)}
</div>
)
}
'use client'
import { useSession } from 'next-auth/react'
import { trpc } from '@/lib/trpc/client'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Skeleton } from '@/components/ui/skeleton'
import { MentorChat } from '@/components/shared/mentor-chat'
import {
MessageSquare,
UserCircle,
FileText,
} from 'lucide-react'
export default function ApplicantMentorPage() {
const { data: session, status: sessionStatus } = useSession()
const isAuthenticated = sessionStatus === 'authenticated'
const { data: dashboardData, isLoading: dashLoading } = trpc.applicant.getMyDashboard.useQuery(
undefined,
{ enabled: isAuthenticated }
)
const projectId = dashboardData?.project?.id
const { data: mentorMessages, isLoading: messagesLoading } = trpc.applicant.getMentorMessages.useQuery(
{ projectId: projectId! },
{ enabled: !!projectId }
)
const utils = trpc.useUtils()
const sendMessage = trpc.applicant.sendMentorMessage.useMutation({
onSuccess: () => {
utils.applicant.getMentorMessages.invalidate({ projectId: projectId! })
},
})
if (dashLoading) {
return (
<div className="space-y-6">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-64" />
</div>
<Skeleton className="h-96 w-full" />
</div>
)
}
if (!projectId) {
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Mentor</h1>
</div>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12">
<FileText className="h-12 w-12 text-muted-foreground/50 mb-4" />
<h2 className="text-xl font-semibold mb-2">No Project</h2>
<p className="text-muted-foreground text-center">
Submit a project first to communicate with your mentor.
</p>
</CardContent>
</Card>
</div>
)
}
const mentor = dashboardData?.project?.mentorAssignment?.mentor
return (
<div className="space-y-6">
{/* Header */}
<div>
<h1 className="text-2xl font-semibold tracking-tight flex items-center gap-2">
<MessageSquare className="h-6 w-6" />
Mentor Communication
</h1>
<p className="text-muted-foreground">
Chat with your assigned mentor
</p>
</div>
{/* Mentor info */}
{mentor ? (
<Card className="bg-muted/50">
<CardContent className="p-4">
<div className="flex items-center gap-3">
<UserCircle className="h-10 w-10 text-muted-foreground" />
<div>
<p className="font-medium">{mentor.name || 'Mentor'}</p>
<p className="text-sm text-muted-foreground">{mentor.email}</p>
</div>
</div>
</CardContent>
</Card>
) : (
<Card className="bg-muted/50">
<CardContent className="flex flex-col items-center justify-center py-8">
<UserCircle className="h-12 w-12 text-muted-foreground/50 mb-3" />
<p className="text-muted-foreground text-center">
No mentor has been assigned to your project yet.
You&apos;ll be notified when a mentor is assigned.
</p>
</CardContent>
</Card>
)}
{/* Chat */}
{mentor && (
<Card>
<CardHeader>
<CardTitle>Messages</CardTitle>
<CardDescription>
Your conversation history with {mentor.name || 'your mentor'}
</CardDescription>
</CardHeader>
<CardContent>
<MentorChat
messages={mentorMessages || []}
currentUserId={session?.user?.id || ''}
onSendMessage={async (message) => {
await sendMessage.mutateAsync({ projectId: projectId!, message })
}}
isLoading={messagesLoading}
isSending={sendMessage.isPending}
/>
</CardContent>
</Card>
)}
</div>
)
}

View File

@@ -1,363 +1,363 @@
'use client'
import { useSession } from 'next-auth/react'
import Link from 'next/link'
import type { Route } from 'next'
import { trpc } from '@/lib/trpc/client'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Skeleton } from '@/components/ui/skeleton'
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
import { StatusTracker } from '@/components/shared/status-tracker'
import { AnimatedCard } from '@/components/shared/animated-container'
import {
FileText,
Calendar,
Clock,
AlertCircle,
CheckCircle,
Users,
Crown,
MessageSquare,
Upload,
ArrowRight,
} from 'lucide-react'
const statusColors: Record<string, 'default' | 'success' | 'secondary' | 'destructive' | 'warning'> = {
DRAFT: 'secondary',
SUBMITTED: 'default',
UNDER_REVIEW: 'default',
ELIGIBLE: 'default',
SEMIFINALIST: 'success',
FINALIST: 'success',
WINNER: 'success',
REJECTED: 'destructive',
}
export default function ApplicantDashboardPage() {
const { status: sessionStatus } = useSession()
const isAuthenticated = sessionStatus === 'authenticated'
const { data, isLoading } = trpc.applicant.getMyDashboard.useQuery(undefined, {
enabled: isAuthenticated,
})
if (sessionStatus === 'loading' || isLoading) {
return (
<div className="space-y-6">
<div className="space-y-2">
<Skeleton className="h-8 w-64" />
<Skeleton className="h-4 w-96" />
</div>
<div className="grid gap-6 lg:grid-cols-3">
<div className="lg:col-span-2 space-y-6">
<Skeleton className="h-48 w-full" />
<Skeleton className="h-32 w-full" />
</div>
<div className="space-y-6">
<Skeleton className="h-64 w-full" />
<Skeleton className="h-48 w-full" />
</div>
</div>
</div>
)
}
// No project yet
if (!data?.project) {
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">My Project</h1>
<p className="text-muted-foreground">
Your applicant dashboard
</p>
</div>
<AnimatedCard index={0}>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12">
<div className="rounded-2xl bg-muted/60 p-4 mb-4">
<FileText className="h-8 w-8 text-muted-foreground/70" />
</div>
<h2 className="text-xl font-semibold mb-2">No Project Yet</h2>
<p className="text-muted-foreground text-center max-w-md">
You haven&apos;t submitted a project yet. Check for open application rounds
on the MOPC website.
</p>
</CardContent>
</Card>
</AnimatedCard>
</div>
)
}
const { project, timeline, currentStatus, openStages } = data
const isDraft = !project.submittedAt
const programYear = project.program?.year
const programName = project.program?.name
return (
<div className="space-y-6">
{/* Header */}
<div className="flex items-start justify-between flex-wrap gap-4">
<div>
<div className="flex items-center gap-3">
<h1 className="text-2xl font-semibold tracking-tight">{project.title}</h1>
{currentStatus && (
<Badge variant={statusColors[currentStatus] || 'secondary'}>
{currentStatus.replace('_', ' ')}
</Badge>
)}
</div>
<p className="text-muted-foreground">
{programYear ? `${programYear} Edition` : ''}{programName ? ` - ${programName}` : ''}
</p>
</div>
</div>
{/* Draft warning */}
{isDraft && (
<Alert>
<Clock className="h-4 w-4" />
<AlertTitle>Draft Submission</AlertTitle>
<AlertDescription>
This submission has not been submitted yet. You can continue editing and submit when ready.
</AlertDescription>
</Alert>
)}
<div className="grid gap-6 lg:grid-cols-3">
{/* Main content */}
<div className="lg:col-span-2 space-y-6">
{/* Project details */}
<AnimatedCard index={0}>
<Card>
<CardHeader>
<CardTitle>Project Details</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
{project.teamName && (
<div>
<p className="text-sm font-medium text-muted-foreground">Team/Organization</p>
<p>{project.teamName}</p>
</div>
)}
{project.description && (
<div>
<p className="text-sm font-medium text-muted-foreground">Description</p>
<p className="whitespace-pre-wrap">{project.description}</p>
</div>
)}
{project.tags && project.tags.length > 0 && (
<div>
<p className="text-sm font-medium text-muted-foreground mb-2">Tags</p>
<div className="flex flex-wrap gap-2">
{project.tags.map((tag) => (
<Badge key={tag} variant="outline">
{tag}
</Badge>
))}
</div>
</div>
)}
{/* Metadata */}
{project.metadataJson && Object.keys(project.metadataJson as Record<string, unknown>).length > 0 && (
<div className="border-t pt-4 mt-4">
<p className="text-sm font-medium text-muted-foreground mb-3">Additional Information</p>
<dl className="space-y-2">
{Object.entries(project.metadataJson as Record<string, unknown>).map(([key, value]) => (
<div key={key} className="flex justify-between">
<dt className="text-sm text-muted-foreground capitalize">
{key.replace(/_/g, ' ')}
</dt>
<dd className="text-sm font-medium">{String(value)}</dd>
</div>
))}
</dl>
</div>
)}
{/* Meta info row */}
<div className="flex flex-wrap gap-4 text-sm text-muted-foreground border-t pt-4 mt-4">
<div className="flex items-center gap-1">
<Calendar className="h-4 w-4" />
Created {new Date(project.createdAt).toLocaleDateString()}
</div>
{project.submittedAt ? (
<div className="flex items-center gap-1">
<CheckCircle className="h-4 w-4 text-green-500" />
Submitted {new Date(project.submittedAt).toLocaleDateString()}
</div>
) : (
<div className="flex items-center gap-1">
<Clock className="h-4 w-4 text-orange-500" />
Draft
</div>
)}
<div className="flex items-center gap-1">
<FileText className="h-4 w-4" />
{project.files.length} file(s)
</div>
</div>
</CardContent>
</Card>
</AnimatedCard>
{/* Quick actions */}
<AnimatedCard index={1}>
<div className="grid gap-4 sm:grid-cols-3">
<Link href={"/applicant/documents" as Route} className="group flex items-center gap-3 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-blue-500/30 hover:bg-blue-500/5">
<div className="rounded-xl bg-blue-500/10 p-2.5 transition-colors group-hover:bg-blue-500/20">
<Upload className="h-5 w-5 text-blue-600 dark:text-blue-400" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium">Documents</p>
<p className="text-xs text-muted-foreground">
{openStages.length > 0 ? `${openStages.length} stage(s) open` : 'View uploads'}
</p>
</div>
<ArrowRight className="h-4 w-4 text-muted-foreground" />
</Link>
<Link href={"/applicant/team" as Route} className="group flex items-center gap-3 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-purple-500/30 hover:bg-purple-500/5">
<div className="rounded-xl bg-purple-500/10 p-2.5 transition-colors group-hover:bg-purple-500/20">
<Users className="h-5 w-5 text-purple-600 dark:text-purple-400" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium">Team</p>
<p className="text-xs text-muted-foreground">
{project.teamMembers.length} member(s)
</p>
</div>
<ArrowRight className="h-4 w-4 text-muted-foreground" />
</Link>
<Link href={"/applicant/mentor" as Route} className="group flex items-center gap-3 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-green-500/30 hover:bg-green-500/5">
<div className="rounded-xl bg-green-500/10 p-2.5 transition-colors group-hover:bg-green-500/20">
<MessageSquare className="h-5 w-5 text-green-600 dark:text-green-400" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium">Mentor</p>
<p className="text-xs text-muted-foreground">
{project.mentorAssignment?.mentor?.name || 'Not assigned'}
</p>
</div>
<ArrowRight className="h-4 w-4 text-muted-foreground" />
</Link>
</div>
</AnimatedCard>
</div>
{/* Sidebar */}
<div className="space-y-6">
{/* Status timeline */}
<AnimatedCard index={2}>
<Card>
<CardHeader>
<CardTitle>Status Timeline</CardTitle>
</CardHeader>
<CardContent>
<StatusTracker
timeline={timeline}
currentStatus={currentStatus || 'SUBMITTED'}
/>
</CardContent>
</Card>
</AnimatedCard>
{/* Team overview */}
<AnimatedCard index={3}>
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="flex items-center gap-2">
<Users className="h-5 w-5" />
Team
</CardTitle>
<Button variant="ghost" size="sm" asChild>
<Link href={"/applicant/team" as Route}>
Manage
</Link>
</Button>
</div>
</CardHeader>
<CardContent className="space-y-3">
{project.teamMembers.length > 0 ? (
project.teamMembers.slice(0, 5).map((member) => (
<div key={member.id} className="flex items-center gap-3">
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-muted">
{member.role === 'LEAD' ? (
<Crown className="h-4 w-4 text-yellow-500" />
) : (
<span className="text-xs font-medium">
{member.user.name?.charAt(0).toUpperCase() || '?'}
</span>
)}
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium truncate">
{member.user.name || member.user.email}
</p>
<p className="text-xs text-muted-foreground">
{member.role === 'LEAD' ? 'Team Lead' : member.role === 'ADVISOR' ? 'Advisor' : 'Member'}
</p>
</div>
</div>
))
) : (
<p className="text-sm text-muted-foreground text-center py-2">
No team members yet
</p>
)}
{project.teamMembers.length > 5 && (
<p className="text-xs text-muted-foreground text-center">
+{project.teamMembers.length - 5} more
</p>
)}
</CardContent>
</Card>
</AnimatedCard>
{/* Key dates */}
<AnimatedCard index={4}>
<Card>
<CardHeader>
<CardTitle>Key Dates</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Created</span>
<span>{new Date(project.createdAt).toLocaleDateString()}</span>
</div>
{project.submittedAt && (
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Submitted</span>
<span>{new Date(project.submittedAt).toLocaleDateString()}</span>
</div>
)}
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Last Updated</span>
<span>{new Date(project.updatedAt).toLocaleDateString()}</span>
</div>
{openStages.length > 0 && openStages[0].windowCloseAt && (
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Deadline</span>
<span>{new Date(openStages[0].windowCloseAt).toLocaleDateString()}</span>
</div>
)}
</CardContent>
</Card>
</AnimatedCard>
</div>
</div>
</div>
)
}
'use client'
import { useSession } from 'next-auth/react'
import Link from 'next/link'
import type { Route } from 'next'
import { trpc } from '@/lib/trpc/client'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Skeleton } from '@/components/ui/skeleton'
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
import { StatusTracker } from '@/components/shared/status-tracker'
import { AnimatedCard } from '@/components/shared/animated-container'
import {
FileText,
Calendar,
Clock,
AlertCircle,
CheckCircle,
Users,
Crown,
MessageSquare,
Upload,
ArrowRight,
} from 'lucide-react'
const statusColors: Record<string, 'default' | 'success' | 'secondary' | 'destructive' | 'warning'> = {
DRAFT: 'secondary',
SUBMITTED: 'default',
UNDER_REVIEW: 'default',
ELIGIBLE: 'default',
SEMIFINALIST: 'success',
FINALIST: 'success',
WINNER: 'success',
REJECTED: 'destructive',
}
export default function ApplicantDashboardPage() {
const { status: sessionStatus } = useSession()
const isAuthenticated = sessionStatus === 'authenticated'
const { data, isLoading } = trpc.applicant.getMyDashboard.useQuery(undefined, {
enabled: isAuthenticated,
})
if (sessionStatus === 'loading' || isLoading) {
return (
<div className="space-y-6">
<div className="space-y-2">
<Skeleton className="h-8 w-64" />
<Skeleton className="h-4 w-96" />
</div>
<div className="grid gap-6 lg:grid-cols-3">
<div className="lg:col-span-2 space-y-6">
<Skeleton className="h-48 w-full" />
<Skeleton className="h-32 w-full" />
</div>
<div className="space-y-6">
<Skeleton className="h-64 w-full" />
<Skeleton className="h-48 w-full" />
</div>
</div>
</div>
)
}
// No project yet
if (!data?.project) {
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">My Project</h1>
<p className="text-muted-foreground">
Your applicant dashboard
</p>
</div>
<AnimatedCard index={0}>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12">
<div className="rounded-2xl bg-muted/60 p-4 mb-4">
<FileText className="h-8 w-8 text-muted-foreground/70" />
</div>
<h2 className="text-xl font-semibold mb-2">No Project Yet</h2>
<p className="text-muted-foreground text-center max-w-md">
You haven&apos;t submitted a project yet. Check for open application rounds
on the MOPC website.
</p>
</CardContent>
</Card>
</AnimatedCard>
</div>
)
}
const { project, timeline, currentStatus, openStages } = data
const isDraft = !project.submittedAt
const programYear = project.program?.year
const programName = project.program?.name
return (
<div className="space-y-6">
{/* Header */}
<div className="flex items-start justify-between flex-wrap gap-4">
<div>
<div className="flex items-center gap-3">
<h1 className="text-2xl font-semibold tracking-tight">{project.title}</h1>
{currentStatus && (
<Badge variant={statusColors[currentStatus] || 'secondary'}>
{currentStatus.replace('_', ' ')}
</Badge>
)}
</div>
<p className="text-muted-foreground">
{programYear ? `${programYear} Edition` : ''}{programName ? ` - ${programName}` : ''}
</p>
</div>
</div>
{/* Draft warning */}
{isDraft && (
<Alert>
<Clock className="h-4 w-4" />
<AlertTitle>Draft Submission</AlertTitle>
<AlertDescription>
This submission has not been submitted yet. You can continue editing and submit when ready.
</AlertDescription>
</Alert>
)}
<div className="grid gap-6 lg:grid-cols-3">
{/* Main content */}
<div className="lg:col-span-2 space-y-6">
{/* Project details */}
<AnimatedCard index={0}>
<Card>
<CardHeader>
<CardTitle>Project Details</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
{project.teamName && (
<div>
<p className="text-sm font-medium text-muted-foreground">Team/Organization</p>
<p>{project.teamName}</p>
</div>
)}
{project.description && (
<div>
<p className="text-sm font-medium text-muted-foreground">Description</p>
<p className="whitespace-pre-wrap">{project.description}</p>
</div>
)}
{project.tags && project.tags.length > 0 && (
<div>
<p className="text-sm font-medium text-muted-foreground mb-2">Tags</p>
<div className="flex flex-wrap gap-2">
{project.tags.map((tag) => (
<Badge key={tag} variant="outline">
{tag}
</Badge>
))}
</div>
</div>
)}
{/* Metadata */}
{project.metadataJson && Object.keys(project.metadataJson as Record<string, unknown>).length > 0 && (
<div className="border-t pt-4 mt-4">
<p className="text-sm font-medium text-muted-foreground mb-3">Additional Information</p>
<dl className="space-y-2">
{Object.entries(project.metadataJson as Record<string, unknown>).map(([key, value]) => (
<div key={key} className="flex justify-between">
<dt className="text-sm text-muted-foreground capitalize">
{key.replace(/_/g, ' ')}
</dt>
<dd className="text-sm font-medium">{String(value)}</dd>
</div>
))}
</dl>
</div>
)}
{/* Meta info row */}
<div className="flex flex-wrap gap-4 text-sm text-muted-foreground border-t pt-4 mt-4">
<div className="flex items-center gap-1">
<Calendar className="h-4 w-4" />
Created {new Date(project.createdAt).toLocaleDateString()}
</div>
{project.submittedAt ? (
<div className="flex items-center gap-1">
<CheckCircle className="h-4 w-4 text-green-500" />
Submitted {new Date(project.submittedAt).toLocaleDateString()}
</div>
) : (
<div className="flex items-center gap-1">
<Clock className="h-4 w-4 text-orange-500" />
Draft
</div>
)}
<div className="flex items-center gap-1">
<FileText className="h-4 w-4" />
{project.files.length} file(s)
</div>
</div>
</CardContent>
</Card>
</AnimatedCard>
{/* Quick actions */}
<AnimatedCard index={1}>
<div className="grid gap-4 sm:grid-cols-3">
<Link href={"/applicant/documents" as Route} className="group flex items-center gap-3 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-blue-500/30 hover:bg-blue-500/5">
<div className="rounded-xl bg-blue-500/10 p-2.5 transition-colors group-hover:bg-blue-500/20">
<Upload className="h-5 w-5 text-blue-600 dark:text-blue-400" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium">Documents</p>
<p className="text-xs text-muted-foreground">
{openStages.length > 0 ? `${openStages.length} stage(s) open` : 'View uploads'}
</p>
</div>
<ArrowRight className="h-4 w-4 text-muted-foreground" />
</Link>
<Link href={"/applicant/team" as Route} className="group flex items-center gap-3 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-purple-500/30 hover:bg-purple-500/5">
<div className="rounded-xl bg-purple-500/10 p-2.5 transition-colors group-hover:bg-purple-500/20">
<Users className="h-5 w-5 text-purple-600 dark:text-purple-400" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium">Team</p>
<p className="text-xs text-muted-foreground">
{project.teamMembers.length} member(s)
</p>
</div>
<ArrowRight className="h-4 w-4 text-muted-foreground" />
</Link>
<Link href={"/applicant/mentor" as Route} className="group flex items-center gap-3 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-green-500/30 hover:bg-green-500/5">
<div className="rounded-xl bg-green-500/10 p-2.5 transition-colors group-hover:bg-green-500/20">
<MessageSquare className="h-5 w-5 text-green-600 dark:text-green-400" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium">Mentor</p>
<p className="text-xs text-muted-foreground">
{project.mentorAssignment?.mentor?.name || 'Not assigned'}
</p>
</div>
<ArrowRight className="h-4 w-4 text-muted-foreground" />
</Link>
</div>
</AnimatedCard>
</div>
{/* Sidebar */}
<div className="space-y-6">
{/* Status timeline */}
<AnimatedCard index={2}>
<Card>
<CardHeader>
<CardTitle>Status Timeline</CardTitle>
</CardHeader>
<CardContent>
<StatusTracker
timeline={timeline}
currentStatus={currentStatus || 'SUBMITTED'}
/>
</CardContent>
</Card>
</AnimatedCard>
{/* Team overview */}
<AnimatedCard index={3}>
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="flex items-center gap-2">
<Users className="h-5 w-5" />
Team
</CardTitle>
<Button variant="ghost" size="sm" asChild>
<Link href={"/applicant/team" as Route}>
Manage
</Link>
</Button>
</div>
</CardHeader>
<CardContent className="space-y-3">
{project.teamMembers.length > 0 ? (
project.teamMembers.slice(0, 5).map((member) => (
<div key={member.id} className="flex items-center gap-3">
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-muted">
{member.role === 'LEAD' ? (
<Crown className="h-4 w-4 text-yellow-500" />
) : (
<span className="text-xs font-medium">
{member.user.name?.charAt(0).toUpperCase() || '?'}
</span>
)}
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium truncate">
{member.user.name || member.user.email}
</p>
<p className="text-xs text-muted-foreground">
{member.role === 'LEAD' ? 'Team Lead' : member.role === 'ADVISOR' ? 'Advisor' : 'Member'}
</p>
</div>
</div>
))
) : (
<p className="text-sm text-muted-foreground text-center py-2">
No team members yet
</p>
)}
{project.teamMembers.length > 5 && (
<p className="text-xs text-muted-foreground text-center">
+{project.teamMembers.length - 5} more
</p>
)}
</CardContent>
</Card>
</AnimatedCard>
{/* Key dates */}
<AnimatedCard index={4}>
<Card>
<CardHeader>
<CardTitle>Key Dates</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Created</span>
<span>{new Date(project.createdAt).toLocaleDateString()}</span>
</div>
{project.submittedAt && (
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Submitted</span>
<span>{new Date(project.submittedAt).toLocaleDateString()}</span>
</div>
)}
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Last Updated</span>
<span>{new Date(project.updatedAt).toLocaleDateString()}</span>
</div>
{openStages.length > 0 && openStages[0].windowCloseAt && (
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Deadline</span>
<span>{new Date(openStages[0].windowCloseAt).toLocaleDateString()}</span>
</div>
)}
</CardContent>
</Card>
</AnimatedCard>
</div>
</div>
</div>
)
}

View File

@@ -1,167 +1,167 @@
'use client'
import { use } from 'react'
import { trpc } from '@/lib/trpc/client'
import Link from 'next/link'
import type { Route } from 'next'
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import {
ArrowLeft,
AlertCircle,
Clock,
FileText,
Upload,
} from 'lucide-react'
import { StageBreadcrumb } from '@/components/shared/stage-breadcrumb'
import { StageWindowBadge } from '@/components/shared/stage-window-badge'
import { CountdownTimer } from '@/components/shared/countdown-timer'
import { RequirementUploadList } from '@/components/shared/requirement-upload-slot'
export default function StageDocumentsPage({
params,
}: {
params: Promise<{ stageId: string }>
}) {
const { stageId } = use(params)
// Get applicant's project via dashboard endpoint
const { data: dashboard } = trpc.applicant.getMyDashboard.useQuery()
const project = dashboard?.project
const projectId = project?.id ?? ''
const { data: requirements, isLoading: reqLoading } =
trpc.stage.getRequirements.useQuery(
{ stageId, projectId },
{ enabled: !!projectId }
)
const isWindowOpen = requirements?.windowStatus?.isOpen ?? false
const isLate = requirements?.windowStatus?.isLate ?? false
const closeAt = requirements?.windowStatus?.closesAt
? new Date(requirements.windowStatus.closesAt)
: null
if (reqLoading) {
return (
<div className="space-y-4">
<Skeleton className="h-6 w-64" />
<Skeleton className="h-8 w-48" />
<Skeleton className="h-64 w-full" />
</div>
)
}
return (
<div className="space-y-4">
{/* Back */}
<div className="flex items-center gap-3">
<Button variant="ghost" size="icon" asChild className="h-8 w-8">
<Link href={"/applicant/pipeline" as Route}>
<ArrowLeft className="h-4 w-4" />
</Link>
</Button>
<span className="text-sm text-muted-foreground">Back to Pipeline</span>
</div>
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div>
<h1 className="text-2xl font-bold tracking-tight">Stage Documents</h1>
<p className="text-sm text-muted-foreground mt-0.5">
Upload required documents for this stage
</p>
</div>
<StageWindowBadge
windowOpenAt={requirements?.deadlineInfo?.windowOpenAt}
windowCloseAt={requirements?.deadlineInfo?.windowCloseAt}
/>
</div>
{/* Deadline info */}
{closeAt && isWindowOpen && (
<Card>
<CardContent className="flex items-center justify-between py-3">
<div className="flex items-center gap-2">
<Clock className="h-4 w-4 text-muted-foreground" />
<span className="text-sm">Submission deadline</span>
</div>
<CountdownTimer deadline={closeAt} label="Closes in" />
</CardContent>
</Card>
)}
{/* Late submission warning */}
{isLate && (
<Card className="border-amber-200 bg-amber-50/50 dark:border-amber-900 dark:bg-amber-950/20">
<CardContent className="flex items-center gap-3 py-3">
<AlertCircle className="h-5 w-5 text-amber-600 shrink-0" />
<p className="text-sm text-amber-800 dark:text-amber-200">
The submission window has passed. Late submissions may be accepted at the discretion of the administrators.
</p>
</CardContent>
</Card>
)}
{/* Window closed */}
{!isWindowOpen && !isLate && (
<Card className="border-destructive/50 bg-destructive/5">
<CardContent className="flex items-center gap-3 py-3">
<AlertCircle className="h-5 w-5 text-destructive shrink-0" />
<p className="text-sm text-destructive">
The document submission window for this stage is closed.
</p>
</CardContent>
</Card>
)}
{/* File requirements */}
{requirements?.fileRequirements && requirements.fileRequirements.length > 0 ? (
<RequirementUploadList
projectId={projectId}
stageId={stageId}
disabled={!isWindowOpen && !isLate}
/>
) : (
<Card>
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
<FileText className="h-12 w-12 text-muted-foreground/50 mb-3" />
<p className="font-medium">No document requirements</p>
<p className="text-sm text-muted-foreground mt-1">
There are no specific document requirements for this stage.
</p>
</CardContent>
</Card>
)}
{/* Uploaded files summary */}
{requirements?.uploadedFiles && requirements.uploadedFiles.length > 0 && (
<Card>
<CardHeader>
<CardTitle className="text-lg">Uploaded Files</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-2">
{requirements.uploadedFiles.map((file: { id: string; fileName: string; size: number; createdAt: string | Date }) => (
<div key={file.id} className="flex items-center gap-3 text-sm">
<FileText className="h-4 w-4 text-muted-foreground shrink-0" />
<span className="truncate">{file.fileName}</span>
<span className="text-xs text-muted-foreground shrink-0">
{(file.size / (1024 * 1024)).toFixed(1)}MB
</span>
</div>
))}
</div>
</CardContent>
</Card>
)}
</div>
)
}
'use client'
import { use } from 'react'
import { trpc } from '@/lib/trpc/client'
import Link from 'next/link'
import type { Route } from 'next'
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import {
ArrowLeft,
AlertCircle,
Clock,
FileText,
Upload,
} from 'lucide-react'
import { StageBreadcrumb } from '@/components/shared/stage-breadcrumb'
import { StageWindowBadge } from '@/components/shared/stage-window-badge'
import { CountdownTimer } from '@/components/shared/countdown-timer'
import { RequirementUploadList } from '@/components/shared/requirement-upload-slot'
export default function StageDocumentsPage({
params,
}: {
params: Promise<{ stageId: string }>
}) {
const { stageId } = use(params)
// Get applicant's project via dashboard endpoint
const { data: dashboard } = trpc.applicant.getMyDashboard.useQuery()
const project = dashboard?.project
const projectId = project?.id ?? ''
const { data: requirements, isLoading: reqLoading } =
trpc.stage.getRequirements.useQuery(
{ stageId, projectId },
{ enabled: !!projectId }
)
const isWindowOpen = requirements?.windowStatus?.isOpen ?? false
const isLate = requirements?.windowStatus?.isLate ?? false
const closeAt = requirements?.windowStatus?.closesAt
? new Date(requirements.windowStatus.closesAt)
: null
if (reqLoading) {
return (
<div className="space-y-4">
<Skeleton className="h-6 w-64" />
<Skeleton className="h-8 w-48" />
<Skeleton className="h-64 w-full" />
</div>
)
}
return (
<div className="space-y-4">
{/* Back */}
<div className="flex items-center gap-3">
<Button variant="ghost" size="icon" asChild className="h-8 w-8">
<Link href={"/applicant/pipeline" as Route}>
<ArrowLeft className="h-4 w-4" />
</Link>
</Button>
<span className="text-sm text-muted-foreground">Back to Pipeline</span>
</div>
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div>
<h1 className="text-2xl font-bold tracking-tight">Stage Documents</h1>
<p className="text-sm text-muted-foreground mt-0.5">
Upload required documents for this stage
</p>
</div>
<StageWindowBadge
windowOpenAt={requirements?.deadlineInfo?.windowOpenAt}
windowCloseAt={requirements?.deadlineInfo?.windowCloseAt}
/>
</div>
{/* Deadline info */}
{closeAt && isWindowOpen && (
<Card>
<CardContent className="flex items-center justify-between py-3">
<div className="flex items-center gap-2">
<Clock className="h-4 w-4 text-muted-foreground" />
<span className="text-sm">Submission deadline</span>
</div>
<CountdownTimer deadline={closeAt} label="Closes in" />
</CardContent>
</Card>
)}
{/* Late submission warning */}
{isLate && (
<Card className="border-amber-200 bg-amber-50/50 dark:border-amber-900 dark:bg-amber-950/20">
<CardContent className="flex items-center gap-3 py-3">
<AlertCircle className="h-5 w-5 text-amber-600 shrink-0" />
<p className="text-sm text-amber-800 dark:text-amber-200">
The submission window has passed. Late submissions may be accepted at the discretion of the administrators.
</p>
</CardContent>
</Card>
)}
{/* Window closed */}
{!isWindowOpen && !isLate && (
<Card className="border-destructive/50 bg-destructive/5">
<CardContent className="flex items-center gap-3 py-3">
<AlertCircle className="h-5 w-5 text-destructive shrink-0" />
<p className="text-sm text-destructive">
The document submission window for this stage is closed.
</p>
</CardContent>
</Card>
)}
{/* File requirements */}
{requirements?.fileRequirements && requirements.fileRequirements.length > 0 ? (
<RequirementUploadList
projectId={projectId}
stageId={stageId}
disabled={!isWindowOpen && !isLate}
/>
) : (
<Card>
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
<FileText className="h-12 w-12 text-muted-foreground/50 mb-3" />
<p className="font-medium">No document requirements</p>
<p className="text-sm text-muted-foreground mt-1">
There are no specific document requirements for this stage.
</p>
</CardContent>
</Card>
)}
{/* Uploaded files summary */}
{requirements?.uploadedFiles && requirements.uploadedFiles.length > 0 && (
<Card>
<CardHeader>
<CardTitle className="text-lg">Uploaded Files</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-2">
{requirements.uploadedFiles.map((file: { id: string; fileName: string; size: number; createdAt: string | Date }) => (
<div key={file.id} className="flex items-center gap-3 text-sm">
<FileText className="h-4 w-4 text-muted-foreground shrink-0" />
<span className="truncate">{file.fileName}</span>
<span className="text-xs text-muted-foreground shrink-0">
{(file.size / (1024 * 1024)).toFixed(1)}MB
</span>
</div>
))}
</div>
</CardContent>
</Card>
)}
</div>
)
}

View File

@@ -1,278 +1,278 @@
'use client'
import { use } from 'react'
import { trpc } from '@/lib/trpc/client'
import Link from 'next/link'
import type { Route } from 'next'
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import {
ArrowLeft,
CheckCircle2,
XCircle,
Clock,
ArrowRight,
AlertCircle,
} from 'lucide-react'
const stateLabels: Record<string, string> = {
PENDING: 'Pending',
IN_PROGRESS: 'In Progress',
PASSED: 'Passed',
REJECTED: 'Not Selected',
COMPLETED: 'Completed',
WAITING: 'Waiting',
}
const stateColors: Record<string, string> = {
PASSED: 'text-emerald-600 bg-emerald-50 border-emerald-200 dark:text-emerald-400 dark:bg-emerald-950/30 dark:border-emerald-900',
COMPLETED: 'text-emerald-600 bg-emerald-50 border-emerald-200 dark:text-emerald-400 dark:bg-emerald-950/30 dark:border-emerald-900',
REJECTED: 'text-destructive bg-destructive/5 border-destructive/30',
IN_PROGRESS: 'text-blue-600 bg-blue-50 border-blue-200 dark:text-blue-400 dark:bg-blue-950/30 dark:border-blue-900',
PENDING: 'text-muted-foreground bg-muted border-muted',
WAITING: 'text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950/30 dark:border-amber-900',
}
export default function StageStatusPage({
params,
}: {
params: Promise<{ stageId: string }>
}) {
const { stageId } = use(params)
// Get applicant's project via dashboard endpoint
const { data: dashboard } = trpc.applicant.getMyDashboard.useQuery()
const project = dashboard?.project
const projectId = project?.id ?? ''
const programId = project?.program?.id ?? ''
const { data: pipelineView } =
trpc.pipeline.getApplicantView.useQuery(
{ programId, projectId },
{ enabled: !!programId && !!projectId }
)
const { data: timeline, isLoading } =
trpc.stage.getApplicantTimeline.useQuery(
{ projectId, pipelineId: pipelineView?.pipelineId ?? '' },
{ enabled: !!projectId && !!pipelineView?.pipelineId }
)
// Find the specific stage
const stageData = timeline?.find((item) => item.stageId === stageId)
if (isLoading) {
return (
<div className="space-y-4">
<Skeleton className="h-6 w-64" />
<Skeleton className="h-48 w-full" />
</div>
)
}
return (
<div className="space-y-4">
{/* Back */}
<div className="flex items-center gap-3">
<Button variant="ghost" size="icon" asChild className="h-8 w-8">
<Link href={"/applicant/pipeline" as Route}>
<ArrowLeft className="h-4 w-4" />
</Link>
</Button>
<span className="text-sm text-muted-foreground">Back to Pipeline</span>
</div>
{stageData ? (
<>
{/* Stage state card */}
<Card className={`border ${stateColors[stageData.state] ?? ''}`}>
<CardContent className="py-8 text-center">
<div className="flex flex-col items-center gap-3">
{stageData.state === 'PASSED' || stageData.state === 'COMPLETED' ? (
<CheckCircle2 className="h-12 w-12 text-emerald-600" />
) : stageData.state === 'REJECTED' ? (
<XCircle className="h-12 w-12 text-destructive" />
) : (
<Clock className="h-12 w-12 text-blue-600" />
)}
<div>
<h2 className="text-xl font-bold">{stageData.stageName}</h2>
<Badge className="mt-2 text-sm">
{stateLabels[stageData.state] ?? stageData.state}
</Badge>
</div>
</div>
</CardContent>
</Card>
{/* Decision details */}
<Card>
<CardHeader>
<CardTitle className="text-lg">Stage Details</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="grid gap-3 sm:grid-cols-2">
<div>
<p className="text-xs text-muted-foreground uppercase tracking-wide">Stage Type</p>
<p className="text-sm font-medium capitalize">
{stageData.stageType.toLowerCase().replace(/_/g, ' ')}
</p>
</div>
{stageData.enteredAt && (
<div>
<p className="text-xs text-muted-foreground uppercase tracking-wide">Entered</p>
<p className="text-sm font-medium">
{new Date(stageData.enteredAt).toLocaleDateString('en-US', {
month: 'long',
day: 'numeric',
year: 'numeric',
})}
</p>
</div>
)}
{stageData.exitedAt && (
<div>
<p className="text-xs text-muted-foreground uppercase tracking-wide">Exited</p>
<p className="text-sm font-medium">
{new Date(stageData.exitedAt).toLocaleDateString('en-US', {
month: 'long',
day: 'numeric',
year: 'numeric',
})}
</p>
</div>
)}
</div>
</CardContent>
</Card>
{/* Next steps */}
{(stageData.state === 'IN_PROGRESS' || stageData.state === 'PENDING') && (
<Card>
<CardHeader>
<CardTitle className="text-lg flex items-center gap-2">
<ArrowRight className="h-4 w-4" />
Next Steps
</CardTitle>
</CardHeader>
<CardContent>
<ul className="space-y-2 text-sm text-muted-foreground">
{stageData.stageType === 'INTAKE' && (
<>
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
Make sure all required documents are uploaded before the deadline.
</li>
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
You will be notified once reviewers complete their evaluation.
</li>
</>
)}
{stageData.stageType === 'EVALUATION' && (
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
Your project is being reviewed by jury members. Results will be shared once evaluation is complete.
</li>
)}
{stageData.stageType === 'LIVE_FINAL' && (
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
Prepare for the live presentation. Check your email for schedule and logistics details.
</li>
)}
{!['INTAKE', 'EVALUATION', 'LIVE_FINAL'].includes(stageData.stageType) && (
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
Your project is progressing through this stage. Updates will appear here.
</li>
)}
</ul>
</CardContent>
</Card>
)}
{/* Full timeline */}
{timeline && timeline.length > 1 && (
<Card>
<CardHeader>
<CardTitle className="text-lg">Full Timeline</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-0">
{timeline.map((item, index) => (
<div key={item.stageId} className="relative flex gap-4">
{index < timeline.length - 1 && (
<div className={`absolute left-[11px] top-[24px] h-full w-0.5 ${
item.state === 'PASSED' || item.state === 'COMPLETED'
? 'bg-emerald-500'
: 'bg-muted'
}`} />
)}
<div className="relative z-10 flex h-6 w-6 shrink-0 items-center justify-center">
<div className={`h-3 w-3 rounded-full ${
item.stageId === stageId
? 'ring-2 ring-brand-blue ring-offset-2 bg-brand-blue'
: item.state === 'PASSED' || item.state === 'COMPLETED'
? 'bg-emerald-500'
: item.state === 'REJECTED'
? 'bg-destructive'
: item.isCurrent
? 'bg-blue-500'
: 'bg-muted-foreground/30'
}`} />
</div>
<div className="flex-1 pb-6">
<div className="flex items-center gap-2">
<p className={`text-sm font-medium ${
item.stageId === stageId ? 'text-brand-blue dark:text-brand-teal' : ''
}`}>
{item.stageName}
</p>
<Badge
variant={
item.state === 'PASSED' || item.state === 'COMPLETED'
? 'success'
: item.state === 'REJECTED'
? 'destructive'
: 'secondary'
}
className="text-xs"
>
{stateLabels[item.state] ?? item.state}
</Badge>
</div>
{item.enteredAt && (
<p className="text-xs text-muted-foreground mt-0.5">
{new Date(item.enteredAt).toLocaleDateString()}
</p>
)}
</div>
</div>
))}
</div>
</CardContent>
</Card>
)}
</>
) : (
<Card>
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
<AlertCircle className="h-12 w-12 text-muted-foreground/50 mb-3" />
<p className="font-medium">Stage not found</p>
<p className="text-sm text-muted-foreground mt-1">
Your project has not entered this stage yet.
</p>
</CardContent>
</Card>
)}
</div>
)
}
'use client'
import { use } from 'react'
import { trpc } from '@/lib/trpc/client'
import Link from 'next/link'
import type { Route } from 'next'
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import {
ArrowLeft,
CheckCircle2,
XCircle,
Clock,
ArrowRight,
AlertCircle,
} from 'lucide-react'
const stateLabels: Record<string, string> = {
PENDING: 'Pending',
IN_PROGRESS: 'In Progress',
PASSED: 'Passed',
REJECTED: 'Not Selected',
COMPLETED: 'Completed',
WAITING: 'Waiting',
}
const stateColors: Record<string, string> = {
PASSED: 'text-emerald-600 bg-emerald-50 border-emerald-200 dark:text-emerald-400 dark:bg-emerald-950/30 dark:border-emerald-900',
COMPLETED: 'text-emerald-600 bg-emerald-50 border-emerald-200 dark:text-emerald-400 dark:bg-emerald-950/30 dark:border-emerald-900',
REJECTED: 'text-destructive bg-destructive/5 border-destructive/30',
IN_PROGRESS: 'text-blue-600 bg-blue-50 border-blue-200 dark:text-blue-400 dark:bg-blue-950/30 dark:border-blue-900',
PENDING: 'text-muted-foreground bg-muted border-muted',
WAITING: 'text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950/30 dark:border-amber-900',
}
export default function StageStatusPage({
params,
}: {
params: Promise<{ stageId: string }>
}) {
const { stageId } = use(params)
// Get applicant's project via dashboard endpoint
const { data: dashboard } = trpc.applicant.getMyDashboard.useQuery()
const project = dashboard?.project
const projectId = project?.id ?? ''
const programId = project?.program?.id ?? ''
const { data: pipelineView } =
trpc.pipeline.getApplicantView.useQuery(
{ programId, projectId },
{ enabled: !!programId && !!projectId }
)
const { data: timeline, isLoading } =
trpc.stage.getApplicantTimeline.useQuery(
{ projectId, pipelineId: pipelineView?.pipelineId ?? '' },
{ enabled: !!projectId && !!pipelineView?.pipelineId }
)
// Find the specific stage
const stageData = timeline?.find((item) => item.stageId === stageId)
if (isLoading) {
return (
<div className="space-y-4">
<Skeleton className="h-6 w-64" />
<Skeleton className="h-48 w-full" />
</div>
)
}
return (
<div className="space-y-4">
{/* Back */}
<div className="flex items-center gap-3">
<Button variant="ghost" size="icon" asChild className="h-8 w-8">
<Link href={"/applicant/pipeline" as Route}>
<ArrowLeft className="h-4 w-4" />
</Link>
</Button>
<span className="text-sm text-muted-foreground">Back to Pipeline</span>
</div>
{stageData ? (
<>
{/* Stage state card */}
<Card className={`border ${stateColors[stageData.state] ?? ''}`}>
<CardContent className="py-8 text-center">
<div className="flex flex-col items-center gap-3">
{stageData.state === 'PASSED' || stageData.state === 'COMPLETED' ? (
<CheckCircle2 className="h-12 w-12 text-emerald-600" />
) : stageData.state === 'REJECTED' ? (
<XCircle className="h-12 w-12 text-destructive" />
) : (
<Clock className="h-12 w-12 text-blue-600" />
)}
<div>
<h2 className="text-xl font-bold">{stageData.stageName}</h2>
<Badge className="mt-2 text-sm">
{stateLabels[stageData.state] ?? stageData.state}
</Badge>
</div>
</div>
</CardContent>
</Card>
{/* Decision details */}
<Card>
<CardHeader>
<CardTitle className="text-lg">Stage Details</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="grid gap-3 sm:grid-cols-2">
<div>
<p className="text-xs text-muted-foreground uppercase tracking-wide">Stage Type</p>
<p className="text-sm font-medium capitalize">
{stageData.stageType.toLowerCase().replace(/_/g, ' ')}
</p>
</div>
{stageData.enteredAt && (
<div>
<p className="text-xs text-muted-foreground uppercase tracking-wide">Entered</p>
<p className="text-sm font-medium">
{new Date(stageData.enteredAt).toLocaleDateString('en-US', {
month: 'long',
day: 'numeric',
year: 'numeric',
})}
</p>
</div>
)}
{stageData.exitedAt && (
<div>
<p className="text-xs text-muted-foreground uppercase tracking-wide">Exited</p>
<p className="text-sm font-medium">
{new Date(stageData.exitedAt).toLocaleDateString('en-US', {
month: 'long',
day: 'numeric',
year: 'numeric',
})}
</p>
</div>
)}
</div>
</CardContent>
</Card>
{/* Next steps */}
{(stageData.state === 'IN_PROGRESS' || stageData.state === 'PENDING') && (
<Card>
<CardHeader>
<CardTitle className="text-lg flex items-center gap-2">
<ArrowRight className="h-4 w-4" />
Next Steps
</CardTitle>
</CardHeader>
<CardContent>
<ul className="space-y-2 text-sm text-muted-foreground">
{stageData.stageType === 'INTAKE' && (
<>
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
Make sure all required documents are uploaded before the deadline.
</li>
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
You will be notified once reviewers complete their evaluation.
</li>
</>
)}
{stageData.stageType === 'EVALUATION' && (
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
Your project is being reviewed by jury members. Results will be shared once evaluation is complete.
</li>
)}
{stageData.stageType === 'LIVE_FINAL' && (
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
Prepare for the live presentation. Check your email for schedule and logistics details.
</li>
)}
{!['INTAKE', 'EVALUATION', 'LIVE_FINAL'].includes(stageData.stageType) && (
<li className="flex items-start gap-2">
<CheckCircle2 className="h-4 w-4 text-brand-teal shrink-0 mt-0.5" />
Your project is progressing through this stage. Updates will appear here.
</li>
)}
</ul>
</CardContent>
</Card>
)}
{/* Full timeline */}
{timeline && timeline.length > 1 && (
<Card>
<CardHeader>
<CardTitle className="text-lg">Full Timeline</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-0">
{timeline.map((item, index) => (
<div key={item.stageId} className="relative flex gap-4">
{index < timeline.length - 1 && (
<div className={`absolute left-[11px] top-[24px] h-full w-0.5 ${
item.state === 'PASSED' || item.state === 'COMPLETED'
? 'bg-emerald-500'
: 'bg-muted'
}`} />
)}
<div className="relative z-10 flex h-6 w-6 shrink-0 items-center justify-center">
<div className={`h-3 w-3 rounded-full ${
item.stageId === stageId
? 'ring-2 ring-brand-blue ring-offset-2 bg-brand-blue'
: item.state === 'PASSED' || item.state === 'COMPLETED'
? 'bg-emerald-500'
: item.state === 'REJECTED'
? 'bg-destructive'
: item.isCurrent
? 'bg-blue-500'
: 'bg-muted-foreground/30'
}`} />
</div>
<div className="flex-1 pb-6">
<div className="flex items-center gap-2">
<p className={`text-sm font-medium ${
item.stageId === stageId ? 'text-brand-blue dark:text-brand-teal' : ''
}`}>
{item.stageName}
</p>
<Badge
variant={
item.state === 'PASSED' || item.state === 'COMPLETED'
? 'success'
: item.state === 'REJECTED'
? 'destructive'
: 'secondary'
}
className="text-xs"
>
{stateLabels[item.state] ?? item.state}
</Badge>
</div>
{item.enteredAt && (
<p className="text-xs text-muted-foreground mt-0.5">
{new Date(item.enteredAt).toLocaleDateString()}
</p>
)}
</div>
</div>
))}
</div>
</CardContent>
</Card>
)}
</>
) : (
<Card>
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
<AlertCircle className="h-12 w-12 text-muted-foreground/50 mb-3" />
<p className="font-medium">Stage not found</p>
<p className="text-sm text-muted-foreground mt-1">
Your project has not entered this stage yet.
</p>
</CardContent>
</Card>
)}
</div>
)
}

View File

@@ -1,267 +1,267 @@
'use client'
import { trpc } from '@/lib/trpc/client'
import Link from 'next/link'
import type { Route } from 'next'
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import {
Upload,
Users,
MessageSquare,
ArrowRight,
FileText,
Clock,
CheckCircle2,
XCircle,
Layers,
} from 'lucide-react'
import { StageTimeline } from '@/components/shared/stage-timeline'
import { StageWindowBadge } from '@/components/shared/stage-window-badge'
import { cn } from '@/lib/utils'
const stateLabels: Record<string, string> = {
PENDING: 'Pending',
IN_PROGRESS: 'In Progress',
PASSED: 'Passed',
REJECTED: 'Not Selected',
COMPLETED: 'Completed',
WAITING: 'Waiting',
}
const stateVariants: Record<string, 'success' | 'destructive' | 'warning' | 'secondary' | 'info'> = {
PENDING: 'secondary',
IN_PROGRESS: 'info',
PASSED: 'success',
REJECTED: 'destructive',
COMPLETED: 'success',
WAITING: 'warning',
}
export default function ApplicantPipelinePage() {
// Get applicant's project via dashboard endpoint
const { data: dashboard } = trpc.applicant.getMyDashboard.useQuery()
const project = dashboard?.project
const projectId = project?.id ?? ''
const programId = project?.program?.id ?? ''
const { data: pipelineView, isLoading: pipelineLoading } =
trpc.pipeline.getApplicantView.useQuery(
{ programId, projectId },
{ enabled: !!programId && !!projectId }
)
const { data: timeline, isLoading: timelineLoading } =
trpc.stage.getApplicantTimeline.useQuery(
{ projectId, pipelineId: pipelineView?.pipelineId ?? '' },
{ enabled: !!projectId && !!pipelineView?.pipelineId }
)
const isLoading = pipelineLoading || timelineLoading
if (!project && !isLoading) {
return (
<div className="space-y-4">
<div>
<h1 className="text-2xl font-bold tracking-tight">Pipeline Progress</h1>
<p className="text-muted-foreground mt-0.5">Track your project through the selection pipeline</p>
</div>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
<Layers className="h-12 w-12 text-muted-foreground/50 mb-3" />
<p className="font-medium">No project found</p>
<p className="text-sm text-muted-foreground mt-1">
You don&apos;t have a project in the current edition yet.
</p>
</CardContent>
</Card>
</div>
)
}
if (isLoading) {
return (
<div className="space-y-4">
<div>
<h1 className="text-2xl font-bold tracking-tight">Pipeline Progress</h1>
<p className="text-muted-foreground mt-0.5">Track your project through the selection pipeline</p>
</div>
<Skeleton className="h-8 w-64" />
<Skeleton className="h-16 w-full" />
<Skeleton className="h-48 w-full" />
</div>
)
}
// Build timeline items for StageTimeline
const timelineItems = timeline?.map((item) => ({
id: item.stageId,
name: item.stageName,
stageType: item.stageType,
isCurrent: item.isCurrent,
state: item.state,
enteredAt: item.enteredAt,
})) ?? []
// Find current stage
const currentStage = timeline?.find((item) => item.isCurrent)
return (
<div className="space-y-4">
<div>
<h1 className="text-2xl font-bold tracking-tight">Pipeline Progress</h1>
<p className="text-muted-foreground mt-0.5">Track your project through the selection pipeline</p>
</div>
{/* Project title + status */}
<Card>
<CardContent className="py-5">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div>
<h2 className="text-lg font-semibold">{project?.title}</h2>
<p className="text-sm text-muted-foreground">{(project as { teamName?: string } | undefined)?.teamName}</p>
</div>
{currentStage && (
<Badge variant={stateVariants[currentStage.state] ?? 'secondary'}>
{stateLabels[currentStage.state] ?? currentStage.state}
</Badge>
)}
</div>
</CardContent>
</Card>
{/* Stage Timeline visualization */}
{timelineItems.length > 0 && (
<Card>
<CardHeader>
<CardTitle className="text-lg">Pipeline Progress</CardTitle>
</CardHeader>
<CardContent>
<StageTimeline stages={timelineItems} orientation="horizontal" />
</CardContent>
</Card>
)}
{/* Current stage details */}
{currentStage && (
<Card className="border-brand-blue/30 dark:border-brand-teal/30">
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="text-lg">Current Stage</CardTitle>
</div>
</CardHeader>
<CardContent className="space-y-3">
<div>
<h3 className="font-semibold">{currentStage.stageName}</h3>
<p className="text-sm text-muted-foreground capitalize">
{currentStage.stageType.toLowerCase().replace(/_/g, ' ')}
</p>
</div>
{currentStage.enteredAt && (
<p className="text-xs text-muted-foreground">
Entered {new Date(currentStage.enteredAt).toLocaleDateString('en-US', {
month: 'long',
day: 'numeric',
year: 'numeric',
})}
</p>
)}
</CardContent>
</Card>
)}
{/* Decision history */}
{timeline && timeline.length > 0 && (
<Card>
<CardHeader>
<CardTitle className="text-lg">Stage History</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-3">
{timeline.map((item) => (
<div
key={item.stageId}
className="flex items-center justify-between py-2 border-b last:border-0"
>
<div className="flex items-center gap-3">
<div className={cn(
'h-2 w-2 rounded-full',
item.state === 'PASSED' || item.state === 'COMPLETED'
? 'bg-emerald-500'
: item.state === 'REJECTED'
? 'bg-destructive'
: item.isCurrent
? 'bg-blue-500'
: 'bg-muted-foreground'
)} />
<div>
<p className="text-sm font-medium">{item.stageName}</p>
{item.enteredAt && (
<p className="text-xs text-muted-foreground">
{new Date(item.enteredAt).toLocaleDateString()}
</p>
)}
</div>
</div>
<Badge variant={stateVariants[item.state] ?? 'secondary'} className="text-xs">
{stateLabels[item.state] ?? item.state}
</Badge>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* Quick actions */}
<div className="grid gap-3 sm:grid-cols-3">
{currentStage && (
<Link
href={`/applicant/pipeline/${currentStage.stageId}/documents` as Route}
className="group flex items-center gap-3 rounded-xl border p-4 transition-all hover:border-brand-blue/30 hover:bg-brand-blue/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-lg bg-blue-50 p-2 dark:bg-blue-950/40">
<Upload className="h-4 w-4 text-blue-600 dark:text-blue-400" />
</div>
<div>
<p className="font-semibold text-sm">Upload Documents</p>
<p className="text-xs text-muted-foreground">Submit required files</p>
</div>
</Link>
)}
<Link
href={"/applicant/team" as Route}
className="group flex items-center gap-3 rounded-xl border p-4 transition-all hover:border-brand-teal/30 hover:bg-brand-teal/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-lg bg-teal-50 p-2 dark:bg-teal-950/40">
<Users className="h-4 w-4 text-brand-teal" />
</div>
<div>
<p className="font-semibold text-sm">View Team</p>
<p className="text-xs text-muted-foreground">Team members</p>
</div>
</Link>
<Link
href={"/applicant/mentor" as Route}
className="group flex items-center gap-3 rounded-xl border p-4 transition-all hover:border-amber-500/30 hover:bg-amber-50/50 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-lg bg-amber-50 p-2 dark:bg-amber-950/40">
<MessageSquare className="h-4 w-4 text-amber-600 dark:text-amber-400" />
</div>
<div>
<p className="font-semibold text-sm">Contact Mentor</p>
<p className="text-xs text-muted-foreground">Send a message</p>
</div>
</Link>
</div>
</div>
)
}
'use client'
import { trpc } from '@/lib/trpc/client'
import Link from 'next/link'
import type { Route } from 'next'
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import {
Upload,
Users,
MessageSquare,
ArrowRight,
FileText,
Clock,
CheckCircle2,
XCircle,
Layers,
} from 'lucide-react'
import { StageTimeline } from '@/components/shared/stage-timeline'
import { StageWindowBadge } from '@/components/shared/stage-window-badge'
import { cn } from '@/lib/utils'
const stateLabels: Record<string, string> = {
PENDING: 'Pending',
IN_PROGRESS: 'In Progress',
PASSED: 'Passed',
REJECTED: 'Not Selected',
COMPLETED: 'Completed',
WAITING: 'Waiting',
}
const stateVariants: Record<string, 'success' | 'destructive' | 'warning' | 'secondary' | 'info'> = {
PENDING: 'secondary',
IN_PROGRESS: 'info',
PASSED: 'success',
REJECTED: 'destructive',
COMPLETED: 'success',
WAITING: 'warning',
}
export default function ApplicantPipelinePage() {
// Get applicant's project via dashboard endpoint
const { data: dashboard } = trpc.applicant.getMyDashboard.useQuery()
const project = dashboard?.project
const projectId = project?.id ?? ''
const programId = project?.program?.id ?? ''
const { data: pipelineView, isLoading: pipelineLoading } =
trpc.pipeline.getApplicantView.useQuery(
{ programId, projectId },
{ enabled: !!programId && !!projectId }
)
const { data: timeline, isLoading: timelineLoading } =
trpc.stage.getApplicantTimeline.useQuery(
{ projectId, pipelineId: pipelineView?.pipelineId ?? '' },
{ enabled: !!projectId && !!pipelineView?.pipelineId }
)
const isLoading = pipelineLoading || timelineLoading
if (!project && !isLoading) {
return (
<div className="space-y-4">
<div>
<h1 className="text-2xl font-bold tracking-tight">Pipeline Progress</h1>
<p className="text-muted-foreground mt-0.5">Track your project through the selection pipeline</p>
</div>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
<Layers className="h-12 w-12 text-muted-foreground/50 mb-3" />
<p className="font-medium">No project found</p>
<p className="text-sm text-muted-foreground mt-1">
You don&apos;t have a project in the current edition yet.
</p>
</CardContent>
</Card>
</div>
)
}
if (isLoading) {
return (
<div className="space-y-4">
<div>
<h1 className="text-2xl font-bold tracking-tight">Pipeline Progress</h1>
<p className="text-muted-foreground mt-0.5">Track your project through the selection pipeline</p>
</div>
<Skeleton className="h-8 w-64" />
<Skeleton className="h-16 w-full" />
<Skeleton className="h-48 w-full" />
</div>
)
}
// Build timeline items for StageTimeline
const timelineItems = timeline?.map((item) => ({
id: item.stageId,
name: item.stageName,
stageType: item.stageType,
isCurrent: item.isCurrent,
state: item.state,
enteredAt: item.enteredAt,
})) ?? []
// Find current stage
const currentStage = timeline?.find((item) => item.isCurrent)
return (
<div className="space-y-4">
<div>
<h1 className="text-2xl font-bold tracking-tight">Pipeline Progress</h1>
<p className="text-muted-foreground mt-0.5">Track your project through the selection pipeline</p>
</div>
{/* Project title + status */}
<Card>
<CardContent className="py-5">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div>
<h2 className="text-lg font-semibold">{project?.title}</h2>
<p className="text-sm text-muted-foreground">{(project as { teamName?: string } | undefined)?.teamName}</p>
</div>
{currentStage && (
<Badge variant={stateVariants[currentStage.state] ?? 'secondary'}>
{stateLabels[currentStage.state] ?? currentStage.state}
</Badge>
)}
</div>
</CardContent>
</Card>
{/* Stage Timeline visualization */}
{timelineItems.length > 0 && (
<Card>
<CardHeader>
<CardTitle className="text-lg">Pipeline Progress</CardTitle>
</CardHeader>
<CardContent>
<StageTimeline stages={timelineItems} orientation="horizontal" />
</CardContent>
</Card>
)}
{/* Current stage details */}
{currentStage && (
<Card className="border-brand-blue/30 dark:border-brand-teal/30">
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="text-lg">Current Stage</CardTitle>
</div>
</CardHeader>
<CardContent className="space-y-3">
<div>
<h3 className="font-semibold">{currentStage.stageName}</h3>
<p className="text-sm text-muted-foreground capitalize">
{currentStage.stageType.toLowerCase().replace(/_/g, ' ')}
</p>
</div>
{currentStage.enteredAt && (
<p className="text-xs text-muted-foreground">
Entered {new Date(currentStage.enteredAt).toLocaleDateString('en-US', {
month: 'long',
day: 'numeric',
year: 'numeric',
})}
</p>
)}
</CardContent>
</Card>
)}
{/* Decision history */}
{timeline && timeline.length > 0 && (
<Card>
<CardHeader>
<CardTitle className="text-lg">Stage History</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-3">
{timeline.map((item) => (
<div
key={item.stageId}
className="flex items-center justify-between py-2 border-b last:border-0"
>
<div className="flex items-center gap-3">
<div className={cn(
'h-2 w-2 rounded-full',
item.state === 'PASSED' || item.state === 'COMPLETED'
? 'bg-emerald-500'
: item.state === 'REJECTED'
? 'bg-destructive'
: item.isCurrent
? 'bg-blue-500'
: 'bg-muted-foreground'
)} />
<div>
<p className="text-sm font-medium">{item.stageName}</p>
{item.enteredAt && (
<p className="text-xs text-muted-foreground">
{new Date(item.enteredAt).toLocaleDateString()}
</p>
)}
</div>
</div>
<Badge variant={stateVariants[item.state] ?? 'secondary'} className="text-xs">
{stateLabels[item.state] ?? item.state}
</Badge>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* Quick actions */}
<div className="grid gap-3 sm:grid-cols-3">
{currentStage && (
<Link
href={`/applicant/pipeline/${currentStage.stageId}/documents` as Route}
className="group flex items-center gap-3 rounded-xl border p-4 transition-all hover:border-brand-blue/30 hover:bg-brand-blue/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-lg bg-blue-50 p-2 dark:bg-blue-950/40">
<Upload className="h-4 w-4 text-blue-600 dark:text-blue-400" />
</div>
<div>
<p className="font-semibold text-sm">Upload Documents</p>
<p className="text-xs text-muted-foreground">Submit required files</p>
</div>
</Link>
)}
<Link
href={"/applicant/team" as Route}
className="group flex items-center gap-3 rounded-xl border p-4 transition-all hover:border-brand-teal/30 hover:bg-brand-teal/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-lg bg-teal-50 p-2 dark:bg-teal-950/40">
<Users className="h-4 w-4 text-brand-teal" />
</div>
<div>
<p className="font-semibold text-sm">View Team</p>
<p className="text-xs text-muted-foreground">Team members</p>
</div>
</Link>
<Link
href={"/applicant/mentor" as Route}
className="group flex items-center gap-3 rounded-xl border p-4 transition-all hover:border-amber-500/30 hover:bg-amber-50/50 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-lg bg-amber-50 p-2 dark:bg-amber-950/40">
<MessageSquare className="h-4 w-4 text-amber-600 dark:text-amber-400" />
</div>
<div>
<p className="font-semibold text-sm">Contact Mentor</p>
<p className="text-xs text-muted-foreground">Send a message</p>
</div>
</Link>
</div>
</div>
)
}

View File

@@ -1,424 +1,424 @@
'use client'
import { useState } from 'react'
import { useSession } from 'next-auth/react'
import { useForm } from 'react-hook-form'
import { zodResolver } from '@hookform/resolvers/zod'
import { z } from 'zod'
import { trpc } from '@/lib/trpc/client'
import { toast } from 'sonner'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Badge } from '@/components/ui/badge'
import { Skeleton } from '@/components/ui/skeleton'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import {
Users,
UserPlus,
Crown,
Mail,
Trash2,
Loader2,
AlertCircle,
CheckCircle,
Clock,
FileText,
} from 'lucide-react'
const inviteSchema = z.object({
name: z.string().min(1, 'Name is required'),
email: z.string().email('Invalid email address'),
role: z.enum(['MEMBER', 'ADVISOR']),
title: z.string().optional(),
})
type InviteFormData = z.infer<typeof inviteSchema>
const roleLabels: Record<string, string> = {
LEAD: 'Team Lead',
MEMBER: 'Team Member',
ADVISOR: 'Advisor',
}
const statusLabels: Record<string, { label: string; icon: React.ComponentType<{ className?: string }> }> = {
ACTIVE: { label: 'Active', icon: CheckCircle },
INVITED: { label: 'Pending', icon: Clock },
SUSPENDED: { label: 'Suspended', icon: AlertCircle },
}
export default function ApplicantTeamPage() {
const { data: session, status: sessionStatus } = useSession()
const isAuthenticated = sessionStatus === 'authenticated'
const [isInviteOpen, setIsInviteOpen] = useState(false)
const { data: dashboardData, isLoading: dashLoading } = trpc.applicant.getMyDashboard.useQuery(
undefined,
{ enabled: isAuthenticated }
)
const projectId = dashboardData?.project?.id
const { data: teamData, isLoading: teamLoading, refetch } = trpc.applicant.getTeamMembers.useQuery(
{ projectId: projectId! },
{ enabled: !!projectId }
)
const inviteMutation = trpc.applicant.inviteTeamMember.useMutation({
onSuccess: (result) => {
if (result.requiresAccountSetup) {
toast.success('Invitation email sent to team member')
} else {
toast.success('Team member added and notified by email')
}
setIsInviteOpen(false)
refetch()
},
onError: (error) => {
toast.error(error.message)
},
})
const removeMutation = trpc.applicant.removeTeamMember.useMutation({
onSuccess: () => {
toast.success('Team member removed')
refetch()
},
onError: (error) => {
toast.error(error.message)
},
})
const form = useForm<InviteFormData>({
resolver: zodResolver(inviteSchema),
defaultValues: {
name: '',
email: '',
role: 'MEMBER',
title: '',
},
})
const onInvite = async (data: InviteFormData) => {
if (!projectId) return
await inviteMutation.mutateAsync({
projectId,
...data,
})
form.reset()
}
const isLoading = dashLoading || teamLoading
if (isLoading) {
return (
<div className="space-y-6">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-64" />
</div>
<Card>
<CardContent className="p-6 space-y-4">
{[1, 2, 3].map((i) => (
<div key={i} className="flex items-center justify-between">
<div className="flex items-center gap-4">
<Skeleton className="h-10 w-10 rounded-full" />
<div className="space-y-2">
<Skeleton className="h-4 w-32" />
<Skeleton className="h-3 w-24" />
</div>
</div>
<Skeleton className="h-8 w-20" />
</div>
))}
</CardContent>
</Card>
</div>
)
}
if (!projectId) {
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Team</h1>
</div>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12">
<FileText className="h-12 w-12 text-muted-foreground/50 mb-4" />
<h2 className="text-xl font-semibold mb-2">No Project</h2>
<p className="text-muted-foreground text-center">
Submit a project first to manage your team.
</p>
</CardContent>
</Card>
</div>
)
}
// Check if user is team lead
const currentUserMember = teamData?.teamMembers.find(
(tm) => tm.userId === session?.user?.id
)
const isTeamLead =
currentUserMember?.role === 'LEAD' ||
teamData?.submittedBy?.id === session?.user?.id
return (
<div className="space-y-6">
{/* Header */}
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-semibold tracking-tight flex items-center gap-2">
<Users className="h-6 w-6" />
Team Members
</h1>
<p className="text-muted-foreground">
Manage your project team
</p>
</div>
{isTeamLead && (
<Dialog open={isInviteOpen} onOpenChange={setIsInviteOpen}>
<DialogTrigger asChild>
<Button>
<UserPlus className="mr-2 h-4 w-4" />
Invite Member
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Invite Team Member</DialogTitle>
<DialogDescription>
Send an invitation to join your project team. They will receive an email
with instructions to create their account.
</DialogDescription>
</DialogHeader>
<form onSubmit={form.handleSubmit(onInvite)} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="name">Full Name</Label>
<Input
id="name"
placeholder="Jane Doe"
{...form.register('name')}
/>
{form.formState.errors.name && (
<p className="text-sm text-destructive">
{form.formState.errors.name.message}
</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="email">Email Address</Label>
<Input
id="email"
type="email"
placeholder="jane@example.com"
{...form.register('email')}
/>
{form.formState.errors.email && (
<p className="text-sm text-destructive">
{form.formState.errors.email.message}
</p>
)}
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="role">Role</Label>
<Select
value={form.watch('role')}
onValueChange={(value) => form.setValue('role', value as 'MEMBER' | 'ADVISOR')}
>
<SelectTrigger>
<SelectValue placeholder="Select role" />
</SelectTrigger>
<SelectContent>
<SelectItem value="MEMBER">Team Member</SelectItem>
<SelectItem value="ADVISOR">Advisor</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="title">Title (optional)</Label>
<Input
id="title"
placeholder="CTO, Designer..."
{...form.register('title')}
/>
</div>
</div>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => setIsInviteOpen(false)}
>
Cancel
</Button>
<Button type="submit" disabled={inviteMutation.isPending}>
{inviteMutation.isPending && (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
)}
Send Invitation
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)}
</div>
{/* Team Members List */}
<Card>
<CardHeader>
<CardTitle>Team ({teamData?.teamMembers.length || 0} members)</CardTitle>
<CardDescription>
Everyone on this list can view and collaborate on this project.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{teamData?.teamMembers.map((member) => {
const StatusIcon = statusLabels[member.user.status]?.icon || AlertCircle
return (
<div
key={member.id}
className="flex items-center justify-between rounded-lg border p-4"
>
<div className="flex items-center gap-4">
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-muted">
{member.role === 'LEAD' ? (
<Crown className="h-5 w-5 text-yellow-500" />
) : (
<span className="text-sm font-medium">
{member.user.name?.charAt(0).toUpperCase() || '?'}
</span>
)}
</div>
<div>
<div className="flex items-center gap-2">
<span className="font-medium">{member.user.name}</span>
<Badge variant="outline" className="text-xs">
{roleLabels[member.role] || member.role}
</Badge>
{member.title && (
<span className="text-xs text-muted-foreground">
({member.title})
</span>
)}
</div>
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<Mail className="h-3 w-3" />
{member.user.email}
<StatusIcon className="h-3 w-3 ml-2" />
<span className="text-xs">
{statusLabels[member.user.status]?.label || member.user.status}
</span>
</div>
</div>
</div>
{isTeamLead && member.role !== 'LEAD' && teamData.submittedBy?.id !== member.userId && (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="ghost" size="icon" className="text-destructive">
<Trash2 className="h-4 w-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Remove Team Member</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to remove {member.user.name} from the team?
They will no longer have access to this project.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={() => removeMutation.mutate({ projectId, userId: member.userId })}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
Remove
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)}
</div>
)
})}
{(!teamData?.teamMembers || teamData.teamMembers.length === 0) && (
<div className="flex flex-col items-center justify-center py-8 text-center">
<Users className="h-12 w-12 text-muted-foreground/50 mb-4" />
<p className="text-muted-foreground">No team members yet.</p>
{isTeamLead && (
<Button
variant="outline"
className="mt-4"
onClick={() => setIsInviteOpen(true)}
>
<UserPlus className="mr-2 h-4 w-4" />
Invite Your First Team Member
</Button>
)}
</div>
)}
</CardContent>
</Card>
{/* Team Documents - visible via applicant documents page */}
{/* Info Card */}
<Card className="bg-muted/50">
<CardContent className="p-4">
<div className="flex items-start gap-3">
<AlertCircle className="h-5 w-5 text-muted-foreground mt-0.5" />
<div className="text-sm text-muted-foreground">
<p className="font-medium text-foreground">About Team Access</p>
<p className="mt-1">
All team members can view project details and status updates.
Only the team lead can invite or remove team members.
Invited members will receive an email to set up their account.
</p>
</div>
</div>
</CardContent>
</Card>
</div>
)
}
'use client'
import { useState } from 'react'
import { useSession } from 'next-auth/react'
import { useForm } from 'react-hook-form'
import { zodResolver } from '@hookform/resolvers/zod'
import { z } from 'zod'
import { trpc } from '@/lib/trpc/client'
import { toast } from 'sonner'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Badge } from '@/components/ui/badge'
import { Skeleton } from '@/components/ui/skeleton'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import {
Users,
UserPlus,
Crown,
Mail,
Trash2,
Loader2,
AlertCircle,
CheckCircle,
Clock,
FileText,
} from 'lucide-react'
const inviteSchema = z.object({
name: z.string().min(1, 'Name is required'),
email: z.string().email('Invalid email address'),
role: z.enum(['MEMBER', 'ADVISOR']),
title: z.string().optional(),
})
type InviteFormData = z.infer<typeof inviteSchema>
const roleLabels: Record<string, string> = {
LEAD: 'Team Lead',
MEMBER: 'Team Member',
ADVISOR: 'Advisor',
}
const statusLabels: Record<string, { label: string; icon: React.ComponentType<{ className?: string }> }> = {
ACTIVE: { label: 'Active', icon: CheckCircle },
INVITED: { label: 'Pending', icon: Clock },
SUSPENDED: { label: 'Suspended', icon: AlertCircle },
}
export default function ApplicantTeamPage() {
const { data: session, status: sessionStatus } = useSession()
const isAuthenticated = sessionStatus === 'authenticated'
const [isInviteOpen, setIsInviteOpen] = useState(false)
const { data: dashboardData, isLoading: dashLoading } = trpc.applicant.getMyDashboard.useQuery(
undefined,
{ enabled: isAuthenticated }
)
const projectId = dashboardData?.project?.id
const { data: teamData, isLoading: teamLoading, refetch } = trpc.applicant.getTeamMembers.useQuery(
{ projectId: projectId! },
{ enabled: !!projectId }
)
const inviteMutation = trpc.applicant.inviteTeamMember.useMutation({
onSuccess: (result) => {
if (result.requiresAccountSetup) {
toast.success('Invitation email sent to team member')
} else {
toast.success('Team member added and notified by email')
}
setIsInviteOpen(false)
refetch()
},
onError: (error) => {
toast.error(error.message)
},
})
const removeMutation = trpc.applicant.removeTeamMember.useMutation({
onSuccess: () => {
toast.success('Team member removed')
refetch()
},
onError: (error) => {
toast.error(error.message)
},
})
const form = useForm<InviteFormData>({
resolver: zodResolver(inviteSchema),
defaultValues: {
name: '',
email: '',
role: 'MEMBER',
title: '',
},
})
const onInvite = async (data: InviteFormData) => {
if (!projectId) return
await inviteMutation.mutateAsync({
projectId,
...data,
})
form.reset()
}
const isLoading = dashLoading || teamLoading
if (isLoading) {
return (
<div className="space-y-6">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-64" />
</div>
<Card>
<CardContent className="p-6 space-y-4">
{[1, 2, 3].map((i) => (
<div key={i} className="flex items-center justify-between">
<div className="flex items-center gap-4">
<Skeleton className="h-10 w-10 rounded-full" />
<div className="space-y-2">
<Skeleton className="h-4 w-32" />
<Skeleton className="h-3 w-24" />
</div>
</div>
<Skeleton className="h-8 w-20" />
</div>
))}
</CardContent>
</Card>
</div>
)
}
if (!projectId) {
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Team</h1>
</div>
<Card>
<CardContent className="flex flex-col items-center justify-center py-12">
<FileText className="h-12 w-12 text-muted-foreground/50 mb-4" />
<h2 className="text-xl font-semibold mb-2">No Project</h2>
<p className="text-muted-foreground text-center">
Submit a project first to manage your team.
</p>
</CardContent>
</Card>
</div>
)
}
// Check if user is team lead
const currentUserMember = teamData?.teamMembers.find(
(tm) => tm.userId === session?.user?.id
)
const isTeamLead =
currentUserMember?.role === 'LEAD' ||
teamData?.submittedBy?.id === session?.user?.id
return (
<div className="space-y-6">
{/* Header */}
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-semibold tracking-tight flex items-center gap-2">
<Users className="h-6 w-6" />
Team Members
</h1>
<p className="text-muted-foreground">
Manage your project team
</p>
</div>
{isTeamLead && (
<Dialog open={isInviteOpen} onOpenChange={setIsInviteOpen}>
<DialogTrigger asChild>
<Button>
<UserPlus className="mr-2 h-4 w-4" />
Invite Member
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Invite Team Member</DialogTitle>
<DialogDescription>
Send an invitation to join your project team. They will receive an email
with instructions to create their account.
</DialogDescription>
</DialogHeader>
<form onSubmit={form.handleSubmit(onInvite)} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="name">Full Name</Label>
<Input
id="name"
placeholder="Jane Doe"
{...form.register('name')}
/>
{form.formState.errors.name && (
<p className="text-sm text-destructive">
{form.formState.errors.name.message}
</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="email">Email Address</Label>
<Input
id="email"
type="email"
placeholder="jane@example.com"
{...form.register('email')}
/>
{form.formState.errors.email && (
<p className="text-sm text-destructive">
{form.formState.errors.email.message}
</p>
)}
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="role">Role</Label>
<Select
value={form.watch('role')}
onValueChange={(value) => form.setValue('role', value as 'MEMBER' | 'ADVISOR')}
>
<SelectTrigger>
<SelectValue placeholder="Select role" />
</SelectTrigger>
<SelectContent>
<SelectItem value="MEMBER">Team Member</SelectItem>
<SelectItem value="ADVISOR">Advisor</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="title">Title (optional)</Label>
<Input
id="title"
placeholder="CTO, Designer..."
{...form.register('title')}
/>
</div>
</div>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => setIsInviteOpen(false)}
>
Cancel
</Button>
<Button type="submit" disabled={inviteMutation.isPending}>
{inviteMutation.isPending && (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
)}
Send Invitation
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)}
</div>
{/* Team Members List */}
<Card>
<CardHeader>
<CardTitle>Team ({teamData?.teamMembers.length || 0} members)</CardTitle>
<CardDescription>
Everyone on this list can view and collaborate on this project.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{teamData?.teamMembers.map((member) => {
const StatusIcon = statusLabels[member.user.status]?.icon || AlertCircle
return (
<div
key={member.id}
className="flex items-center justify-between rounded-lg border p-4"
>
<div className="flex items-center gap-4">
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-muted">
{member.role === 'LEAD' ? (
<Crown className="h-5 w-5 text-yellow-500" />
) : (
<span className="text-sm font-medium">
{member.user.name?.charAt(0).toUpperCase() || '?'}
</span>
)}
</div>
<div>
<div className="flex items-center gap-2">
<span className="font-medium">{member.user.name}</span>
<Badge variant="outline" className="text-xs">
{roleLabels[member.role] || member.role}
</Badge>
{member.title && (
<span className="text-xs text-muted-foreground">
({member.title})
</span>
)}
</div>
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<Mail className="h-3 w-3" />
{member.user.email}
<StatusIcon className="h-3 w-3 ml-2" />
<span className="text-xs">
{statusLabels[member.user.status]?.label || member.user.status}
</span>
</div>
</div>
</div>
{isTeamLead && member.role !== 'LEAD' && teamData.submittedBy?.id !== member.userId && (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="ghost" size="icon" className="text-destructive">
<Trash2 className="h-4 w-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Remove Team Member</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to remove {member.user.name} from the team?
They will no longer have access to this project.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={() => removeMutation.mutate({ projectId, userId: member.userId })}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
Remove
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)}
</div>
)
})}
{(!teamData?.teamMembers || teamData.teamMembers.length === 0) && (
<div className="flex flex-col items-center justify-center py-8 text-center">
<Users className="h-12 w-12 text-muted-foreground/50 mb-4" />
<p className="text-muted-foreground">No team members yet.</p>
{isTeamLead && (
<Button
variant="outline"
className="mt-4"
onClick={() => setIsInviteOpen(true)}
>
<UserPlus className="mr-2 h-4 w-4" />
Invite Your First Team Member
</Button>
)}
</div>
)}
</CardContent>
</Card>
{/* Team Documents - visible via applicant documents page */}
{/* Info Card */}
<Card className="bg-muted/50">
<CardContent className="p-4">
<div className="flex items-start gap-3">
<AlertCircle className="h-5 w-5 text-muted-foreground mt-0.5" />
<div className="text-sm text-muted-foreground">
<p className="font-medium text-foreground">About Team Access</p>
<p className="mt-1">
All team members can view project details and status updates.
Only the team lead can invite or remove team members.
Invited members will receive an email to set up their account.
</p>
</div>
</div>
</CardContent>
</Card>
</div>
)
}

View File

@@ -1,33 +1,33 @@
import { redirect } from 'next/navigation'
import { auth } from '@/lib/auth'
import { ApplicantNav } from '@/components/layouts/applicant-nav'
export const dynamic = 'force-dynamic'
export default async function ApplicantLayout({
children,
}: {
children: React.ReactNode
}) {
const session = await auth()
if (!session?.user) {
redirect('/login')
}
if (session.user.role !== 'APPLICANT') {
redirect('/login')
}
return (
<div className="min-h-screen bg-background">
<ApplicantNav
user={{
name: session.user.name,
email: session.user.email,
}}
/>
<main className="container-app py-6 lg:py-8">{children}</main>
</div>
)
}
import { redirect } from 'next/navigation'
import { auth } from '@/lib/auth'
import { ApplicantNav } from '@/components/layouts/applicant-nav'
export const dynamic = 'force-dynamic'
export default async function ApplicantLayout({
children,
}: {
children: React.ReactNode
}) {
const session = await auth()
if (!session?.user) {
redirect('/login')
}
if (session.user.role !== 'APPLICANT') {
redirect('/login')
}
return (
<div className="min-h-screen bg-background">
<ApplicantNav
user={{
name: session.user.name,
email: session.user.email,
}}
/>
<main className="container-app py-6 lg:py-8">{children}</main>
</div>
)
}