Fix round assignment pool, create-page parity, and file settings UX

This commit is contained in:
root
2026-02-12 17:25:30 +01:00
parent 52cdca1b85
commit 8a328357e3
7 changed files with 2233 additions and 878 deletions

View File

@@ -1,8 +1,8 @@
'use client'
"use client";
import { useState, useCallback, useEffect, useMemo } from 'react'
import { trpc } from '@/lib/trpc/client'
import { toast } from 'sonner'
import { useState, useCallback, useEffect, useMemo } from "react";
import { trpc } from "@/lib/trpc/client";
import { toast } from "sonner";
import {
Dialog,
DialogContent,
@@ -10,18 +10,18 @@ import {
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
} from "@/components/ui/dialog";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
import { Badge } from '@/components/ui/badge'
import { Label } from '@/components/ui/label'
} from "@/components/ui/select";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import { Badge } from "@/components/ui/badge";
import { Label } from "@/components/ui/label";
import {
Table,
TableBody,
@@ -29,15 +29,15 @@ import {
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
import { ArrowRightCircle, Loader2, Info } from 'lucide-react'
} from "@/components/ui/table";
import { ArrowRightCircle, Loader2, Info } from "lucide-react";
interface AdvanceProjectsDialogProps {
roundId: string
programId: string
open: boolean
onOpenChange: (open: boolean) => void
onSuccess?: () => void
roundId: string;
programId: string;
open: boolean;
onOpenChange: (open: boolean) => void;
onSuccess?: () => void;
}
export function AdvanceProjectsDialog({
@@ -47,98 +47,98 @@ export function AdvanceProjectsDialog({
onOpenChange,
onSuccess,
}: AdvanceProjectsDialogProps) {
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set())
const [targetRoundId, setTargetRoundId] = useState<string>('')
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
const [targetRoundId, setTargetRoundId] = useState<string>("");
const utils = trpc.useUtils()
const utils = trpc.useUtils();
// Reset state when dialog opens
useEffect(() => {
if (open) {
setSelectedIds(new Set())
setTargetRoundId('')
setSelectedIds(new Set());
setTargetRoundId("");
}
}, [open])
}, [open]);
// Fetch rounds in program
const { data: roundsData } = trpc.round.list.useQuery(
{ programId },
{ enabled: open }
)
{ enabled: open },
);
// Fetch projects in current round
const { data: projectsData, isLoading } = trpc.project.list.useQuery(
{ roundId, page: 1, perPage: 5000 },
{ enabled: open }
)
{ roundId, page: 1, perPage: 200 },
{ enabled: open },
);
// Auto-select next round by sortOrder
const otherRounds = useMemo(() => {
if (!roundsData) return []
if (!roundsData) return [];
return roundsData
.filter((r) => r.id !== roundId)
.sort((a, b) => a.sortOrder - b.sortOrder)
}, [roundsData, roundId])
.sort((a, b) => a.sortOrder - b.sortOrder);
}, [roundsData, roundId]);
const currentRound = useMemo(() => {
return roundsData?.find((r) => r.id === roundId)
}, [roundsData, roundId])
return roundsData?.find((r) => r.id === roundId);
}, [roundsData, roundId]);
// Auto-select next round in sort order
useEffect(() => {
if (open && otherRounds.length > 0 && !targetRoundId && currentRound) {
const nextRound = otherRounds.find(
(r) => r.sortOrder > currentRound.sortOrder
)
setTargetRoundId(nextRound?.id || otherRounds[0].id)
(r) => r.sortOrder > currentRound.sortOrder,
);
setTargetRoundId(nextRound?.id || otherRounds[0].id);
}
}, [open, otherRounds, targetRoundId, currentRound])
}, [open, otherRounds, targetRoundId, currentRound]);
const advanceMutation = trpc.round.advanceProjects.useMutation({
onSuccess: (result) => {
const targetName = otherRounds.find((r) => r.id === targetRoundId)?.name
const targetName = otherRounds.find((r) => r.id === targetRoundId)?.name;
toast.success(
`${result.advanced} project${result.advanced !== 1 ? 's' : ''} advanced to ${targetName}`
)
utils.round.get.invalidate()
utils.project.list.invalidate()
onSuccess?.()
onOpenChange(false)
`${result.advanced} project${result.advanced !== 1 ? "s" : ""} advanced to ${targetName}`,
);
utils.round.get.invalidate();
utils.project.list.invalidate();
onSuccess?.();
onOpenChange(false);
},
onError: (error) => {
toast.error(error.message)
toast.error(error.message);
},
})
});
const projects = projectsData?.projects ?? []
const projects = projectsData?.projects ?? [];
const toggleProject = useCallback((id: string) => {
setSelectedIds((prev) => {
const next = new Set(prev)
if (next.has(id)) next.delete(id)
else next.add(id)
return next
})
}, [])
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}, []);
const toggleAll = useCallback(() => {
if (selectedIds.size === projects.length) {
setSelectedIds(new Set())
setSelectedIds(new Set());
} else {
setSelectedIds(new Set(projects.map((p) => p.id)))
setSelectedIds(new Set(projects.map((p) => p.id)));
}
}, [selectedIds.size, projects])
}, [selectedIds.size, projects]);
const handleAdvance = () => {
if (selectedIds.size === 0 || !targetRoundId) return
if (selectedIds.size === 0 || !targetRoundId) return;
advanceMutation.mutate({
fromRoundId: roundId,
toRoundId: targetRoundId,
projectIds: Array.from(selectedIds),
})
}
});
};
const targetRoundName = otherRounds.find((r) => r.id === targetRoundId)?.name
const targetRoundName = otherRounds.find((r) => r.id === targetRoundId)?.name;
return (
<Dialog open={open} onOpenChange={onOpenChange}>
@@ -158,7 +158,8 @@ export function AdvanceProjectsDialog({
<Label>Target Round</Label>
{otherRounds.length === 0 ? (
<p className="text-sm text-muted-foreground">
No other rounds available in this program. Create another round first.
No other rounds available in this program. Create another round
first.
</p>
) : (
<Select value={targetRoundId} onValueChange={setTargetRoundId}>
@@ -179,8 +180,9 @@ export function AdvanceProjectsDialog({
<div className="flex items-start gap-2 rounded-lg bg-blue-50 p-3 text-sm text-blue-800 dark:bg-blue-950/50 dark:text-blue-200">
<Info className="h-4 w-4 mt-0.5 shrink-0" />
<span>
Projects will be copied to the target round with &quot;Submitted&quot; status.
They will remain in the current round with their existing status.
Projects will be copied to the target round with
&quot;Submitted&quot; status. They will remain in the current round
with their existing status.
</span>
</div>
@@ -200,7 +202,9 @@ export function AdvanceProjectsDialog({
<div className="space-y-3">
<div className="flex items-center gap-2">
<Checkbox
checked={selectedIds.size === projects.length && projects.length > 0}
checked={
selectedIds.size === projects.length && projects.length > 0
}
onCheckedChange={toggleAll}
/>
<span className="text-sm text-muted-foreground">
@@ -222,7 +226,11 @@ export function AdvanceProjectsDialog({
{projects.map((project) => (
<TableRow
key={project.id}
className={selectedIds.has(project.id) ? 'bg-muted/50' : 'cursor-pointer'}
className={
selectedIds.has(project.id)
? "bg-muted/50"
: "cursor-pointer"
}
onClick={() => toggleProject(project.id)}
>
<TableCell>
@@ -236,11 +244,11 @@ export function AdvanceProjectsDialog({
{project.title}
</TableCell>
<TableCell className="text-muted-foreground">
{project.teamName || '—'}
{project.teamName || "—"}
</TableCell>
<TableCell>
<Badge variant="secondary" className="text-xs">
{(project.status ?? 'SUBMITTED').replace('_', ' ')}
{(project.status ?? "SUBMITTED").replace("_", " ")}
</Badge>
</TableCell>
</TableRow>
@@ -270,10 +278,10 @@ export function AdvanceProjectsDialog({
<ArrowRightCircle className="mr-2 h-4 w-4" />
)}
Advance Selected ({selectedIds.size})
{targetRoundName ? ` to ${targetRoundName}` : ''}
{targetRoundName ? ` to ${targetRoundName}` : ""}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
);
}

View File

@@ -1,8 +1,8 @@
'use client'
"use client";
import { useState, useCallback, useEffect } from 'react'
import { trpc } from '@/lib/trpc/client'
import { toast } from 'sonner'
import { useState, useCallback, useEffect } from "react";
import { trpc } from "@/lib/trpc/client";
import { toast } from "sonner";
import {
Dialog,
DialogContent,
@@ -10,11 +10,11 @@ import {
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Checkbox } from '@/components/ui/checkbox'
import { Badge } from '@/components/ui/badge'
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Checkbox } from "@/components/ui/checkbox";
import { Badge } from "@/components/ui/badge";
import {
Table,
TableBody,
@@ -22,16 +22,16 @@ import {
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
import { Search, Loader2, Plus, Package, CheckCircle2 } from 'lucide-react'
import { getCountryName } from '@/lib/countries'
} from "@/components/ui/table";
import { Search, Loader2, Plus, Package, CheckCircle2 } from "lucide-react";
import { getCountryName } from "@/lib/countries";
interface AssignProjectsDialogProps {
roundId: string
programId: string
open: boolean
onOpenChange: (open: boolean) => void
onSuccess?: () => void
roundId: string;
programId: string;
open: boolean;
onOpenChange: (open: boolean) => void;
onSuccess?: () => void;
}
export function AssignProjectsDialog({
@@ -41,81 +41,87 @@ export function AssignProjectsDialog({
onOpenChange,
onSuccess,
}: AssignProjectsDialogProps) {
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set())
const [search, setSearch] = useState('')
const [debouncedSearch, setDebouncedSearch] = useState('')
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
const [search, setSearch] = useState("");
const [debouncedSearch, setDebouncedSearch] = useState("");
const utils = trpc.useUtils()
const utils = trpc.useUtils();
// Debounce search
useEffect(() => {
const timer = setTimeout(() => setDebouncedSearch(search), 300)
return () => clearTimeout(timer)
}, [search])
const timer = setTimeout(() => setDebouncedSearch(search), 300);
return () => clearTimeout(timer);
}, [search]);
// Reset state when dialog opens
useEffect(() => {
if (open) {
setSelectedIds(new Set())
setSearch('')
setDebouncedSearch('')
setSelectedIds(new Set());
setSearch("");
setDebouncedSearch("");
}
}, [open])
}, [open]);
const { data, isLoading } = trpc.project.list.useQuery(
const { data, isLoading, error } = trpc.project.list.useQuery(
{
programId,
unassignedOnly: true,
search: debouncedSearch || undefined,
page: 1,
perPage: 5000,
perPage: 200,
},
{ enabled: open }
)
{ enabled: open },
);
const assignMutation = trpc.round.assignProjects.useMutation({
onSuccess: (result) => {
toast.success(`${result.assigned} project${result.assigned !== 1 ? 's' : ''} assigned to round`)
utils.round.get.invalidate({ id: roundId })
utils.project.list.invalidate()
onSuccess?.()
onOpenChange(false)
toast.success(
`${result.assigned} project${result.assigned !== 1 ? "s" : ""} assigned to round`,
);
utils.round.get.invalidate({ id: roundId });
utils.project.list.invalidate();
onSuccess?.();
onOpenChange(false);
},
onError: (error) => {
toast.error(error.message)
toast.error(error.message);
},
})
});
const projects = data?.projects ?? []
const projects = data?.projects ?? [];
const alreadyInRound = new Set(
projects.filter((p) => p.round?.id === roundId).map((p) => p.id)
)
const assignableProjects = projects.filter((p) => !alreadyInRound.has(p.id))
projects.filter((p) => p.round?.id === roundId).map((p) => p.id),
);
const assignableProjects = projects.filter((p) => !alreadyInRound.has(p.id));
const toggleProject = useCallback((id: string) => {
if (alreadyInRound.has(id)) return
setSelectedIds((prev) => {
const next = new Set(prev)
if (next.has(id)) next.delete(id)
else next.add(id)
return next
})
}, [alreadyInRound])
const toggleProject = useCallback(
(id: string) => {
if (alreadyInRound.has(id)) return;
setSelectedIds((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
},
[alreadyInRound],
);
const toggleAll = useCallback(() => {
if (selectedIds.size === assignableProjects.length) {
setSelectedIds(new Set())
setSelectedIds(new Set());
} else {
setSelectedIds(new Set(assignableProjects.map((p) => p.id)))
setSelectedIds(new Set(assignableProjects.map((p) => p.id)));
}
}, [selectedIds.size, assignableProjects])
}, [selectedIds.size, assignableProjects]);
const handleAssign = () => {
if (selectedIds.size === 0) return
if (selectedIds.size === 0) return;
assignMutation.mutate({
roundId,
projectIds: Array.from(selectedIds),
})
}
});
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
@@ -126,7 +132,7 @@ export function AssignProjectsDialog({
Assign Projects to Round
</DialogTitle>
<DialogDescription>
Select projects from the program to add to this round.
Select projects from the program pool to add to this round.
</DialogDescription>
</DialogHeader>
@@ -145,12 +151,19 @@ export function AssignProjectsDialog({
<div className="flex items-center justify-center py-12">
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
</div>
) : error ? (
<div className="flex flex-col items-center justify-center py-12 text-center">
<p className="mt-2 font-medium">Failed to load projects</p>
<p className="text-sm text-muted-foreground">{error.message}</p>
</div>
) : projects.length === 0 ? (
<div className="flex flex-col items-center justify-center py-12 text-center">
<Package className="h-12 w-12 text-muted-foreground/50" />
<p className="mt-2 font-medium">No projects found</p>
<p className="text-sm text-muted-foreground">
{debouncedSearch ? 'No projects match your search.' : 'This program has no projects yet.'}
{debouncedSearch
? "No projects in the pool match your search."
: "This program has no projects in the pool yet."}
</p>
</div>
) : (
@@ -158,14 +171,20 @@ export function AssignProjectsDialog({
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Checkbox
checked={assignableProjects.length > 0 && selectedIds.size === assignableProjects.length}
checked={
assignableProjects.length > 0 &&
selectedIds.size === assignableProjects.length
}
disabled={assignableProjects.length === 0}
onCheckedChange={toggleAll}
/>
<span className="text-sm text-muted-foreground">
{selectedIds.size} of {assignableProjects.length} assignable selected
{selectedIds.size} of {assignableProjects.length} assignable
selected
{alreadyInRound.size > 0 && (
<span className="ml-1">({alreadyInRound.size} already in round)</span>
<span className="ml-1">
({alreadyInRound.size} already in round)
</span>
)}
</span>
</div>
@@ -183,16 +202,16 @@ export function AssignProjectsDialog({
</TableHeader>
<TableBody>
{projects.map((project) => {
const isInRound = alreadyInRound.has(project.id)
const isInRound = alreadyInRound.has(project.id);
return (
<TableRow
key={project.id}
className={
isInRound
? 'opacity-60'
? "opacity-60"
: selectedIds.has(project.id)
? 'bg-muted/50'
: 'cursor-pointer'
? "bg-muted/50"
: "cursor-pointer"
}
onClick={() => toggleProject(project.id)}
>
@@ -202,7 +221,9 @@ export function AssignProjectsDialog({
) : (
<Checkbox
checked={selectedIds.has(project.id)}
onCheckedChange={() => toggleProject(project.id)}
onCheckedChange={() =>
toggleProject(project.id)
}
onClick={(e) => e.stopPropagation()}
/>
)}
@@ -218,17 +239,19 @@ export function AssignProjectsDialog({
</div>
</TableCell>
<TableCell className="text-muted-foreground">
{project.teamName || '—'}
{project.teamName || "—"}
</TableCell>
<TableCell>
{project.country ? (
<Badge variant="outline" className="text-xs">
{getCountryName(project.country)}
</Badge>
) : '—'}
) : (
"—"
)}
</TableCell>
</TableRow>
)
);
})}
</TableBody>
</Table>
@@ -255,5 +278,5 @@ export function AssignProjectsDialog({
</DialogFooter>
</DialogContent>
</Dialog>
)
);
}

View File

@@ -1,20 +1,20 @@
'use client'
"use client";
import { useState } from 'react'
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 { Textarea } from '@/components/ui/textarea'
import { Switch } from '@/components/ui/switch'
import { Badge } from '@/components/ui/badge'
import { useState } from "react";
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 { Textarea } from "@/components/ui/textarea";
import { Switch } from "@/components/ui/switch";
import { Badge } from "@/components/ui/badge";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
} from "@/components/ui/card";
import {
Dialog,
DialogContent,
@@ -22,8 +22,8 @@ import {
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { toast } from 'sonner'
} from "@/components/ui/dialog";
import { toast } from "sonner";
import {
Plus,
Pencil,
@@ -33,103 +33,117 @@ import {
ArrowDown,
FileText,
Loader2,
} from 'lucide-react'
} from "lucide-react";
const MIME_TYPE_PRESETS = [
{ label: 'PDF', value: 'application/pdf' },
{ label: 'Images', value: 'image/*' },
{ label: 'Video', value: 'video/*' },
{ label: 'Word Documents', value: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' },
{ label: 'Excel', value: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' },
{ label: 'PowerPoint', value: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' },
]
{ label: "PDF", value: "application/pdf" },
{ label: "Images", value: "image/*" },
{ label: "Video", value: "video/*" },
{
label: "Word Documents",
value:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
},
{
label: "Excel",
value: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
},
{
label: "PowerPoint",
value:
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
},
];
function getMimeLabel(mime: string): string {
const preset = MIME_TYPE_PRESETS.find((p) => p.value === mime)
if (preset) return preset.label
if (mime.endsWith('/*')) return mime.replace('/*', '')
return mime
const preset = MIME_TYPE_PRESETS.find((p) => p.value === mime);
if (preset) return preset.label;
if (mime.endsWith("/*")) return mime.replace("/*", "");
return mime;
}
interface FileRequirementsEditorProps {
roundId: string
roundId: string;
}
interface RequirementFormData {
name: string
description: string
acceptedMimeTypes: string[]
maxSizeMB: string
isRequired: boolean
name: string;
description: string;
acceptedMimeTypes: string[];
maxSizeMB: string;
isRequired: boolean;
}
const emptyForm: RequirementFormData = {
name: '',
description: '',
name: "",
description: "",
acceptedMimeTypes: [],
maxSizeMB: '',
maxSizeMB: "",
isRequired: true,
}
};
export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps) {
const utils = trpc.useUtils()
export function FileRequirementsEditor({
roundId,
}: FileRequirementsEditorProps) {
const utils = trpc.useUtils();
const { data: requirements = [], isLoading } = trpc.file.listRequirements.useQuery({ roundId })
const { data: requirements = [], isLoading } =
trpc.file.listRequirements.useQuery({ roundId });
const createMutation = trpc.file.createRequirement.useMutation({
onSuccess: () => {
utils.file.listRequirements.invalidate({ roundId })
toast.success('Requirement created')
utils.file.listRequirements.invalidate({ roundId });
toast.success("Requirement created");
},
onError: (err) => toast.error(err.message),
})
});
const updateMutation = trpc.file.updateRequirement.useMutation({
onSuccess: () => {
utils.file.listRequirements.invalidate({ roundId })
toast.success('Requirement updated')
utils.file.listRequirements.invalidate({ roundId });
toast.success("Requirement updated");
},
onError: (err) => toast.error(err.message),
})
});
const deleteMutation = trpc.file.deleteRequirement.useMutation({
onSuccess: () => {
utils.file.listRequirements.invalidate({ roundId })
toast.success('Requirement deleted')
utils.file.listRequirements.invalidate({ roundId });
toast.success("Requirement deleted");
},
onError: (err) => toast.error(err.message),
})
});
const reorderMutation = trpc.file.reorderRequirements.useMutation({
onSuccess: () => utils.file.listRequirements.invalidate({ roundId }),
onError: (err) => toast.error(err.message),
})
});
const [dialogOpen, setDialogOpen] = useState(false)
const [editingId, setEditingId] = useState<string | null>(null)
const [form, setForm] = useState<RequirementFormData>(emptyForm)
const [dialogOpen, setDialogOpen] = useState(false);
const [editingId, setEditingId] = useState<string | null>(null);
const [form, setForm] = useState<RequirementFormData>(emptyForm);
const openCreate = () => {
setEditingId(null)
setForm(emptyForm)
setDialogOpen(true)
}
setEditingId(null);
setForm(emptyForm);
setDialogOpen(true);
};
const openEdit = (req: typeof requirements[number]) => {
setEditingId(req.id)
const openEdit = (req: (typeof requirements)[number]) => {
setEditingId(req.id);
setForm({
name: req.name,
description: req.description || '',
description: req.description || "",
acceptedMimeTypes: req.acceptedMimeTypes,
maxSizeMB: req.maxSizeMB?.toString() || '',
maxSizeMB: req.maxSizeMB?.toString() || "",
isRequired: req.isRequired,
})
setDialogOpen(true)
}
});
setDialogOpen(true);
};
const handleSave = async () => {
if (!form.name.trim()) {
toast.error('Name is required')
return
toast.error("Name is required");
return;
}
const maxSizeMB = form.maxSizeMB ? parseInt(form.maxSizeMB) : undefined
const maxSizeMB = form.maxSizeMB ? parseInt(form.maxSizeMB) : undefined;
if (editingId) {
await updateMutation.mutateAsync({
@@ -139,7 +153,7 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
acceptedMimeTypes: form.acceptedMimeTypes,
maxSizeMB: maxSizeMB || null,
isRequired: form.isRequired,
})
});
} else {
await createMutation.mutateAsync({
roundId,
@@ -149,26 +163,29 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
maxSizeMB,
isRequired: form.isRequired,
sortOrder: requirements.length,
})
});
}
setDialogOpen(false)
}
setDialogOpen(false);
};
const handleDelete = async (id: string) => {
await deleteMutation.mutateAsync({ id })
}
await deleteMutation.mutateAsync({ id });
};
const handleMove = async (index: number, direction: 'up' | 'down') => {
const newOrder = [...requirements]
const swapIndex = direction === 'up' ? index - 1 : index + 1
if (swapIndex < 0 || swapIndex >= newOrder.length) return
;[newOrder[index], newOrder[swapIndex]] = [newOrder[swapIndex], newOrder[index]]
const handleMove = async (index: number, direction: "up" | "down") => {
const newOrder = [...requirements];
const swapIndex = direction === "up" ? index - 1 : index + 1;
if (swapIndex < 0 || swapIndex >= newOrder.length) return;
[newOrder[index], newOrder[swapIndex]] = [
newOrder[swapIndex],
newOrder[index],
];
await reorderMutation.mutateAsync({
roundId,
orderedIds: newOrder.map((r) => r.id),
})
}
});
};
const toggleMimeType = (mime: string) => {
setForm((prev) => ({
@@ -176,10 +193,10 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
acceptedMimeTypes: prev.acceptedMimeTypes.includes(mime)
? prev.acceptedMimeTypes.filter((m) => m !== mime)
: [...prev.acceptedMimeTypes, mime],
}))
}
}));
};
const isSaving = createMutation.isPending || updateMutation.isPending
const isSaving = createMutation.isPending || updateMutation.isPending;
return (
<Card>
@@ -194,7 +211,7 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
Define required files applicants must upload for this round
</CardDescription>
</div>
<Button onClick={openCreate} size="sm">
<Button type="button" onClick={openCreate} size="sm">
<Plus className="mr-1 h-4 w-4" />
Add Requirement
</Button>
@@ -207,7 +224,8 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
</div>
) : requirements.length === 0 ? (
<div className="text-center py-8 text-muted-foreground">
No file requirements defined. Applicants can still upload files freely.
No file requirements defined. Applicants can still upload files
freely.
</div>
) : (
<div className="space-y-2">
@@ -218,19 +236,21 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
>
<div className="flex flex-col gap-0.5">
<Button
type="button"
variant="ghost"
size="icon"
className="h-6 w-6"
onClick={() => handleMove(index, 'up')}
onClick={() => handleMove(index, "up")}
disabled={index === 0}
>
<ArrowUp className="h-3 w-3" />
</Button>
<Button
type="button"
variant="ghost"
size="icon"
className="h-6 w-6"
onClick={() => handleMove(index, 'down')}
onClick={() => handleMove(index, "down")}
disabled={index === requirements.length - 1}
>
<ArrowDown className="h-3 w-3" />
@@ -240,12 +260,17 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 mb-1">
<span className="font-medium truncate">{req.name}</span>
<Badge variant={req.isRequired ? 'destructive' : 'secondary'} className="text-xs shrink-0">
{req.isRequired ? 'Required' : 'Optional'}
<Badge
variant={req.isRequired ? "destructive" : "secondary"}
className="text-xs shrink-0"
>
{req.isRequired ? "Required" : "Optional"}
</Badge>
</div>
{req.description && (
<p className="text-sm text-muted-foreground line-clamp-1">{req.description}</p>
<p className="text-sm text-muted-foreground line-clamp-1">
{req.description}
</p>
)}
<div className="flex flex-wrap gap-1 mt-1">
{req.acceptedMimeTypes.map((mime) => (
@@ -261,10 +286,17 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
</div>
</div>
<div className="flex items-center gap-1 shrink-0">
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={() => openEdit(req)}>
<Button
type="button"
variant="ghost"
size="icon"
className="h-8 w-8"
onClick={() => openEdit(req)}
>
<Pencil className="h-4 w-4" />
</Button>
<Button
type="button"
variant="ghost"
size="icon"
className="h-8 w-8 text-destructive hover:text-destructive"
@@ -284,7 +316,9 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
<DialogContent className="max-w-md">
<DialogHeader>
<DialogTitle>{editingId ? 'Edit' : 'Add'} File Requirement</DialogTitle>
<DialogTitle>
{editingId ? "Edit" : "Add"} File Requirement
</DialogTitle>
<DialogDescription>
Define what file applicants need to upload for this round.
</DialogDescription>
@@ -296,7 +330,9 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
<Input
id="req-name"
value={form.name}
onChange={(e) => setForm((p) => ({ ...p, name: e.target.value }))}
onChange={(e) =>
setForm((p) => ({ ...p, name: e.target.value }))
}
placeholder="e.g., Executive Summary"
/>
</div>
@@ -306,7 +342,9 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
<Textarea
id="req-desc"
value={form.description}
onChange={(e) => setForm((p) => ({ ...p, description: e.target.value }))}
onChange={(e) =>
setForm((p) => ({ ...p, description: e.target.value }))
}
placeholder="Describe what this file should contain..."
rows={3}
/>
@@ -318,7 +356,11 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
{MIME_TYPE_PRESETS.map((preset) => (
<Badge
key={preset.value}
variant={form.acceptedMimeTypes.includes(preset.value) ? 'default' : 'outline'}
variant={
form.acceptedMimeTypes.includes(preset.value)
? "default"
: "outline"
}
className="cursor-pointer"
onClick={() => toggleMimeType(preset.value)}
>
@@ -337,7 +379,9 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
id="req-size"
type="number"
value={form.maxSizeMB}
onChange={(e) => setForm((p) => ({ ...p, maxSizeMB: e.target.value }))}
onChange={(e) =>
setForm((p) => ({ ...p, maxSizeMB: e.target.value }))
}
placeholder="No limit"
min={1}
max={5000}
@@ -354,22 +398,28 @@ export function FileRequirementsEditor({ roundId }: FileRequirementsEditorProps)
<Switch
id="req-required"
checked={form.isRequired}
onCheckedChange={(checked) => setForm((p) => ({ ...p, isRequired: checked }))}
onCheckedChange={(checked) =>
setForm((p) => ({ ...p, isRequired: checked }))
}
/>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setDialogOpen(false)}>
<Button
type="button"
variant="outline"
onClick={() => setDialogOpen(false)}
>
Cancel
</Button>
<Button onClick={handleSave} disabled={isSaving}>
<Button type="button" onClick={handleSave} disabled={isSaving}>
{isSaving && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{editingId ? 'Update' : 'Create'}
{editingId ? "Update" : "Create"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</Card>
)
);
}

View File

@@ -1,8 +1,8 @@
'use client'
"use client";
import { useState, useCallback, useEffect } from 'react'
import { trpc } from '@/lib/trpc/client'
import { toast } from 'sonner'
import { useState, useCallback, useEffect } from "react";
import { trpc } from "@/lib/trpc/client";
import { toast } from "sonner";
import {
Dialog,
DialogContent,
@@ -10,7 +10,7 @@ import {
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
} from "@/components/ui/dialog";
import {
AlertDialog,
AlertDialogAction,
@@ -20,10 +20,10 @@ import {
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
import { Badge } from '@/components/ui/badge'
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import { Badge } from "@/components/ui/badge";
import {
Table,
TableBody,
@@ -31,14 +31,14 @@ import {
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
import { Minus, Loader2, AlertTriangle } from 'lucide-react'
} from "@/components/ui/table";
import { Minus, Loader2, AlertTriangle } from "lucide-react";
interface RemoveProjectsDialogProps {
roundId: string
open: boolean
onOpenChange: (open: boolean) => void
onSuccess?: () => void
roundId: string;
open: boolean;
onOpenChange: (open: boolean) => void;
onSuccess?: () => void;
}
export function RemoveProjectsDialog({
@@ -47,66 +47,66 @@ export function RemoveProjectsDialog({
onOpenChange,
onSuccess,
}: RemoveProjectsDialogProps) {
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set())
const [confirmOpen, setConfirmOpen] = useState(false)
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
const [confirmOpen, setConfirmOpen] = useState(false);
const utils = trpc.useUtils()
const utils = trpc.useUtils();
// Reset state when dialog opens
useEffect(() => {
if (open) {
setSelectedIds(new Set())
setConfirmOpen(false)
setSelectedIds(new Set());
setConfirmOpen(false);
}
}, [open])
}, [open]);
const { data, isLoading } = trpc.project.list.useQuery(
{ roundId, page: 1, perPage: 5000 },
{ enabled: open }
)
{ roundId, page: 1, perPage: 200 },
{ enabled: open },
);
const removeMutation = trpc.round.removeProjects.useMutation({
onSuccess: (result) => {
toast.success(
`${result.removed} project${result.removed !== 1 ? 's' : ''} removed from round`
)
utils.round.get.invalidate({ id: roundId })
utils.project.list.invalidate()
onSuccess?.()
onOpenChange(false)
`${result.removed} project${result.removed !== 1 ? "s" : ""} removed from round`,
);
utils.round.get.invalidate({ id: roundId });
utils.project.list.invalidate();
onSuccess?.();
onOpenChange(false);
},
onError: (error) => {
toast.error(error.message)
toast.error(error.message);
},
})
});
const projects = data?.projects ?? []
const projects = data?.projects ?? [];
const toggleProject = useCallback((id: string) => {
setSelectedIds((prev) => {
const next = new Set(prev)
if (next.has(id)) next.delete(id)
else next.add(id)
return next
})
}, [])
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}, []);
const toggleAll = useCallback(() => {
if (selectedIds.size === projects.length) {
setSelectedIds(new Set())
setSelectedIds(new Set());
} else {
setSelectedIds(new Set(projects.map((p) => p.id)))
setSelectedIds(new Set(projects.map((p) => p.id)));
}
}, [selectedIds.size, projects])
}, [selectedIds.size, projects]);
const handleRemove = () => {
if (selectedIds.size === 0) return
if (selectedIds.size === 0) return;
removeMutation.mutate({
roundId,
projectIds: Array.from(selectedIds),
})
setConfirmOpen(false)
}
});
setConfirmOpen(false);
};
return (
<>
@@ -118,8 +118,8 @@ export function RemoveProjectsDialog({
Remove Projects from Round
</DialogTitle>
<DialogDescription>
Select projects to remove from this round. The projects will remain
in the program and can be re-assigned later.
Select projects to remove from this round. The projects will
remain in the program and can be re-assigned later.
</DialogDescription>
</DialogHeader>
@@ -147,7 +147,10 @@ export function RemoveProjectsDialog({
<div className="space-y-3">
<div className="flex items-center gap-2">
<Checkbox
checked={selectedIds.size === projects.length && projects.length > 0}
checked={
selectedIds.size === projects.length &&
projects.length > 0
}
onCheckedChange={toggleAll}
/>
<span className="text-sm text-muted-foreground">
@@ -169,7 +172,11 @@ export function RemoveProjectsDialog({
{projects.map((project) => (
<TableRow
key={project.id}
className={selectedIds.has(project.id) ? 'bg-muted/50' : 'cursor-pointer'}
className={
selectedIds.has(project.id)
? "bg-muted/50"
: "cursor-pointer"
}
onClick={() => toggleProject(project.id)}
>
<TableCell>
@@ -183,11 +190,14 @@ export function RemoveProjectsDialog({
{project.title}
</TableCell>
<TableCell className="text-muted-foreground">
{project.teamName || '—'}
{project.teamName || "—"}
</TableCell>
<TableCell>
<Badge variant="secondary" className="text-xs">
{(project.status ?? 'SUBMITTED').replace('_', ' ')}
{(project.status ?? "SUBMITTED").replace(
"_",
" ",
)}
</Badge>
</TableCell>
</TableRow>
@@ -225,7 +235,7 @@ export function RemoveProjectsDialog({
<AlertDialogTitle>Confirm Removal</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to remove {selectedIds.size} project
{selectedIds.size !== 1 ? 's' : ''} from this round? Their
{selectedIds.size !== 1 ? "s" : ""} from this round? Their
assignments and evaluations in this round will be deleted. The
projects will remain in the program.
</AlertDialogDescription>
@@ -242,5 +252,5 @@ export function RemoveProjectsDialog({
</AlertDialogContent>
</AlertDialog>
</>
)
);
}