'use client' import { useEffect, useState } from 'react' import { useParams, useRouter } from 'next/navigation' import Link from 'next/link' import type { Route } from 'next' import { trpc } from '@/lib/trpc/client' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@/components/ui/card' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { Badge } from '@/components/ui/badge' import { Skeleton } from '@/components/ui/skeleton' import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table' import { toast } from 'sonner' import { TagInput } from '@/components/shared/tag-input' import { ArrowLeft, Save, Mail, GraduationCap, Loader2, AlertCircle, ClipboardList, User, } from 'lucide-react' export default function MentorDetailPage() { const params = useParams() const router = useRouter() const mentorId = params.id as string const { data: mentor, isLoading, refetch } = trpc.user.get.useQuery({ id: mentorId }) const updateUser = trpc.user.update.useMutation() const sendInvitation = trpc.user.sendInvitation.useMutation() const { data: assignmentsData } = trpc.mentor.listAssignments.useQuery({ mentorId, perPage: 50, }) const [name, setName] = useState('') const [status, setStatus] = useState<'INVITED' | 'ACTIVE' | 'SUSPENDED'>('INVITED') const [expertiseTags, setExpertiseTags] = useState([]) const [maxAssignments, setMaxAssignments] = useState('') useEffect(() => { if (mentor) { setName(mentor.name || '') setStatus(mentor.status as 'INVITED' | 'ACTIVE' | 'SUSPENDED') setExpertiseTags(mentor.expertiseTags || []) setMaxAssignments(mentor.maxAssignments?.toString() || '') } }, [mentor]) const handleSave = async () => { try { await updateUser.mutateAsync({ id: mentorId, name: name || null, status, expertiseTags, maxAssignments: maxAssignments ? parseInt(maxAssignments) : null, }) toast.success('Mentor updated successfully') refetch() } catch (error) { toast.error(error instanceof Error ? error.message : 'Failed to update mentor') } } const handleSendInvitation = async () => { try { await sendInvitation.mutateAsync({ userId: mentorId }) toast.success('Invitation email sent successfully') refetch() } catch (error) { toast.error(error instanceof Error ? error.message : 'Failed to send invitation') } } if (isLoading) { return (
) } if (!mentor) { return (
Mentor not found The mentor you're looking for does not exist.
) } const statusColors: Record = { ACTIVE: 'success', INVITED: 'secondary', SUSPENDED: 'destructive', } return (
{/* Header */}

{mentor.name || 'Unnamed Mentor'}

{mentor.email}

{mentor.status} {mentor.status === 'INVITED' && ( )}
{/* Profile Info */} Profile Information Update the mentor's profile and settings
setName(e.target.value)} placeholder="Enter name" />
{/* Expertise & Capacity */} Expertise & Capacity Configure expertise areas and assignment limits
setMaxAssignments(e.target.value)} placeholder="Unlimited" />

Maximum number of projects this mentor can be assigned

{mentor._count && (

Statistics

Total Assignments

{mentor._count.assignments}

Last Login

{mentor.lastLoginAt ? new Date(mentor.lastLoginAt).toLocaleDateString() : 'Never'}

)}
{/* Save Button */}
{/* Assigned Projects */} Assigned Projects Projects currently assigned to this mentor {assignmentsData && assignmentsData.assignments.length > 0 ? ( Project Team Category Status Assigned {assignmentsData.assignments.map((assignment) => ( {assignment.project.title} {assignment.project.teamName || '-'} {assignment.project.competitionCategory ? ( {assignment.project.competitionCategory} ) : ( - )} {assignment.project.status} {new Date(assignment.assignedAt).toLocaleDateString()} ))}
) : (

No projects assigned to this mentor yet.

)}
{/* Invitation Status */} {mentor.status === 'INVITED' && ( Invitation Pending This mentor hasn't accepted their invitation yet. You can resend the invitation email using the button above. )}
) }