Admin platform audit: fix bugs, harden backend, add auto-refresh, clean dead code
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m23s
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m23s
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>
This commit is contained in:
@@ -5,7 +5,7 @@ import { trpc } from '@/lib/trpc/client';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { ChevronLeft, ChevronRight, Play, Square, Timer } from 'lucide-react';
|
||||
import { ChevronLeft, ChevronRight, Play, Square, Pause, Timer } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
interface LiveControlPanelProps {
|
||||
@@ -15,18 +15,36 @@ interface LiveControlPanelProps {
|
||||
|
||||
export function LiveControlPanel({ roundId, competitionId }: LiveControlPanelProps) {
|
||||
const utils = trpc.useUtils();
|
||||
const [timerSeconds, setTimerSeconds] = useState(300); // 5 minutes default
|
||||
const [timerSeconds, setTimerSeconds] = useState(300);
|
||||
const [isTimerRunning, setIsTimerRunning] = useState(false);
|
||||
|
||||
const { data: cursor } = trpc.live.getCursor.useQuery({ roundId });
|
||||
// TODO: Add getScores to live router
|
||||
const scores: any[] = [];
|
||||
const { data: cursor } = trpc.live.getCursor.useQuery(
|
||||
{ roundId },
|
||||
{ refetchInterval: 5000 }
|
||||
);
|
||||
|
||||
// TODO: Implement cursor mutation
|
||||
const moveCursorMutation = {
|
||||
mutate: () => {},
|
||||
isPending: false
|
||||
};
|
||||
const jumpMutation = trpc.live.jump.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.live.getCursor.invalidate({ roundId });
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
});
|
||||
|
||||
const pauseMutation = trpc.live.pause.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.live.getCursor.invalidate({ roundId });
|
||||
toast.success('Live session paused');
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
});
|
||||
|
||||
const resumeMutation = trpc.live.resume.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.live.getCursor.invalidate({ roundId });
|
||||
toast.success('Live session resumed');
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTimerRunning) return;
|
||||
@@ -44,14 +62,24 @@ export function LiveControlPanel({ roundId, competitionId }: LiveControlPanelPro
|
||||
return () => clearInterval(interval);
|
||||
}, [isTimerRunning]);
|
||||
|
||||
const currentIndex = cursor?.activeOrderIndex ?? 0;
|
||||
const totalProjects = cursor?.totalProjects ?? 0;
|
||||
const isNavigating = jumpMutation.isPending;
|
||||
|
||||
const handlePrevious = () => {
|
||||
// TODO: Implement previous navigation
|
||||
toast.info('Previous navigation not yet implemented');
|
||||
if (currentIndex <= 0) {
|
||||
toast.info('Already at the first project');
|
||||
return;
|
||||
}
|
||||
jumpMutation.mutate({ roundId, index: currentIndex - 1 });
|
||||
};
|
||||
|
||||
const handleNext = () => {
|
||||
// TODO: Implement next navigation
|
||||
toast.info('Next navigation not yet implemented');
|
||||
if (currentIndex >= totalProjects - 1) {
|
||||
toast.info('Already at the last project');
|
||||
return;
|
||||
}
|
||||
jumpMutation.mutate({ roundId, index: currentIndex + 1 });
|
||||
};
|
||||
|
||||
const formatTime = (seconds: number) => {
|
||||
@@ -67,12 +95,17 @@ export function LiveControlPanel({ roundId, competitionId }: LiveControlPanelPro
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle>Current Project</CardTitle>
|
||||
<div className="flex gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
{cursor && (
|
||||
<span className="text-sm text-muted-foreground tabular-nums">
|
||||
{currentIndex + 1} / {totalProjects}
|
||||
</span>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={handlePrevious}
|
||||
disabled={moveCursorMutation.isPending}
|
||||
disabled={isNavigating || currentIndex <= 0}
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -80,7 +113,7 @@ export function LiveControlPanel({ roundId, competitionId }: LiveControlPanelPro
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={handleNext}
|
||||
disabled={moveCursorMutation.isPending}
|
||||
disabled={isNavigating || currentIndex >= totalProjects - 1}
|
||||
>
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -92,13 +125,24 @@ export function LiveControlPanel({ roundId, competitionId }: LiveControlPanelPro
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<h3 className="text-2xl font-bold">{cursor.activeProject.title}</h3>
|
||||
{cursor.activeProject.teamName && (
|
||||
<p className="text-muted-foreground">{cursor.activeProject.teamName}</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
Total projects: {cursor.totalProjects}
|
||||
</div>
|
||||
{cursor.activeProject.tags && (cursor.activeProject.tags as string[]).length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{(cursor.activeProject.tags as string[]).map((tag: string) => (
|
||||
<Badge key={tag} variant="secondary" className="text-xs">
|
||||
{tag}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-muted-foreground">No project selected</p>
|
||||
<p className="text-muted-foreground">
|
||||
{cursor ? 'No project selected' : 'No live session active for this round'}
|
||||
</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -144,48 +188,48 @@ export function LiveControlPanel({ roundId, competitionId }: LiveControlPanelPro
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Voting Controls */}
|
||||
{/* Session Controls */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Voting Controls</CardTitle>
|
||||
<CardDescription>Manage jury and audience voting</CardDescription>
|
||||
<CardTitle>Session Controls</CardTitle>
|
||||
<CardDescription>Pause or resume the live presentation</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<Button className="w-full" variant="default">
|
||||
<Play className="mr-2 h-4 w-4" />
|
||||
Open Jury Voting
|
||||
</Button>
|
||||
<Button className="w-full" variant="outline">
|
||||
Close Voting
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Scores Display */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Live Scores</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{scores && scores.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{scores.map((score: any, index: number) => (
|
||||
<div
|
||||
key={score.projectId}
|
||||
className="flex items-center justify-between rounded-lg border p-3"
|
||||
>
|
||||
<div>
|
||||
<p className="font-medium">
|
||||
#{index + 1} {score.projectTitle}
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">{score.votes} votes</p>
|
||||
</div>
|
||||
<Badge variant="outline">{score.totalScore.toFixed(1)}</Badge>
|
||||
{cursor?.isPaused ? (
|
||||
<Button
|
||||
className="w-full"
|
||||
onClick={() => resumeMutation.mutate({ roundId })}
|
||||
disabled={resumeMutation.isPending}
|
||||
>
|
||||
<Play className="mr-2 h-4 w-4" />
|
||||
{resumeMutation.isPending ? 'Resuming...' : 'Resume Session'}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
className="w-full"
|
||||
variant="outline"
|
||||
onClick={() => pauseMutation.mutate({ roundId })}
|
||||
disabled={pauseMutation.isPending || !cursor}
|
||||
>
|
||||
<Pause className="mr-2 h-4 w-4" />
|
||||
{pauseMutation.isPending ? 'Pausing...' : 'Pause Session'}
|
||||
</Button>
|
||||
)}
|
||||
{cursor?.isPaused && (
|
||||
<Badge variant="destructive" className="w-full justify-center py-1">
|
||||
Session Paused
|
||||
</Badge>
|
||||
)}
|
||||
{cursor?.openCohorts && cursor.openCohorts.length > 0 && (
|
||||
<div className="rounded-lg border p-3">
|
||||
<p className="text-sm font-medium mb-2">Open Voting Windows</p>
|
||||
{cursor.openCohorts.map((cohort: any) => (
|
||||
<div key={cohort.id} className="flex items-center justify-between text-sm">
|
||||
<span>{cohort.name}</span>
|
||||
<Badge variant="outline">{cohort.votingMode}</Badge>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-center text-muted-foreground">No scores yet</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user