feat(user): context-aware default dashboard (§D.1)

user.getDefaultDashboard returns the highest-priority role for which the
user has actionable work right now — pending eval in active round, active
mentoring assignment, applicant project in active round, etc. — falling
back to static priority order if nothing is actionable.

src/app/page.tsx now reads roles[] (multi-role array) instead of just the
primary role, fixing the bug where mentor+juror users always landed on
their primary role's dashboard. Uses static priority for simplicity in
the server component; the context-aware procedure remains available for
client surfaces.

Tests cover six cases: super-admin, juror with active eval, juror+observer
fallback, mentor+juror in mentoring round, both-active-priority-tiebreak,
observer-only.

Plan: docs/superpowers/plans/2026-04-28-pr6-multi-role-and-workspace-previews.md
This commit is contained in:
Matt
2026-04-28 16:00:56 +02:00
parent cedd188328
commit 0c2b2d1f96
3 changed files with 269 additions and 15 deletions

View File

@@ -4,28 +4,27 @@ import Image from 'next/image'
import { auth } from '@/lib/auth'
import { redirect } from 'next/navigation'
import type { Route } from 'next'
import type { UserRole } from '@prisma/client'
export const metadata: Metadata = { title: 'Monaco Ocean Protection Challenge' }
export default async function HomePage() {
const session = await auth()
// Redirect authenticated users to their appropriate dashboard
// Redirect authenticated users to their appropriate dashboard.
// Reads the multi-role array (roles[]) so a user who is e.g. JURY_MEMBER+MENTOR
// lands on /jury (their highest-priority role) rather than always falling
// through on the singular `role` field. The context-aware variant —
// user.getDefaultDashboard tRPC procedure — exists for surfaces that can call
// tRPC; page.tsx uses static priority for simplicity.
if (session?.user) {
if (
session.user.role === 'SUPER_ADMIN' ||
session.user.role === 'PROGRAM_ADMIN'
) {
redirect('/admin')
} else if (session.user.role === 'JURY_MEMBER') {
redirect('/jury')
} else if (session.user.role === 'MENTOR') {
redirect('/mentor' as Route)
} else if (session.user.role === 'OBSERVER') {
redirect('/observer')
} else if (session.user.role === 'APPLICANT') {
redirect('/applicant' as Route)
}
const roles = (session.user.roles as UserRole[] | undefined) ?? [session.user.role as UserRole]
if (roles.includes('SUPER_ADMIN') || roles.includes('PROGRAM_ADMIN')) redirect('/admin')
if (roles.includes('AWARD_MASTER')) redirect('/award-master')
if (roles.includes('JURY_MEMBER')) redirect('/jury')
if (roles.includes('MENTOR')) redirect('/mentor' as Route)
if (roles.includes('APPLICANT')) redirect('/applicant' as Route)
if (roles.includes('OBSERVER')) redirect('/observer')
}
return (