'use client' import { useState } from 'react' import { trpc } from '@/lib/trpc/client' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Skeleton } from '@/components/ui/skeleton' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { FileText, Upload, CheckCircle2, ArrowUp } from 'lucide-react' import { toast } from 'sonner' interface FilePromotionPanelProps { mentorAssignmentId: string } function formatFileSize(bytes: number): string { if (bytes === 0) return '0 B' const k = 1024 const sizes = ['B', 'KB', 'MB', 'GB'] const i = Math.floor(Math.log(bytes) / Math.log(k)) return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i] } export function FilePromotionPanel({ mentorAssignmentId }: FilePromotionPanelProps) { const [selectedSlot, setSelectedSlot] = useState('') const utils = trpc.useUtils() const { data: workspaceFiles = [], isLoading: filesLoading } = trpc.mentor.workspaceGetFiles.useQuery( { mentorAssignmentId }, { enabled: !!mentorAssignmentId }, ) const promoteMutation = trpc.mentor.workspacePromoteFile.useMutation({ onSuccess: () => { toast.success('File promoted successfully') setSelectedSlot('') }, onError: (err) => toast.error(err.message), }) const handlePromote = (mentorFileId: string) => { if (!selectedSlot) { toast.error('Please select a file requirement slot') return } promoteMutation.mutate({ roundId: '', // Would need to get this from context mentorFileId, slotKey: selectedSlot, }) } const isLoading = filesLoading if (isLoading) { return (
{[1, 2, 3].map((i) => ( ))}
) } return ( File Promotion Promote workspace files to official submission windows {/* Slot selector */}

Select which file requirement to promote files to

{/* Workspace files list */}
{workspaceFiles.length === 0 ? (

No workspace files available

Files shared in the workspace will appear here

) : ( workspaceFiles.map((file: any) => { const isPromoted = file.promotedToWindow return (

{file.filename}

{file.mimeType?.split('/')[1]?.toUpperCase() || 'FILE'} {file.size && ( {formatFileSize(file.size)} )}
{isPromoted ? ( Promoted ) : ( )}
{isPromoted && file.promotedToWindow && (

Promoted to: {file.promotedToWindow.name}

)}
) }) )}
{workspaceFiles.length > 0 && (

Note: Promoting a file will make it visible to jurors in the selected submission window. This action can help teams submit refined versions of their work.

)}
) }