Fix jury reminders, add notify jurors button, fix checkbox borders, widen assignment modal
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m32s
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m32s
- Send Reminders button now works: added sendManualReminders() that bypasses cron-specific window/deadline/dedup guards so admin can send immediately - Added Notify Jurors button that sends direct BATCH_ASSIGNED emails to all jurors with assignments (not dependent on NotificationEmailSetting config) - Fixed checkbox component: default border is now neutral grey (border-input), red border (border-primary) only applied when checked - Widened Add Assignment dialog from max-w-2xl to max-w-3xl to prevent overflow Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,7 @@ import {
|
|||||||
ShieldAlert,
|
ShieldAlert,
|
||||||
Eye,
|
Eye,
|
||||||
Pencil,
|
Pencil,
|
||||||
|
Mail,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import {
|
import {
|
||||||
Command,
|
Command,
|
||||||
@@ -1784,9 +1785,10 @@ export default function RoundDetailPage() {
|
|||||||
<ScoreDistribution roundId={roundId} />
|
<ScoreDistribution roundId={roundId} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Actions: Send Reminders + Export */}
|
{/* Actions: Send Reminders + Notify + Export */}
|
||||||
<div className="flex flex-wrap items-center gap-3">
|
<div className="flex flex-wrap items-center gap-3">
|
||||||
<SendRemindersButton roundId={roundId} />
|
<SendRemindersButton roundId={roundId} />
|
||||||
|
<NotifyJurorsButton roundId={roundId} />
|
||||||
<Button variant="outline" size="sm" onClick={() => setExportOpen(true)}>
|
<Button variant="outline" size="sm" onClick={() => setExportOpen(true)}>
|
||||||
<Download className="h-4 w-4 mr-1.5" />
|
<Download className="h-4 w-4 mr-1.5" />
|
||||||
Export Evaluations
|
Export Evaluations
|
||||||
@@ -2356,6 +2358,48 @@ function SendRemindersButton({ roundId }: { roundId: string }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Notify Jurors of Assignments Button ──────────────────────────────────
|
||||||
|
|
||||||
|
function NotifyJurorsButton({ roundId }: { roundId: string }) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const mutation = trpc.assignment.notifyJurorsOfAssignments.useMutation({
|
||||||
|
onSuccess: (data) => {
|
||||||
|
toast.success(`Notified ${data.jurorCount} juror(s) — ${data.emailsSent} email(s) sent`)
|
||||||
|
setOpen(false)
|
||||||
|
},
|
||||||
|
onError: (err) => toast.error(err.message),
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => setOpen(true)}>
|
||||||
|
<Mail className="h-4 w-4 mr-1.5" />
|
||||||
|
Notify Jurors
|
||||||
|
</Button>
|
||||||
|
<AlertDialog open={open} onOpenChange={setOpen}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Notify jurors of their assignments?</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This will send an email to every juror assigned to this round, reminding them of how many projects they need to evaluate.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={() => mutation.mutate({ roundId })}
|
||||||
|
disabled={mutation.isPending}
|
||||||
|
>
|
||||||
|
{mutation.isPending && <Loader2 className="h-4 w-4 mr-1.5 animate-spin" />}
|
||||||
|
Notify Jurors
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// ── Export Evaluations Dialog ─────────────────────────────────────────────
|
// ── Export Evaluations Dialog ─────────────────────────────────────────────
|
||||||
|
|
||||||
function ExportEvaluationsDialog({
|
function ExportEvaluationsDialog({
|
||||||
@@ -2640,7 +2684,7 @@ function IndividualAssignmentsTable({
|
|||||||
if (!open) resetDialog()
|
if (!open) resetDialog()
|
||||||
else setAddDialogOpen(true)
|
else setAddDialogOpen(true)
|
||||||
}}>
|
}}>
|
||||||
<DialogContent className="sm:max-w-[540px]">
|
<DialogContent className="max-w-3xl">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Add Assignment</DialogTitle>
|
<DialogTitle>Add Assignment</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
@@ -2674,7 +2718,7 @@ function IndividualAssignmentsTable({
|
|||||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-[480px] p-0" align="start">
|
<PopoverContent className="w-[var(--radix-popover-trigger-width)] p-0" align="start">
|
||||||
<Command>
|
<Command>
|
||||||
<CommandInput placeholder="Search by name or email..." />
|
<CommandInput placeholder="Search by name or email..." />
|
||||||
<CommandList>
|
<CommandList>
|
||||||
@@ -2775,7 +2819,7 @@ function IndividualAssignmentsTable({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Project checklist */}
|
{/* Project checklist */}
|
||||||
<ScrollArea className="h-[240px] rounded-md border">
|
<ScrollArea className="h-[320px] rounded-md border">
|
||||||
<div className="p-2 space-y-0.5">
|
<div className="p-2 space-y-0.5">
|
||||||
{!selectedJurorId ? (
|
{!selectedJurorId ? (
|
||||||
<p className="text-sm text-muted-foreground text-center py-8">
|
<p className="text-sm text-muted-foreground text-center py-8">
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const Checkbox = React.forwardRef<
|
|||||||
<CheckboxPrimitive.Root
|
<CheckboxPrimitive.Root
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
'peer h-4 w-4 shrink-0 rounded-xs border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground',
|
'peer h-4 w-4 shrink-0 rounded-xs border border-input ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=checked]:border-primary',
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
NotificationTypes,
|
NotificationTypes,
|
||||||
} from '../services/in-app-notification'
|
} from '../services/in-app-notification'
|
||||||
import { logAudit } from '@/server/utils/audit'
|
import { logAudit } from '@/server/utils/audit'
|
||||||
|
import { sendStyledNotificationEmail } from '@/lib/email'
|
||||||
|
|
||||||
async function runAIAssignmentJob(jobId: string, roundId: string, userId: string) {
|
async function runAIAssignmentJob(jobId: string, roundId: string, userId: string) {
|
||||||
try {
|
try {
|
||||||
@@ -1357,4 +1358,115 @@ export const assignmentRouter = router({
|
|||||||
createdAt: job.createdAt,
|
createdAt: job.createdAt,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify all jurors of their current assignments for a round (admin only).
|
||||||
|
* Sends both in-app notifications AND direct emails to each juror.
|
||||||
|
*/
|
||||||
|
notifyJurorsOfAssignments: adminProcedure
|
||||||
|
.input(z.object({ roundId: z.string() }))
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const round = await ctx.prisma.round.findUniqueOrThrow({
|
||||||
|
where: { id: input.roundId },
|
||||||
|
select: { name: true, windowCloseAt: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
// Get all assignments grouped by user
|
||||||
|
const assignments = await ctx.prisma.assignment.findMany({
|
||||||
|
where: { roundId: input.roundId },
|
||||||
|
select: { userId: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (assignments.length === 0) {
|
||||||
|
return { sent: 0, jurorCount: 0, emailsSent: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count assignments per user
|
||||||
|
const userCounts: Record<string, number> = {}
|
||||||
|
for (const a of assignments) {
|
||||||
|
userCounts[a.userId] = (userCounts[a.userId] || 0) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
const deadline = round.windowCloseAt
|
||||||
|
? new Date(round.windowCloseAt).toLocaleDateString('en-US', {
|
||||||
|
weekday: 'long',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
})
|
||||||
|
: undefined
|
||||||
|
|
||||||
|
// Create in-app notifications grouped by project count
|
||||||
|
const usersByProjectCount = new Map<number, string[]>()
|
||||||
|
for (const [userId, projectCount] of Object.entries(userCounts)) {
|
||||||
|
const existing = usersByProjectCount.get(projectCount) || []
|
||||||
|
existing.push(userId)
|
||||||
|
usersByProjectCount.set(projectCount, existing)
|
||||||
|
}
|
||||||
|
|
||||||
|
let totalSent = 0
|
||||||
|
for (const [projectCount, userIds] of usersByProjectCount) {
|
||||||
|
if (userIds.length === 0) continue
|
||||||
|
await createBulkNotifications({
|
||||||
|
userIds,
|
||||||
|
type: NotificationTypes.BATCH_ASSIGNED,
|
||||||
|
title: `${projectCount} Projects Assigned`,
|
||||||
|
message: `You have been assigned ${projectCount} project${projectCount > 1 ? 's' : ''} to evaluate for ${round.name || 'this round'}.`,
|
||||||
|
linkUrl: `/jury/competitions`,
|
||||||
|
linkLabel: 'View Assignments',
|
||||||
|
metadata: { projectCount, stageName: round.name, deadline },
|
||||||
|
})
|
||||||
|
totalSent += userIds.length
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send direct emails to every juror (regardless of notification email settings)
|
||||||
|
const allUserIds = Object.keys(userCounts)
|
||||||
|
const users = await ctx.prisma.user.findMany({
|
||||||
|
where: { id: { in: allUserIds } },
|
||||||
|
select: { id: true, name: true, email: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
const baseUrl = process.env.NEXTAUTH_URL || 'https://monaco-opc.com'
|
||||||
|
let emailsSent = 0
|
||||||
|
|
||||||
|
for (const user of users) {
|
||||||
|
const projectCount = userCounts[user.id] || 0
|
||||||
|
if (projectCount === 0) continue
|
||||||
|
|
||||||
|
try {
|
||||||
|
await sendStyledNotificationEmail(
|
||||||
|
user.email,
|
||||||
|
user.name || '',
|
||||||
|
'BATCH_ASSIGNED',
|
||||||
|
{
|
||||||
|
name: user.name || undefined,
|
||||||
|
title: `Projects Assigned - ${round.name}`,
|
||||||
|
message: `You have been assigned ${projectCount} project${projectCount > 1 ? 's' : ''} to evaluate for ${round.name}.`,
|
||||||
|
linkUrl: `${baseUrl}/jury/competitions`,
|
||||||
|
metadata: { projectCount, roundName: round.name, deadline },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
emailsSent++
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to send assignment email to ${user.email}:`, error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await logAudit({
|
||||||
|
prisma: ctx.prisma,
|
||||||
|
userId: ctx.user.id,
|
||||||
|
action: 'NOTIFY_JURORS_OF_ASSIGNMENTS',
|
||||||
|
entityType: 'Round',
|
||||||
|
entityId: input.roundId,
|
||||||
|
detailsJson: {
|
||||||
|
jurorCount: Object.keys(userCounts).length,
|
||||||
|
totalAssignments: assignments.length,
|
||||||
|
emailsSent,
|
||||||
|
},
|
||||||
|
ipAddress: ctx.ip,
|
||||||
|
userAgent: ctx.userAgent,
|
||||||
|
})
|
||||||
|
|
||||||
|
return { sent: totalSent, jurorCount: Object.keys(userCounts).length, emailsSent }
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { TRPCError } from '@trpc/server'
|
|||||||
import { router, protectedProcedure, adminProcedure, juryProcedure } from '../trpc'
|
import { router, protectedProcedure, adminProcedure, juryProcedure } from '../trpc'
|
||||||
import { logAudit } from '@/server/utils/audit'
|
import { logAudit } from '@/server/utils/audit'
|
||||||
import { notifyAdmins, NotificationTypes } from '../services/in-app-notification'
|
import { notifyAdmins, NotificationTypes } from '../services/in-app-notification'
|
||||||
import { processEvaluationReminders } from '../services/evaluation-reminders'
|
import { sendManualReminders } from '../services/evaluation-reminders'
|
||||||
import { generateSummary } from '@/server/services/ai-evaluation-summary'
|
import { generateSummary } from '@/server/services/ai-evaluation-summary'
|
||||||
|
|
||||||
export const evaluationRouter = router({
|
export const evaluationRouter = router({
|
||||||
@@ -564,7 +564,7 @@ export const evaluationRouter = router({
|
|||||||
triggerReminders: adminProcedure
|
triggerReminders: adminProcedure
|
||||||
.input(z.object({ roundId: z.string() }))
|
.input(z.object({ roundId: z.string() }))
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const result = await processEvaluationReminders(input.roundId)
|
const result = await sendManualReminders(input.roundId)
|
||||||
|
|
||||||
await logAudit({
|
await logAudit({
|
||||||
prisma: ctx.prisma,
|
prisma: ctx.prisma,
|
||||||
|
|||||||
@@ -14,9 +14,113 @@ interface ReminderResult {
|
|||||||
errors: number
|
errors: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manually send reminders to all jurors with incomplete assignments for a round.
|
||||||
|
* Bypasses window/deadline checks — the admin explicitly chose to send now.
|
||||||
|
* Uses 'MANUAL' type so it doesn't interfere with automated cron deduplication,
|
||||||
|
* but still deduplicates within manual sends (one manual reminder per juror per round).
|
||||||
|
*/
|
||||||
|
export async function sendManualReminders(roundId: string): Promise<ReminderResult> {
|
||||||
|
let sent = 0
|
||||||
|
let errors = 0
|
||||||
|
|
||||||
|
const round = await prisma.round.findUnique({
|
||||||
|
where: { id: roundId },
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
windowCloseAt: true,
|
||||||
|
competition: { select: { name: true } },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!round) return { sent, errors }
|
||||||
|
|
||||||
|
// Find jurors with incomplete assignments
|
||||||
|
const incompleteAssignments = await prisma.assignment.findMany({
|
||||||
|
where: { roundId, isCompleted: false },
|
||||||
|
select: { userId: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
const userIds = [...new Set(incompleteAssignments.map((a) => a.userId))]
|
||||||
|
if (userIds.length === 0) return { sent, errors }
|
||||||
|
|
||||||
|
// Deduplicate: only one MANUAL reminder per juror per round
|
||||||
|
const existingManual = await prisma.reminderLog.findMany({
|
||||||
|
where: { roundId, type: 'MANUAL', userId: { in: userIds } },
|
||||||
|
select: { userId: true },
|
||||||
|
})
|
||||||
|
const alreadySent = new Set(existingManual.map((r) => r.userId))
|
||||||
|
const usersToNotify = userIds.filter((id) => !alreadySent.has(id))
|
||||||
|
|
||||||
|
if (usersToNotify.length === 0) return { sent, errors }
|
||||||
|
|
||||||
|
const users = await prisma.user.findMany({
|
||||||
|
where: { id: { in: usersToNotify } },
|
||||||
|
select: { id: true, name: true, email: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
const baseUrl = process.env.NEXTAUTH_URL || 'https://monaco-opc.com'
|
||||||
|
const deadlineStr = round.windowCloseAt
|
||||||
|
? round.windowCloseAt.toLocaleDateString('en-US', {
|
||||||
|
weekday: 'long',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
timeZoneName: 'short',
|
||||||
|
})
|
||||||
|
: undefined
|
||||||
|
|
||||||
|
const pendingCounts = new Map<string, number>()
|
||||||
|
for (const a of incompleteAssignments) {
|
||||||
|
pendingCounts.set(a.userId, (pendingCounts.get(a.userId) || 0) + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const user of users) {
|
||||||
|
const pendingCount = pendingCounts.get(user.id) || 0
|
||||||
|
if (pendingCount === 0) continue
|
||||||
|
|
||||||
|
try {
|
||||||
|
const deadlineNote = deadlineStr ? ` The deadline is ${deadlineStr}.` : ''
|
||||||
|
await sendStyledNotificationEmail(
|
||||||
|
user.email,
|
||||||
|
user.name || '',
|
||||||
|
'REMINDER_24H',
|
||||||
|
{
|
||||||
|
name: user.name || undefined,
|
||||||
|
title: `Evaluation Reminder - ${round.name}`,
|
||||||
|
message: `You have ${pendingCount} pending evaluation${pendingCount !== 1 ? 's' : ''} for ${round.name}.${deadlineNote}`,
|
||||||
|
linkUrl: `${baseUrl}/jury/rounds/${round.id}/assignments`,
|
||||||
|
metadata: {
|
||||||
|
pendingCount,
|
||||||
|
roundName: round.name,
|
||||||
|
...(deadlineStr && { deadline: deadlineStr }),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
await prisma.reminderLog.create({
|
||||||
|
data: { roundId, userId: user.id, type: 'MANUAL' },
|
||||||
|
})
|
||||||
|
|
||||||
|
sent++
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`Failed to send manual reminder to ${user.email} for round ${round.name}:`,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
errors++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { sent, errors }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find active stages with approaching deadlines and send reminders
|
* Find active stages with approaching deadlines and send reminders
|
||||||
* to jurors who have incomplete assignments.
|
* to jurors who have incomplete assignments. (Used by cron job)
|
||||||
*/
|
*/
|
||||||
export async function processEvaluationReminders(roundId?: string): Promise<ReminderResult> {
|
export async function processEvaluationReminders(roundId?: string): Promise<ReminderResult> {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|||||||
Reference in New Issue
Block a user