feat: show applicant's current round instead of assignments in members table
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
For APPLICANT users in the admin members list, the Assignments column now shows the project's current round name and state badge (Active, Pending, Rejected, etc.) instead of "0 assigned". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -297,8 +297,73 @@ export const userRouter = router({
|
||||
|
||||
const usersWithAvatars = await attachAvatarUrls(users)
|
||||
|
||||
// For APPLICANT users, attach their project's current round info
|
||||
const applicantIds = users.filter((u) => u.role === 'APPLICANT').map((u) => u.id)
|
||||
const applicantRoundMap = new Map<string, { roundName: string; state: string } | null>()
|
||||
|
||||
if (applicantIds.length > 0) {
|
||||
// Find each applicant's project, then the latest round state
|
||||
const projects = await ctx.prisma.project.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ submittedByUserId: { in: applicantIds } },
|
||||
{ teamMembers: { some: { userId: { in: applicantIds } } } },
|
||||
],
|
||||
},
|
||||
include: {
|
||||
teamMembers: { select: { userId: true } },
|
||||
projectRoundStates: {
|
||||
select: {
|
||||
state: true,
|
||||
round: { select: { name: true, sortOrder: true } },
|
||||
},
|
||||
orderBy: { round: { sortOrder: 'desc' } },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// Build a map of userId -> project's current round info
|
||||
for (const proj of projects) {
|
||||
const userIds = [
|
||||
proj.submittedByUserId,
|
||||
...proj.teamMembers.map((tm) => tm.userId),
|
||||
].filter((id): id is string => id !== null)
|
||||
|
||||
// Find the latest active round state (non-terminal first, fallback to terminal)
|
||||
const latestActive = proj.projectRoundStates.find((rs) =>
|
||||
rs.state === 'IN_PROGRESS' || rs.state === 'PENDING'
|
||||
)
|
||||
const latestTerminal = proj.projectRoundStates.find((rs) =>
|
||||
rs.state === 'REJECTED' || rs.state === 'WITHDRAWN'
|
||||
)
|
||||
const latest = latestActive ?? proj.projectRoundStates[0]
|
||||
|
||||
for (const uid of userIds) {
|
||||
if (!applicantIds.includes(uid)) continue
|
||||
if (latestTerminal && !latestActive) {
|
||||
applicantRoundMap.set(uid, {
|
||||
roundName: latestTerminal.round.name,
|
||||
state: latestTerminal.state,
|
||||
})
|
||||
} else if (latest) {
|
||||
applicantRoundMap.set(uid, {
|
||||
roundName: latest.round.name,
|
||||
state: latest.state,
|
||||
})
|
||||
} else {
|
||||
applicantRoundMap.set(uid, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const enrichedUsers = usersWithAvatars.map((u) => ({
|
||||
...u,
|
||||
applicantRoundInfo: applicantRoundMap.get(u.id) ?? null,
|
||||
}))
|
||||
|
||||
return {
|
||||
users: usersWithAvatars,
|
||||
users: enrichedUsers,
|
||||
total,
|
||||
page,
|
||||
perPage,
|
||||
|
||||
Reference in New Issue
Block a user