Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
|
|
|
import { Label } from '@/components/ui/label';
|
|
|
|
|
import { Input } from '@/components/ui/input';
|
|
|
|
|
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
|
|
|
|
|
import {
|
|
|
|
|
AlertDialog,
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
AlertDialogTitle
|
|
|
|
|
} from '@/components/ui/alert-dialog';
|
|
|
|
|
import { Badge } from '@/components/ui/badge';
|
|
|
|
|
|
|
|
|
|
interface Project {
|
|
|
|
|
id: string;
|
|
|
|
|
title: string;
|
Admin platform audit: fix bugs, harden backend, add auto-refresh, clean dead code
Phase 1 — Critical bugs:
- Fix deliberation participant selection (wire jury group query)
- Fix reports "By Round" tab (inline content instead of 404 route)
- Fix messages "Sent History" (add message.sent procedure, wire tab)
- Add missing fields to competition award form (criteriaText, maxRankedPicks)
- Wire LiveControlPanel buttons (cursor, voting, scores)
- Fix ResultLockControls empty snapshot (fetch actual data before lock)
- Fix SubmissionWindowManager losing fields on edit
Phase 2 — Backend fixes:
- Remove write-in-query from specialAward.get
- Fix award eligibility job overwriting manual shortlist overrides
- Fix filtering startJob deleting all prior results (defer cleanup to post-success)
- Tighten access control: protectedProcedure → adminProcedure on 8 procedures
- Add audit logging to deliberation mutations
- Add FINALIST/SEMIFINALIST delete guard on project.delete/bulkDelete
Phase 3 — Auto-refresh:
- Add refetchInterval to 15+ admin pages/components (10s–30s)
- Fix AI job polling: derive speed from job status for all viewers
Phase 4 — Dead code cleanup:
- Delete unused command-palette, pdf-report, admin-page-transition
- Remove dead subItems sidebar code, unused GripVertical import
- Replace redundant isGenerating state with mutation.isPending
- Add Role column to jury members table
- Remove misleading manual mentor assignment stub
Phase 5 — UX improvements:
- Fix rounds page single-competition assumption (add selector)
- Remove raw UUID fallback in deliberation config
- Fix programs page "Stage" → "Round" terminology
Phase 6 — Backend hardening:
- Complete logAudit calls (add prisma, ipAddress, userAgent)
- Batch analytics queries (fix N+1 in getCrossRoundComparison, getYearOverYear)
- Batch user.bulkCreate writes (assignments, jury memberships, intents)
- Remove any casts from deliberation service (typed PrismaClient + TransactionClient)
- Fix stale DeliberationStatus enum values blocking build
40 files changed, 1010 insertions(+), 612 deletions(-)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 08:20:13 +01:00
|
|
|
category?: string;
|
|
|
|
|
teamName?: string | null;
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface DeliberationRankingFormProps {
|
|
|
|
|
projects: Project[];
|
|
|
|
|
mode: 'SINGLE_WINNER_VOTE' | 'FULL_RANKING';
|
|
|
|
|
onSubmit: (votes: Array<{ projectId: string; rank?: number; isWinnerPick?: boolean }>) => void;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function DeliberationRankingForm({
|
|
|
|
|
projects,
|
|
|
|
|
mode,
|
|
|
|
|
onSubmit,
|
|
|
|
|
disabled = false
|
|
|
|
|
}: DeliberationRankingFormProps) {
|
|
|
|
|
const [selectedWinner, setSelectedWinner] = useState<string>('');
|
|
|
|
|
const [rankings, setRankings] = useState<Record<string, number>>({});
|
|
|
|
|
const [confirmDialogOpen, setConfirmDialogOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
const handleSubmit = () => {
|
|
|
|
|
if (mode === 'SINGLE_WINNER_VOTE') {
|
|
|
|
|
if (!selectedWinner) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// FULL_RANKING mode - check if all ranks are assigned
|
|
|
|
|
const assignedRanks = Object.values(rankings);
|
|
|
|
|
if (assignedRanks.length !== projects.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setConfirmDialogOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleConfirm = () => {
|
|
|
|
|
if (mode === 'SINGLE_WINNER_VOTE') {
|
|
|
|
|
onSubmit([
|
|
|
|
|
{
|
|
|
|
|
projectId: selectedWinner,
|
|
|
|
|
isWinnerPick: true
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
// FULL_RANKING mode
|
|
|
|
|
const votes = Object.entries(rankings).map(([projectId, rank]) => ({
|
|
|
|
|
projectId,
|
|
|
|
|
rank
|
|
|
|
|
}));
|
|
|
|
|
onSubmit(votes);
|
|
|
|
|
}
|
|
|
|
|
setConfirmDialogOpen(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const isValid = mode === 'SINGLE_WINNER_VOTE'
|
|
|
|
|
? !!selectedWinner
|
|
|
|
|
: Object.keys(rankings).length === projects.length;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>
|
|
|
|
|
{mode === 'SINGLE_WINNER_VOTE' ? 'Select Winner' : 'Rank All Projects'}
|
|
|
|
|
</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
{mode === 'SINGLE_WINNER_VOTE'
|
|
|
|
|
? 'Choose your top pick for this category'
|
|
|
|
|
: 'Assign a rank (1 = best) to each project'}
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent className="space-y-6">
|
|
|
|
|
{mode === 'SINGLE_WINNER_VOTE' ? (
|
|
|
|
|
<RadioGroup value={selectedWinner} onValueChange={setSelectedWinner}>
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
{projects.map((project) => (
|
|
|
|
|
<div
|
|
|
|
|
key={project.id}
|
|
|
|
|
className="flex items-center space-x-3 rounded-lg border p-4"
|
|
|
|
|
>
|
|
|
|
|
<RadioGroupItem value={project.id} id={project.id} />
|
|
|
|
|
<Label htmlFor={project.id} className="flex-1 cursor-pointer">
|
|
|
|
|
<div>
|
|
|
|
|
<p className="font-medium">{project.title}</p>
|
|
|
|
|
<Badge variant="outline" className="mt-1">
|
|
|
|
|
{project.category}
|
|
|
|
|
</Badge>
|
|
|
|
|
</div>
|
|
|
|
|
</Label>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</RadioGroup>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
{projects.map((project) => (
|
|
|
|
|
<div
|
|
|
|
|
key={project.id}
|
|
|
|
|
className="flex items-center gap-3 rounded-lg border p-4"
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
min="1"
|
|
|
|
|
max={projects.length}
|
|
|
|
|
placeholder="Rank"
|
|
|
|
|
value={rankings[project.id] || ''}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const rank = parseInt(e.target.value) || 0;
|
|
|
|
|
if (rank > 0 && rank <= projects.length) {
|
|
|
|
|
setRankings({
|
|
|
|
|
...rankings,
|
|
|
|
|
[project.id]: rank
|
|
|
|
|
});
|
|
|
|
|
} else if (e.target.value === '') {
|
|
|
|
|
const newRankings = { ...rankings };
|
|
|
|
|
delete newRankings[project.id];
|
|
|
|
|
setRankings(newRankings);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
className="w-20"
|
|
|
|
|
/>
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<p className="font-medium">{project.title}</p>
|
|
|
|
|
<Badge variant="outline" className="mt-1">
|
|
|
|
|
{project.category}
|
|
|
|
|
</Badge>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Button onClick={handleSubmit} disabled={!isValid || disabled} className="w-full" size="lg">
|
|
|
|
|
{disabled ? 'Submitting...' : 'Submit Vote'}
|
|
|
|
|
</Button>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
{/* Confirmation Dialog */}
|
|
|
|
|
<AlertDialog open={confirmDialogOpen} onOpenChange={setConfirmDialogOpen}>
|
|
|
|
|
<AlertDialogContent>
|
|
|
|
|
<AlertDialogHeader>
|
|
|
|
|
<AlertDialogTitle>Confirm Your Vote</AlertDialogTitle>
|
|
|
|
|
<AlertDialogDescription>
|
|
|
|
|
{mode === 'SINGLE_WINNER_VOTE'
|
|
|
|
|
? 'You have selected your winner. This vote cannot be changed once submitted.'
|
|
|
|
|
: 'You have ranked all projects. This ranking cannot be changed once submitted.'}
|
|
|
|
|
</AlertDialogDescription>
|
|
|
|
|
</AlertDialogHeader>
|
|
|
|
|
<AlertDialogFooter>
|
|
|
|
|
<AlertDialogCancel>Review</AlertDialogCancel>
|
|
|
|
|
<AlertDialogAction onClick={handleConfirm}>Confirm Vote</AlertDialogAction>
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|