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:
@@ -16,6 +16,7 @@ import {
|
||||
NotificationTypes,
|
||||
} from '../services/in-app-notification'
|
||||
import { logAudit } from '@/server/utils/audit'
|
||||
import { sendStyledNotificationEmail } from '@/lib/email'
|
||||
|
||||
async function runAIAssignmentJob(jobId: string, roundId: string, userId: string) {
|
||||
try {
|
||||
@@ -1357,4 +1358,115 @@ export const assignmentRouter = router({
|
||||
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 }
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user