Implement 15 platform features: digest, availability, templates, comparison, live voting SSE, file versioning, mentorship, messaging, analytics, drafts, webhooks, peer review, audit enhancements, i18n

Features implemented:
- F1: Email digest notifications with cron endpoint and per-user frequency
- F2: Jury availability windows and workload preferences in smart assignment
- F3: Round templates with save-from-round and CRUD management
- F4: Side-by-side project comparison view for jury members
- F5: Real-time voting dashboard with Server-Sent Events (SSE)
- F6: Live voting UX: QR codes, audience voting, tie-breaking, score animations
- F7: File versioning, inline preview, bulk download with presigned URLs
- F8: Mentor dashboard: milestones, private notes, activity tracking
- F9: Communication hub with broadcasts, templates, and recipient targeting
- F10: Advanced analytics: cross-round comparison, juror consistency, diversity metrics, PDF export
- F11: Applicant draft saving with magic link resume and cron cleanup
- F12: Webhook integration layer with HMAC signing, retry, and delivery logs
- F13: Peer review discussions with anonymized scores and threaded comments
- F14: Audit log enhancements: before/after diffs, session grouping, anomaly detection, retention
- F15: i18n foundation with next-intl (EN/FR), cookie-based locale, language switcher

Schema: 12 new models, field additions to User, Project, ProjectFile, LiveVotingSession, LiveVote, MentorAssignment, AuditLog, Program
New routers: roundTemplate, message, webhook (registered in _app.ts)
New services: email-digest, webhook-dispatcher
New cron endpoints: /api/cron/digest, /api/cron/draft-cleanup, /api/cron/audit-cleanup
New API routes: /api/live-voting/stream (SSE), /api/files/bulk-download

All features are admin-configurable via SystemSettings or per-model settingsJson fields.
Docker build verified successfully.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 23:31:41 +01:00
parent f038c95777
commit 59436ed67a
68 changed files with 14541 additions and 546 deletions

View File

@@ -1,6 +1,6 @@
'use client'
import { use } from 'react'
import { use, useCallback, useState } from 'react'
import { trpc } from '@/lib/trpc/client'
import { Badge } from '@/components/ui/badge'
import {
@@ -12,19 +12,65 @@ import {
import { Skeleton } from '@/components/ui/skeleton'
import { Progress } from '@/components/ui/progress'
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
import { Trophy, Star, Clock, AlertCircle, Zap } from 'lucide-react'
import { Trophy, Star, Clock, AlertCircle, Zap, Wifi, WifiOff } from 'lucide-react'
import { useLiveVotingSSE, type VoteUpdate } from '@/hooks/use-live-voting-sse'
interface PageProps {
params: Promise<{ sessionId: string }>
}
interface PublicSession {
id: string
status: string
currentProjectId: string | null
votingEndsAt: string | null
presentationSettings: Record<string, unknown> | null
allowAudienceVotes: boolean
}
interface PublicProject {
id: string | undefined
title: string | undefined
teamName: string | null | undefined
averageScore: number
voteCount: number
}
function PublicScoresContent({ sessionId }: { sessionId: string }) {
// Fetch session data with polling
const { data, isLoading } = trpc.liveVoting.getPublicSession.useQuery(
// Track SSE-based score updates keyed by projectId
const [liveScores, setLiveScores] = useState<Record<string, { avg: number; count: number }>>({})
// Use public (no-auth) endpoint with reduced polling since SSE handles real-time
const { data, isLoading, refetch } = trpc.liveVoting.getPublicResults.useQuery(
{ sessionId },
{ refetchInterval: 2000 } // Poll every 2 seconds
{ refetchInterval: 10000 }
)
// SSE for real-time updates
const onVoteUpdate = useCallback((update: VoteUpdate) => {
setLiveScores((prev) => ({
...prev,
[update.projectId]: {
avg: update.averageScore ?? 0,
count: update.totalVotes,
},
}))
}, [])
const onSessionStatus = useCallback(() => {
refetch()
}, [refetch])
const onProjectChange = useCallback(() => {
refetch()
}, [refetch])
const { isConnected } = useLiveVotingSSE(sessionId, {
onVoteUpdate,
onSessionStatus,
onProjectChange,
})
if (isLoading) {
return <PublicScoresSkeleton />
}
@@ -43,16 +89,32 @@ function PublicScoresContent({ sessionId }: { sessionId: string }) {
)
}
const isCompleted = data.session.status === 'COMPLETED'
const isVoting = data.session.status === 'IN_PROGRESS'
const session = data.session as PublicSession
const projects = data.projects as PublicProject[]
const isCompleted = session.status === 'COMPLETED'
const isVoting = session.status === 'IN_PROGRESS'
// Merge live SSE scores with fetched data
const projectsWithLive = projects.map((project) => {
const live = project.id ? liveScores[project.id] : null
return {
...project,
averageScore: live ? live.avg : (project.averageScore || 0),
voteCount: live ? live.count : (project.voteCount || 0),
}
})
// Sort projects by score for leaderboard
const sortedProjects = [...data.projects].sort(
const sortedProjects = [...projectsWithLive].sort(
(a, b) => (b.averageScore || 0) - (a.averageScore || 0)
)
// Find max score for progress bars
const maxScore = Math.max(...data.projects.map((p) => p.averageScore || 0), 1)
const maxScore = Math.max(...sortedProjects.map((p) => p.averageScore || 0), 1)
// Get presentation settings
const presentationSettings = session.presentationSettings
return (
<div className="min-h-screen bg-gradient-to-br from-[#053d57] to-[#557f8c] p-4 md:p-8">
@@ -62,20 +124,22 @@ function PublicScoresContent({ sessionId }: { sessionId: string }) {
<div className="flex items-center justify-center gap-2 mb-2">
<Zap className="h-8 w-8" />
<h1 className="text-3xl font-bold">Live Scores</h1>
{isConnected ? (
<Wifi className="h-4 w-4 text-green-400" />
) : (
<WifiOff className="h-4 w-4 text-red-400" />
)}
</div>
<p className="text-white/80">
{data.round.program.name} - {data.round.name}
</p>
<Badge
variant={isVoting ? 'default' : isCompleted ? 'secondary' : 'outline'}
className="mt-2"
>
{isVoting ? 'LIVE' : isCompleted ? 'COMPLETED' : data.session.status}
{isVoting ? 'LIVE' : isCompleted ? 'COMPLETED' : session.status}
</Badge>
</div>
{/* Current project highlight */}
{isVoting && data.session.currentProjectId && (
{isVoting && session.currentProjectId && (
<Card className="border-2 border-green-500 bg-green-500/10 animate-pulse">
<CardHeader className="pb-2">
<div className="flex items-center gap-2 text-green-400">
@@ -85,7 +149,7 @@ function PublicScoresContent({ sessionId }: { sessionId: string }) {
</CardHeader>
<CardContent>
<p className="text-xl font-semibold text-white">
{data.projects.find((p) => p?.id === data.session.currentProjectId)?.title}
{projects.find((p) => p?.id === session.currentProjectId)?.title}
</p>
</CardContent>
</Card>
@@ -108,12 +172,13 @@ function PublicScoresContent({ sessionId }: { sessionId: string }) {
<div className="space-y-4">
{sortedProjects.map((project, index) => {
if (!project) return null
const isCurrent = project.id === data.session.currentProjectId
const isCurrent = project.id === session.currentProjectId
const scoreFormat = presentationSettings?.scoreDisplayFormat as string || 'bar'
return (
<div
key={project.id}
className={`rounded-lg p-4 ${
className={`rounded-lg p-4 transition-all duration-300 ${
isCurrent
? 'bg-green-500/10 border border-green-500'
: 'bg-muted/50'
@@ -147,29 +212,58 @@ function PublicScoresContent({ sessionId }: { sessionId: string }) {
{/* Score */}
<div className="shrink-0 text-right">
<div className="flex items-center gap-1">
<Star className="h-4 w-4 text-yellow-500" />
<span className="text-xl font-bold">
{project.averageScore?.toFixed(1) || '--'}
</span>
</div>
<p className="text-xs text-muted-foreground">
{project.voteCount} votes
</p>
{scoreFormat === 'radial' ? (
<div className="relative w-14 h-14">
<svg viewBox="0 0 36 36" className="w-14 h-14 -rotate-90">
<path
d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"
fill="none"
stroke="currentColor"
strokeWidth="2"
className="text-muted/30"
/>
<path
d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"
fill="none"
stroke="currentColor"
strokeWidth="2.5"
strokeDasharray={`${((project.averageScore || 0) / 10) * 100}, 100`}
className="text-primary"
/>
</svg>
<span className="absolute inset-0 flex items-center justify-center text-sm font-bold">
{project.averageScore?.toFixed(1) || '--'}
</span>
</div>
) : (
<>
<div className="flex items-center gap-1">
<Star className="h-4 w-4 text-yellow-500" />
<span className="text-xl font-bold">
{project.averageScore?.toFixed(1) || '--'}
</span>
</div>
<p className="text-xs text-muted-foreground">
{project.voteCount} votes
</p>
</>
)}
</div>
</div>
{/* Score bar */}
<div className="mt-3">
<Progress
value={
project.averageScore
? (project.averageScore / maxScore) * 100
: 0
}
className="h-2"
/>
</div>
{/* Score bar - shown for 'bar' format */}
{scoreFormat !== 'number' && scoreFormat !== 'radial' && (
<div className="mt-3">
<Progress
value={
project.averageScore
? (project.averageScore / maxScore) * 100
: 0
}
className="h-2"
/>
</div>
)}
</div>
)
})}
@@ -178,10 +272,28 @@ function PublicScoresContent({ sessionId }: { sessionId: string }) {
</CardContent>
</Card>
{/* Audience voting info */}
{session.allowAudienceVotes && isVoting && (
<Card className="border-primary/30 bg-primary/5">
<CardContent className="py-4 text-center">
<p className="text-sm font-medium">
Audience voting is enabled for this session
</p>
</CardContent>
</Card>
)}
{/* Footer */}
<p className="text-center text-white/60 text-sm">
Scores update in real-time
</p>
<div className="flex items-center justify-center gap-2">
{isConnected ? (
<Wifi className="h-3 w-3 text-green-400" />
) : (
<WifiOff className="h-3 w-3 text-red-400" />
)}
<p className="text-center text-white/60 text-sm">
Scores update in real-time
</p>
</div>
</div>
</div>
)