'use client' import { useState } from 'react' import { useSession } from 'next-auth/react' import { format } from 'date-fns' import { trpc } from '@/lib/trpc/client' import { Card, CardContent, CardDescription, 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 { MentorChat } from '@/components/shared/mentor-chat' import { WorkspaceFilesPanel } from '@/components/mentor/workspace-files-panel' import { RequestChangeDialog } from './request-change-dialog' import { MessageSquare, UserCircle, FileText, UserCog, } 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! }) }, }) const [isChangeOpen, setIsChangeOpen] = useState(false) if (dashLoading) { return (
) } if (!projectId) { return (

Mentor

No Project

Submit a project first to communicate with your mentor.

) } const assignments = dashboardData?.project?.mentorAssignments ?? [] const hasMentors = assignments.length > 0 const primaryAssignment = assignments[0] ?? null const primaryMentor = primaryAssignment?.mentor const hasPendingChangeRequest = !!dashboardData?.hasPendingMentorChangeRequest const dialogMentors = assignments .filter((a) => !!a.mentor) .map((a) => ({ assignmentId: a.id, name: a.mentor?.name || a.mentor?.email || 'Mentor', })) const teamHeading = assignments.length > 1 ? 'Your mentor team' : 'Your mentor' return (
{/* Header */}

Mentor Communication

{assignments.length > 1 ? 'Chat with your assigned mentor team' : 'Chat with your assigned mentor'}

{/* Mentor list */} {hasMentors ? (

{teamHeading}

{assignments.map((assignment) => { const mentor = assignment.mentor if (!mentor) return null const expertise = mentor.expertiseTags ?? [] return (

{mentor.name || 'Mentor'}

{mentor.email}

{assignment.assignedAt && (

Assigned since {format(new Date(assignment.assignedAt), 'MMM d, yyyy')}

)}
{expertise.length > 0 && (
{expertise.map((tag) => ( {tag} ))}
)}
) })}
{/* Request change action */}

{hasPendingChangeRequest ? "You have a pending mentor change request — admins will follow up soon." : 'Need a different match? Let the program admins know.'}

) : (

No mentor has been assigned to your project yet. You'll be notified when a mentor is assigned.

)} {/* Chat */} {primaryMentor && ( Messages {assignments.length > 1 ? 'Your conversation history with your mentor team' : `Your conversation history with ${primaryMentor.name || 'your mentor'}`} { await sendMessage.mutateAsync({ projectId: projectId!, message }) }} isLoading={messagesLoading} isSending={sendMessage.isPending} /> )} {/* Files */} {primaryAssignment?.id && projectId && ( )} {/* Request change dialog */} {projectId && ( )}
) }