Add per-juror notify button in Jury Progress section
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m45s
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m45s
Adds a mail icon on hover for each juror row in the Jury Progress table, allowing admins to send assignment notifications to individual jurors instead of only bulk-notifying all at once. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2363,11 +2363,18 @@ function JuryProgressTable({ roundId }: { roundId: string }) {
|
|||||||
{ refetchInterval: 15_000 },
|
{ refetchInterval: 15_000 },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const notifyMutation = trpc.assignment.notifySingleJurorOfAssignments.useMutation({
|
||||||
|
onSuccess: (data) => {
|
||||||
|
toast.success(`Notified juror of ${data.projectCount} assignment(s)`)
|
||||||
|
},
|
||||||
|
onError: (err) => toast.error(err.message),
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-base">Jury Progress</CardTitle>
|
<CardTitle className="text-base">Jury Progress</CardTitle>
|
||||||
<CardDescription>Evaluation completion per juror</CardDescription>
|
<CardDescription>Evaluation completion per juror. Click the mail icon to notify an individual juror.</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
@@ -2391,12 +2398,34 @@ function JuryProgressTable({ roundId }: { roundId: string }) {
|
|||||||
: 'bg-gray-300'
|
: 'bg-gray-300'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={juror.id} className="space-y-1 hover:bg-muted/20 rounded px-1 py-0.5 -mx-1 transition-colors">
|
<div key={juror.id} className="space-y-1 hover:bg-muted/20 rounded px-1 py-0.5 -mx-1 transition-colors group">
|
||||||
<div className="flex justify-between text-xs">
|
<div className="flex justify-between items-center text-xs">
|
||||||
<span className="font-medium truncate max-w-[60%]">{juror.name}</span>
|
<span className="font-medium truncate max-w-[50%]">{juror.name}</span>
|
||||||
<span className="text-muted-foreground shrink-0 tabular-nums">
|
<div className="flex items-center gap-2 shrink-0">
|
||||||
|
<span className="text-muted-foreground tabular-nums">
|
||||||
{juror.completed}/{juror.assigned} ({pct}%)
|
{juror.completed}/{juror.assigned} ({pct}%)
|
||||||
</span>
|
</span>
|
||||||
|
<TooltipProvider delayDuration={200}>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"
|
||||||
|
disabled={notifyMutation.isPending}
|
||||||
|
onClick={() => notifyMutation.mutate({ roundId, userId: juror.id })}
|
||||||
|
>
|
||||||
|
{notifyMutation.isPending && notifyMutation.variables?.userId === juror.id ? (
|
||||||
|
<Loader2 className="h-3 w-3 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Mail className="h-3 w-3" />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent side="left"><p>Notify this juror of their assignments</p></TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="h-2 bg-muted rounded-full overflow-hidden">
|
<div className="h-2 bg-muted rounded-full overflow-hidden">
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -1466,4 +1466,58 @@ export const assignmentRouter = router({
|
|||||||
|
|
||||||
return { sent: totalSent, jurorCount: Object.keys(userCounts).length }
|
return { sent: totalSent, jurorCount: Object.keys(userCounts).length }
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
notifySingleJurorOfAssignments: adminProcedure
|
||||||
|
.input(z.object({ roundId: z.string(), userId: z.string() }))
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const round = await ctx.prisma.round.findUniqueOrThrow({
|
||||||
|
where: { id: input.roundId },
|
||||||
|
select: { name: true, windowCloseAt: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
const assignments = await ctx.prisma.assignment.findMany({
|
||||||
|
where: { roundId: input.roundId, userId: input.userId },
|
||||||
|
select: { id: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (assignments.length === 0) {
|
||||||
|
throw new TRPCError({ code: 'NOT_FOUND', message: 'No assignments found for this juror in this round' })
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectCount = assignments.length
|
||||||
|
const deadline = round.windowCloseAt
|
||||||
|
? new Date(round.windowCloseAt).toLocaleDateString('en-US', {
|
||||||
|
weekday: 'long',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
})
|
||||||
|
: undefined
|
||||||
|
|
||||||
|
await createBulkNotifications({
|
||||||
|
userIds: [input.userId],
|
||||||
|
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, roundName: round.name, deadline },
|
||||||
|
})
|
||||||
|
|
||||||
|
await logAudit({
|
||||||
|
prisma: ctx.prisma,
|
||||||
|
userId: ctx.user.id,
|
||||||
|
action: 'NOTIFY_SINGLE_JUROR_OF_ASSIGNMENTS',
|
||||||
|
entityType: 'Round',
|
||||||
|
entityId: input.roundId,
|
||||||
|
detailsJson: {
|
||||||
|
targetUserId: input.userId,
|
||||||
|
assignmentCount: projectCount,
|
||||||
|
},
|
||||||
|
ipAddress: ctx.ip,
|
||||||
|
userAgent: ctx.userAgent,
|
||||||
|
})
|
||||||
|
|
||||||
|
return { sent: 1, projectCount }
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user