2026-02-14 15:26:42 +01:00
|
|
|
'use client'
|
|
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
import { useState, useMemo } from 'react'
|
2026-02-14 15:26:42 +01:00
|
|
|
import Link from 'next/link'
|
|
|
|
|
import { trpc } from '@/lib/trpc/client'
|
|
|
|
|
import {
|
|
|
|
|
Card,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardDescription,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
|
|
|
|
} from '@/components/ui/card'
|
|
|
|
|
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 { Badge } from '@/components/ui/badge'
|
|
|
|
|
import { Skeleton } from '@/components/ui/skeleton'
|
|
|
|
|
import { Checkbox } from '@/components/ui/checkbox'
|
|
|
|
|
import { Switch } from '@/components/ui/switch'
|
|
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectGroup,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectLabel,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
} from '@/components/ui/select'
|
|
|
|
|
import {
|
|
|
|
|
Tabs,
|
|
|
|
|
TabsContent,
|
|
|
|
|
TabsList,
|
|
|
|
|
TabsTrigger,
|
|
|
|
|
} from '@/components/ui/tabs'
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from '@/components/ui/table'
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from '@/components/ui/dialog'
|
|
|
|
|
import {
|
|
|
|
|
Send,
|
|
|
|
|
Mail,
|
|
|
|
|
Bell,
|
|
|
|
|
Clock,
|
|
|
|
|
Loader2,
|
|
|
|
|
LayoutTemplate,
|
|
|
|
|
AlertCircle,
|
|
|
|
|
Inbox,
|
|
|
|
|
CheckCircle2,
|
|
|
|
|
Eye,
|
2026-03-06 10:32:03 +01:00
|
|
|
Users,
|
|
|
|
|
FolderOpen,
|
|
|
|
|
XCircle,
|
|
|
|
|
ArrowRight,
|
2026-02-14 15:26:42 +01:00
|
|
|
} from 'lucide-react'
|
|
|
|
|
import { toast } from 'sonner'
|
|
|
|
|
import { formatDate } from '@/lib/utils'
|
|
|
|
|
|
2026-03-03 19:14:41 +01:00
|
|
|
type RecipientType = 'ALL' | 'ROLE' | 'ROUND_JURY' | 'ROUND_APPLICANTS' | 'PROGRAM_TEAM' | 'USER'
|
2026-02-14 15:26:42 +01:00
|
|
|
|
|
|
|
|
const RECIPIENT_TYPE_OPTIONS: { value: RecipientType; label: string }[] = [
|
|
|
|
|
{ value: 'ALL', label: 'All Users' },
|
|
|
|
|
{ value: 'ROLE', label: 'By Role' },
|
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
|
|
|
{ value: 'ROUND_JURY', label: 'Round Jury' },
|
2026-03-03 19:14:41 +01:00
|
|
|
{ value: 'ROUND_APPLICANTS', label: 'Round Applicants' },
|
2026-02-14 15:26:42 +01:00
|
|
|
{ value: 'PROGRAM_TEAM', label: 'Program Team' },
|
|
|
|
|
{ value: 'USER', label: 'Specific User' },
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const ROLES = ['JURY_MEMBER', 'MENTOR', 'OBSERVER', 'APPLICANT', 'PROGRAM_ADMIN']
|
|
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
const STATE_LABELS: Record<string, string> = {
|
|
|
|
|
PENDING: 'Pending',
|
|
|
|
|
IN_PROGRESS: 'Active',
|
|
|
|
|
COMPLETED: 'Completed',
|
|
|
|
|
PASSED: 'Passed',
|
|
|
|
|
REJECTED: 'Rejected',
|
|
|
|
|
WITHDRAWN: 'Withdrawn',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const STATE_BADGE_VARIANT: Record<string, 'default' | 'success' | 'destructive' | 'secondary'> = {
|
|
|
|
|
PENDING: 'secondary',
|
|
|
|
|
IN_PROGRESS: 'default',
|
|
|
|
|
COMPLETED: 'default',
|
|
|
|
|
PASSED: 'success',
|
|
|
|
|
REJECTED: 'destructive',
|
|
|
|
|
WITHDRAWN: 'secondary',
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 15:26:42 +01:00
|
|
|
export default function MessagesPage() {
|
|
|
|
|
const [recipientType, setRecipientType] = useState<RecipientType>('ALL')
|
|
|
|
|
const [selectedRole, setSelectedRole] = useState('')
|
2026-02-19 11:11:00 +01:00
|
|
|
const [roundId, setRoundId] = useState('')
|
2026-02-14 15:26:42 +01:00
|
|
|
const [selectedProgramId, setSelectedProgramId] = useState('')
|
|
|
|
|
const [selectedUserId, setSelectedUserId] = useState('')
|
|
|
|
|
const [subject, setSubject] = useState('')
|
|
|
|
|
const [body, setBody] = useState('')
|
|
|
|
|
const [selectedTemplateId, setSelectedTemplateId] = useState('')
|
|
|
|
|
const [deliveryChannels, setDeliveryChannels] = useState<string[]>(['EMAIL', 'IN_APP'])
|
|
|
|
|
const [isScheduled, setIsScheduled] = useState(false)
|
|
|
|
|
const [scheduledAt, setScheduledAt] = useState('')
|
|
|
|
|
const [showPreview, setShowPreview] = useState(false)
|
2026-03-06 10:32:03 +01:00
|
|
|
const [excludeRejected, setExcludeRejected] = useState(true)
|
|
|
|
|
const [excludeWithdrawn, setExcludeWithdrawn] = useState(true)
|
2026-02-14 15:26:42 +01:00
|
|
|
|
|
|
|
|
const utils = trpc.useUtils()
|
|
|
|
|
|
|
|
|
|
// Fetch supporting data
|
|
|
|
|
const { data: programs } = trpc.program.list.useQuery({ includeStages: true })
|
|
|
|
|
const rounds = programs?.flatMap((p) =>
|
|
|
|
|
((p.stages ?? []) as Array<{ id: string; name: string }>).map((s: { id: string; name: string }) => ({ ...s, program: { name: p.name } }))
|
|
|
|
|
) || []
|
|
|
|
|
const { data: templates } = trpc.message.listTemplates.useQuery()
|
|
|
|
|
const { data: users } = trpc.user.list.useQuery(
|
|
|
|
|
{ page: 1, perPage: 100 },
|
|
|
|
|
{ enabled: recipientType === 'USER' }
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
// Fetch sent messages for history
|
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
|
|
|
const { data: sentMessages, isLoading: loadingSent } = trpc.message.sent.useQuery(
|
|
|
|
|
{ page: 1, pageSize: 50 },
|
|
|
|
|
{ refetchInterval: 30_000 }
|
2026-02-14 15:26:42 +01:00
|
|
|
)
|
|
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
// Compute exclude states list
|
|
|
|
|
const excludeStates = useMemo(() => {
|
|
|
|
|
const states: string[] = []
|
|
|
|
|
if (excludeRejected) states.push('REJECTED')
|
|
|
|
|
if (excludeWithdrawn) states.push('WITHDRAWN')
|
|
|
|
|
return states
|
|
|
|
|
}, [excludeRejected, excludeWithdrawn])
|
|
|
|
|
|
|
|
|
|
// Live recipient preview — fetches whenever selection changes
|
|
|
|
|
const recipientPreview = trpc.message.previewRecipients.useQuery(
|
|
|
|
|
{
|
|
|
|
|
recipientType,
|
|
|
|
|
recipientFilter: buildRecipientFilterValue(),
|
|
|
|
|
roundId: roundId || undefined,
|
|
|
|
|
excludeStates: recipientType === 'ROUND_APPLICANTS' ? excludeStates : undefined,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
enabled: recipientType === 'ROUND_APPLICANTS'
|
|
|
|
|
? !!roundId
|
|
|
|
|
: recipientType === 'ROUND_JURY'
|
|
|
|
|
? !!roundId
|
|
|
|
|
: recipientType === 'ROLE'
|
|
|
|
|
? !!selectedRole
|
|
|
|
|
: recipientType === 'USER'
|
|
|
|
|
? !!selectedUserId
|
|
|
|
|
: recipientType === 'PROGRAM_TEAM'
|
|
|
|
|
? !!selectedProgramId
|
|
|
|
|
: recipientType === 'ALL',
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-03 19:14:41 +01:00
|
|
|
const emailPreview = trpc.message.previewEmail.useQuery(
|
|
|
|
|
{ subject, body },
|
|
|
|
|
{ enabled: showPreview && subject.length > 0 && body.length > 0 }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const sendTestMutation = trpc.message.sendTest.useMutation({
|
|
|
|
|
onSuccess: (data) => toast.success(`Test email sent to ${data.to}`),
|
|
|
|
|
onError: (e) => toast.error(e.message),
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-14 15:26:42 +01:00
|
|
|
const sendMutation = trpc.message.send.useMutation({
|
|
|
|
|
onSuccess: (data) => {
|
|
|
|
|
const count = (data as Record<string, unknown>)?.recipientCount || ''
|
|
|
|
|
toast.success(`Message sent successfully${count ? ` to ${count} recipients` : ''}`)
|
|
|
|
|
resetForm()
|
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
|
|
|
utils.message.sent.invalidate()
|
2026-02-14 15:26:42 +01:00
|
|
|
},
|
|
|
|
|
onError: (e) => toast.error(e.message),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const resetForm = () => {
|
|
|
|
|
setSubject('')
|
|
|
|
|
setBody('')
|
|
|
|
|
setSelectedTemplateId('')
|
|
|
|
|
setSelectedRole('')
|
2026-02-19 11:11:00 +01:00
|
|
|
setRoundId('')
|
2026-02-14 15:26:42 +01:00
|
|
|
setSelectedProgramId('')
|
|
|
|
|
setSelectedUserId('')
|
|
|
|
|
setIsScheduled(false)
|
|
|
|
|
setScheduledAt('')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleTemplateSelect = (templateId: string) => {
|
|
|
|
|
setSelectedTemplateId(templateId)
|
|
|
|
|
if (templateId && templateId !== '__none__' && templates) {
|
|
|
|
|
const template = (templates as Array<Record<string, unknown>>).find(
|
|
|
|
|
(t) => String(t.id) === templateId
|
|
|
|
|
)
|
|
|
|
|
if (template) {
|
|
|
|
|
setSubject(String(template.subject || ''))
|
|
|
|
|
setBody(String(template.body || ''))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const toggleChannel = (channel: string) => {
|
|
|
|
|
setDeliveryChannels((prev) =>
|
|
|
|
|
prev.includes(channel)
|
|
|
|
|
? prev.filter((c) => c !== channel)
|
|
|
|
|
: [...prev, channel]
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
function buildRecipientFilterValue(): unknown {
|
2026-02-14 15:26:42 +01:00
|
|
|
switch (recipientType) {
|
|
|
|
|
case 'ROLE':
|
|
|
|
|
return selectedRole ? { role: selectedRole } : undefined
|
|
|
|
|
case 'USER':
|
|
|
|
|
return selectedUserId ? { userId: selectedUserId } : undefined
|
|
|
|
|
case 'PROGRAM_TEAM':
|
|
|
|
|
return selectedProgramId ? { programId: selectedProgramId } : undefined
|
|
|
|
|
default:
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getRecipientDescription = (): string => {
|
|
|
|
|
switch (recipientType) {
|
|
|
|
|
case 'ALL':
|
|
|
|
|
return 'All platform users'
|
|
|
|
|
case 'ROLE': {
|
|
|
|
|
const roleLabel = selectedRole ? selectedRole.replace(/_/g, ' ') : ''
|
|
|
|
|
return roleLabel ? `All ${roleLabel}s` : 'By Role (none selected)'
|
|
|
|
|
}
|
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
|
|
|
case 'ROUND_JURY': {
|
|
|
|
|
if (!roundId) return 'Stage Jury (none selected)'
|
2026-03-06 10:32:03 +01:00
|
|
|
const stage = rounds?.find((r) => r.id === roundId)
|
2026-02-14 15:26:42 +01:00
|
|
|
return stage
|
|
|
|
|
? `Jury of ${stage.program ? `${stage.program.name} - ` : ''}${stage.name}`
|
|
|
|
|
: 'Stage Jury'
|
|
|
|
|
}
|
2026-03-03 19:14:41 +01:00
|
|
|
case 'ROUND_APPLICANTS': {
|
|
|
|
|
if (!roundId) return 'Round Applicants (none selected)'
|
|
|
|
|
const appRound = rounds?.find((r) => r.id === roundId)
|
|
|
|
|
return appRound
|
|
|
|
|
? `Applicants in ${appRound.program ? `${appRound.program.name} - ` : ''}${appRound.name}`
|
|
|
|
|
: 'Round Applicants'
|
|
|
|
|
}
|
2026-02-14 15:26:42 +01:00
|
|
|
case 'PROGRAM_TEAM': {
|
|
|
|
|
if (!selectedProgramId) return 'Program Team (none selected)'
|
|
|
|
|
const program = (programs as Array<{ id: string; name: string }> | undefined)?.find(
|
|
|
|
|
(p) => p.id === selectedProgramId
|
|
|
|
|
)
|
|
|
|
|
return program ? `Team of ${program.name}` : 'Program Team'
|
|
|
|
|
}
|
|
|
|
|
case 'USER': {
|
|
|
|
|
if (!selectedUserId) return 'Specific User (none selected)'
|
|
|
|
|
const userList = (users as { users: Array<{ id: string; name: string | null; email: string }> } | undefined)?.users
|
|
|
|
|
const user = userList?.find((u) => u.id === selectedUserId)
|
|
|
|
|
return user ? (user.name || user.email) : 'Specific User'
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return 'Unknown'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
const validateForm = (): boolean => {
|
2026-02-14 15:26:42 +01:00
|
|
|
if (!subject.trim()) {
|
|
|
|
|
toast.error('Subject is required')
|
2026-03-06 10:32:03 +01:00
|
|
|
return false
|
2026-02-14 15:26:42 +01:00
|
|
|
}
|
|
|
|
|
if (!body.trim()) {
|
|
|
|
|
toast.error('Message body is required')
|
2026-03-06 10:32:03 +01:00
|
|
|
return false
|
2026-02-14 15:26:42 +01:00
|
|
|
}
|
|
|
|
|
if (deliveryChannels.length === 0) {
|
|
|
|
|
toast.error('Select at least one delivery channel')
|
2026-03-06 10:32:03 +01:00
|
|
|
return false
|
2026-02-14 15:26:42 +01:00
|
|
|
}
|
|
|
|
|
if (recipientType === 'ROLE' && !selectedRole) {
|
|
|
|
|
toast.error('Please select a role')
|
2026-03-06 10:32:03 +01:00
|
|
|
return false
|
2026-02-14 15:26:42 +01:00
|
|
|
}
|
2026-03-03 19:14:41 +01:00
|
|
|
if ((recipientType === 'ROUND_JURY' || recipientType === 'ROUND_APPLICANTS') && !roundId) {
|
2026-02-19 11:11:00 +01:00
|
|
|
toast.error('Please select a round')
|
2026-03-06 10:32:03 +01:00
|
|
|
return false
|
2026-02-14 15:26:42 +01:00
|
|
|
}
|
|
|
|
|
if (recipientType === 'PROGRAM_TEAM' && !selectedProgramId) {
|
|
|
|
|
toast.error('Please select a program')
|
2026-03-06 10:32:03 +01:00
|
|
|
return false
|
2026-02-14 15:26:42 +01:00
|
|
|
}
|
|
|
|
|
if (recipientType === 'USER' && !selectedUserId) {
|
|
|
|
|
toast.error('Please select a user')
|
2026-03-06 10:32:03 +01:00
|
|
|
return false
|
2026-02-14 15:26:42 +01:00
|
|
|
}
|
2026-03-06 10:32:03 +01:00
|
|
|
return true
|
|
|
|
|
}
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
const handlePreview = () => {
|
|
|
|
|
if (!validateForm()) return
|
2026-02-14 15:26:42 +01:00
|
|
|
setShowPreview(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleActualSend = () => {
|
|
|
|
|
sendMutation.mutate({
|
|
|
|
|
recipientType,
|
2026-03-06 10:32:03 +01:00
|
|
|
recipientFilter: buildRecipientFilterValue(),
|
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
|
|
|
roundId: roundId || undefined,
|
2026-03-06 10:32:03 +01:00
|
|
|
excludeStates: recipientType === 'ROUND_APPLICANTS' ? excludeStates : undefined,
|
2026-02-14 15:26:42 +01:00
|
|
|
subject: subject.trim(),
|
|
|
|
|
body: body.trim(),
|
|
|
|
|
deliveryChannels,
|
|
|
|
|
scheduledAt: isScheduled && scheduledAt ? new Date(scheduledAt).toISOString() : undefined,
|
|
|
|
|
templateId: selectedTemplateId && selectedTemplateId !== '__none__' ? selectedTemplateId : undefined,
|
|
|
|
|
})
|
|
|
|
|
setShowPreview(false)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
const preview = recipientPreview.data
|
|
|
|
|
|
2026-02-14 15:26:42 +01:00
|
|
|
return (
|
|
|
|
|
<div className="space-y-6">
|
|
|
|
|
{/* Header */}
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 className="text-2xl font-semibold tracking-tight">Communication Hub</h1>
|
|
|
|
|
<p className="text-muted-foreground">
|
|
|
|
|
Send messages and notifications to platform users
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<Button variant="outline" asChild>
|
|
|
|
|
<Link href="/admin/messages/templates">
|
|
|
|
|
<LayoutTemplate className="mr-2 h-4 w-4" />
|
|
|
|
|
Templates
|
|
|
|
|
</Link>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Tabs defaultValue="compose">
|
|
|
|
|
<TabsList>
|
|
|
|
|
<TabsTrigger value="compose">
|
|
|
|
|
<Send className="mr-2 h-4 w-4" />
|
|
|
|
|
Compose
|
|
|
|
|
</TabsTrigger>
|
|
|
|
|
<TabsTrigger value="history">
|
|
|
|
|
<Inbox className="mr-2 h-4 w-4" />
|
|
|
|
|
Sent History
|
|
|
|
|
</TabsTrigger>
|
|
|
|
|
</TabsList>
|
|
|
|
|
|
|
|
|
|
<TabsContent value="compose" className="space-y-4 mt-4">
|
2026-03-06 10:32:03 +01:00
|
|
|
<div className="grid gap-4 lg:grid-cols-3">
|
|
|
|
|
{/* Left: Compose form */}
|
|
|
|
|
<div className="lg:col-span-2 space-y-4">
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle className="text-lg">Compose Message</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
Send a message via email, in-app notifications, or both
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent className="space-y-4">
|
|
|
|
|
{/* Recipient type */}
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label>Recipient Type</Label>
|
|
|
|
|
<Select
|
|
|
|
|
value={recipientType}
|
|
|
|
|
onValueChange={(v) => {
|
|
|
|
|
setRecipientType(v as RecipientType)
|
|
|
|
|
setSelectedRole('')
|
|
|
|
|
setRoundId('')
|
|
|
|
|
setSelectedProgramId('')
|
|
|
|
|
setSelectedUserId('')
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{RECIPIENT_TYPE_OPTIONS.map((opt) => (
|
|
|
|
|
<SelectItem key={opt.value} value={opt.value}>
|
|
|
|
|
{opt.label}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
{/* Conditional sub-filters */}
|
|
|
|
|
{recipientType === 'ROLE' && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label>Select Role</Label>
|
|
|
|
|
<Select value={selectedRole} onValueChange={setSelectedRole}>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue placeholder="Choose a role..." />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{ROLES.map((role) => (
|
|
|
|
|
<SelectItem key={role} value={role}>
|
|
|
|
|
{role.replace(/_/g, ' ')}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
{(recipientType === 'ROUND_JURY' || recipientType === 'ROUND_APPLICANTS') && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label>Select Round</Label>
|
|
|
|
|
<Select value={roundId} onValueChange={setRoundId}>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue placeholder="Choose a round..." />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{rounds?.map((round) => (
|
|
|
|
|
<SelectItem key={round.id} value={round.id}>
|
|
|
|
|
{round.program ? `${round.program.name} - ${round.name}` : round.name}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
{/* Exclude filters for Round Applicants */}
|
|
|
|
|
{recipientType === 'ROUND_APPLICANTS' && roundId && (
|
|
|
|
|
<div className="rounded-lg border p-3 space-y-2">
|
|
|
|
|
<Label className="text-sm font-medium">Exclude Project States</Label>
|
|
|
|
|
<div className="flex flex-wrap gap-4">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Checkbox
|
|
|
|
|
id="exclude-rejected"
|
|
|
|
|
checked={excludeRejected}
|
|
|
|
|
onCheckedChange={(v) => setExcludeRejected(!!v)}
|
|
|
|
|
/>
|
|
|
|
|
<label htmlFor="exclude-rejected" className="text-sm cursor-pointer flex items-center gap-1.5">
|
|
|
|
|
<XCircle className="h-3.5 w-3.5 text-destructive" />
|
|
|
|
|
Exclude Rejected
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Checkbox
|
|
|
|
|
id="exclude-withdrawn"
|
|
|
|
|
checked={excludeWithdrawn}
|
|
|
|
|
onCheckedChange={(v) => setExcludeWithdrawn(!!v)}
|
|
|
|
|
/>
|
|
|
|
|
<label htmlFor="exclude-withdrawn" className="text-sm cursor-pointer flex items-center gap-1.5">
|
|
|
|
|
<XCircle className="h-3.5 w-3.5 text-muted-foreground" />
|
|
|
|
|
Exclude Withdrawn
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
{recipientType === 'PROGRAM_TEAM' && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label>Select Program</Label>
|
|
|
|
|
<Select value={selectedProgramId} onValueChange={setSelectedProgramId}>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue placeholder="Choose a program..." />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{(programs as Array<{ id: string; name: string }> | undefined)?.map((prog) => (
|
|
|
|
|
<SelectItem key={prog.id} value={prog.id}>
|
|
|
|
|
{prog.name}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
{recipientType === 'USER' && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label>Select User</Label>
|
|
|
|
|
<Select value={selectedUserId} onValueChange={setSelectedUserId}>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue placeholder="Choose a user..." />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{(() => {
|
|
|
|
|
const userList = (users as { users: Array<{ id: string; name: string | null; email: string; role: string }> } | undefined)?.users
|
|
|
|
|
if (!userList) return null
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
const grouped = userList.reduce<Record<string, typeof userList>>((acc, u) => {
|
|
|
|
|
const role = u.role || 'OTHER'
|
|
|
|
|
if (!acc[role]) acc[role] = []
|
|
|
|
|
acc[role].push(u)
|
|
|
|
|
return acc
|
|
|
|
|
}, {})
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
const roleLabels: Record<string, string> = {
|
|
|
|
|
SUPER_ADMIN: 'Super Admins',
|
|
|
|
|
PROGRAM_ADMIN: 'Program Admins',
|
|
|
|
|
JURY_MEMBER: 'Jury Members',
|
|
|
|
|
MENTOR: 'Mentors',
|
|
|
|
|
OBSERVER: 'Observers',
|
|
|
|
|
APPLICANT: 'Applicants',
|
|
|
|
|
OTHER: 'Other',
|
|
|
|
|
}
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
const roleOrder = ['SUPER_ADMIN', 'PROGRAM_ADMIN', 'JURY_MEMBER', 'MENTOR', 'OBSERVER', 'APPLICANT', 'OTHER']
|
|
|
|
|
|
|
|
|
|
return roleOrder
|
|
|
|
|
.filter((role) => grouped[role]?.length)
|
|
|
|
|
.map((role) => (
|
|
|
|
|
<SelectGroup key={role}>
|
|
|
|
|
<SelectLabel>{roleLabels[role] || role}</SelectLabel>
|
|
|
|
|
{grouped[role]
|
|
|
|
|
.sort((a, b) => (a.name || a.email).localeCompare(b.name || b.email))
|
|
|
|
|
.map((u) => (
|
|
|
|
|
<SelectItem key={u.id} value={u.id}>
|
|
|
|
|
{u.name || u.email}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectGroup>
|
|
|
|
|
))
|
|
|
|
|
})()}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
{recipientType === 'ALL' && (
|
|
|
|
|
<div className="flex items-center gap-2 rounded-lg bg-amber-500/10 p-3 text-amber-700">
|
|
|
|
|
<AlertCircle className="h-4 w-4 shrink-0" />
|
|
|
|
|
<p className="text-sm">
|
|
|
|
|
This message will be sent to all platform users.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Template selector */}
|
|
|
|
|
{templates && (templates as unknown[]).length > 0 && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label>Template (optional)</Label>
|
|
|
|
|
<Select value={selectedTemplateId} onValueChange={handleTemplateSelect}>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue placeholder="Load from template..." />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
<SelectItem value="__none__">No template</SelectItem>
|
|
|
|
|
{(templates as Array<Record<string, unknown>>).map((t) => (
|
|
|
|
|
<SelectItem key={String(t.id)} value={String(t.id)}>
|
|
|
|
|
{String(t.name)}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Subject */}
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label>Subject</Label>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="Message subject..."
|
|
|
|
|
value={subject}
|
|
|
|
|
onChange={(e) => setSubject(e.target.value)}
|
2026-02-14 15:26:42 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
2026-03-06 10:32:03 +01:00
|
|
|
|
|
|
|
|
{/* Body */}
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<Label>Message Body</Label>
|
|
|
|
|
<span className="text-xs text-muted-foreground">
|
|
|
|
|
Variables: {'{{projectName}}'}, {'{{userName}}'}, {'{{deadline}}'}, {'{{roundName}}'}, {'{{programName}}'}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<Textarea
|
|
|
|
|
placeholder="Write your message..."
|
|
|
|
|
value={body}
|
|
|
|
|
onChange={(e) => setBody(e.target.value)}
|
|
|
|
|
rows={6}
|
2026-02-14 15:26:42 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
{/* Delivery channels */}
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label>Delivery Channels</Label>
|
|
|
|
|
<div className="flex items-center gap-6">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Checkbox
|
|
|
|
|
id="channel-email"
|
|
|
|
|
checked={deliveryChannels.includes('EMAIL')}
|
|
|
|
|
onCheckedChange={() => toggleChannel('EMAIL')}
|
|
|
|
|
/>
|
|
|
|
|
<label htmlFor="channel-email" className="text-sm cursor-pointer flex items-center gap-1">
|
|
|
|
|
<Mail className="h-3 w-3" />
|
|
|
|
|
Email
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Checkbox
|
|
|
|
|
id="channel-inapp"
|
|
|
|
|
checked={deliveryChannels.includes('IN_APP')}
|
|
|
|
|
onCheckedChange={() => toggleChannel('IN_APP')}
|
|
|
|
|
/>
|
|
|
|
|
<label htmlFor="channel-inapp" className="text-sm cursor-pointer flex items-center gap-1">
|
|
|
|
|
<Bell className="h-3 w-3" />
|
|
|
|
|
In-App
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-14 15:26:42 +01:00
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
{/* Schedule */}
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Switch
|
|
|
|
|
id="schedule-toggle"
|
|
|
|
|
checked={isScheduled}
|
|
|
|
|
onCheckedChange={setIsScheduled}
|
|
|
|
|
/>
|
|
|
|
|
<label htmlFor="schedule-toggle" className="text-sm cursor-pointer flex items-center gap-1">
|
|
|
|
|
<Clock className="h-3 w-3" />
|
|
|
|
|
Schedule for later
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
{isScheduled && (
|
|
|
|
|
<Input
|
|
|
|
|
type="datetime-local"
|
|
|
|
|
value={scheduledAt}
|
|
|
|
|
onChange={(e) => setScheduledAt(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Preview button */}
|
|
|
|
|
<div className="flex justify-end">
|
|
|
|
|
<Button onClick={handlePreview} disabled={sendMutation.isPending}>
|
|
|
|
|
{sendMutation.isPending ? (
|
|
|
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
|
|
|
) : (
|
|
|
|
|
<Eye className="mr-2 h-4 w-4" />
|
|
|
|
|
)}
|
|
|
|
|
{isScheduled ? 'Preview & Schedule' : 'Preview & Send'}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Right sidebar: Recipient Summary */}
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader className="pb-3">
|
|
|
|
|
<CardTitle className="text-sm flex items-center gap-2">
|
|
|
|
|
<Users className="h-4 w-4 text-blue-500" />
|
|
|
|
|
Recipient Summary
|
|
|
|
|
</CardTitle>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
{recipientPreview.isLoading ? (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Skeleton className="h-5 w-32" />
|
|
|
|
|
<Skeleton className="h-4 w-24" />
|
|
|
|
|
</div>
|
|
|
|
|
) : preview ? (
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<div className="text-sm text-muted-foreground">
|
|
|
|
|
{getRecipientDescription()}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Stats */}
|
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
|
|
|
{preview.totalProjects > 0 && (
|
|
|
|
|
<div className="rounded-lg border p-3 text-center">
|
|
|
|
|
<div className="flex items-center justify-center gap-1.5 mb-1">
|
|
|
|
|
<FolderOpen className="h-3.5 w-3.5 text-muted-foreground" />
|
|
|
|
|
<span className="text-xs text-muted-foreground">Projects</span>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-xl font-bold tabular-nums">{preview.totalProjects}</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className={`rounded-lg border p-3 text-center ${preview.totalProjects > 0 ? '' : 'col-span-2'}`}>
|
|
|
|
|
<div className="flex items-center justify-center gap-1.5 mb-1">
|
|
|
|
|
<Users className="h-3.5 w-3.5 text-muted-foreground" />
|
|
|
|
|
<span className="text-xs text-muted-foreground">Recipients</span>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-xl font-bold tabular-nums">{preview.totalApplicants}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* State breakdown for Round Applicants */}
|
|
|
|
|
{recipientType === 'ROUND_APPLICANTS' && Object.keys(preview.stateBreakdown).length > 0 && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
|
|
|
|
|
Projects by Status
|
|
|
|
|
</p>
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
{Object.entries(preview.stateBreakdown)
|
|
|
|
|
.sort(([a], [b]) => {
|
|
|
|
|
const order = ['IN_PROGRESS', 'PENDING', 'COMPLETED', 'PASSED', 'REJECTED', 'WITHDRAWN']
|
|
|
|
|
return order.indexOf(a) - order.indexOf(b)
|
|
|
|
|
})
|
|
|
|
|
.map(([state, count]) => {
|
|
|
|
|
const isExcluded = excludeStates.includes(state)
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={state}
|
|
|
|
|
className={`flex items-center justify-between rounded-md px-2.5 py-1.5 text-sm ${
|
|
|
|
|
isExcluded ? 'bg-muted/50 opacity-50 line-through' : 'bg-muted/30'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Badge
|
|
|
|
|
variant={STATE_BADGE_VARIANT[state] || 'secondary'}
|
|
|
|
|
className="text-[10px] px-1.5 py-0"
|
|
|
|
|
>
|
|
|
|
|
{STATE_LABELS[state] || state}
|
|
|
|
|
</Badge>
|
|
|
|
|
{isExcluded && (
|
|
|
|
|
<span className="text-[10px] text-muted-foreground">(excluded)</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-semibold tabular-nums">{count}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Included vs excluded summary */}
|
|
|
|
|
{excludeStates.length > 0 && (
|
|
|
|
|
<div className="rounded-lg bg-blue-500/5 border border-blue-200/50 p-2.5 mt-2">
|
|
|
|
|
<p className="text-xs text-blue-700">
|
|
|
|
|
Sending to <span className="font-semibold">{preview.totalApplicants}</span> applicants
|
|
|
|
|
{' '}across{' '}
|
|
|
|
|
<span className="font-semibold">
|
|
|
|
|
{preview.totalProjects - Object.entries(preview.stateBreakdown)
|
|
|
|
|
.filter(([s]) => excludeStates.includes(s))
|
|
|
|
|
.reduce((sum, [, c]) => sum + c, 0)}
|
|
|
|
|
</span>{' '}
|
|
|
|
|
projects (excluding{' '}
|
|
|
|
|
{excludeStates.map((s) => STATE_LABELS[s] || s).join(' & ').toLowerCase()}).
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-02-14 15:26:42 +01:00
|
|
|
) : (
|
2026-03-06 10:32:03 +01:00
|
|
|
<p className="text-sm text-muted-foreground">
|
|
|
|
|
Select a recipient type{recipientType !== 'ALL' ? ' and filter' : ''} to see a summary.
|
|
|
|
|
</p>
|
2026-02-14 15:26:42 +01:00
|
|
|
)}
|
2026-03-06 10:32:03 +01:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-14 15:26:42 +01:00
|
|
|
</TabsContent>
|
|
|
|
|
|
|
|
|
|
<TabsContent value="history" className="mt-4">
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle className="text-lg">Sent Messages</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
Recent messages sent through the platform
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
{loadingSent ? (
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
{[1, 2, 3].map((i) => (
|
|
|
|
|
<div key={i} className="flex items-center gap-4">
|
|
|
|
|
<Skeleton className="h-4 w-48" />
|
|
|
|
|
<Skeleton className="h-6 w-24" />
|
|
|
|
|
<Skeleton className="h-4 w-32 ml-auto" />
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
) : sentMessages && sentMessages.items.length > 0 ? (
|
|
|
|
|
<Table>
|
|
|
|
|
<TableHeader>
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableHead>Subject</TableHead>
|
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
|
|
|
<TableHead className="hidden md:table-cell">Recipients</TableHead>
|
|
|
|
|
<TableHead className="hidden md:table-cell">Channels</TableHead>
|
2026-02-14 15:26:42 +01:00
|
|
|
<TableHead className="hidden lg:table-cell">Status</TableHead>
|
|
|
|
|
<TableHead className="text-right">Date</TableHead>
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
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
|
|
|
{sentMessages.items.map((msg: any) => {
|
|
|
|
|
const channels = (msg.deliveryChannels as string[]) || []
|
|
|
|
|
const recipientCount = msg._count?.recipients ?? 0
|
|
|
|
|
const isSent = !!msg.sentAt
|
2026-02-14 15:26:42 +01:00
|
|
|
|
|
|
|
|
return (
|
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
|
|
|
<TableRow key={msg.id}>
|
2026-02-14 15:26:42 +01:00
|
|
|
<TableCell>
|
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
|
|
|
<span className="font-medium">
|
|
|
|
|
{msg.subject || 'No subject'}
|
|
|
|
|
</span>
|
2026-02-14 15:26:42 +01:00
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="hidden md:table-cell text-sm text-muted-foreground">
|
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
|
|
|
{msg.recipientType === 'ALL'
|
|
|
|
|
? 'All users'
|
|
|
|
|
: msg.recipientType === 'ROLE'
|
|
|
|
|
? `By role`
|
|
|
|
|
: msg.recipientType === 'ROUND_JURY'
|
|
|
|
|
? 'Round jury'
|
2026-03-06 10:32:03 +01:00
|
|
|
: msg.recipientType === 'ROUND_APPLICANTS'
|
|
|
|
|
? 'Round applicants'
|
|
|
|
|
: msg.recipientType === 'USER'
|
|
|
|
|
? `${recipientCount || 1} user${recipientCount > 1 ? 's' : ''}`
|
|
|
|
|
: msg.recipientType}
|
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
|
|
|
{recipientCount > 0 && ` (${recipientCount})`}
|
2026-02-14 15:26:42 +01:00
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="hidden md:table-cell">
|
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
|
|
|
<div className="flex gap-1">
|
|
|
|
|
{channels.includes('EMAIL') && (
|
|
|
|
|
<Badge variant="outline" className="text-xs">
|
|
|
|
|
<Mail className="mr-1 h-3 w-3" />Email
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
{channels.includes('IN_APP') && (
|
|
|
|
|
<Badge variant="outline" className="text-xs">
|
|
|
|
|
<Bell className="mr-1 h-3 w-3" />In-App
|
|
|
|
|
</Badge>
|
2026-02-14 15:26:42 +01:00
|
|
|
)}
|
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
|
|
|
</div>
|
2026-02-14 15:26:42 +01:00
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="hidden lg:table-cell">
|
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
|
|
|
{isSent ? (
|
2026-02-14 15:26:42 +01:00
|
|
|
<Badge variant="secondary" className="text-xs">
|
|
|
|
|
<CheckCircle2 className="mr-1 h-3 w-3" />
|
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
|
|
|
Sent
|
2026-02-14 15:26:42 +01:00
|
|
|
</Badge>
|
2026-02-19 11:11:00 +01:00
|
|
|
) : msg.scheduledAt ? (
|
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
|
|
|
<Badge variant="default" className="text-xs">
|
|
|
|
|
<Clock className="mr-1 h-3 w-3" />
|
|
|
|
|
Scheduled
|
|
|
|
|
</Badge>
|
2026-02-19 11:11:00 +01:00
|
|
|
) : (
|
|
|
|
|
<Badge variant="outline" className="text-xs">
|
|
|
|
|
Draft
|
|
|
|
|
</Badge>
|
2026-02-14 15:26:42 +01:00
|
|
|
)}
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="text-right text-sm text-muted-foreground">
|
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
|
|
|
{msg.sentAt
|
|
|
|
|
? formatDate(msg.sentAt)
|
|
|
|
|
: msg.scheduledAt
|
|
|
|
|
? formatDate(msg.scheduledAt)
|
|
|
|
|
: ''}
|
2026-02-14 15:26:42 +01:00
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex flex-col items-center justify-center py-12 text-center">
|
|
|
|
|
<Inbox className="h-12 w-12 text-muted-foreground/50" />
|
|
|
|
|
<p className="mt-2 font-medium">No messages yet</p>
|
|
|
|
|
<p className="text-sm text-muted-foreground">
|
|
|
|
|
Sent messages will appear here.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</TabsContent>
|
|
|
|
|
</Tabs>
|
|
|
|
|
|
2026-03-06 10:32:03 +01:00
|
|
|
{/* Preview & Send Dialog */}
|
2026-02-14 15:26:42 +01:00
|
|
|
<Dialog open={showPreview} onOpenChange={setShowPreview}>
|
2026-03-06 10:32:03 +01:00
|
|
|
<DialogContent className="max-w-3xl max-h-[90vh] overflow-y-auto">
|
2026-02-14 15:26:42 +01:00
|
|
|
<DialogHeader>
|
2026-03-06 10:32:03 +01:00
|
|
|
<DialogTitle className="text-xl">Review & Send</DialogTitle>
|
|
|
|
|
<DialogDescription>Verify everything looks correct before sending</DialogDescription>
|
2026-02-14 15:26:42 +01:00
|
|
|
</DialogHeader>
|
2026-03-06 10:32:03 +01:00
|
|
|
|
|
|
|
|
<div className="grid gap-6 md:grid-cols-5">
|
|
|
|
|
{/* Left: Message details */}
|
|
|
|
|
<div className="md:col-span-3 space-y-4">
|
|
|
|
|
<div>
|
|
|
|
|
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Subject</p>
|
|
|
|
|
<p className="text-base font-semibold mt-1">{subject}</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider mb-2">Email Preview</p>
|
|
|
|
|
<div className="rounded-lg border overflow-hidden bg-gray-50">
|
|
|
|
|
{emailPreview.data?.html ? (
|
|
|
|
|
<iframe
|
|
|
|
|
srcDoc={emailPreview.data.html}
|
|
|
|
|
sandbox="allow-same-origin"
|
|
|
|
|
className="w-full h-[400px] border-0"
|
|
|
|
|
title="Email Preview"
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="p-4">
|
|
|
|
|
<p className="text-sm whitespace-pre-wrap">{body}</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-14 15:26:42 +01:00
|
|
|
</div>
|
2026-03-06 10:32:03 +01:00
|
|
|
|
|
|
|
|
{/* Right: Recipient & delivery summary */}
|
|
|
|
|
<div className="md:col-span-2 space-y-4">
|
|
|
|
|
<div className="rounded-lg border p-4 space-y-3">
|
|
|
|
|
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Recipients</p>
|
|
|
|
|
<p className="text-sm font-medium">{getRecipientDescription()}</p>
|
|
|
|
|
|
|
|
|
|
{preview && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
{preview.totalProjects > 0 && (
|
|
|
|
|
<div className="flex items-center justify-between text-sm">
|
|
|
|
|
<span className="text-muted-foreground flex items-center gap-1.5">
|
|
|
|
|
<FolderOpen className="h-3.5 w-3.5" />
|
|
|
|
|
Projects
|
|
|
|
|
</span>
|
|
|
|
|
<span className="font-semibold tabular-nums">
|
|
|
|
|
{preview.totalProjects - Object.entries(preview.stateBreakdown)
|
|
|
|
|
.filter(([s]) => excludeStates.includes(s))
|
|
|
|
|
.reduce((sum, [, c]) => sum + c, 0)}
|
|
|
|
|
{excludeStates.length > 0 && (
|
|
|
|
|
<span className="text-muted-foreground font-normal"> / {preview.totalProjects}</span>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="flex items-center justify-between text-sm">
|
|
|
|
|
<span className="text-muted-foreground flex items-center gap-1.5">
|
|
|
|
|
<Users className="h-3.5 w-3.5" />
|
|
|
|
|
Applicants
|
|
|
|
|
</span>
|
|
|
|
|
<span className="font-semibold tabular-nums">{preview.totalApplicants}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* State breakdown in preview */}
|
|
|
|
|
{recipientType === 'ROUND_APPLICANTS' && Object.keys(preview.stateBreakdown).length > 0 && (
|
|
|
|
|
<div className="pt-2 border-t space-y-1">
|
|
|
|
|
{Object.entries(preview.stateBreakdown)
|
|
|
|
|
.sort(([a], [b]) => {
|
|
|
|
|
const order = ['IN_PROGRESS', 'PENDING', 'COMPLETED', 'PASSED', 'REJECTED', 'WITHDRAWN']
|
|
|
|
|
return order.indexOf(a) - order.indexOf(b)
|
|
|
|
|
})
|
|
|
|
|
.map(([state, count]) => {
|
|
|
|
|
const isExcluded = excludeStates.includes(state)
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={state}
|
|
|
|
|
className={`flex items-center justify-between text-xs ${isExcluded ? 'opacity-40 line-through' : ''}`}
|
|
|
|
|
>
|
|
|
|
|
<Badge variant={STATE_BADGE_VARIANT[state] || 'secondary'} className="text-[10px] px-1.5 py-0">
|
|
|
|
|
{STATE_LABELS[state] || state}
|
|
|
|
|
</Badge>
|
|
|
|
|
<span className="tabular-nums">{count} projects</span>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-03-03 19:14:41 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-14 15:26:42 +01:00
|
|
|
</div>
|
2026-03-06 10:32:03 +01:00
|
|
|
|
|
|
|
|
<div className="rounded-lg border p-4 space-y-2">
|
|
|
|
|
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Delivery</p>
|
|
|
|
|
<div className="flex flex-wrap gap-1.5">
|
|
|
|
|
{deliveryChannels.includes('EMAIL') && (
|
|
|
|
|
<Badge variant="outline" className="text-xs">
|
|
|
|
|
<Mail className="mr-1 h-3 w-3" />
|
|
|
|
|
Email
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
{deliveryChannels.includes('IN_APP') && (
|
|
|
|
|
<Badge variant="outline" className="text-xs">
|
|
|
|
|
<Bell className="mr-1 h-3 w-3" />
|
|
|
|
|
In-App
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{isScheduled && scheduledAt && (
|
|
|
|
|
<div className="flex items-center gap-1.5 text-sm text-muted-foreground mt-1">
|
|
|
|
|
<Clock className="h-3.5 w-3.5" />
|
|
|
|
|
Scheduled: {formatDate(new Date(scheduledAt))}
|
|
|
|
|
</div>
|
2026-02-14 15:26:42 +01:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-06 10:32:03 +01:00
|
|
|
|
|
|
|
|
<DialogFooter className="flex-col sm:flex-row gap-2 mt-4 border-t pt-4">
|
2026-03-03 19:14:41 +01:00
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => sendTestMutation.mutate({ subject, body })}
|
|
|
|
|
disabled={sendTestMutation.isPending}
|
|
|
|
|
className="sm:mr-auto"
|
|
|
|
|
>
|
|
|
|
|
{sendTestMutation.isPending ? (
|
|
|
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
|
|
|
) : (
|
|
|
|
|
<Mail className="mr-2 h-4 w-4" />
|
|
|
|
|
)}
|
|
|
|
|
Send Test to Me
|
|
|
|
|
</Button>
|
2026-02-14 15:26:42 +01:00
|
|
|
<Button variant="outline" onClick={() => setShowPreview(false)}>
|
2026-03-06 10:32:03 +01:00
|
|
|
Back to Edit
|
2026-02-14 15:26:42 +01:00
|
|
|
</Button>
|
2026-03-06 10:32:03 +01:00
|
|
|
<Button onClick={handleActualSend} disabled={sendMutation.isPending} size="lg">
|
2026-02-14 15:26:42 +01:00
|
|
|
{sendMutation.isPending ? (
|
|
|
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
|
|
|
) : (
|
|
|
|
|
<Send className="mr-2 h-4 w-4" />
|
|
|
|
|
)}
|
2026-03-06 10:32:03 +01:00
|
|
|
{isScheduled ? 'Confirm & Schedule' : `Send to ${preview?.totalApplicants ?? '...'} Recipients`}
|
2026-02-14 15:26:42 +01:00
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|