'use client' import { useMemo, useState } from 'react' import Link from 'next/link' import { trpc } from '@/lib/trpc/client' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Skeleton } from '@/components/ui/skeleton' import { Search, UserPlus, ArrowRight, Sparkles } from 'lucide-react' import { CountryDisplay } from '@/components/shared/country-display' type Filter = 'all' | 'unassigned' | 'assigned' | 'wants_only' export function MentoringProjectsTable({ roundId }: { roundId: string }) { const [search, setSearch] = useState('') const [filter, setFilter] = useState('all') const { data, isLoading } = trpc.round.listMentoringProjects.useQuery( { roundId }, { refetchInterval: 30_000 }, ) const filtered = useMemo(() => { if (!data) return [] const q = search.trim().toLowerCase() return data.projects.filter((p) => { if (filter === 'unassigned' && p.mentors.length > 0) return false if (filter === 'assigned' && p.mentors.length === 0) return false if (filter === 'wants_only' && !p.wantsMentorship) return false if (!q) return true const hay = [ p.title, p.teamName ?? '', p.country ?? '', ...p.mentors.map((m) => m.name ?? m.email), ] .join(' ') .toLowerCase() return hay.includes(q) }) }, [data, search, filter]) const totals = useMemo(() => { if (!data) return { total: 0, unassigned: 0, assigned: 0, wants: 0 } return { total: data.projects.length, unassigned: data.projects.filter((p) => p.mentors.length === 0).length, assigned: data.projects.filter((p) => p.mentors.length > 0).length, wants: data.projects.filter((p) => p.wantsMentorship).length, } }, [data]) if (isLoading) { return (
{[1, 2, 3, 4, 5].map((i) => ( ))}
) } if (!data || data.projects.length === 0) { return (
No projects in this mentoring round yet.
) } const Pill = ({ value, label, count, }: { value: Filter label: string count: number }) => ( ) return (
setSearch(e.target.value)} placeholder="Search projects, teams, or mentors…" className="pl-8" />
Project Wants? Mentors Action {filtered.length === 0 ? ( No projects match the current filter. ) : ( filtered.map((p) => (
{p.title}
{p.teamName ?? '—'} {p.country && ( <> {' · '} )}
{p.wantsMentorship ? ( Requested ) : ( No )} {p.finalistConfirmationStatus !== 'CONFIRMED' && ( {p.finalistConfirmationStatus ? p.finalistConfirmationStatus.toLowerCase() : 'no confirmation'} )}
{p.mentors.length === 0 ? ( Unassigned ) : (
{p.mentors.map((m) => ( {(m.method === 'AI_AUTO' || m.method === 'AI_SUGGESTED') && ( )} {m.name ?? m.email} ))}
)}
)) )}
) }