Compare commits

..

279 Commits

Author SHA1 Message Date
Matt
2945a92193 feat(finale): per-project presentation/Q&A durations in m:ss + config-save merge fix
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m30s
- setProjectTiming stores per-project overrides in round config; phase starts
  resolve: explicit input > project override > round default
- Run Order rows get m:ss inputs per project; PhaseControls one-off overrides
  now also m:ss (shared parseClock: '7:30', '12:05', plain '7')
- CRITICAL: round.update now MERGES validated form config over the existing
  configJson — saving the Config tab was wiping projectOrder (would have
  destroyed a running ceremony) and the finals-docs upload toggle

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 20:14:49 +02:00
Matt
9b56eb27fb fix(finale): live-verification fixes — session sync on start, honest vote form, reveal panel polish
All checks were successful
Build and Push Docker Image / build (push) Successful in 10m43s
Found by driving the full ceremony end-to-end in the browser:
- live.start + startPresentation sync LiveVotingSession (status/currentProjectId)
  — jury votes silently failed when the admin never used sendToScreens
- LiveVotingForm no longer shows 'submitted' on a failed mutation; pages
  re-key on votedAt so async vote data renders the right state after refresh
- reveal compose prefers DELIB_LOCKED deliberation results over jury score
  order (listSessions now includes results); Arm unlocks right after save
- deliberation jury page review cards re-key on revision

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 19:24:45 +02:00
Matt
160333c2f9 fix(finale): ceremony-day rate-limit bucket — venue NAT would 429 audience polling
Requests consisting only of cheap public ceremony reads (+ token-gated vote
casts) get a 6000/min per-IP budget instead of 100/min. Vote integrity is
enforced by the token + AudienceFavoriteVote IP cap, not the rate limiter.
Found live: big-screen polling hit 429 within minutes in verification.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:45:15 +02:00
Matt
f7fdfdec9b test(finale): tally audit — weighted criteria math, ordering, ties, favorites separation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:35:44 +02:00
Matt
a2c6baf718 feat(finale): full ceremony UI — admin console, jury phases+notes, deliberation flow, audience voting, big-screen view
- Admin Ceremony tab: phase driver with real server timers + overtime, run
  order with category grouping + send-to-screens, audience windows + QR
  dialog, override slides, timing log, results reveal builder/stepper
- Admin Deliberation tab: per-category session creation from the round's
  jury group, open/close voting, tally/runoff/override/finalize
- Jury live page: ON_DECK/PRESENTING/QA/SCORING aware, autosaved notes,
  vote comments; LiveVotingForm fixed (criteria score >10 rejection bug,
  permanent lock-out after submit) and made revisable
- Jury deliberation page: identityless submitVote, review-before-rank
  context (finale scores editable, ceremony notes, docs link)
- Jury nav: Live Ceremony + per-category Deliberation links
- Public: rebuilt QR audience voting page (anonymous-safe, favorite-pick
  windows, change-until-close), new /live/ceremony/[roundId] projector view
  with animated reveal, confetti, audience QR slide, override slides

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:34:50 +02:00
Matt
c9dc1bfabd feat(finale): deliberation jury identity resolution, rankable projects, score-revision path, session sync
- submitVote resolves the caller's JuryGroupMember participant row server-side
  (was comparing JuryGroupMember id to User id — every juror got FORBIDDEN)
- getSessionWithVotes now includes category projects so the ranking form has
  data before finalize
- liveVoting.vote accepts any finale-ordered project (revision during
  deliberation); timed window still applies to the live project
- live.sendToScreens keeps LiveVotingSession.currentProjectId/status in sync

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:15:45 +02:00
Matt
4e6904fa12 feat(finale): reveal controller + public ceremony-state endpoint (no-leak guaranteed)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:12:00 +02:00
Matt
45b007334e feat(finale): vote comments, by-round session lookup, my-finale-inputs query
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:10:32 +02:00
Matt
6d2fa3369f feat(finale): audience favorite-vote windows with category gating + IP cap
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:09:02 +02:00
Matt
6eccfc694e feat(finale): per-project phase machine, server timers, overtime log, juror notes
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:07:02 +02:00
Matt
97ef3e59ac feat(finale): server-stamped phase timer helper
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:04:51 +02:00
Matt
a66bd728cd feat(finale): schema for phases, audience windows, favorite votes, notes, reveal
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:04:25 +02:00
Matt
64f88890f5 fix(auth): make audience vote, live-scores and ceremony routes public
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:02:08 +02:00
Matt
dcd85c9b13 docs(finale): implementation plan for grand-finale ceremony system
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 18:01:12 +02:00
Matt
3be1fcd24a docs(finale): approved design spec for grand-finale ceremony system (option C)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 17:54:31 +02:00
Matt
d38fe7887a feat(final-docs): optional-mode banner/panel + admin 'Documents shown to judges' picker
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m31s
- finalist banner/panel render an optional-uploads state (settle to green via
  hasRequired ? allRequiredUploaded : allUploaded; 'optional' copy when nothing required)
- ReviewDocsPicker admin card on the LIVE_FINAL round page to curate judge-visible docs
2026-06-10 15:02:19 +02:00
Matt
28ca7bb0a6 feat(final-docs): judge-doc curation — reviewVisibleRequirementIds filter, picker helper, admin procedures
- listFinalistDocumentsForReview filters prior-round files by the round's
  reviewVisibleRequirementIds (finale uploads always shown; null = show all)
- listReviewVisibilityOptions: distinct prior-round slots + file counts for the picker
- finalist.getReviewDocSettings / setReviewVisibleRequirements (adminProcedure, audited,
  preserves sibling configJson keys)
2026-06-10 15:00:49 +02:00
Matt
d89f67ba57 feat(final-docs): hasRequired/allUploaded on FinalDocumentStatus for optional-uploads mode 2026-06-10 14:58:39 +02:00
Matt
2c311bc65a feat(finals): prominent finalist-docs banner on jury dashboard + gate nav to finals jury
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m37s
Grand-Final jurors couldn't find the finalist documents review: the only entry
point was a top-nav text link (hidden in the hamburger on mobile), with nothing
on the dashboard. Add a prominent dashboard banner (shown only to finals-jury
members) linking to /jury/finals-documents, and gate the nav "Finalist Documents"
link to members so other jurors don't hit a dead "No access" page.

- finalist.canReviewDocuments: lightweight boolean procedure (self-resolves active
  program) so the nav can gate the link without fetching the full payload
- jury-nav: show "Finalist Documents" only when canReviewDocuments
- jury dashboard: FinalsJuryBanner server component, gated via userCanReviewFinals,
  rendered above content regardless of assignment state

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 14:56:02 +02:00
Matt
85937ec942 docs(final-docs): implementation plan for judge-doc curation + optional uploads
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 22:06:20 +02:00
Matt
81352d7bd2 docs(final-docs): spec for judge-doc curation + optional revised uploads
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 21:59:48 +02:00
Matt
8a4184d20f feat(final-docs): judges see all teams' prior-round files; revised uploads behind admin toggle
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m47s
The finals jury needs the teams' EXISTING submissions (pitch deck, exec summary,
business plan, videos from prior rounds) — which all 9 teams already have. So:

- listFinalistDocumentsForReview now returns ALL of each finalist team's files
  across every round (labeled by doc type + round; finale uploads flagged
  'Revised for finals'), with presigned URLs. NOT gated — judges always see.
- Revised re-uploads are now an admin toggle (Round.configJson.allowFinalistRevisedUploads,
  default OFF): gates the banner/panel (getFinalDocumentStatusForProject), the
  upload guard (getUploadUrl/deleteFile), the documents-page round, and the
  reminders (manual + cron). When off, teams aren't prompted/able to upload.
- finalist.get/setRevisedUploadSetting + a Switch on the admin finale overview.
- judge review component rewritten to a per-team labeled file list.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 17:19:09 +02:00
Matt
f8f2d77e3b feat(final-docs): decouple grand-final docs from LIVE_FINAL being ROUND_ACTIVE
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m44s
The Grand Final round = the live event; document upload + judge review happen
in the lead-up BEFORE it opens. So gate them on finalist enrollment + the round
being open-for-docs (DRAFT or ACTIVE, not closed/finalized) instead of requiring
ROUND_ACTIVE. Lets the round stay DRAFT until event time.

- getOpenFinaleRound (was getActiveFinaleRound): status in {DRAFT,ACTIVE}, not finalized
- cron + userCanReviewFinals use the same open-status condition
- getUploadUrl + deleteFile allow a not-yet-closed LIVE_FINAL round
- getMyDashboard openRounds includes the enrolled DRAFT LIVE_FINAL round (finalists only)
- tests: DRAFT now works; CLOSED returns null

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 16:57:24 +02:00
Matt
696d7e9041 fix(final-docs): exclude dropped mentors from doc access; relative in-app reminder link
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m43s
Review follow-ups: mentor.getProjectFinalDocuments now filters droppedAt:null
(a dropped mentor no longer sees a team's final docs); reminder linkUrl is
relative so the in-app notification does client-side nav (email still absolutized).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 16:19:16 +02:00
Matt
f61dcfa89a feat(final-docs): notify mentor when a finalist uploads a Grand Final document
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 16:07:28 +02:00
Matt
146691be00 fix(auth): allow /api/cron paths past middleware (self-guarded by CRON_SECRET)
The middleware matcher intercepts /api/cron/* but the prefix was absent from
publicPaths, so unauthenticated scheduler calls were 307'd to /login and the
cron handlers never ran. All 9 cron routes already enforce x-cron-secret, so
opening the prefix is safe and unblocks the new final-document-reminders cron
(and repairs the existing crons). Same class of gap as the /lunch/pick fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 16:03:55 +02:00
Matt
e4f13aaed4 feat(final-docs): auto pre-deadline reminder cron 2026-06-09 16:00:42 +02:00
Matt
6e1dcc8cbf feat(final-docs): add FinalistConfirmation.finalDocsReminderSentAt
Additive nullable column for the auto document-reminder cron (fires once per
team). Migration hand-authored + applied to dev via db execute (NOT migrate dev,
per drifted-dev-history rule); prod applies it via migrate deploy on next build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 15:56:46 +02:00
Matt
24c7c4bc6c feat(final-docs): Final Documents panel on team + mentor views
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 15:53:39 +02:00
Matt
8c6a59bad9 feat(final-docs): mentor.getProjectFinalDocuments procedure
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 15:50:42 +02:00
Matt
b66e2071f9 refactor(final-docs): shared review component reachable by jury + admin routes
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 15:47:56 +02:00
Matt
df0be6bb48 feat(final-docs): judge review page + entry points
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 15:44:37 +02:00
Matt
e9e072dda7 feat(final-docs): finalist document review service + procedure with finale-access gate
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 15:36:59 +02:00
Matt
b0a0a71cfe chore(final-docs): script to configure the 4 grand-final file requirements 2026-06-09 15:33:25 +02:00
Matt
61bf5a4032 feat(final-docs): admin manual reminder button
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 15:31:18 +02:00
Matt
26709e2c9b feat(final-docs): manual admin document-reminder blast
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 15:26:50 +02:00
Matt
f3d3a21156 feat(final-docs): GRAND_FINAL_DOCS_REMINDER/SUBMITTED notification types + email template
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 15:23:44 +02:00
Matt
9e058e6ad7 feat(final-docs): finalist upload banner on applicant dashboard 2026-06-09 15:21:08 +02:00
Matt
16e0a08f16 feat(final-docs): applicant.getFinalDocumentStatus procedure 2026-06-09 15:17:47 +02:00
Matt
c53ec23109 fix(final-docs): round-scope file query + guard empty-required edge case 2026-06-09 15:15:22 +02:00
Matt
b1923cf0e1 feat(final-docs): grand-final document status service 2026-06-09 15:09:50 +02:00
Matt
b757aae551 docs(grand-final): implementation plan (4 phases, TDD)
Phase 1: foundation service + finalist banner + manual reminder + 4-doc reconfig
Phase 2: judge review page (finale-access gate, embedded presigned URLs)
Phase 3: mentor-section Final Documents panel (team + mentor)
Phase 4: auto reminder cron + on-upload mentor notification + migration

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 14:57:19 +02:00
Matt
c2afa58606 docs(grand-final): 4-doc set (PDF-only), thin dedicated judge page rationale
Confirmed document set: Final Presentation, Final Business Plan, 1-min Video,
Executive Summary (all required, PDF-only docs), same for both categories.
Judge page stays a thin dedicated page reusing the existing doc viewer because
the finale has 0 assignments / empty jury group (group-based, not assignment-based).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 14:49:26 +02:00
Matt
537de07245 docs(grand-final): spec for final-document upload, mentor surfacing, judge review, notifications
Design for surfacing the already-live Grand Final document upload (PDF + 1-min
video) to the 9 confirmed finalists via a dashboard banner, a read-only judge
review page (Finals Jury group + admins), a Final Documents panel on both the
team and mentor views, and email + in-app reminders (auto cron + manual blast).
Reuses the existing legacy FileRequirement anchor, upload mechanics, and
notification pipeline. Grounded in verified prod state.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 14:31:49 +02:00
Matt
a6fc697e4d fix(auth): allow /lunch/pick public access for accountless external attendees
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m30s
The external dish-picker page is reached via a signed token by attendees who
have no account. The middleware authorized() callback redirected any non
allowlisted path to /login, which is a dead end for accountless users — so the
picker shipped in 8d4f0ba was unreachable in prod (307 → /login). Add
/lunch/pick to publicPaths; data stays gated by token verification in tRPC.

Adds a regression test asserting the path is public and a protected path is not.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 12:18:10 +02:00
Matt
8d4f0bac1e feat(logistics): external attendees self-select lunch dish via tokenized page
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m51s
External lunch attendees had no way to pick their own dish — an admin had to set
it inline and no email was ever sent. (Marine added herself as an external
expecting a dish-selection link and never received one.)

Adds:
- ExternalAttendee.inviteSentAt + additive migration
- HMAC-signed external lunch token (mirrors finalist-token)
- Public no-login picker page /lunch/pick/[token] — dish + allergens + notes,
  gated by the lunch change deadline, read-only after
- tRPC getExternalByToken / setExternalPick (public) + sendExternalInvite (admin)
- Auto-send invite on createExternal when an email is present; per-row resend
  button + status chip (Invited / Picked / no email) in the logistics screen
- Unpicked externals chased by the lunch reminder cron + manual "Send reminders"
- sendExternalDishInviteEmail (branded). Page + email title use the configurable
  venue ("Lunch at {venue}") rather than "grand finale"

Tests: token roundtrip/tamper/expiry, selectUnpickedExternals filter,
get/set-by-token happy + deadline + bad-token, createExternal auto-send,
cron external reminders. Full suite 303 passing; build clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 12:04:13 +02:00
Matt
f2c8cc1e80 fix(logistics): Hotels tab crash — Radix SelectItem cannot have empty value
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m58s
The 'Unassigned' rooming option used value="" which throws at runtime
(blank tab behind the error boundary). Use a sentinel value mapped to unassign.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 19:50:18 +02:00
Matt
89ab5cc8e6 test(logistics): remove obsolete single-hotel test (superseded by logistics-hotels)
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m20s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 19:25:41 +02:00
Matt
3bbc80332c feat(logistics): Hotels tab — multi-hotel management + rooming assignment
Rewrites hotels-tab.tsx from the removed single-hotel getHotel/upsertHotel
pattern to the new multi-hotel API: Hotels section (list/add/edit/delete with
occupancy badge) + Rooming section (per-attendee hotel+room+dates assignment,
team-assign shortcut, CSV export).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 19:24:06 +02:00
Matt
9313eb96f0 feat(applicant): My Logistics shows assigned hotel + room
Replace the program-level hotel.findUnique (broken after removing @unique)
with the caller's HotelStay (include hotel) on their AttendingMember.
Returns hotel: {name,address,link,notes}|null and room: {roomNumber,
checkInAt,checkOutAt}|null. MyLogisticsCard renders the Room section
(number + Monaco-time check-in/out) when room is present.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 19:21:29 +02:00
Matt
4cd2651f9c feat(logistics): hotels CRUD + rooming + assignment procedures + travel email
Replace getHotel/upsertHotel with listHotels/createHotel/updateHotel/deleteHotel
(multi-hotel per edition). Add listRooming, assignStay, assignTeamToHotel, and
unassignStay procedures for per-attendee room assignments. Update setFlightStatus
to include attendee's HotelStay in TRAVEL_CONFIRMED notification metadata.
Extend getTravelConfirmedTemplate to render room number and check-in/out dates.
All procedures are adminProcedure and audit-logged. 10 new unit tests green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 19:19:18 +02:00
Matt
75e63eb47f feat(hotel): many hotels per edition + HotelStay (room assignment)
- Hotel.programId no longer unique (many hotels per edition)
- New HotelStay 1:1 with AttendingMember (hotelId, room, check-in/out)
- Program.hotel -> hotels[]

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 19:13:52 +02:00
Matt
200b5e0cb9 docs(logistics): multi-hotel + rooming implementation plan
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 19:09:49 +02:00
Matt
42e6b5f8c0 docs(logistics): multi-hotel + room-assignment design spec
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 19:08:51 +02:00
Matt
97951deb68 feat(logistics): departure-after-arrival validation + travel/visa CSV export
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m11s
- upsertFlightDetail throws BAD_REQUEST when departureAt < arrivalAt
- Travel tab: Download CSV button (project/attendee/email/flight fields/status/visa)
- Visas tab: Download CSV button (project/attendee/nationality/status/dates/notes)
- TDD: 2 new tests (rejects invalid, accepts valid); all 6 flight tests pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 16:56:22 +02:00
Matt
53b623fb20 feat(applicant): My Logistics card (hotel/flights/visa+nationality) + confirm-page dashboard link
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 16:53:21 +02:00
Matt
74cd111e3a feat(applicant): self-service visa nationality entry
Add updateMyVisaNationality mutation: finds the caller's AttendingMember where the program has visaStatusVisibleToMembers=true and a VisaApplication exists, updates VisaApplication.nationality, and emits a VISA_NATIONALITY_SELF_SET audit log. Throws NOT_FOUND when no eligible application exists. Tests: persists update; rejects caller without a visible visa app.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 16:51:01 +02:00
Matt
d03c705642 feat(applicant): getMyLogistics (hotel+flight+visa) + submitter-match fix
- Fix getMyFinalistConfirmation to resolve project via OR [submittedByUserId, teamMembers] so a lead who submitted but has no TeamMember row can see their card.
- Add getMyLogistics query: returns projectTitle, confirmationStatus, hotel (program 1:1), myFlight (caller's AttendingMember.flightDetail), visaVisible flag, and myVisa when visible. Returns null for non-confirmed or unrelated callers.
- Tests: confirmed finalist sees hotel/flight/visa; non-finalist gets null; PENDING confirmation gets null.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 16:50:14 +02:00
Matt
ed426a6fb4 docs(logistics): Wave 4 plan — team-facing My Logistics + travel/visa UX
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:46:12 +02:00
Matt
ee8d65a300 feat(logistics): enable Email Templates tab
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:41:39 +02:00
Matt
0058b2b73b feat(logistics): Email Templates tab (toggle/subject/preview/test) + logistics in global settings
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:41:33 +02:00
Matt
e5788b3e9d feat(notifications): renderNotificationEmail + previewEmailTemplate + logistics sample data
- Export `renderNotificationEmail` from email.ts (pure template resolver, no send)
- Refactor `sendStyledNotificationEmail` to delegate to `renderNotificationEmail`
- Hoist sampleData to module-level `NOTIFICATION_SAMPLE_DATA` in notification router
- Add 8 logistics sample entries (FINALIST_*/TRAVEL_CONFIRMED/VISA_STATUS_UPDATE)
- Add `notification.previewEmailTemplate` adminProcedure query (returns subject/html/hasStyledTemplate)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 16:39:29 +02:00
Matt
27bdf8cdef docs(logistics): Wave 3 plan — enable Email Templates tab
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:36:05 +02:00
Matt
3f25ba112b fix(lunch): reminder filter, recap failure surfacing, manual send-reminders
- Extract selectUnpickedAttendees helper with OR filter (is null OR pickedAt null)
  to fix cron missing attendees with no MemberLunchPick row at all
- Update cron route to use the helper
- sendRecap now throws TRPCError on email failure instead of silently stamping success
- Add lunch.sendReminders adminProcedure for manual on-demand reminder sends
- Add "Send reminders now" AlertDialog button to LunchRecapActions
- Tests: lunch-reminder-filter.test.ts (2 new), all 5 lunch test files pass (40 tests)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:24:01 +02:00
Matt
884c96c710 feat(logistics): travel-confirmed + visa-status emails to attendees
When a flight is set to CONFIRMED, fire a TRAVEL_CONFIRMED in-app
notification (+ email via the existing NotificationEmailSetting pipeline)
to the attending member. When a visa status changes to one of
INVITATION_SENT|APPOINTMENT_BOOKED|GRANTED|DENIED, fire a
VISA_STATUS_UPDATE notification. Both are best-effort (try/catch, never
throw inside the mutation). Admin notes are not forwarded to metadata.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 16:20:21 +02:00
Matt
1b4ab6be18 feat(finalist): deadline reminder emails via cron
Add sendDueConfirmationReminders() to finalist-confirmation.ts: queries
PENDING confirmations with no reminderSentAt whose deadline is within the
per-program LIVE_FINAL round reminderHoursBeforeDeadline window (default 12h),
sends a FINALIST_REMINDER in-app notification (+ email via pipeline) to the
team LEAD, then stamps reminderSentAt for idempotency.

Wire into the finalist-confirmations cron route alongside expirePendingPastDeadline.
Also clear reminderSentAt on re-invite in resetOrCreatePendingConfirmation so
re-invited teams get a fresh reminder window.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:17:19 +02:00
Matt
d501624c56 feat(finalist): withdrawal notification to team on decline/unconfirm/unenroll
Notifies the team LEAD with FINALIST_WITHDRAWN (in-app + email) when an admin
withdraws a grand-finale slot via adminDecline, unconfirm, or unenroll.
For unenroll, only notifies when a CONFIRMED confirmation existed before deletion.
Adds finalist-withdrawal.test.ts (4 tests) covering all three paths.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:14:26 +02:00
Matt
b2826d595f feat(finalist): admin alerts on confirm/decline/expire/promote
Wire notifyAdmins() into finalist lifecycle events so admins receive
in-app (+ email when enabled) notifications on each key transition:
- finalist.confirm → FINALIST_CONFIRMED
- finalist.decline / adminDecline → FINALIST_DECLINED
- expirePendingPastDeadline (per row) → FINALIST_EXPIRED
- promoteNextWaitlistEntry + manualPromote → FINALIST_WAITLIST_PROMOTED

All calls are wrapped in try/catch — comms never throw inside a mutation
or cron (CLAUDE.md: "round notifications never throw"). Added project
title to the project select where it was missing.

Tests: tests/unit/finalist-comms.test.ts — 3 tests passing (TDD).
Regression: finalist-confirmation, finalist-admin-confirm,
finalist-enrollment — 30 tests all passing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:11:17 +02:00
Matt
f529e79cd7 feat(comms): logistics notification types, templates, and email settings
- Add 8 constants to NotificationTypes (FINALIST_CONFIRMED/DECLINED/EXPIRED/
  WAITLIST_PROMOTED/REMINDER/WITHDRAWN, TRAVEL_CONFIRMED, VISA_STATUS_UPDATE)
  with matching icons and priorities in NotificationIcons/NotificationPriorities
- Add 4 branded email templates: getFinalistReminderTemplate,
  getFinalistWithdrawnTemplate, getTravelConfirmedTemplate,
  getVisaStatusTemplate — registered in NOTIFICATION_EMAIL_TEMPLATES
  (admin-alert types use generic fallback)
- Add 8 logistics seed rows to seed-notification-settings.ts; upserted to
  dev DB (idempotent)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 16:06:10 +02:00
Matt
0ea949309a feat(finalist): add reminderSentAt for confirmation reminders
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:02:57 +02:00
Matt
8afef1ecba docs(logistics): Wave 2 plan — close the email/notification void
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:02:12 +02:00
Matt
34bb2bad57 fix(finalist): program-scope guards on enroll/unenroll (code review)
- enrollFinalists: reject a roundId whose competition belongs to a
  different program than input.programId.
- unenroll: reject a project/round pair from different programs before
  any delete.
- Hoist ADMIN_CONFIRM attendee validation to a pre-pass so a bad entry
  in a multi-team batch fails before any project is partially written.
- Add regression tests for both cross-program guards.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 15:49:13 +02:00
Matt
8ee517f6ca feat(logistics): waitlist populate UI + confirmations-tab un-confirm/re-invite actions
- waitlist-card: AddToWaitlistForm sub-component wires finalist.addToWaitlist (category + project pickers sourced from listEnrollmentCandidates, filtered to exclude confirmed/waitlisted projects; appends at next rank)
- confirmations-tab: fix dead-end empty-state copy to reference Grand Final round Overview tab
- confirmations-tab: CONFIRMED rows → Un-confirm button (AlertDialog with required reason, calls finalist.unconfirm)
- confirmations-tab: DECLINED/EXPIRED rows → Re-invite button (calls enrollFinalists EMAIL mode via liveFinalRoundId from listEnrollmentCandidates)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 15:36:15 +02:00
Matt
2a98f0cacf feat(grand-finale): finalist enrollment card on LIVE_FINAL round page
Adds EnrollAttendeesDialog and FinalistEnrollmentCard components and
wires the card above FinalistSlotsCard on the LIVE_FINAL round Overview,
giving admins the missing UI entry point to enroll mentoring-round teams
into the Grand Final via EMAIL or ADMIN_CONFIRM mode.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 15:32:40 +02:00
Matt
e80710487c feat(finalist): listEnrollmentCandidates query for enrollment UI
Returns mentoring-round candidates grouped by category with status,
team members, quota and confirmed/pending counts; inLiveFinal flag and
attendeeCap for the enrollment UI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 15:29:26 +02:00
Matt
375aeb08af feat(finalist): unenroll reverses round membership + confirmation
Adds finalist.unenroll(projectId, roundId) which deletes the
FinalistConfirmation (cascading AttendingMember/FlightDetail/
VisaApplication/MemberLunchPick) and the LIVE_FINAL ProjectRoundState,
then logs a FINALIST_UNENROLL audit entry. Safe no-op when no rows exist.
Tests cover ADMIN_CONFIRM enrolled teardown and the no-rows path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 15:23:50 +02:00
Matt
f1e62fdd3b feat(finalist): unified enrollFinalists (round membership + confirmation + email/admin-confirm)
- Add `finalist.enrollFinalists` adminProcedure: creates ProjectRoundState in
  LIVE_FINAL round (skipDuplicates) + resets/creates FinalistConfirmation in
  one step, with EMAIL and ADMIN_CONFIRM attendee modes.
- Extract `confirmAttendanceInTx` helper into finalist-enrollment.ts; reuse
  from both adminConfirm and enrollFinalists (DRY refactor, all tests green).
- Add 4 tests covering EMAIL mode, ADMIN_CONFIRM mode, re-enroll safety, and
  over-cap rejection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 15:20:51 +02:00
Matt
dde8ea9345 feat(finalist): re-invite-safe confirmation reset helper
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 15:16:52 +02:00
Matt
ca9edcd038 fix(lunch): allow non-admins to read dish list (unblocks applicant picker) 2026-06-04 15:15:14 +02:00
Matt
647e7f09a7 docs(logistics): Wave 1 plan — finalist enrollment + BLOCKER fixes
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 15:13:01 +02:00
Matt
6b37e9bb9e fix(email): correct member-row spacing in mentor welcome emails
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m34s
Member/mentor/teammate tables used width:100%, stretching the two
columns apart and forcing names to wrap; wrapped names then misaligned
with their email (default vertical-align: middle).

Drop width:100% so tables hug content, add 16px column gap via name-cell
padding, and set vertical-align: top so emails align to the first line
of the name. Applied to getMentorBulkAssignmentTemplate and
getTeamMentorIntroductionTemplate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-02 09:11:01 +02:00
Matt
eb891403f1 Merge: populate roles[] on user creation (role in roles invariant)
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m43s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 20:06:52 +02:00
Matt
60f1a53d70 fix(users): populate roles[] with primary role on user creation
All user-creation paths (admin create, bulk invite import, public application
contact + team members, project team members, jury-group + special-award
invites) now set roles=[role] so the invariant role in roles[] holds for new
users, matching seed.ts and the role-change mutations. Prevents the empty
roles[] inconsistency that hid primary-role mentors from the mentor picker.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 20:06:52 +02:00
Matt
501b4ffdb5 Merge: primary-role mentors assignable on mentor config page
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m51s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 19:34:40 +02:00
Matt
828c09df6d fix(mentor): primary-role mentors are selectable/assignable
getCandidates, getMentorPool and bulkAssign matched MENTOR via roles[] only, so
a user with role=MENTOR but an empty roles[] array (legacy/seeded records, e.g.
Arnaud Blandin on prod) was excluded from the mentor picker and rejected by
bulk assign. Match MENTOR as primary role OR in roles[], mirroring userHasRole.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 19:34:40 +02:00
Matt
fe7f133879 Merge: members role tabs include secondary roles
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m1s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 18:51:11 +02:00
Matt
d4a77f63d3 fix(members): role tabs/filter include users with secondary roles
user.list and user.listInvitableIds filtered on the singular User.role column,
so the type tabs (Jury/Mentor/…) omitted users holding that role as a secondary
role (User.roles[]). Match the role as primary OR secondary (roles hasSome),
combined with search via AND, mirroring userHasRole / hasRole middleware.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 18:51:11 +02:00
Matt
040e5ff9a9 Merge: brand-align mentorship welcome emails
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m10s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 18:21:49 +02:00
Matt
652c3ed4f2 fix(email): use shared branded wrapper (logo/footer) for mentorship emails
Migrate getMentorBulkAssignmentTemplate + getTeamMentorIntroductionTemplate to
getEmailWrapper() so they match the other ~40 platform emails: MOPC logo header,
ocean background, big-logo footer, and UTF-8 charset (fixes accent/em-dash
rendering). Body now uses sectionTitle/paragraph/infoBox/ctaButton helpers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 18:21:49 +02:00
Matt
ed4948cc3d Merge: mentorship comms + welcome/reminder email
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m8s
- Email-all-team-members button for mentors
- Upgraded round-open emails (instructions + contact addresses)
- Admin re-sendable welcome/reminder blast with live preview
- New tRPC: mentor.previewMentorshipWelcome / sendMentorshipWelcome

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 17:04:36 +02:00
Matt
bd05aaa87d feat(mentor): email all team members button on project detail
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 16:50:00 +02:00
Matt
0d6f71b9e1 feat(admin): send mentorship welcome/reminder button on mentoring rounds
Adds a sky-accented "Send Welcome / Reminder" button to the Notifications
grid in the round page, visible only on MENTORING rounds. Wires into
trpc.mentor.previewMentorshipWelcome / sendMentorshipWelcome via the
shared EmailPreviewDialog with optional custom note support.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 16:46:58 +02:00
Matt
829b082912 feat(mentor): admin preview + send mentorship welcome/reminder email
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 16:40:38 +02:00
Matt
32116dac75 feat(mentor): round-open emails now carry team-member contacts
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 16:33:27 +02:00
Matt
0e221c3916 feat(email): mentorship senders forward contacts/note, return success
sendMentorBulkAssignmentEmail now accepts optional teamMembers per project
and a customNote, forwards both to the template, switches to getBaseUrl(),
and returns Promise<boolean> (true on success, false on empty/error).

sendTeamMentorIntroductionEmail now accepts optional teammates and customNote,
forwards both to the template, switches to getBaseUrl(), and returns
Promise<boolean> (true on success, false on empty/error).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 16:29:47 +02:00
Matt
9d3ed1cc64 test(email): cover customNote escaping + text-path for mentorship templates 2026-06-01 16:28:32 +02:00
Matt
a973b1316c feat(email): instructions + contact emails + optional note in mentorship templates
Export getMentorBulkAssignmentTemplate and getTeamMentorIntroductionTemplate,
adding an always-on instructions block, optional team-member/teammate contact
lists, and an optional custom note to both. Covers TDD with 4 new unit tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 16:24:31 +02:00
Matt
5a9821807a docs(mentor): implementation plan for mentorship comms + welcome email
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 16:20:05 +02:00
Matt
d57495be15 docs(mentor): design spec for mentorship comms + welcome/reminder email
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 16:08:46 +02:00
Matt
03526fca97 fix(mentor): defer in-app-notification emails when mentoring round is draft
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m14s
Mentor-assignment flows (mentor.assign, autoAssign, bulkAssign,
bulkAutoAssign, autoAssignBulkForRound) call createNotification and
notifyProjectTeam for MENTEE_ASSIGNED / MENTOR_ASSIGNED. Both
notification types have NotificationEmailSetting.sendEmail = true, so
the notification system fires its own styled email in addition to the
explicit mentor-team / coalesced emails on the same code path. The
earlier defer-emails-until-round-open fix only gated the explicit
sendMentorBulkAssignmentEmail / sendMentorTeamAssignmentEmail calls;
this parallel email path kept firing immediately at every assignment.

Result on prod 2026-05-26: Camille Lopez (assigned to 9 projects via
two bulk_assigns) received 7 emails at 15:04 + 1 at 15:32 from the
notification-system path during draft, plus 1 coalesced email at the
18:20 round activation = 9 sends instead of 1. Every PEARL team
member (and equivalents on other teams) received 3 emails for the
same reason.

Fix
- Add `skipEmail?: boolean` to CreateNotificationParams,
  createNotification, createBulkNotifications, and (via spread)
  notifyProjectTeam. When true the in-app notification row still
  fires but the parallel email send is suppressed; the coalesced
  mentor email and team intro at activateRound time remain the
  single source of email truth.
- Wire it up in every mentor-assignment site: compute the existing
  shouldDeferEmailsForProject gate once before the createNotification
  / notifyProjectTeam calls and pass `skipEmail: deferThisEmail`.
  bulkAssign precomputes draftProjectIds for the whole batch.
  autoAssignBulkForRound uses the round's status directly.
- New regression suite (mentor-email-deferral.test.ts, 3 cases):
  vi.mocks @/lib/email, asserts zero outbound sends when round is
  ROUND_DRAFT, confirms in-app notification rows still get written,
  and re-verifies the ACTIVE-round path still emails.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 13:12:41 +02:00
Matt
61dfc608cd fix(mentor): restore Add Project on mentoring rounds + gate mentor assignment
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m15s
Three related bugs around the mentoring-round Projects tab:

1. Add Project to Round was unreachable on MENTORING rounds — the table swap
   in the prior commit lost the button. Export AddProjectDialog from
   project-states-table and render it inside MentoringProjectsTable with an
   "Add" button in the filter row and a CTA in the empty state.
2. The "Assign Projects" quick action on the round overview linked to the
   global pool with an opaque filter; on MENTORING rounds it now switches
   to the Projects tab where the new Add Project button + auto-fill +
   per-team picker all live. Non-mentoring rounds keep the old behavior.
3. mentor.assign and mentor.bulkAssign now refuse projects that aren't
   enrolled in any MENTORING round (any status). The single-assign throws
   BAD_REQUEST with a guidance message; the bulk path filters them out and
   reports ineligibleProjectCount in the result so the UI can warn the
   admin instead of silently skipping.

Tests: the multi-mentor-assignment suite now sets up a MENTORING round +
ProjectRoundState for each project it tests against, matching the new gate.
2026-05-26 15:20:01 +02:00
Matt
c4f7216bc1 feat(mentor): defer all assignment emails until round opens + per-project bulk UI
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m7s
Email policy
- mentor.assign, mentor.bulkAssign, and autoAssignBulkForRound now suppress
  outbound email entirely when the project's MENTORING round is still
  ROUND_DRAFT. The MentorAssignment row is created (and in-app notifications
  still fire), but notificationSentAt and teamIntroducedAt remain null so
  activateRound can pick them up later.
- activateRound, when activating a MENTORING round, now does a coalesced
  mentor-side email pass in addition to the existing team-side intro pass.
  Every (mentorId) bucket of pending assignments in this round gets exactly
  one combined email; the row stamps prevent duplicates on re-activation.
- The "send immediately" path is preserved for assignments made while the
  round is already ROUND_ACTIVE — mentors and teams stay in the loop in
  real time, but staging during draft is silent.

Per-project bulk UI
- The /admin/projects/[id]/mentor manual picker now has a checkbox column,
  header select-all, and a primary-tinted action toolbar that appears when
  one or more candidates are selected. Submitting calls mentor.bulkAssign
  with the single projectId so the cartesian server path handles dedup,
  coalesced emails, and team intros uniformly with the round-page bulk.
2026-05-26 14:48:38 +02:00
Matt
cb2a864b7f feat(mentor): many-to-many bulk assignment (multi-mentor × multi-project)
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m27s
mentor.bulkAssign now accepts mentorIds[] instead of a single mentorId and
creates the cartesian product of (mentor, project) assignments. Existing
active (mentor, project) pairs are skipped per-pair, not per-project, so
choosing two mentors against a project that already has one of them still
adds the second.

Email coalescing stays one-per-mentor: each mentor receives a single email
listing only their own newly-assigned projects (not the union). Each touched
project still triggers a single team-introduction email when its MENTORING
round is ROUND_ACTIVE, listing all currently-active mentors on that team.

Dialog UI swaps the radio picker for a checkbox group with a removable chip
strip for selected mentors, a live preview of the assignment count
(mentors × projects = up to N), and a submit button that names both
counts. Toast on success reports total assignments created, projects
touched, pairs skipped, and how many mentor emails went out.
2026-05-26 14:25:41 +02:00
Matt
195fc787a9 feat(mentor): bulk assignment + coalesced emails + team intros on round open
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m53s
Round-page bulk-assign UI
- Checkboxes on every project row, header select-all, primary-tinted action
  toolbar that appears when 1+ rows are selected with an "Assign mentor…"
  CTA and Clear. Dialog lists the mentor pool with search (name/email/
  country/expertise), load indicator, and a radio picker.
- Always-visible tip strip when nothing is selected explains the bulk flow
  and offers a one-click "Select all N without a mentor" shortcut.
- New tRPC procedure `mentor.bulkAssign({ mentorId, projectIds })` assigns
  one mentor to many projects in a transaction; idempotent on the per-pair
  `(projectId, mentorId)` unique; per-project in-app notifications still
  fire for each team.
- Mutation invalidates listMentoringProjects, getProjectsNeedingMentor,
  getMentoringImportCandidates, getMentorPool, getRoundStats, project.list
  so the page reflects the new state without a refresh.

Coalesced mentor emails
- New `sendMentorBulkAssignmentEmail` (single email listing every newly-
  assigned project + workspace links) used by `mentor.bulkAssign` and
  `mentor.autoAssignBulkForRound`. The previously-silent auto-fill flow
  now emails mentors at the end of the batch, one combined email per
  mentor regardless of how many projects they received.

Team introduction emails when the round opens
- New `sendTeamMentorIntroductionEmail` lists every assigned mentor with
  name + email and a link to the workspace, so teams can reach out
  directly.
- `activateRound` (round-engine) fires the introduction for every project
  in a MENTORING round that has active mentors when the round opens.
- `mentor.assign`, `mentor.bulkAssign`, and `autoAssignBulkForRound` also
  fire the introduction immediately when the project's MENTORING round is
  already ROUND_ACTIVE — so mentors added mid-round still reach the team.
- Idempotency via the new `MentorAssignment.teamIntroducedAt` column
  (migration 20260526114936) — independent from `notificationSentAt` so
  pre-existing mentor-side stamps don't suppress the team-side email.
2026-05-26 14:04:32 +02:00
Matt
921019aaa4 fix(mentor): unbreak the mentor pipeline end-to-end
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m42s
Adding the MENTOR role from /admin/members/[id] only updated React state — the
AlertDialog "Add role" confirmation never called the server, so prod ended up
with zero users in MENTOR roles[] and /admin/mentors showed "No mentors yet".
The dialog now awaits updateUser.mutateAsync({ roles }) before closing.

Other corrections in the same area:

- DialogContent uses flex flex-col with max-h-[90vh] overflow-y-auto so tall
  modals (e.g. Add Project to Round) scroll internally instead of overflowing
  past their own rounded background.
- getProjectsNeedingMentor now matches autoAssignBulkForRound exactly: both
  filter mentorAssignments by droppedAt: null and require
  finalistConfirmation: CONFIRMED, so the toolbar count never exceeds what
  auto-fill actually processes. The toolbar surfaces hasNoMentors /
  hasNoEligible / count / all-assigned as distinct states instead of one
  misleading "All eligible projects have a mentor" line.
- New per-team table (MentoringProjectsTable) replaces ProjectStatesTable on
  the Projects tab of MENTORING rounds. Lists every project with its active
  mentors (multi-mentor aware), filter pills, search, finalist-confirmation
  badge, and a per-row link to /admin/projects/[id]/mentor for assigning.
- Applicant team page now lists ALL active mentors (PR8 Task 7) instead of
  just mentorAssignments[0].
- Hard guard in src/lib/email.ts short-circuits sendEmail when NODE_ENV=test
  or VITEST=true so test runs can never emit real notifications again.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 13:01:05 +02:00
Matt
5b99d6a530 refactor(ui): strip all dark: Tailwind classes (single-theme product)
All checks were successful
Build and Push Docker Image / build (push) Successful in 12m17s
Mechanical sweep of 41 files via `perl -i -pe 's{\s+dark:[\w:/\[\]\.\-]+}{}g'`.
All dark: variants were paired with light-mode counterparts already; no
elements relied on a dark:-only style.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 18:45:42 +02:00
Matt
6969b9c2bc chore(deps): drop next-themes; remove ThemeProvider + theme toggle UI 2026-05-22 18:43:25 +02:00
Matt
3bc9c11a51 merge: PR10 — applicant nationality stats card 2026-05-22 18:42:51 +02:00
Matt
8d4b62a602 feat(reports): applicant nationality breakdown card with scope filter (PR10)
- stats.getApplicantNationalities procedure aggregates User.nationality
  across team members of projects in the selected scope (round/program
  /global)
- New Applicant Nationalities card on /admin/reports, top-10 with
  Show all expansion, country names from the existing ISO map
- Handles the ~30% null case explicitly ("Not declared: N")

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 18:38:52 +02:00
Matt
f64e68e751 merge: PR8 — multi-mentor per team + change-requests + inline previews
Schema: MentorAssignment becomes M:N (composite unique on (projectId, mentorId)).
MentorFile re-scopes to projectId (team-wide); mentorAssignmentId becomes a
nullable audit FK with SetNull. New MentorChangeRequest model + status enum.

Behavior:
- mentor.assign stacks mentors per team; per-team assignment email fires
  once per row (idempotent via notificationSentAt).
- mentor.requestChange / listChangeRequests / resolveChangeRequest provide
  the change-request inbox; mentors are NOT notified, only admins.
- Workspace files re-scoped to project so all co-mentors and team members
  share one file list and chat.
- New inline FilePreview support in the mentor workspace.
- mentor.getProjectMentors surfaces co-mentors on the mentor workspace.

Migration: hand-written, idempotent guards, two-phase backfill on
MentorFile.projectId. Verified against May 7 prod dump with rollback.sql.

PRE-DEPLOY: pull a fresh prod DB dump and re-run the dry-run before
applying the migration to prod (the May 7 snapshot may not include
mentors added since by another admin).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 18:26:37 +02:00
Matt
48e48f058d feat(mentor-workspace): inline document preview matching applicant docs pattern
- Eye toggle expands the row below to embed FilePreview from
  @/components/shared/file-viewer (PDF iframe, image, video, Office docs)
- Download button uses explicit Content-Disposition: attachment via a
  new `disposition` input on workspaceGetFileDownloadUrl
- getPresignedUrl learns `inline: true` and optional `response-content-type`
  override so PDFs/images don't get force-downloaded by MinIO's default
- Eye button only renders for previewable mime types

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 18:26:20 +02:00
Matt
ec92b03006 test(mentor): cover multi-mentor stacking + change-request procedures (PR8 Task 10)
- multi-mentor-assignment.test.ts: stacking, P2002 dup-pair, per-team email
  idempotency via notificationSentAt, requestChange/list/resolve auth +
  conflict semantics
- mentor-file-scope.test.ts: schema invariant (projectId required, dropping
  the originating assignment leaves the file in place via SetNull)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 17:20:01 +02:00
Matt
349671f37c merge: PR8 Task 8 — admin multi-mentor UI + change-request inbox 2026-05-22 17:13:02 +02:00
Matt
4f444a1baa merge: PR8 Task 7 — applicant mentor list + request-change dialog 2026-05-22 17:12:58 +02:00
Matt
d47db17027 merge: PR8 Task 9 — mentor co-mentor visibility 2026-05-22 17:12:54 +02:00
Matt
83e950bb67 feat(admin): multi-mentor stacking UI + change-request inbox (PR8 Task 8)
- /admin/projects/[id]/mentor renders all co-mentors as a list with per-row
  Unassign (confirm dialog) and a stacking "Add a mentor" flow that no longer
  hides when at least one mentor is assigned. Candidates and AI suggestions
  filter out already-assigned mentors.
- Pending change-requests panel appears above the mentor list when there are
  open requests for the project, with per-card Mark Resolved / Dismiss actions
  routed through mentor.resolveChangeRequest (optional resolution note).
- MentoringRoundOverview gains a "Pending change requests" row showing the
  PENDING count across the program; the Review link deep-links to the first
  pending request's project mentor page.
- mentor.unassign now accepts { assignmentId } so the admin UI can target a
  specific co-mentor (legacy { projectId }-only callers still work and remove
  the most-recent assignment).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 17:11:31 +02:00
Matt
ba115f71a0 feat(applicant): mentor list + request-change dialog (PR8 Task 7)
- /applicant/mentor renders all co-mentors as cards
- New "Request a mentor change" dialog opens a free-form reason + optional
  per-mentor target; calls mentor.requestChange and shows admin-routed
  confirmation toast
- Pending-request guard disables the button until the admin resolves
2026-05-22 17:09:06 +02:00
Matt
d440b5f274 feat(mentor): show co-mentors on workspace page (PR8 Task 9)
- Adds mentor.getProjectMentors({ projectId }) — returns all active
  MentorAssignment rows for a project, authorized to any mentor on it
- Workspace page header surfaces "You + N co-mentor(s): names…" so each
  mentor knows the team composition without having to ask the admin

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 17:07:11 +02:00
Matt
ee47c0305f feat(mentor): add change-request procedures + admin email notification
- mentor.requestChange: applicants/admins open a PENDING MentorChangeRequest
  with a reason; one open request per (user, project) enforced
- mentor.listChangeRequests: admin-only inbox listing
- mentor.resolveChangeRequest: admin marks RESOLVED or DISMISSED with optional
  resolution note
- sendMentorChangeRequestEmail: notifies all SUPER_ADMIN/PROGRAM_ADMIN users
  when a request is opened (try/catch — never throws)
- Mentors are NOT notified of change requests, even after resolution
  (per design decision in PR8 plan)
- Audit log entries for create + resolve; raw reason redacted from audit

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 16:59:23 +02:00
Matt
3a1eb149b6 feat(mentor-workspace): re-scope files from assignment to project for team-wide visibility
- MentorFile.projectId is the new access boundary; mentorAssignmentId stays
  as informational audit FK (nullable).
- uploadFile derives projectId from the assignment; getFiles takes projectId
  directly; deleteFile/addFileComment auth checks any mentor on the project
  OR a project team member.
- HMAC upload token now binds to projectId (in addition to assignmentId).
- promoteFile reads file.projectId directly (no more mentorAssignment null
  navigation).
- Removes 3 placeholder NOT_FOUND guards added in Task 4.
2026-05-22 16:53:07 +02:00
Matt
a5ad11a1b5 feat(mentor): allow stacking mentors per team; send per-team assignment email
- mentor.assign no longer rejects on existing mentor; rejects only on
  duplicate (projectId, mentorId) via P2002 catch.
- After successful create, sendMentorTeamAssignmentEmail fires once and
  stamps MentorAssignment.notificationSentAt for idempotency.
- All existing behavior preserved: audit log, in-app notifications,
  MENTORING round auto-transition.
- mentor.getSuggestions no longer short-circuits when a mentor is already
  assigned — the suggestions list is now informational and the per-pair
  unique constraint enforces correctness at assign time.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 16:38:14 +02:00
Matt
66110598a0 refactor(schema-cascade): rename Project.mentorAssignment → mentorAssignments
Schema dropped @unique on MentorAssignment.projectId in PR8 Task 1 →
back-relation becomes a list. Mechanical rename of Prisma queries and
consumer accessors. Legacy single-mentor callers use [0] with a TODO for
PR8 Task 8 to surface the full list. mentor-workspace.ts is left as Task 5.

- routers (mentor, project, applicant, finalist, round) and smart-assignment
  service: include/where/select keys renamed; `mentorAssignment: null` →
  `mentorAssignments: { none: {} }`; `{ isNot: null }` → `{ some: {} }`.
- UI consumers (mentor + applicant pages): `project.mentorAssignment` →
  `project.mentorAssignments[0]` with TODO markers.
- Tests: `findUnique({ projectId })` → `findFirst({ projectId })` since the
  composite key now requires both projectId+mentorId. MentorFile.create gains
  the new required projectId.
- Workspace endpoints in mentor.ts now guard null mentorAssignmentId until
  Task 5 re-scopes them to project.
- finalist.unconfirm now cascades to ALL active mentor assignments.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 16:37:37 +02:00
Matt
9152ebb399 feat(email): add sendMentorTeamAssignmentEmail for per-team mentor notifications
Fires when a mentor is added to a specific project team — distinct from the
one-time onboarding email keyed by User.mentorOnboardingSentAt. Idempotency
for this new email is enforced at the call site in Task 4 via
MentorAssignment.notificationSentAt. Wrapped in try/catch — never throws.
2026-05-22 16:16:28 +02:00
Matt
a26e486ab5 chore(migration): include manual rollback.sql for PR8 multi-mentor
Tested against the 2026-05-07 prod dump: restore → forward → rollback restores
the schema to its pre-migration state. Safe to run only BEFORE any project
gets a second mentor — re-adding UNIQUE(projectId) will fail otherwise
(intended safety signal).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 16:13:28 +02:00
Matt
e89dca24c3 feat(schema): multi-mentor per team + change-requests + per-assignment email field
- MentorAssignment: drop projectId @unique -> composite (projectId, mentorId)
- MentorAssignment: add notificationSentAt for idempotent per-team email
- MentorFile: add projectId (primary scope); mentorAssignmentId becomes nullable audit FK
- MentorChangeRequest: new model + status enum
- Migration hand-written with IF EXISTS guards (safe for docker-entrypoint retry)
2026-05-22 16:05:25 +02:00
Matt
3bcbf72ad6 fix(members): replace flat role checkbox grid with assigned-only dropdown + confirm modal
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m55s
The previous Additional Roles grid laid every role option out as a row of
checkboxes regardless of assignment, which made unchecked roles look like
roles the user already had — admins almost toggled the wrong role on the
wrong user (e.g. nearly granting JURY_MEMBER when looking at an
AWARD_MASTER).

New layout shows only the roles a user actually has, as removable badges
with an X. A "Manage roles" dropdown next to them surfaces the full role
list as DropdownMenuCheckboxItems (assigned ones are checked, the
primary role is excluded). Toggling any item opens an AlertDialog with
add/remove-specific copy that names the user and the dashboard being
granted/revoked, so the click is impossible to misread.

The change is staged into local additionalRoles state — same flow as
before — and persisted on Save. Modal copy spells this out so the admin
knows the action isn't applied until they click Save below.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 18:27:15 +02:00
Matt
47746d79dd feat(auth): admin access link doubles as magic-login for users with passwords
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m7s
The original generateAccessLink branched on user state and minted either
an invite URL (forces password setup) or a reset URL (forces password
change). Both required the user to set/change a password — fine for new
users, painful for tech-illiterate sponsor jurors who already have a
working password and just need a fresh login because their JWT went
stale or their email is bouncing.

This adapts the existing invite-token flow to behave as a magic-login
when the user already has a password:

  - auth.ts credentials.authorize: only set mustSetPassword=true if the
    user has no passwordHash. Users who already set one keep it, the
    invite token is consumed, JWT is issued with their current role,
    they're signed in.
  - accept-invite/page.tsx: redirect to / after accept (was hardcoded
    to /set-password). The middleware already enforces the
    /set-password detour when mustSetPassword is true, so users who
    need it still land there; everyone else routes by role.
  - generateAccessLink: drop the reset-password branch. Always emits an
    /accept-invite URL. The flow naturally adapts: setup for new users,
    magic-login for active ones. Audit log records which behavior fired
    (kind: 'setup' | 'magic_login').
  - dialog copy: clearer description for each kind.

Net behavior: Didier (active, has password, stale JWT after role
migration) clicks his link → instant login on /jury, password preserved.
Magali (no password yet) clicks hers → /set-password → onboarding.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 17:35:22 +02:00
Matt
44c7accf62 feat(admin): generate access link for users when email isn't reaching them
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
Adds a "Copy Access Link" button on the member detail page that mints a
one-time URL the admin can share over Slack, WhatsApp, or any other
channel. Solves the "we sent them an invite three weeks ago and it
silently dropped into spam" failure mode that left jurors stranded.

Server: user.generateAccessLink (adminProcedure) inspects the target
user's state and picks the right flow:
  - INVITED / NONE / mustSetPassword / no password ever set → invite-flow
    URL (/accept-invite?token=…); the existing flow takes them through
    accept → set password → onboarding without further admin help.
  - Active user with a password → password-reset URL
    (/reset-password?token=…); they pick a new password and middleware
    bounces them to onboarding if it's still pending.

Both flows already exist; this just exposes a way to mint a fresh token
without sending an email. The token has a 24h hard expiry and is consumed
on successful completion of the flow, so a leaked or screenshot link
can't be replayed against a different user later in the day. Each
generation is audit-logged with the admin's id, the target user's id +
email, and the link kind.

UI: button next to Resend Invite on /admin/members/[id]; opens a dialog
with a read-only input pre-selected, a one-click copy button, expiry
timestamp, and a warning not to paste in public channels.

Side benefit: users like Didier who have stale JWTs from a recent role
change can use a fresh access link to force a re-login that picks up
their updated role.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 17:28:43 +02:00
Matt
9a9a73dde2 fix(docker): query _prisma_migrations directly for failed-migration auto-resolve
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m9s
The previous regex against `prisma migrate status` output silently drifted
out of sync with Prisma 6's wording, so today's failed migration on prod
was never auto-resolved — the container crash-looped and required a
manual DELETE on _prisma_migrations to recover.

Truth lives in the table: a row with `finished_at IS NULL AND
rolled_back_at IS NULL` is an unresolved failure. Query that directly via
the Prisma client (already shelled out for the user-count check below)
and loop until none remain (with a 5-iteration safety bound).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 17:10:44 +02:00
Matt
cad5b3fc28 fix(migration): drop default on User.roles before altering type
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m3s
The 20260507151706_drop_award_master_role migration failed on prod with
'default for column "roles" cannot be cast automatically to type
"UserRole_new"[]'. Postgres won't auto-cast the @default([]) binding
through an enum-type swap. Same DROP DEFAULT / SET DEFAULT dance the
singular `role` column already had.

The original migration ran in a transaction that fully rolled back, so
the DB is unchanged — the fixed migration can be applied as-is once the
failed record is resolved (DELETE FROM _prisma_migrations WHERE
migration_name='20260507151706_drop_award_master_role').

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 16:31:08 +02:00
Matt
7bc2b84d1d refactor(awards): remove AWARD_MASTER role, fold features into jury chair flow
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m5s
The AWARD_MASTER role split sponsor jurors into a parallel UI that hid
project files (only showed when the award was anchored to an evaluation
round) and duplicated the jury voting path with no real difference in
authority — tie-break and finalize were already governed by AwardJuror.isChair
regardless of the user's global role. Inviting a juror via the award page
defaulted to AWARD_MASTER, randomly fragmenting jury panels.

This collapses the role into JURY_MEMBER + isChair:

- specialAward.getMyAwardDetail now returns evaluation scores, chair
  visibility into other jurors' votes, and juror roster
- specialAward.submitVote accepts an optional justification per vote
- specialAward.confirmWinner moves from awardMasterProcedure to
  protectedProcedure (juror+chair check inside)
- bulkInviteJurors creates JURY_MEMBER accounts and, when the award has
  a juryGroupId, also adds them to that JuryGroup so they appear on
  the round-page jury panel
- jury award page renders justification, eval-score badges, and a
  chair tools panel with vote tally + finalize-winner CTA
- juryGroup.list includes attached SpecialAwards; the jury-list UI
  shows a trophy pill alongside round pills
- (award-master) route group, awardMasterProcedure, AWARD_MASTER role
  enum value, and AWARD_MASTER_DECISION decisionMode are deleted
- migration demotes any residual AWARD_MASTER users to JURY_MEMBER and
  recreates the UserRole enum without the value

Coup de Coeur on prod: Didier (the sponsor juror added today as
AWARD_MASTER by the buggy invite form) was migrated to JURY_MEMBER and
attached to the existing "Coup de Coeur" JuryGroup; the SpecialAward
itself was linked to that group (juryGroupId was NULL).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 15:21:09 +02:00
Matt
a9116b5833 fix(applicant-feedback): correct dashboard card scale + visible criterion bars
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m39s
- Dashboard summary card: globalScore is /10 (was /100) and DELIBERATION
  rounds skip the avg-score row (rank, not score)
- Per-criterion progress bars on full evaluations page: bg-brand-dark is
  not a defined class and rendered invisible; switched to bg-brand-blue

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 12:34:45 +02:00
Matt
b7a4eac2b1 fix(applicant-feedback): correct scales, hide jury-internal criteria, declutter UI
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m11s
- globalScore is /10 (was hardcoded /100); use real round.name (was 'Round N')
- Render criteria by type: numeric uses parsed scale (1-10/0-10/1-5),
  text shows as quoted block, boolean/advance hidden as jury-internal
- Drop redundant cross-round stat strip and per-round Score Comparison
- Plain language: 'Lowest/Highest' instead of 'Range', 'reviews' not 'evaluations'
- Settings toggles update optimistically (was waiting for refresh)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 12:21:52 +02:00
Matt
55e6abc161 feat(finalization): winner email + UI for terminal rounds
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m7s
When finalizing a round with no further round to advance to, passing teams
are winners — not advancers. Detected for both special-award terminal rounds
(label = award name) and the main competition's terminal round (label =
competition name). Wording uses "a winner" so it works for both single-winner
awards and top-N main-track outcomes.

Adds AWARD_WINNER_NOTIFICATION email type + template ("Your project has won!"
with "our team will reach out about next steps" copy). Routes through the
notification dispatch table the same way ADVANCEMENT_NOTIFICATION does.

The FinalizationSummary gains a `winnerContext` field; the admin finalization
tab uses it to swap "X projects will advance to Y" → "X winners will be
notified for [label]" and renames "Advancement Message" → "Winner Message"
in the custom-message field. The email-preview button shows the winner
template when applicable.

In-app notification (bell icon) gets matching winner copy.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 20:30:35 +02:00
Matt
e8d0bb050f fix(finalization): skip MENTORING rounds in advancement display copy
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m10s
The mentoring round is opt-in (eligibility: requested_only) and only a subset
of advancing teams enter it; the rest auto-pass through. Showing it as the
"next round" in the finalization summary and advancement emails was misleading
since Grand Finale is the shared destination for all advancing teams.

Routing is unchanged — targetRoundId still points to the next round by sortOrder
(may be MENTORING) so opt-in handling is preserved. Only the user-facing label
skips MENTORING.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 20:02:35 +02:00
Matt
6e36704bb1 feat(awards): notify jurors on assignment + admin reminder button
All checks were successful
Build and Push Docker Image / build (push) Successful in 11m41s
The previous addJuror / bulkAddJurors / bulkInviteJurors flows silently
created AwardJuror rows with no notification when the user already had
an account. The result: assigned jurors had no idea they were assigned
unless they happened to log in and check /jury/awards manually.

Three changes:

1. New email template + sender (sendAwardJurorNotificationEmail). Tells
   the juror what the award is, how many projects are eligible, when
   voting closes, and links straight to /jury/awards/<id>. Reused for
   both the initial assignment notification and admin reminders.

2. Auto-send on assignment. addJuror / bulkAddJurors / bulkInviteJurors
   now send the email to newly-attached jurors. bulkInviteJurors checks
   for a prior AwardJuror row before sending so duplicate "Bulk Invite"
   clicks don't spam jurors who were already assigned. addJuror /
   bulkAddJurors accept a `sendEmail` flag so admin tooling can opt out.

3. New admin procedure specialAward.notifyJurors(awardId, userIds?,
   customMessage?). Surfaced in the Jurors tab as a "Send reminder to
   all" button at the top and a per-row mail icon for individual
   reminders. Audit-logged with action: 'JUROR_REMINDER'.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 13:17:29 +02:00
Matt
7d72ee271f fix(security): route ai-shortlist through canonical anonymization pipeline
ai-shortlist was sending raw project.description, raw juror feedback
text (feedbackGeneral / feedbackText), and full extracted file text
content directly to OpenAI as part of the user prompt. Its only
"anonymization" was renaming `id` to `anonymousId`. This bypassed the
GDPR contract documented in the file's own header comment ("All project
data is anonymized before AI processing — No personal identifiers in
prompts") and in CLAUDE.md ("All AI calls anonymize data before sending
to OpenAI").

A juror writing "Contact applicant Jane Doe at jane@example.com" in
feedback would ship that PII to OpenAI verbatim every time an admin
generated a shortlist. Same for any names / emails / phone numbers
embedded in extracted PDF text.

generateCategoryShortlist now mirrors the pattern used by ai-filtering /
ai-tagging / ai-award-eligibility:

- toProjectWithRelations + anonymizeProjectsForAI(_, 'FILTERING')
- validateAnonymizedProjects gate that aborts on detected PII
- Aggregates (avgScore, evaluationCount, feedbackSamples) computed
  separately and merged onto the anonymized projects; each feedback
  sample passes through sanitizeText (strips email/phone/url/ssn) and
  is truncated to 1000 chars.

Defense-in-depth fix in the shared helper: anonymizeProjectForAI now
also runs sanitizeText over each file's text_content before emitting it
to AI services. Previously the helper passed extracted file text
through unchanged, which would have leaked PII from PDF body text via
ai-filtering / ai-tagging / ai-award-eligibility too if those services
turn on aiParseFiles.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 04:14:58 +02:00
Matt
fbc42f11fd fix(security): defang CSV formula injection in all exports
CSV cells whose first character is one of `=`, `+`, `-`, `@`, `\t`, `\r`
are interpreted as formulas by Excel and LibreOffice when the file is
opened. `=HYPERLINK(...)` and `=WEBSERVICE(...)` execute on cell focus
with no prompt and can exfiltrate row data to an attacker URL; DDE
(`=cmd|...`) reaches RCE behind the "enable content" prompt.

The platform exposes anonymous-attacker reachable sinks:

- `application.submit` is publicProcedure with `projectName` as
  `z.string().min(2).max(200)` — no character filter — so a project
  titled `=HYPERLINK("https://evil/?d="&A1,"Click")` lands in every
  admin export that includes Project.title.
- `userAgent` from any unauthenticated request is persisted to
  `AuditLog.userAgent` and dumped verbatim into the audit-log CSV.

Three independent CSV builders all only escaped commas/quotes/newlines
and missed the formula-prefix class:

- `src/components/shared/csv-export-dialog.tsx` — used by
  export.evaluations, export.assignments, export.filteringResults,
  export.auditLogs, export.projectScores
- `src/components/admin/round/ranking-dashboard.tsx`
- `src/server/routers/lunch.ts` (lunch.exportManifestCsv)

Centralized the fix in a new `src/lib/csv.ts` `csvCell` helper that
prefixes a single quote when the value starts with a formula trigger,
then applies the standard quote/escape rules. Wired into all three
builders.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 04:14:42 +02:00
Matt
9d0beed02f fix(security): file storage authorization hardening
Three separate issues in the file storage layer:

1. IDOR via client-controlled object key in applicant.saveFileMetadata
   and file.replaceFile. Both procedures accepted `bucket` and `objectKey`
   from the client and stored them on a new ProjectFile row attached to
   the caller's own project. Because file.getDownloadUrl authorizes via
   `findFirst({ bucket, objectKey })` -> projectId, an attacker could
   bind another team's storage object to their own project row and then
   download the foreign object through the legitimate authorization
   path. Now both procedures require `bucket === BUCKET_NAME` and the
   `objectKey` to start with the project's sanitized title prefix
   (matches the prefix that generateObjectKey produces server-side).

   New helper `objectKeyBelongsToProject` exported from src/lib/minio.ts;
   `sanitizePath` is now exported as well so the helper can reuse it.

2. Missing per-round scope on file.getBulkDownloadUrls. The single-file
   getDownloadUrl restricts a juror to files in rounds with sortOrder
   <= their assigned round, but the bulk variant only checked that an
   Assignment row existed for the project. A juror assigned only to
   EVALUATION could pull URLs for LIVE_FINAL/DELIBERATION confidential
   files via this endpoint. Now applies the same per-round filter when
   the caller's access to the project is jury-only (mentors / team
   members / award jurors retain unrestricted access, matching
   getDownloadUrl semantics).

3. Same omission on the standalone /api/files/bulk-download REST route.
   Same fix applied there.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 03:30:00 +02:00
Matt
89e637843a fix(security): harden user router role guards + drop self-service email change
Three high-severity issues in user router:

1. user.update accepted both `role` and `roles[]` from input but only
   guarded the singular `role`. A PROGRAM_ADMIN could pass `roles:
   ['SUPER_ADMIN']` and self-escalate. Now applies the same guards to the
   array field and uses both fields when checking the target's current
   admin tier.

2. user.updateRoles only blocked SUPER_ADMIN grants; PROGRAM_ADMIN could
   grant PROGRAM_ADMIN laterally and could pass `roles: []` against any
   existing SUPER_ADMIN to silently demote them. Now blocks PROGRAM_ADMIN
   grants and refuses to mutate any target who currently holds SUPER_ADMIN
   or PROGRAM_ADMIN unless the caller is SUPER_ADMIN.

3. user.bulkUpdateRoles had the same omission and additionally let a
   PROGRAM_ADMIN strip SUPER_ADMIN from every peer admin in one call. Now
   requires SUPER_ADMIN for any add/remove of admin-tier roles, blocks
   modifying admin targets entirely from non-super-admins, and adds a
   PROGRAM_ADMIN self-demote guard.

Plus: user.updateProfile previously let any authenticated user silently
overwrite their own email with no verification or notification — turning
any short-lived session compromise into permanent account takeover via
password reset on the new address. Email is removed from the input
schema; the profile page email field is now read-only with a "contact
an administrator" hint.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 03:29:09 +02:00
Matt
a1c293028a fix(security): per-role visibility on project.list and project.get
project.list previously gated only JURY_MEMBER to assigned projects;
APPLICANT, MENTOR, OBSERVER, AUDIENCE, AWARD_MASTER fell through with
full access to every project across every program (team-member PII,
files, mentor identities). project.get had the same flaw.

Now: SUPER_ADMIN/PROGRAM_ADMIN see all (existing); OBSERVER/AWARD_MASTER
see all (these roles exist for cross-program oversight); JURY_MEMBER
sees only their assignments; MENTOR sees only their mentorAssignments;
APPLICANT sees only their team's projects; AUDIENCE sees nothing.

For users holding multiple roles, the access check uses an OR over the
applicable relationships (e.g. a mentor who is also an applicant sees
both their mentor projects and their team projects).

Existing admin/jury/mentor UIs continue to work because their access
paths are still satisfied. Audience users were not expected to use
project.list in the first place; they now correctly receive an empty
list rather than the full database.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 03:13:19 +02:00
Matt
765bdf9f9e fix(security): restrict file.replaceFile to admins + team members only
Replace was previously accepted from anyone with a relationship to the
project: jury (assignment), mentor (mentorAssignment), or team member.
That allowed jurors and mentors to swap a team's submission, with the
attacker-supplied bucket+objectKey pointing at any object they had
uploaded elsewhere.

Now only admins and the team itself (submitter or TeamMember) can
replace files. Jurors and mentors remain read-only on submissions.
The legitimate UI flow (team-lead replacing files from the applicant
dashboard) is unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 03:13:11 +02:00
Matt
48d29d4a6b fix(security): assignment check on getDiscussion/addComment/getCOIStatus
evaluation.getDiscussion and evaluation.addComment were juryProcedure
that took projectId+roundId from input but never verified the caller
had an Assignment for that project+round. A juror could read foreign
deliberations and inject comments into them.

evaluation.getCOIStatus was protectedProcedure with no ownership check,
returning the full ConflictOfInterest record (including the free-text
description that captures personal/financial relationships) for any
assignmentId.

Both now check that admins are allowed always and otherwise require
assignment ownership. getCOIStatus loads the assignment to verify
caller ownership before returning the COI record.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 03:13:06 +02:00
Matt
90dcb47c25 fix(security): assertWorkspaceAccess on mentor workspace messaging
workspaceSendMessage, workspaceGetMessages, workspaceMarkRead, and
workspaceAddFileComment previously trusted the caller-supplied ID and
only checked workspaceEnabled. Any user with the MENTOR role could
read/post in any workspace, impersonating the assigned mentor and
inserting comments under any team's deliverables.

All four now run assertWorkspaceAccess (assigned mentor or team member
of the project), mirroring the file-handling procedures in the same
router. workspaceMarkRead resolves the message -> workspaceId first,
and additionally short-circuits when the caller is the sender so unread
state stays honest. workspaceAddFileComment resolves the file ->
mentorAssignmentId before the access check.

Procedures downgraded from mentorProcedure to protectedProcedure since
assertWorkspaceAccess is the real gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 03:13:01 +02:00
Matt
35f46c3e34 fix(security): require jury membership for liveVoting.vote
Prevents non-jury authenticated users from casting votes that get
counted in the jury aggregate. Admins are still allowed; everyone else
must be a JuryGroupMember of the round's jury group. Also explicitly
sets isAudienceVote=false on the upsert so audience votes can't be
laundered into jury votes via this path. Audience voting continues to
flow through the existing castAudienceVote publicProcedure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 03:12:54 +02:00
Matt
e0f6b7e741 chore: drop lunch placeholder from edition settings coming-soon card
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:50:39 +02:00
Matt
31b98f6f1e feat: read-only external attendees strip on applicant dashboard
Adds lunch.getProjectExternals (team-member guarded). Strip auto-hides
when no externals attached to the team.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:50:15 +02:00
Matt
df95867465 feat: lunch picker on attending-members card + admin slide-over
LunchPickForm shared between applicant dashboard rows (member-self /
team-lead context) and the admin manifest's edit-pencil slide-over.
Adds lunch.getMemberPick read for the per-row hydration.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:49:08 +02:00
Matt
ec24d404c5 feat: lunch banner on applicant dashboard
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:46:02 +02:00
Matt
618def6174 feat: lunch recap actions card with preview + send + resend confirm
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:45:12 +02:00
Matt
bbfe2d8097 feat: external lunch attendees card + dialog
Adds program.listFinalistProjects helper. Externals dialog supports
both standalone and project-attached entries; manifest's external row
edit-pencil opens this dialog via forwardRef.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:44:38 +02:00
Matt
051dea4d0e feat: lunch manifest card with filters + CSV export
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:42:49 +02:00
Matt
939a13c0e8 feat: lunch dishes card with create/edit/delete
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:42:07 +02:00
Matt
ec00942620 feat: lunch event configuration card
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:41:34 +02:00
Matt
6fcabc89d7 feat: lunch tab scaffold + un-disable trigger
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:40:32 +02:00
Matt
d4e5d54de2 feat: lunch cron endpoints — reminders + recap
Both endpoints follow the existing GET + x-cron-secret pattern. Per-event
try/catch ensures one failing event does not poison the sweep.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:39:51 +02:00
Matt
829a7e457a feat: lunch recap aggregation + sendRecap with forceUpdate gate
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:38:00 +02:00
Matt
05b0412534 feat: lunch reminder + recap email templates
Adds sendLunchReminderEmail and sendLunchRecapEmail. Templates use
Intl.DateTimeFormat with Europe/Monaco zone. Reuses existing
escapeHtml helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:37:17 +02:00
Matt
a671bb853c feat: lunch manifest query + CSV export
Adds buildManifest service shared between getManifest and the recap.
CSV escaper handles commas/quotes/newlines for safe spreadsheet import.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:34:24 +02:00
Matt
d779959e54 feat: lunch member reads — getEventForMember + getTeamPicks
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:33:24 +02:00
Matt
9e14775f08 feat: lunch.upsertPick with role-aware guard + cutoff
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:32:42 +02:00
Matt
06b171b0d4 feat: external lunch attendees CRUD
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:31:28 +02:00
Matt
1f24f5539c feat: dish CRUD on lunch router
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:30:49 +02:00
Matt
7da4200e72 feat: lunch.getEvent + lunch.updateEvent procedures
Lazy-creates LunchEvent on first read or update. Audit-logs every
update with the patched fields.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:30:06 +02:00
Matt
1a0afd8c6e feat: auto-create MemberLunchPick on attendee writes
Adds ensureLunchPickForAttendingMember helper called from confirm,
adminConfirm, and editAttendees attendee-creation paths. No-ops when
the program has no LunchEvent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:28:51 +02:00
Matt
cdb18cc3d1 feat: schema for lunch event, dishes, picks, externals
Adds LunchEvent (1:1 per Program), Dish, MemberLunchPick (1:1 per
AttendingMember), ExternalAttendee + DietaryTag/Allergen enums.
Allergens use the EU 14 regulated list.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:23:55 +02:00
Matt
e16039142e docs: implementation plan for PR 6 — lunch event
Bite-sized TDD tasks covering schema migration, auto-create hook,
lunch router (admin CRUD + mixed-permission upsertPick + member reads
+ manifest + CSV export + recap), email templates, two cron endpoints,
five-card admin UI on Logistics → Lunch tab, applicant dashboard
banner + picker, project-page externals strip, and the edition-settings
cleanup. Cross-references the design spec.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:20:07 +02:00
Matt
1a58b3db1a docs: design spec for PR 6 — lunch event
Locked-in design covering data model (LunchEvent, Dish, MemberLunchPick,
ExternalAttendee + DietaryTag/Allergen enums), tRPC API surface,
admin/team-lead/member UI on Logistics → Lunch tab and applicant
dashboard, reminder + recap email/cron flows, edge cases, and testing
strategy. Ready for implementation plan.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 02:06:28 +02:00
Matt
eb19cb11a1 chore: drop dead Logistics tabs + move visa toggle to settings
- Remove the Documents tab — visa documents are out of scope for this
  edition and there is no other concrete document need.
- Remove the Logistics > Settings disabled tab — every per-edition
  configuration knob now lives at /admin/settings > Edition.
- Replace the inline "Visible to teams" toggle on the Visas tab with a
  small "Edition settings" button that links straight to the
  consolidated settings page. The toggle itself moved to that page in
  the previous commit.
- Drop the now-unused getVisaVisibility / setVisaVisibility wiring
  inside VisasTab. (The procedures still exist server-side; the new
  Edition tab uses program.updateEditionSettings instead.)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 20:09:50 +02:00
Matt
2f59b87e4f feat: Edition tab on /admin/settings
New top-level Edition tab in the admin settings sidebar (under General,
between Defaults and Branding). Driven by the EditionSettingsTab
component which uses the EditionContext to scope to the current edition
and calls program.getEditionSettings / updateEditionSettings.

Three sub-sections:
  - Grand-finale logistics: defaultAttendeeCap, confirmationWindowHours,
    attendeeEditCutoffHours.
  - Visa: visaStatusVisibleToMembers toggle (will be removed from the
    Logistics > Visas tab in the next commit).
  - Coming soon: placeholders for Lunch and Email Templates.

Each numeric input commits on blur; the visa toggle commits immediately.
All writes invalidate the query so the rest of the UI reflects changes
without a refresh.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 20:01:48 +02:00
Matt
78992a493a feat: program.getEditionSettings + updateEditionSettings
Backs the new consolidated Edition tab on /admin/settings.

getEditionSettings returns a merged view of Program-level fields
(defaultAttendeeCap, visaStatusVisibleToMembers) plus LIVE_FINAL round
config (attendeeEditCutoffHours, confirmationWindowHours, with
sensible defaults). Round-derived values are null when the round
doesn't exist yet.

updateEditionSettings is partial — only supplied fields are written.
Round config writes merge into the existing configJson so other keys
are preserved. Audit-logged as PROGRAM_EDITION_SETTINGS_UPDATE.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:59:31 +02:00
Matt
62ab27a05a feat: mentor detail side sheet + Teams column
The mentor list now ends with a Teams column showing chips of each
mentor's active assignments (truncated at 2 + overflow badge). Clicking
any row opens a right-side Sheet with the mentor's profile (expertise,
country, joined date, max assignments) and a per-team activity feed —
project, status (active / completed / dropped), assignment date, and
counts of messages / files / milestones with their last timestamp.

Stat cards on both the Mentor and Mentee panels were stale and not
particularly informative, so they're gone — the table itself is now
the focal element on each panel.

getMentorPool gained an activeTeams[] field; new getMentorDetail query
backs the side sheet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:52:17 +02:00
Matt
030db533e1 fix: size logistics tab bar to fit buttons + horizontal scrollbar
The fixed h-10 wasn't tall enough to fit a 32px tab button plus the
overflow-x scrollbar, so buttons clipped and a vertical scroll appeared
inside the bar. Switching to h-auto + pb-2 lets the bar size naturally
and reserves space below the row for the scrollbar.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:45:52 +02:00
Matt
7824b00ff4 fix: horizontal scroll on logistics tab bar instead of wrapping
Stacking 8 tabs onto two rows looked rough. Switching the TabsList to
w-full + justify-start + overflow-x-auto keeps every tab on one line
and lets the bar scroll horizontally on narrower viewports.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:44:38 +02:00
Matt
46a78c3a74 feat: render visa status + next date on AttendingMembersCard
Each member now sees their own visa status (status badge + next
upcoming date) on the applicant dashboard, sourced from
applicant.getMyVisaApplications. Other teammates' rows still show the
generic "Visa support" badge if they need a visa, since the platform
deliberately scopes visa visibility to the caller. The whole visa
surface auto-hides if the program toggle is off.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:40:25 +02:00
Matt
fe630e0e2d feat: admin Visas tab — table + edit dialog + visibility toggle
Activates the previously-disabled Visas tab on /admin/logistics.

VisasTab renders a flat table joined per attendee per project, sorted
by status priority. Status filter pills mirror the Confirmations tab.
The header carries a "Visible to teams" Switch backed by a new
logistics.getVisaVisibility query and the existing setVisaVisibility
mutation; toggling it controls whether members see their own status.

VisaEditDialog is a per-row editor with a status dropdown,
nationality input, three native date inputs (invitation / appointment
/ decision), and a notes textarea. No file uploads — the platform
deliberately holds zero document artifacts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:37:55 +02:00
Matt
7c86e42413 feat: applicant.getMyVisaApplications gated by program toggle
Returns the caller's visa application rows when the program's
visaStatusVisibleToMembers toggle is on; returns null when it's off
(so the UI can hide the section entirely); returns an empty array
when the toggle is on but the caller has no needsVisa attendees.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:33:40 +02:00
Matt
0e104e0b6f feat: admin visa CRUD procedures
logistics router gains three procedures for the Visas tab:
  - listVisaApplications: program-scoped, joined with project + attendee,
    sorted by status priority (REQUESTED first → NOT_NEEDED last).
  - updateVisaApplication: partial update of status / dates / nationality /
    notes; clears nullable fields on null. Audit-logged as VISA_UPDATE
    with previous + next snapshots.
  - setVisaVisibility: flips Program.visaStatusVisibleToMembers. Audit-
    logged as VISA_VISIBILITY_SET.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:32:52 +02:00
Matt
bdfd99874a feat: auto-create/sync VisaApplication on attendee writes
confirm and adminConfirm now create REQUESTED VisaApplication rows for
every attendee with needsVisa=true, in the same Prisma transaction as
the AttendingMember inserts. editAttendees was extended into a fully
diff-aware sync: existing attendees whose needsVisa flips on get a new
VisaApp; flipping off deletes it; staying true preserves the row (and
its status / notes / dates). Removed attendees cascade automatically
via the FK.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:31:28 +02:00
Matt
289903c8bd feat: schema for visa tracking (additive)
Adds VisaStatus enum, VisaApplication model 1:1 with AttendingMember
(cascade-delete), and Program.visaStatusVisibleToMembers Boolean
toggle. The model intentionally stores process metadata only — status,
optional nationality, key dates, free-text notes. Sensitive documents
(passport scans, invitation letters, decision papers) continue to flow
over email and are never persisted in the platform.

Migration is purely additive: CREATE TYPE / CREATE TABLE / ADD COLUMN /
ADD FK. No DROP / ALTER on existing data.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:28:53 +02:00
Matt
6e5f607425 feat: admin can confirm/decline attendance on team behalf
This edition is being handled manually via email — admins need to
record what each finalist replied. Adds:
  - finalist.adminConfirm — flips PENDING → CONFIRMED with attendees +
    visa flags. Same cap and team-membership checks as the public flow,
    audit-logged as FINALIST_ADMIN_CONFIRM.
  - finalist.adminDecline — flips PENDING → DECLINED with optional
    reason and triggers waitlist promotion. Audit-logged as
    FINALIST_ADMIN_DECLINE.
  - finalist.getConfirmationDetail — feeds the admin attendee picker.
  - Per-row Confirm / Decline actions on the Logistics > Confirmations
    table (PENDING rows only) backed by a shared dialog that switches
    between attendee-picker and reason-input modes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 19:03:01 +02:00
Matt
ff355ee10e feat: gate mentor auto-assign on CONFIRMED finalist status
mentor.autoAssignBulkForRound now skips any project whose finalist
confirmation isn't CONFIRMED — there's no point assigning a mentor to
a team that won't be at the grand finale. Other eligibility rules
(wantsMentorship, admin_selected, already-assigned) are preserved.

Updated existing requested_only and skip-already-assigned tests to seed
CONFIRMED confirmations so they continue to isolate their target gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 18:57:18 +02:00
Matt
903ec2401f chore: bump version to 1.0.0
The platform now covers the full 2026 edition lifecycle — invite-driven
auth, multi-round jury voting, mentor workspace + self-drop, AI
services, finalist confirmation + waitlist, logistics + travel + visa
self-declare, and a public confirmation flow. Marking 1.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 18:55:12 +02:00
Matt
a6284e5c66 feat: edit-attendees dialog + roster card on applicant dashboard
Adds applicant.getMyFinalistConfirmation query (returns roster + cutoff
metadata for the team's confirmation, or null). New AttendingMembersCard
shows the confirmed attendee list and surfaces an Edit dialog to the
team lead — disabled past the editable cutoff. Card auto-hides until the
confirmation reaches CONFIRMED status.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 18:54:40 +02:00
Matt
5b642c3d50 feat: finalist.editAttendees with cutoff and diff-based update
Team-lead-only mutation that replaces the AttendingMember roster on a
CONFIRMED finalist confirmation. Diffs the requested user list against
existing rows: kept rows are updated in place (preserving FlightDetail),
removed rows are deleted, added rows are created. Enforces:
  - team-lead role
  - CONFIRMED status
  - defaultAttendeeCap
  - team-membership of every supplied userId
  - cutoff = LIVE_FINAL.windowOpenAt − attendeeEditCutoffHours (default 48)

Audit-logged as FINALIST_EDIT_ATTENDEES with the diff payload.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 18:50:52 +02:00
Matt
3d8aab46f1 feat: mentor self-drop dialog on project detail page
DropAssignmentDialog with required reason (10-1000 chars) calls
mentor.dropAssignment, redirects to /mentor on success. Button surfaces
in the project header only when the viewer is the assigned mentor and
the assignment is neither dropped nor completed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 18:48:09 +02:00
Matt
3bc1cc14c7 feat: mentor self-drop with required reason
Adds mentor.dropAssignment mutation (mentor-only, ownership-checked, reason
min 10 chars). Filters dropped MentorAssignment rows out of getMyProjects,
getCandidates mentor count, getMentorPool, and getMenteeActivity so they
no longer surface in the mentor or admin UI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 18:44:45 +02:00
Matt
5bdb65181d feat: finalist.unconfirm with mentor cascade
Admin can un-confirm a CONFIRMED finalist (e.g. to allow a category
quota decrease). Sets status to SUPERSEDED, cascades to drop the active
mentor assignment (if any) with droppedBy='finalist_unconfirmed' and
the reason embedded. Mentor receives a MENTEE_DROPPED notification.
Already-completed assignments are preserved untouched.
2026-04-28 18:37:34 +02:00
Matt
e706913a57 feat: add MENTEE_DROPPED + MENTOR_DROPPED notification types 2026-04-28 18:35:50 +02:00
Matt
6487f4b209 feat: schema — mentor assignment drop tracking
Adds 3 nullable fields to MentorAssignment for drop lifecycle:
- droppedAt: timestamp of drop (null while active)
- droppedReason: free text (required when droppedAt is set)
- droppedBy: 'mentor' | 'admin' | 'finalist_unconfirmed'

Migration is purely additive: no DROP, no ALTER COLUMN, no RENAME.
All existing rows automatically get NULL for the new columns.
2026-04-28 18:34:49 +02:00
Matt
57ec28edad feat: logistics page shell + Confirmations/Travel/Hotels tabs
- /admin/logistics page with shadcn Tabs (3 active + 5 disabled "(soon)"
  placeholder tabs for Visas / Lunch / Documents / Email Templates / Settings).
- Sidebar entry "Logistics" between Mentors and Awards (Plane icon).
- Confirmations tab: read-only table with status filter pills, browser-
  local-time deadline display, attendee count, decline reason snippet.
- Hotels tab: single-hotel form (name/address/link/notes) with live
  email-preview card showing what teams will see.
- Travel tab: per-attendee flight tracker with arrival/departure
  datetimes, flight numbers, IATA airports, click-to-toggle status badge,
  edit Sheet, and unfilled/pending/confirmed filter pills.

Smoke-tested end-to-end: navigation, sidebar entry, all three tabs
render, hotel save persists to DB and renders in preview card.
2026-04-28 18:25:29 +02:00
Matt
d1f29a149a feat: list-confirmations admin query 2026-04-28 18:20:40 +02:00
Matt
b1e6eb81eb feat: flight-detail CRUD on logistics router 2026-04-28 18:19:39 +02:00
Matt
497145b983 feat: hotel CRUD on logistics router 2026-04-28 18:18:16 +02:00
Matt
88548cbea3 feat: schema for logistics hotels + flight tracking
Adds 2 new models for grand-finale logistics PR 2:
- Hotel: 1:1 with Program (one per edition); name + address + link + notes
- FlightDetail: 1:1 with AttendingMember; arrival + departure datetimes,
  flight numbers, airports, admin status (PENDING/CONFIRMED), admin notes

Migration is purely additive: no DROP/ALTER COLUMN/RENAME. FKs point
FROM new tables TO existing tables (Program, AttendingMember) with
ON DELETE CASCADE only firing on parent deletion.
2026-04-28 18:17:09 +02:00
Matt
95055e0dae feat: admin UI for finalist slot quotas + waitlist on grand-finale round
- New components/admin/grand-finale/finalist-slots-card: per-category
  quota editor with confirmed/pending counts, dirty-tracking, save button.
  Renders an empty editor for both Startup and Business Concept categories
  even when no quota exists yet.
- New components/admin/grand-finale/waitlist-card: per-category ranked
  waitlist display with status badges + manual-promote AlertDialog
  (audit-logged via FINALIST_MANUAL_PROMOTE).
- Round detail page: embeds both cards conditionally when
  roundType === 'LIVE_FINAL'.
- New finalist router queries: listQuotas, listCategoryCounts (groupBy
  on category+status), listWaitlist (rank-ordered with project relation).

Smoke-tested: setting Startup quota to 3 persists to DB; UI renders
quota editor and waitlist card cleanly with empty state.
2026-04-28 18:07:55 +02:00
Matt
437bed2326 feat: public finalist confirmation page UI
- /finalist/confirm/[token] under (public) route group
- Browser-local-time deadline + zone label + live countdown
- Default-selects up to defaultAttendeeCap team members
- Per-member "Needs visa?" toggle that surfaces only when selected
- Decline AlertDialog with optional reason textarea
- Distinct friendly states for invalid / expired / already-confirmed /
  already-declined / superseded tokens (not generic errors)
- Smoke-tested end-to-end against live dev server: confirmation row
  flipped to CONFIRMED, AttendingMember row created with correct visa flag
2026-04-28 18:04:25 +02:00
Matt
14a81cd6ec feat: auto-cascade cron + admin waitlist management procedures
- expirePendingPastDeadline service: scans PENDING confirmations past
  deadline, marks each EXPIRED + audit-logs, then promotes the next
  waitlist entry per affected category (using each program's grand-final
  round configJson for windowHours).
- /api/cron/finalist-confirmations: hourly cron entrypoint (CRON_SECRET
  header gate), wraps the service.
- finalist.addToWaitlist: insert at a specific rank, shifting later
  entries down (transactional).
- finalist.reorderWaitlist: rewrite a category's rank order in one go,
  using a temp-rank trick to avoid unique-constraint conflicts mid-update.
- finalist.manualPromote: out-of-rank-order admin promote with audit log
  (FINALIST_MANUAL_PROMOTE) + fresh confirmation email.

2 new tests. Suite at 14/14 for finalist-confirmation.
2026-04-28 18:00:47 +02:00
Matt
19ef364c71 feat: public confirm/decline procedures with waitlist auto-promotion
- finalist.getByToken: public lookup of a confirmation by signed token,
  with all the data the public page needs (project, team members, current
  state). Throws on expired/tampered tokens.
- finalist.confirm: validates team membership of every selected user,
  checks against program.defaultAttendeeCap, atomically writes
  status=CONFIRMED + AttendingMember rows in a transaction.
- finalist.decline: captures optional reason, then promotes the next
  WAITING waitlist entry in the same category (no-op if waitlist empty).
  Resolves the new windowHours from the LIVE_FINAL round configJson.
- promoteNextWaitlistEntry service: encapsulates the cascade (mark
  PROMOTED, create fresh PENDING confirmation, send email).
2026-04-28 17:58:31 +02:00
Matt
895be93678 feat: selectFinalists creates PENDING confirmations and sends emails
- New service module createPendingConfirmation: writes a PENDING
  FinalistConfirmation row with a signed token whose exp matches the
  computed deadline.
- selectFinalists admin mutation: reads windowHours from the round's
  configJson.confirmationWindowHours (default 24), validates category
  match + quota, then creates one confirmation per selected project
  and sends a notification email to the team lead. Email failures are
  logged but never roll back the row creation.
- New email helpers: getFinalistConfirmationTemplate +
  sendFinalistConfirmationEmail.
2026-04-28 17:55:09 +02:00
Matt
3ea36296b9 feat: per-category finalist slot quotas with confirmed-count guard 2026-04-28 17:52:22 +02:00
Matt
53a1e62614 feat: HMAC-signed finalist confirmation token 2026-04-28 17:50:17 +02:00
Matt
dff18b17f7 feat: schema for finalist confirmation flow + per-category quotas
Adds 4 new models for grand-finale logistics PR 1:
- FinalistSlotQuota: per-category mutable quotas
- WaitlistEntry: ranked per-category waitlist
- FinalistConfirmation: token-gated confirmation lifecycle (PENDING /
  CONFIRMED / DECLINED / EXPIRED / SUPERSEDED) with optional decline reason
- AttendingMember: who from each team is attending, with visa flag

Plus Program.defaultAttendeeCap (default 3) for the per-edition team
attendance cap.

Migration is purely additive: no DROP/ALTER COLUMN/RENAME on existing
schema. All FKs ON DELETE CASCADE only fire on parent deletion.
2026-04-28 17:49:26 +02:00
Matt
d0058b46ed feat: Mentees & Activity tab on /admin/mentors
Adds a project-centric ops view for mentor management:
- New mentor.getMenteeActivity tRPC procedure aggregates every project
  with wantsMentorship=true and derives a status (unassigned / assigned
  / active / stalled) from the latest message + file activity.
- /admin/mentors becomes a tabbed page: existing Mentor list +
  new Mentees & Activity table with status pills, search, and a
  per-row Assign/Open CTA linking to /admin/projects/[id]/mentor.
- Includes 2 unit tests covering classification + program scoping.

Also: ignore .remember/ (plugin scratch dir).
2026-04-28 16:47:53 +02:00
Matt
11ab0943f6 feat: name current view in role-switcher pill, add Mentors sidebar entry
- Switcher trigger now shows the current view's icon + label with a
  chevron (e.g. "Admin View ⌄") instead of the vague "Switch View".
  Dropdown adds a header, marks the current view with a checkmark,
  and lists each accessible alternative explicitly.
- Adds a "Mentors" entry to the admin sidebar between Juries and
  Awards so the existing /admin/mentors page is reachable from nav.
2026-04-28 16:32:51 +02:00
Matt
e37f3a5874 fix: render enum labels as proper title case
formatEnumLabel was leaving inputs uppercase ("TECHNOLOGY_INNOVATION"
became "TECHNOLOGY INNOVATION"); lowercasing first yields proper
title case ("Technology Innovation") and improves labels app-wide.
Apply it on the project mentor page for Ocean Issue + Category.
2026-04-28 16:28:30 +02:00
Matt
26ff8ed111 feat(workspace): mentor + applicant message previews (§F.2)
mentor.getRecentMessages: last N unread messages from teams across all
of a mentor's assignments. Drives a Recent Messages card on /mentor.

applicant.getMentorConversationPreview: last 3 messages + unread count
for a given project. Drives a 'Conversation with [Mentor]' card on
/applicant — auto-hides when no mentor is assigned.

Both procedures use the existing MentorMessage(projectId, createdAt)
composite index — no new index needed.

Plan: docs/superpowers/plans/2026-04-28-pr6-multi-role-and-workspace-previews.md
2026-04-28 16:14:11 +02:00
Matt
70a9752d73 refactor(layouts): shared RoleSwitcherPill across dashboards (§D.6)
Extract ROLE_SWITCH_OPTIONS + switchableRoles computation from the two
duplicated copies (role-nav.tsx + admin-sidebar.tsx) into a single
src/components/layouts/role-switcher.tsx module.

Adds a RoleSwitcherPill component placed top-right of every dashboard:
  - Hidden for single-role users
  - Hidden during impersonation
  - Same visual + click target across /jury, /mentor, /applicant,
    /observer, /award-master AND /admin (admin layout gains a small
    top-bar to host the pill)

Removes the duplicate role-switcher items from the admin sidebar's
bottom user-menu — one source of truth instead of three.

Plan: docs/superpowers/plans/2026-04-28-pr6-multi-role-and-workspace-previews.md
2026-04-28 16:09:40 +02:00
Matt
6475d5c418 fix(impersonation): pointer-events + show all roles (§D.4-5)
Banner wrapper now uses pointer-events-none so it doesn't intercept clicks
on the user-menu dropdown sitting underneath; the 'Return to Admin' button
re-enables pointer events on itself only.

Banner also lists every role the impersonated user holds (e.g.
'JURY MEMBER, MENTOR') instead of just the primary role, matching how
multi-role users are surfaced everywhere else.

Plan: docs/superpowers/plans/2026-04-28-pr6-multi-role-and-workspace-previews.md
2026-04-28 16:05:51 +02:00
Matt
432470083c feat(admin): bulk role updates + mentor-onboarding email (§D.2-3)
user.bulkUpdateRoles({userIds, addRole?, removeRole?}) batches role
changes across up to 200 users with a SUPER_ADMIN self-demote guard.
When MENTOR is freshly added, fires sendMentorOnboardingEmail once per
user, gated by User.mentorOnboardingSentAt for idempotency. Audit log
entry per user changed.

UI: 'Add MENTOR role' button surfaces in the existing /admin/members
bulk-selection toolbar when ≥1 user is selected. Other roles
(OBSERVER / AWARD_MASTER) supported by the procedure but not yet wired
to UI; one button keeps the toolbar minimal until a clear need arises.

Tests cover happy path, idempotency on second call, removeRole semantics,
and the SUPER_ADMIN self-demote guard.

Plan: docs/superpowers/plans/2026-04-28-pr6-multi-role-and-workspace-previews.md
2026-04-28 16:05:16 +02:00
Matt
0c2b2d1f96 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
2026-04-28 16:00:56 +02:00
Matt
cedd188328 feat(email): mentor-onboarding email template + sender (§D)
One-shot email sent when a user is first granted the MENTOR role.
Subject: 'Welcome to MOPC mentoring'. Includes a CTA to /mentor and
a hint about the Switch View pill for multi-role users.

Idempotency lives at the call site (User.mentorOnboardingSentAt
checked in user.bulkUpdateRoles / user.updateRoles).

Plan: docs/superpowers/plans/2026-04-28-pr6-multi-role-and-workspace-previews.md
2026-04-28 15:58:17 +02:00
Matt
75c8829c3f feat(db): add User.mentorOnboardingSentAt for one-shot onboarding email (§D)
Single nullable DateTime column. No backfill. Catalog-only ALTER TABLE —
sub-millisecond on PostgreSQL regardless of table size. The column is
unused until the bulk role-update flow wires it up as an idempotency
stamp for the mentor-onboarding email.

Plan: docs/superpowers/plans/2026-04-28-pr6-multi-role-and-workspace-previews.md
Spec: docs/superpowers/specs/2026-04-28-mentor-round-readiness-design.md §D
2026-04-28 15:57:09 +02:00
Matt
08829df54d fix(mentor): show non-suspended users in pool + picker (§B/§C)
mentor.getCandidates and mentor.getMentorPool both filtered on
status='ACTIVE', which excluded every seeded mentor (status=NONE)
and any INVITED mentor. Production scenario: PR 4's Manual Picker and
PR 5's pool counts both rendered empty against real data.

Filter changed to status != SUSPENDED — admins want to see all mentors
they manage (including INVITED + NONE), but not suspended ones.

Found via Playwright smoke of PR 5: pool count read 0 against 4 seeded
mentors with roles[]=['MENTOR'], status='NONE'.
2026-04-28 15:32:28 +02:00
Matt
34bd267c32 feat(admin): real /admin/mentors list page (§B)
Replaces the redirect-to-/admin/members stub with a sortable, searchable
list of all MENTOR-role users powered by mentor.getMentorPool. Columns:
name, expertise tags, country, active count, completed count, capacity
remaining, last activity. Header summary cards show pool size, total
active assignments, and average load.

Row links continue to /admin/members/[id]; /admin/mentors/[id] remains
a redirect (mentor-detail view deferred to a future PR).

Plan: docs/superpowers/plans/2026-04-28-pr5-mentor-round-overview.md
2026-04-28 15:28:09 +02:00
Matt
a0a2c5f06a feat(mentor): mentoring-specific Round Overview card grid (§B)
Renders above Round Details when round.roundType === 'MENTORING':
  - Top-line counts: requested + assigned (with awaiting badge)
  - Request window: countdown pill (amber <48h, red <12h)
  - Mentor pool: size + avg load + 'View all' link to /admin/mentors
  - Workspace activity: msgs / files / milestones / last activity

Round Details panel now shows 'Mentor Pool: N members' (linked) instead
of an always-empty 'Jury Group' row on MENTORING rounds.

Plan: docs/superpowers/plans/2026-04-28-pr5-mentor-round-overview.md
2026-04-28 15:26:31 +02:00
Matt
f9bffabf05 feat(mentor): getRoundStats + getMentorPool procedures (§B)
- getRoundStats(roundId): totals + requested/assigned/awaiting counts +
  request-window deadline (windowOpenAt + mentoringRequestDeadlineDays) +
  workspace activity (msgs / files / milestones / lastActivityAt).
- getMentorPool({programId?}): all MENTOR-role users with current/completed
  assignment counts, capacity remaining, last activity. Drives both the
  round-overview pool card and the /admin/mentors list page.
- Tests cover empty rounds, mixed-state rounds, and capacity arithmetic.

Plan: docs/superpowers/plans/2026-04-28-pr5-mentor-round-overview.md
Spec: docs/superpowers/specs/2026-04-28-mentor-round-readiness-design.md §B
2026-04-28 15:24:07 +02:00
Matt
64668b047e chore: one-shot script to remove leaked test data from dev DB
Test runs that crash before reaching afterAll leave orphan @test.local
users + programs (Test Program / getCandidates- / bulk- / source-flag-
/ mentor-files- name patterns). Mirrors tests/helpers.ts cleanupTestData
cascade order. Idempotent — safe to re-run any time the dev DB picks up
test pollution.

Run: npx tsx scripts/cleanup-test-pollution.ts
2026-04-28 15:15:56 +02:00
Matt
2b07c12c18 feat(mentor): round-level auto-fill toolbar on Projects tab (§C)
Adds an 'Auto-fill remaining' button above ProjectStatesTable on the
MENTORING round Projects tab. Calls mentor.autoAssignBulkForRound,
respecting the round's configJson.eligibility:
  - requested_only / all_advancing: enabled, count from new
    round.getProjectsNeedingMentor query
  - admin_selected: disabled with explanatory copy

Plan: docs/superpowers/plans/2026-04-28-pr4-mentor-assignment-ux.md
2026-04-28 14:58:32 +02:00
Matt
ddae34c8f5 feat(mentor): rewrite project mentor-assignment page (§C)
Replaces single-section AI-only stub with three sections (Project Context,
Currently Assigned, Pick a Mentor). Pick a Mentor is a tab strip:
  - Manual Picker (default): all MENTOR-role users sorted by expertise
    overlap %, with search + load/capacity columns. Assign sends
    method=MANUAL.
  - AI Suggestions: existing pane, with an amber 'AI matching unavailable'
    banner + 'Tag overlap' pills when OPENAI_API_KEY is unset.

Plan: docs/superpowers/plans/2026-04-28-pr4-mentor-assignment-ux.md
2026-04-28 14:56:46 +02:00
Matt
4874491b18 feat(mentor): getCandidates + autoAssignBulkForRound procedures (§C)
- getCandidates: lists MENTOR-role users with expertise-overlap %, load,
  capacity. Drives the manual picker on /admin/projects/[id]/mentor.
- autoAssignBulkForRound: round-scoped bulk auto-fill respecting the
  round's configJson.eligibility (requested_only / all_advancing /
  admin_selected). Skips already-assigned projects.
- getSuggestions returns source: 'ai' | 'fallback' so the UI can label
  the AI tab when OPENAI_API_KEY is missing.
- Tests cover ordering, skip-already-assigned, eligibility refusal, and
  the source flag.

Plan: docs/superpowers/plans/2026-04-28-pr4-mentor-assignment-ux.md
Spec: docs/superpowers/specs/2026-04-28-mentor-round-readiness-design.md §C
2026-04-28 14:54:43 +02:00
Matt
c29410fd4e refactor(mentor): extract computeExpertiseOverlap helper (§C prep)
Pure function reused by upcoming mentor.getCandidates + AI fallback path.
Refactors getAlgorithmicMatches to call it. No behavior change.

Plan: docs/superpowers/plans/2026-04-28-pr4-mentor-assignment-ux.md
2026-04-28 14:50:50 +02:00
Matt
b867c45114 feat: Email Team button + custom-email dialog on project page
Adds a PROJECT_TEAM recipient type to the message router (resolver
returns team members + project lead) and an "Email Team" button on
the admin project detail page that opens a self-contained dialog
matching the look of /admin/messages: subject, body (pre-filled
with "Hello [Project Title] team,\n\n"), live HTML preview iframe,
"Send test to me" + "Send to N" actions.

The composer reuses the existing message.previewEmail and
message.send tRPC procedures end-to-end — no parallel email
infrastructure introduced.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 14:29:42 +02:00
Matt
16156111a6 feat: complete MENTORING round config form (§A)
Surfaces every MentoringConfigSchema field on the round Config tab:

- Adds "Mentoring Request Window" card with mentoringRequestDeadlineDays
  numeric input (1-90 days, default 14) and passThroughIfNoRequest toggle
  (default ON; OFF holds projects PENDING until manual mentor assignment).
- Adds inline help-text for the Eligibility dropdown explaining each
  option's effect on auto-PASS behavior.
- Hides the General Settings card on MENTORING rounds (it only renders
  Advancement Targets, which don't apply to a pass-through round).
- Relaxes the Launch Readiness "File requirements set" gate for MENTORING
  rounds without filePromotionEnabled + a target window — file requirements
  only matter when files will be promoted to a downstream submission window.

Spec: docs/superpowers/specs/2026-04-28-mentor-round-readiness-design.md §A
Plan: docs/superpowers/plans/2026-04-28-pr3-mentoring-config-completeness.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 14:25:23 +02:00
Matt
2e7b545a1b feat: mentor workspace files end-to-end with secure presign
Adds generateMentorObjectKey helper producing
<projectName>/mentorship/<timestamp>-<file>. Replaces the
client-supplied bucket/objectKey on workspaceUploadFile with an
HMAC-signed upload token that binds bucket, objectKey, uploader,
and a 1h expiry — paths can no longer be forged from the client.

Adds workspaceGetUploadUrl, workspaceGetFiles,
workspaceGetFileDownloadUrl, workspaceDeleteFile procedures with
mentor-or-team-member auth. Builds <WorkspaceFilesPanel> and
wires it into the mentor workspace Files tab and the applicant
/applicant/mentor page. Replaces the file-promotion-panel mock
array with a real workspaceGetFiles query.

Tests cover token sign/verify (5), key construction (5), and
end-to-end procedure flow including auth + tampered tokens (7).

Spec: docs/superpowers/specs/2026-04-28-mentor-round-readiness-design.md §F.1
Plan: docs/superpowers/plans/2026-04-28-pr2-mentor-workspace-files.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 13:33:18 +02:00
Matt
dd48db5eea docs: PR 2 plan — mentor workspace files end-to-end (security + UI)
Bundle backend security (HMAC-signed upload tokens, server-built
objectKeys, mentor-or-team-member auth) with the actual file UI
that didn't exist yet (Files tab placeholder, file-promotion-panel
mock array, and applicant-side gap).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 13:27:45 +02:00
Matt
0222da79e0 fix: filter juror preferences banner to review-round groups
The "Confirm Your Evaluation Preferences" banner was including jury
group memberships whose only rounds are LIVE_FINAL or DELIBERATION.
Those ceremonies don't use cap+category preferences, so the sliders
were meaningless. Filter getOnboardingContext to memberships in
groups with at least one INTAKE/FILTERING/EVALUATION/SUBMISSION/
MENTORING round.

Spec: docs/superpowers/specs/2026-04-28-mentor-round-readiness-design.md §E
Plan: docs/superpowers/plans/2026-04-28-pr1-jury-preferences-filter.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 13:08:21 +02:00
Matt
6ef0e50081 docs: PR 1 implementation plan — jury preferences filter
Step-by-step plan for §E. Single-procedure change to filter
getOnboardingContext memberships by linked-round type, plus a
new test file covering review-only, LIVE_FINAL-only, and mixed
group cases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 13:04:29 +02:00
Matt
0c35531b87 docs: extend §D — context-aware default dashboard + standardized role switcher
After review, two additions to the multi-role UX section:

1. Replace static-priority post-login redirect with context-aware
   "go where the work is" via new user.getDefaultDashboard() — a
   juror+observer landing during an active jury round goes to /jury
   even though observer has no work; falls back to static priority
   when no role has actionable work.

2. Standardize the role switcher's location across all dashboards.
   Extract shared useRoleSwitcher hook + new RoleSwitcherPill that
   renders in the top-right of every layout, including admin (which
   currently puts switching in the bottom-left sidebar pill).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 13:00:20 +02:00
Matt
305b35f3a8 docs: mentor round readiness design spec
Comprehensive spec for upcoming MENTORING round (R6): config form
completeness, mentor-specific admin views, manual + auto-fill
assignment UX, multi-role juror→mentor flow, juror preferences filter,
workspace messaging/file UX with server-side path enforcement, and
test coverage. Phased into six independently-shippable PRs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 12:54:50 +02:00
Matt
67f6fc3aba fix: hoist ranking display toggles out of project side panel
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m35s
Balance-juror-grading and factor-advance-votes switches now live as a
compact card above the per-category sections on the rankings page,
always visible. Hiding them inside the project modal was confusing
because flipping them re-sorts the entire list.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 16:50:14 +02:00
Matt
bfa9fb5c83 feat: reset to system-calculated ranking order
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m34s
Adds a 'Reset to system order' button per category (Startups and
Business Concepts). The button only appears when admins have
drag-reordered that category — otherwise there's nothing to reset.
Clicking it wipes that category's reorder history from the snapshot's
reordersJson via a new ranking.clearReorders mutation, after which
the dashboard re-initializes and falls back to the live composite
ranking (balanced/raw score, optionally blended with balanced pass
rate per the toggles).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 14:47:32 +02:00
Matt
900700f6ae fix: advance-vote toggle off restores score-only ranking
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m52s
The toggle was previously a balanced-vs-raw switch for the pass-rate
input, but pass rate was always present in the composite formula.
That contradicted the original ask — admins want a clean way to say
'don't factor in yes/no at all'. Toggle off now drops pass rate from
the composite entirely; the ranking falls back to pure
balanced-or-raw score, matching the behavior before this thread of
work introduced the composite formula.

The label is updated accordingly ('Factor advance votes into ranking'),
and the pass-rate chip on each list row only appears when the toggle
is on so admins aren't shown a number that isn't influencing rank.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 14:45:44 +02:00
Matt
e0103fa956 feat: side panel adds country, description, and per-criterion scores
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m40s
Three side-panel additions on the ranking dashboard's project detail
sheet:

- Project country and team name as outline badges in the header,
  matching the row chips on the list view.
- Collapsible 'Description' box (closed by default) that reveals the
  full project description without leaving the panel.
- Expanding a juror row now shows their per-criterion scores in
  addition to the free-text feedback. Boolean criteria render with
  the form's trueLabel/falseLabel (or 'Yes'/'No' fallback); numeric
  criteria show the raw value next to the criterion label from the
  active form's criteriaJson.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 14:30:12 +02:00
Matt
70f1f64ea3 feat: factor balanced pass rate into composite rankings
The dashboard now computes its own composite ranking score on the
client, blending (balanced-or-raw) average score with (balanced-or-raw)
advance pass rate via the existing scoreWeight / passRateWeight
sliders. Both inputs are toggled independently:

- 'Balance juror grading style (score)' — existing useBalancedRanking
- 'Balance juror approval rate (advance vote)' — new useBalancedPassRate

Both default to true and persist per-round. The pass rate is balanced
the same way scores are: each juror's personal yes-rate gives them a
Bernoulli stddev, each vote is z-normalized against that, and the
project's mean z is rescaled to the round's overall yes rate. A 'yes'
from a juror who rarely says yes counts more than a 'yes' from a
lenient juror.

List rows now show two chips — score (Bal/Raw X.XX) and pass rate
(Bal Yes% / Yes% N%) — so admins can see what's driving the order.
The threshold cutoff and live re-sort effect both use the same
composite formula.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 14:28:49 +02:00
Matt
aed5e078b3 fix: resolve advance decision and surface country on rankings list
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m35s
The side panel only read Evaluation.binaryDecision, which is null when
the round's evaluation form stores the 'proceed to next round' answer
as a boolean criterion in criterionScoresJson (the current round's
shape). project.getFullDetail now resolves a unified `decision` field
per assignment using the same fallback pattern as the ranking router:
prefer the column, fall back to a type='advance' (or legacy 'move to
the next stage' boolean) criterion looked up by id in the active form.

Also: project country in the rankings list now renders whenever it's
present, not only when teamName is also set.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 14:20:09 +02:00
Matt
90c53ef49f feat: poll evaluation scores every 30s and re-sort live
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m32s
The ranking dashboard now refetches roundEvaluationScores every 30
seconds. When a juror submits a new evaluation, the next refetch
updates the raw and balanced averages, and the existing re-sort
effect (now also keyed on snapshot + evalScores, not just the toggle)
re-orders the list in place. Manual reorders persisted on the
snapshot still take precedence — admins who have dragged rows aren't
overruled by score updates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 14:05:40 +02:00
Matt
d0e7bfd60a feat: show active ranking score on each list row
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m20s
Each ranking row now displays a small chip with the score that's
currently driving the rank — the juror-balanced average when the
round's useBalancedRanking toggle is on, the raw juror average when
it's off. The chip is labeled 'Bal' or 'Raw' so the source is
unambiguous. Per-juror score pills stay alongside; full Raw +
Balanced detail still lives in the side panel.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:54:13 +02:00
Matt
9db8312b96 feat: render project averages to two decimals
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m15s
Project-level averages (Raw + Balanced in the side panel, observer
project detail score card, observer preview dialog Avg Score) now
show two decimals (e.g. 8.33 instead of 8.0/8.3) so admins can see
the actual computed value. Per-juror individual scores keep one
decimal — they're submissions, not aggregates. ScorePill gains an
optional precision prop so call sites can opt into 2-decimal display
where the value is an aggregate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:32:52 +02:00
Matt
3b12078e04 feat: mount score explainer dialog in admin and observer surfaces
Adds the 'How scores are calculated' affordance to:
- the admin ranking dashboard side panel (next to the Avg Score card)
- the observer full project detail page (in the score card)
- the observer reports preview dialog (next to Evaluation Summary)

so all three audiences can open the same explainer dialog.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:31:29 +02:00
Matt
b4f5189a8e feat: shared 'How scores are calculated' explainer dialog
Reusable component used by admin and observer surfaces. Covers the
algorithm, a five-step plain-language walkthrough, a worked example
with three jurors of different grading styles, edge cases, and why
both Raw and Balanced are always shown.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:25:20 +02:00
Matt
ee68f8af41 feat: side panel shows per-juror baseline and balanced contribution
Extends the ranking router's roundEvaluationScores response with
per-juror grading stats (mean, stddev, count) plus the round's overall
mean/stddev. The side-sheet juror rows render 'typical X.XX →
contributes Y.YY' next to each Score badge whenever balanced is on,
making the z-rescaling visible per individual rather than only as a
project-level number.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:24:34 +02:00
Matt
664a682585 feat: side panel shows raw + balanced averages, list drops delta
Removes the per-row '⇢ X.X' annotation from the ranking list — the
list view stays clean. The side panel's stats area gains a combined
Avg Score card that shows Raw and Balanced side-by-side, with the
active one (per the round's toggle) bolded and tagged 'used for
ranking'. Pass Rate and Evaluators move below into a 2-col grid.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:23:29 +02:00
Matt
e12f26092a feat: list sort respects useBalancedRanking toggle
The two existing sort sites (initial init + threshold cutoff) now read
from the local toggle. A second effect re-sorts the list when the
toggle flips, but only when no manual reorder is pinned to the
snapshot — persisted manual reorders always win, matching prior
behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:22:11 +02:00
Matt
387f84c338 feat: per-round balanced-scoring toggle in side sheet
A Switch at the top of the project side panel writes
useBalancedRanking onto Round.configJson via the existing round.update
mutation. The flip is shared across all viewers because the value
lives in the round's persisted config; hydration runs on every
roundData refetch so the UI converges quickly when another admin
flips it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:20:21 +02:00
Matt
0680a5d601 feat: add useBalancedRanking flag to round config schema
Defaults to true so existing rounds preserve current behavior; toggled
per-round from the ranking dashboard side panel.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:19:15 +02:00
Matt
6f3e8885e0 feat: resolve observer project page round default and add selector
The observer full project page used to call getProjectDetail without
a round, getting cross-round contaminated stats. It now resolves a
default — the currently OPEN round the project is in, falling back
to the most recently CLOSED one — and renders a selector chip in
the score card whenever the project participated in more than one
candidate round. Initial selection respects the ?round= query param.

A new observer procedure (getProjectRoundsForObserver) returns the
project's open or closed rounds for the picker.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:18:36 +02:00
Matt
cfd9dc6afe fix: scope observer reports preview dialog to selected round
Threads the active roundId through ProjectPreviewDialog and its two
callers (filtering tabs, expandable juror table). When a round is in
scope, the preview's stats card now matches the per-juror list and
the page-level round selector. The roundId prop is optional so the
component still works in any future caller that lacks round context.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:17:18 +02:00
Matt
9a2c10a6f8 fix: scope admin ranking dashboard side-sheet stats to current round
The admin dashboard fetches its side-sheet detail from project.getFullDetail
(not analytics.getProjectDetail as the audit assumed), and that procedure
had the same cross-round contamination bug. Add an optional roundId to
its input, filter the SUBMITTED-evaluations query when provided, and pass
roundId from the dashboard's useQuery so the Avg Score / Pass Rate /
Evaluators card now matches the per-juror list rendered below it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:15:47 +02:00
Matt
97d1f2a3af fix: compute z-context per-round in edition-mode rankings rollup
Previously the edition-level branch of analytics.getProjectRankings
(programId mode) pooled every juror's evaluations across every round
into a single z-normalization context. A juror's mean and stddev are
not stable across round types — quick intake screening produces a
very different grading profile than a deep evaluation round, and
mixing them yields a meaningless personal calibration.

The rollup now groups points by roundId, computes one balance context
per round, and aggregates per-project as the unweighted mean of the
per-round balanced averages. roundId mode is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:14:30 +02:00
Matt
7147115918 fix: scope analytics.getProjectDetail by optional roundId
The procedure pulled every SUBMITTED evaluation for a project across
every round it ever participated in, then computed Avg Score / Pass
Rate / Evaluators from that pool. Meanwhile the per-juror list rendered
in the admin sheet filters to the current round, producing a card that
disagreed with the visible list. With roundId in the input, callers
opt into round-scoped stats; omitting it preserves the old aggregate
behavior for any caller that hasn't been updated yet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:12:27 +02:00
Matt
260baf3a41 docs: add implementation plan for juror-balance toggle and scoping fixes
15 TDD-style tasks covering the round-scoping bug fixes for
getProjectDetail and getProjectRankings, the per-round toggle, the
side-panel deeper display, the shared score explainer dialog, and the
decimal display audit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 12:59:36 +02:00
Matt
64e7be2418 docs: add design spec for juror-balance toggle and round-scoping fixes
Captures the per-round toggle, side-panel deeper display, "How scores
are calculated" explainer dialog, and the cross-round contamination
fixes for getProjectDetail and getProjectRankings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 12:50:32 +02:00
Matt
901d9ba982 feat: rank projects by balanced score in ranking dashboard
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m0s
Initial ranking order, advancement cutoff line, and per-row "advancing"
highlight now all use the juror-balanced (z-score corrected) average,
falling back to the raw avgGlobalScore when no balanced score exists.
The init effect waits for evalScores so the sort has the data it needs.

Admin drag-reorders still take precedence — saved reorders override the
default sort exactly as before.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 15:33:56 +02:00
Matt
2e080a5d09 feat: lift round selector to reports page top-level
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m42s
Top-level selector in the URL (?round=...) drives every single-round tab
(Overview, Analytics, Juror Consistency, Diversity) and narrows the Pipeline
tab to the selected program. Cross-Round keeps its own multi-select because
it compares multiple rounds by design.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 18:39:18 +02:00
Matt
982d5193c5 feat: surface juror-balanced scores and AI calibration advisory
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m27s
Adds a shared juror-balancing utility (z-score normalization per juror,
rescaled back onto the raw 1-10 scale) and wires it into:

- Admin reports page: Top-10 project table now shows "Raw Avg" and
  "Balanced" columns side by side, and the summary stats row shows a
  balanced-average tile. Sort defaults to balanced so harsh and lenient
  graders no longer skew the ranking.
- Ranking dashboard: each project row shows a green/amber balanced-score
  chip next to the raw average when the two differ by ≥0.05, making it
  obvious when juror calibration moved a project's effective ranking.

Also adds AI Juror Calibration Advisory — a mutation that takes
anonymized per-juror stats, calls OpenAI, and produces a plain-language
explanation of the cohort's grading patterns plus per-juror severity
(normal / notable / outlier) with a one-sentence narrative. The advisory
describes the statistical balance that already runs; it does not
introduce a new weighting layer. Rendered as a panel in the Juror
Consistency tab when a specific round is selected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 16:19:00 +02:00
Matt
07dd7a0692 fix: scope analytics assignments to selected round
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m38s
getProjectRankings and getAllProjects in the analytics router were
loading every assignment for each project regardless of the selected
round, so per-round rankings in the admin reports were counting
evaluations from prior rounds and mixing their scores into averages.
A Round 2 view with 3 reviews per project was showing 5 evaluations
and a skewed average that included Round 1 data.

Filter the nested assignments include by the round (or program) the
request is scoped to, matching the pattern already used by the ranking
service and by getStatusBreakdown.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 16:07:26 +02:00
Matt
f36f68bbf9 fix: don't mark next round as current before advancement is declared
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m48s
The applicant timeline sidebar was treating any previous round with
status ROUND_CLOSED as "advanced past", which caused the Grand Finale
to show "You are here" as soon as the semi-final round closed — before
admins declared which teams actually advanced.

Require explicit PASSED/COMPLETED project state on every prior round
before marking the next one as current. A closed-but-unresolved round
now correctly keeps the applicant anchored to it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 14:39:43 +02:00
Matt
be4449e4ef fix: surface advance-type criterion in ranking yes/no counts
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m7s
The ranking dashboard showed 0/X Yes for every project in rounds using
the 'advance' criterion type because the matcher only looked for
type === 'boolean' with a "move to the next stage" label.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 14:03:26 +02:00
Matt
f37a9b49b5 test: add integration coverage for admin proxy evaluation
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m0s
Seven scenarios covering the new admin procedures:
- non-admin users are rejected on adminStart/adminSubmitOnBehalf
- admin can list a juror's assignments with COI flag surfaced
- admin can complete the full draft→autosave→submit cycle with the
  voting window already closed, confirming bypass works
- COI-declared assignments still block admin submission
- feedback minimum length is enforced on admin submit
- adminAutosave refuses to overwrite a SUBMITTED evaluation
- audit log captures admin id, juror id, and bypassedWindow flag

Also swaps a lucide icon alias (FileEdit → Pencil) in the juror
assignments page to avoid the deprecated alias form.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 17:00:03 +02:00
Matt
9cb3b9de13 feat: admin can fill in evaluations on behalf of jurors
All checks were successful
Build and Push Docker Image / build (push) Successful in 11m54s
When a juror cannot connect during an evaluation round, an admin
can now submit evaluations for them.

Router — new admin procedures:
- adminStart / adminAutosave: create and save drafts for any juror.
- adminSubmitOnBehalf: submit bypassing ROUND_ACTIVE and voting-window
  checks. COI block and feedback/criterion validation still enforced.
  Audit log records both admin and juror IDs plus bypassedWindow flag.
- getJurorAssignmentsForRound: list a juror's assignments + eval state.

UI — two new admin pages under /admin/rounds/[roundId]/jurors/[userId]/:
- evaluate: list of pending + completed assignments, COI flagged.
- evaluate/[projectId]: evaluation form reusing the juror's scoring UI,
  with an "acting on behalf" banner and confirmation dialog before
  submit. Back button returns to the assignments list.

Entry point: FilePen icon on each juror row in JuryProgressTable.

Refactor: extracted the scoring form JSX into shared
EvaluationFormFields component so the juror page and the admin proxy
page render identical inputs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 16:41:14 +02:00
Matt
fd4f6dde16 fix: humanize category label in unassigned queue row
Queue payload exposes the field as `category` (aliased from
`competitionCategory`), not `competitionCategory` itself, so the
previous lookup was always undefined and every project rendered as
"No category". Now shows "Startup" / "Business Concept" correctly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 16:40:54 +02:00
Matt
f1955b68f9 feat: show vote status on jury dashboard and add logos to award-master
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m47s
- Jury dashboard now shows "Submitted" badge (green) with "Edit
  Rankings" button when juror has already voted, instead of always
  showing "Vote Now" — prevents confusion about whether vote saved
- Award-master page now shows project logos next to project names
- Backend getMyAwardDetailEnhanced now returns logo URLs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 13:09:34 -04:00
Matt
3a6a9a2b45 feat: add inline file viewer and project logos to award voting
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m24s
- Replace custom download-only file list with full FileViewer component
  that supports inline preview (PDF, video, images, Office docs),
  open in new tab, and download
- Add project logos next to project names in award voting cards
- Backend now returns full file metadata (mimeType, size, pageCount,
  language detection) and project logo URLs
- Award jurors can access files for eligible projects (access control
  already added in prior commit)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 12:49:28 -04:00
Matt
0987d49817 feat: show awards on jury dashboard and add project details to award voting
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m27s
- Jury dashboard now shows active award voting banners with project
  count, deadline countdown, and direct link to vote
- Award voting page shows full project details: description, team
  members, tags, and downloadable files in expandable cards
- Award jurors can now download files for eligible projects (added
  awardJuror access check to file.getDownloadUrl)
- Backend query enhanced to include files and team members

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 12:28:53 -04:00
Matt
acd75427b3 feat: add jury group import to special awards and fix juror dropdown
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m43s
The juror dropdown was always empty because the page requested
perPage: 200 but the user.list API caps at 100 (Zod validation).
Fixed to perPage: 100 with role filter for JURY_MEMBER/AWARD_MASTER.

Added "Import from Jury Group" section to the awards juror tab:
select a jury group, see members with checkboxes (already-assigned
shown as disabled), bulk-add selected members via bulkAddJurors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 11:39:34 -04:00
Matt
eb1e8a7870 fix: case-insensitive email matching in auth and password reset
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m10s
Email lookups used findUnique (case-sensitive on PostgreSQL) but user
input was lowercased, causing login failures for users with mixed-case
emails stored in the DB (e.g. Laurent_Faure@dietsmann.com). Also
normalized 7 affected emails to lowercase on the production DB.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 11:04:31 -04:00
Matt
ec69706bc7 fix: include direct round files in finalization doc count
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m36s
Files uploaded by admins with roundId but no requirementId were not
counted in the finalization page Docs column.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 23:37:52 -04:00
Matt
c7488b3e07 fix: save roundId on admin file upload and group assignments by round
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m45s
The admin upload flow accepted roundId but never wrote it to the
ProjectFile record, causing all admin-uploaded files to appear under
"General". Fixed the create call, the listByProject filter, and the
listByProjectForStage grouping to also use the direct roundId field.

Jury assignments on the project detail page are now grouped by round
with per-round completion counts instead of a flat list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 23:20:48 -04:00
Matt
2344f2e4ff fix: drop stale unique index blocking per-category evaluation forms
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m35s
The category migration used DROP CONSTRAINT but the index was created
with CREATE UNIQUE INDEX, so it was never actually removed. This
prevented saving business concept criteria when startup criteria
already existed at the same version number.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 13:57:36 -04:00
Matt
498baa7e01 feat: add clickable projects and doc counts to finalization page
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m36s
Project names now link to their detail page on all finalization tabs.
Submission/intake rounds show a docs submitted/required column.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 11:38:05 -04:00
Matt
a51241f7ff feat: add multi-role editor to member detail page
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m42s
Adds an "Additional Roles" checkbox section below the primary Role
dropdown. Admins can now grant a user multiple dashboard views (e.g.,
Observer + Jury Member) without changing their primary role. The roles
array is saved alongside the primary role and used by the role switcher.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 21:08:32 -04:00
Matt
2d6cee394f feat: add bulk invite to jury group page + widen member search role filter
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m48s
Adds bulkInviteMembers procedure to juryGroup router and integrates
BulkInviteForm into the jury group members tab. Also removes the
JURY_MEMBER-only filter from the user search — any user can now be
added to a jury group.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:37:25 -04:00
Matt
5537946b5a feat: add bulk invite form to award juror tab, widen role filter to all users
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m57s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:15:55 -04:00
Matt
29502a2b88 feat: add Decision Mode dropdown to award edit page
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:13:51 -04:00
Matt
b901047418 fix: show jury group selector at top of assignments tab when none assigned
Previously showed "Select a jury group below" but the selector was
buried at the bottom (or not rendered at all when no jury was assigned).
Now shows the actual dropdown + "New Jury" button right where the
empty state message was.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:12:25 -04:00
Matt
22a08ef957 feat: add reusable BulkInviteForm component for multi-row name+email invites
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:11:45 -04:00
Matt
158eba416d feat: add auto-retry (3 attempts) for file uploads on flaky connections
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:10:52 -04:00
Matt
97d7f9b625 docs: add implementation plan for award UX fixes and bulk invite
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:36:20 -04:00
328 changed files with 64474 additions and 6795 deletions

6
.gitignore vendored
View File

@@ -62,3 +62,9 @@ build-output.txt
# Private keys and secrets
private/
public/build-id.json
.remember/
# Local tooling + session screenshots
.claude/
.serena/
/*.png

View File

@@ -6,15 +6,38 @@ MIGRATION_RETRY_DELAY_SECONDS="${MIGRATION_RETRY_DELAY_SECONDS:-2}"
ATTEMPT=1
# Auto-resolve any previously failed migrations so deploy can proceed.
# This handles the case where a migration partially applied and was fixed
# in a subsequent deploy — without this, Prisma refuses to run anything.
# This handles the case where a migration failed mid-flight and was then
# fixed in a subsequent deploy — without this, Prisma refuses to run
# anything else (P3009).
#
# We query `_prisma_migrations` directly rather than parsing the output of
# `prisma migrate status`, because that output's wording has shifted between
# Prisma versions and any drift means failed migrations slip through and
# the container crash-loops. Truth lives in the table: a row with
# `finished_at IS NULL AND rolled_back_at IS NULL` is an unresolved failure.
echo "==> Checking for failed migrations..."
MIGRATE_STATUS=$(npx prisma migrate status 2>&1 || true)
FAILED=$(echo "$MIGRATE_STATUS" | sed -n 's/.*The `\([^`]*\)` migration.*failed.*/\1/p' | head -1)
if [ -n "$FAILED" ]; then
echo "==> Found failed migration: $FAILED — marking as rolled back..."
npx prisma migrate resolve --rolled-back "$FAILED"
RESOLVE_ATTEMPTS=0
while [ "$RESOLVE_ATTEMPTS" -lt 5 ]; do
FAILED=$(node -e "
const { PrismaClient } = require('@prisma/client');
const p = new PrismaClient();
p.\$queryRaw\`
SELECT migration_name FROM _prisma_migrations
WHERE finished_at IS NULL AND rolled_back_at IS NULL
ORDER BY started_at ASC LIMIT 1
\`.then(r => { console.log(r[0]?.migration_name || ''); p.\$disconnect(); })
.catch(() => { console.log(''); p.\$disconnect(); });
" 2>/dev/null || echo "")
if [ -z "$FAILED" ]; then
break
fi
echo "==> Found failed migration: $FAILED — marking as rolled back..."
npx prisma migrate resolve --rolled-back "$FAILED" || {
echo "WARNING: prisma migrate resolve failed for $FAILED"
break
}
RESOLVE_ATTEMPTS=$((RESOLVE_ATTEMPTS + 1))
done
echo "==> Running database migrations (with retry)..."
until npx prisma migrate deploy; do

View File

@@ -0,0 +1,747 @@
# Award UX Fixes & Bulk Invite — Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Fix 5 issues: upload auto-retry for flaky connections, bulk invite for award jurors, jury group selector UX, decision mode setting on award edit page, and award juror role filter.
**Architecture:** These are 5 independent fixes touching different files. No schema changes needed — all are UI/UX and router-level changes. The bulk invite is the largest task, requiring a new reusable component, a new tRPC procedure, and integration into the award juror tab.
**Tech Stack:** Next.js 15 App Router, tRPC 11, Prisma 6, shadcn/ui, Tailwind CSS 4
---
## File Map
### New Files
| File | Purpose |
|------|---------|
| `src/components/shared/bulk-invite-form.tsx` | Reusable multi-row name+email invite form component |
### Modified Files
| File | Change |
|------|--------|
| `src/components/shared/requirement-upload-slot.tsx` | Add XHR retry logic (3 attempts, exponential backoff) |
| `src/app/(admin)/admin/awards/[id]/page.tsx` | Integrate bulk invite form, widen role filter, add chair toggle |
| `src/app/(admin)/admin/rounds/[roundId]/page.tsx` | Move jury group selector above empty-state message |
| `src/app/(admin)/admin/awards/[id]/edit/page.tsx` | Add Decision Mode dropdown |
| `src/server/routers/specialAward.ts` | Add `bulkInviteJurors` procedure |
---
## Task 1: Upload Auto-Retry
**Files:**
- Modify: `src/components/shared/requirement-upload-slot.tsx:169-188`
- [ ] **Step 1: Replace the single-attempt XHR upload with a retry wrapper**
In `src/components/shared/requirement-upload-slot.tsx`, find the XHR upload block (lines 169-188). Replace it with a retry loop. The key change is wrapping the XHR Promise in a function and calling it up to 3 times with exponential backoff.
Find this code:
```tsx
// Upload file with progress tracking
await new Promise<void>((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.upload.addEventListener('progress', (event) => {
if (event.lengthComputable) {
setProgress(Math.round((event.loaded / event.total) * 100))
}
})
xhr.addEventListener('load', () => {
if (xhr.status >= 200 && xhr.status < 300) {
resolve()
} else {
reject(new Error(`Upload failed with status ${xhr.status}`))
}
})
xhr.addEventListener('error', () => reject(new Error('Upload failed')))
xhr.open('PUT', url)
xhr.setRequestHeader('Content-Type', file.type)
xhr.send(file)
})
```
Replace with:
```tsx
// Upload file with progress tracking and auto-retry
const maxRetries = 3
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
await new Promise<void>((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.upload.addEventListener('progress', (event) => {
if (event.lengthComputable) {
setProgress(Math.round((event.loaded / event.total) * 100))
}
})
xhr.addEventListener('load', () => {
if (xhr.status >= 200 && xhr.status < 300) {
resolve()
} else {
reject(new Error(`Upload failed with status ${xhr.status}`))
}
})
xhr.addEventListener('error', () =>
reject(new Error('Network error during upload'))
)
xhr.addEventListener('abort', () =>
reject(new Error('Upload was aborted'))
)
xhr.open('PUT', url)
xhr.setRequestHeader('Content-Type', file.type)
xhr.send(file)
})
break // Success — exit retry loop
} catch (uploadErr) {
if (attempt < maxRetries) {
const delay = attempt * 2000 // 2s, 4s
toast.info(`Upload interrupted, retrying... (${attempt}/${maxRetries})`)
setProgress(0)
await new Promise((r) => setTimeout(r, delay))
} else {
throw uploadErr // Final attempt failed — propagate to outer catch
}
}
}
```
- [ ] **Step 2: Verify it compiles**
```bash
powershell -ExecutionPolicy Bypass -Command "npx tsc --noEmit 2>&1 | Select-String 'requirement-upload'"
```
Expected: No errors for this file.
- [ ] **Step 3: Commit**
```bash
git add src/components/shared/requirement-upload-slot.tsx
git commit -m "feat: add auto-retry (3 attempts) for file uploads on flaky connections
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>"
```
---
## Task 2: Bulk Invite Form Component
**Files:**
- Create: `src/components/shared/bulk-invite-form.tsx`
- [ ] **Step 1: Create the reusable bulk invite component**
Create `src/components/shared/bulk-invite-form.tsx`. This is a multi-row form where each row has Name + Email fields, with an "Add Row" button and a "Send Invites" button.
```tsx
'use client'
import { useState } from 'react'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { toast } from 'sonner'
import { Plus, Trash2, Send, Loader2 } from 'lucide-react'
interface InviteRow {
name: string
email: string
}
interface BulkInviteFormProps {
onSubmit: (rows: InviteRow[]) => Promise<void>
isPending?: boolean
/** Label for the submit button */
submitLabel?: string
}
const emptyRow = (): InviteRow => ({ name: '', email: '' })
export function BulkInviteForm({
onSubmit,
isPending = false,
submitLabel = 'Send Invites',
}: BulkInviteFormProps) {
const [rows, setRows] = useState<InviteRow[]>([emptyRow()])
const updateRow = (index: number, field: keyof InviteRow, value: string) => {
setRows((prev) => prev.map((r, i) => (i === index ? { ...r, [field]: value } : r)))
}
const addRow = () => setRows((prev) => [...prev, emptyRow()])
const removeRow = (index: number) => {
if (rows.length <= 1) return
setRows((prev) => prev.filter((_, i) => i !== index))
}
const validRows = rows.filter(
(r) => r.email.trim() && r.email.includes('@')
)
const handleSubmit = async () => {
if (validRows.length === 0) {
toast.error('Please enter at least one valid email address')
return
}
// Check for duplicate emails
const emails = validRows.map((r) => r.email.trim().toLowerCase())
const dupes = emails.filter((e, i) => emails.indexOf(e) !== i)
if (dupes.length > 0) {
toast.error(`Duplicate email: ${dupes[0]}`)
return
}
await onSubmit(validRows.map((r) => ({ name: r.name.trim(), email: r.email.trim() })))
setRows([emptyRow()])
}
return (
<div className="space-y-3">
<div className="space-y-2">
{rows.map((row, index) => (
<div key={index} className="flex items-end gap-2">
<div className="flex-1 space-y-1">
{index === 0 && (
<Label className="text-xs text-muted-foreground">Name</Label>
)}
<Input
placeholder="Full name"
value={row.name}
onChange={(e) => updateRow(index, 'name', e.target.value)}
disabled={isPending}
/>
</div>
<div className="flex-1 space-y-1">
{index === 0 && (
<Label className="text-xs text-muted-foreground">
Email <span className="text-destructive">*</span>
</Label>
)}
<Input
type="email"
placeholder="email@example.com"
value={row.email}
onChange={(e) => updateRow(index, 'email', e.target.value)}
disabled={isPending}
/>
</div>
<Button
variant="ghost"
size="icon"
onClick={() => removeRow(index)}
disabled={rows.length <= 1 || isPending}
className="shrink-0"
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
))}
</div>
<div className="flex items-center justify-between">
<Button
variant="outline"
size="sm"
onClick={addRow}
disabled={isPending}
>
<Plus className="mr-1.5 h-4 w-4" />
Add Row
</Button>
<Button
onClick={handleSubmit}
disabled={validRows.length === 0 || isPending}
size="sm"
>
{isPending ? (
<Loader2 className="mr-1.5 h-4 w-4 animate-spin" />
) : (
<Send className="mr-1.5 h-4 w-4" />
)}
{submitLabel} ({validRows.length})
</Button>
</div>
</div>
)
}
```
- [ ] **Step 2: Commit**
```bash
git add src/components/shared/bulk-invite-form.tsx
git commit -m "feat: add reusable BulkInviteForm component for multi-row name+email invites
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>"
```
---
## Task 3: Backend — Bulk Invite Jurors Procedure
**Files:**
- Modify: `src/server/routers/specialAward.ts` — add `bulkInviteJurors` procedure
This procedure accepts an array of `{ name, email }`, creates user accounts (or finds existing ones), assigns them the specified role, adds them as `AwardJuror`, and sends invite emails.
- [ ] **Step 1: Add the `bulkInviteJurors` procedure**
In `src/server/routers/specialAward.ts`, add the following imports near the top (after existing imports):
```typescript
import { generateInviteToken, getInviteExpiryMs } from '@/server/utils/invite'
import { sendJuryInvitationEmail } from '@/lib/email'
```
Check if these are already imported — `generateInviteToken` and `getInviteExpiryMs` are already imported (line 9). `sendJuryInvitationEmail` may not be — add it if missing.
Then add the procedure after the existing `bulkAddJurors` procedure (after ~line 576):
```typescript
/**
* Bulk invite new users as award jurors — creates accounts, assigns role, sends invite emails
*/
bulkInviteJurors: adminProcedure
.input(
z.object({
awardId: z.string(),
role: z.enum(['JURY_MEMBER', 'AWARD_MASTER']).default('AWARD_MASTER'),
invitees: z.array(
z.object({
name: z.string().optional(),
email: z.string().email(),
})
).min(1).max(50),
})
)
.mutation(async ({ ctx, input }) => {
const award = await ctx.prisma.specialAward.findUniqueOrThrow({
where: { id: input.awardId },
select: { id: true, name: true },
})
const results: Array<{ email: string; status: 'created' | 'existing' | 'error'; error?: string }> = []
for (const invitee of input.invitees) {
try {
// Check if user already exists
let user = await ctx.prisma.user.findUnique({
where: { email: invitee.email },
select: { id: true, status: true, role: true },
})
if (!user) {
// Create new user with invite token
const inviteToken = generateInviteToken()
const expiryMs = await getInviteExpiryMs(ctx.prisma)
user = await ctx.prisma.user.create({
data: {
email: invitee.email,
name: invitee.name || null,
role: input.role,
status: 'INVITED',
inviteToken,
inviteTokenExpiresAt: new Date(Date.now() + expiryMs),
},
select: { id: true, status: true, role: true },
})
// Send invite email
const inviteUrl = `${process.env.NEXTAUTH_URL}/accept-invite?token=${inviteToken}`
try {
await sendJuryInvitationEmail(
invitee.email,
invitee.name || null,
inviteUrl,
award.name
)
} catch {
// Email failure shouldn't block the invite
}
results.push({ email: invitee.email, status: 'created' })
} else {
results.push({ email: invitee.email, status: 'existing' })
}
// Add as award juror (skip if already added)
await ctx.prisma.awardJuror.upsert({
where: {
awardId_userId: { awardId: input.awardId, userId: user.id },
},
update: {},
create: { awardId: input.awardId, userId: user.id },
})
} catch (err) {
results.push({
email: invitee.email,
status: 'error',
error: err instanceof Error ? err.message : 'Unknown error',
})
}
}
await logAudit({
userId: ctx.user.id,
action: 'CREATE',
entityType: 'AwardJuror',
entityId: input.awardId,
detailsJson: {
action: 'BULK_INVITE',
awardName: award.name,
role: input.role,
count: input.invitees.length,
results,
},
})
return {
created: results.filter((r) => r.status === 'created').length,
existing: results.filter((r) => r.status === 'existing').length,
errors: results.filter((r) => r.status === 'error').length,
results,
}
}),
```
- [ ] **Step 2: Check that `sendJuryInvitationEmail` is importable**
Verify the import exists in `src/lib/email.ts`:
```bash
grep -n "export.*sendJuryInvitationEmail" src/lib/email.ts
```
Expected: Shows the exported function. If it doesn't exist, check for the actual name and adjust the import.
- [ ] **Step 3: Verify it compiles**
```bash
powershell -ExecutionPolicy Bypass -Command "npx tsc --noEmit 2>&1 | Select-String 'specialAward'"
```
- [ ] **Step 4: Commit**
```bash
git add src/server/routers/specialAward.ts
git commit -m "feat: add bulkInviteJurors procedure — creates accounts, assigns role, sends invites
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>"
```
---
## Task 4: Integrate Bulk Invite into Award Juror Tab + Widen Role Filter
**Files:**
- Modify: `src/app/(admin)/admin/awards/[id]/page.tsx`
Three changes in this file:
1. Widen the `allUsers` query role filter to include `AWARD_MASTER`
2. Add a collapsible "Invite New Jurors" section with the `BulkInviteForm`
3. Wire up the `bulkInviteJurors` mutation
- [ ] **Step 1: Widen the role filter**
At line 405-408, change:
```tsx
const { data: allUsers } = trpc.user.list.useQuery(
{ role: 'JURY_MEMBER', page: 1, perPage: 100 },
{ enabled: activeTab === 'jurors' }
)
```
to:
```tsx
const { data: allUsers } = trpc.user.list.useQuery(
{ page: 1, perPage: 200 },
{ enabled: activeTab === 'jurors' }
)
```
This removes the role filter entirely — `AwardJuror` is role-agnostic, so any user should be selectable. Increase `perPage` to 200 to cover more users.
- [ ] **Step 2: Add the bulk invite mutation**
Near the other mutations (after `removeJuror` at ~line 479), add:
```tsx
const bulkInvite = trpc.specialAward.bulkInviteJurors.useMutation({
onSuccess: (data) => {
utils.specialAward.listJurors.invalidate({ awardId })
toast.success(`${data.created} invited, ${data.existing} already existed${data.errors > 0 ? `, ${data.errors} failed` : ''}`)
},
onError: (err) => toast.error(err.message),
})
```
- [ ] **Step 3: Add the BulkInviteForm to the juror tab**
Add the import at the top of the file:
```tsx
import { BulkInviteForm } from '@/components/shared/bulk-invite-form'
```
In the jurors tab (after the existing "Add Juror" button section, around line 1329), add a separator and the bulk invite form:
```tsx
<Separator className="my-4" />
<div className="space-y-2">
<h3 className="text-sm font-medium">Invite New Jurors by Email</h3>
<p className="text-xs text-muted-foreground">
Invite new users who don&apos;t have accounts yet. They&apos;ll receive an invitation email and be added as jurors for this award.
</p>
<BulkInviteForm
onSubmit={async (rows) => {
await bulkInvite.mutateAsync({
awardId,
role: 'AWARD_MASTER',
invitees: rows.map((r) => ({ name: r.name || undefined, email: r.email })),
})
}}
isPending={bulkInvite.isPending}
submitLabel="Invite & Add as Jurors"
/>
</div>
```
Make sure `Separator` is imported from `@/components/ui/separator` (check existing imports).
- [ ] **Step 4: Verify it compiles**
```bash
powershell -ExecutionPolicy Bypass -Command "npx tsc --noEmit 2>&1 | Select-String 'awards/\[id\]'"
```
- [ ] **Step 5: Commit**
```bash
git add src/app/(admin)/admin/awards/[id]/page.tsx
git commit -m "feat: add bulk invite form to award juror tab, widen role filter to all users
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>"
```
---
## Task 5: Move Jury Group Selector to Top of Assignments Tab
**Files:**
- Modify: `src/app/(admin)/admin/rounds/[roundId]/page.tsx:1787-1793, 1987-2060`
- [ ] **Step 1: Replace the empty-state placeholder with the jury group selector**
In `src/app/(admin)/admin/rounds/[roundId]/page.tsx`, find the "Select a jury group below" placeholder (lines 1787-1793):
```tsx
{!round?.juryGroupId ? (
<Card>
<CardContent className="py-8 text-center">
<p className="text-sm text-muted-foreground">Select a jury group below to get started.</p>
</CardContent>
</Card>
) : (
```
Replace the Card block inside the `!round?.juryGroupId` branch with the actual jury group selector (same UI that's at the bottom). Change it to:
```tsx
{!round?.juryGroupId ? (
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<div>
<CardTitle className="text-base">Jury Group</CardTitle>
<CardDescription>
Select or create a jury group to get started
</CardDescription>
</div>
<Button size="sm" variant="outline" onClick={() => setCreateJuryOpen(true)}>
<Plus className="h-4 w-4 mr-1.5" />
New Jury
</Button>
</div>
</CardHeader>
<CardContent>
{juryGroups && juryGroups.length > 0 ? (
<Select
value="__none__"
onValueChange={(value) => {
if (value !== '__none__') {
assignJuryMutation.mutate({ id: roundId, juryGroupId: value })
}
}}
disabled={assignJuryMutation.isPending}
>
<SelectTrigger className="w-full sm:w-80">
<SelectValue placeholder="Select jury group..." />
</SelectTrigger>
<SelectContent>
<SelectItem value="__none__">No jury assigned</SelectItem>
{juryGroups.map((jg: any) => (
<SelectItem key={jg.id} value={jg.id}>
{jg.name} ({jg._count?.members ?? 0} members)
</SelectItem>
))}
</SelectContent>
</Select>
) : (
<p className="text-sm text-muted-foreground">
No jury groups exist yet. Create one to get started.
</p>
)}
</CardContent>
</Card>
) : (
```
This replaces the unhelpful "Select a jury group below" message with the actual selector, right at the top where the user expects it.
- [ ] **Step 2: Verify it compiles**
```bash
powershell -ExecutionPolicy Bypass -Command "npx tsc --noEmit 2>&1 | Select-String 'rounds/\[roundId\]'"
```
- [ ] **Step 3: Commit**
```bash
git add "src/app/(admin)/admin/rounds/[roundId]/page.tsx"
git commit -m "fix: show jury group selector at top of assignments tab when none assigned
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>"
```
---
## Task 6: Add Decision Mode Dropdown to Award Edit Page
**Files:**
- Modify: `src/app/(admin)/admin/awards/[id]/edit/page.tsx`
- Modify: `src/server/routers/specialAward.ts` (update mutation input to accept `decisionMode`)
- [ ] **Step 1: Verify the `update` procedure accepts `decisionMode`**
Check if the `specialAward.update` procedure already accepts `decisionMode` in its input schema. Search for `decisionMode` in the update input:
```bash
grep -A5 "decisionMode" src/server/routers/specialAward.ts | head -20
```
If it's NOT in the update input, add it. In the `update` procedure's `.input()` schema (around line 200-220), add:
```typescript
decisionMode: z.enum(['JURY_VOTE', 'AWARD_MASTER_DECISION', 'ADMIN_DECISION']).nullable().optional(),
```
And in the mutation data (the `ctx.prisma.specialAward.update` call), include:
```typescript
decisionMode: input.decisionMode,
```
- [ ] **Step 2: Add state and initialization for decisionMode on the edit page**
In `src/app/(admin)/admin/awards/[id]/edit/page.tsx`, near the other state declarations (around line 54), add:
```tsx
const [decisionMode, setDecisionMode] = useState<'JURY_VOTE' | 'AWARD_MASTER_DECISION' | 'ADMIN_DECISION'>('JURY_VOTE')
```
In the `useEffect` or initialization block where award data populates the form (around line 76), add:
```tsx
setDecisionMode((award.decisionMode as typeof decisionMode) || 'JURY_VOTE')
```
In the submit handler (around line 95), include `decisionMode` in the mutation call.
- [ ] **Step 3: Add the Decision Mode dropdown to the form**
In the grid that contains the Scoring Mode dropdown (around line 199, the `sm:grid-cols-2` div), add a new cell after the Scoring Mode `</div>`:
```tsx
<div className="space-y-2">
<Label htmlFor="decisionMode">Decision Mode</Label>
<Select
value={decisionMode}
onValueChange={(v) => setDecisionMode(v as typeof decisionMode)}
>
<SelectTrigger id="decisionMode">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="JURY_VOTE">Jury Vote tallied from all jurors</SelectItem>
<SelectItem value="AWARD_MASTER_DECISION">Award Master sponsor picks winner</SelectItem>
<SelectItem value="ADMIN_DECISION">Admin Decision admin selects winner</SelectItem>
</SelectContent>
</Select>
</div>
```
- [ ] **Step 4: Verify it compiles**
```bash
powershell -ExecutionPolicy Bypass -Command "npx tsc --noEmit 2>&1 | Select-String 'edit/page'"
```
- [ ] **Step 5: Commit**
```bash
git add "src/app/(admin)/admin/awards/[id]/edit/page.tsx" src/server/routers/specialAward.ts
git commit -m "feat: add Decision Mode dropdown to award edit page
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>"
```
---
## Task 7: Verification
- [ ] **Step 1: Run typecheck**
```bash
powershell -ExecutionPolicy Bypass -Command "npx tsc --noEmit"
```
- [ ] **Step 2: Run tests**
```bash
npx vitest run
```
- [ ] **Step 3: Run build**
```bash
npm run build
```
- [ ] **Step 4: Manual smoke test checklist**
1. **Upload retry:** Find a large file upload, verify progress shows. Simulate by disconnecting network briefly during upload — should see "retrying" toast, then succeed.
2. **Bulk invite:** Go to Awards → [award] → Jurors tab. See the "Invite New Jurors by Email" section. Add 2 rows with name+email, click "Invite & Add as Jurors". Verify users created and added as jurors.
3. **Jury group selector:** Go to Rounds → any evaluation round with no jury assigned. The jury group dropdown should appear at the top, not buried at the bottom.
4. **Decision Mode:** Go to Awards → [award] → Edit. See the Decision Mode dropdown. Select "Award Master" and save. Verify it persists on reload.
5. **Role filter:** On the award juror tab, the "Select a juror" dropdown should show all users, not just JURY_MEMBER.
---
## Key Design Decisions
| Decision | Rationale |
|----------|-----------|
| Retry with exponential backoff (2s, 4s) | Gives time for transient network issues to resolve without overwhelming the server |
| `BulkInviteForm` as shared component | Reusable for jury group invites later, not award-specific |
| `bulkInviteJurors` creates accounts + adds jurors in one call | Avoids requiring admin to do two separate steps (create user, then add juror) |
| `upsert` for AwardJuror in bulk invite | Safe for re-inviting — won't error if user is already a juror |
| Remove role filter entirely from juror dropdown | `AwardJuror` is role-agnostic; any user should be selectable. The old JURY_MEMBER filter was too restrictive. |
| Inline jury group selector when empty | Users couldn't find it at the bottom; showing it where the empty state message is matches user expectation |

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,399 @@
# PR 1 — Jury Preferences Filter (§E)
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Filter the juror "Confirm Your Evaluation Preferences" banner so it only shows jury group memberships whose linked rounds include at least one review-type round (INTAKE/FILTERING/EVALUATION/SUBMISSION/MENTORING). Memberships in groups whose only rounds are LIVE_FINAL or DELIBERATION must be hidden — those ceremonies don't use cap+category preferences.
**Architecture:** Single-procedure change. `getOnboardingContext` in `src/server/routers/user.ts` adds a Prisma `juryGroup.rounds: { some: { roundType: { in: [...] } } }` filter to the `juryGroupMember.findMany` query. No schema migration. No frontend change (the banner consumes the same return shape).
**Tech Stack:** Prisma 6, tRPC 11, Vitest 4. Tests use `prisma` directly + `createCaller(userRouter, user)` from `tests/setup.ts`.
**Spec:** `docs/superpowers/specs/2026-04-28-mentor-round-readiness-design.md` §E.
---
## File map
| File | Action | Responsibility |
|------|--------|----------------|
| `src/server/routers/user.ts` (`getOnboardingContext`, lines 1395-1422) | Modify | Add `juryGroup.rounds.some` filter to membership query |
| `tests/unit/jury-preferences-filter.test.ts` | Create | Three test cases covering the filter behavior |
No new files beyond the test. No schema changes. No client change.
---
## Task 1: Orient on the current implementation
**Files:**
- Read: `src/server/routers/user.ts:1395-1422`
- Read: `src/components/jury/preferences-banner.tsx:17-62`
- Read: `prisma/schema.prisma` (lines 2249-2280 for `JuryGroup`, lines 2149-2200 for `Round`)
- [ ] **Step 1: Read the current procedure**
```bash
sed -n '1395,1425p' /Users/matt/Repos/MOPC/src/server/routers/user.ts
```
Expected: see the `getOnboardingContext: protectedProcedure.query(...)` definition that calls `prisma.juryGroupMember.findMany({ where: { userId: ctx.user.id }, include: { juryGroup: { select: ... } } })`.
- [ ] **Step 2: Confirm the JuryGroup ↔ Round relation field**
```bash
sed -n '2249,2280p' /Users/matt/Repos/MOPC/prisma/schema.prisma
```
Expected: see `model JuryGroup { ... rounds Round[] ... }`. The relation field name is **`rounds`** (plural). This is the field name we'll use in the Prisma `where` filter.
- [ ] **Step 3: Inspect the consumer to confirm return shape stays identical**
```bash
sed -n '17,62p' /Users/matt/Repos/MOPC/src/components/jury/preferences-banner.tsx
```
Expected: see that the banner reads `(ctx?.memberships ?? []).filter(m => m.selfServiceCap === null)`. We are only narrowing the rows returned — the row shape is unchanged — so the banner needs no edit.
---
## Task 2: Write the failing tests
**Files:**
- Create: `tests/unit/jury-preferences-filter.test.ts`
- [ ] **Step 1: Create the test file**
Write the file at `tests/unit/jury-preferences-filter.test.ts`:
```ts
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import { prisma, createCaller } from '../setup'
import {
createTestUser, createTestProgram, createTestCompetition, createTestRound,
cleanupTestData, uid,
} from '../helpers'
import { userRouter } from '../../src/server/routers/user'
describe('user.getOnboardingContext — preferences filter excludes LIVE_FINAL/DELIBERATION-only groups', () => {
let programId: string
let competitionId: string
let juror: { id: string; email: string; role: 'JURY_MEMBER' }
let observerOnlyGroupId: string
let reviewGroupId: string
let mixedGroupId: string
const userIds: string[] = []
beforeAll(async () => {
const program = await createTestProgram({ name: `prefs-filter-${uid()}` })
programId = program.id
const competition = await createTestCompetition(programId)
competitionId = competition.id
const reviewRound = await createTestRound(competitionId, {
name: 'Review Round', slug: `review-${uid()}`, roundType: 'EVALUATION', sortOrder: 0,
})
const liveFinalRound = await createTestRound(competitionId, {
name: 'Final Round', slug: `final-${uid()}`, roundType: 'LIVE_FINAL', sortOrder: 1,
})
const deliberationRound = await createTestRound(competitionId, {
name: 'Delib Round', slug: `delib-${uid()}`, roundType: 'DELIBERATION', sortOrder: 2,
})
const reviewOnlyGroup = await prisma.juryGroup.create({
data: {
id: uid('jg-rev'), competitionId, name: 'Review Only Group',
slug: uid('rev'), defaultMaxAssignments: 30,
},
})
reviewGroupId = reviewOnlyGroup.id
const liveFinalOnlyGroup = await prisma.juryGroup.create({
data: {
id: uid('jg-fin'), competitionId, name: 'Finals Only Group',
slug: uid('fin'), defaultMaxAssignments: 10,
},
})
observerOnlyGroupId = liveFinalOnlyGroup.id
const mixedGroup = await prisma.juryGroup.create({
data: {
id: uid('jg-mix'), competitionId, name: 'Mixed Group',
slug: uid('mix'), defaultMaxAssignments: 20,
},
})
mixedGroupId = mixedGroup.id
await prisma.round.update({ where: { id: reviewRound.id }, data: { juryGroupId: reviewOnlyGroup.id } })
await prisma.round.update({ where: { id: liveFinalRound.id }, data: { juryGroupId: liveFinalOnlyGroup.id } })
const mixedReview = await createTestRound(competitionId, {
name: 'Mixed Review', slug: `mixed-rev-${uid()}`, roundType: 'EVALUATION', sortOrder: 3,
})
const mixedFinal = await createTestRound(competitionId, {
name: 'Mixed Final', slug: `mixed-fin-${uid()}`, roundType: 'LIVE_FINAL', sortOrder: 4,
})
await prisma.round.update({ where: { id: mixedReview.id }, data: { juryGroupId: mixedGroup.id } })
await prisma.round.update({ where: { id: mixedFinal.id }, data: { juryGroupId: mixedGroup.id } })
void deliberationRound // referenced for cleanup; not attached to a group in these scenarios
const u = await createTestUser('JURY_MEMBER')
userIds.push(u.id)
juror = { id: u.id, email: u.email, role: 'JURY_MEMBER' }
await prisma.juryGroupMember.createMany({
data: [
{ id: uid('jgm-rev'), juryGroupId: reviewGroupId, userId: u.id, role: 'MEMBER' },
{ id: uid('jgm-fin'), juryGroupId: observerOnlyGroupId, userId: u.id, role: 'MEMBER' },
{ id: uid('jgm-mix'), juryGroupId: mixedGroupId, userId: u.id, role: 'MEMBER' },
],
})
})
afterAll(async () => {
await cleanupTestData(programId, userIds)
})
it('returns the review-only group membership', async () => {
const caller = createCaller(userRouter, juror)
const ctx = await caller.getOnboardingContext()
const names = ctx.memberships.map((m) => m.juryGroupName).sort()
expect(names).toContain('Review Only Group')
})
it('omits the LIVE_FINAL-only group membership', async () => {
const caller = createCaller(userRouter, juror)
const ctx = await caller.getOnboardingContext()
const names = ctx.memberships.map((m) => m.juryGroupName)
expect(names).not.toContain('Finals Only Group')
})
it('keeps the mixed group (has at least one review round)', async () => {
const caller = createCaller(userRouter, juror)
const ctx = await caller.getOnboardingContext()
const names = ctx.memberships.map((m) => m.juryGroupName)
expect(names).toContain('Mixed Group')
})
it('returns hasSelfServiceOptions=true when at least one membership remains', async () => {
const caller = createCaller(userRouter, juror)
const ctx = await caller.getOnboardingContext()
expect(ctx.hasSelfServiceOptions).toBe(true)
expect(ctx.memberships.length).toBe(2)
})
})
describe('user.getOnboardingContext — juror with only LIVE_FINAL membership', () => {
let programId: string
let juror: { id: string; email: string; role: 'JURY_MEMBER' }
const userIds: string[] = []
beforeAll(async () => {
const program = await createTestProgram({ name: `prefs-only-fin-${uid()}` })
programId = program.id
const competition = await createTestCompetition(programId)
const liveFinalRound = await createTestRound(competition.id, {
name: 'Solo Final', slug: `solo-fin-${uid()}`, roundType: 'LIVE_FINAL', sortOrder: 0,
})
const liveFinalOnlyGroup = await prisma.juryGroup.create({
data: {
id: uid('jg-only-fin'), competitionId: competition.id, name: 'Solo Finals Group',
slug: uid('solo-fin'), defaultMaxAssignments: 10,
},
})
await prisma.round.update({ where: { id: liveFinalRound.id }, data: { juryGroupId: liveFinalOnlyGroup.id } })
const u = await createTestUser('JURY_MEMBER')
userIds.push(u.id)
juror = { id: u.id, email: u.email, role: 'JURY_MEMBER' }
await prisma.juryGroupMember.create({
data: { id: uid('jgm-only-fin'), juryGroupId: liveFinalOnlyGroup.id, userId: u.id, role: 'MEMBER' },
})
})
afterAll(async () => {
await cleanupTestData(programId, userIds)
})
it('returns no memberships and hasSelfServiceOptions=false', async () => {
const caller = createCaller(userRouter, juror)
const ctx = await caller.getOnboardingContext()
expect(ctx.memberships).toEqual([])
expect(ctx.hasSelfServiceOptions).toBe(false)
})
})
```
- [ ] **Step 2: Run the new tests and confirm they FAIL**
```bash
cd /Users/matt/Repos/MOPC && npx vitest run tests/unit/jury-preferences-filter.test.ts 2>&1 | tail -30
```
Expected: at least one of these failures:
- "omits the LIVE_FINAL-only group membership" → `expected [...] not to contain 'Finals Only Group'` (today the procedure returns ALL memberships, so it WILL contain that name).
- "returns no memberships and hasSelfServiceOptions=false" → `expected [{ ... 'Solo Finals Group' ... }] to equal []` (today returns the lone Finals membership).
If all four tests pass with no code change, STOP — that means the filter is already in place or the test fixtures aren't exercising the procedure correctly. Re-read Task 1 outputs.
---
## Task 3: Apply the Prisma filter
**Files:**
- Modify: `src/server/routers/user.ts` (the `findMany` call inside `getOnboardingContext`)
- [ ] **Step 1: Read the current procedure to anchor the edit**
```bash
sed -n '1397,1410p' /Users/matt/Repos/MOPC/src/server/routers/user.ts
```
Expected: lines look like
```ts
getOnboardingContext: protectedProcedure.query(async ({ ctx }) => {
const memberships = await ctx.prisma.juryGroupMember.findMany({
where: { userId: ctx.user.id },
include: {
juryGroup: {
select: {
id: true,
name: true,
defaultMaxAssignments: true,
},
},
},
})
```
- [ ] **Step 2: Add the round-type filter to the `where` clause**
Edit `src/server/routers/user.ts`. Replace the `findMany` call's `where` clause:
```ts
// before
where: { userId: ctx.user.id },
// after
where: {
userId: ctx.user.id,
juryGroup: {
rounds: {
some: {
roundType: {
in: ['INTAKE', 'FILTERING', 'EVALUATION', 'SUBMISSION', 'MENTORING'],
},
},
},
},
},
```
(The `include` block stays unchanged. The `return` block stays unchanged.)
- [ ] **Step 3: Re-run the tests and confirm they all PASS**
```bash
cd /Users/matt/Repos/MOPC && npx vitest run tests/unit/jury-preferences-filter.test.ts 2>&1 | tail -30
```
Expected: 5 passing, 0 failing across the two `describe` blocks.
If any test fails:
- Re-read the procedure: did the edit save? `sed -n '1397,1415p' src/server/routers/user.ts`
- Did the relation field name change? Re-confirm via `grep "rounds " prisma/schema.prisma`
- Did the test cleanup run from a previous failed test leave stale data? Try `npx vitest run -t 'returns the review-only group membership'` in isolation.
---
## Task 4: Run the full unit suite to check for regressions
- [ ] **Step 1: Run all unit tests**
```bash
cd /Users/matt/Repos/MOPC && npx vitest run tests/unit 2>&1 | tail -20
```
Expected: all unit tests pass. The new file should appear in the output as `tests/unit/jury-preferences-filter.test.ts ... ✓`. No previously-passing test should now fail.
If any other test fails: read the failure. The most likely cause is that the Prisma filter unintentionally hides memberships from a test fixture that happens to use a jury group with no attached rounds. If so, the test fixture (not our change) is the problem — flag it and fix the fixture to attach a review-type round.
---
## Task 5: Run typecheck
- [ ] **Step 1: Run the project typecheck**
```bash
cd /Users/matt/Repos/MOPC && npm run typecheck 2>&1 | tail -10
```
Expected: `tsc --noEmit` exits with code 0, no output.
---
## Task 6: Commit
- [ ] **Step 1: Stage the changes**
```bash
cd /Users/matt/Repos/MOPC && git add src/server/routers/user.ts tests/unit/jury-preferences-filter.test.ts
```
- [ ] **Step 2: Verify staged diff is what we expect**
```bash
cd /Users/matt/Repos/MOPC && git diff --cached --stat
```
Expected:
```
src/server/routers/user.ts | ~10 +-
tests/unit/jury-preferences-filter.test.ts | ~140 ++++
2 files changed, ~150 insertions(+), ~3 deletions(-)
```
(Numbers approximate. If anything else is staged, unstage it: `git restore --staged <unwanted-file>`.)
- [ ] **Step 3: Commit**
```bash
cd /Users/matt/Repos/MOPC && git commit -m "$(cat <<'EOF'
fix: filter juror preferences banner to review-round groups
The "Confirm Your Evaluation Preferences" banner was including jury
group memberships whose only rounds are LIVE_FINAL or DELIBERATION.
Those ceremonies don't use cap+category preferences, so the sliders
were meaningless. Filter getOnboardingContext to memberships in
groups with at least one INTAKE/FILTERING/EVALUATION/SUBMISSION/
MENTORING round.
Spec: docs/superpowers/specs/2026-04-28-mentor-round-readiness-design.md §E
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
EOF
)"
```
- [ ] **Step 4: Verify clean status**
```bash
cd /Users/matt/Repos/MOPC && git status --short && git log -1 --oneline
```
Expected: empty status, latest commit is the one just created.
---
## Acceptance criteria
- [ ] `npx vitest run tests/unit/jury-preferences-filter.test.ts` → 5 pass
- [ ] `npx vitest run tests/unit` → no regressions
- [ ] `npm run typecheck` → no errors
- [ ] Commit message references §E of the spec
- [ ] No frontend changes
- [ ] No Prisma migration files changed
## Out of scope (verified)
- The `preferences-banner.tsx` component is NOT modified — the return shape from `getOnboardingContext` is unchanged, only the row count differs.
- Existing tests are NOT modified — the change is additive.
- Prisma schema is NOT touched.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
# PR 3 — MENTORING Round Config Completeness (§A)
> **For agentic workers:** Use superpowers:executing-plans for inline execution.
**Goal:** Surface every `MentoringConfigSchema` field on the round Config tab; hide the empty General Settings card on MENTORING rounds; relax the "File requirements set" Launch Readiness gate when no file promotion is configured.
**Architecture:** UI-only changes. No schema, no API. Three files touched.
**Spec:** `docs/superpowers/specs/2026-04-28-mentor-round-readiness-design.md` §A.
## File map
| File | Action | Why |
|------|--------|-----|
| `src/components/admin/rounds/config/mentoring-config.tsx` | Modify | Add `mentoringRequestDeadlineDays` numeric input + `passThroughIfNoRequest` toggle; add help-text to Eligibility |
| `src/app/(admin)/admin/rounds/[roundId]/page.tsx` | Modify | Hide General Settings card when `round.roundType === 'MENTORING'`; relax File-requirements readiness gate for MENTORING rounds without file promotion configured |
## Tasks
### Task 1: Add the two missing inputs to `mentoring-config.tsx`
- [ ] **Step 1: Patch the file** — append a new "Mentoring Request Window" card BETWEEN the existing two cards, and add help-text to Eligibility. Code in execution.
- [ ] **Step 2: Typecheck**`npm run typecheck`. Expect 0 errors.
### Task 2: Hide General Settings card + relax readiness on MENTORING rounds
- [ ] **Step 1: Patch `(admin)/admin/rounds/[roundId]/page.tsx`** — wrap the General Settings card in `{!isMentoring && (...)}` and extend the file-requirements bypass condition.
- [ ] **Step 2: Typecheck + build** — confirm clean.
### Task 3: Smoke + commit
- [ ] **Step 1: `npm run build`** — confirm clean.
- [ ] **Step 2: Commit** — message references §A.
## Out of scope
Form unit tests (heavy render setup; existing config-save mutation already verified by other PRs). Manual smoke covers the UI work.

View File

@@ -0,0 +1,269 @@
# PR 4: Visa Tracking Implementation Plan
> **For agentic workers:** Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Track the visa-application lifecycle for grand-finale attendees who need a visa, without ever holding sensitive documents (passport scans, visa letters). Documents continue to flow over email; the platform records process metadata only.
**Architecture:** A new `VisaApplication` model 1:1 with `AttendingMember`, auto-created when `needsVisa=true` flips on. Compact 5-stage status enum. A `Program.visaStatusVisibleToMembers` toggle gates whether teams see their own status. Auto-create / auto-cleanup runs in the same writes as `confirm` / `adminConfirm` / `editAttendees` so the lifecycle stays in sync.
**Tech Stack:** Prisma 6 (additive migration), tRPC (router additions to `logistics` + `applicant`), Vitest 4 for TDD, shadcn/ui for the admin tab + member badge.
---
## Task 1: Schema migration (additive)
**Files:**
- Modify: `prisma/schema.prisma`
- Create: `prisma/migrations/<timestamp>_add_visa_tracking/migration.sql`
- [ ] **Step 1: Add the enum + model + program toggle**
```prisma
enum VisaStatus {
NOT_NEEDED
REQUESTED
INVITATION_SENT
APPOINTMENT_BOOKED
GRANTED
DENIED
}
model VisaApplication {
id String @id @default(cuid())
attendingMemberId String @unique
status VisaStatus @default(REQUESTED)
nationality String? // self-declared, optional
invitationSentAt DateTime?
appointmentAt DateTime?
decisionAt DateTime? // GRANTED or DENIED date
notes String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attendingMember AttendingMember @relation(fields: [attendingMemberId], references: [id], onDelete: Cascade)
@@index([status])
}
```
Add the back-reference on `AttendingMember`:
```prisma
visaApplication VisaApplication?
```
Add to `Program`:
```prisma
visaStatusVisibleToMembers Boolean @default(true)
```
- [ ] **Step 2: Generate migration with `--create-only`** and inspect the SQL for any non-additive operations (DROP COLUMN / ALTER COLUMN / RENAME). Should be only `CREATE TYPE`, `CREATE TABLE`, `ALTER TABLE Program ADD COLUMN`, foreign keys.
Run: `npx prisma migrate dev --name add_visa_tracking --create-only`
Then: read migration SQL, verify it's safe.
- [ ] **Step 3: Apply migration + regenerate client**
Run: `npx prisma migrate dev` (apply pending) and `npx prisma generate`.
- [ ] **Step 4: Commit**.
---
## Task 2: Auto-create / cleanup VisaApplication on attendee writes (TDD)
**Files:**
- Modify: `src/server/routers/finalist.ts` (`confirm`, `adminConfirm`, `editAttendees`)
- Create: `tests/unit/visa-application-lifecycle.test.ts`
- [ ] **Step 1: Write failing tests**
```ts
describe('VisaApplication lifecycle', () => {
it('public confirm creates a VisaApplication for each needsVisa=true attendee', async () => {
// setup: PENDING confirmation, 2 team members
// call confirm with both attending, visaFlags { lead: false, member: true }
// assert: 1 VisaApplication with status=REQUESTED for member
})
it('adminConfirm creates a VisaApplication for each needsVisa=true attendee', async () => {
// same as above but via adminConfirm
})
it('editAttendees creates a VisaApplication when an attendee flips to needsVisa=true', async () => {
// setup: CONFIRMED with 1 attendee (lead) needsVisa=false, no VisaApp
// call editAttendees with same attendees but visaFlags { lead: true }
// assert: 1 VisaApplication for lead
})
it('editAttendees deletes the VisaApplication when an attendee flips to needsVisa=false', async () => {
// setup: CONFIRMED with 1 attendee needsVisa=true + VisaApp exists
// call editAttendees same roster but visaFlags { lead: false }
// assert: 0 VisaApplications
})
it('editAttendees preserves an existing VisaApplication when needsVisa stays true', async () => {
// setup: VisaApp with notes='abc', status=APPOINTMENT_BOOKED
// call editAttendees same roster + visaFlags unchanged
// assert: VisaApp unchanged (notes still 'abc', status still APPOINTMENT_BOOKED)
})
it('removing an attendee cascades the VisaApplication', async () => {
// setup: CONFIRMED with 2 attendees, both needsVisa=true with VisaApp rows
// call editAttendees roster of just the lead
// assert: only 1 VisaApp left (for lead)
})
})
```
- [ ] **Step 2: Run tests, expect 6 failures**.
- [ ] **Step 3: Wire auto-create in `confirm` (public)**
After the existing `attendingMember.createMany`, add a follow-up createMany for any user with `visaFlags[uid] === true`:
```ts
// inside the same $transaction
ctx.prisma.visaApplication.createMany({
data: input.attendingUserIds
.filter((uid) => input.visaFlags[uid] === true)
.map((uid) => /* will need attendingMemberId — use a separate post-tx pass */),
})
```
Note: `createMany` won't have the `attendingMemberId` until after the AttendingMember rows are created. Easiest: run the visa creation in a follow-up step (after the transaction commits) by re-querying the attendee rows. The transaction guarantees the attendees are committed; if the visa step fails the worst case is missing visa rows that the admin can manually re-create — but to be safer wrap both in a single Prisma transaction using `$transaction(async (tx) => {...})` callback form.
- [ ] **Step 4: Wire auto-create in `adminConfirm`** — same pattern.
- [ ] **Step 5: Wire diff-aware sync in `editAttendees`**
After the existing diff transaction, derive the desired `needsVisa=true` set, the existing VisaApplication set, and:
- Create rows for new needsVisa=true attendees with no VisaApp
- Delete rows for attendees whose needsVisa flipped to false (or whose AttendingMember was deleted — already cascaded)
- Leave alone rows where needsVisa stays true (preserves notes / status)
- [ ] **Step 6: Run tests, expect green**.
- [ ] **Step 7: Commit**.
---
## Task 3: Admin visa CRUD procedures (TDD)
**Files:**
- Modify: `src/server/routers/logistics.ts` (add 3 procedures)
- Create: `tests/unit/visa-admin.test.ts`
- [ ] **Step 1: Write failing tests**
```ts
describe('logistics.listVisaApplications', () => {
it('returns rows joined with project + attendee for the program, sorted by status priority', async () => {
// 3 visa apps: GRANTED, REQUESTED, APPOINTMENT_BOOKED
// expect order: REQUESTED, INVITATION_SENT (none), APPOINTMENT_BOOKED, GRANTED
})
})
describe('logistics.updateVisaApplication', () => {
it('updates status + dates + notes + nationality', async () => {
// setup: REQUESTED app
// update -> APPOINTMENT_BOOKED + appointmentAt + notes
// assert: row updated, audit log VISA_UPDATE written
})
it('rejects an unknown application id', async () => {
// expect throw /not found/i
})
})
describe('logistics.setVisaVisibility', () => {
it('flips Program.visaStatusVisibleToMembers', async () => {
// default true -> set false -> verify
})
})
```
- [ ] **Step 2: Implement the three procedures** in `logistics.ts`.
- [ ] **Step 3: Run tests, expect green**.
- [ ] **Step 4: Commit**.
---
## Task 4: Member visa query (TDD)
**Files:**
- Modify: `src/server/routers/applicant.ts`
- Modify: `tests/unit/visa-admin.test.ts` (add a describe block) OR new file `tests/unit/visa-member-visibility.test.ts`
- [ ] **Step 1: Write failing tests**
```ts
describe('applicant.getMyVisaApplications', () => {
it('returns the caller-team visa apps when toggle is true', async () => {
// setup: program toggle=true, member with VisaApp
// assert: returns array with that app
})
it('returns null when toggle is false', async () => {
// assert: returns null
})
it('returns empty array when caller has no visa apps', async () => {
// assert: []
})
})
```
- [ ] **Step 2: Implement** — query AttendingMember rows where `userId = caller`, include VisaApplication. Return null if `program.visaStatusVisibleToMembers === false`.
- [ ] **Step 3: Commit**.
---
## Task 5: Admin Visas tab UI
**Files:**
- Modify: `src/app/(admin)/admin/logistics/page.tsx` (un-disable the Visas tab)
- Create: `src/components/admin/logistics/visas-tab.tsx`
- Create: `src/components/admin/logistics/visa-edit-dialog.tsx`
- [ ] **Step 1: Build the tab**
Table columns: Project · Member · Nationality · Status · Next date · Notes (truncated) · Actions. Status filter pills mirror the Confirmations tab. Header has a "Visible to teams" Switch wired to `setVisaVisibility`.
- [ ] **Step 2: Build the edit dialog**
Status dropdown, nationality input, three date pickers (invitation / appointment / decision), notes textarea. Save calls `updateVisaApplication`.
- [ ] **Step 3: Activate the tab** — remove the `disabled` prop and wire `<VisasTab programId={programId} />`.
- [ ] **Step 4: Live smoke** — confirm a finalist with one needsVisa attendee, open Visas tab, edit → verify persistence.
- [ ] **Step 5: Commit**.
---
## Task 6: Member visa surface on AttendingMembersCard
**Files:**
- Modify: `src/components/applicant/attending-members-card.tsx`
- [ ] **Step 1: Wire the query**
Call `applicant.getMyVisaApplications` alongside the existing confirmation query. If the result is null (toggle off), don't render any visa info. Otherwise, render a small status badge + the next upcoming date next to each attendee whose `needsVisa=true`.
- [ ] **Step 2: Live smoke** — toggle visibility off in the admin tab, confirm member can no longer see status.
- [ ] **Step 3: Commit**.
---
## Task 7: Final verification
- [ ] **Step 1: Full vitest**`npx vitest run`. Expect 148 + new tests, all green.
- [ ] **Step 2: Typecheck**`npm run typecheck`.
- [ ] **Step 3: Build**`npm run build`.
- [ ] **Step 4: Live smoke** end-to-end — confirm an attendee with visa, edit status as admin, verify member view, toggle off, verify hidden.

View File

@@ -0,0 +1,142 @@
# PR 5: Settings Consolidation Implementation Plan
> **For agentic workers:** Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Consolidate per-edition logistics configuration onto `/admin/settings` so admins find every knob in one place. Remove dead Logistics tabs and move the visa-visibility toggle out of the Visas tab.
**Architecture:** A new "Edition" tab on `/admin/settings` reads + writes a merged view: `Program` fields (defaultAttendeeCap, visaStatusVisibleToMembers) + the LIVE_FINAL round's `configJson` (attendeeEditCutoffHours, confirmationWindowHours). One reader (`program.getEditionSettings`) + one writer (`program.updateEditionSettings`) so the UI stays simple.
**Tech Stack:** Prisma 6 (no migration — purely a UX layer over existing fields), tRPC, Vitest 4 for the procedure tests, shadcn/ui for the tab + sub-sections.
---
## Task 1: tRPC procedures for edition settings (TDD)
**Files:**
- Modify: `src/server/routers/program.ts`
- Create: `tests/unit/program-edition-settings.test.ts`
- [ ] **Step 1: Failing tests**
```ts
describe('program.getEditionSettings', () => {
it('returns the merged view (program fields + LIVE_FINAL round config)', async () => {
// setup: program with defaultAttendeeCap=5, visaStatusVisibleToMembers=false
// + LIVE_FINAL round with configJson { attendeeEditCutoffHours: 24, confirmationWindowHours: 12 }
// assert: shape { defaultAttendeeCap, visaStatusVisibleToMembers, attendeeEditCutoffHours, confirmationWindowHours }
})
it('falls back to defaults when LIVE_FINAL round has no config', async () => {
// assert: attendeeEditCutoffHours = 48, confirmationWindowHours = 24
})
it('returns nulls for round-derived fields if no LIVE_FINAL round exists', async () => {
// assert: attendeeEditCutoffHours = null, confirmationWindowHours = null
})
})
describe('program.updateEditionSettings', () => {
it('writes program fields + round configJson + audit-logs', async () => {
// call with partial { defaultAttendeeCap: 4, attendeeEditCutoffHours: 36 }
// assert: program.defaultAttendeeCap=4, round.configJson.attendeeEditCutoffHours=36
// assert: AuditLog action=PROGRAM_EDITION_SETTINGS_UPDATE
})
it('preserves untouched configJson keys', async () => {
// round.configJson initially { foo: 'bar', attendeeEditCutoffHours: 48 }
// call with { attendeeEditCutoffHours: 24 }
// assert: round.configJson = { foo: 'bar', attendeeEditCutoffHours: 24 }
})
})
```
- [ ] **Step 2: Run failing tests**.
- [ ] **Step 3: Implement getEditionSettings**
```ts
getEditionSettings: adminProcedure
.input(z.object({ programId: z.string() }))
.query(async ({ ctx, input }) => {
const program = await ctx.prisma.program.findUniqueOrThrow({
where: { id: input.programId },
select: { id: true, defaultAttendeeCap: true, visaStatusVisibleToMembers: true },
})
const round = await ctx.prisma.round.findFirst({
where: { competition: { programId: input.programId }, roundType: 'LIVE_FINAL' },
orderBy: { sortOrder: 'desc' },
select: { id: true, configJson: true },
})
const cfg = (round?.configJson ?? {}) as Record<string, unknown>
return {
programId: program.id,
defaultAttendeeCap: program.defaultAttendeeCap,
visaStatusVisibleToMembers: program.visaStatusVisibleToMembers,
liveFinalRoundId: round?.id ?? null,
attendeeEditCutoffHours: round
? ((cfg.attendeeEditCutoffHours as number | undefined) ?? 48)
: null,
confirmationWindowHours: round
? ((cfg.confirmationWindowHours as number | undefined) ?? 24)
: null,
}
}),
```
- [ ] **Step 4: Implement updateEditionSettings** with merge semantics on configJson + audit log.
- [ ] **Step 5: Run tests, expect green**.
- [ ] **Step 6: Commit**.
---
## Task 2: Edition Settings tab UI
**Files:**
- Create: `src/components/admin/settings/edition-settings-tab.tsx`
- Modify: `src/components/settings/settings-content.tsx` (add the new tab + entry)
- [ ] **Step 1: Build the Edition Settings tab**
Three sub-sections (Card per section):
1. **Grand-finale logistics**`defaultAttendeeCap` (number input), `attendeeEditCutoffHours` (number input with "hours before LIVE_FINAL" hint), `confirmationWindowHours` (number input with "hours from email send" hint).
2. **Visa**`visaStatusVisibleToMembers` Switch + caption.
3. **Coming soon** — placeholder for Lunch + Email Templates that PRs 6 + 7 will fill.
Each input fires `program.updateEditionSettings.useMutation` debounced or on-blur. Toast on success.
- [ ] **Step 2: Wire into `/admin/settings`** — add `<TabsTrigger value="edition">` and `<TabsContent value="edition">` in settings-content. Place before existing tabs.
- [ ] **Step 3: Live smoke** — open settings, verify it renders, toggle visa visibility, verify it persists in the DB and the applicant dashboard hides the surface.
- [ ] **Step 4: Commit**.
---
## Task 3: Cleanup — remove dead Logistics tabs + visibility toggle
**Files:**
- Modify: `src/app/(admin)/admin/logistics/page.tsx`
- Modify: `src/components/admin/logistics/visas-tab.tsx`
- [ ] **Step 1: Remove disabled tabs**
Drop the `<TabsTrigger value="documents" disabled>` and `<TabsTrigger value="settings" disabled>` blocks. Also drop their unused imports (`FileText`, `Settings`).
- [ ] **Step 2: Replace visibility toggle with a hint**
In `visas-tab.tsx`, swap the inline Switch + Label for a small banner: "Configure visibility in Settings → Edition" with a Link to `/admin/settings?tab=edition`. Drop the `getVisaVisibility` query and `setVisaVisibility` mutation usage from this component (keep the procedures — used by the new settings page).
- [ ] **Step 3: Live smoke** — confirm Logistics tab bar shows only the active tabs, visas tab no longer has a toggle, settings page does.
- [ ] **Step 4: Commit**.
---
## Task 4: Final verification
- [ ] **Step 1: Full vitest**`npx vitest run`. Expect 161 + new tests (~5).
- [ ] **Step 2: Typecheck** — clean.
- [ ] **Step 3: Build** — clean.
- [ ] **Step 4: E2E smoke** — open `/admin/settings` → Edition tab, change knobs, verify persistence; confirm the Visas tab no longer shows the toggle and the hint links to settings.

View File

@@ -0,0 +1,182 @@
# PR 7 — "Email Team" Modal on Project Detail Page
> **For agentic workers:** Use superpowers:executing-plans for inline execution.
**Goal:** Add an "Email Team" button to `/admin/projects/[id]` that opens a modal composing a custom email to that project's team. Same look + features as `/admin/messages` (subject, body, live HTML preview, send-to-all). Body pre-filled with `Hello [Project Title] team,\n\n` so admin can edit and add their custom content beneath.
**Architecture:** Adds `PROJECT_TEAM` to the existing `RecipientType` enum (5 places) + a resolver branch. New self-contained `<ProjectEmailDialog>` component reuses the existing `message.previewEmail` and `message.send` procedures. No template-system rewrite.
**Spec:** New ask added during PR review (2026-04-28). Not in original spec but adjacent to §B (admin views).
## File map
| File | Action | Why |
|------|--------|-----|
| `src/server/routers/message.ts` | Modify | Add `PROJECT_TEAM` to 4 input enums + 1 resolver case |
| `src/components/admin/project-email-dialog.tsx` | Create | Self-contained modal with subject + body + live preview + send |
| `src/app/(admin)/admin/projects/[id]/page.tsx` | Modify | Add "Email Team" button next to Edit button; render the dialog |
| `tests/unit/message-recipient-project-team.test.ts` | Create | Resolver returns team members + submittedByUserId |
## Tasks
### Task 1: Backend — `PROJECT_TEAM` recipient type
- [ ] **Step 1: Write failing test**
```ts
// tests/unit/message-recipient-project-team.test.ts
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import { prisma, createCaller } from '../setup'
import {
createTestUser, createTestProgram, createTestProject, cleanupTestData, uid,
} from '../helpers'
import { messageRouter } from '../../src/server/routers/message'
describe('message.previewRecipients — PROJECT_TEAM', () => {
let programId: string
let admin: { id: string; email: string; role: 'SUPER_ADMIN' }
let projectId: string
const userIds: string[] = []
beforeAll(async () => {
const program = await createTestProgram({ name: `proj-team-${uid()}` })
programId = program.id
const lead = await createTestUser('APPLICANT')
userIds.push(lead.id)
const project = await createTestProject(programId, { title: 'TestProj' })
projectId = project.id
await prisma.project.update({ where: { id: projectId }, data: { submittedByUserId: lead.id } })
const member1 = await createTestUser('APPLICANT')
const member2 = await createTestUser('APPLICANT')
userIds.push(member1.id, member2.id)
await prisma.teamMember.createMany({
data: [
{ id: uid('tm'), projectId, userId: member1.id, role: 'MEMBER' },
{ id: uid('tm'), projectId, userId: member2.id, role: 'MEMBER' },
],
})
const a = await createTestUser('SUPER_ADMIN')
userIds.push(a.id)
admin = { id: a.id, email: a.email, role: 'SUPER_ADMIN' }
})
afterAll(async () => {
await cleanupTestData(programId, userIds)
})
it('counts the lead + 2 team members', async () => {
const caller = createCaller(messageRouter, admin)
const result = await caller.previewRecipients({
recipientType: 'PROJECT_TEAM',
recipientFilter: { projectId },
})
expect(result.totalApplicants).toBe(3)
})
it('returns 0 when projectId is missing', async () => {
const caller = createCaller(messageRouter, admin)
const result = await caller.previewRecipients({
recipientType: 'PROJECT_TEAM',
recipientFilter: {},
})
expect(result.totalApplicants).toBe(0)
})
})
```
- [ ] **Step 2: Run, expect FAIL**`'PROJECT_TEAM'` not in enum.
- [ ] **Step 3: Patch `src/server/routers/message.ts`**
Replace ALL FIVE enum literal lines:
```ts
recipientType: z.enum(['USER', 'ROLE', 'ROUND_JURY', 'ROUND_APPLICANTS', 'PROGRAM_TEAM', 'ALL']),
```
with:
```ts
recipientType: z.enum(['USER', 'ROLE', 'ROUND_JURY', 'ROUND_APPLICANTS', 'PROGRAM_TEAM', 'PROJECT_TEAM', 'ALL']),
```
(Use Edit's `replace_all: true` since the line is identical at all 5 occurrences.)
Add a new case in `resolveRecipients` (after `'PROGRAM_TEAM'`):
```ts
case 'PROJECT_TEAM': {
const projectId = filter?.projectId as string
if (!projectId) return []
const [teamMembers, project] = await Promise.all([
prisma.teamMember.findMany({
where: { projectId },
select: { userId: true },
}),
prisma.project.findUnique({
where: { id: projectId },
select: { submittedByUserId: true },
}),
])
const ids = new Set<string>()
for (const tm of teamMembers) ids.add(tm.userId)
if (project?.submittedByUserId) ids.add(project.submittedByUserId)
return [...ids]
}
```
- [ ] **Step 4: Re-run, expect PASS.**
### Task 2: Build `<ProjectEmailDialog>`
- [ ] **Step 1: Create the component** (full code in execution)
Behaviour:
- Open via `open: boolean; onClose: () => void; projectId: string; projectTitle: string` props.
- On open, body field is pre-filled: ``Hello ${projectTitle} team,\n\n``. Cursor placed at the end.
- Subject field default: empty (admin types).
- Live HTML preview pane below the form, calling `message.previewEmail` with `{ subject, body }` (debounced 300ms).
- Recipient count line: calls `message.previewRecipients` with `PROJECT_TEAM` + `{ projectId }`. Shows "Will email N team members."
- "Send Test" button: sends to the admin only via `message.sendTest`.
- "Send" button: calls `message.send` with `recipientType: 'PROJECT_TEAM'`, `recipientFilter: { projectId }`, `deliveryChannels: ['EMAIL']`, `linkType: 'NONE'`.
- On success: toast + close dialog. On error: toast.
### Task 3: Wire the button on project detail page
- [ ] **Step 1: Add button next to Edit** in `src/app/(admin)/admin/projects/[id]/page.tsx`:
```tsx
<Button variant="outline" onClick={() => setEmailDialogOpen(true)}>
<Mail className="mr-2 h-4 w-4" />
Email Team
</Button>
```
(Add `Mail` to the lucide imports. Add `useState` for `emailDialogOpen`.)
Render the dialog at the bottom of the page:
```tsx
{project && (
<ProjectEmailDialog
open={emailDialogOpen}
onClose={() => setEmailDialogOpen(false)}
projectId={project.id}
projectTitle={project.title}
/>
)}
```
### Task 4: Verify + commit
- [ ] `npx vitest run tests/unit` → all pass.
- [ ] `npm run typecheck` → clean.
- [ ] `npm run build` → clean.
- [ ] Commit with message referencing PR 7.
## Out of scope
Template picker (admins can use plain body for now; integration with template system can land later). HTML editor (plain textarea — same UX as messages page composer).

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,76 @@
# Multiple Hotels + Room Assignments — Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: superpowers:subagent-driven-development. Steps use `- [ ]`.
**Goal:** Replace the one-hotel-per-edition model with many hotels + per-attendee room assignments (hotel, room number, check-in/out), assignable per-member or per-team, surfaced to teams and in the travel email.
**Architecture:** New `HotelStay` 1:1 detail record per `AttendingMember` (mirrors `FlightDetail`); `Hotel.programId` becomes non-unique. Logistics router gains list/CRUD + rooming/assignment procedures; the Hotels tab is reworked into Hotels + Rooming sections. Spec: `docs/superpowers/specs/2026-06-04-multi-hotel-rooming-design.md`.
**Tech Stack:** Next.js 15, tRPC 11, Prisma 6, shadcn/ui, Vitest 4. One schema migration (additive + drop one unique constraint).
**Verified facts:** `Hotel` (`schema.prisma`) is `programId @unique`; `FlightDetail` is the 1:1-detail pattern to mirror. 1:1 hotel callers to update: `logistics.ts:13` (`getHotel`), `:17/33` (`upsertHotel`), `:231` (travel email program-hotel lookup), `applicant.ts:2899` (`getMyLogistics`), `hotels-tab.tsx:20/37/40`.
---
## Task 1: Schema — many hotels + `HotelStay`
**Files:** `prisma/schema.prisma`, migration.
- [ ] **Step 1:** Edit `Hotel`: remove `@unique` from `programId`; add `stays HotelStay[]` and `@@index([programId])`.
- [ ] **Step 2:** Add `HotelStay` model exactly as in the spec (1:1 `attendingMemberId @unique`, required `hotelId`, `roomNumber?`, `checkInAt?`, `checkOutAt?`, `notes?`, timestamps; `attendingMember` relation `onDelete: Cascade`; `hotel` relation `onDelete: Restrict`; `@@index([hotelId])`). Add `hotelStay HotelStay?` to `AttendingMember`.
- [ ] **Step 3:** `npx prisma migrate dev --name multi_hotel_and_hotel_stay` → migration created + applied + client regenerated. Confirm the generated SQL drops `Hotel_programId_key`, adds the index, and creates `HotelStay` with both FKs.
- [ ] **Step 4:** `npm run typecheck` (existing `getHotel`/`upsertHotel` still compile until Task 2). Commit: `git add prisma/ && git commit -m "feat(hotel): many hotels per edition + HotelStay (room assignment)"`
---
## Task 2: Logistics router — hotels CRUD + rooming + assignment + travel email
**Files:** `src/server/routers/logistics.ts`; test `tests/unit/logistics-hotels.test.ts`.
Replace `getHotel`/`upsertHotel` with the full set (read the spec table for exact inputs):
- `listHotels({ programId })` — hotels + `_count: { stays }`.
- `createHotel` / `updateHotel` / `deleteHotel` (deleteHotel: pre-count stays; if >0 throw `BAD_REQUEST` "Reassign N occupant(s) first"). All audited.
- `listRooming({ programId })` — one row per CONFIRMED `AttendingMember` in the program: `{ attendingMemberId, projectId, projectTitle, user{id,name,email}, stay: { hotelId, roomNumber, checkInAt, checkOutAt } | null }`, sorted by project title then user name.
- `assignStay({ attendingMemberId, hotelId, roomNumber?, checkInAt?, checkOutAt?, notes? })` — upsert `HotelStay` (validate the hotel belongs to the same program as the attendee). Audit `HOTEL_STAY_ASSIGN`.
- `assignTeamToHotel({ confirmationId, hotelId, checkInAt?, checkOutAt? })` — for each `AttendingMember` of the confirmation, upsert `HotelStay` with `hotelId` (+ optional dates), preserving existing `roomNumber`. Audit `HOTEL_TEAM_ASSIGN`.
- `unassignStay({ attendingMemberId })``deleteMany` (no-op safe). Audit `HOTEL_STAY_UNASSIGN`.
Then update **`setFlightStatus`** (the `TRAVEL_CONFIRMED` path, ~line 231): instead of the program 1:1 hotel, load the attendee's `hotelStay` (with `hotel`) and pass hotel + room/dates into the notification `metadata` (keys: `hotel: { name, address, link }`, `roomNumber`, `checkInAt`, `checkOutAt`). Update `getTravelConfirmedTemplate` (`src/lib/email.ts`) + its `NOTIFICATION_EMAIL_TEMPLATES` entry to render room/dates if present (additive — keep existing fields working).
- [ ] **Step 1: Tests** (`tests/unit/logistics-hotels.test.ts`, mirror `logistics-hotel.test.ts`): create 2 hotels for one program; `deleteHotel` on an occupied hotel rejects, on an empty one succeeds; `assignStay` upsert (create→update room); `assignTeamToHotel` assigns all of a 2-attendee team; `unassignStay` removes; `listRooming` returns the confirmed attendees with/without stays.
- [ ] **Step 2:** Run → fail → implement → pass (`npx vitest run tests/unit/logistics-hotels.test.ts`). Re-run `tests/unit/logistics-flight.test.ts tests/unit/logistics-comms.test.ts` (travel-email change).
- [ ] **Step 3:** `npm run typecheck`. Commit: `feat(logistics): hotels CRUD + rooming + assignment procedures + travel email`
---
## Task 3: Applicant `getMyLogistics` + My Logistics card → assigned hotel/room
**Files:** `src/server/routers/applicant.ts`, `src/components/applicant/my-logistics-card.tsx`; test `tests/unit/applicant-my-logistics.test.ts` (extend).
- [ ] **Step 1:** In `getMyLogistics` (~line 2899), replace the `prisma.hotel.findUnique({ where: { programId } })` with the caller's `AttendingMember.hotelStay` (include `hotel`). Return `hotel: { name, address, link, notes } | null` and `room: { roomNumber, checkInAt, checkOutAt } | null`. Extend the test to seed a `HotelStay` and assert `hotel.name` + `room.roomNumber`.
- [ ] **Step 2:** Update `MyLogisticsCard` Hotel section to also show **Room** (number) + check-in/out (Monaco-time labels) when `room` is present.
- [ ] **Step 3:** Run the applicant test → pass; `npm run typecheck`. Commit: `feat(applicant): My Logistics shows assigned hotel + room`
---
## Task 4: Hotels tab rework — Hotels + Rooming UI
**Files:** `src/components/admin/logistics/hotels-tab.tsx` (rework); optionally split a `rooming-section.tsx`.
- [ ] **Step 1: Hotels section**`trpc.logistics.listHotels`; list cards with name/address/link/notes + occupancy badge (`_count.stays`); Add / Edit (dialog) / Delete (AlertDialog; show the "reassign first" error toast on rejection) wired to create/update/deleteHotel. Invalidate on success.
- [ ] **Step 2: Rooming section**`trpc.logistics.listRooming`; group rows by project (team). Per team header: an **"Assign whole team to…"** Select → `assignTeamToHotel`. Per attendee row: `Hotel` Select (→ `assignStay`, or `unassignStay` when cleared), `Room #` input (blur → `assignStay`), `Check-in` / `Check-out` date inputs (blur → `assignStay`). Hotel options from `listHotels`. Skeleton while loading; empty state "No confirmed attendees yet." **Download CSV** button (Team, Member, Email, Hotel, Room, Check-in, Check-out) mirroring the travel/visa export. Visible affordances only.
- [ ] **Step 3:** `npm run typecheck`. Commit: `feat(logistics): Hotels tab — multi-hotel management + rooming assignment`
---
## Task 5: Verify + deploy
- [ ] **Step 1:** `npx vitest run` — full suite green; `npm run typecheck` clean.
- [ ] **Step 2:** Stop dev, `rm -rf .next`, `npm run build` — clean.
- [ ] **Step 3:** Restart dev on :3001. Dev smoke (admin): Logistics → Hotels tab → add 2 hotels; enroll a team (ADMIN_CONFIRM) so attendees exist; in Rooming, "assign whole team" to hotel A, override one member to hotel B + a room number; verify occupancy counts; check the team-member dashboard shows their assigned hotel + room. Clean up.
- [ ] **Step 4:** Merge to `main` (fast-forward if possible), push, watch Gitea build #N succeed, then redeploy on prod (`ssh stefan@89.58.5.223:22022`, `/opt/letsbe/stacks/mopc-portal`, `docker compose pull && docker compose down && docker compose up -d`**NO -v**), verify migration applied + app healthy + `GET /login` 200.
- [ ] **Step 5:** Summarize.
## Notes
- All comms/assignment writes best-effort where they sit inside other mutations (travel email try/catch already in place).
- Prod migration is additive + one dropped unique constraint (safe; no `HotelStay` data exists yet).

View File

@@ -0,0 +1,467 @@
# Wave 1 — Make Logistics Operable: Finalist Enrollment + BLOCKER fixes
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Give the grand-finale logistics flow its missing entry points so it is operable end-to-end: a unified "Enroll finalists" action that advances mentoring-round teams into the Grand Final round *and* creates their attendance confirmation in one step, a way to populate the waitlist, safe re-invitation, un-enroll, and the lunch-picker permission fix.
**Architecture:** Three new `finalist` tRPC procedures (`listEnrollmentCandidates`, `enrollFinalists`, `unenroll`) plus one shared service helper. The enroll mutation composes three existing mechanisms that are currently disconnected: (a) round membership (`ProjectRoundState` in the LIVE_FINAL round — same pattern as `round.advanceProjects`), (b) finalist confirmation (`createPendingConfirmation` service), and (c) optional immediate admin confirmation (same transaction as `finalist.adminConfirm`). A new admin card on the LIVE_FINAL round Overview drives it. One one-line permission fix unblocks the applicant lunch picker.
**Tech Stack:** Next.js 15 App Router, tRPC 11 (Zod), Prisma 6, shadcn/ui, Vitest 4. No schema migration required (all models already exist).
**Decisions locked (with Matt, 2026-06-04):**
- Enroll is **one unified step**: adds the team to the R7 LIVE_FINAL round (so the Finals Jury sees them) AND creates the finalist confirmation. Un-enroll reverses both.
- **Offer both attendee modes per team** at enroll time: `EMAIL` (send the self-confirm link; team lead picks ≤cap attendees) or `ADMIN_CONFIRM` (admin picks attendees now; status goes straight to CONFIRMED, no email).
---
## File structure
**Create:**
- `src/server/services/finalist-enrollment.ts` — shared helpers: `resetOrCreatePendingConfirmation()` (re-invite-safe) and `confirmAttendanceInTx()` (extracted from adminConfirm, reused by enroll's ADMIN_CONFIRM mode).
- `src/components/admin/grand-finale/finalist-enrollment-card.tsx` — the enrollment UI card on the LIVE_FINAL round Overview.
- `src/components/admin/grand-finale/enroll-attendees-dialog.tsx` — per-team attendee picker for ADMIN_CONFIRM mode.
- `tests/unit/finalist-enrollment.test.ts` — enrollFinalists (both modes), re-invite safety, unified PRS creation.
- `tests/unit/finalist-unenroll.test.ts` — unenroll reverses membership + confirmation.
- `tests/unit/lunch-list-dishes-perm.test.ts` — non-admin can read dishes.
**Modify:**
- `src/server/routers/finalist.ts` — add `listEnrollmentCandidates`, `enrollFinalists`, `unenroll`; refactor `adminConfirm`/`selectFinalists` to reuse the new helpers.
- `src/server/services/finalist-confirmation.ts` — export the reset-safe helper or re-export from the new module (keep `createPendingConfirmation` intact for waitlist promotion).
- `src/server/routers/lunch.ts:42``listDishes`: `adminProcedure``protectedProcedure`.
- `src/app/(admin)/admin/rounds/[roundId]/page.tsx` — render `FinalistEnrollmentCard` in the LIVE_FINAL grand-finale block (currently lines ~15281531, above `FinalistSlotsCard`).
- `src/components/admin/grand-finale/waitlist-card.tsx` — add an "Add to waitlist" control (wires the existing `finalist.addToWaitlist`, which has no UI today).
- `src/components/admin/logistics/confirmations-tab.tsx` — fix the dead-end empty-state copy; add **Un-confirm** and **Re-invite** row actions (surface existing `unconfirm` + new re-invite via `enrollFinalists`).
---
## Background facts the executor needs (verified 2026-06-04)
- **Two disconnected systems.** A project is "in" the Grand Final round iff it has a `ProjectRoundState{ roundId: <LIVE_FINAL>, ... }`. A project is a "confirmed finalist (logistics)" iff it has a `FinalistConfirmation`. `selectFinalists` only ever created the latter and **had zero UI callers**; `addToWaitlist` also had zero UI callers. This wave joins them.
- **Rounds for the live edition:** R5 EVALUATION → **R6 MENTORING (active)****R7 LIVE_FINAL** → R8 DELIBERATION. Candidates to enroll = projects with a `ProjectRoundState` in the MENTORING round.
- **`FinalistConfirmation.projectId` is `@unique`** (`prisma/schema.prisma:2755`). `createPendingConfirmation` does a naive `.create()` → a second invite for a previously DECLINED/EXPIRED project throws Prisma P2002. The new `resetOrCreatePendingConfirmation()` fixes this.
- **Cap:** `Program.defaultAttendeeCap` (live value: 3) bounds attendees per team.
- **Reference code to mirror:**
- PRS creation in target round: `src/server/routers/round.ts:545-551` (`createMany … skipDuplicates`).
- Admin confirm transaction (attendees + visa rows + lunch picks): `src/server/routers/finalist.ts:492-523`.
- Pending-confirmation + token + email: `src/server/services/finalist-confirmation.ts:12-42` and `src/server/routers/finalist.ts:191-219`.
- Candidate data source: `src/server/routers/round.ts:323` (`listMentoringProjects`).
- Test harness: `tests/unit/finalist-admin-confirm.test.ts` (factories, `createCaller`, cleanup pattern).
---
## Task 1: Unblock the applicant lunch picker (BLOCKER)
**Files:**
- Modify: `src/server/routers/lunch.ts:42`
- Test: `tests/unit/lunch-list-dishes-perm.test.ts`
- [ ] **Step 1: Write the failing test** — a non-admin (APPLICANT) can call `listDishes`.
```ts
import { afterAll, describe, expect, it } from 'vitest'
import { prisma, createCaller } from '../setup'
import { createTestUser, createTestProgram, cleanupTestData, uid } from '../helpers'
import { lunchRouter } from '../../src/server/routers/lunch'
describe('lunch.listDishes permission', () => {
const programIds: string[] = []
const userIds: string[] = []
afterAll(async () => {
for (const id of programIds) {
await prisma.dish.deleteMany({ where: { lunchEvent: { programId: id } } })
await prisma.lunchEvent.deleteMany({ where: { programId: id } })
await cleanupTestData(id, [])
}
if (userIds.length) await prisma.user.deleteMany({ where: { id: { in: userIds } } })
})
it('lets a non-admin (APPLICANT) read the dish list', async () => {
const program = await createTestProgram({ name: `dish-perm-${uid()}` })
programIds.push(program.id)
const event = await prisma.lunchEvent.create({
data: { programId: program.id, enabled: true },
})
await prisma.dish.create({ data: { lunchEventId: event.id, name: 'Sea bass', sortOrder: 0 } })
const applicant = await createTestUser('APPLICANT')
userIds.push(applicant.id)
const caller = createCaller(lunchRouter, {
id: applicant.id, email: applicant.email, role: 'APPLICANT',
})
const dishes = await caller.listDishes({ lunchEventId: event.id })
expect(dishes).toHaveLength(1)
expect(dishes[0].name).toBe('Sea bass')
})
})
```
> Note: confirm the exact `Dish` field names (`lunchEventId`, `name`, `sortOrder`) against `prisma/schema.prisma` before running; adjust the factory data if they differ.
- [ ] **Step 2: Run it, verify it fails**`npx vitest run tests/unit/lunch-list-dishes-perm.test.ts`. Expected: FAIL with an `UNAUTHORIZED` TRPCError (APPLICANT blocked by `adminProcedure`).
- [ ] **Step 3: Change the procedure** — in `src/server/routers/lunch.ts:42`, change `listDishes: adminProcedure` to `listDishes: protectedProcedure`. Ensure `protectedProcedure` is imported in that file (it is used elsewhere in the router; if not, add it to the import from `../trpc`).
- [ ] **Step 4: Run it, verify it passes** — same command. Expected: PASS.
- [ ] **Step 5: Commit**`git add -A && git commit -m "fix(lunch): allow non-admins to read dish list (unblocks applicant picker)"`
---
## Task 2: Re-invite-safe confirmation helper (fixes the P2002 dead-end)
**Files:**
- Create: `src/server/services/finalist-enrollment.ts`
- Test: covered indirectly in Task 3; add a focused unit here.
- [ ] **Step 1: Write the failing test** (add to `tests/unit/finalist-enrollment.test.ts`, created here):
```ts
import { afterAll, describe, expect, it } from 'vitest'
import { prisma } from '../setup'
import { createTestProgram, createTestProject, cleanupTestData, uid } from '../helpers'
import { resetOrCreatePendingConfirmation } from '../../src/server/services/finalist-enrollment'
describe('resetOrCreatePendingConfirmation', () => {
const programIds: string[] = []
afterAll(async () => {
for (const id of programIds) {
await prisma.attendingMember.deleteMany({ where: { confirmation: { project: { programId: id } } } })
await prisma.finalistConfirmation.deleteMany({ where: { project: { programId: id } } })
await cleanupTestData(id, [])
}
})
it('creates a fresh PENDING row when none exists', async () => {
const program = await createTestProgram({ name: `reinvite-new-${uid()}` })
programIds.push(program.id)
const project = await createTestProject(program.id, { competitionCategory: 'STARTUP' })
const res = await resetOrCreatePendingConfirmation(prisma, {
projectId: project.id, category: 'STARTUP', windowHours: 24,
})
const row = await prisma.finalistConfirmation.findUniqueOrThrow({ where: { id: res.id } })
expect(row.status).toBe('PENDING')
expect(res.alreadyConfirmed).toBe(false)
})
it('resets a DECLINED row to a fresh PENDING (no unique-constraint crash)', async () => {
const program = await createTestProgram({ name: `reinvite-declined-${uid()}` })
programIds.push(program.id)
const project = await createTestProject(program.id, { competitionCategory: 'STARTUP' })
await prisma.finalistConfirmation.create({
data: { projectId: project.id, category: 'STARTUP', status: 'DECLINED',
deadline: new Date(Date.now() - 1000), token: `tok_${uid()}`, declinedAt: new Date(),
declineReason: 'busy' },
})
const res = await resetOrCreatePendingConfirmation(prisma, {
projectId: project.id, category: 'STARTUP', windowHours: 24,
})
const row = await prisma.finalistConfirmation.findUniqueOrThrow({ where: { id: res.id } })
expect(row.status).toBe('PENDING')
expect(row.declinedAt).toBeNull()
expect(row.declineReason).toBeNull()
expect(res.alreadyConfirmed).toBe(false)
})
it('is a no-op flagged alreadyConfirmed when row is CONFIRMED', async () => {
const program = await createTestProgram({ name: `reinvite-confirmed-${uid()}` })
programIds.push(program.id)
const project = await createTestProject(program.id, { competitionCategory: 'STARTUP' })
await prisma.finalistConfirmation.create({
data: { projectId: project.id, category: 'STARTUP', status: 'CONFIRMED',
deadline: new Date(Date.now() + 1000), token: `tok_${uid()}`, confirmedAt: new Date() },
})
const res = await resetOrCreatePendingConfirmation(prisma, {
projectId: project.id, category: 'STARTUP', windowHours: 24,
})
expect(res.alreadyConfirmed).toBe(true)
})
})
```
- [ ] **Step 2: Run it, verify it fails**`npx vitest run tests/unit/finalist-enrollment.test.ts`. Expected: FAIL (module/function not found).
- [ ] **Step 3: Implement the helper** — create `src/server/services/finalist-enrollment.ts`:
```ts
import type { CompetitionCategory, Prisma, PrismaClient } from '@prisma/client'
import { signFinalistToken } from '@/lib/finalist-token'
type TxClient = PrismaClient | Prisma.TransactionClient
/**
* Re-invite-safe variant of createPendingConfirmation. If a confirmation row
* already exists for the project (projectId is @unique), reset any
* non-CONFIRMED row back to a fresh PENDING with a new token/deadline and
* clear stale attendee rows; report CONFIRMED rows as a no-op so callers can
* skip them. Returns the row id + token + deadline for the email step.
*/
export async function resetOrCreatePendingConfirmation(
prisma: TxClient,
args: { projectId: string; category: CompetitionCategory; windowHours: number },
): Promise<{ id: string; token: string; deadline: Date; alreadyConfirmed: boolean }> {
const deadline = new Date(Date.now() + args.windowHours * 3_600_000)
const existing = await prisma.finalistConfirmation.findUnique({
where: { projectId: args.projectId },
select: { id: true, status: true },
})
if (existing?.status === 'CONFIRMED') {
return { id: existing.id, token: '', deadline, alreadyConfirmed: true }
}
if (existing) {
const token = signFinalistToken({
confirmationId: existing.id,
exp: Math.floor(deadline.getTime() / 1000),
})
// Clear any attendee rows from a prior cycle (cascade-deletes flight/visa/lunch).
await prisma.attendingMember.deleteMany({ where: { confirmationId: existing.id } })
await prisma.finalistConfirmation.update({
where: { id: existing.id },
data: {
category: args.category,
status: 'PENDING',
deadline,
token,
confirmedAt: null,
declinedAt: null,
declineReason: null,
expiredAt: null,
},
})
return { id: existing.id, token, deadline, alreadyConfirmed: false }
}
const id = `cmfc_${Math.random().toString(36).slice(2, 10)}_${Date.now().toString(36)}`
const token = signFinalistToken({
confirmationId: id,
exp: Math.floor(deadline.getTime() / 1000),
})
await prisma.finalistConfirmation.create({
data: {
id,
projectId: args.projectId,
category: args.category,
status: 'PENDING',
deadline,
token,
},
})
return { id, token, deadline, alreadyConfirmed: false }
}
```
> Confirm `AttendingMember`→`FlightDetail`/`VisaApplication`/`MemberLunchPick` are `onDelete: Cascade` (they are, per schema 2789+); the `deleteMany` then cleans dependents. If `signFinalistToken`'s import path differs, match `src/server/services/finalist-confirmation.ts:2`.
- [ ] **Step 4: Run it, verify it passes** — same command. Expected: PASS (3 tests).
- [ ] **Step 5: Commit**`git add -A && git commit -m "feat(finalist): re-invite-safe confirmation reset helper"`
---
## Task 3: `finalist.enrollFinalists` — the unified entry point
**Files:**
- Modify: `src/server/routers/finalist.ts` (add procedure; import the helper)
- Test: `tests/unit/finalist-enrollment.test.ts` (extend)
**Procedure contract:**
```ts
enrollFinalists: adminProcedure
.input(z.object({
programId: z.string(),
roundId: z.string(), // the LIVE_FINAL round
enrollments: z.array(z.object({
projectId: z.string(),
mode: z.enum(['EMAIL', 'ADMIN_CONFIRM']),
attendingUserIds: z.array(z.string()).optional(), // required for ADMIN_CONFIRM
visaFlags: z.record(z.string(), z.boolean()).optional(),
})).min(1),
}))
.mutation(async ({ ctx, input }) => { /* see steps */ })
```
Behavior per enrollment:
1. Validate the project is in `programId` and read its `competitionCategory`, `defaultAttendeeCap`, team members + LEAD email.
2. **Round membership:** `projectRoundState.createMany({ data: [{ projectId, roundId }], skipDuplicates: true })` (mirror `round.ts:545`).
3. **Confirmation:** `resetOrCreatePendingConfirmation()`. If `alreadyConfirmed`, record `skipped: 'ALREADY_CONFIRMED'` and continue.
4. If `mode === 'EMAIL'`: send `sendFinalistConfirmationEmail(lead.email, lead.name, project.title, deadline, confirmUrl)` inside a try/catch (never throw in the loop — mirror `finalist.ts:213`).
5. If `mode === 'ADMIN_CONFIRM'`: validate `attendingUserIds` (non-empty, ≤ cap, all team members) then run the confirm transaction (attendees + visa rows + lunch picks) exactly as `finalist.ts:492-523`. No email.
6. Audit `FINALIST_ENROLL` with `{ projectId, mode }`.
7. Return `{ enrolled, emailed, adminConfirmed, skipped: [...] }`.
- [ ] **Step 1: Write failing tests** (extend `finalist-enrollment.test.ts`). Build an admin caller via `createCaller(finalistRouter, {…SUPER_ADMIN})`, a program (`defaultAttendeeCap: 3`), a competition with a `LIVE_FINAL` round (`createTestRound(comp.id, { roundType: 'LIVE_FINAL', sortOrder: 99, configJson: { confirmationWindowHours: 24 } })`) and a MENTORING round with a `ProjectRoundState` for the project. Assert:
```ts
// EMAIL mode
it('EMAIL mode: creates PRS in LIVE_FINAL + PENDING confirmation, no attendees', async () => {
// ... call enrollFinalists with one { projectId, mode: 'EMAIL' }
const prs = await prisma.projectRoundState.findFirst({ where: { projectId, roundId: liveFinalId } })
expect(prs).not.toBeNull()
const conf = await prisma.finalistConfirmation.findUniqueOrThrow({ where: { projectId } })
expect(conf.status).toBe('PENDING')
expect(await prisma.attendingMember.count({ where: { confirmationId: conf.id } })).toBe(0)
})
// ADMIN_CONFIRM mode
it('ADMIN_CONFIRM mode: CONFIRMED with attendee + visa + lunch rows', async () => {
// ... call with { projectId, mode: 'ADMIN_CONFIRM', attendingUserIds: [lead.id, member.id], visaFlags: { [member.id]: true } }
const conf = await prisma.finalistConfirmation.findUniqueOrThrow({ where: { projectId } })
expect(conf.status).toBe('CONFIRMED')
expect(await prisma.attendingMember.count({ where: { confirmationId: conf.id } })).toBe(2)
expect(await prisma.visaApplication.count({ where: { attendingMember: { confirmationId: conf.id } } })).toBe(1)
})
// idempotent membership + re-invite
it('re-enrolling a DECLINED project resets it without crashing and keeps one PRS row', async () => {
// pre-create DECLINED confirmation + a PRS; enroll EMAIL again
// expect status PENDING and exactly one PRS row for (projectId, liveFinalId)
})
// ADMIN_CONFIRM over cap rejects
it('ADMIN_CONFIRM rejects when attendees exceed cap', async () => {
await expect(/* 4 attendees with cap 3 */).rejects.toThrow(/cap/i)
})
```
- [ ] **Step 2: Run, verify fail**`npx vitest run tests/unit/finalist-enrollment.test.ts`. Expected: FAIL (`enrollFinalists` not a function).
- [ ] **Step 3: Implement** the procedure in `finalist.ts`. Reuse: import `resetOrCreatePendingConfirmation` from `../services/finalist-enrollment`; reuse `sendFinalistConfirmationEmail`, `ensureLunchPickForAttendingMember`, `logAudit`, `signFinalistToken` already imported. For the ADMIN_CONFIRM transaction body, copy the exact `$transaction` block from `adminConfirm` (`finalist.ts:492-523`). Resolve `windowHours` from the LIVE_FINAL round's `configJson.confirmationWindowHours ?? 24` (mirror `finalist.ts:145`). Build `confirmUrl` from `NEXTAUTH_URL` (mirror `finalist.ts:191-204`).
- [ ] **Step 4: Run, verify pass** — same command. Expected: PASS.
- [ ] **Step 5: Refactor for DRY (optional within budget)** — extract the shared confirm transaction into `confirmAttendanceInTx(tx, { confirmationId, attendingUserIds, visaFlags })` in `finalist-enrollment.ts` and call it from both `adminConfirm` and `enrollFinalists`. Re-run `npx vitest run tests/unit/finalist-admin-confirm.test.ts tests/unit/finalist-enrollment.test.ts`. Expected: PASS both.
- [ ] **Step 6: Commit**`git commit -am "feat(finalist): unified enrollFinalists (round membership + confirmation + email/admin-confirm)"`
---
## Task 4: `finalist.unenroll` — reverse membership + confirmation
**Files:**
- Modify: `src/server/routers/finalist.ts`
- Test: `tests/unit/finalist-unenroll.test.ts`
**Contract:** `unenroll({ projectId, roundId })`
1. Delete the `FinalistConfirmation` for the project (cascade removes AttendingMember/FlightDetail/VisaApplication/lunch picks).
2. Delete the LIVE_FINAL `ProjectRoundState` (`deleteMany({ where: { projectId, roundId } })`).
3. Audit `FINALIST_UNENROLL`.
4. Return `{ ok: true }`. (Mentor assignments are tied to the MENTORING round and are intentionally left untouched.)
- [ ] **Step 1: Failing test** — enroll (ADMIN_CONFIRM) a project, then `unenroll`; assert no confirmation, no attendees, no LIVE_FINAL PRS, and an audit row exists.
- [ ] **Step 2: Run, verify fail.**
- [ ] **Step 3: Implement** the procedure.
- [ ] **Step 4: Run, verify pass**`npx vitest run tests/unit/finalist-unenroll.test.ts`.
- [ ] **Step 5: Commit**`git commit -am "feat(finalist): unenroll reverses round membership + confirmation"`
---
## Task 5: `finalist.listEnrollmentCandidates` — data for the UI
**Files:**
- Modify: `src/server/routers/finalist.ts`
- Test: `tests/unit/finalist-enrollment.test.ts` (extend)
**Contract:** `listEnrollmentCandidates({ programId })` resolves the program's competition, finds the MENTORING round and the LIVE_FINAL round, and returns:
```ts
{
liveFinalRoundId: string | null,
attendeeCap: number,
categories: Array<{
category: CompetitionCategory,
quota: number | null,
confirmedCount: number,
pendingCount: number,
candidates: Array<{
projectId: string,
title: string,
teamName: string | null,
country: string | null,
inLiveFinal: boolean, // has a LIVE_FINAL ProjectRoundState
confirmationStatus: FinalistConfirmationStatus | null,
teamMembers: Array<{ userId: string, name: string | null, role: 'LEAD' | 'MEMBER', email: string }>,
}>,
}>,
}
```
Source candidates from `ProjectRoundState` in the MENTORING round (mirror `round.ts:335`), join `project.finalistConfirmation.status`, a `ProjectRoundState` existence check against the LIVE_FINAL round for `inLiveFinal`, and `project.teamMembers` (for the ADMIN_CONFIRM picker). Group by `competitionCategory`; merge per-category `FinalistSlotQuota` + confirmed/pending counts (reuse the count logic from `finalist.listCategoryCounts`).
- [ ] **Step 1: Failing test** — set up a MENTORING round with one STARTUP project (PRS), assert the project appears under the STARTUP category with `inLiveFinal: false`, `confirmationStatus: null`, and its team members listed.
- [ ] **Step 2: Run, verify fail.**
- [ ] **Step 3: Implement.**
- [ ] **Step 4: Run, verify pass.**
- [ ] **Step 5: Commit**`git commit -am "feat(finalist): listEnrollmentCandidates query for enrollment UI"`
---
## Task 6: Enrollment UI card on the LIVE_FINAL round page
**Files:**
- Create: `src/components/admin/grand-finale/finalist-enrollment-card.tsx`
- Create: `src/components/admin/grand-finale/enroll-attendees-dialog.tsx`
- Modify: `src/app/(admin)/admin/rounds/[roundId]/page.tsx` (render the card in the grand-finale block, ~line 1528, above `FinalistSlotsCard`)
**Card UX (follow the visual pattern of `finalist-slots-card.tsx` / `waitlist-card.tsx`):**
- `trpc.finalist.listEnrollmentCandidates.useQuery({ programId })`. Loading → Skeleton; empty → "No mentoring-round teams to enroll yet."
- Group candidates by category with a header showing `confirmed/quota` (e.g. "Startup — 2/8 confirmed, 1 pending").
- Each candidate row: checkbox, title + teamName + country, and a status badge (`Not enrolled` / `In round` / `Pending` / `Confirmed` / `Declined`). Confirmed/declined rows show an **Un-enroll** button instead of a checkbox.
- Per selected row, a small mode toggle: **Email team** (default) or **Set attendees now**. Choosing "Set attendees now" opens `EnrollAttendeesDialog` (a ≤cap member multi-select with per-member "needs visa" checkbox) and stashes the chosen `attendingUserIds`/`visaFlags` on that row.
- Footer: **Enroll selected** and **Enroll all eligible** (eligible = not already CONFIRMED). Calls `trpc.finalist.enrollFinalists.useMutation`, then `utils.finalist.listEnrollmentCandidates.invalidate()` + `utils.logistics.listConfirmations.invalidate()`. Toast the `{ enrolled, emailed, adminConfirmed, skipped }` summary.
- Un-enroll buttons call `trpc.finalist.unenroll` behind an `AlertDialog` confirm ("This removes them from the Grand Final round and deletes their attendance record. Continue?").
> Use shadcn `AlertDialog` for confirms (no native `confirm()`), per house style and the no-keyboard-shortcuts preference (visible affordances only).
- [ ] **Step 1:** Build `enroll-attendees-dialog.tsx` (props: `members`, `cap`, `onConfirm(attendingUserIds, visaFlags)`).
- [ ] **Step 2:** Build `finalist-enrollment-card.tsx` per the UX above.
- [ ] **Step 3:** Render `<FinalistEnrollmentCard programId={programId} roundId={round.id} />` in the LIVE_FINAL grand-finale block in the round page.
- [ ] **Step 4: Typecheck**`npm run typecheck`. Expected: clean.
- [ ] **Step 5: Commit**`git commit -am "feat(grand-finale): finalist enrollment card on LIVE_FINAL round page"`
---
## Task 7: Waitlist populate UI + confirmations-tab dead-end fixes
**Files:**
- Modify: `src/components/admin/grand-finale/waitlist-card.tsx`
- Modify: `src/components/admin/logistics/confirmations-tab.tsx`
- [ ] **Step 1: Add-to-waitlist control** in `waitlist-card.tsx` — a category + project picker (project options = enrollment candidates not already confirmed/waitlisted) that calls the existing `trpc.finalist.addToWaitlist` mutation (which had no UI). Invalidate `listWaitlist` on success. Confirm `addToWaitlist`'s exact input shape at `finalist.ts:629` before wiring.
- [ ] **Step 2: Fix the dead-end copy** in `confirmations-tab.tsx:127` — replace "Use the grand-finale round page to send confirmations." with "Enroll finalists from the Grand Final round's Overview tab to start confirmations." (Or, if scope allows, render an inline `<Link>` to the round page.)
- [ ] **Step 3: Add row actions** to `confirmations-tab.tsx` (currently only PENDING rows show Confirm/Decline; all others show "—"):
- CONFIRMED rows → **Un-confirm** button calling existing `trpc.finalist.unconfirm` (behind `AlertDialog`).
- DECLINED / EXPIRED rows → **Re-invite** button calling `trpc.finalist.enrollFinalists` with `{ projectId, mode: 'EMAIL', roundId: liveFinalRoundId }` (re-invite-safe via Task 2). Needs the LIVE_FINAL roundId — fetch via `listEnrollmentCandidates` or add it to `listConfirmations`' payload.
- [ ] **Step 4: Typecheck**`npm run typecheck`. Expected: clean.
- [ ] **Step 5: Commit**`git commit -am "feat(logistics): waitlist populate UI + confirmations-tab un-confirm/re-invite actions"`
---
## Task 8: Full verification
- [ ] **Step 1: Run the whole finalist/lunch/logistics suite**`npx vitest run tests/unit/finalist-enrollment.test.ts tests/unit/finalist-unenroll.test.ts tests/unit/lunch-list-dishes-perm.test.ts tests/unit/finalist-admin-confirm.test.ts tests/unit/finalist-quotas.test.ts tests/unit/finalist-confirmation.test.ts`. Expected: all PASS (regression check on the refactor).
- [ ] **Step 2: Typecheck + build**`npm run typecheck && npm run build`. Expected: clean (build is required before any push, per CLAUDE.md).
- [ ] **Step 3: Dev smoke (Playwright, server already on :3001 as super-admin)** — verify the end-to-end the audit proved was impossible:
1. Mentoring round (R6) → ensure a project has a `ProjectRoundState` (advance one in if needed).
2. Grand Final round (R7) Overview → the new Enrollment card lists it; enroll it in EMAIL mode.
3. `/admin/logistics` → Confirmations tab now shows a PENDING row (no longer the dead-end empty state).
4. Enroll a second team in ADMIN_CONFIRM mode with 2 attendees → Confirmations shows CONFIRMED with attendee count 2; Travel/Visas tabs now list those attendees.
5. Confirm the LIVE_FINAL round's Projects tab now shows the enrolled teams (jury can see them).
- [ ] **Step 4: Final commit / branch** — ensure work is on a feature branch (not `main`); summarize for review.
---
## Self-review notes (coverage vs. the 4 BLOCKERs)
- BLOCKER 1 (no select-finalists UI) → Tasks 3 + 6 (`enrollFinalists` + enrollment card).
- BLOCKER 2 (no waitlist populate UI) → Task 7 step 1.
- BLOCKER 3 (lunch picker broken) → Task 1.
- BLOCKER 4 (re-invite crash) → Task 2 (`resetOrCreatePendingConfirmation`), surfaced via Task 7 step 3 (Re-invite action).
- Unified enroll + both attendee modes (locked decisions) → Task 3.
- Un-confirm dead-end (HIGH) → Task 7 step 3.
**Out of scope for Wave 1 (deferred to later waves):** all the new transactional emails/notifications and reminders (Wave 2), the Email Templates tab (Wave 3), team-facing "My Logistics" + timezone/validation/export UX fixes (Wave 4). The only email this wave sends is the existing `sendFinalistConfirmationEmail` (now reachable via EMAIL-mode enroll and Re-invite).

View File

@@ -0,0 +1,186 @@
# Wave 2 — Close the Logistics Email/Notification Void
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
**Goal:** Make logistics actually *communicate*. Today logistics fires exactly one automatic email (`sendFinalistConfirmationEmail`) and creates zero in-app notifications. This wave adds confirmation reminders, admin alerts, withdrawal emails, attendee travel/visa emails, and fixes the lunch reminder/recap comms — all routed through the existing notification pipeline so admins keep on/off control.
**Architecture:** Reuse the established comms pipeline (decision: reuse, not a new system). `createNotification({ userId, type, title, message, linkUrl, metadata })` writes an in-app row AND conditionally sends a branded email when a `NotificationEmailSetting` row exists for that type with `sendEmail=true` and the user's `notificationPreference` allows email. New notification types get registered in `NotificationTypes`, optionally given a custom branded template in `NOTIFICATION_EMAIL_TEMPLATES` (team/attendee-facing) or left to fall back to the generic branded template (admin alerts), and seeded in `prisma/seed-notification-settings.ts` (which runs on every deploy + dev).
**Tech Stack:** Next.js 15, tRPC 11, Prisma 6, Vitest 4. One small schema migration (`reminderSentAt`).
**Key infra facts (verified 2026-06-04):**
- `createNotification(params)``src/server/services/in-app-notification.ts:185`. Email leg gated by `NotificationEmailSetting` (no row OR `sendEmail=false` → no email) + user `notificationPreference ∈ {EMAIL, BOTH}`.
- Helpers: `notifyAdmins({type,title,message,linkUrl,metadata})` (`:324`), `notifyProjectTeam({projectId,...})` (`:374`), `createBulkNotifications` (`:263`).
- Email body for a type comes from `NOTIFICATION_EMAIL_TEMPLATES[type]` (`src/lib/email.ts:2196`); missing entry → generic branded fallback `getNotificationEmailTemplate` (`:2635`). `sendStyledNotificationEmail` (`:2400`) is the sender.
- Settings seeded idempotently in `prisma/seed-notification-settings.ts` (row shape `{ notificationType, category, label, description, sendEmail }`), run on every container start via `docker/docker-entrypoint.sh:72`.
- Dead stub types already in registry (do NOT reuse; add explicit new ones): `MENTEE_FINALIST`, `EVENT_INVITATION`, `FINALISTS_ANNOUNCED`.
- Recipients: admins via `roles: { has: 'SUPER_ADMIN' }` / `'PROGRAM_ADMIN'` + `status:'ACTIVE'`; team lead via `teamMembers where role:'LEAD'`; attendee email via `AttendingMember.user`.
- `FinalistConfirmation` has NO `reminderSentAt` yet (Task 1 adds it). Lunch cron attendee-filter bug confirmed (Task 7).
**New notification type constants (add all to `NotificationTypes`):**
| Constant | Audience | Email template | Seed `sendEmail` |
|---|---|---|---|
| `FINALIST_CONFIRMED` | admins | fallback | true |
| `FINALIST_DECLINED` | admins | fallback | true |
| `FINALIST_EXPIRED` | admins | fallback | true |
| `FINALIST_WAITLIST_PROMOTED` | admins | fallback | true |
| `FINALIST_REMINDER` | team lead | custom | true |
| `FINALIST_WITHDRAWN` | team | custom | true |
| `TRAVEL_CONFIRMED` | attendee | custom | true |
| `VISA_STATUS_UPDATE` | attendee | custom | true |
---
## File structure
**Create:**
- `prisma/migrations/<ts>_add_finalist_reminder_sent_at/migration.sql`
- `tests/unit/finalist-comms.test.ts` — admin alerts + withdrawal notifications fire
- `tests/unit/finalist-reminders.test.ts` — reminder cron sends + stamps + idempotent
- `tests/unit/logistics-comms.test.ts` — flight-confirmed + visa-status emails fire
- `tests/unit/lunch-reminder-filter.test.ts` — cron picks up attendees with no pick row
**Modify:**
- `prisma/schema.prisma``FinalistConfirmation.reminderSentAt DateTime?`
- `src/server/services/in-app-notification.ts` — add 8 `NotificationTypes` constants (+ icons/priorities optional)
- `src/lib/email.ts` — 4 custom templates + register in `NOTIFICATION_EMAIL_TEMPLATES`
- `prisma/seed-notification-settings.ts` — 8 new setting rows (category `logistics`)
- `src/server/routers/finalist.ts` — admin alerts in `confirm`/`decline`/`adminDecline`/`manualPromote`; withdrawal in `adminDecline`/`unconfirm`/`unenroll`
- `src/server/services/finalist-confirmation.ts` — admin alert in `expirePendingPastDeadline` + `promoteNextWaitlistEntry`; new `sendDueConfirmationReminders`
- `src/app/api/cron/finalist-confirmations/route.ts` — call `sendDueConfirmationReminders`
- `src/server/routers/logistics.ts` — emails in `setFlightStatus`(→CONFIRMED) + `updateVisaApplication`(status transitions)
- `src/app/api/cron/lunch-reminders/route.ts` — fix attendee OR-filter
- `src/server/routers/lunch.ts` — surface recap send failure; add `sendReminders` mutation
- `src/components/admin/logistics/lunch-recap-actions.tsx` — "Send reminders now" button
---
## Task 1: Schema — `reminderSentAt`
**Files:** `prisma/schema.prisma`, migration.
- [ ] **Step 1:** Add to `FinalistConfirmation`: `reminderSentAt DateTime?` (near `confirmedAt`/`expiredAt`).
- [ ] **Step 2:** `npx prisma migrate dev --name add_finalist_reminder_sent_at`. Expected: migration created + applied, client regenerated.
- [ ] **Step 3:** `npm run typecheck` — clean.
- [ ] **Step 4: Commit**`git add prisma/ && git commit -m "feat(finalist): add reminderSentAt for confirmation reminders"`
---
## Task 2: Notification types, templates, and settings
**Files:** `src/server/services/in-app-notification.ts`, `src/lib/email.ts`, `prisma/seed-notification-settings.ts`.
- [ ] **Step 1:** Add the 8 constants to the `NotificationTypes` object (`in-app-notification.ts:15`), grouped under a `// Logistics` comment, e.g. `FINALIST_CONFIRMED: 'FINALIST_CONFIRMED',` … through `VISA_STATUS_UPDATE: 'VISA_STATUS_UPDATE',`. Optionally add icons/priorities (e.g. `FINALIST_EXPIRED: 'urgent'`, `VISA_STATUS_UPDATE: 'high'`).
- [ ] **Step 2:** Add 4 custom branded templates in `src/lib/email.ts` (mirror an existing private template that uses `getEmailWrapper` + `sectionTitle`/`paragraph`/`ctaButton`/`infoBox`). Each returns `{ subject, html, text }`:
- `getFinalistReminderTemplate(name, projectTitle, deadline, confirmUrl)` — "Reminder: confirm your grand-finale attendance by <formatted deadline>". Format the deadline human-readably (`toLocaleString('en-GB', { timeZone: 'Europe/Paris', dateStyle:'full', timeStyle:'short' })`).
- `getFinalistWithdrawnTemplate(name, projectTitle, reason?)` — "Your grand-finale slot has been withdrawn".
- `getTravelConfirmedTemplate(name, projectTitle, flight, hotel?)` — itinerary (arrival/departure flight no + airport + formatted times) and, if `hotel` provided, hotel name/address/link.
- `getVisaStatusTemplate(name, projectTitle, status, note?)` — status-specific copy for `INVITATION_SENT` / `APPOINTMENT_BOOKED` / `GRANTED` / `DENIED`.
Then register them in `NOTIFICATION_EMAIL_TEMPLATES` (`:2196`) keyed by the type string, reading fields from `ctx.metadata` (e.g. `FINALIST_REMINDER: (ctx) => getFinalistReminderTemplate(ctx.name||'', ctx.metadata?.projectTitle as string, new Date(ctx.metadata?.deadline as string), ctx.linkUrl||'')`). Admin-alert types are intentionally NOT registered (they use the generic fallback).
- [ ] **Step 3:** Add 8 rows to `NOTIFICATION_EMAIL_SETTINGS` in `prisma/seed-notification-settings.ts` (category `'logistics'`), all `sendEmail: true`, with clear `label`/`description`.
- [ ] **Step 4:** Apply to the dev DB: `npx tsx prisma/seed-notification-settings.ts`. Expected: upserts succeed (idempotent).
- [ ] **Step 5:** `npm run typecheck` — clean.
- [ ] **Step 6: Commit**`git commit -am "feat(comms): logistics notification types, templates, and email settings"`
---
## Task 3: Admin alerts on confirmation lifecycle
**Files:** `src/server/routers/finalist.ts`, `src/server/services/finalist-confirmation.ts`; test `tests/unit/finalist-comms.test.ts`.
For each event, call `notifyAdmins({ type, title, message, linkUrl: '/admin/logistics', metadata: { projectId, projectTitle, category } })`. Wrap in try/catch — comms must never throw inside the mutation (mirror the round-notification rule in CLAUDE.md).
- Team confirms (`finalist.confirm`, after the transaction) → `FINALIST_CONFIRMED`.
- Team declines (`finalist.decline`) and admin declines (`finalist.adminDecline`) → `FINALIST_DECLINED`.
- Cron expiry (`expirePendingPastDeadline`, per expired row) → `FINALIST_EXPIRED`.
- Waitlist promotion (`promoteNextWaitlistEntry` and `manualPromote`) → `FINALIST_WAITLIST_PROMOTED`.
- [ ] **Step 1: Failing tests** — for `confirm`, `decline`, and `expirePendingPastDeadline`, assert an `InAppNotification` row with the right `type` is created for an admin user after the action (set up a `SUPER_ADMIN` with `status:'ACTIVE'`). Use the existing finalist test setup patterns.
- [ ] **Step 2:** Run → fail.
- [ ] **Step 3:** Implement the `notifyAdmins` calls. Import from `../services/in-app-notification` (note: `finalist-confirmation.ts` is a service — import directly).
- [ ] **Step 4:** Run → pass; re-run `tests/unit/finalist-confirmation.test.ts` for no regressions.
- [ ] **Step 5: Commit**`git commit -am "feat(finalist): admin alerts on confirm/decline/expire/promote"`
---
## Task 4: Withdrawal emails to teams
**Files:** `src/server/routers/finalist.ts`; test `tests/unit/finalist-comms.test.ts`.
When a team's slot is withdrawn by an admin, notify the team lead with `FINALIST_WITHDRAWN` (in-app + email). Events: `adminDecline`, `unconfirm` (CONFIRMED→SUPERSEDED), and `unenroll` when a CONFIRMED confirmation existed.
- [ ] **Step 1: Failing test** — after `adminDecline`, assert a `FINALIST_WITHDRAWN` `InAppNotification` exists for the team lead's userId.
- [ ] **Step 2:** Run → fail.
- [ ] **Step 3:** Implement: resolve the lead (`teamMembers where role:'LEAD'`), `createNotification({ userId: lead.userId, type: NotificationTypes.FINALIST_WITHDRAWN, title:'Grand finale slot withdrawn', message:`Your team "${title}" is no longer a confirmed finalist.${reason? ' Reason: '+reason : ''}`, linkUrl:'/applicant', metadata:{ projectTitle: title, reason } })` in try/catch. In `unenroll`, capture whether a CONFIRMED row existed BEFORE the delete, and only notify then.
- [ ] **Step 4:** Run → pass; re-run `finalist-unconfirm`, `finalist-unenroll`, `finalist-admin-confirm` suites.
- [ ] **Step 5: Commit**`git commit -am "feat(finalist): withdrawal notification to team on decline/unconfirm/unenroll"`
---
## Task 5: Confirmation reminder cron
**Files:** `src/server/services/finalist-confirmation.ts`, `src/app/api/cron/finalist-confirmations/route.ts`; test `tests/unit/finalist-reminders.test.ts`.
Add `sendDueConfirmationReminders(prisma): Promise<{ remindersSent: number }>`:
- Resolve a reminder lead time: read each program's LIVE_FINAL round `configJson.reminderHoursBeforeDeadline` (default 12).
- Query `FinalistConfirmation` where `status:'PENDING' AND reminderSentAt IS NULL AND deadline > now AND deadline <= now + reminderHours`. (Simplest: load all PENDING with `reminderSentAt:null AND deadline>now`, then filter by each program's lead time.)
- For each: send via `createNotification({ userId: lead.userId, type: FINALIST_REMINDER, title, message, linkUrl: confirmUrl (the public token URL — build like selectFinalists), metadata:{ projectTitle, deadline } })`, then `update reminderSentAt = now`. Best-effort per row (try/catch).
- Reset `reminderSentAt` is NOT needed (deadlines don't move here; if re-invited, `resetOrCreatePendingConfirmation` should also clear `reminderSentAt` — ADD that field reset in the Wave 1 helper).
- [ ] **Step 1:** In `resetOrCreatePendingConfirmation` (`src/server/services/finalist-enrollment.ts`), add `reminderSentAt: null` to the reset `update` data (so re-invited teams get a fresh reminder window).
- [ ] **Step 2: Failing test** — create a PENDING confirmation with `deadline = now + 6h` and `reminderSentAt:null`, a LIVE_FINAL round with `reminderHoursBeforeDeadline: 12`, a lead user; call `sendDueConfirmationReminders`; assert `remindersSent===1`, a `FINALIST_REMINDER` notification exists for the lead, and `reminderSentAt` is now set. Second call → `remindersSent===0` (idempotent).
- [ ] **Step 3:** Run → fail.
- [ ] **Step 4:** Implement `sendDueConfirmationReminders` and call it from the cron route (before or after `expirePendingPastDeadline`).
- [ ] **Step 5:** Run → pass.
- [ ] **Step 6: Commit**`git commit -am "feat(finalist): deadline reminder emails via cron"`
---
## Task 6: Travel + visa attendee emails
**Files:** `src/server/routers/logistics.ts`; test `tests/unit/logistics-comms.test.ts`.
- `setFlightStatus` → when set to `CONFIRMED`: load the attendee's user + the program hotel; `createNotification({ userId: attendee.userId, type: TRAVEL_CONFIRMED, ..., metadata:{ projectTitle, arrival/departure fields, hotel } })`. (No email when set back to PENDING.)
- `updateVisaApplication` → when `input.status` changes to one of `INVITATION_SENT|APPOINTMENT_BOOKED|GRANTED|DENIED` (and differs from `existing.status`): `createNotification({ userId: attendee.userId, type: VISA_STATUS_UPDATE, ..., metadata:{ projectTitle, status, note } })`. Gate on nothing (visa outcomes are always relevant); include the admin `notes` only if appropriate — default: don't leak internal notes, send status-only copy.
- [ ] **Step 1: Failing tests** — set a flight to CONFIRMED → assert `TRAVEL_CONFIRMED` notification for the attendee; update a visa to `GRANTED` → assert `VISA_STATUS_UPDATE` notification. (Reuse `logistics-flight.test.ts` / `visa-admin.test.ts` setup patterns.)
- [ ] **Step 2:** Run → fail.
- [ ] **Step 3:** Implement. For `setFlightStatus`, the procedure currently only has `flightDetailId`; join to `attendingMember.user` + program hotel. For `updateVisaApplication`, the existing row read already gives `attendingMember` — extend the select to include `user` + project title.
- [ ] **Step 4:** Run → pass; re-run `logistics-flight`, `visa-admin`, `visa-application-lifecycle`.
- [ ] **Step 5: Commit**`git commit -am "feat(logistics): travel-confirmed + visa-status emails to attendees"`
---
## Task 7: Lunch reminder/recap fixes
**Files:** `src/app/api/cron/lunch-reminders/route.ts`, `src/server/routers/lunch.ts`, `src/components/admin/logistics/lunch-recap-actions.tsx`; test `tests/unit/lunch-reminder-filter.test.ts`.
- [ ] **Step 1: Failing test** — a CONFIRMED attendee with NO `MemberLunchPick` row should be counted as needing a reminder. Assert the cron's selection query (extract it into a small exported helper `selectUnpickedAttendees(prisma, event)` for testability) returns that attendee.
- [ ] **Step 2:** Run → fail (current `is` filter misses null-relation rows).
- [ ] **Step 3:** Fix the filter to `OR: [{ lunchPick: { is: null } }, { lunchPick: { is: { pickedAt: null } } }]` (cron `route.ts:44`).
- [ ] **Step 4:** Recap failure surfacing (`lunch.ts:345`): only stamp `recapSentAt` + audit `LUNCH_RECAP_SENT` if `sendLunchRecapEmail` resolved; on failure, re-throw (or return `{ ok:false, error }`) so the admin sees a failure toast. Update `lunch-recap-actions.tsx` to show the error.
- [ ] **Step 5:** Add `lunch.sendReminders` mutation (admin) that runs the same selection + `sendLunchReminderEmail` loop as the cron for a given `lunchEventId`, returns `{ sent }`; add a "Send reminders now" button to `lunch-recap-actions.tsx` (behind a confirm).
- [ ] **Step 6:** Run tests → pass; `npm run typecheck` — clean.
- [ ] **Step 7: Commit**`git commit -am "fix(lunch): reminder filter, recap failure surfacing, manual send-reminders"`
---
## Task 8: Full verification
- [ ] **Step 1:** `npx vitest run` — full suite green (target: prior 256 + new tests).
- [ ] **Step 2:** `npm run typecheck` — clean.
- [ ] **Step 3:** Stop the dev server, `rm -rf .next`, `npm run build` — clean (don't build while dev server runs).
- [ ] **Step 4:** Restart dev on :3001; `npx tsx prisma/seed-notification-settings.ts` to ensure settings exist. Dev smoke: enroll a team (ADMIN_CONFIRM) → set their flight CONFIRMED in Travel tab → set a visa GRANTED in Visas tab → confirm an `InAppNotification` row exists for the attendee (query DB) for `TRAVEL_CONFIRMED` and `VISA_STATUS_UPDATE`. Decline a PENDING team → confirm admin `FINALIST_DECLINED` + team `FINALIST_WITHDRAWN`. Clean up (unenroll).
- [ ] **Step 5:** Summarize for review.
---
## Notes
- All comms calls are best-effort (try/catch, never throw inside a mutation/cron) — consistent with CLAUDE.md "round notifications never throw".
- Email sending in dev uses `SMTP_HOST=localhost` (`.env.local`) → sends fail silently and are swallowed; tests assert on the `InAppNotification` row, not on actual delivery.
- Prod gets the new `NotificationEmailSetting` rows automatically via `docker-entrypoint.sh` running `seed-notification-settings.ts` on deploy.
- Deferred to later waves: Email Templates admin tab (Wave 3), team-facing "My Logistics" (Wave 4).

View File

@@ -0,0 +1,113 @@
# Wave 3 — Enable the "Email Templates" tab (logistics hub)
> **For agentic workers:** REQUIRED SUB-SKILL: superpowers:subagent-driven-development. Steps use `- [ ]`.
**Goal:** Turn the disabled "Email Templates (soon)" tab in `/admin/logistics` into a working surface where admins can, for every logistics email, toggle it on/off, customize the subject, **preview** the rendered email, and send a test to themselves — reusing the existing notification-settings infra.
**Architecture:** Reuse `notification.getEmailSettings` / `updateEmailSetting` / `sendTestEmail` (already built) scoped to the `logistics` category (the 8 types seeded in Wave 2). The only new server capability is **preview without sending**: extract a `renderNotificationEmail(...)` from `sendStyledNotificationEmail` and expose a `notification.previewEmailTemplate({ notificationType })` query returning `{ subject, html }`. UI reuses the existing `EmailPreviewDialog` (with `previewOnly`).
**Tech Stack:** Next.js 15, tRPC 11, shadcn/ui. No schema change.
**Key facts (verified 2026-06-04):**
- `notification.getEmailSettings` (`src/server/routers/notification.ts:140`) returns all `NotificationEmailSetting` rows (incl. our 8 `category:'logistics'` rows).
- `notification.updateEmailSetting` (`:152`) accepts `{ notificationType, sendEmail, emailSubject?, emailTemplate? }`.
- `notification.sendTestEmail` (`:243`) renders via `sendStyledNotificationEmail` using a per-type `sampleData` map (which currently has NO logistics entries → previews/tests render with template fallbacks).
- `sendStyledNotificationEmail` (`src/lib/email.ts:2400`) looks up `NOTIFICATION_EMAIL_TEMPLATES[type]`, else falls back to `getNotificationEmailTemplate`. Our 4 custom templates are registered; the 4 admin-alert types use the fallback.
- `EmailPreviewDialog` (`src/components/admin/round/email-preview-dialog.tsx`) props: `{ open, onOpenChange, title, description, recipientCount, previewHtml, isPreviewLoading, onSend, isSending, showCustomMessage?, onRefreshPreview?, previewOnly? }`.
- The existing global form `src/components/settings/notification-settings-form.tsx` renders categories team/jury/mentor/observer/admin — NOT `logistics`.
---
## Task 1: Server — render-without-send + preview query + logistics sample data
**Files:** `src/lib/email.ts`, `src/server/routers/notification.ts`; test `tests/unit/notification-preview.test.ts`.
- [ ] **Step 1:** In `src/lib/email.ts`, extract the template-resolution logic of `sendStyledNotificationEmail` into an exported pure function:
```ts
export function renderNotificationEmail(
name: string,
type: string,
context: NotificationEmailContext,
subjectOverride?: string,
): EmailTemplate {
const generator = NOTIFICATION_EMAIL_TEMPLATES[type]
const template = generator
? generator({ ...context, name })
: getNotificationEmailTemplate(name, subjectOverride || context.title, context.message, ensureAbsoluteUrl(context.linkUrl))
return subjectOverride ? { ...template, subject: subjectOverride } : template
}
```
Then refactor `sendStyledNotificationEmail` to call `renderNotificationEmail(...)` and `sendEmail(...)` the result (keep its existing signature/behavior identical — verify by re-running any notification email tests).
- [ ] **Step 2:** In `src/server/routers/notification.ts`, hoist the `sampleData` map (currently inside `sendTestEmail`) to a module-level `const NOTIFICATION_SAMPLE_DATA` and ADD logistics entries so previews/tests are realistic:
```ts
FINALIST_CONFIRMED: { projectTitle: 'Ocean Cleanup Initiative', category: 'STARTUP' },
FINALIST_DECLINED: { projectTitle: 'Ocean Cleanup Initiative', category: 'STARTUP' },
FINALIST_EXPIRED: { projectTitle: 'Ocean Cleanup Initiative', category: 'STARTUP' },
FINALIST_WAITLIST_PROMOTED:{ projectTitle: 'Reef Guardians', category: 'STARTUP' },
FINALIST_REMINDER: { projectTitle: 'Ocean Cleanup Initiative', deadline: new Date(Date.now()+86_400_000).toISOString() },
FINALIST_WITHDRAWN: { projectTitle: 'Ocean Cleanup Initiative', reason: 'Schedule conflict' },
TRAVEL_CONFIRMED: { projectTitle: 'Ocean Cleanup Initiative', arrivalAt: new Date(Date.now()+5*86_400_000).toISOString(), arrivalFlightNumber: 'AF1234', arrivalAirport: 'NCE', departureAt: new Date(Date.now()+7*86_400_000).toISOString(), departureFlightNumber: 'AF1235', departureAirport: 'NCE', hotel: { name: 'Hotel de Paris', address: 'Place du Casino, Monaco', link: 'https://example.com' } },
VISA_STATUS_UPDATE: { projectTitle: 'Ocean Cleanup Initiative', status: 'GRANTED' },
```
Have `sendTestEmail` use `NOTIFICATION_SAMPLE_DATA` (behavior unchanged otherwise).
- [ ] **Step 3:** Add a `previewEmailTemplate` adminProcedure query:
```ts
previewEmailTemplate: adminProcedure
.input(z.object({ notificationType: z.string() }))
.query(async ({ ctx, input }) => {
const setting = await ctx.prisma.notificationEmailSetting.findUnique({ where: { notificationType: input.notificationType } })
const label = setting?.label || input.notificationType
const metadata = NOTIFICATION_SAMPLE_DATA[input.notificationType] || {}
const rendered = renderNotificationEmail(ctx.user.name || 'Admin', input.notificationType, {
title: label,
message: `Preview of the "${label}" email.`,
linkUrl: `${process.env.NEXTAUTH_URL || ''}/applicant`,
linkLabel: 'Open',
metadata,
}, setting?.emailSubject || undefined)
return { subject: rendered.subject, html: rendered.html, hasStyledTemplate: input.notificationType in NOTIFICATION_EMAIL_TEMPLATES }
}),
```
Import `renderNotificationEmail` from `@/lib/email`.
- [ ] **Step 4: Test** (`tests/unit/notification-preview.test.ts`): call `notification.previewEmailTemplate({ notificationType: 'VISA_STATUS_UPDATE' })` via an admin caller; assert `html` contains a recognizable string (e.g. 'visa' or 'Grand Finale') and `subject` is non-empty. Also test a fallback type (`FINALIST_EXPIRED`) returns non-empty `html`. (Pattern: `createCaller(notificationRouter, {SUPER_ADMIN})`.)
- [ ] **Step 5:** `npx vitest run tests/unit/notification-preview.test.ts` → pass. `npm run typecheck` → clean.
- [ ] **Step 6: Commit**`git commit -am "feat(notifications): renderNotificationEmail + previewEmailTemplate + logistics sample data"`
---
## Task 2: UI — logistics Email Templates tab + show logistics in global settings
**Files:** create `src/components/admin/logistics/email-templates-tab.tsx`; modify `src/components/settings/notification-settings-form.tsx`.
- [ ] **Step 1:** Add `logistics: { label: 'Logistics', icon: Plane }` to the `CATEGORIES` map in `notification-settings-form.tsx` (import `Plane` from lucide-react) so logistics settings are also manageable on the global settings page.
- [ ] **Step 2:** Build `EmailTemplatesTab` (`src/components/admin/logistics/email-templates-tab.tsx`), `'use client'`, mirroring `NotificationSettingsForm`'s structure but: (a) filter `trpc.notification.getEmailSettings` to `category === 'logistics'`; (b) per row show the toggle (`updateEmailSetting`), a **subject** input (debounced `onBlur``updateEmailSetting({ notificationType, sendEmail, emailSubject })`), a **Test** button (`sendTestEmail`), and a **Preview** button; (c) Preview opens `EmailPreviewDialog` with `previewOnly`, fetching `trpc.notification.previewEmailTemplate({ notificationType })` (lazy, `enabled: !!previewType`) and passing its `html` to `previewHtml`. Loading → Skeleton; empty → "No logistics email types found — run the notification settings seed." Use sonner toasts + `trpc.useUtils()` invalidation.
- [ ] **Step 3:** `npm run typecheck` → clean.
- [ ] **Step 4: Commit**`git commit -am "feat(logistics): Email Templates tab (toggle/subject/preview/test) + logistics in global settings"`
---
## Task 3: Enable the tab in the logistics page
**Files:** `src/app/(admin)/admin/logistics/page.tsx`.
- [ ] **Step 1:** Remove `disabled` + the "(soon)" span from the `email-templates` `TabsTrigger`; import and add `<TabsContent value="email-templates"><EmailTemplatesTab programId={programId} /></TabsContent>` (the tab doesn't strictly need programId — settings are global — but pass it for consistency / future scoping; if unused, omit the prop).
- [ ] **Step 2:** `npm run typecheck` → clean.
- [ ] **Step 3: Commit**`git commit -am "feat(logistics): enable Email Templates tab"`
---
## Task 4: Verify
- [ ] **Step 1:** `npx vitest run` — full suite green.
- [ ] **Step 2:** `npm run typecheck` — clean. Stop dev server, `rm -rf .next`, `npm run build` — clean.
- [ ] **Step 3:** Restart dev on :3001; dev smoke: `/admin/logistics` → Email Templates tab renders the 8 logistics types; toggle one off/on (persists); click Preview on `VISA_STATUS_UPDATE` → dialog shows the rendered branded email; click Test → success toast (email swallowed by localhost SMTP in dev — fine). Screenshot.
- [ ] **Step 4:** Summarize.
## Notes
- No new email is sent automatically by this wave — it only adds admin visibility/control over the Wave-2 emails.
- Deferred to Wave 4: team-facing "My Logistics" + travel/visa UX fixes.

View File

@@ -0,0 +1,101 @@
# Wave 4 — Team-facing "My Logistics" + travel/visa UX fixes
> **For agentic workers:** REQUIRED SUB-SKILL: superpowers:subagent-driven-development. Steps use `- [ ]`.
**Goal:** Close the loop for finalist teams. Today a confirmed team can see only their attendee roster + a visa badge; they have no view of their flights or hotel, can't self-enter passport nationality, and the submitter (non-TeamMember lead) can't even see the card. This wave adds a team-facing "My Logistics" view (flights + hotel + visa + nationality self-entry), fixes the submitter gap, links the confirm-success page to the dashboard, and adds the admin-side travel/visa correctness fixes (departure-after-arrival validation, CSV export).
**Architecture:** New read procedures on the applicant router (`getMyLogistics`) reusing the same caller→project resolution as the existing finalist procedures, plus a self-service `updateMyVisaNationality`. A new applicant dashboard card. Admin-side: input validation on `logistics.upsertFlightDetail` + CSV export buttons mirroring the lunch manifest.
**Tech Stack:** Next.js 15, tRPC 11, Prisma 6, shadcn/ui. No schema change.
**Key facts (verified 2026-06-04):**
- `applicant.getMyFinalistConfirmation` (`src/server/routers/applicant.ts:2748`) resolves the project via `teamMembers: { some: { userId } }` — MISSES a lead who submitted but has no TeamMember row, and has no role guard.
- `applicant.getMyVisaApplications` (`:2819`) returns visa rows when `program.visaStatusVisibleToMembers`, else null. Reuse its visibility logic.
- Admin-only: `logistics.getHotel`, `logistics.listFlightDetails` (`src/server/routers/logistics.ts`). No team-facing equivalents → teams never see hotel/flights.
- Applicant dashboard composes cards in `src/app/(applicant)/applicant/page.tsx` (~line 409): `LunchBanner`, `ExternalAttendeesStrip`, `AttendingMembersCard`. Add the new card here.
- Confirm-success copy at `src/app/(public)/finalist/confirm/[token]/page.tsx:183` promises "your project page" with no link.
- `logistics.upsertFlightDetail` input (`:145`) has no departure-after-arrival check. Lunch CSV export pattern: `src/components/admin/logistics/lunch-manifest.tsx:28-57`.
- Models: `Hotel{ name, address?, link?, notes? }` (programId 1:1); `FlightDetail{ arrival/departure At/FlightNumber/Airport, status, adminNotes }` (per AttendingMember); `VisaApplication{ status, nationality?, ... }`.
---
## Task 1: Team-facing read endpoint + submitter fix
**Files:** `src/server/routers/applicant.ts`; test `tests/unit/applicant-my-logistics.test.ts`.
- [ ] **Step 1:** Fix `getMyFinalistConfirmation` resolution: change the `where` to
`{ OR: [{ submittedByUserId: ctx.user.id }, { teamMembers: { some: { userId: ctx.user.id } } }], finalistConfirmation: { isNot: null } }`
(verify `Project.submittedByUserId` is the correct field name in schema). Keep the rest. (No role guard added — APPLICANT/lead may not have an explicit role; the project-scoping is the guard. If other procedures in this router use a role check, match it; otherwise leave project-scoping as the guard and note it.)
- [ ] **Step 2:** Add `getMyLogistics: protectedProcedure.query`:
- Resolve the caller's confirmed-finalist project (same OR-resolution as above; return `null` if none or confirmation not CONFIRMED).
- Return:
```ts
{
projectTitle: string,
confirmationStatus: FinalistConfirmationStatus,
hotel: { name, address, link, notes } | null, // program Hotel (1:1)
myFlight: { arrivalAt, arrivalFlightNumber, arrivalAirport, departureAt, departureFlightNumber, departureAirport, status } | null, // the caller's own AttendingMember.flightDetail
visaVisible: boolean, // program.visaStatusVisibleToMembers
myVisa: { status, nationality } | null, // caller's own VisaApplication, only when visaVisible
}
```
- `myFlight`: find the caller's `AttendingMember` for this confirmation (`where confirmationId + userId`), include `flightDetail`. `hotel`: `prisma.hotel.findUnique({ where: { programId } })`. `myVisa`: only when `visaVisible` and the caller's AttendingMember has a `visaApplication`.
- [ ] **Step 3: Test** — set up a CONFIRMED finalist with the caller as an AttendingMember, a Hotel, a FlightDetail (CONFIRMED), `visaStatusVisibleToMembers:true`, a VisaApplication GRANTED. Call `getMyLogistics` as that user → assert `hotel.name`, `myFlight.arrivalFlightNumber`, `visaVisible:true`, `myVisa.status==='GRANTED'`. Also: a non-finalist user → `null`. (Caller via `createCaller(applicantRouter, { id, email, role:'APPLICANT' })`.)
- [ ] **Step 4:** `npx vitest run tests/unit/applicant-my-logistics.test.ts` → pass; re-run any applicant tests touching these procedures. `npm run typecheck` → clean.
- [ ] **Step 5: Commit** — `git commit -am "feat(applicant): getMyLogistics (hotel+flight+visa) + submitter-match fix"`
---
## Task 2: Self-service nationality entry
**Files:** `src/server/routers/applicant.ts`; test in the same file.
- [ ] **Step 1:** Add `updateMyVisaNationality: protectedProcedure.input(z.object({ nationality: z.string().max(100) })).mutation`:
- Find the caller's `AttendingMember` whose program has `visaStatusVisibleToMembers:true` and which has a `VisaApplication`; if none → `TRPCError NOT_FOUND` ("No visa application to update").
- Update that `VisaApplication.nationality`. Audit `VISA_NATIONALITY_SELF_SET`. Return `{ ok: true }`.
- (Optional nicety: also copy to `User.nationality` if empty.)
- [ ] **Step 2: Test** — caller with a visible VisaApplication sets nationality → assert it persisted. Caller without one → rejects.
- [ ] **Step 3:** Run → pass. `npm run typecheck` → clean.
- [ ] **Step 4: Commit** — `git commit -am "feat(applicant): self-service visa nationality entry"`
---
## Task 3: "My Logistics" card + confirm-page link
**Files:** create `src/components/applicant/my-logistics-card.tsx`; modify `src/app/(applicant)/applicant/page.tsx`, `src/app/(public)/finalist/confirm/[token]/page.tsx`.
- [ ] **Step 1:** Build `MyLogisticsCard` (`'use client'`): `trpc.applicant.getMyLogistics.useQuery()`. If `null` or loading → render nothing / Skeleton. Otherwise a Card "Your grand-finale logistics" with sections:
- **Hotel** — name + address + link (if present), else "Hotel details coming soon."
- **Flights** — the caller's arrival/departure (flight no, airport, formatted date/time in Europe/Paris) + a status badge, else "Your flight details will appear here once arranged."
- **Visa** (only if `visaVisible`) — status badge + a nationality field: shows current `myVisa.nationality` or an inline editable input → `trpc.applicant.updateMyVisaNationality` (sonner toast + invalidate).
Follow the visual pattern of `attending-members-card.tsx`. Visible affordances only.
- [ ] **Step 2:** Render `<MyLogisticsCard />` in `src/app/(applicant)/applicant/page.tsx` near `AttendingMembersCard` (~line 415).
- [ ] **Step 3:** In the confirm-success block (`finalist/confirm/[token]/page.tsx:168-185`), replace the dead "your project page" sentence with a real link/button to `/applicant` ("Go to my dashboard"). (The confirm page is public; the link will hit auth and land them on their dashboard after login.)
- [ ] **Step 4:** `npm run typecheck` → clean.
- [ ] **Step 5: Commit** — `git commit -am "feat(applicant): My Logistics card (hotel/flights/visa+nationality) + confirm-page dashboard link"`
---
## Task 4: Admin travel/visa UX — validation + CSV export
**Files:** `src/server/routers/logistics.ts`, `src/components/admin/logistics/travel-tab.tsx`, `src/components/admin/logistics/visas-tab.tsx`; test `tests/unit/logistics-flight.test.ts` (extend).
- [ ] **Step 1:** Server validation in `logistics.upsertFlightDetail`: after building `data`, if both `arrivalAt` and `departureAt` are present and `departureAt < arrivalAt`, throw `TRPCError BAD_REQUEST` ("Departure must be after arrival"). Add a test asserting the rejection.
- [ ] **Step 2:** CSV export — add a "Download CSV" button to `travel-tab.tsx` (columns: Project, Attendee, Email, Arrival date/time, Arrival flight, Arrival airport, Departure date/time, Departure flight, Departure airport, Status, Needs visa) and to `visas-tab.tsx` (columns: Project, Attendee, Email, Nationality, Status, Invitation sent, Appointment, Decision, Notes). MIRROR the CSV builder in `src/components/admin/logistics/lunch-manifest.tsx:28-57` (Blob + anchor download; escape commas/quotes). Build from the data already loaded by each tab's query.
- [ ] **Step 3:** `npx vitest run tests/unit/logistics-flight.test.ts` → pass. `npm run typecheck` → clean.
- [ ] **Step 4: Commit** — `git commit -am "feat(logistics): departure-after-arrival validation + travel/visa CSV export"`
---
## Task 5: Verify
- [ ] **Step 1:** `npx vitest run` — full suite green.
- [ ] **Step 2:** `npm run typecheck` — clean. Stop dev, `rm -rf .next`, `npm run build` — clean.
- [ ] **Step 3:** Restart dev on :3001. Dev smoke: as admin, enroll a team (ADMIN_CONFIRM) and add flight + hotel + set a visa; then log in as that team's lead (seed user `matt@letsbe.solutions` is a MEMBER of "Revamp Flips" — or use the lead) and confirm the "My Logistics" card shows the hotel + flight + visa + nationality field. Verify the CSV export downloads. Clean up.
- [ ] **Step 4:** Summarize.
## Notes
- Deep timezone overhaul of the admin flight `datetime-local` inputs (storing explicit Europe/Paris) is a separate design decision — NOT in this wave; the validation + Europe/Paris display labels are the pragmatic improvement. Flag as remaining polish.
- This completes the 4-wave logistics overhaul.

View File

@@ -0,0 +1,745 @@
# Grand Final Judge-Doc Curation + Optional Uploads Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Let admins curate which previously-submitted documents finale judges see, and make the "optional revised uploads" mode render correctly for finalists.
**Architecture:** Everything builds on the existing `final-documents.ts` service + `finalist` tRPC router + the LIVE_FINAL round's `configJson` (same pattern as the shipped `allowFinalistRevisedUploads` toggle). A new configJson key `reviewVisibleRequirementIds` filters the judge review payload; new status fields `hasRequired`/`allUploaded` drive optional-mode rendering in the finalist banner/panel. No schema migration.
**Tech Stack:** Next.js 15 App Router, tRPC 11 + Zod, Prisma 6, Vitest 4 (sequential, real test DB), shadcn/ui (Card/Switch/Checkbox).
**Spec:** `docs/superpowers/specs/2026-06-09-finale-doc-curation-optional-uploads-design.md`
**Conventions for every task:** TypeScript strict, `type` over `interface`. Tests use the factories in `tests/helpers.ts` (`createTestProgram`, `createTestCompetition`, `createTestRound`, `createTestProject`, `createTestProjectRoundState`, `createTestUser`, `uid`) and clean up with `cleanupTestData(programId, userIds?)` in `afterAll`. Run a single file with `npx vitest run tests/unit/<file>.test.ts`.
---
### Task 1: `hasRequired` + `allUploaded` on `FinalDocumentStatus`
**Files:**
- Modify: `src/server/services/final-documents.ts` (type at ~line 14, computation at ~line 95)
- Test: `tests/unit/final-documents.test.ts` (extend existing file)
- [ ] **Step 1: Write the failing tests**
In `tests/unit/final-documents.test.ts`, first extend the `makeFinaleProgram` factory (top of file) with an `optionalRequirements` option — change the two `fileRequirement.create` calls to use it:
```ts
async function makeFinaleProgram(
opts: { roundStatus?: 'ROUND_ACTIVE' | 'ROUND_DRAFT' | 'ROUND_CLOSED'; closeAt?: Date; skipRequirements?: boolean; uploadsEnabled?: boolean; optionalRequirements?: boolean } = {},
) {
// ... existing body unchanged, except both requirement creates:
// isRequired: !opts.optionalRequirements
}
```
Then add inside the existing `describe('getFinalDocumentStatusForProject', ...)` block:
```ts
it('all-optional round: hasRequired false, allUploaded flips when every slot has a file', async () => {
const { program, round, reqPlan, reqVideo } = await makeFinaleProgram({ optionalRequirements: true })
const project = await createTestProject(program.id)
await createTestProjectRoundState(project.id, round.id)
const before = await getFinalDocumentStatusForProject(prisma, project.id)
expect(before!.hasRequired).toBe(false)
expect(before!.allUploaded).toBe(false)
expect(before!.allRequiredUploaded).toBe(false)
for (const req of [reqPlan!, reqVideo!]) {
await prisma.projectFile.create({
data: {
id: uid('file'), projectId: project.id, roundId: round.id, requirementId: req.id,
fileType: 'SUPPORTING_DOC', fileName: `f-${req.id}`, mimeType: 'application/pdf', size: 10,
bucket: 'b', objectKey: uid('key'),
},
})
}
const after = await getFinalDocumentStatusForProject(prisma, project.id)
expect(after!.hasRequired).toBe(false)
expect(after!.allUploaded).toBe(true)
})
it('mixed round: hasRequired true; allUploaded only when optional slots are filled too', async () => {
const { program, round, reqPlan } = await makeFinaleProgram()
await prisma.fileRequirement.update({ where: { id: reqPlan!.id }, data: { isRequired: false } })
const project = await createTestProject(program.id)
await createTestProjectRoundState(project.id, round.id)
const status = await getFinalDocumentStatusForProject(prisma, project.id)
expect(status!.hasRequired).toBe(true) // reqVideo still required
expect(status!.allUploaded).toBe(false)
})
it('zero slots: allUploaded false (no vacuous completeness)', async () => {
const { program, round } = await makeFinaleProgram({ skipRequirements: true })
const project = await createTestProject(program.id)
await createTestProjectRoundState(project.id, round.id)
const status = await getFinalDocumentStatusForProject(prisma, project.id)
expect(status!.hasRequired).toBe(false)
expect(status!.allUploaded).toBe(false)
})
```
- [ ] **Step 2: Run tests to verify they fail**
Run: `npx vitest run tests/unit/final-documents.test.ts`
Expected: the 3 new tests FAIL with TypeScript/undefined errors on `hasRequired` / `allUploaded` (fields don't exist yet); all pre-existing tests still pass.
- [ ] **Step 3: Implement**
In `src/server/services/final-documents.ts`, extend the type (~line 14):
```ts
export type FinalDocumentStatus = {
roundId: string
roundName: string
deadline: Date | null
deadlinePassed: boolean
requirements: FinalDocRequirement[]
allRequiredUploaded: boolean
hasRequired: boolean // any slot is marked required
allUploaded: boolean // every listed slot has a file (false when no slots exist)
}
```
And in `getFinalDocumentStatusForProject` (~line 95), replace the return-value computation:
```ts
const required = reqStatuses.filter((r) => r.isRequired)
const allRequiredUploaded = required.length > 0 && required.every((r) => r.uploaded)
const hasRequired = required.length > 0
const allUploaded = reqStatuses.length > 0 && reqStatuses.every((r) => r.uploaded)
const deadline = round.windowCloseAt ?? null
return {
roundId: round.id,
roundName: round.name,
deadline,
deadlinePassed: deadline ? new Date() > deadline : false,
requirements: reqStatuses,
allRequiredUploaded,
hasRequired,
allUploaded,
}
```
- [ ] **Step 4: Run tests to verify they pass**
Run: `npx vitest run tests/unit/final-documents.test.ts`
Expected: ALL tests pass (new + pre-existing).
- [ ] **Step 5: Commit**
```bash
git add src/server/services/final-documents.ts tests/unit/final-documents.test.ts
git commit -m "feat(final-docs): hasRequired/allUploaded on FinalDocumentStatus for optional-uploads mode"
```
---
### Task 2: Curation filter in `listFinalistDocumentsForReview`
**Files:**
- Modify: `src/server/services/final-documents.ts` (`listFinalistDocumentsForReview`, ~line 257; new helper next to `finalistUploadsEnabled` ~line 45)
- Test: Create `tests/unit/final-documents-curation.test.ts`
- [ ] **Step 1: Write the failing tests**
Create `tests/unit/final-documents-curation.test.ts`. The review service presigns every file via MinIO, so mock `getPresignedUrl` (partial module mock — keeps `BUCKET_NAME` etc. real):
```ts
import { describe, it, expect, afterAll, vi } from 'vitest'
vi.mock('@/lib/minio', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/lib/minio')>()
return { ...actual, getPresignedUrl: vi.fn(async () => 'https://example.test/presigned') }
})
import { prisma } from '../setup'
import {
createTestProgram,
createTestCompetition,
createTestRound,
createTestProject,
createTestProjectRoundState,
cleanupTestData,
uid,
} from '../helpers'
import { listFinalistDocumentsForReview } from '@/server/services/final-documents'
const programIds: string[] = []
afterAll(async () => {
for (const id of programIds) await cleanupTestData(id)
})
/**
* One finalist team with 4 files:
* - Business Plan (prior SUBMISSION round, via requirement reqBP)
* - Pitch Deck (prior SUBMISSION round, via requirement reqDeck)
* - loose.pdf (prior SUBMISSION round, NO requirement)
* - final.mp4 (uploaded directly to the LIVE_FINAL round, via reqFinal)
*/
async function setupCuration() {
const program = await createTestProgram()
programIds.push(program.id)
const comp = await createTestCompetition(program.id, { status: 'ACTIVE' })
const priorRound = await createTestRound(comp.id, { roundType: 'SUBMISSION', status: 'ROUND_CLOSED', sortOrder: 2 })
const reqBP = await prisma.fileRequirement.create({
data: { id: uid('req'), roundId: priorRound.id, name: 'Business Plan', acceptedMimeTypes: ['application/pdf'], isRequired: true, sortOrder: 1 },
})
const reqDeck = await prisma.fileRequirement.create({
data: { id: uid('req'), roundId: priorRound.id, name: 'Pitch Deck', acceptedMimeTypes: ['application/pdf'], isRequired: true, sortOrder: 2 },
})
const finale = await createTestRound(comp.id, {
roundType: 'LIVE_FINAL', status: 'ROUND_ACTIVE', sortOrder: 6,
windowCloseAt: new Date(Date.now() + 86_400_000),
configJson: { allowFinalistRevisedUploads: true },
})
const reqFinal = await prisma.fileRequirement.create({
data: { id: uid('req'), roundId: finale.id, name: '1-minute Video', acceptedMimeTypes: ['video/*'], isRequired: false, sortOrder: 1 },
})
const project = await createTestProject(program.id)
await createTestProjectRoundState(project.id, finale.id)
const mkFile = (roundId: string, requirementId: string | null, fileName: string) =>
prisma.projectFile.create({
data: {
id: uid('file'), projectId: project.id, roundId, requirementId,
fileType: 'SUPPORTING_DOC', fileName, mimeType: 'application/pdf', size: 10,
bucket: 'b', objectKey: uid('key'),
},
})
await mkFile(priorRound.id, reqBP.id, 'bp.pdf')
await mkFile(priorRound.id, reqDeck.id, 'deck.pdf')
await mkFile(priorRound.id, null, 'loose.pdf')
await mkFile(finale.id, reqFinal.id, 'final.mp4')
return { program, priorRound, finale, reqBP, reqDeck, reqFinal, project }
}
async function setSelection(roundId: string, ids: string[] | null) {
const round = await prisma.round.findUniqueOrThrow({ where: { id: roundId }, select: { configJson: true } })
const cfg = (round.configJson ?? {}) as Record<string, unknown>
if (ids === null) delete cfg.reviewVisibleRequirementIds
else cfg.reviewVisibleRequirementIds = ids
await prisma.round.update({ where: { id: roundId }, data: { configJson: cfg as object } })
}
describe('listFinalistDocumentsForReview curation', () => {
it('no selection key → all files visible (current behavior)', async () => {
const { program } = await setupCuration()
const result = await listFinalistDocumentsForReview(prisma, program.id)
expect(result.teams).toHaveLength(1)
expect(result.teams[0].files).toHaveLength(4)
})
it('selection → only matching prior files, finale uploads always visible', async () => {
const { program, finale, reqBP } = await setupCuration()
await setSelection(finale.id, [reqBP.id])
const result = await listFinalistDocumentsForReview(prisma, program.id)
const names = result.teams[0].files.map((f) => f.fileName).sort()
expect(names).toEqual(['bp.pdf', 'final.mp4']) // deck.pdf and loose.pdf hidden
})
it('empty selection → only finale uploads visible', async () => {
const { program, finale } = await setupCuration()
await setSelection(finale.id, [])
const result = await listFinalistDocumentsForReview(prisma, program.id)
expect(result.teams[0].files.map((f) => f.fileName)).toEqual(['final.mp4'])
})
it('prior file without a requirement is excluded under any selection', async () => {
const { program, finale, reqBP, reqDeck } = await setupCuration()
await setSelection(finale.id, [reqBP.id, reqDeck.id])
const result = await listFinalistDocumentsForReview(prisma, program.id)
expect(result.teams[0].files.map((f) => f.fileName)).not.toContain('loose.pdf')
})
})
```
- [ ] **Step 2: Run tests to verify they fail**
Run: `npx vitest run tests/unit/final-documents-curation.test.ts`
Expected: the first test PASSES (current behavior), the other three FAIL (filter not implemented — they see all 4 files).
- [ ] **Step 3: Implement**
In `src/server/services/final-documents.ts`, add a config reader next to `finalistUploadsEnabled` (~line 45):
```ts
/**
* Which prior-round FileRequirement ids are visible to finale judges.
* null = no curation (show all prior files). Empty array = hide all prior
* files (Grand Final round uploads are always shown regardless).
*/
export function reviewVisibleRequirementIds(configJson: unknown): string[] | null {
const v = (configJson as { reviewVisibleRequirementIds?: unknown } | null)?.reviewVisibleRequirementIds
return Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string') : null
}
```
In `listFinalistDocumentsForReview`:
1. After the `if (!round) return ...` guard, read the selection: `const visibleIds = reviewVisibleRequirementIds(round.configJson)`
2. Add `requirementId: true` to the `allFiles` select.
3. At the top of the `for (const f of allFiles)` loop, before building `rf`:
```ts
const isFinaleUpload = f.roundId === round.id
// Curated mode: prior-round files must match a selected requirement; finale uploads always pass.
if (!isFinaleUpload && visibleIds !== null && (!f.requirementId || !visibleIds.includes(f.requirementId))) continue
```
4. Use the `isFinaleUpload` const in the `rf` object (replacing the inline `f.roundId === round.id`).
- [ ] **Step 4: Run tests to verify they pass**
Run: `npx vitest run tests/unit/final-documents-curation.test.ts`
Expected: all 4 PASS.
Also run the neighbors to catch regressions: `npx vitest run tests/unit/final-documents.test.ts`
Expected: all PASS.
- [ ] **Step 5: Commit**
```bash
git add src/server/services/final-documents.ts tests/unit/final-documents-curation.test.ts
git commit -m "feat(final-docs): filter judge review by reviewVisibleRequirementIds (finale uploads always shown)"
```
---
### Task 3: Picker options helper `listReviewVisibilityOptions`
**Files:**
- Modify: `src/server/services/final-documents.ts` (new exported function + type, after `listFinalistDocumentsForReview`)
- Test: `tests/unit/final-documents-curation.test.ts` (extend)
- [ ] **Step 1: Write the failing tests**
Add to `tests/unit/final-documents-curation.test.ts` (import `listReviewVisibilityOptions` from the same service module):
```ts
describe('listReviewVisibilityOptions', () => {
it('lists distinct prior-round slots with counts; excludes finale-round slots and requirement-less files', async () => {
const { program, reqBP, reqDeck } = await setupCuration()
const options = await listReviewVisibilityOptions(prisma, program.id)
expect(options.map((o) => o.requirementId).sort()).toEqual([reqBP.id, reqDeck.id].sort())
const bp = options.find((o) => o.requirementId === reqBP.id)!
expect(bp.name).toBe('Business Plan')
expect(bp.fileCount).toBe(1)
expect(bp.roundName).toBeTruthy()
})
it('returns [] when there is no open finale round', async () => {
const program = await createTestProgram()
programIds.push(program.id)
expect(await listReviewVisibilityOptions(prisma, program.id)).toEqual([])
})
})
```
- [ ] **Step 2: Run tests to verify they fail**
Run: `npx vitest run tests/unit/final-documents-curation.test.ts`
Expected: FAIL — `listReviewVisibilityOptions` is not exported.
- [ ] **Step 3: Implement**
In `src/server/services/final-documents.ts`, after `listFinalistDocumentsForReview`:
```ts
export type ReviewDocSlot = {
requirementId: string
name: string
roundName: string
roundSort: number
fileCount: number
}
/**
* Distinct prior-round document slots (FileRequirements) that the finalist
* teams have files for — the options offered in the admin "documents shown to
* judges" picker. Excludes the finale round's own slots (those uploads are
* always visible to judges) and files without a requirement.
*/
export async function listReviewVisibilityOptions(prisma: PrismaClient, programId: string): Promise<ReviewDocSlot[]> {
const round = await getOpenFinaleRound(prisma, programId)
if (!round) return []
const states = await prisma.projectRoundState.findMany({ where: { roundId: round.id }, select: { projectId: true } })
const files = await prisma.projectFile.findMany({
where: { projectId: { in: states.map((s) => s.projectId) }, requirement: { roundId: { not: round.id } } },
select: {
requirementId: true,
requirement: { select: { name: true, round: { select: { name: true, sortOrder: true } } } },
},
})
const slots = new Map<string, ReviewDocSlot>()
for (const f of files) {
if (!f.requirementId || !f.requirement) continue
const existing = slots.get(f.requirementId)
if (existing) existing.fileCount++
else slots.set(f.requirementId, {
requirementId: f.requirementId,
name: f.requirement.name.trim(),
roundName: f.requirement.round.name,
roundSort: f.requirement.round.sortOrder,
fileCount: 1,
})
}
return [...slots.values()].sort((a, b) => a.roundSort - b.roundSort || a.name.localeCompare(b.name))
}
```
- [ ] **Step 4: Run tests to verify they pass**
Run: `npx vitest run tests/unit/final-documents-curation.test.ts`
Expected: all PASS.
- [ ] **Step 5: Commit**
```bash
git add src/server/services/final-documents.ts tests/unit/final-documents-curation.test.ts
git commit -m "feat(final-docs): listReviewVisibilityOptions — distinct prior-round doc slots for the curation picker"
```
---
### Task 4: tRPC procedures `getReviewDocSettings` / `setReviewVisibleRequirements`
**Files:**
- Modify: `src/server/routers/finalist.ts` (add two procedures next to `getRevisedUploadSetting`/`setRevisedUploadSetting`, ~line 1695; extend the existing `@/server/services/final-documents` import with `listReviewVisibilityOptions` and `reviewVisibleRequirementIds`)
- Test: `tests/unit/final-documents-curation.test.ts` (extend)
- [ ] **Step 1: Write the failing tests**
Add to `tests/unit/final-documents-curation.test.ts`:
```ts
import * as finalistRouter from '@/server/routers/finalist'
import { createCaller } from '../setup'
import { createTestUser } from '../helpers' // merge into the existing helpers import
describe('finalist review-doc settings procedures', () => {
const userIds: string[] = []
afterAll(async () => {
// cleanupTestData of programIds already runs in the file-level afterAll;
// pass userIds through an extra cleanup for the admin users:
for (const id of programIds) await cleanupTestData(id, userIds)
})
it('round-trips a selection and preserves sibling configJson keys', async () => {
const { program, finale, reqBP } = await setupCuration()
const admin = await createTestUser('PROGRAM_ADMIN')
userIds.push(admin.id)
const caller = createCaller(finalistRouter.finalistRouter, admin)
const initial = await caller.getReviewDocSettings({ programId: program.id, roundId: finale.id })
expect(initial.selectedIds).toBeNull()
expect(initial.options.length).toBe(2)
await caller.setReviewVisibleRequirements({ roundId: finale.id, requirementIds: [reqBP.id] })
const curated = await caller.getReviewDocSettings({ programId: program.id, roundId: finale.id })
expect(curated.selectedIds).toEqual([reqBP.id])
// sibling key from setupCuration must survive
const round = await prisma.round.findUniqueOrThrow({ where: { id: finale.id }, select: { configJson: true } })
expect((round.configJson as Record<string, unknown>).allowFinalistRevisedUploads).toBe(true)
await caller.setReviewVisibleRequirements({ roundId: finale.id, requirementIds: null })
const cleared = await caller.getReviewDocSettings({ programId: program.id, roundId: finale.id })
expect(cleared.selectedIds).toBeNull()
})
it('rejects a non-LIVE_FINAL round', async () => {
const { program, priorRound } = await setupCuration()
const admin = await createTestUser('PROGRAM_ADMIN')
userIds.push(admin.id)
const caller = createCaller(finalistRouter.finalistRouter, admin)
await expect(
caller.setReviewVisibleRequirements({ roundId: priorRound.id, requirementIds: [] }),
).rejects.toThrow()
void program
})
})
```
(Adjust the top-of-file `../helpers` import to include `createTestUser` rather than re-importing.)
- [ ] **Step 2: Run tests to verify they fail**
Run: `npx vitest run tests/unit/final-documents-curation.test.ts`
Expected: FAIL — `getReviewDocSettings` does not exist on the router.
- [ ] **Step 3: Implement**
In `src/server/routers/finalist.ts`, extend the existing service import with `listReviewVisibilityOptions, reviewVisibleRequirementIds`, then add after `setRevisedUploadSetting`:
```ts
/** Options + current selection for the "documents shown to judges" picker. */
getReviewDocSettings: adminProcedure
.input(z.object({ programId: z.string(), roundId: z.string() }))
.query(async ({ ctx, input }) => {
const round = await ctx.prisma.round.findUnique({ where: { id: input.roundId }, select: { configJson: true } })
return {
options: await listReviewVisibilityOptions(ctx.prisma, input.programId),
selectedIds: reviewVisibleRequirementIds(round?.configJson ?? null),
}
}),
/** Set which prior-round documents finale judges see. null = show all (clears curation). */
setReviewVisibleRequirements: adminProcedure
.input(z.object({ roundId: z.string(), requirementIds: z.array(z.string()).nullable() }))
.mutation(async ({ ctx, input }) => {
const round = await ctx.prisma.round.findUnique({ where: { id: input.roundId }, select: { configJson: true, roundType: true } })
if (!round || round.roundType !== 'LIVE_FINAL') {
throw new TRPCError({ code: 'BAD_REQUEST', message: 'Not a grand-final round' })
}
const { reviewVisibleRequirementIds: _omit, ...rest } = (round.configJson ?? {}) as Record<string, unknown>
const next = input.requirementIds === null ? rest : { ...rest, reviewVisibleRequirementIds: input.requirementIds }
await ctx.prisma.round.update({ where: { id: input.roundId }, data: { configJson: next } })
await logAudit({
prisma: ctx.prisma,
userId: ctx.user.id,
action: 'FINALIST_REVIEW_DOCS_CURATED',
entityType: 'Round',
entityId: input.roundId,
detailsJson: { requirementIds: input.requirementIds },
})
return { ok: true }
}),
```
Note: `data: { configJson: next }` may need `next as Prisma.InputJsonValue` depending on inference — match how the file already imports/uses Prisma types if the typechecker complains.
- [ ] **Step 4: Run tests to verify they pass**
Run: `npx vitest run tests/unit/final-documents-curation.test.ts`
Expected: all PASS. Then `npm run typecheck` — clean.
- [ ] **Step 5: Commit**
```bash
git add src/server/routers/finalist.ts tests/unit/final-documents-curation.test.ts
git commit -m "feat(final-docs): admin procedures to read/set judge-visible document curation"
```
---
### Task 5: Optional-mode rendering — banner + panel
No component-test infrastructure exists in this repo (vitest covers server code only) — verify via typecheck + the manual smoke in Task 7.
**Files:**
- Modify: `src/components/applicant/final-documents-banner.tsx`
- Modify: `src/components/applicant/final-documents-panel.tsx`
- [ ] **Step 1: Update the banner**
In `final-documents-banner.tsx`:
1. Guard (line 11): `if (!status || status.requirements.length === 0) return null`
2. Replace the `done` computation (line 18) and add the mode flag:
```ts
const optionalMode = !status.hasRequired
const done = status.hasRequired ? status.allRequiredUploaded : status.allUploaded
```
3. Replace the title span (lines 26-28):
```tsx
<span className="font-semibold">
{done
? optionalMode ? 'Grand Final documents uploaded' : 'Grand Final documents submitted'
: optionalMode ? 'Upload updated Grand Final documents (optional)' : 'Upload your Grand Final documents'}
</span>
```
Everything else (styling, checklist, deadline, button gated on `!done`) stays as is.
- [ ] **Step 2: Update the panel**
In `final-documents-panel.tsx`:
1. Guard (line 21): `if (!status || status.requirements.length === 0) return null`
2. Add after the guard: `const done = status.hasRequired ? status.allRequiredUploaded : status.allUploaded`
3. Replace both `status.allRequiredUploaded` usages (badge at line 29, team upload-button gate at line 51) with `done`.
4. Badge label: `{status.hasRequired ? 'Submitted' : 'Uploaded'}`
5. Description (line 38) — append the optional hint:
```tsx
<CardDescription>
{props.variant === 'team' ? 'Your final deliverables for the Grand Finale.' : 'This team\'s final deliverables for the Grand Finale.'}
{!status.hasRequired && ' These uploads are optional.'}
</CardDescription>
```
- [ ] **Step 3: Typecheck**
Run: `npm run typecheck`
Expected: clean. (The tRPC client types pick up `hasRequired`/`allUploaded` from Task 1 automatically.)
- [ ] **Step 4: Commit**
```bash
git add src/components/applicant/final-documents-banner.tsx src/components/applicant/final-documents-panel.tsx
git commit -m "feat(final-docs): optional-mode rendering for finalist banner + panel"
```
---
### Task 6: Admin "Documents shown to judges" card
**Files:**
- Create: `src/components/admin/grand-finale/review-docs-picker.tsx`
- Modify: `src/app/(admin)/admin/rounds/[roundId]/page.tsx` (import near line 100; render near line 1535)
- [ ] **Step 1: Create the picker component**
`src/components/admin/grand-finale/review-docs-picker.tsx` (full file):
```tsx
'use client'
import { trpc } from '@/lib/trpc/client'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Checkbox } from '@/components/ui/checkbox'
import { Switch } from '@/components/ui/switch'
import { Label } from '@/components/ui/label'
import { toast } from 'sonner'
import { Eye } from 'lucide-react'
/**
* Admin picker: which previously-submitted documents finale judges see on the
* review page. Default (switch off) shows everything; switching to curated
* mode starts with all slots ticked, and the admin unticks what to hide.
* Grand Final round uploads are always visible regardless.
*/
export function ReviewDocsPicker({ programId, roundId }: { programId: string; roundId: string }) {
const utils = trpc.useUtils()
const { data } = trpc.finalist.getReviewDocSettings.useQuery({ programId, roundId })
const set = trpc.finalist.setReviewVisibleRequirements.useMutation({
onSuccess: () => utils.finalist.getReviewDocSettings.invalidate({ programId, roundId }),
onError: (e) => toast.error(e.message),
})
if (!data || data.options.length === 0) return null
const curated = data.selectedIds !== null
const selected = new Set(data.selectedIds ?? data.options.map((o) => o.requirementId))
const toggleSlot = (id: string, on: boolean) => {
const next = new Set(selected)
if (on) next.add(id)
else next.delete(id)
set.mutate({ roundId, requirementIds: [...next] })
}
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2 text-lg">
<Eye className="h-5 w-5" /> Documents shown to judges
</CardTitle>
<CardDescription>
Choose which previously submitted documents judges see on the finalist review page.
Documents uploaded directly to this Grand Final round are always visible.
</CardDescription>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex items-center gap-2">
<Switch
id="curate-review-docs"
checked={curated}
disabled={set.isPending}
onCheckedChange={(v) =>
set.mutate({ roundId, requirementIds: v ? data.options.map((o) => o.requirementId) : null })}
/>
<Label htmlFor="curate-review-docs" className="text-sm text-muted-foreground cursor-pointer">
{curated ? 'Curated — judges see only the checked documents' : 'Showing all submitted documents'}
</Label>
</div>
{curated && (
<div className="space-y-2">
{data.options.map((o) => (
<label key={o.requirementId} className="flex items-center gap-2 text-sm cursor-pointer">
<Checkbox
checked={selected.has(o.requirementId)}
disabled={set.isPending}
onCheckedChange={(v) => toggleSlot(o.requirementId, v === true)}
/>
<span>{o.name} {o.roundName}</span>
<span className="text-xs text-muted-foreground">
({o.fileCount} file{o.fileCount === 1 ? '' : 's'})
</span>
</label>
))}
</div>
)}
</CardContent>
</Card>
)
}
```
- [ ] **Step 2: Wire into the round admin page**
In `src/app/(admin)/admin/rounds/[roundId]/page.tsx`:
Import (next to the other grand-finale imports, ~line 100):
```tsx
import { ReviewDocsPicker } from '@/components/admin/grand-finale/review-docs-picker'
```
Render inside the existing `isGrandFinale && programId` block, directly after the flex row containing `<FinalDocsUploadsToggle …>` (the `</div>` around line 1545):
```tsx
<ReviewDocsPicker programId={programId} roundId={roundId} />
```
- [ ] **Step 3: Typecheck**
Run: `npm run typecheck`
Expected: clean.
- [ ] **Step 4: Commit**
```bash
git add src/components/admin/grand-finale/review-docs-picker.tsx "src/app/(admin)/admin/rounds/[roundId]/page.tsx"
git commit -m "feat(final-docs): admin card to curate documents shown to finale judges"
```
---
### Task 7: Full verification
**Files:** none (verification only)
- [ ] **Step 1: Full test suite**
Run: `npx vitest run`
Expected: all tests pass (was 321 before this work; now more).
- [ ] **Step 2: Lint + typecheck + build**
Run: `npm run lint && npm run typecheck && npm run build`
Expected: all clean. (CLAUDE.md: always build before push.)
- [ ] **Step 3: Manual smoke (dev server + Playwright or browser)**
1. As admin, open the Grand Final round page → the "Documents shown to judges" card lists the prior-round slots with counts; flip to curated, untick one slot.
2. Open `/admin/finals-documents` → the unticked document type disappears from every team; any Grand Final uploads remain.
3. Flip the curation switch off → all documents reappear.
4. With `allowFinalistRevisedUploads` ON and all finale slots optional (set in dev data), check the applicant dashboard banner shows "Upload updated Grand Final documents (optional)" and turns green only when every slot is filled.
- [ ] **Step 4: Commit anything outstanding**
```bash
git status --short # should be clean except untracked screenshots/docs
```
---
## Self-Review (completed at planning time)
- **Spec coverage:** configJson key + semantics → Tasks 2/4; always-visible finale uploads → Task 2; requirement-less files excluded under selection → Task 2; picker options with counts → Task 3; admin UI next to toggle → Task 6; `hasRequired`/`allUploaded` + zero-slot edge → Tasks 1/5; sibling-key preservation + audit → Task 4; reminders unchanged → verified in spec, no task needed.
- **Placeholder scan:** none.
- **Type consistency:** `ReviewDocSlot`, `reviewVisibleRequirementIds(configJson)`, `getReviewDocSettings`/`setReviewVisibleRequirements`, `hasRequired`/`allUploaded` used consistently across tasks.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,592 @@
# Grand Finale Ceremony System Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Ship the full Option-C grand-finale ceremony system (admin-driven presentation phases with real timers + overtime log, audience QR favorite-voting with per-category windows, persisted juror notes/comments, deliberation completion, big-screen ceremony view with cinematic results reveal) before the 2026-06-11 event.
**Architecture:** Extend the existing `LiveProgressCursor` with a per-project phase state machine and server-stamped timers; extend `LiveVotingSession` with audience-window state and a new `AudienceFavoriteVote` pick-one model; big screen is a pure derivation of existing state plus a small `RevealState` controller. No new session-level phase machine.
**Tech Stack:** Next.js 15 App Router, tRPC 11, Prisma 6/PostgreSQL, Tailwind 4 + shadcn/ui, `motion` v11 (already installed) for reveal animations, `qrcode.react` (new tiny dep), Vitest 4.
**Spec:** `docs/superpowers/specs/2026-06-10-grand-finale-ceremony-design.md`
**Critical context for the implementer:**
- Two parallel live systems exist: `live.ts` (LiveProgressCursor, cohort-based votes) and `live-voting.ts` (LiveVotingSession, jury criteria votes + audience tokens). The finale uses **cursor for presentation flow** and **LiveVotingSession for all voting**. The cohort-based `castVote`/`castStageVote` in `live.ts` are NOT used for the finale — leave them alone.
- Source of truth for presentation order: `round.configJson.projectOrder` (managed by `live.start`/`live.reorder`).
- Known bug: jury live page passes `params.roundId` as `sessionId` to `getSessionForVoting` → NOT_FOUND. Fixed in Task 7.
- Known bug: deliberation jury page has `juryMemberId: ''` and `hasVoted = false` hardcoded. Fixed in Task 10.
- `LiveVotingSession.roundId` is `@unique`, so by-round lookup is safe.
- Project category field is `competitionCategory` (`STARTUP | BUSINESS_CONCEPT`), nullable.
- **NEVER** run `prisma migrate dev` if `migrate status` shows drift (memory rule) — use the create-only + `db execute` + `migrate resolve` path in Task 2.
- Run tests with `npx vitest run tests/unit/<file>` (sequential forks pool). Build check: `npm run build`. Always build before push.
---
### Task 1: Public paths for audience + ceremony routes
**Files:**
- Modify: `src/lib/auth.config.ts:52-65`
- Test: `tests/unit/auth-public-paths.test.ts` (extend existing)
- [ ] **Step 1: Extend the existing public-paths test** — read `tests/unit/auth-public-paths.test.ts` first and follow its existing assertion style; add cases asserting `/vote/competition/abc`, `/vote/xyz`, `/live-scores/xyz`, `/live/ceremony/abc` are public and that `/live` alone (jury route prefix is `/jury/...` so no conflict) does not accidentally open admin routes (assert `/admin` still private).
- [ ] **Step 2: Run** `npx vitest run tests/unit/auth-public-paths.test.ts` — expect new cases FAIL.
- [ ] **Step 3: Implement** — in `src/lib/auth.config.ts` add to `publicPaths`:
```ts
'/vote', // audience QR voting (token-based, no account)
'/live-scores', // public live scoreboard
'/live/ceremony', // big-screen ceremony view (projector)
```
- [ ] **Step 4: Run test again** — expect PASS. Also `curl -sI http://localhost:3000/vote/competition/x | head -3` (dev server) → must NOT be a redirect to /login.
- [ ] **Step 5: Commit** `fix(auth): make audience vote, live-scores and ceremony routes public`
---
### Task 2: Schema migration
**Files:**
- Modify: `prisma/schema.prisma` (LiveProgressCursor ~2152, LiveVotingSession ~1165, LiveVote ~1202, AudienceVoter ~1230, Round, Project, User back-relations)
- Create: `prisma/migrations/<ts>_grand_finale_ceremony/migration.sql`
- [ ] **Step 1: Add enums** (near other enums):
```prisma
enum LivePhase {
ON_DECK
PRESENTING
QA
SCORING
}
enum AudiencePhase {
CLOSED
OPEN
}
```
- [ ] **Step 2: Extend `LiveProgressCursor`:**
```prisma
projectPhase LivePhase @default(ON_DECK)
phaseStartedAt DateTime?
phaseDurationSeconds Int?
phasePausedAt DateTime?
phasePausedAccumMs Int @default(0)
timingLogJson Json? @db.JsonB // [{projectId, phase, startedAt, endedAt, configuredSeconds, overranSeconds}]
overrideSlide String? // 'welcome' | 'break' | 'deliberation' | 'thanks'
```
- [ ] **Step 3: Extend `LiveVotingSession`:**
```prisma
// Audience favorite-vote window (grand finale)
audiencePhase AudiencePhase @default(CLOSED)
audienceWindowKey String? // 'CATEGORY:STARTUP' | 'CATEGORY:BUSINESS_CONCEPT' | 'OVERALL'
audienceWindowOpenedAt DateTime?
audienceWindowClosesAt DateTime?
allowOverallFavorite Boolean @default(false)
```
and relations `favoriteVotes AudienceFavoriteVote[]`, `revealState RevealState?`.
- [ ] **Step 4: Extend `LiveVote`** with `comment String? @db.Text`, and `AudienceVoter` with `favoriteVotes AudienceFavoriteVote[]`.
- [ ] **Step 5: New models** (after AudienceVoter):
```prisma
model AudienceFavoriteVote {
id String @id @default(cuid())
sessionId String
windowKey String // matches LiveVotingSession.audienceWindowKey at cast time
projectId String
audienceVoterId String
ipAddress String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
session LiveVotingSession @relation(fields: [sessionId], references: [id], onDelete: Cascade)
audienceVoter AudienceVoter @relation(fields: [audienceVoterId], references: [id], onDelete: Cascade)
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
@@unique([sessionId, windowKey, audienceVoterId])
@@index([sessionId, windowKey, ipAddress])
@@index([sessionId, windowKey, projectId])
}
model LiveNote {
id String @id @default(cuid())
roundId String
projectId String
userId String
content String @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
round Round @relation(fields: [roundId], references: [id], onDelete: Cascade)
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([roundId, projectId, userId])
@@index([userId])
}
model RevealState {
id String @id @default(cuid())
sessionId String @unique
status String @default("DRAFT") // DRAFT | ARMED | REVEALING | DONE
stepsJson Json @db.JsonB // RevealStep[] — see Task 8
currentStepIndex Int @default(-1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
session LiveVotingSession @relation(fields: [sessionId], references: [id], onDelete: Cascade)
}
```
Add back-relations: `Project.audienceFavoriteVotes AudienceFavoriteVote[]`, `Project.liveNotes LiveNote[]`, `Round.liveNotes LiveNote[]`, `User.liveNotes LiveNote[]`.
- [ ] **Step 6: Migrate safely.** `npx prisma migrate status` first. If clean: `npx prisma migrate dev --name grand_finale_ceremony`. If drifted: `npx prisma migrate dev --create-only --name grand_finale_ceremony`, review SQL, then `npx prisma db execute --file prisma/migrations/<ts>_grand_finale_ceremony/migration.sql` and `npx prisma migrate resolve --applied <ts>_grand_finale_ceremony`. Then `npx prisma generate`.
- [ ] **Step 7: Verify** `npm run typecheck` passes (pre-existing errors aside). Commit `feat(finale): schema for phases, audience windows, favorite votes, notes, reveal`.
---
### Task 3: Timer helper `src/lib/live-timer.ts`
**Files:**
- Create: `src/lib/live-timer.ts`
- Test: `tests/unit/live-timer.test.ts`
- [ ] **Step 1: Write failing tests** (pure functions, no DB):
```ts
import { describe, it, expect } from 'vitest'
import { elapsedMs, remainingSeconds, formatClock } from '@/lib/live-timer'
const t0 = new Date('2026-06-11T10:00:00Z')
const at = (s: number) => new Date(t0.getTime() + s * 1000)
describe('live-timer', () => {
it('elapsedMs counts from phaseStartedAt', () => {
expect(elapsedMs({ phaseStartedAt: t0, phaseDurationSeconds: 300, phasePausedAt: null, phasePausedAccumMs: 0 }, at(90))).toBe(90_000)
})
it('elapsedMs freezes while paused and subtracts accumulated pause', () => {
// paused at +60s, asked at +90s → frozen at 60s
expect(elapsedMs({ phaseStartedAt: t0, phaseDurationSeconds: 300, phasePausedAt: at(60), phasePausedAccumMs: 0 }, at(90))).toBe(60_000)
// resumed with 30s pause accumulated, asked at +120s → 90s elapsed
expect(elapsedMs({ phaseStartedAt: t0, phaseDurationSeconds: 300, phasePausedAt: null, phasePausedAccumMs: 30_000 }, at(120))).toBe(90_000)
})
it('remainingSeconds goes negative on overtime', () => {
expect(remainingSeconds({ phaseStartedAt: t0, phaseDurationSeconds: 60, phasePausedAt: null, phasePausedAccumMs: 0 }, at(75))).toBe(-15)
})
it('remainingSeconds is null without timer', () => {
expect(remainingSeconds({ phaseStartedAt: null, phaseDurationSeconds: null, phasePausedAt: null, phasePausedAccumMs: 0 }, t0)).toBeNull()
})
it('formatClock renders mm:ss and overtime', () => {
expect(formatClock(305)).toBe('5:05')
expect(formatClock(0)).toBe('0:00')
expect(formatClock(-83)).toBe('+1:23')
})
})
```
- [ ] **Step 2: Run** — FAIL (module not found).
- [ ] **Step 3: Implement:**
```ts
export type PhaseTimerState = {
phaseStartedAt: Date | string | null
phaseDurationSeconds: number | null
phasePausedAt: Date | string | null
phasePausedAccumMs: number
}
export function elapsedMs(t: PhaseTimerState, now: Date = new Date()): number {
if (!t.phaseStartedAt) return 0
const start = new Date(t.phaseStartedAt).getTime()
const end = t.phasePausedAt ? new Date(t.phasePausedAt).getTime() : now.getTime()
return Math.max(0, end - start - t.phasePausedAccumMs)
}
export function remainingSeconds(t: PhaseTimerState, now: Date = new Date()): number | null {
if (!t.phaseStartedAt || t.phaseDurationSeconds == null) return null
return t.phaseDurationSeconds - Math.floor(elapsedMs(t, now) / 1000)
}
export function formatClock(seconds: number): string {
const over = seconds < 0
const abs = Math.abs(seconds)
const m = Math.floor(abs / 60)
const s = abs % 60
return `${over ? '+' : ''}${m}:${s.toString().padStart(2, '0')}`
}
```
- [ ] **Step 4: Run** — PASS. Commit `feat(finale): server-stamped phase timer helper`.
---
### Task 4: Phase machine + notes in `live.ts`
**Files:**
- Modify: `src/server/routers/live.ts`
- Test: `tests/unit/live-phase.test.ts`
- [ ] **Step 1: Write failing tests.** Use `createCaller(liveRouter, adminUser)` + factories (`createTestProgram/Competition/Round/Project`, round status `ROUND_ACTIVE`, `live.start` with 2 projects). Cases:
- `sendToScreens` sets `projectPhase='ON_DECK'`, target project active, timer fields null, `overrideSlide` cleared.
- `startPresentation``PRESENTING`, `phaseStartedAt` set, `phaseDurationSeconds` from input (e.g. 120) else from `round.configJson.presentationDurationMinutes*60` else 300.
- `startQA` after PRESENTING appends a timing-log entry `{projectId, phase:'PRESENTING', configuredSeconds, overranSeconds}` and starts QA timer.
- `openScoring` appends QA entry, phase `SCORING`, timer cleared.
- `pausePhase`/`resumePhase`: after pause, `phasePausedAt` set; resume folds into `phasePausedAccumMs` and clears `phasePausedAt`; pausing twice errors; resuming unpaused errors.
- overtime: startPresentation with `durationSeconds: 1`, manipulate by directly `prisma.liveProgressCursor.update({phaseStartedAt: new Date(Date.now()-10_000)})`, then `startQA` → log entry `overranSeconds >= 9`.
- `setOverrideSlide` sets/clears.
- `saveNote` upserts by (roundId, projectId, userId); second save with same juror overwrites content; `getMyNotes` returns only caller's notes.
- [ ] **Step 2: Run** — FAIL (procedures missing).
- [ ] **Step 3: Implement in `live.ts`.** Shared helper at top of file:
```ts
type TimingEntry = {
projectId: string
phase: 'PRESENTING' | 'QA'
startedAt: string
endedAt: string
configuredSeconds: number | null
overranSeconds: number
}
function closedOutTiming(cursor: {
activeProjectId: string | null
projectPhase: string
phaseStartedAt: Date | null
phaseDurationSeconds: number | null
phasePausedAt: Date | null
phasePausedAccumMs: number
timingLogJson: unknown
}, now: Date): Prisma.InputJsonValue | undefined {
if (!cursor.phaseStartedAt || !cursor.activeProjectId) return undefined
if (cursor.projectPhase !== 'PRESENTING' && cursor.projectPhase !== 'QA') return undefined
const end = cursor.phasePausedAt ?? now
const elapsedSec = Math.max(0, Math.floor((end.getTime() - cursor.phaseStartedAt.getTime() - cursor.phasePausedAccumMs) / 1000))
const entry: TimingEntry = {
projectId: cursor.activeProjectId,
phase: cursor.projectPhase,
startedAt: cursor.phaseStartedAt.toISOString(),
endedAt: now.toISOString(),
configuredSeconds: cursor.phaseDurationSeconds,
overranSeconds: cursor.phaseDurationSeconds == null ? 0 : Math.max(0, elapsedSec - cursor.phaseDurationSeconds),
}
const log = Array.isArray(cursor.timingLogJson) ? (cursor.timingLogJson as TimingEntry[]) : []
return [...log, entry] as unknown as Prisma.InputJsonValue
}
async function getRoundDurations(prisma: PrismaClient, roundId: string) {
const round = await prisma.round.findUniqueOrThrow({ where: { id: roundId } })
const cfg = (round.configJson as Record<string, unknown>) ?? {}
return {
presentation: typeof cfg.presentationDurationMinutes === 'number' ? cfg.presentationDurationMinutes * 60 : 300,
qa: typeof cfg.qaDurationMinutes === 'number' ? cfg.qaDurationMinutes * 60 : 300,
projectOrder: (cfg.projectOrder as string[]) ?? [],
}
}
```
Mutations (all `adminProcedure`, all audit-logged following the file's existing `logAudit` pattern with actions `LIVE_SEND_TO_SCREENS`, `LIVE_PHASE_STARTED`, `LIVE_PHASE_PAUSED`, `LIVE_PHASE_RESUMED`, `LIVE_OVERRIDE_SLIDE`):
```ts
sendToScreens: input {roundId, projectId} cursor findUniqueOrThrow by roundId; durations+order;
index = order.indexOf(projectId) (BAD_REQUEST if -1);
update: { activeProjectId, activeOrderIndex: index, projectPhase: 'ON_DECK',
phaseStartedAt: null, phaseDurationSeconds: null, phasePausedAt: null, phasePausedAccumMs: 0,
overrideSlide: null, timingLogJson: closedOutTiming(cursor, now) }
startPresentation: input {roundId, durationSeconds?: z.number().int().min(10).max(7200).optional()}
update { projectPhase: 'PRESENTING', phaseStartedAt: now,
phaseDurationSeconds: input.durationSeconds ?? durations.presentation,
phasePausedAt: null, phasePausedAccumMs: 0, timingLogJson: closedOutTiming(cursor, now) }
startQA: same shape, phase 'QA', default durations.qa
openScoring: { projectPhase: 'SCORING', phaseStartedAt: null, phaseDurationSeconds: null,
phasePausedAt: null, phasePausedAccumMs: 0, timingLogJson: closedOutTiming(cursor, now) }
pausePhase: PRECONDITION_FAILED if !cursor.phaseStartedAt || cursor.phasePausedAt; set phasePausedAt: now
resumePhase: PRECONDITION_FAILED if !cursor.phasePausedAt;
set phasePausedAccumMs: cursor.phasePausedAccumMs + (now - cursor.phasePausedAt), phasePausedAt: null
setOverrideSlide: input {roundId, slide: z.enum(['welcome','break','deliberation','thanks']).nullable()}
update { overrideSlide: input.slide }
```
Notes procedures (`protectedProcedure`):
```ts
saveNote: input {roundId, projectId, content: z.string().max(20_000)}
prisma.liveNote.upsert({ where: { roundId_projectId_userId: { roundId, projectId, userId: ctx.user.id } },
create: {...}, update: { content } })
getMyNotes: input {roundId} prisma.liveNote.findMany({ where: { roundId, userId: ctx.user.id } })
```
Extend `getCursor` return: spread now includes the new cursor fields automatically (`...cursor`); additionally fetch `orderedProjects` (id, title, teamName, competitionCategory) for the whole `projectOrder` (one `findMany` + reorder in JS) and include `activeProject.competitionCategory` in its select.
- [ ] **Step 4: Run** `npx vitest run tests/unit/live-phase.test.ts` — PASS. Run `npx vitest run tests/unit/auth-public-paths.test.ts` too (regression).
- [ ] **Step 5: Commit** `feat(finale): per-project phase machine, server timers, overtime log, juror notes`.
---
### Task 5: Audience windows + favorite votes in `live-voting.ts`
**Files:**
- Modify: `src/server/routers/live-voting.ts`
- Test: `tests/unit/audience-window.test.ts`
- [ ] **Step 1: Write failing tests.** Setup: program/competition/round (LIVE_FINAL, ROUND_ACTIVE), 3 projects (2 STARTUP, 1 BUSINESS_CONCEPT via `prisma.project.update` setting `competitionCategory`), `round.configJson.projectOrder` set, LiveVotingSession created with `allowAudienceVotes: true`, two AudienceVoter rows (tokens A, B). Cases:
1. `openAudienceWindow({windowKey:'CATEGORY:STARTUP', durationMinutes:5})` → phase OPEN, closesAt ≈ now+5m. Opening again → CONFLICT.
2. `castFavoriteVote` token A for STARTUP project → row created. Re-cast token A other STARTUP project → same row updated (count still 1).
3. Cast for the BUSINESS_CONCEPT project while STARTUP window open → BAD_REQUEST.
4. Set `audienceWindowClosesAt` to past via prisma, cast → PRECONDITION_FAILED (server-side time check, no cron).
5. `closeAudienceWindow` then cast → PRECONDITION_FAILED. Re-open works (new window, key CATEGORY:BUSINESS_CONCEPT) → casting BUSINESS_CONCEPT project OK.
6. `openAudienceWindow({windowKey:'OVERALL'})` with `allowOverallFavorite:false` → FORBIDDEN; after `updateSessionConfig({allowOverallFavorite:true})` → OK; any ordered project castable.
7. IP cap: create 3 voters with ctx ip '1.2.3.4' casting in same window (use `createTestContext` with custom ip — check `tests/setup.ts` signature; if ip not injectable, set `ipAddress` on rows directly and cast the 4th via caller whose ctx.ip is '1.2.3.4') → 4th distinct voter from same IP → TOO_MANY_REQUESTS. A voter updating their own vote from that IP still succeeds.
8. `getFavoriteTallies` returns per-windowKey per-project counts.
9. `getAudienceWindow` (public) reports phase CLOSED once `closesAt` past even without an explicit close, includes eligible projects in order, and `myVote` for a token.
- [ ] **Step 2: Run** — FAIL.
- [ ] **Step 3: Implement.** Zod: `const windowKeySchema = z.enum(['CATEGORY:STARTUP', 'CATEGORY:BUSINESS_CONCEPT', 'OVERALL'])`. Helper in file:
```ts
function windowIsOpen(s: { audiencePhase: string; audienceWindowClosesAt: Date | null }, now = new Date()) {
return s.audiencePhase === 'OPEN' && !!s.audienceWindowClosesAt && now <= s.audienceWindowClosesAt
}
function categoryForKey(key: string): 'STARTUP' | 'BUSINESS_CONCEPT' | null {
return key === 'CATEGORY:STARTUP' ? 'STARTUP' : key === 'CATEGORY:BUSINESS_CONCEPT' ? 'BUSINESS_CONCEPT' : null
}
async function getOrderedFinaleProjects(prisma: PrismaClient, session: { roundId: string | null; projectOrderJson: unknown }) {
let order: string[] = []
if (session.roundId) {
const round = await prisma.round.findUnique({ where: { id: session.roundId } })
order = ((round?.configJson as Record<string, unknown>)?.projectOrder as string[]) ?? []
}
if (order.length === 0) order = (session.projectOrderJson as string[]) ?? []
const projects = await prisma.project.findMany({
where: { id: { in: order } },
select: { id: true, title: true, teamName: true, competitionCategory: true },
})
const byId = new Map(projects.map((p) => [p.id, p]))
return order.map((id) => byId.get(id)).filter(Boolean) as typeof projects
}
```
Procedures:
```ts
openAudienceWindow (adminProcedure): input {sessionId, windowKey: windowKeySchema, durationMinutes: z.number().int().min(1).max(120).default(5)}
session findUniqueOrThrow; if windowIsOpen(session) CONFLICT 'An audience window is already open';
if windowKey==='OVERALL' && !session.allowOverallFavorite FORBIDDEN 'Overall favorite vote is not enabled';
update { audiencePhase:'OPEN', audienceWindowKey: windowKey, audienceWindowOpenedAt: now,
audienceWindowClosesAt: new Date(now + durationMinutes*60_000) }; audit 'AUDIENCE_WINDOW_OPENED'.
closeAudienceWindow (adminProcedure): update { audiencePhase:'CLOSED', audienceWindowKey:null,
audienceWindowOpenedAt:null, audienceWindowClosesAt:null }; audit 'AUDIENCE_WINDOW_CLOSED'.
getAudienceWindow (publicProcedure): input {sessionId, token: z.string().optional()}
session select audiencePhase/windowKey/closesAt/allowAudienceVotes/roundId/projectOrderJson;
const open = windowIsOpen(session); const key = open ? session.audienceWindowKey : null;
projects = open ? getOrderedFinaleProjects(...).filter(p => { const cat = categoryForKey(key!); return cat ? p.competitionCategory === cat : true }) : [];
myVote: if token && key voter by token favoriteVote findUnique by (sessionId, windowKey:key, audienceVoterId) projectId;
return { open, windowKey: key, closesAt: open ? session.audienceWindowClosesAt : null, projects, myVoteProjectId }
castFavoriteVote (publicProcedure): input {sessionId, token, projectId}
voter by token (UNAUTHORIZED if missing/mismatched session);
session findUniqueOrThrow; if !windowIsOpen PRECONDITION_FAILED 'Voting is not open right now';
const key = session.audienceWindowKey!; const cat = categoryForKey(key);
project findUniqueOrThrow select competitionCategory; ordered = getOrderedFinaleProjects(...);
if (!ordered.some(p => p.id === input.projectId)) BAD_REQUEST 'Project is not part of this vote';
if (cat && project.competitionCategory !== cat) BAD_REQUEST 'Project is not in the open category';
existing = favoriteVote findUnique (sessionId, windowKey:key, audienceVoterId: voter.id);
if (!existing && ctx.ip) { const ipCount = await prisma.audienceFavoriteVote.count({ where: { sessionId, windowKey: key, ipAddress: ctx.ip } });
if (ipCount >= 3) TOO_MANY_REQUESTS 'Vote limit reached for this network' }
upsert (update: { projectId, ipAddress: ctx.ip ?? existing?.ipAddress }); return { projectId }
getFavoriteTallies (adminProcedure): input {sessionId}
groupBy ['windowKey','projectId'] _count; plus projects (title/teamName) join; plus per-window total counts.
```
Add `allowOverallFavorite: z.boolean().optional()` to `updateSessionConfig` input (passes straight through to `data`).
- [ ] **Step 4: Run** — PASS. Commit `feat(finale): audience favorite-vote windows with category gating + IP cap`.
---
### Task 6: Jury vote comment + by-round session resolution + my-votes query
**Files:**
- Modify: `src/server/routers/live-voting.ts`
- Test: `tests/unit/live-vote-comment.test.ts`
- [ ] **Step 1: Failing tests:** (a) `vote` with `comment: 'strong pitch'` persists it; re-vote updates it; (b) new `getSessionForVotingByRound({roundId})` returns the same payload shape as `getSessionForVoting` and creates nothing (null when no session); (c) new `getMyFinaleInputs({roundId})` returns caller's LiveVotes (score, criterionScoresJson, comment, projectId) and LiveNotes for the round.
- [ ] **Step 2: Run** — FAIL.
- [ ] **Step 3: Implement:**
- `vote` input gains `comment: z.string().max(5000).optional()`; include in upsert create/update (`comment: input.comment ?? undefined` on update so an omitted comment doesn't erase).
- `getSessionForVotingByRound` (protectedProcedure): `findUnique({ where: { roundId } })`; if null return null; else reuse the body of `getSessionForVoting` (extract a shared `buildVotingPayload(session, ctx)` helper used by both procedures — DRY).
- `getMyFinaleInputs` (protectedProcedure): input `{roundId}` → session by roundId (null-safe) → `liveVote.findMany({ where: { sessionId, userId: ctx.user.id } , select: { projectId, score, criterionScoresJson, comment, votedAt } })` + `liveNote.findMany({ where: { roundId, userId: ctx.user.id } })`. Return `{ votes, notes, session: { id, votingMode, criteriaJson } | null }`.
- [ ] **Step 4: Run** — PASS. Commit `feat(finale): vote comments, by-round session lookup, my-finale-inputs query`.
---
### Task 7: Jury live page rework
**Files:**
- Modify: `src/app/(jury)/jury/competitions/[roundId]/live/page.tsx`
- Modify: `src/components/jury/live-voting-form.tsx` (add comment field — read it first; pass `comment` through `onVoteSubmit`)
No DB logic here; verified by build + Playwright in Task 13. Behaviors:
- [ ] **Step 1: Fix session wiring** — replace `getSessionForVoting({sessionId: params.roundId})` with `getSessionForVotingByRound({roundId: params.roundId})` (poll 2000ms). Keep `live.getCursor` poll at 2000ms (was 5000 — tighten for ceremony).
- [ ] **Step 2: Phase rendering** from `cursor.projectPhase`:
- `ON_DECK`: full-width banner card — "Up next" eyebrow, project title XL, team name; muted note "Presentation starting shortly". No scoring form.
- `PRESENTING` / `QA`: project card with phase badge (`Presentation` / `Q&A`) and live countdown chip using `remainingSeconds`/`formatClock` from `@/lib/live-timer` (tick via 1s `setInterval`, computed from server stamps — never local countdown state); red text when negative. Notes + scoring form below.
- `SCORING`: same but scoring card gets a highlighted ring (`ring-2 ring-[#de0f1e]`) and a "Scoring is open" badge.
- [ ] **Step 3: Persisted notes** — replace local `notes` state: load via `trpc.live.getMyNotes({roundId})`, keep a `Record<projectId, string>` local draft, debounce 800ms → `trpc.live.saveNote.mutate({roundId, projectId, content})`; show "Saved" / "Saving…" microcopy. Notes keyed per active project (switching project switches the note).
- [ ] **Step 4: Comment field** — add optional `Textarea` "Comment (visible to admins with your scores)" inside the voting form submission; include `comment` in `vote` mutation.
- [ ] **Step 5:** `npm run build` green. Commit `feat(finale): phase-aware jury live page with persisted notes + comments`.
---
### Task 8: Reveal controller (backend)
**Files:**
- Modify: `src/server/routers/live-voting.ts`
- Test: `tests/unit/reveal.test.ts`
- [ ] **Step 1: Failing tests:** (a) `saveReveal` upserts steps in DRAFT; (b) `armReveal` requires ≥1 step, DRAFT→ARMED; (c) `revealNext` ARMED→REVEALING idx 0, increments, last step → DONE (idx stays last); (d) `resetReveal` → DRAFT idx -1; (e) **no-leak:** `getCeremonyState` (public, Task 9 — write the test now against the procedure added there if sequencing demands; otherwise assert via a `getPublicReveal` helper) returns only steps `0..currentStepIndex`, empty when ARMED, none when DRAFT.
- [ ] **Step 2: Run** — FAIL.
- [ ] **Step 3: Implement.** Step schema:
```ts
const revealStepSchema = z.object({
kind: z.enum(['category-intro', 'place', 'audience-award', 'overall-favorite', 'thanks']),
category: z.enum(['STARTUP', 'BUSINESS_CONCEPT']).optional(),
place: z.number().int().min(1).max(10).optional(),
projectId: z.string().optional(),
title: z.string().max(200).optional(), // resolved display strings, stored denormalized
subtitle: z.string().max(300).optional(),
})
```
```ts
saveReveal (adminProcedure): {sessionId, steps: z.array(revealStepSchema).max(50)}
revealState upsert by sessionId { stepsJson: steps, status: 'DRAFT', currentStepIndex: -1 }
armReveal (adminProcedure): requires existing DRAFT with steps.length>0 status 'ARMED'
revealNext (adminProcedure): ARMED { status:'REVEALING', currentStepIndex: 0 };
REVEALING idx+1; if idx+1 === steps.length-1 also status 'DONE'
// careful: advance then check — newIndex = currentStepIndex + 1; clamp to steps.length-1;
// status = newIndex >= steps.length - 1 ? 'DONE' : 'REVEALING'
resetReveal (adminProcedure): { status:'DRAFT', currentStepIndex: -1 }
getRevealAdmin (adminProcedure): full state incl. all steps (for preview)
```
Audit-log arm/next/reset with action names `REVEAL_ARMED`, `REVEAL_ADVANCED`, `REVEAL_RESET`.
- [ ] **Step 4: Run** — PASS. Commit `feat(finale): results reveal controller with step-through state`.
---
### Task 9: Public ceremony state endpoint
**Files:**
- Modify: `src/server/routers/live-voting.ts`
- Test: extend `tests/unit/reveal.test.ts` + `tests/unit/audience-window.test.ts` no-leak/shape cases
- [ ] **Step 1: Failing test:** `getCeremonyState({roundId})` (publicProcedure) returns `{ overrideSlide, phase: {projectPhase, phaseStartedAt, phaseDurationSeconds, phasePausedAt, phasePausedAccumMs}, activeProject: {title, teamName, competitionCategory} | null, audience: { open, windowKey, closesAt, voteCount }, reveal: { status, steps: <revealed only>, currentStepIndex } | null, programName }`. Assert: never includes scores, never includes un-revealed steps, includes audience voteCount for the open window only.
- [ ] **Step 2: Run** — FAIL.
- [ ] **Step 3: Implement** — compose from `liveProgressCursor.findUnique({roundId})`, session by roundId, `audienceFavoriteVote.count({sessionId, windowKey})` when open, `revealState` (slice steps `0..currentStepIndex` only when REVEALING/DONE; `[]` when ARMED; null when DRAFT/absent). One procedure, ~60 lines.
- [ ] **Step 4: Run** — PASS. Commit `feat(finale): public ceremony-state endpoint for big screen`.
---
### Task 10: Deliberation jury completion
**Files:**
- Modify: `src/app/(jury)/jury/competitions/deliberation/[sessionId]/page.tsx`
- Modify: `src/server/services/deliberation.ts` (only if `getSessionWithVotes` lacks project list — verify first)
- Modify: `src/server/routers/deliberation.ts` (add projects to getSession payload if needed)
- Read first: `src/components/jury/deliberation-ranking-form.tsx`
- Test: `tests/unit/deliberation-jury-wiring.test.ts`
- [ ] **Step 1: Investigate** `getSessionWithVotes` — confirm what `session.participants[].user` contains (expect JuryGroupMember incl. `user`), and where the rank-able project list comes from (`session.results` is empty before finalize — the form currently gets `[]`!). Decide: extend `getSessionWithVotes` to include `projects` = projects of the session's round + category (via `ProjectRoundState` where `roundId`, project `competitionCategory === session.category`), selecting id/title/teamName.
- [ ] **Step 2: Failing test:** caller = juror user who is a JuryGroupMember + DeliberationParticipant; `deliberation.getSession` exposes `projects` (non-empty pre-finalize) and participant rows that let the client resolve `juryMemberId`; `submitVote` with that `juryMemberId` succeeds and `getSession` then shows the vote (`hasVoted` derivable). Also assert a juror cannot submit with another member's `juryMemberId` (existing enforcement — pin it).
- [ ] **Step 3: Implement service/router change**, run test — PASS.
- [ ] **Step 4: Fix the page:**
```ts
const { data: me } = trpc.user.me.useQuery() // or useSession() — match codebase pattern (check src for existing usage)
const myParticipant = session?.participants?.find((p: any) => p.user?.user?.id === me?.id)
const juryMemberId = myParticipant?.user?.id ?? null // JuryGroupMember.id
const hasVoted = !!session?.votes?.some((v: any) => v.juryMember?.user?.id === me?.id)
```
Pass `projects={session.projects}` to `DeliberationRankingForm`. Submit all votes in ONE call sequence with `juryMemberId`; disable submit when `!juryMemberId` with explanatory text ("You are not a participant of this deliberation").
- [ ] **Step 5: Context panels** (below the ranking form, one collapsible card per project): my finale criteria scores + comment from `trpc.liveVoting.getMyFinaleInputs({roundId: session.roundId})` (criteria labels from `session` payload's criteriaJson), editable via the same `LiveVotingForm` in a dialog (submits `liveVoting.vote` — works because session status check is `IN_PROGRESS`; **verify**: if finale session will be COMPLETED by deliberation time, relax `vote`'s status guard to allow `IN_PROGRESS | PAUSED` and gate `currentProjectId` check to only apply when phase-voting — simplest: allow voting for any ordered project when `round.roundType === 'DELIBERATION'`-linked… **Decision:** add `allowRevote: true` behavior — `vote` accepts any `projectId` in the finale order when the session status is `IN_PROGRESS` or `PAUSED`; keep the `currentProjectId` equality check ONLY when `projectPhase` voting is live i.e. when the cursor's active project equals the voted project OR session.status === 'PAUSED'. Implement as: skip the `currentProjectId !== input.projectId` check when `input.projectId` is in the session's project order and the cursor for the round is in `SCORING` or session is `PAUSED`. Write a unit test for this relaxation.) Also show my `LiveNote` per project, and a link row to the finals documents page (route: check `src/app/(jury)` for the finals docs page added 2026-06-09 — link to it with the project preselected if supported, else plain link).
- [ ] **Step 6:** Tests + `npm run build` green. Commit `feat(finale): working jury deliberation flow with finale-score review and notes`.
---
### Task 11: Admin control panel revamp
**Files:**
- Modify: `src/components/admin/live/live-control-panel.tsx` (becomes orchestrator)
- Create: `src/components/admin/live/run-order-list.tsx`, `phase-controls.tsx`, `audience-window-panel.tsx`, `timing-log-card.tsx`, `reveal-panel.tsx`
- Modify: `package.json` (add `qrcode.react`)
- Find the admin page hosting `LiveControlPanel` (grep usage) — ensure it passes `roundId` + `competitionId` and has room for the new layout (2-col grid on lg).
Pure UI — verified via Playwright in Task 13. Behaviors per component:
- [ ] **Step 1:** `npm i qrcode.react`.
- [ ] **Step 2: `run-order-list.tsx`** — props `{roundId}`; uses `live.getCursor` data (`orderedProjects`, `activeProjectId`, `activeOrderIndex`). Groups rows under `BUSINESS_CONCEPT` / `STARTUP` headings (preserving global order); each row: index, title, teamName, category dot, ▲▼ buttons (swap in `projectOrder`, call `live.reorder`), and a "Send to screens" button (`live.sendToScreens`). Active row highlighted; ON_DECK row shows "on deck" badge.
- [ ] **Step 3: `phase-controls.tsx`** — props `{roundId}`. Shows active project + phase badge; one primary button for the next transition (ON_DECK→"Start presentation", PRESENTING→"Start Q&A", QA→"Open scoring", SCORING→"Send next project" which calls `sendToScreens` with the next project in order); secondary buttons for pause/resume; the big server-derived countdown (`remainingSeconds`/`formatClock`, 1s tick, `text-red-600 animate-pulse` when negative with "OVER" label); duration override `Input` (minutes, prefilled from round config) applied to the next start call. Keep legacy session pause/resume (cursor.isPaused) as a small row.
- [ ] **Step 4: `audience-window-panel.tsx`** — props `{roundId}`. Resolves session via `liveVoting.getSession({roundId})`. Buttons "Open vote — Business Concepts" / "Open vote — Startups" / "Open vote — Overall favorite" (last disabled unless `allowOverallFavorite`; a `Switch` toggles it via `updateSessionConfig`), shared duration `Input` (default 5). When open: countdown, live vote count (`getFavoriteTallies` poll 3s — render per-window totals; per-project tallies in a collapsible "Tallies (admin only)"), "Close now" `destructive` button. "Show QR" button → `Dialog` with `<QRCodeSVG value={origin + '/vote/competition/' + roundId} size={420}/>` + the URL printed beneath.
- [ ] **Step 5: `timing-log-card.tsx`** — renders `cursor.timingLogJson` rows: project title (lookup from orderedProjects), phase, configured vs actual, overran chip (red `+m:ss`) when `overranSeconds > 0`.
- [ ] **Step 6: `reveal-panel.tsx`** — props `{roundId}`. "Compose from results" button: pulls `liveVoting.getResults({sessionId})`, `getFavoriteTallies`, and `deliberation.listSessions({competitionId})` → for each category with a finalized deliberation use its results order, else fall back to jury `getResults` order filtered by category; builds default steps (category-intro → places 3,2,1 → audience-award per category → overall-favorite if tallies exist → thanks) with resolved `title` (team/project name) and `subtitle` ("3rd place — Business Concepts" etc.); shows editable preview list (delete/reorder steps); "Save draft" → `saveReveal`. Then "Arm" (confirm dialog: "Big screen will switch to Results mode"), "Reveal next" (primary, shows `currentStepIndex+1 / steps.length`), "Reset". Show current step preview text so the admin always knows what fires next.
- [ ] **Step 7:** Compose all into `live-control-panel.tsx` (left col: phase-controls + run-order-list; right col: audience-window-panel + timing-log-card + reveal-panel). `npm run build` green. Commit `feat(finale): admin ceremony control panel — phases, run order, audience windows, QR, reveal`.
---
### Task 12: Audience voting page + big-screen ceremony page
**Files:**
- Modify: `src/app/(public)/vote/competition/[roundId]/page.tsx` (read existing first; rework content)
- Create: `src/app/(public)/live/ceremony/[roundId]/page.tsx`
- Create: `src/components/public/ceremony/` (slides: `ceremony-shell.tsx`, `presentation-slide.tsx`, `audience-vote-slide.tsx`, `reveal-slide.tsx`, `static-slide.tsx`)
**Invoke the `frontend-design` skill before building these two surfaces** — the reveal especially must be projector-gorgeous (spec §9): Montserrat 700, dark-blue `#053d57` field, red `#de0f1e` accent, `motion` (v11, import from `'motion/react'`) AnimatePresence transitions, confetti-grade flourish on 1st place + audience award, 16:9-safe, high contrast, no text below ~32px effective.
- [ ] **Step 1: Audience page** — resolve session: add tiny public procedure `liveVoting.getAudienceContextByRound({roundId})` returning `{sessionId, allowAudienceVotes, programName, roundName}` (5 lines, include in Task 5's test file as a shape assertion). Page flow: on mount ensure token in `localStorage['mopc-audience-' + sessionId]` else `registerAudienceVoter` → store. Poll `getAudienceWindow({sessionId, token})` every 3s. States: **waiting** (brand header, "Voting opens after the presentations — keep this page open", subtle wave animation), **open** (windowKey title — "Pick your favorite Business Concept", big tappable project cards (title + team), selected ring, confirm button → `castFavoriteVote`, then **voted** state: green check, "Vote recorded — you can change it until voting closes", countdown chip, tap-again-to-change), **closed** ("Voting is closed — thanks!"). Friendly error toast for IP-cap rejection. Mobile-first, thumb-sized targets, zero instructions needed.
- [ ] **Step 2: Ceremony page**`'use client'`; poll `liveVoting.getCeremonyState({roundId})` every 2s; full-screen `ceremony-shell` (fixed inset-0, `bg-[#053d57]`, MOPC wordmark small top-left, no nav chrome). Render precedence exactly: overrideSlide → reveal (ARMED: "Results" splash; REVEALING/DONE: `reveal-slide` for `steps[currentStepIndex]` with AnimatePresence between steps) → audience window open (`audience-vote-slide`: giant centered QR (white tile, rounded), "Vote for your favorite …", mm:ss countdown, "N votes cast" ticker) → cursor phase (ON_DECK: "Up next" + team; PRESENTING/QA: team name hero + phase label + huge countdown `formatClock`, red glow when negative; SCORING: "The jury is scoring" interstitial) → welcome slide. 1s local tick for countdowns computed from server stamps.
- [ ] **Step 3: Reveal slide details**`place` step: eyebrow ("3rd place — Startups"), team name scales in (motion spring, `initial={{opacity:0, y:40, scale:0.9}}`), 1st place gets gold treatment + confetti burst (CSS/motion particles — ~40 absolutely-positioned animated divs, no new dep); `audience-award`/`overall-favorite`: red accent treatment "Audience Choice"; `category-intro` and `thanks`: typographic full-bleed statements.
- [ ] **Step 4:** `npm run build` green. Commit `feat(finale): audience voting page + big-screen ceremony view with animated reveal`.
---
### Task 13: End-to-end verification + tally audit
**Files:**
- Test: `tests/unit/live-results-tally.test.ts`
- All previous files (fixes as found)
- [ ] **Step 1: Tally audit tests**`getResults`: 2 jury voters scoring 2 projects (criteria mode: assert weighted normalization matches hand-computed values), audienceWeight 0 default keeps jury-only ordering; tie detection fires on equal totals; `getFavoriteTallies` counts match casts. Run — PASS (fix `getResults` if hand-computed values disagree; document any fix in the commit).
- [ ] **Step 2: Full suite** `npx vitest run` — all green. `npm run typecheck` and `npm run build` — green.
- [ ] **Step 3: Manual drive (Playwright MCP against dev server), screenshots at each stop:** seed/identify a LIVE_FINAL round with projects in both categories → admin: start live session, send project to screens, start presentation (1 min override), watch countdown go red, start Q&A, open scoring → jury (second context): see ON_DECK→phases follow along, write a note, refresh (note persists), submit criteria scores + comment → admin: open Business-Concepts audience window → **clean browser context** (NOT the logged-in profile): load `/vote/competition/[roundId]`, cast favorite, change vote, see voted state → ceremony page shows QR + count → close window → compose reveal from results, arm, step through all steps on ceremony page → deliberation: create session, open voting, juror ranks (verify the Task 10 fix), close, aggregate, adminDecide override, finalize.
- [ ] **Step 4: Public-route curl checks** for `/vote/competition/<id>`, `/live/ceremony/<id>`, `/live-scores/<id>` — 200, no login redirect.
- [ ] **Step 5: Fix everything found; re-run suite; commit** `test(finale): tally audit + e2e ceremony verification fixes`.
---
### Task 14 (STRETCH — only if all above is done and verified): Live ranking mode toggle
Skip unless time clearly permits. Admin toggle on the session (`votingMode: 'ranking'`), juror drag-rank of seen-so-far projects persisted to a new `LiveRank` model, results by Borda. **Do not start this before Task 13 is fully green.**
---
## Execution ground rules
- Commit after every task (or sub-step where marked); never push without `npm run build` green.
- Local dev DB only tonight; prod deploy is a separate explicit step with the user (memory: backup first, never `docker compose down -v`).
- If a step's investigation contradicts this plan (shapes, routes, component props), trust the code, adjust minimally, note the deviation in the commit message.

View File

@@ -0,0 +1,218 @@
# Juror-Balanced Scoring Toggle + Round-Scoping Fixes
**Status:** design
**Date:** 2026-04-27
**Author:** Matt + Claude
## Goal
Two related changes to the ranking system:
1. **Add a per-round toggle** that controls whether the ranking dashboard ranks projects by the juror-balanced (z-normalized) score or by the raw average. The toggle persists in `Round.configJson` and is shared across all viewers. Admins flip it from the side panel of the admin ranking dashboard; observers see the effect (which score is "active") but don't get the toggle UI themselves, matching today's role gates on the dashboard.
2. **Fix cross-round contamination** in two analytics procedures (`getProjectDetail`, `getProjectRankings`) and several UI surfaces that consume them. Per-juror balance contexts must be computed within a single round; aggregate stats (avg score, evaluator count, pass rate) must be scoped to the round being viewed.
A side panel "deeper display" replaces the small `⇢ X.X` annotation on the list view: the list view stays clean, and clicking into a project surfaces the raw + balanced numbers, the toggle, an explainer, and per-juror balance contributions.
## Background
Juror-balanced scoring (`src/server/services/juror-balance.ts`) corrects for per-juror grading harshness using z-normalization. Each juror's scores are normalized against their own mean + stddev across the round, then rescaled onto the round's overall mean + stddev so balanced numbers are comparable to raw averages.
The math is correct, but two scoping problems exist:
**Problem 1 — `getProjectDetail` is round-blind.** The query at `src/server/routers/analytics.ts:1417-1422` pulls every SUBMITTED evaluation for a project across every round it ever participated in, then computes Avg Score / Evaluators / Pass Rate from that pool. Meanwhile the per-juror list rendered in the admin sheet at `src/components/admin/round/ranking-dashboard.tsx:1034-1036` filters to the current round. Result: stats card disagrees with the visible per-juror list.
**Problem 2 — `getProjectRankings` (programId/edition mode) pools z-context across rounds.** At `src/server/routers/analytics.ts:212-218`, when invoked with `programId` (instead of `roundId`), evaluations from every round in the edition are fed into a single `computeBalanceContext`. A juror's mean/stddev is then computed across mixed contexts (e.g. quick intake screening + deep evaluation), producing meaningless personal calibration.
Other call sites (`ranking.ts`, `ai-juror-calibration.ts`) already filter by round and are unaffected.
## Surfaces affected
| # | Surface | Procedure | Issue |
|---|---|---|---|
| 1 | Admin ranking dashboard side sheet | `analytics.getProjectDetail` | Stats card pulls cross-round evals |
| 2 | Observer full project detail page | `analytics.getProjectDetail` | Same; observer-side |
| 3 | Observer reports preview dialog | `analytics.getProjectDetail` | Same; observer-side |
| 4 | Admin reports overview tab rankings | `analytics.getProjectRankings` | Edition mode uses cross-round z-context |
| 5 | Admin reports detail tab rankings | `analytics.getProjectRankings` | Same |
| 6 | Admin reports overview "Balanced Avg" tile | derives from #4 | Inherits the bad numbers |
| 7 | Result lock controls | `analytics.getProjectRankings` (roundId only) | OK — already round-scoped |
| 8 | Admin ranking dashboard list | `ranking.getRoundRanking` | OK — already filters by roundId |
| 9 | AI juror calibration service | self-contained | OK — already filters by roundId |
## Design
### 1. Round-scoping fixes
#### `analytics.getProjectDetail`
- Add an optional `roundId` to the input schema.
- When `roundId` is provided, filter `submittedEvaluations` (the query at line 1417) by `assignment: { roundId }`. The stats block computed from those evaluations becomes round-scoped automatically.
- When `roundId` is not provided, return `stats: null` and a new field `statsByRound: Array<{ roundId, roundName, stats }>` so callers can render per-round breakdowns instead of one misleading aggregate. (The current dialogs always know which round they want — they just weren't passing it.)
- Pass `roundId` from the three callers (#1, #2, #3 above).
#### `analytics.getProjectRankings`
When called in edition mode (`programId` only), z-normalization must run **per round**, not across the pool:
1. Group `points: ScorePoint[]` by `roundId` (we'll need to include `roundId` in each point — currently `evalWhere` returns flat evaluations; add `assignment.round.id` to the select).
2. For each round, call `computeBalanceContext(pointsForRound)` and `computeBalancedProjectScores(pointsForRound, ctx)`.
3. Aggregate per-project: a project's edition-level `balancedScore` is the unweighted mean of its per-round balanced averages. Its `averageScore` (raw) is the unweighted mean of its per-round raw averages.
4. `evaluationCount` becomes the total across rounds (unchanged in spirit).
In `roundId` mode, behavior is unchanged.
#### Default round resolution (observer full project page, #2)
The observer page at `/observer/projects/[projectId]` doesn't know which round to focus on. Resolution logic:
```
Among rounds where ProjectRoundState exists for this project:
1. If exactly one round.status = ROUND_ACTIVE, use it.
2. Else use the most recent round with status = ROUND_CLOSED
(ordered by sortOrder desc, or exitedAt desc as tiebreak).
3. Else if only ROUND_DRAFT rounds exist, fall back to none (stats: null).
```
A small round selector chip near the stats card lets the user switch contexts; the URL updates with `?round=<id>`.
### 2. Per-round balanced-scoring toggle
#### Storage
Add `useBalancedRanking: boolean` to `Round.configJson` (default `true` — preserve current behavior). No schema migration needed since `configJson` is already a flexible JSON column.
#### tRPC procedure
Extend `ranking.updateConfig` (or add `setUseBalancedRanking`) — admin/observer-procedure level. The page is admin-only today, so observer access for this toggle would be a deliberate widening. **Decision: keep it `adminProcedure`** (PROGRAM_ADMIN + SUPER_ADMIN). The user said "anyone who can view should be able to toggle," and the page is gated to admins.
#### UI integration
- Toggle lives at the top of the side sheet (not the list view) — labeled "Use balanced scoring for ranking" with a help icon that opens the explainer.
- When toggled, the dashboard re-sorts immediately (the list-view sort at `ranking-dashboard.tsx:417,879` reads from `evalScores.balanced[id]?.balancedAverage`; we'll wrap that in `useBalancedRanking ? balanced : raw`).
- The list row's compact `⇢ X.X` annotation is **removed**. Visual delta lives in the side panel only.
### 3. Side panel deeper display
The existing side sheet (`ranking-dashboard.tsx:970-1090`) gains:
#### Stats area (replaces the current 3-card grid)
```
┌──────────────────────────────────────────────────────────────┐
│ Avg Score │
│ Raw: 8.3 Balanced: 8.0 ← used for ranking │
│ │
│ Evaluators: 3 Pass Rate: 67% │
│ │
│ ⓘ How is this calculated? (collapsible) │
└──────────────────────────────────────────────────────────────┘
```
- "Raw" and "Balanced" sit side-by-side. The active one (per the round's toggle) gets a subtle "← used for ranking" tag and bolder weight.
- Both numbers always show one decimal (`.toFixed(1)`).
- Below the numbers, a clickable affordance: **"How scores are calculated"** (small button or link with an info icon). Clicking opens an explainer dialog (see "Score explainer dialog" below).
#### Per-juror rows (extends current `Juror Evaluations` block)
Each row currently shows `Name · Yes/No badge · Score: 9.0`. New layout when balanced is on:
```
Rachid Benchaouir Yes Score: 9.0 (typical 7.2 → contributes 8.5)
```
The trailing chip is muted text. When balanced is off, the chip is hidden. Tooltip on the chip explains the calculation.
#### Per-round toggle row at top
```
[Use balanced scoring for ranking] [toggle] ⓘ
```
Single horizontal row, just below the project header. Persists on flip. The ⓘ icon opens the same "How scores are calculated" dialog.
#### Score explainer dialog ("How scores are calculated")
A reusable dialog component (`<ScoreExplainerDialog />`) opens from the affordance in the side panel and from a matching affordance on the observer surfaces (#2, #3) so both audiences see the same explanation. Content is plain-language, not academic, and walks through one concrete worked example.
Structure:
1. **What it does (1 paragraph)** — "Different jurors have different grading styles. Some grade harshly, some leniently. Balanced scoring corrects for that so a project isn't punished for drawing harsh jurors or rewarded for drawing lenient ones."
2. **How it works, step by step** — five short numbered points:
1. For each juror, calculate their personal average and spread across all the projects they scored in this round.
2. Convert each individual score into "how many standard deviations above or below this juror's typical" — a 6 from a juror who averages 5 reads the same as a 9 from a juror who averages 8.
3. Average those normalized values across the project's jurors.
4. Rescale back onto the same 110 scale using the round's overall average and spread.
5. The result is directly comparable to the raw average — same scale, but corrected for grading style.
3. **Worked example** — a concrete table using fabricated jurors, e.g.:
| Juror | Their typical avg | Their score for "Project X" | What that means |
|---|---|---|---|
| Juror A (lenient) | 8.2 | 9.0 | Just slightly above their typical (+0.4σ) |
| Juror B (harsh) | 5.8 | 7.5 | Well above their typical (+1.5σ) |
| Juror C (typical) | 7.0 | 8.0 | Slightly above their typical (+0.7σ) |
"Raw average: (9.0 + 7.5 + 8.0) / 3 = **8.2**
Balanced average rescales each juror's enthusiasm to the round's overall scale and lands at **8.4** — Juror B's strong endorsement (well above their harsh baseline) carries more weight than the raw 7.5 suggests."
4. **When it kicks in / when it doesn't** — short paragraph:
- Needs ≥ 2 evaluations from the round to compute a juror's spread; otherwise that juror falls back to the round-wide average.
- Needs at least one juror with non-zero spread for the round; if everyone gave identical scores, balanced equals raw.
- Computed within a single round only — a juror's grading style in an intake screening round doesn't affect their balance in a deeper evaluation round.
5. **Why "Raw" is still shown** — "We always show both numbers so admins can sanity-check. The toggle at the top of the panel decides which one is used for ranking."
The dialog is a `shadcn/ui` `Dialog`, max-width ~`md`, scrollable. No live data — content is static text + the static example table. Lives in `src/components/shared/score-explainer-dialog.tsx` so it can be imported by admin and observer surfaces alike.
### 4. Decimal display audit
Standardize on **one decimal** for all balanced/raw score surfaces:
- `admin/reports/page.tsx:368` currently shows `toFixed(2)` — change to `toFixed(1)`.
- All other sites already use `.toFixed(1)` or compute integers.
## Data flow summary
```
Round.configJson.useBalancedRanking ──→ ranking-dashboard reads on mount
──→ list sort uses raw or balanced based on flag
──→ side panel shows both, marks the active one
getProjectDetail({ id, roundId }) ──→ filtered submittedEvaluations
──→ round-scoped stats
──→ optionally: per-round balance context computed
inline for the side panel deeper display
getProjectRankings({ programId }) ──→ group by roundId
──→ per-round balance context
──→ aggregate per-project means across rounds
```
## Out of scope
- Migrating historical `ResultLock` snapshots that captured the old (potentially miscomputed) edition-level rankings. Past locks were round-scoped, so they're already correct; only the read-time edition rollup was broken.
- Exposing the toggle to OBSERVER role. Today it's admin-only, matching page access.
- AI calibration service changes — already round-scoped.
- Changing the underlying juror-balance math. The algorithm is correct; only the inputs needed scoping.
## Risks
- **Edition rollup semantic change.** Anyone currently looking at "all rounds" balanced rankings sees different numbers after the fix. This is the right outcome but should be communicated to the team. The numbers shown today are not trustworthy.
- **Toggle default.** Defaulting `useBalancedRanking = true` preserves today's behavior. Existing rounds without the field set use the default.
- **Side-panel re-renders.** The toggle live-updates the list sort; ensure `useQuery` invalidations are wired so a flip in the panel triggers a re-fetch / re-sort without a full page reload.
## Open items
None blocking. Implementation plan can proceed.
## Acceptance criteria
1. With 3 round-scoped evaluations of 9, 8, 8, the side panel stats card shows **Avg 8.3** (not 8.0) and **Evaluators 3** (not 5).
2. Flipping the per-round toggle re-sorts the list view; the choice persists across page reloads and is shared across users.
3. The list view shows no per-row balanced delta annotation.
4. The side panel always shows both Raw and Balanced; the active one is marked.
5. Edition-level rankings (`programId` mode) compute one balance context per round and aggregate, never pooling across rounds.
6. Observer project detail page defaults to the currently-active or most-recently-closed round the project participated in.
7. All score displays use one decimal.
8. A "How scores are calculated" affordance is present in the admin side panel, the observer full project page, and the observer reports preview dialog. Clicking it opens an explainer dialog with the algorithm summary, a step-by-step plain-language walkthrough, and a worked example.

View File

@@ -0,0 +1,520 @@
# Mentor Round Readiness — End-to-End Design
**Date:** 2026-04-28
**Author:** Matt + Claude (brainstorming session)
**Status:** Draft, awaiting review
## Motivation
R5 (Semi-Final Evaluation) is about to close. Next is R6 (Mentoring) for projects that request or are assigned a mentor, then R7 (Grand Final). The MENTORING backend exists but has gaps that block operational use:
- Admin Config form omits two `MentoringConfigSchema` fields (`mentoringRequestDeadlineDays`, `passThroughIfNoRequest`)
- Round Overview shows generic stats only — no mentor-specific dashboard
- `/admin/projects/[id]/mentor` exposes only AI suggestions; manual mentor selection is missing entirely from the UI
- File uploads (`mentor.workspaceUploadFile`) accept client-controlled `bucket` / `objectKey` — security/consistency hole
- Juror "Confirm Your Evaluation Preferences" banner pulls in LIVE_FINAL groups (not appropriate for a live ceremony)
- Multi-role users (juror + mentor) land on primary role's dashboard only; no quick path for an admin to bulk-promote jurors
- Zero tests for MENTORING round behavior
This spec covers all of the above plus workspace messaging/file UX polish, in one design with phased PRs.
## Goals
1. Admin can fully configure a MENTORING round from the UI (no DB-direct edits needed for any `MentoringConfigSchema` field).
2. Admin can see at a glance: who requested mentoring, who has a mentor, who doesn't, who's mentoring whom, what the mentor pool looks like.
3. Admin can manually assign a mentor to any project, AND auto-fill all unassigned projects in one action.
4. Files uploaded in the mentor workspace land at `<projectName>/mentorship/<file>` in the configured bucket, with paths constructed server-side.
5. Mentors and applicant teams see recent messages on their respective dashboards.
6. A juror who is also a mentor can switch dashboards in one click, without seeing irrelevant LIVE_FINAL preference cards.
7. The MENTORING round behavior (pass-through, eligibility, advancement) is covered by integration tests.
## Non-goals
- Redesigning messaging or notifications from scratch.
- Replacing the AI mentor-matching service with a different model.
- Building a mentor scheduling/calendar feature.
- Bulk-promoting jurors to mentors via CSV import (per-row checkbox + bulk action is enough for this iteration).
- Migrating any existing mentor file objects in MinIO (none exist yet — spec asserts a pre-flight check).
## Out-of-scope but adjacent
- Grand Finale (R7 LIVE_FINAL) UX — explicitly deferred per user direction (handled separately, much further build-out planned).
- Mentor pool capacity / load-balancing algorithm changes — covered only by surfacing existing fields in the admin view.
---
## High-level architecture
No new top-level architecture. Extending existing patterns:
- **Storage path:** new helper `generateMentorObjectKey(projectTitle, fileName)` in `src/lib/minio.ts` that returns `<sanitizedProjectName>/mentorship/<timestamp>-<sanitizedFileName>` — exact same shape as `generateObjectKey()` with `roundName="mentorship"`. Server-side only.
- **Config schema:** no Prisma migration. The two missing fields (`mentoringRequestDeadlineDays`, `passThroughIfNoRequest`) already exist in `MentoringConfigSchema` and are read by `round-engine.ts` and `applicant.ts` — only the form needs updating.
- **Multi-role dashboards:** existing `User.roles UserRole[]` array drives everything; logic-only changes (post-login redirect priority, bulk-promote bulk action, fix CSS layering on impersonation banner).
- **Preferences filter:** single Prisma query change in `getOnboardingContext`.
- **Workspace dashboards:** reuse existing `MentorMessage` table; new tRPC procedures return last-N message previews.
## Phasing / PR plan
Six PRs, ordered smallest-blast-radius first:
| PR | Section | Risk | What ships |
|----|---------|------|------------|
| 1 | §E | Low | Filter `getOnboardingContext` to review-only rounds |
| 2 | §F.1 | Low | Server-side `objectKey` enforcement + `generateMentorObjectKey` helper |
| 3 | §A | Med | Config form completeness (2 missing inputs + General Settings cleanup + Launch Readiness gate relax) |
| 4 | §C | Med | Manual mentor picker + bulk auto-fill + AI fallback |
| 5 | §B | Med | Mentor-specific Round Overview + un-redirect `/admin/mentors` |
| 6 | §D + §F.2 | Med | Multi-role redirect priority + bulk-promote + impersonation banner fix + dashboard message previews |
| (continuous) | §G | Low | Tests added in each PR for the surface changing in that PR |
A standalone test PR is *not* planned — tests ride with the change they cover.
---
## §A. MENTORING round Config form
**Files:**
- `src/components/admin/round-config/mentoring-config.tsx` (likely path; locate the round-type-specific config component used by `(admin)/admin/rounds/[roundId]` Config tab)
- `src/components/admin/round-config/launch-readiness.tsx` (or similar — the component that renders the 0/3 readiness checklist)
**Changes:**
1. Add **"Mentoring Request Window"** section to the Config form:
- Numeric input bound to `configJson.mentoringRequestDeadlineDays` — int, min 1, max 90, default 14.
- Help text: "Number of days from round opening during which teams may request mentoring. After this window, no new requests are accepted."
2. Add **"Pass-through behavior"** toggle bound to `configJson.passThroughIfNoRequest`:
- Default `true` (matches schema default).
- Off-state label: "Hold all projects in PENDING until mentor is assigned (manual gate)"
- On-state label: "Auto-PASS projects that don't request mentoring (default)"
3. Replace empty **"General Settings"** section header. Either:
- Delete the empty header (preferred — fewer questions); OR
- Move the eligibility dropdown into it (so the section has content).
4. Relax Launch Readiness "File requirements set" gate for MENTORING rounds:
- Required only when `configJson.filePromotionEnabled === true` AND `configJson.promotionTargetWindowId` is set (i.e., the round is configured to promote mentor-authored files into a downstream submission window).
- Otherwise treat the readiness item as N/A and don't count it against the 0/3 (it becomes 0/2 for mentoring rounds without promotion configured).
5. Help-text added to the existing **Eligibility** dropdown explaining each option:
- `requested_only` — only projects that flag `mentoringRequested` participate (default).
- `all_advancing` — every project advancing into this round gets a mentor.
- `admin_selected` — admin manually picks which projects participate.
**Tests** (in PR 3): one per `MentoringConfigSchema` field — render with default config, change input, submit, assert config persisted via the existing config-save mutation.
---
## §B. Mentoring-specific admin views
**Files:**
- `src/app/(admin)/admin/rounds/[roundId]/page.tsx` (Round Overview tab)
- `src/app/(admin)/admin/rounds/[roundId]/projects-tab.tsx` (Projects tab — exact filename to confirm during impl)
- `src/app/(admin)/admin/mentors/page.tsx` (currently a redirect stub — replace with a real list page)
- `src/app/(admin)/admin/mentors/[id]/page.tsx` (also a stub today; replace with mentor detail)
- New tRPC procedures on `mentor` router (admin-gated): `getRoundStats`, `getMentorPool`, `getMentorDetail`
**Round Overview — replace generic Round Details with a mentoring-specific stats card** when `round.roundType === 'MENTORING'`:
- **Top-line counts** (single row of stat cards):
- Total projects in round
- Requested mentoring (count + % of total)
- Mentor assigned (count + % of total)
- Awaiting assignment (= requested - assigned)
- **Request window** card:
- Deadline (computed from `windowOpenAt + mentoringRequestDeadlineDays`)
- Time remaining (live countdown, using existing `formatCountdown` helper)
- "Closes in N days" pill, turns amber within 48 hours, red within 12 hours
- **Mentor pool** card:
- Pool size (count of users with MENTOR role in the program)
- Average load (assigned projects ÷ pool size)
- Capacity remaining (sum of `User.maxAssignmentsOverride` minus current load, where overrides exist)
- Link → `/admin/mentors`
- **Workspace activity** card:
- Total messages exchanged (sum across all assignments in round)
- Total files uploaded
- Total milestones completed
- "Last activity" timestamp
**Round Details panel** stays at the bottom of the Overview tab when round is MENTORING (the existing panel is still useful for type/status/position/dates), but with these field-level adjustments:
- Replace "Jury Group: —" row with "Mentor Pool: N members" (link to `/admin/mentors`).
- Keep "Type", "Status", "Position", "Opens", "Closes" rows unchanged.
- The new "mentoring stats card" (top-line counts, request window, mentor pool, workspace activity) renders **above** the Round Details panel, not in place of it.
**Projects tab — when round is MENTORING**, the per-project row shows:
- Project title + team lead
- "Requested mentoring" badge (yes/no)
- "Mentor assigned" cell — mentor name + expertise overlap chip, OR "Unassigned" with inline "Assign" button → opens the manual-pick drawer (see §C)
- "Workspace activity" small-text summary (msgs / files / milestones)
- Bulk action bar (when ≥1 project selected): "Auto-fill mentors for selected" → calls `mentor.autoAssignBulk`
**`/admin/mentors` — un-redirect, replace stub with a real list page:**
- Searchable/filterable list of all users with MENTOR role in the current edition.
- Columns: name, email, country, expertise tags (chips), assigned-projects count, completed count, capacity remaining, last activity.
- Row → `/admin/mentors/[id]` detail page (existing route, replace stub):
- Mentor profile + expertise + bio
- List of assigned projects (link to per-project workspace)
- Per-project status (in_progress / completed / paused)
- Recent activity feed (messages / file uploads / milestone completions across all assignments)
- Admin actions: reassign / unassign
**Tests** (in PR 5): integration test for `getRoundStats` returning correct counts; render-test for round overview when round.roundType=MENTORING.
---
## §C. Manual + auto-fill mentor assignment
**Files:**
- `src/app/(admin)/admin/projects/[id]/mentor/page.tsx` (rewrite)
- `src/server/services/mentor-matching.ts` (add expertise-tag fallback)
- `src/server/routers/mentor.ts` (`getCandidates` new procedure for manual picker; ensure `autoAssignBulk` exposes a "skip already assigned" param — confirm and document)
**Page rewrite — three sections, all visible at once (not tabs):**
1. **Project Context** card (top):
- Project title, ocean issue, country, team size, expertise needs (project tags)
- Round being assigned for (linked)
- Mentoring requested? Yes/no
2. **Currently Assigned** card:
- If assigned: mentor name, email, country, expertise overlap chips, "Assigned by [admin], 3 days ago, method: MANUAL/AUTO", actions: Unassign | Swap
- If unassigned: empty state with copy "No mentor assigned yet — pick one below or use AI"
3. **Pick a mentor** card with a tab strip:
- **Tab 1 — Manual picker** (default selected):
- Searchable input
- Sortable table of all MENTOR-role users in the program: name, expertise tags, country, current load, capacity, **expertise overlap with this project** (computed: count of shared tags / total project tags, displayed as a percentage chip)
- Default sort: highest expertise overlap first
- Per-row "Assign" button → calls `mentor.assign({ projectId, mentorId, method: 'MANUAL' })`
- **Tab 2 — AI suggestions**:
- Existing pane (loads `getSuggestions`).
- **Fallback**: if AI fails (no `OPENAI_API_KEY`, network error, or returns empty) — show expertise-tag-overlap ranking as the suggestion source instead, with a banner: "AI matching unavailable — showing expertise-tag overlap instead". (The fallback ranking is the same algorithm as Tab 1's default sort, so the lists may look similar — that's fine.)
**Auto-fill remainder** (bulk action):
- On round Projects tab + Round Overview, button: "Auto-fill mentors for unassigned projects".
- Call `mentor.autoAssignBulk` with the round ID; the service filters to projects-in-round-without-MentorAssignment, scoped further by the round's `eligibility` config:
- `requested_only` → only projects with `mentoringRequested=true`
- `all_advancing` → every project in the round
- `admin_selected` → button disabled (admins must pick manually for this mode)
- Confirm the existing service already skips projects with a MentorAssignment (any method); if it doesn't, fix in the same PR.
- Result toast: "Assigned N projects, skipped M already-assigned, K unassignable (no matching mentor)".
**Tests** (in PR 4):
- `mentor.assign` round-trips with method=MANUAL
- `mentor.autoAssignBulk` skips manually-assigned projects
- `getCandidates` returns expected expertise-overlap ordering
- Fallback path used when AI unavailable
---
## §D. Juror→mentor multi-role UX
**Files:**
- `src/app/page.tsx` (post-login redirect)
- `src/app/(admin)/admin/members/page.tsx` (bulk action)
- `src/components/layouts/role-nav.tsx` (no change — switcher already correct)
- `src/components/layouts/impersonation-banner.tsx` (or wherever the banner lives — find via grep)
- `src/server/routers/user.ts` (new `bulkUpdateRoles` mutation if not exists)
- `src/lib/email/templates/mentor-onboarding.tsx` (new)
- `src/server/services/notifications.ts` (or equivalent — call site to send mentor-onboarding email when MENTOR role is freshly added to a user)
**1. Post-login redirect — context-aware "go where the work is":**
Replace single-`role` switch in `src/app/page.tsx` with a priority list that is *filtered by actionable work*. The user lands on the highest-priority role for which they have something to do right now; if no role has active work, fall back to the static priority order.
New tRPC query: `user.getDefaultDashboard()` (server-side, called from `src/app/page.tsx`):
```ts
// Static priority — used as fallback ordering AND as the order we check for work.
const ROLE_DASHBOARD_PRIORITY: Array<[UserRole, Route]> = [
['SUPER_ADMIN', '/admin'],
['PROGRAM_ADMIN', '/admin'],
['AWARD_MASTER', '/award-master'],
['JURY_MEMBER', '/jury'],
['MENTOR', '/mentor'],
['APPLICANT', '/applicant'],
['OBSERVER', '/observer'],
['AUDIENCE', '/audience'],
]
```
For each role the user holds (in priority order), the server checks "does this user have actionable work in this role right now?":
| Role | "Has actionable work" predicate |
|------|---------------------------------|
| SUPER_ADMIN / PROGRAM_ADMIN | Always true (admin work is always present) |
| AWARD_MASTER | Any unfinalized award decision in an active round in current edition |
| JURY_MEMBER | Any `JuryAssignment` linked to a round whose `status = ROUND_ACTIVE` AND the user has at least one PENDING evaluation |
| MENTOR | Any `MentorAssignment` whose linked round is `ROUND_ACTIVE` AND `workspaceEnabled = true` |
| APPLICANT | Any `Project` led by user with at least one `ProjectRoundState` in a non-terminal state in an active round |
| OBSERVER | Always false (observers have nothing to act on) |
| AUDIENCE | Always false |
Algorithm:
1. Try roles in priority order. Return the first role whose predicate is true.
2. If no role has actionable work, return the highest-priority role the user holds (static fallback).
3. Always end with a non-null route (worst case: any signed-in user has at least their primary role).
**Why this matters (your example):** a juror+observer who logs in during an open jury round lands on `/jury` (because they have a pending evaluation), not `/observer`. A mentor+juror logs in during an active MENTORING round → `/mentor`. After both rounds close, same user logs in → static fallback (jury > mentor) → `/jury`. The role switcher in the user menu is always available to override.
**Decision: context-aware, not "remember last view".** "Remember last view" requires a new column and surprises users when their last context disappears (round closed, role removed). Context-aware is deterministic, explains itself, and handles the cross-role overlap cleanly. The role switcher dropdown is the user's escape hatch.
**Tests** (in PR 6):
- Juror with pending evaluation in active round + Observer → `/jury`
- Juror with no active assignments + Observer → `/jury` (fallback to static priority)
- Mentor+Juror, MENTORING round active, no jury work → `/mentor`
- Mentor+Juror, both rounds active with work in both → `/jury` (priority order breaks the tie)
- Observer-only user → `/observer`
- Multi-role with no active work anywhere → static-priority fallback
**2. Bulk juror→mentor promotion** on `/admin/members`:
- Add row checkboxes to the Members table (already a table — confirm during impl).
- When ≥1 row selected, surface a bulk action toolbar with "Add role…" dropdown (OBSERVER / MENTOR / AWARD_MASTER) and "Remove role…".
- Call new `user.bulkUpdateRoles({ userIds, addRole?, removeRole? })` mutation. Server-side: only SUPER_ADMIN/PROGRAM_ADMIN, log a `DecisionAuditLog` entry per user changed.
- After success, refresh the table and toast "Added MENTOR role to N users; M already had it (no-op)".
**3. Mentor-onboarding email** (one-shot):
- New email template at `src/lib/email/templates/mentor-onboarding.tsx`: brief welcome, explanation of mentor responsibilities, link to `/mentor`, link to "Switch View" doc/walkthrough.
- Trigger: in `user.bulkUpdateRoles` and the existing single-user `updateRoles` mutation, when MENTOR is **newly** added (i.e., wasn't in `roles[]` before this update) → enqueue the email. Idempotent on subsequent edits that keep MENTOR in `roles`.
- Add a `User.mentorOnboardingSentAt: DateTime?` column for idempotency. Migration: nullable column, no backfill needed.
**4. Fix impersonation banner pointer-events:**
- Locate the banner component (grep `Impersonating` / `bg-red-600 fixed top-0`).
- Restructure: banner sits in a flex container above the header rather than being `position: fixed` over it. The header height stays unchanged; the banner pushes content down.
- Alternative (smaller change): keep `position: fixed` but `pointer-events: none` on the banner div and re-enable `pointer-events: auto` on the inner "Return to Admin" button only. Either fixes the menu intercept.
- Pick the simpler diff at impl time; document choice in PR.
**5. Banner shows all roles:**
- When `session.user.roles.length > 1`, render comma-separated list: "Impersonating Dr. Sophie Laurent (JURY MEMBER, MENTOR)".
**6. Standardize the role-switcher (location + presentation):**
Today's state:
- Header layouts (`role-nav.tsx`) — used by jury, mentor, applicant, observer, award-master — put the user menu **top-right** with role-switcher items inside the dropdown.
- Admin layout (`admin-sidebar.tsx`) puts the user menu **bottom-left of the sidebar** with its own duplicate `ROLE_SWITCH_OPTIONS` constant + `switchableRoles` filter (lines 161, 191, 377-401).
Two problems: (a) duplicated logic across two files; (b) different physical placement, so a multi-role user has to learn two patterns to find "Switch View".
Changes:
- **Extract a shared module** at `src/components/layouts/role-switcher.tsx` exporting:
- `useRoleSwitcher()` hook returning `{ switchableRoles: Array<{ label, path, icon }>, currentBasePath }`. Both `role-nav.tsx` and `admin-sidebar.tsx` import this. Source of truth for `ROLE_SWITCH_OPTIONS` lives here only.
- `RoleSwitcherMenuItems` component — renders the dropdown items (used inside both layouts' user menus). Keeps rendering inline-consistent.
- `RoleSwitcherPill` component — a standalone visible button that renders just outside the user-menu dropdown, with label "Switch View" + the icon of the next-best alternate role. Visible only when `switchableRoles.length > 0`. Click opens a small popover listing alternates.
- **Place the `RoleSwitcherPill` in a consistent location across all layouts**: top-right of the header, immediately to the LEFT of the notifications bell. For the admin layout (sidebar-based), add a top-right header strip that hosts the pill + notifications + theme toggle, mirroring the other dashboards. (The admin sidebar keeps everything else; just the top-bar is added.)
Why top-right: that's where the existing role-nav layouts already put switching/profile actions. Admins gain the pill in the same spot — no learning curve when switching from /admin to /jury.
- **Pill behavior:**
- Hidden if `switchableRoles.length === 0` (single-role users see nothing — clean default).
- Hidden when `isImpersonating` (impersonator UX is already different; the existing impersonation banner with "Return to Admin" handles role-switching for that path).
- On hover/focus: shows tooltip "Switch dashboard view".
- Keyboard: `Cmd+Shift+V` shortcut opens the popover (nice-to-have; ship if it doesn't add much code).
- **Admin sidebar bottom user pill stays** (so admin users can still sign out / open settings from there). The role-switcher items are removed from that menu — they live exclusively in the new pill + the user-dropdown's switch list. (Avoids three places to switch view.)
**Acceptance for §D.6:** any signed-in user with `roles.length > 1` sees a "Switch View" pill in the same screen position regardless of which dashboard they're currently in.
**Tests** (in PR 6):
- `user.getDefaultDashboard` test cases enumerated above (juror+observer with active jury round → /jury; etc.).
- `bulkUpdateRoles` adds MENTOR to N users and sends N onboarding emails.
- Idempotency: second `bulkUpdateRoles` with same input does NOT resend email.
- Impersonation banner does not intercept clicks on user dropdown (Playwright e2e if available).
- `RoleSwitcherPill` renders in the top-right of every dashboard for multi-role users; renders nothing for single-role users.
- Single shared `useRoleSwitcher` source means changing `ROLE_SWITCH_OPTIONS` updates both layouts simultaneously.
---
## §E. Filter juror preferences to review-only rounds (PR 1)
**File:** `src/server/routers/user.ts:1397-1422` (`getOnboardingContext`)
**Change:** Query the membership's jury group, including its linked rounds. Filter out memberships where every linked round is LIVE_FINAL or DELIBERATION. Keep memberships where at least one linked round is INTAKE / FILTERING / EVALUATION / SUBMISSION / MENTORING.
```ts
const memberships = await ctx.prisma.juryGroupMember.findMany({
where: {
userId: ctx.user.id,
juryGroup: {
rounds: {
some: {
roundType: {
in: ['INTAKE', 'FILTERING', 'EVALUATION', 'SUBMISSION', 'MENTORING'],
},
},
},
},
},
include: { juryGroup: { select: { id: true, name: true, defaultMaxAssignments: true } } },
})
```
(Confirm the relation field name `rounds` on `JuryGroup` during impl — Prisma schema field may be `Round[]` named differently.)
**Tests** (in PR 1):
- Juror with memberships in (Screening: FILTERING) + (Finals: LIVE_FINAL) → only Screening returned.
- Juror with memberships in (Mixed: EVALUATION + LIVE_FINAL) → returned (group has at least one review round).
- Juror with only (Finals: LIVE_FINAL) → no memberships returned.
**Risk:** very low. Single procedure, additive Prisma filter, easy to revert.
---
## §F. Workspace messaging + files end-to-end
### §F.1 — Server-side path enforcement (PR 2)
**Files:**
- `src/lib/minio.ts` (add helper)
- `src/server/routers/mentor.ts` (`workspaceUploadFile` procedure + presign procedure)
- `src/server/services/mentor-workspace.ts` (`uploadFile` service)
**New helper** in `src/lib/minio.ts`:
```ts
export function generateMentorObjectKey(projectTitle: string, fileName: string): string {
return generateObjectKey(projectTitle, fileName, 'mentorship')
}
```
This produces `<sanitizedProjectName>/mentorship/<timestamp>-<sanitizedFileName>`, matching the existing project-file scheme.
**Procedure changes:**
1. Add a presign procedure (if not present): `mentor.presignWorkspaceUpload({ mentorAssignmentId, fileName, mimeType, size })`
- Loads the `MentorAssignment` + linked `Project` (server-side).
- Authorizes: user is the assigned mentor OR a project team member (mentorProcedure for mentors; protectedProcedure with project-team check for applicants).
- Constructs `objectKey = generateMentorObjectKey(project.title, fileName)`.
- Returns `{ uploadUrl, bucket, objectKey }` — the presigned PUT URL is short-lived (1h).
2. Change `workspaceUploadFile` to accept ONLY `{ uploadToken, description? }` (where `uploadToken` is an opaque value returned by the presign call). The presign procedure stores `{ token → { mentorAssignmentId, fileName, mimeType, size, bucket, objectKey } }` in a short-lived cache (in-memory or Redis if configured, 1h TTL). The upload procedure looks up the token, validates that the user is the same one who called presign, then writes the `MentorFile` row using the cached values. This eliminates any client-controlled path entirely.
3. Mirror the same change for applicant-side uploads to mentor workspace (if a separate procedure exists).
**Migration:** Pre-flight — confirm `MentorFile` table is empty (or only test data) in production. If it has any rows, migrate `objectKey`s to the new scheme via a one-shot script; otherwise skip migration.
**Tests** (in PR 2):
- Presign returns key matching `<projectName>/mentorship/<timestamp>-<file>` shape.
- `workspaceUploadFile` rejects payloads that include `bucket` or `objectKey` (input schema rejects unknown fields via Zod).
- Authorization: mentor uploading to a workspace they're NOT assigned to → throws TRPCError UNAUTHORIZED.
### §F.2 — Dashboard message previews (PR 6)
**Files:**
- New component: `src/components/mentor/recent-messages-card.tsx`
- New component: `src/components/applicant/mentor-conversation-card.tsx`
- `src/app/(mentor)/mentor/page.tsx` — embed RecentMessagesCard
- `src/app/(applicant)/applicant/page.tsx` — embed MentorConversationCard (only render when project has mentorAssignment + workspace enabled)
- `src/server/routers/mentor.ts` — new procedure `getRecentMessagesForMentor` (returns last N msgs across all assignments)
- `src/server/routers/applicant.ts` — new procedure `getMentorConversationPreview({ projectId })` (returns last 3 msgs + unread count for one project)
**Mentor dashboard preview**:
- Card title: "Recent Messages"
- Shows last 5 unread messages across ALL assignments (sender name + project + first 100 chars + relative timestamp).
- Each row links to `/mentor/workspace/<projectId>` (jumps to that conversation).
- "View all" link → `/mentor/messages` (existing or new index — confirm during impl).
- Empty state: "No new messages. Your mentees will appear here when they reach out."
**Applicant dashboard preview** (only when project has assigned mentor + workspace enabled):
- Card title: "Conversation with [Mentor Name]"
- Shows last 3 messages (sender name + content + timestamp).
- Unread count badge.
- "Send a message" inline composer or "Open chat" button → `/applicant/mentor`.
- Empty state: "Say hi to your mentor — they're here to help you sharpen your project."
**Performance:** both queries use indexed lookups on `MentorMessage(workspaceId, createdAt)`. Add an index migration if not present.
**Tests** (in PR 6):
- `getRecentMessagesForMentor` returns N most-recent unread messages across assignments.
- `getMentorConversationPreview` returns 3 most-recent messages + correct unread count.
- Renders gracefully when no assignment / no messages.
### §F.3 — End-to-end verification scenario (covered in §G)
A single integration test walking through the full happy path. See §G.
---
## §G. Tests
**New test files:**
- `tests/unit/mentor-config.test.ts` (PR 3) — Config form persistence per field
- `tests/unit/mentor-key-construction.test.ts` (PR 2) — `generateMentorObjectKey` shape + sanitization
- `tests/integration/mentor-assignment.test.ts` (PR 4) — manual + auto + bulk + skip
- `tests/integration/mentor-round-engine.test.ts` (NEW for PR 3 or PR 5) — pass-through behavior, eligibility variants, advancement
- `tests/integration/mentor-workspace.test.ts` (PR 6) — message + file lifecycle, dashboard previews, milestone auto-complete
- `tests/unit/jury-preferences-filter.test.ts` (PR 1) — `getOnboardingContext` filter
**End-to-end happy path** (`tests/integration/mentor-round-e2e.test.ts`, ships with PR 6):
1. Admin creates a MENTORING round, sets dates + eligibility=requested_only + 14-day deadline.
2. Admin activates round.
3. Project A has `mentoringRequested=true`, project B does not.
4. Round-engine activation: B auto-PASSED (pass-through), A stays PENDING.
5. Admin manually assigns mentor M1 to project A. A flips PENDING → IN_PROGRESS. Mentor + team get assignment notification.
6. M1 sends a message in workspace; team replies. Both messages appear in respective dashboard previews.
7. M1 uploads a file. ObjectKey matches `<projectA-title>/mentorship/<timestamp>-...`. Team comments on the file.
8. M1 marks all required milestones complete → assignment.completionStatus = "completed".
9. Admin closes round. A and B both PASSED; A also COMPLETED.
This single test covers the operational path the user actually cares about for the upcoming round.
---
## Open questions
1. **`generateMentorObjectKey` — which "project name" field do we pass?** `Project.title` is the obvious choice (it's what `generateObjectKey` for submission files uses). Confirm during impl that there's no team-name-specific field we should prefer.
2. **Does `JuryGroup` have a direct `rounds` Prisma relation?** Spec assumes it; confirm field name during impl. If it's `Round.juryGroupId` only (no back-relation), use a nested `Round` query.
3. **Mentor-onboarding email content** — copy needs writing. Owned by admin, not blocking impl; can ship with placeholder copy and finalize before going live.
4. **`mentor.autoAssignBulk` — does it already skip manually-assigned?** Spec assumes yes; confirm by reading source during PR 4. If no, change is small (add `where: { method: { not: 'MANUAL' } }` to its query).
5. **Pre-flight check on existing mentor files in prod MinIO before §F.1** — must be empty or migrated, not orphaned. Confirm via `prisma db query` against prod read replica before deploying PR 2.
## Risks
| Risk | Severity | Mitigation |
|------|----------|------------|
| Existing mentor files in prod use legacy keys | High if hit | Pre-flight check; migration script ready before deploy |
| `bulkUpdateRoles` accidentally removes a critical role | Med | Server-side guard: SUPER_ADMIN cannot be self-demoted; audit log all changes |
| Multi-role redirect priority surprises some users | Low | Document the priority order; role switcher exists for override |
| AI fallback ordering doesn't match prior AI suggestions | Low | UX banner clearly states fallback is in use; keep logic simple |
| Filter on `getOnboardingContext` accidentally hides valid memberships | Low | Tests cover the three cases; ship behind no flag, easy to revert |
## Migration plan
- §A: no migration.
- §B: no migration.
- §C: no migration.
- §D: one Prisma migration adding nullable `User.mentorOnboardingSentAt: DateTime?`. No backfill (treat all existing users as not-yet-onboarded; on next role edit, email fires once).
- §E: no migration.
- §F.1: optional one-shot script to rewrite legacy `MentorFile.objectKey` rows to the new scheme. Only runs if pre-flight check finds rows. The script copies objects to the new key path then updates DB rows in a transaction; old keys remain readable until manual cleanup.
- §F.2: optional Prisma index on `MentorMessage(workspaceId, createdAt DESC)` if not present.
## Rollback
Each PR independently revertable. PRs 1, 2, 4 ship with no migration → straight git revert. PR 6 has a migration → revert PR + one-line down migration to drop the column. PR 3 has no migration; PR 5 has no migration.
## Acceptance criteria (per phase)
**PR 1 (§E):**
- Sophie Laurent (member of Screening, Expert, Finals jury groups) sees Screening + Expert preferences only — not Finals.
**PR 2 (§F.1):**
- New mentor file uploads write to `<projectName>/mentorship/<timestamp>-<file>` in MinIO.
- Removing `bucket` / `objectKey` from a `workspaceUploadFile` call still succeeds.
- Old `objectKey` upload payloads now fail Zod validation.
**PR 3 (§A):**
- All `MentoringConfigSchema` fields are editable from the Config tab.
- A draft MENTORING round with no document-promotion configured can pass Launch Readiness without a "File requirements set" check.
**PR 4 (§C):**
- Admin can manually assign any MENTOR-role user to any project from `/admin/projects/[id]/mentor`.
- Round Projects tab "Auto-fill remaining" assigns to all `mentoringRequested=true` projects without a mentor.
- Page renders sensibly with no `OPENAI_API_KEY` set (expertise-tag fallback).
**PR 5 (§B):**
- MENTORING round Overview shows live counts (requested / assigned / unassigned), deadline countdown, mentor pool size, workspace activity totals.
- `/admin/mentors` shows real list of MENTOR-role users with current assignments.
**PR 6 (§D + §F.2):**
- Juror+observer logging in during an active jury round lands on `/jury` (context-aware default). Same user logging in after the round closes lands on `/jury` via static fallback (still highest-priority role they hold).
- Mentor+juror with active mentoring assignments and no jury work lands on `/mentor`.
- `RoleSwitcherPill` ("Switch View") renders in the top-right of the header on every dashboard for multi-role users, in the same screen position regardless of layout. Single-role users don't see it.
- Admin sidebar still has the user pill at the bottom-left for sign-out / settings; role-switcher entries are removed from that menu (live in the new pill instead).
- `/admin/members` allows multi-select + "Add MENTOR role to selected" → all selected users get email + role.
- Impersonation banner doesn't intercept clicks on the user dropdown.
- Mentor `/mentor` dashboard shows "Recent Messages" card; applicant `/applicant` dashboard shows "Conversation with [Mentor]" card.

View File

@@ -0,0 +1,348 @@
# PR 6 — Lunch event (design)
Date: 2026-04-29
Status: design locked, ready for implementation plan
## 1. Goal & scope
Replace the Lunch tab placeholder on `/admin/logistics` with a working flow: admins configure a single per-edition lunch event, attendees pick a dish + log allergies, and the manifest is reviewable in-app, exportable to CSV, and emailed at the change deadline.
**In scope:**
- New models: `LunchEvent` (1:1 per program), `Dish` (per event), `MemberLunchPick` (1:1 per `AttendingMember`), `ExternalAttendee` (per program, optionally team-attached).
- Enums: `DietaryTag`, `Allergen`.
- Admin UI on the existing Logistics → Lunch tab: event config card, dishes CRUD, manifest table, externals CRUD, recap preview/send, audit logging.
- Team-lead UX: dish/allergy editing for any `AttendingMember` on their project, on the existing applicant dashboard.
- Member self-serve UX: dish/allergy editing for own `AttendingMember`, on the same dashboard.
- Single reminder email (configurable hours before deadline).
- Recap email (manual button + cron auto-send, both toggleable; admin recipients + free-form extras).
- Removal of the Lunch placeholders from Edition settings and from the disabled Logistics tab trigger.
**Out of scope:**
- No caterer-facing email integration. Admins forward the recap manually.
- No multi-event per edition (1:1 with `Program`).
- No public token-gated picker. Members must have an account; team leads or admins fill in for non-active members.
- Editable email templates (lands in PR 7).
## 2. Permission matrix
| Editor | Can edit |
| --- | --- |
| Member (logged in) | Their own dish + allergies, until deadline |
| Team lead | Any `AttendingMember` on their project, until deadline |
| Admin | Everything — all `AttendingMember` picks + all `ExternalAttendee` records, no deadline cap |
External (off-platform) attendees are admin-only to manage; team leads see them on the project page read-only when an external is attached to their team.
*"Team lead"* throughout this spec means a user with a `TeamMember` row on the project where `TeamMember.role === 'LEAD'` (existing enum value, defined at `schema.prisma:273-277`).
*"Admins of the edition"* (used by recap recipients and audit-log actor scoping) means all users with `role === 'SUPER_ADMIN'` plus all users with `role === 'PROGRAM_ADMIN'`. There is no per-program admin scoping today, so all program admins receive the recap.
## 3. Data model
```prisma
enum DietaryTag {
VEGETARIAN
VEGAN
GLUTEN_FREE
PESCATARIAN
}
enum Allergen {
GLUTEN // cereals containing gluten
CRUSTACEANS
EGGS
FISH
PEANUTS
SOYBEANS
MILK
TREE_NUTS
CELERY
MUSTARD
SESAME
SULPHITES
LUPIN
MOLLUSCS
}
model LunchEvent {
id String @id @default(cuid())
programId String @unique // 1:1 — one lunch per edition
enabled Boolean @default(false)
eventAt DateTime? // nullable until admin sets it
endAt DateTime?
venue String?
notes String? @db.Text
changeCutoffHours Int @default(48)
reminderHoursBeforeDeadline Int? // null = no reminder
cronEnabled Boolean @default(true) // auto-recap at deadline
extraRecipients String[] @default([]) // off-platform recap recipients
reminderSentAt DateTime? // cron idempotency
recapSentAt DateTime? // gates "send updated recap?" prompt
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
program Program @relation(fields: [programId], references: [id], onDelete: Cascade)
dishes Dish[]
externalAttendees ExternalAttendee[]
}
model Dish {
id String @id @default(cuid())
lunchEventId String
name String
sortOrder Int @default(0)
dietaryTags DietaryTag[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lunchEvent LunchEvent @relation(fields: [lunchEventId], references: [id], onDelete: Cascade)
memberPicks MemberLunchPick[]
externals ExternalAttendee[]
@@index([lunchEventId])
}
model MemberLunchPick {
id String @id @default(cuid())
attendingMemberId String @unique // 1:1, mirrors FlightDetail/VisaApplication
dishId String? // null = not picked yet
allergens Allergen[] @default([])
allergenOther String? // "other" free-text
pickedAt DateTime? // null until first pick made
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attendingMember AttendingMember @relation(fields: [attendingMemberId], references: [id], onDelete: Cascade)
dish Dish? @relation(fields: [dishId], references: [id], onDelete: SetNull)
@@index([dishId])
}
model ExternalAttendee {
id String @id @default(cuid())
lunchEventId String
projectId String? // optional — null = standalone (jury/dignitary/etc.)
name String
email String?
roleNote String?
dishId String?
allergens Allergen[] @default([])
allergenOther String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lunchEvent LunchEvent @relation(fields: [lunchEventId], references: [id], onDelete: Cascade)
project Project? @relation(fields: [projectId], references: [id], onDelete: SetNull)
dish Dish? @relation(fields: [dishId], references: [id], onDelete: SetNull)
@@index([lunchEventId])
@@index([projectId])
}
```
**Back-references on existing models:**
```prisma
model Program {
// ...existing fields...
lunchEvent LunchEvent?
}
model AttendingMember {
// ...existing fields...
lunchPick MemberLunchPick?
}
model Project {
// ...existing fields...
externalLunchAttendees ExternalAttendee[]
}
```
**Auto-create hook.** When an `AttendingMember` is created, if a `LunchEvent` exists for the parent program, also create an empty `MemberLunchPick` (`dishId=null`, `pickedAt=null`). When the `AttendingMember` is deleted, the cascade handles the pick. Mirrors the visa-application auto-sync added in commit `bdfd998`.
**Migrations are additive.** Nothing existing changes shape. `pickedAt` is set on the first `upsertPick` call where `dishId` is non-null; subsequent edits update `updatedAt` only.
## 4. API surface
New router `src/server/routers/lunch.ts`, mounted as `trpc.lunch.*`. Logistics router unchanged.
### Admin-only (`adminProcedure`)
| Procedure | Purpose |
| --- | --- |
| `getEvent` | Get-or-create the `LunchEvent` for the current program (lazy create, mirrors hotel's pattern). |
| `updateEvent` | Patch any subset of: `enabled, eventAt, endAt, venue, notes, changeCutoffHours, reminderHoursBeforeDeadline, cronEnabled, extraRecipients[]`. |
| `createDish` / `updateDish` / `deleteDish` / `reorderDishes` | Dish CRUD. Delete sets `dishId=null` on picks via Prisma `SetNull`. |
| `listExternals` / `createExternal` / `updateExternal` / `deleteExternal` | External-attendee CRUD. |
| `getManifest` | Full manifest: attending members (filtered to `FinalistConfirmation.status === CONFIRMED`) + externals, each with project, name, dish, allergens. Backs the Lunch tab table and CSV export. |
| `exportManifestCsv` | Server-side CSV generation; returns string for client-side download. |
| `getRecapPreview` | Returns the recap email payload (counts + table) for in-app preview. |
| `sendRecap` | Manual send. Input `{ forceUpdate?: boolean }`. If `recapSentAt` is set and `forceUpdate=false`, throws `PRECONDITION_FAILED` so the UI can show the "send updated?" confirm. Sends to admins of the edition + `extraRecipients[]`. Updates `recapSentAt`. Audit-logged. |
### Mixed permission (`protectedProcedure` with role guard inside)
| Procedure | Purpose |
| --- | --- |
| `upsertPick` | Single procedure for member-self / team-lead / admin. Input: `{ attendingMemberId, dishId, allergens, allergenOther }`. Guard: caller is (a) the `AttendingMember.userId`, OR (b) team lead of the parent project, OR (c) admin. After `changeCutoffHours` cutoff, only admins pass. Audit-logged on every write with actor role. |
### Member read (`protectedProcedure`)
| Procedure | Purpose |
| --- | --- |
| `getEventForMember` | Public-ish event view: `{ enabled, eventAt, endAt, venue, notes, changeDeadline }` for the dashboard banner. Returns `null` when `enabled=false`. |
| `getTeamPicks` | All picks for the caller's team (resolved via `TeamMember → project`). Returns `[{ attendingMemberId, memberName, dish, allergens, hasPicked }]` for the team-wide-read visibility. |
### Cron endpoints (REST, `CRON_SECRET` guarded)
| Endpoint | Behavior |
| --- | --- |
| `POST /api/cron/lunch-reminders` | Single fire per event: scans enabled `LunchEvent`s with `reminderHoursBeforeDeadline` set and `reminderSentAt` null. If `now ∈ [reminderAt, deadline)`, emails attending members with `pickedAt=null` whose parent `FinalistConfirmation.status === CONFIRMED`, then stamps `reminderSentAt`. Idempotent. |
| `POST /api/cron/lunch-recap` | Single fire per event: scans enabled `LunchEvent`s with `cronEnabled=true`, `recapSentAt` null, and `now >= deadline`. Sends recap to admins + `extraRecipients[]`, stamps `recapSentAt`. Idempotent. |
Both endpoints follow the CLAUDE.md rule "Round notifications never throw — all errors caught and logged" with per-event `try/catch` so one failure does not poison the sweep.
## 5. UI
### Admin: `/admin/logistics → Lunch tab`
Stack of cards on the existing tab content area:
1. **Event config card** — enabled toggle (master switch), `eventAt` + `endAt` date pickers, `venue`, `notes`, `changeCutoffHours`, `reminderHoursBeforeDeadline`, `cronEnabled`, `extraRecipients[]` (chip-input for emails). Same blur-to-commit pattern used by the Edition settings tab.
2. **Dishes card** — list of dishes (name, dietary-tag pills, drag handle for `sortOrder`), inline add row, edit/delete buttons. Empty state: *"Add at least one dish to open picks."*
3. **Manifest card** — table: `Team | Attendee | Type (member/external) | Dish | Allergens | Picked at`. Filters: team dropdown, "Missing picks only" toggle. Header summary chip: *"23/30 picked · 3 vegan · 2 nut-allergic · 1 missing"*. Externals appear inline (team column shows "—" for standalone). Edit-pencil opens a slide-over on any row (admin override).
4. **Externals card** — table of external attendees with add button → dialog (name, email, project (optional), `roleNote`, `dishId`, `allergens`, `allergenOther`). Edits use the same dialog.
5. **Recap actions card** — two buttons: *"Preview recap"* (modal showing email body) and *"Send recap now"* (with the post-deadline "you already sent — resend updated?" confirm); plus *"Download CSV"*. Footer text: *"Last sent: 2026-06-25 14:02. Recipients: 4 admins + 2 extra."*
When `enabled=false`, cards 25 collapse to a single empty state: *"Lunch is disabled — toggle on to configure."*
### Applicant dashboard (`/applicant`) — extend `AttendingMembersCard`
Each attending-member row (already shows visa + flight) gets a new collapsible **Lunch** subsection:
- Dish dropdown (grouped by dietary tag — *"Vegetarian options"*, *"All options"*).
- Allergen checklist (EU 14 inline grid) + "other" textarea.
- "Picked" chip with timestamp once `pickedAt` is set.
Edit affordance:
- **Member viewing own row:** editable until deadline.
- **Team lead viewing teammates' rows:** editable until deadline, with a clear *"Editing on behalf of [Name]"* label.
- **Past deadline:** read-only, with note *"Past change deadline. Contact an admin for changes."*
Above `AttendingMembersCard`, a thin **lunch banner** (only when `enabled=true`) shows event date/time, venue, change-deadline countdown, and a *"Notes from organizers"* expander.
### Project page
Read-only **External attendees for your team** strip — only when externals with `projectId === thisProject` exist, so the team knows who's joining them. No edits — admin-only.
### Removals
- Drop the Lunch line from the "Coming soon" card on `edition-settings-tab.tsx:212-216`.
- Remove `disabled` from the Lunch tab trigger in `logistics/page.tsx:55-58` and wire it to a new `<LunchTab>` component.
## 6. Email + cron details
**Email templates** live inline in `src/lib/email.ts` (the existing single-file pattern); no new infrastructure.
**Reminder.** Subject: *"Pick your lunch dish — deadline in [Xh]"*. Body: greeting, event date/venue/notes, deadline timestamp, button → applicant dashboard. Sent only to attending members with `pickedAt=null` whose confirmation is `CONFIRMED`.
**Recap.** Subject: *"Lunch manifest — [event date]"*. Body: aggregate counts (dishes, dietary tags, allergens), per-attendee table grouped by team (externals as a final group), event metadata. Plain HTML; no CSV attachment in v1 — admins use the in-app *"Download CSV"* button when needed.
**Time formatting.** Same approach as the confirmation page: format with `Intl.DateTimeFormat` in the recipient's email-client locale, plus a hardcoded `"Europe/Monaco"` zone label and the ISO timestamp for unambiguous parsing.
**Audit log entries** (new `eventType` string literals on the existing `DecisionAuditLog.eventType` field — no schema change since the column is free-form):
- `LUNCH_EVENT_UPDATED`
- `LUNCH_DISH_CREATED` / `LUNCH_DISH_UPDATED` / `LUNCH_DISH_DELETED`
- `LUNCH_PICK_UPDATED` (records actor role: `SELF` / `TEAM_LEAD` / `ADMIN`)
- `LUNCH_EXTERNAL_CREATED` / `LUNCH_EXTERNAL_UPDATED` / `LUNCH_EXTERNAL_DELETED`
- `LUNCH_RECAP_SENT` (with recipient count)
## 7. Edge cases & error handling
| Case | Behavior |
| --- | --- |
| `LunchEvent` does not yet exist for the program | `getEvent` lazily creates it with defaults; member/team-lead reads return `null` (banner hidden). |
| Admin disables lunch after picks made | Picks remain in the database; UI hides them; recap still works if re-enabled. |
| `FinalistConfirmation` flips from `CONFIRMED` to `SUPERSEDED` after a pick was made | Pick row stays; manifest filters the team out. If the team is later re-promoted via waitlist, picks are visible again. |
| Dish is deleted | `dishId` becomes `null` on picks/externals; rows show as "not picked"; admins re-pick. Audit logged. |
| `eventAt` is moved | Deadline (`eventAt - changeCutoffHours`) and reminder window recalculate automatically — no manual adjustment needed. |
| `eventAt` is set in the past | Admin sees a UI warning; cron treats deadline as already-past (so a manual send is the only recourse, since `recapSentAt` may already be moot). |
| `changeCutoffHours = 0` | Deadline equals `eventAt`. Allowed. |
| Admin edits a pick after `recapSentAt` is set | UI surfaces a confirm dialog: *"This will not auto-resend the recap. Send updated recap?"* ─ "Yes" calls `sendRecap` with `forceUpdate=true`. Audit logged regardless. |
| Member with no `AttendingMember` row | Cannot edit. UI hides the lunch subsection (no row exists). |
| External with `projectId` that points to a project no longer in the edition | `onDelete: SetNull` on the relation already covers cascades; standalone-display fallback. |
## 8. Testing strategy
Vitest, sequential pool (per CLAUDE.md). Tests grouped by router/service:
**`tests/lunch/lunch-router.test.ts`**
- `getEvent` lazily creates the row on first call.
- `updateEvent` patches an arbitrary subset.
- Dish CRUD (`createDish`, `updateDish`, `deleteDish`, `reorderDishes`) — delete sets `dishId=null` on existing picks.
- External CRUD covers the standalone (`projectId=null`) and team-attached cases.
- `getManifest` filters out non-`CONFIRMED` confirmations and merges externals.
**`tests/lunch/upsert-pick.test.ts`**
- Member edits own row: succeeds before deadline, fails after.
- Team lead edits teammate row: succeeds before deadline, fails after.
- Team lead edits a non-team member's row: fails with `FORBIDDEN`.
- Admin edits any row before/after deadline: succeeds in both cases.
- Audit log records actor role correctly per case.
**`tests/lunch/recap.test.ts`**
- `sendRecap` with `recapSentAt=null` succeeds and stamps the timestamp.
- `sendRecap` with `recapSentAt` set and `forceUpdate=false` throws `PRECONDITION_FAILED`.
- `sendRecap` with `forceUpdate=true` succeeds and re-stamps.
- Recap aggregation is correct (dish counts, dietary-tag counts, allergen counts).
**`tests/lunch/cron.test.ts`**
- `lunch-reminders` is idempotent (second call within window does not double-send).
- `lunch-reminders` skips events with `reminderSentAt` already set.
- `lunch-recap` skips events with `cronEnabled=false`.
- `lunch-recap` skips events with `recapSentAt` already set.
- Per-event try/catch — a failing send for one event does not stop the next from being processed.
**`tests/lunch/auto-create.test.ts`**
- Creating an `AttendingMember` while a `LunchEvent` exists also creates an empty `MemberLunchPick`.
- Creating an `AttendingMember` while no `LunchEvent` exists does not error and does not create a pick.
Build (`npm run build`), typecheck (`npm run typecheck`), and full test suite must be green before commit.
## 9. File-level work surface (informative — drives the implementation plan)
- `prisma/schema.prisma` — add models, enums, back-references; new migration.
- `src/server/routers/lunch.ts` (new) — router as designed.
- `src/server/routers/_app.ts` — mount `lunch` router.
- `src/server/services/lunch-pick-sync.ts` (new) — `ensureLunchPickForAttendingMember` helper called from existing attendee-creation paths.
- `src/server/services/lunch-recap.ts` (new) — manifest aggregation + email body builder, used by `sendRecap` and the recap cron.
- `src/lib/email.ts` — append two new template functions (reminder + recap).
- `src/app/api/cron/lunch-reminders/route.ts` (new).
- `src/app/api/cron/lunch-recap/route.ts` (new).
- `src/app/(admin)/admin/logistics/page.tsx` — un-disable the Lunch tab trigger; mount new tab content.
- `src/components/admin/logistics/lunch-tab.tsx` (new) — orchestrates the five cards.
- `src/components/admin/logistics/lunch-event-config.tsx` (new) — config card.
- `src/components/admin/logistics/lunch-dishes.tsx` (new) — dishes card.
- `src/components/admin/logistics/lunch-manifest.tsx` (new) — manifest card.
- `src/components/admin/logistics/lunch-externals.tsx` (new) — externals card.
- `src/components/admin/logistics/lunch-recap-actions.tsx` (new) — recap actions card.
- `src/components/applicant/attending-members-card.tsx` — extend each row with the lunch subsection.
- `src/components/applicant/lunch-banner.tsx` (new) — the dashboard banner above the attending-members card.
- `src/components/admin/settings/edition-settings-tab.tsx` — drop the Lunch line from the "Coming soon" card.
## 10. Non-goals reminder
- No keyboard shortcuts anywhere — visible UI affordances only (per existing user feedback memory).
- No editable email templates in this PR (PR 7).
- No public token-gated picker.
- No multi-event support.
- No caterer email integration.

View File

@@ -0,0 +1,122 @@
# Mentorship Communications & Welcome/Reminder Email — Design
- **Date:** 2026-06-01
- **Status:** Approved (pending spec review)
- **Author:** Matt + Claude
- **Topic:** Make mentor↔team contact effortless and add a re-sendable, instructional "welcome/reminder" email for mentoring rounds.
## Context
MOPC already has a working mentorship feature:
- **Two-way in-app messaging** exists (`MentorMessage` model; `WorkspaceChat` + `MentorChat` components; `trpc.mentor.sendMessage` / `getMessages` and `trpc.applicant.sendMentorMessage` / `getMentorMessages`). Mentors are auto-notified when applicants write.
- **Contact emails are already visible**: mentors see each team member's email as individual `mailto:` links (`src/app/(mentor)/mentor/projects/[id]/page.tsx`); applicants see their mentor's name+email (`src/app/(applicant)/applicant/mentor/page.tsx`) and teammates' emails (`src/app/(applicant)/applicant/team/page.tsx`).
- **Round-open auto emails already fire**: flipping a `MENTORING` round draft→active sends a coalesced *"you've been assigned to N projects"* email to each mentor (`getMentorBulkAssignmentTemplate` / `sendMentorBulkAssignmentEmail`) and a *"meet your mentors"* intro to each team (`getTeamMentorIntroductionTemplate` / `sendTeamMentorIntroductionEmail`). These are one-time, gated by `MentorAssignment.notificationSentAt` and `MentorAssignment.teamIntroducedAt` (`src/server/services/round-engine.ts`).
Two gaps remain:
1. There is **no single "email all team members"** affordance for mentors — only per-person `mailto:` links.
2. The round-open emails **don't explain how to use the mentorship features**, and there is **no way to re-send** them later as a reminder.
## Goals
- A mentor can email their whole team in one click (opens their mail client, all members in `To:`).
- The round-open assignment emails are **upgraded in place** to include (a) the relevant contact emails and (b) how-to-use-the-mentorship-features instructions.
- An admin can **re-send** that same email on demand (a "welcome/reminder" blast) to all mentors + teams in a mentoring round, with an optional custom note.
- The admin can **preview** the exact email (mentor + team versions) before sending.
## Non-goals
- No new in-app messaging surfaces (the chat already exists).
- No new email-provider infrastructure (reuse `src/lib/email.ts` wrapper, helpers, throttling, `NotificationLog`).
- No mentors-only / teams-only targeting toggle for v1 — the reminder sends to **both** audiences. (Can be added later if needed.)
## Feature 1 — Mentor "Email all team members" button
- **Location:** `src/app/(mentor)/mentor/projects/[id]/page.tsx`, in the existing Team Members card, alongside the per-member `mailto:` links.
- **Behavior:** builds `mailto:<comma-joined emails>?subject=...` with **all active team members in `To:`** (per decision), subject pre-filled `MOPC Mentorship — {project title}`. Clicking opens the mentor's default mail app.
- **Edge cases:** filter out blank/missing emails defensively (schema makes `User.email` required+non-null, but be safe); hide the button when the team has zero emailable members.
- **Scope:** pure client-side; no backend changes.
## Feature 2 — Unified mentorship welcome/reminder email
### Decision: upgrade in place, don't duplicate
Rather than send a second email on round-open, the **existing** two templates are enhanced so they carry the instructions + contact emails. The same template code is reused by both trigger paths below. One email per audience; one source of truth.
### Content — Mentor version (coalesced per mentor, across their projects in the round)
- Greeting by mentor name.
- Optional custom note (rendered in an info box near the top) — only present on the manual reminder path.
- For **each** assigned project: project title (linked) + the **team members listed with name + email**.
- "How to mentor on MOPC" instructions block: where the workspace chat lives, file sharing, the mentor dashboard.
- CTA → Mentor Dashboard.
### Content — Team version (per project)
- Greeting by recipient name.
- Optional custom note (info box) — manual path only.
- The assigned **mentor(s) listed with name + email**.
- The team's **own members listed with email** (per decision: include teammates too).
- "How to work with your mentor" instructions block: where the in-app chat is, how to reach the mentor, what to expect.
- CTA → mentoring page.
Both reuse `getEmailWrapper()` and existing helpers (`sectionTitle`, `paragraph`, `ctaButton`, `infoBox`, `escapeHtml`) for consistent branding.
### Trigger path A — auto on round-open (existing flow, upgraded content)
- `src/server/services/round-engine.ts` draft→active flow keeps its one-time semantics (`notificationSentAt` / `teamIntroducedAt` gating) and coalescing.
- It now passes the additional data the upgraded templates need: team-member name+email for the mentor email, and mentor name+email + teammate emails for the team email.
- No custom note on this path.
### Trigger path B — manual reminder button (admin, on demand)
- New `adminProcedure`: `mentor.sendMentorshipWelcome({ roundId, customNote?: string })`.
- Resolves **all current** active assignments for the round (`droppedAt: null`) → groups by mentor → sends mentor emails; resolves all projects with assignments → sends team emails to all members.
- **Ignores** `notificationSentAt` / `teamIntroducedAt` (deliberate re-send). Does **not** mutate those flags.
- Throttled + fire-and-forget like existing bulk sends; writes `NotificationLog` rows + a `DecisionAuditLog`/audit entry.
- Returns counts: `{ mentorCount, teamMemberCount, teamCount }` for the success toast.
### Preview
- New query: `mentor.previewMentorshipWelcome({ roundId, customNote?: string })``{ mentor: { subject, html }, team: { subject, html } }`.
- Calls the **same** template functions used by the real send.
- Picks a representative recipient: first mentor with assignments + first project/team in the round. If the round has none yet, returns clearly-labeled sample-data output so the layout is still previewable.
- Rendered in the send dialog inside a sandboxed `<iframe srcDoc={html}>` (isolates email CSS from the app), with **Mentor / Team** sub-tabs. The custom-note textarea updates the preview live (debounced).
### Admin UI
- New component `src/components/admin/round/send-mentorship-welcome-button.tsx`:
- Lives in the round detail page's **Notifications** section (`src/app/(admin)/admin/rounds/[roundId]/page.tsx`, near `NotifyAdvancedButton` / `NotifyRejectedButton` / `BulkInviteButton`), rendered **only when the round is `MENTORING`**.
- Opens a dialog: recipient summary ("N mentors · M team members across K teams"), optional custom-note textarea, live Preview (Mentor/Team tabs), and a Send button with confirmation.
## Files touched
| File | Change |
|---|---|
| `src/app/(mentor)/mentor/projects/[id]/page.tsx` | Add "Email all team members" button (mailto, all in To:) |
| `src/lib/email.ts` | Enhance `getMentorBulkAssignmentTemplate` + `getTeamMentorIntroductionTemplate` (contacts, instructions, optional `customNote`); update `sendMentorBulkAssignmentEmail` / `sendTeamMentorIntroductionEmail` signatures + all call sites |
| `src/server/services/round-engine.ts` | Pass team-member/mentor emails into upgraded templates on round-open |
| `src/server/routers/mentor.ts` | New `sendMentorshipWelcome` (adminProcedure) + `previewMentorshipWelcome` (adminProcedure query) |
| `src/components/admin/round/send-mentorship-welcome-button.tsx` (new) | Dialog: counts, custom note, live iframe preview, send |
| `src/app/(admin)/admin/rounds/[roundId]/page.tsx` | Wire the button into the Notifications section, gated to mentoring rounds |
## Implementation ordering note
Build the templates first and render both to standalone `.html` files (and/or screenshots) for copy review **before** wiring the send path — gives an early visual check with zero throwaway work.
## Testing
- **Template unit tests** (`src/lib/email.ts` fns return `{ subject, html, text }`, easy to assert): mentor email contains each team member's email + instructions block; team email contains mentor email(s) + teammate emails + instructions; custom note appears when passed, absent when not.
- **tRPC test** for `sendMentorshipWelcome` on a seeded mentoring round: correct recipient resolution and returned counts; does not flip the one-time flags.
- **tRPC test** for `previewMentorshipWelcome`: returns non-empty mentor + team HTML for a seeded round; sample-data fallback for an empty round.
## Decisions (resolved during brainstorming)
1. Upgrade existing intro emails in place (single source of truth), reused by both auto-open and the manual reminder; fallback would have been a standalone manual-only blast.
2. Tailored content per audience (mentor vs team), **with contact emails embedded** in the relevant spot.
3. Manual reminder: fixed branded template **+ optional custom note**.
4. "Email all" button: **all members in `To:`**.
5. Team email includes **both** the mentor's email and teammates' emails.
6. Manual reminder sends to **both** audiences (no per-audience toggle in v1).
7. Preview via an in-app button (live, real-data, iframe) rather than pasted static HTML.

View File

@@ -0,0 +1,108 @@
# Multiple Hotels + Room Assignments — Design Spec
**Date:** 2026-06-04
**Status:** Approved (design), pending implementation
**Context:** The grand-finale logistics feature currently supports exactly **one hotel per edition** (`Hotel.programId @unique`), with no way to say who stays where. Admins need **multiple hotels** and the ability to assign each confirmed attendee to a hotel — usually a whole team together, but with per-member flexibility — including **room number and check-in/out dates**.
> Separately resolved (not part of this spec): the finalist attendee cap is configurable (Admin → Settings → Edition) and was set to 4 in production; because every confirmation path reads `Program.defaultAttendeeCap` live, this applied retroactively to already-sent confirmation links.
## Goals
- Many hotels per edition (CRUD).
- Assign each **confirmed attendee** to a hotel, with **per-member granularity** and a **"assign whole team"** shortcut.
- Track **room number + check-in/check-out** per attendee.
- Surface each attendee's assignment in their team-facing "My Logistics" view and the travel-confirmed email.
## Non-goals (YAGNI)
- Room-sharing modeling (two attendees can simply share a `roomNumber` string — no explicit room entity).
- Hotel booking/availability/pricing.
- External (non-portal) lunch guests are unrelated and untouched.
## Data model
Mirror the existing `FlightDetail` pattern (a 1:1 detail record per `AttendingMember`).
**`Hotel`** — relax the uniqueness so an edition can have many:
```prisma
model Hotel {
id String @id @default(cuid())
programId String // was @unique — now many hotels per edition
name String
address String? @db.Text
link String?
notes String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
program Program @relation(fields: [programId], references: [id], onDelete: Cascade)
stays HotelStay[]
@@index([programId])
}
```
**`HotelStay`** (new, 1:1 with `AttendingMember`):
```prisma
model HotelStay {
id String @id @default(cuid())
attendingMemberId String @unique
hotelId String
roomNumber String?
checkInAt DateTime?
checkOutAt DateTime?
notes String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attendingMember AttendingMember @relation(fields: [attendingMemberId], references: [id], onDelete: Cascade)
hotel Hotel @relation(fields: [hotelId], references: [id], onDelete: Restrict)
@@index([hotelId])
}
```
- `AttendingMember` gains `hotelStay HotelStay?` (back-relation).
- `onDelete: Restrict` on `hotel` means a hotel with occupants can't be deleted — the router pre-checks and returns a friendly "reassign N occupants first" error.
- Assigning = upsert a `HotelStay`; unassigning = delete it.
## Server (logistics router, `src/server/routers/logistics.ts`)
Replace the 1:1 hotel procedures with a list-based set; add rooming/assignment procedures. All `adminProcedure`, all audited (mirror existing `HOTEL_UPSERT` etc.).
| Procedure | Input | Behavior |
|---|---|---|
| `listHotels` | `{ programId }` | All hotels for the edition + `_count` of stays (occupancy). |
| `createHotel` | `{ programId, name, address?, link?, notes? }` | Create. |
| `updateHotel` | `{ id, name, address?, link?, notes? }` | Update. |
| `deleteHotel` | `{ id }` | Pre-check stays: if >0 → `BAD_REQUEST` "Reassign N occupants first." Else delete. |
| `listRooming` | `{ programId }` | One row per **CONFIRMED** attendee: team (project title), member (user), and their `hotelStay` (hotelId, roomNumber, checkInAt, checkOutAt) or null. Sorted by team then member. |
| `assignStay` | `{ attendingMemberId, hotelId, roomNumber?, checkInAt?, checkOutAt?, notes? }` | Upsert the attendee's `HotelStay`. |
| `assignTeamToHotel` | `{ confirmationId, hotelId, checkInAt?, checkOutAt? }` | For every `AttendingMember` of the confirmation, upsert `HotelStay` with `hotelId` (and optional shared dates); preserve existing `roomNumber`. The "assign whole team" shortcut. |
| `unassignStay` | `{ attendingMemberId }` | Delete the `HotelStay` (no-op safe). |
**Applicant** (`applicant.getMyLogistics`): replace the program-hotel lookup with the caller's `AttendingMember.hotelStay` → return `hotel: { name, address, link, notes } | null` plus `room: { roomNumber, checkInAt, checkOutAt } | null`.
**Email** (`logistics.setFlightStatus` → CONFIRMED, in the `TRAVEL_CONFIRMED` notification metadata): include the attendee's **assigned** hotel + room (from their `HotelStay`) instead of the edition's single hotel. The `getTravelConfirmedTemplate` already accepts a `hotel` object — extend its metadata to carry room/dates.
## Admin UI (`src/components/admin/logistics/hotels-tab.tsx`, reworked)
Two sections:
1. **Hotels** — a list of the edition's hotels; add/edit/delete each (dialog), with an occupancy badge per hotel. Delete shows the "reassign first" error inline.
2. **Rooming** — a table driven by `listRooming`, grouped by team: columns `Member | Hotel (Select) | Room # | Check-in | Check-out`. Each team header has an **"Assign whole team to…"** Select (calls `assignTeamToHotel`). Per-row edits call `assignStay` (debounced on blur for room/dates; immediate on hotel change); clearing the hotel calls `unassignStay`. A **Download CSV** button (mirror the travel/visa export). Empty state when no confirmed attendees yet. shadcn components, visible affordances only (no keyboard shortcuts).
## Team-facing (`src/components/applicant/my-logistics-card.tsx`)
The Hotel section shows the attendee's **assigned** hotel (name/address/link) + **Room** (number) + **check-in/check-out** (Monaco-time labels), or "Hotel details coming soon" when unassigned.
## Migration
- Drop `Hotel_programId_key` unique constraint; add `Hotel_programId_idx`.
- Create `HotelStay` table + FKs (`attendingMemberId` unique → AttendingMember CASCADE; `hotelId` → Hotel RESTRICT) + `HotelStay_hotelId_idx`.
- No data backfill: no `HotelStay` rows exist yet; any existing single `Hotel` row simply becomes the first of many.
- Additive/safe for prod; applied via `prisma migrate deploy` on container start.
## Testing
- Hotel CRUD: create multiple hotels for one program; `deleteHotel` rejected when occupied, succeeds when empty.
- `assignStay` upsert (create then update room/dates); `assignTeamToHotel` assigns all of a team's attendees; `unassignStay` removes.
- `listRooming` returns confirmed attendees with their stay (and null for unassigned).
- `getMyLogistics` returns the assigned hotel + room for the caller; null when unassigned.
- Migration applies cleanly; existing finalist/logistics tests stay green (callers updated from `getHotel`/`upsertHotel`).
## Affected call sites to update (from 1:1 → multi)
- `hotels-tab.tsx` (reworked), `getMyLogistics` (applicant.ts), `setFlightStatus` travel email (logistics.ts), and any other `getHotel`/`upsertHotel` references — grep to confirm before removing the old procedures.

View File

@@ -0,0 +1,199 @@
# External Attendee Dish Self-Selection — Design Spec
**Date:** 2026-06-05
**Status:** Approved (design), pending implementation plan
**Author:** Matt + Claude
## Problem
External lunch attendees (e.g. partners, VIPs added by an admin in the logistics
screen) currently have **no way to choose their own dish**. The admin is expected
to set each external's `dishId` inline. There is no email and no self-service page.
This surfaced when an admin (Marine Jacq-Pietri, `marine@monaco-impact.org`) added
herself as an external attendee expecting to receive an email to pick a dish, and
never got one — because the flow does not exist. Verified in prod 2026-06-05:
the `ExternalAttendee` row exists with `dishId = null`, and no email path targets
externals.
### Current behaviour (verified in code + prod)
- `lunch.createExternal` / `lunch.updateExternal` write the row and send **no email**.
- The only "Pick your lunch dish" email (`sendLunchReminderEmail`) is driven by
`selectUnpickedAttendees`, which queries **`AttendingMember` rows tied to a
CONFIRMED `FinalistConfirmation`** — finalist team members only. Externals are
never in that set.
- `sendLunchRecapEmail` goes to admins + `extraRecipients` only (a manifest, not a picker).
- Externals' dishes are meant to be set by the admin inline via `dishId`.
## Goal
External attendees with an email on file receive a dish-selection email containing
a tokenized link to a dedicated, no-login page where they choose a dish, declare
allergens, and add allergen notes — mirroring the finalist team-member picker.
## Design decisions (locked)
1. **Email trigger:** auto-send on add (when the external has an email) **plus** a
per-row "Resend invite" button in the logistics screen.
2. **Reminders:** unpicked externals are included in both the reminder cron and the
manual "Send reminders" action.
3. **Page fields:** dish + allergens + allergen notes (mirror the member picker).
4. **Dish write precedence:** last-write-wins. Both the inline admin `dishId` field
and the self-service page can write the dish; the admin can always override.
## Reference pattern
This feature mirrors the existing **finalist confirmation flow**:
- `src/lib/finalist-token.ts` — HMAC-signed token (`{ confirmationId, exp }`) via
`NEXTAUTH_SECRET`.
- `src/app/(public)/finalist/confirm/[token]/page.tsx` — public, tokenized, no-login page.
- `finalist.getByToken` / `finalist.confirm` / `finalist.decline``publicProcedure`s.
We replicate this shape for externals.
## Architecture
### 1. Data model
`prisma/schema.prisma``ExternalAttendee` gains one nullable field:
```prisma
inviteSentAt DateTime? // when the dish-selection email was last sent
```
- Drives an "invited ✓" indicator in the admin UI.
- Does **not** gate resends or reminders (those are intentionally repeatable).
- Nullable, so the migration is additive with no backfill.
**No `token` column.** The link is a stateless HMAC-signed token; the external is
loaded by the `externalId` embedded in the verified payload. Trade-off accepted:
individual links can't be revoked without rotating `NEXTAUTH_SECRET` — acceptable
for low-stakes dish picking. (This is the one intentional divergence from the
finalist flow, which stores a DB token for supersede/rotation scenarios that
externals don't have.)
Migration: single additive column. Apply in prod via `prisma migrate deploy`
(runs automatically on container start per the entrypoint). **Do not** run
`migrate dev` against the drifted dev DB — create the migration SQL and use
`db execute` + `migrate resolve` if needed locally.
### 2. Token helper — `src/lib/external-lunch-token.ts`
Mirror `finalist-token.ts`:
```ts
export type ExternalLunchTokenPayload = { externalId: string; exp: number }
export function signExternalLunchToken(payload): string
export function verifyExternalLunchToken(token): ExternalLunchTokenPayload // throws on bad sig / expired
```
- HMAC-SHA256 over base64url payload, `timingSafeEqual` comparison.
- `exp` = `eventAt + 24h` when `eventAt` is set, else `now + 30d`. Generous so the
link outlives the change deadline (the deadline is enforced separately at write time).
### 3. tRPC — `src/server/routers/lunch.ts`
- **`getExternalByToken`** (`publicProcedure`, input `{ token }`):
verify token → load external (+ its `LunchEvent`, ordered `dishes`, current
`dish`/`allergens`/`allergenOther`) → return payload incl. computed
`changeDeadline = eventAt changeCutoffHours`. Throws map to the page's friendly
error states (`expired` / `signature` / not found).
- **`setExternalPick`** (`publicProcedure`, input
`{ token, dishId: string | null, allergens, allergenOther }`):
verify token → if `eventAt` set and `now > changeDeadline``PRECONDITION_FAILED`
→ update the external's `dishId` / `allergens` / `allergenOther`. No audit row
(no authenticated user on a public pick).
- **`sendExternalInvite`** (`adminProcedure`, input `{ externalId }`):
load external (must have an email, else `PRECONDITION_FAILED`) → sign token →
`sendExternalDishInviteEmail(...)` → stamp `inviteSentAt = now` → audit
`LUNCH_EXTERNAL_INVITE_SENT`. Returns the updated row.
- **`createExternal`** (existing, modified): after insert, if `input.email` present,
fire-and-forget send the invite (sign token, send email, stamp `inviteSentAt`)
wrapped in `try/catch`**never throws** (per the "round notifications never
throw" project constraint). A failed send leaves `inviteSentAt = null` so the
admin can resend.
### 4. Email — `src/lib/email.ts`
```ts
export async function sendExternalDishInviteEmail(opts: {
to: string
name: string
eventAt: Date | null
venue: string | null
notes: string | null
changeDeadline: Date | null
pickUrl: string
}): Promise<void>
```
- Uses the existing branded wrapper.
- Subject: `Choose your lunch dish — MOPC grand finale`.
- Body: greeting, event date (Europe/Monaco), venue, optional notes, deadline, CTA
button → `pickUrl`.
- One template serves both the initial invite and reminders.
### 5. Reminders — extend existing flow
- **`src/server/services/lunch-reminders.ts`**: add
`selectUnpickedExternals(prisma, event)` → externals where `email` is set and
`dishId IS NULL` for the event.
- **`src/app/api/cron/lunch-reminders/route.ts`** and **`lunch.sendReminders`**:
after the existing `AttendingMember` loop, also loop unpicked externals and send
`sendExternalDishInviteEmail` with a freshly signed token URL. External links go
to `/lunch/pick/<token>` (not `/applicant`). Per-send errors are caught and
logged, consistent with the member loop.
### 6. Public page — `src/app/(public)/lunch/pick/[token]/page.tsx`
Mirror `(public)/finalist/confirm/[token]/page.tsx`:
- `'use client'`, reads `token` from params, queries `lunch.getExternalByToken`.
- States: loading skeleton; invalid/expired/not-found friendly cards (reuse the
`FriendlyError` pattern with `info@monaco-opc.com` fallback).
- Header card: event date, venue, notes, deadline countdown (reuse `CountdownLabel`).
- Form: dish radio list with dietary-tag badges, allergen checkboxes, allergen-notes
textarea. Submit → `lunch.setExternalPick`.
- Success state: "Your dish is saved", editable until the deadline.
- Past deadline: read-only with "contact an admin" message.
### 7. Admin UI — logistics externals table
- Per-row status chip: `no email` / `Invited` / `Picked`.
- Per-row **Resend invite** button → `lunch.sendExternalInvite` (disabled when no email).
- The inline `dishId` editor stays (admin override path).
### Manifest / recap
No change. `lunch-recap.ts` already includes externals, so self-service picks flow
into the manifest, CSV export, and recap email automatically.
## Edge cases
- **No email on external:** auto-send skipped; resend button disabled; reminders skip.
- **Tampered / expired link:** friendly error card; no data leak.
- **Pick after deadline:** `PRECONDITION_FAILED`; page shows read-only state.
- **Admin and external both set a dish:** last-write-wins (intended).
- **Email added later via `updateExternal`:** no auto-send on update; admin uses the
resend button (keeps `updateExternal` side-effect-free).
## Testing
- Unit: token sign/verify roundtrip + tamper + expiry rejection (`external-lunch-token`).
- Unit: `selectUnpickedExternals` returns only emailed + unpicked externals.
- Integration: `getExternalByToken` happy path; bad/expired token errors.
- Integration: `setExternalPick` happy path; deadline rejection.
- Integration: `createExternal` with email stamps `inviteSentAt` (mocked email send);
without email leaves it null.
## Out of scope
- External attendee decline / RSVP (this is dish-only).
- Reworking the member picker.
- Audience-window / live-voting rework (tracked separately).
```

View File

@@ -0,0 +1,93 @@
# Grand Final: judge-visible document curation + optional revised uploads
**Date:** 2026-06-09
**Status:** Approved (Matt, this session)
**Builds on:** `2026-06-09-grand-final-documents-design.md` and the same-day pivot (commits `f8f2d77`, `8a4184d`)
## Problem
Feedback from the other program admin:
> Jury actually need to see BP + Exec summary + 1min video — the ones they uploaded already. And candidates should be able to upload their PDF pres + video — optional, as some sent it another way.
Two gaps against what is deployed:
1. **Judges see too much.** `listFinalistDocumentsForReview` returns *every* file each finalist team ever submitted (57 per team on prod: Pitch Deck, Intro Video, Executive Summary, Business Plan, Promotional Video, plus any Grand Final uploads). The admin wants judges to see a curated subset (BP + exec summary + 1-min video). There is no way to choose which prior documents are surfaced.
2. **"Optional uploads" mode renders wrong.** The three modes the admin wants are: no new uploads (toggle OFF — works), mandatory uploads (toggle ON + slots required — works), and optional uploads (toggle ON + slots marked not-required). In the all-optional case, `FinalDocumentStatus.allRequiredUploaded` is hardcoded `false` when zero slots are required, so the finalist banner/panel never reach a settled state and the copy implies the docs are mandatory.
Prod facts (verified 2026-06-09 via read-only query): 9 finalist teams, 48 prior files + 3 Grand Final uploads. Every team has all 5 prior doc types. The Business Plan and the 1-minute promo video live under *two different* `FileRequirement` rows depending on the team's path (Semi-Finals Document Submission for 8 teams, Spotlight on Africa Submission Round for 1 team — Blue Fields Company).
## Part 1 — Admin curation of judge-visible documents
### Storage
New optional key on the LIVE_FINAL round's `configJson`:
```ts
reviewVisibleRequirementIds?: string[] // FileRequirement ids from prior rounds
```
Semantics:
- **absent / null** → show all prior files (current behavior; safe default, no migration needed)
- **non-empty array** → show only prior files whose `requirementId` is in the list
- **empty array** → hide all prior files (only Grand Final uploads remain visible)
- **Grand Final round uploads are always shown**, regardless of the selection — they are what the team explicitly submitted for the finale
- Prior files with no `requirementId` (fileType-only) are excluded whenever a selection is active. (All 48 prod files have a requirement, so nothing is lost in practice.)
### Service (`src/server/services/final-documents.ts`)
`listFinalistDocumentsForReview` adds `requirementId` to its file select and applies the filter above using the finale round's `configJson`. No signature change; `ReviewPayload` unchanged.
New helper to power the admin picker: list the distinct prior-round requirement slots referenced by the finalist teams' files — `{ requirementId, name, roundName, fileCount }`, ordered by round sort then name. Derived from the same file query, so the picker only offers slots that actually have files.
### tRPC (`src/server/routers/finalist.ts`, adminProcedure)
- `getReviewDocSettings``{ options: Slot[], selectedIds: string[] | null }` (null = "all" mode)
- `setReviewVisibleRequirements({ requirementIds: string[] | null })` → writes/clears the configJson key (null clears back to "show all"). Audited like `setRevisedUploadSetting`.
### Admin UI
New card "Documents shown to judges" placed next to the existing revised-uploads toggle (`src/components/admin/grand-finale/final-docs-uploads-toggle.tsx`, rendered on the LIVE_FINAL round admin page `src/app/(admin)/admin/rounds/[roundId]/page.tsx`):
- A "Show all submitted documents" master state (the default), and beneath it a checkbox per slot labeled `"<requirement name> — <round name>"` with the file count (e.g. "Business Plan — Semi-Finals Document Submission (8 files)").
- Unchecking the master switches to curated mode with all boxes ticked; the admin then unticks what judges shouldn't see. Re-checking the master clears the selection (back to null/"all").
- Copy notes that Grand Final uploads are always visible to judges.
For the admin's stated goal, they'd switch to curated mode and leave 5 boxes ticked: Executive Summary (Intake), Business Plan (Semi-Finals + Spotlight), Promotional Video (Semi-Finals) and 1 Minute Promotional Video (Spotlight) — judges then see exactly BP + exec summary + 1-min video per team, plus any finale uploads.
## Part 2 — All-optional upload mode fix
`FinalDocumentStatus` (in `final-documents.ts`) gains:
```ts
hasRequired: boolean // any slot with isRequired
allUploaded: boolean // requirements.length > 0 && every slot has a file, required or not
```
`allRequiredUploaded` keeps its current semantics (meaningful only when `hasRequired`). Edge case: if the toggle is ON but no slots are defined at all (`requirements.length === 0`), the banner and panel render nothing — no vacuous "(0 of 0)" complete state.
UI changes:
- **Banner** (`src/components/applicant/final-documents-banner.tsx`): when `hasRequired` is false — title "Upload updated Grand Final documents (optional)", same neutral blue styling, keep per-doc checklist/count/deadline/upload button; green settled state ("Grand Final documents uploaded") only when `allUploaded`.
- **Panel** (`src/components/applicant/final-documents-panel.tsx`, team + mentor variants): "Submitted" badge driven by `hasRequired ? allRequiredUploaded : allUploaded`; description gains "(optional)" when nothing is required.
Reminders need **no change** — verified: the cron and the untargeted manual blast already skip teams with no missing *required* docs, so all-optional mode never nags; an explicitly targeted manual reminder still sends (intentional admin override).
## Out of scope (admin actions in existing UI, not code)
- Flipping `allowFinalistRevisedUploads` ON
- Creating/adjusting the finale upload slots (PDF presentation + 1-min video, "Required" off) in the round's file-requirements editor
- Ticking the curation checkboxes
- Populating the Finals Jury group (still open from the previous ship)
## Testing
Vitest service tests (extend `tests/` final-documents coverage):
- Curation: null selection → all files; selection → only matching prior files + finale uploads always; empty array → finale uploads only; file without requirementId excluded under a selection.
- Picker helper returns distinct slots with correct counts.
- `setReviewVisibleRequirements` round-trips null/array through configJson without clobbering other keys (`allowFinalistRevisedUploads`).
- Status: `hasRequired`/`allUploaded` across mixed, all-optional (0 required), and fully-uploaded fixtures.
## Risks
- **configJson clobbering:** both toggles write the same JSON column — read-modify-write must preserve sibling keys (existing `setRevisedUploadSetting` pattern already does this; reuse it).
- **Stale selection:** if a selected requirement is later deleted, its files simply stop matching; "all" fallback never breaks. No cleanup needed.

View File

@@ -0,0 +1,156 @@
# Grand-Final Documents — upload visibility, mentor surfacing, judge review, notifications
**Date:** 2026-06-09
**Status:** Design — pending review
**Edition:** MOPC 2026 (program "Monaco Ocean Protection Challenge", competition `MOPC 2026`)
## Problem
Nine finalist teams must submit two final deliverables ahead of the Grand Final — a **final PDF presentation** and a **~1-minute video** — and the upcoming Grand-Final judges need to review those documents. Today there is no discoverable upload prompt, no consolidated judge review surface, and no notifications driving teams to upload.
## Current state (verified against prod, 2026-06-09)
The data layer already exists and is correctly set up:
- **"Grand Final" (LIVE_FINAL) round is `ROUND_ACTIVE`** with `windowCloseAt = 2026-06-11 21:00 UTC` and the empty **"Finals Jury"** group attached (`juryGroupId` set, **0 members**).
- **Two `FileRequirement` rows already exist on the Grand Final round** (legacy per-round system): **"PDF presentation support"** (`application/pdf`) and **"1 minute video"** (`video/*`). Both currently `required = false`, `maxSizeMB = null`, **0 files uploaded**. This set is being expanded to the confirmed 4-document set below.
- **All 9 finalist teams are correctly enrolled**: each has a `ProjectRoundState` in both the (closed) Mentoring round and the (active) Grand Final round, and all 9 have `FinalistConfirmation.status = CONFIRMED`. No mismatches (confirmed↔enrolled↔in-mentor all aligned). All 9 share one mentor, **Camille Lopez**. Attendee counts 14 (program `defaultAttendeeCap = 4`).
- Auto-enroll (confirmed + in mentor round → Grand Final round) is working via `finalist.enrollFinalists`; the **admin override already exists** (`finalist.adminConfirm` to mark attending without a token; `finalist.unenroll` to remove) in the `/admin/logistics` **Confirmations tab** + attendance dialog.
### What this means
The **upload already works today**: `/applicant/documents` renders an upload section for every round in `openRounds`, where `openRounds` = program rounds that are `ROUND_ACTIVE` **and** the project is a member of (`applicant.getMyDashboard`). The Grand Final round qualifies, so all 9 teams can upload the PDF + video right now. The upload procedure (`applicant.getUploadUrl`) permits any team member to upload against a requirement as long as the round is `ROUND_ACTIVE` (it is). The `windowCloseAt` deadline is **advisory only** (display, not blocking).
The gaps are therefore: **discoverability** (no banner/notification), **judge review** (no consolidated surface; jury can only see files for projects they are individually assigned to, and the Finals Jury group is empty), and **mentor-section surfacing** (the final documents never appear in the mentor area).
## Goals
1. Make the existing finalist upload **discoverable** via a dashboard banner and notifications.
2. Give the upcoming Grand-Final judges a **read-only review page** of all finalists' documents.
3. Surface the final documents (and a pre-deadline cue) inside **the mentor section**, on both the team's and the mentor's views.
4. Add **email + in-app notifications**, triggered **automatically** (pre-deadline reminder cron) and **manually** (admin blast).
## Document set (confirmed)
The Grand Final round's `FileRequirement` rows are reconfigured to **four required documents**, identical for both categories (STARTUP and BUSINESS_CONCEPT) — the per-round `FileRequirement` model already applies one set to all teams in the round:
1. **Final Presentation**`application/pdf` (rename of the existing "PDF presentation support" row)
2. **Final Business Plan**`application/pdf` (new)
3. **1-minute Video**`video/*` (existing "1 minute video" row)
4. **Executive Summary**`application/pdf` (new)
All four `required = true`. PDF-only for the three document slots (no Word). This is an additive/safe prod data change (0 files currently uploaded). If per-category document sets are ever needed, that is out of scope here (the per-round model does not support it without extra work).
## Non-goals (YAGNI)
- Admin approve / needs-changes review workflow on documents.
- Migrating to the heavier `SubmissionWindow` system (the legacy `FileRequirement` anchor is already set up and proven).
- A mentor-milestone tracker UI (`MentorMilestone`/`MentorMilestoneCompletion` models exist but have no UI; "last steps of the mentor round" is treated as descriptive framing, surfaced as a read-only Final Documents panel, not a milestone system).
- Comments/threads on the judge review page.
- New admin enrollment/override controls (`adminConfirm` + `unenroll` already exist; we only ensure they are reachable from the finale round overview).
## Architecture decision
Build thin additions on the **existing legacy `FileRequirement` → `ProjectFile` anchor** that is already configured on the Grand Final round. Reuse:
- Upload mechanics (`applicant.getUploadUrl` / `saveFileMetadata`, presigned MinIO PUT, `RequirementUploadList`).
- File preview/download (`FilePreview` / `file-viewer`, `file.getDownloadUrl`).
- The notification pipeline (`createNotification`, `notifyProjectTeam`/`notifyProjectMentors`, `NotificationEmailSetting`, `NOTIFICATION_EMAIL_TEMPLATES`, `sendStyledNotificationEmail`) and the reminder-cron pattern (`sendDueConfirmationReminders`).
**The deadline everywhere** (banner, mentor cue, reminder cron) is the Grand Final round's single `windowCloseAt` field, edited by admins in round settings. All deadline displays use **browser-local time + zone label** (`Intl.DateTimeFormat`), never UTC/fixed Monaco time, per the locked grand-finale timezone rule. Deadline behavior is **soft/advisory** — uploads stay open while the round is active; past the date, files are flagged "late" in the UI but still accepted.
## Shared service: `src/server/services/final-documents.ts`
A new service centralizes the logic, wrapped by thin tRPC procedures:
- `getFinalDocumentStatusForProject(prisma, projectId)``{ roundId, roundName, deadline, deadlinePassed, requirements: [{ id, name, acceptedMimeTypes, uploaded, file? }], allRequiredUploaded }` or `null` when the project is not a CONFIRMED finalist in an active LIVE_FINAL round. The single source of truth for the banner, the mentor panels, and reminder targeting.
- `listFinalistDocumentsForReview(prisma, programId)``{ round: { name, deadline }, totalCount, submittedCount, teams: [{ projectId, teamName, category, confirmStatus, documents: [{ requirementId, requirementName, file? }] }] }`. File metadata only; presigned URLs are fetched per-file on demand by the client via existing `file.getDownloadUrl`.
- `sendDueFinalDocReminders(prisma)` → cron entry. Targets CONFIRMED finalists in the active LIVE_FINAL round with at least one required document missing, whose `finalDocsReminderSentAt` is null and whose deadline is within the reminder window; creates `GRAND_FINAL_DOCS_REMINDER` notifications and stamps `finalDocsReminderSentAt`. Best-effort per row.
- `sendManualFinalDocReminders(prisma, { programId, projectIds?, actorId })` → admin blast. For the given projects (default: all CONFIRMED finalists with missing required docs), create `GRAND_FINAL_DOCS_REMINDER` notifications regardless of `finalDocsReminderSentAt`. Returns `{ sent }`.
## Components
### 1. Finalist upload banner (applicant dashboard)
- New auto-hiding banner component (pattern of `LunchBanner`/`MyLogisticsCard`: returns `null` when not applicable) on `src/app/(applicant)/applicant/page.tsx`.
- Backed by a new query **`applicant.getFinalDocumentStatus`** (wraps `getFinalDocumentStatusForProject` for the caller's project).
- Shows: heading ("Upload your Grand Final documents"), each required document with a ✓ / empty state (e.g. "2 of 4 uploaded"), deadline in browser-local time + zone, and a CTA button → `/applicant/documents`. Collapses to a "✓ Submitted" confirmation once all required documents are uploaded. Non-dismissible while incomplete.
### 2. Mentor-section "Final Documents" panel (team + mentor)
A new read-only `FinalDocumentsPanel` component rendered on **both** mentor surfaces:
- **Team view** — `src/app/(applicant)/applicant/mentor/page.tsx` (adds a panel below the existing mentor cards / chat / workspace-files). Uses `applicant.getFinalDocumentStatus`.
- **Mentor view** — `src/app/(mentor)/mentor/workspace/[projectId]/page.tsx` (adds a "Final Documents" section or tab for the viewed project). Uses a new **`mentor.getProjectFinalDocuments`** procedure (mentor/team access check) wrapping `getFinalDocumentStatusForProject`.
Behavior: before upload + as the deadline nears, a **visual cue** ("Final grand-final documents due [date] — upload now", with an upload CTA on the team view); after upload, the PDF + video appear as the team's read-only "final documents" (inline preview / video player / download), visible to both the team and their mentor. Same underlying `ProjectFile`s — no duplicate storage.
### 3. Judge review page (thin dedicated page, reusing existing components)
**Why dedicated rather than baking into the existing per-project jury page** (verified in prod): the finale has **0 `Assignment` rows**, the "Finals Jury" group has **0 members**, and no `LiveVotingSession` exists. The existing jury flow is assignment-gated — the round page lists `roundAssignment.getMyAssignments` (empty for the finale) and `file.listByProject` 403s any juror without an `Assignment` to the project. The finale runs on a **group + live-session** model, not per-project assignments. Baking in would require either fabricating an assignment per judge × finalist or rewiring the assignment-based access path — more work and risk, and a worse UX (one project at a time vs. all finalists at once). So a dedicated page is the better fit *because* the existing page's access model does not apply to the finale.
It stays thin by **reusing existing components** — the same `MultiWindowDocViewer` / `FilePreview` / `<video>` / `file.getDownloadUrl` used on the per-project page — laid out as a consolidated finale list. Not a reinvented viewer.
- New read-only page (e.g. `src/app/(jury)/jury/finals-documents/page.tsx`) listing all finalist teams grouped by category, each with its four documents (3 PDFs + video) via the reused viewer/preview components plus download. Missing documents show "Not yet uploaded". Header shows the deadline and "X of N submitted".
- Backed by a new **`finalist.listReviewDocuments`** procedure (wraps `listFinalistDocumentsForReview`). Authorization: **SUPER_ADMIN / PROGRAM_ADMIN, OR a `JuryGroupMember` of the active LIVE_FINAL round's jury group**, via a new `assertFinalsReviewAccess(ctx)` helper. Unauthorized → access-denied state.
- Entry points: a jury sidebar link ("Finalist Documents") shown when an active LIVE_FINAL round exists, and a "Review finalist documents" link on the admin Grand Final round overview.
- **Implementation note:** verify the `(jury)` route-group layout does not hard-redirect admins; if it does, either relax it for this page or mount the page on a neutral path reachable by both. Authorization is enforced by the procedure regardless.
### 4. Notifications (email + in-app; auto + manual)
- **New notification type `GRAND_FINAL_DOCS_REMINDER`** (team-facing): added to `NotificationTypes`, with a `NOTIFICATION_EMAIL_TEMPLATES` entry (branded) and a `seed-notification-settings.ts` row (`category: "logistics"`, per-type `sendEmail` toggle, subject/body overridable). In-app + email.
- **New notification type `GRAND_FINAL_DOCS_SUBMITTED`** (mentor-facing, light): when a team uploads a final document, notify the team's mentor(s) in-app so it surfaces in their mentor section. Seed row with `sendEmail` default **off** (in-app on). Triggered from `applicant.saveFileMetadata` when the file is for the LIVE_FINAL round (best-effort, never throws).
- **Automatic (cron):** new route `src/app/api/cron/final-document-reminders/route.ts` (protected by `CRON_SECRET`) calling `sendDueFinalDocReminders`. Reminder window read from the round `configJson.finalDocsReminderHoursBeforeDeadline` (default 48h). Fires once per team (stamped via `finalDocsReminderSentAt`). This doubles as the initial "documents are open" nudge.
- **Manual (admin):** a "Remind teams to upload final documents" action with a live `EmailPreviewDialog` (mirrors the existing finalist reminder-blast), backed by `finalist.sendDocumentReminders``sendManualFinalDocReminders`. Placed on the admin Grand Final round overview and/or the `/admin/logistics` Confirmations tab. Usable immediately to kick off the round.
### 5. Minor polish
- Reconfigure the round's `FileRequirement` rows to the 4-document set (rename "PDF presentation support" → "Final Presentation"; add "Final Business Plan" + "Executive Summary" as `application/pdf`; keep "1-minute Video"), all `required = true` (guarded prod data update at ship time, or via the admin round file-requirement editor if present). Additive/safe — 0 files uploaded.
- Confirm admins can edit the round's `windowCloseAt` in round settings (the admin-set deadline). If no input exists, add a small one; likely already present.
## Data model changes
- `FinalistConfirmation.finalDocsReminderSentAt DateTime?` (new nullable column) — lets the auto reminder fire once per team. Migration required (additive, safe).
- `NotificationTypes`: add `GRAND_FINAL_DOCS_REMINDER`, `GRAND_FINAL_DOCS_SUBMITTED`.
- `seed-notification-settings.ts`: add rows for both new types (auto-provisions on deploy).
- Optional round config field `finalDocsReminderHoursBeforeDeadline` (default 48) validated in the LIVE_FINAL round Zod config.
## tRPC procedures (new)
| Procedure | Router | Auth | Purpose |
|---|---|---|---|
| `applicant.getFinalDocumentStatus` | applicant | protected (team member) | Banner + team mentor panel |
| `mentor.getProjectFinalDocuments` | mentor | mentor/team access to project | Mentor workspace panel |
| `finalist.listReviewDocuments` | finalist | admin OR finale jury-group member | Judge review page |
| `finalist.sendDocumentReminders` | finalist | admin | Manual reminder blast |
(Reminder email preview reuses the existing `notification.previewEmailTemplate`.)
## Testing
Vitest (sequential, factories per `tests/helpers.ts`):
- `getFinalDocumentStatusForProject`: all 4 required uploaded / partial / none (`allRequiredUploaded` correct); returns `null` for a non-confirmed team and when no active LIVE_FINAL round; `deadlinePassed` reflects `windowCloseAt`.
- `listFinalistDocumentsForReview`: returns all finalist teams with correct per-requirement file mapping and `submittedCount`.
- Authorization matrix for `finalist.listReviewDocuments`: admin ✓, finale jury-group member ✓, non-finale jury member ✗, applicant ✗.
- `sendDueFinalDocReminders`: targets only CONFIRMED finalists with missing required docs inside the window; stamps `finalDocsReminderSentAt`; idempotent (no double-send).
- `finalist.sendDocumentReminders`: admin only; counts correctly.
Live-UI smoke on dev (lesson learned — catches what tests/build miss): banner renders for a finalist; team mentor panel + mentor-workspace panel render; judge page renders for an admin and for a finale jury-group member and denies a non-finale juror; upload still works; a manual reminder produces an in-app + email notification.
## Prerequisites / admin actions (outside code)
1. **Populate the "Finals Jury" group** with the actual judges (existing jury-group admin UI) — required before the review page is useful to them.
2. **Extend the Grand Final `windowCloseAt`** (currently 2026-06-11, ~2 days out) to the intended deadline.
3. Reconfigure the round's file requirements to the 4-document set (Final Presentation, Final Business Plan, 1-minute Video, Executive Summary), all `required = true` — I can do this as a guarded prod update.
## Build sequence (shippable in phases; deadline is imminent)
1. **Banner + manual admin reminder + minor polish** — makes the existing upload discoverable now (most urgent).
2. **Judge review page** + access helper + entry points.
3. **Mentor-section Final Documents panel** (team + mentor) + `mentor.getProjectFinalDocuments`.
4. **Auto reminder cron** + `GRAND_FINAL_DOCS_SUBMITTED` on-upload mentor notification + new notification types/templates/seed + migration.
## Deployment
Per the prod-deploy runbook: after everything is reviewed and tested (build clean, `npx vitest run` green), commit to `main`, push to `code.monaco-opc.com/MOPC/MOPC-Portal`, **track the Gitea CI build** until it publishes `mopc/mopc-portal:latest`, then redeploy on prod (`ssh stefan@89.58.5.223:22022`, `/opt/letsbe/stacks/mopc-portal`): `docker compose pull && docker compose up -d` (NEVER `-v`). Confirm the additive migration applied and the new notification-settings rows seeded, then live-smoke the banner, judge page, and a manual reminder.

View File

@@ -0,0 +1,201 @@
# Grand Finale Ceremony System — Design (Option C)
> **Status:** Approved 2026-06-10. Event is 2026-06-11 — build tonight in strict dependency order (see Build Order). Each layer must leave the system complete and operable if work stops there.
>
> Supersedes the operational scope of `2026-04-28-grand-finale-live-voting-rework.md` (the audience-window section of that spec is implemented here as designed).
## Decisions (locked with user)
1. **Jury scoring mode:** criteria scores + optional comment (like prior evaluation rounds). Live ranking mode is a stretch goal only.
2. **Audience votes:** per-category favorite windows always; an **overall-favorite** window exists behind an admin toggle (decided day-of).
3. **Vote gating:** one vote per browser token per window AND max **3 votes per IP per window** (venue NAT tolerance).
4. **Deliberation:** per category (two sessions). Existing backend (FULL_RANKING/Borda, adminDecide override) is used as-is.
5. **Architecture:** Option C = full B scope + big-screen ceremony view + results reveal controller. Big screen is **derived from existing state** — no new session-level phase machine. Only new state: reveal controller + display override slide.
6. **During audience windows the big screen shows vote count only** ("147 votes cast"), never a live per-project tally.
7. **Big-screen results reveal must be visually outstanding** — projector-grade, brand identity (dark blue `#053d57` field, red `#de0f1e` accent, Montserrat), animated transitions.
## Current foundation (verified 2026-06-10)
- `LiveProgressCursor` (cursor: activeProjectId, activeOrderIndex, isPaused) + `live.ts` router (start/jump/reorder/pause/resume/getCursor).
- `LiveVotingSession` / `LiveVote` / `AudienceVoter` + `live-voting.ts` router (criteria voting, importCriteriaFromForm, getResults, registerAudienceVoter/castAudienceVote, public results).
- Jury live page `/jury/competitions/[roundId]/live` follows cursor (poll 5s); notes textarea is **not persisted**; prior-data panel stubbed.
- Admin `live-control-panel.tsx`: prev/next/pause/resume + **client-local fake timer**.
- Public `/live-scores/[sessionId]` scoreboard with SSE.
- Deliberation backend + router 100% complete; jury deliberation page has `juryMemberId=''` and `hasVoted=false` hardcoded (jurors cannot vote).
- `publicPaths` in `auth.config.ts` does **not** include `/vote` or `/live-scores` → audience pages bounce to login. Launch blocker.
---
## 1. Public access (do first)
Add `/vote`, `/live-scores`, `/live/ceremony` to `publicPaths` in `src/lib/auth.config.ts` (wherever publicPaths lives). Verify with `curl -I` (not the logged-in Playwright profile).
## 2. Schema changes (one migration)
```prisma
// LiveProgressCursor — per-project phase + server-stamped timer
projectPhase LivePhase @default(ON_DECK) // ON_DECK | PRESENTING | QA | SCORING
phaseStartedAt DateTime?
phaseDurationSeconds Int?
phasePausedAt DateTime?
phasePausedAccumMs Int @default(0)
timingLogJson Json? // [{projectId, phase, startedAt, endedAt, configuredSeconds, overranSeconds}]
overrideSlide String? // 'welcome' | 'break' | 'deliberation' | 'thanks' | null
enum LivePhase { ON_DECK PRESENTING QA SCORING }
// LiveVotingSession — audience window (locked spec from 2026-04-28 + overall kind)
audiencePhase AudiencePhase @default(CLOSED) // CLOSED | OPEN
audienceWindowKey String? // 'CATEGORY:STARTUP' | 'CATEGORY:BUSINESS_CONCEPT' | 'OVERALL'
audienceWindowOpenedAt DateTime?
audienceWindowClosesAt DateTime?
allowOverallFavorite Boolean @default(false) // admin toggle, decided day-of
enum AudiencePhase { CLOSED OPEN }
// LiveVote — optional overall comment
comment String?
model AudienceFavoriteVote {
id String @id @default(cuid())
sessionId String
windowKey String // matches audienceWindowKey at cast time
projectId String
audienceVoterId String
ipAddress String?
createdAt DateTime @default(now())
@@unique([sessionId, windowKey, audienceVoterId])
@@index([sessionId, windowKey, ipAddress])
}
model LiveNote {
id String @id @default(cuid())
roundId String
projectId String
userId String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([roundId, projectId, userId])
}
model RevealState {
id String @id @default(cuid())
sessionId String @unique
status String @default("DRAFT") // DRAFT | ARMED | REVEALING | DONE
stepsJson Json // ordered reveal steps, see §8
currentStepIndex Int @default(-1)
}
```
Timer math (shared client+server helper `src/lib/live-timer.ts`): `remaining = phaseDurationSeconds (now phaseStartedAt phasePausedAccumMs)`; negative = overtime, displayed `+m:ss` in red. On every phase transition the server appends a timing-log entry with `overranSeconds = max(0, elapsed configured)`.
## 3. Ceremony control — `live.ts` router + admin panel revamp
New adminProcedure mutations on `live`:
- `sendToScreens({roundId, projectId?})` — advance cursor to project (or next), `projectPhase=ON_DECK`, no timer. This is the "next up" grace.
- `startPresentation({roundId, durationSeconds?})``PRESENTING`, stamp `phaseStartedAt`, duration from round config `presentationDurationMinutes` unless overridden.
- `startQA({roundId, durationSeconds?})` — close out PRESENTING into timing log, start QA timer (`qaDurationMinutes` default).
- `openScoring({roundId})` — close QA into log, `phase=SCORING`, no timer.
- `pausePhase` / `resumePhase` — stamp `phasePausedAt` / fold into `phasePausedAccumMs`.
- `setOverrideSlide({roundId, slide})` — force big-screen slide or clear.
- `getCursor` extended to return phase, timer stamps, timing log, override slide.
Admin panel (`live-control-panel.tsx` revamp):
- Project order list **grouped by category**, current/next highlighted, reorder preserved (existing `reorder` mutation), tap-to-`sendToScreens` any project (handles schedule shuffles).
- Big phase buttons in flow order; live server-derived countdown, red + counting up when over; pause/resume.
- Per-project duration override inputs (pre-filled from config).
- Timing log table (per project: presentation over by X, Q&A over by Y).
- Audience section: window open/close buttons per category + overall (gated by `allowOverallFavorite` toggle), duration picker (default 5 min), live countdown, **live vote count**, "Close now". QR button → full-screen dialog with giant QR (`qrcode.react` or equivalent tiny dep) linking to `/vote/competition/[roundId]`.
- Override-slide buttons: Welcome / Break / Deliberation / Thank you / Clear.
- Reveal section: see §9.
## 4. Jury live page
- Phase-aware: ON_DECK → "Up next: Team X" banner; PRESENTING/QA → project details, same countdown the admin sees, persistent notes; SCORING → scoring form spotlighted (form already available from PRESENTING on — early scorers not blocked).
- **Notes**: `LiveNote` autosave (debounced ~800ms) via new `live.saveNote` / `live.getMyNotes` (juryProcedure). Notes resurface in deliberation.
- Scoring: existing criteria form + new optional **comment** textarea → stored on `LiveVote.comment`. Votes upsert-editable until session COMPLETED.
## 5. Audience voting
`live-voting.ts` additions:
- `openAudienceWindow({sessionId, windowKey, durationMinutes})` (admin) — errors if already OPEN; `OVERALL` requires `allowOverallFavorite`.
- `closeAudienceWindow({sessionId})` (admin) — early close allowed anytime.
- `getAudienceWindow({sessionId})` (public) — phase, windowKey, closesAt, eligible projects (category members or all), my-vote-for-this-window (by token).
- `castFavoriteVote({sessionId, token, projectId})` (public). Server-side gates, in order:
1. `audiencePhase === OPEN`
2. `now <= audienceWindowClosesAt` (source of truth even if no cron closes it)
3. project's category matches windowKey (or OVERALL → any finalist project)
4. token valid for session
5. unique (session, windowKey, voter) — re-vote within open window **updates** the row (change-your-mind allowed while open)
6. IP cap: ≥3 distinct-voter rows for (session, windowKey, ipAddress) → reject with friendly message
- `getFavoriteTallies({sessionId})` (admin) — counts per project per windowKey.
- `setAllowOverallFavorite({sessionId, allow})` (admin).
Audience page `/vote/competition/[roundId]` (rework): scan → auto-`registerAudienceVoter`, token in localStorage → states: **waiting** ("Voting opens after the presentations" + current presenting team name), **open** (category title, project cards, tap → confirm → done, countdown chip), **voted** ("Vote recorded — you can change it until the window closes"), **closed**. Mobile-first, zero-instruction usable.
No cron needed: vote-time + read-time checks enforce the close; window auto-renders as closed everywhere once `closesAt` passes.
## 6. Deliberation completion
- Fix jury page wiring: resolve `juryMemberId` from `session.participants` matching current user; derive `hasVoted` from `session.votes`.
- Add per-project context panels to the jury deliberation page: **my finale scores** (from `LiveVote`, editable inline — edits upsert the same vote, audit-logged; "keep" = do nothing), **my live notes** (`LiveNote`), **document links** (reuse the judge-docs components/links from the finals docs feature).
- Admin: existing create-session (per category), aggregate, runoff, `adminDecide` (manual rankings), finalize, result lock — verify end-to-end, no new build expected.
## 7. Big-screen ceremony view — `/live/ceremony/[roundId]` (public)
Full-screen, no chrome, dark-blue field, Montserrat, brand accents. **Pure derivation** of state (poll ~2s + reuse SSE hook where available):
| State | Display |
|---|---|
| `overrideSlide` set | That slide (Welcome / Break / Deliberation in progress / Thank you) |
| Reveal REVEALING/ARMED | Reveal mode (§9) |
| Audience window OPEN | Giant QR + "Vote for your favorite {category}" + countdown + **vote count only** |
| Cursor ON_DECK | "Up next: Team X" |
| Cursor PRESENTING/QA | Team name, category chip, phase label, large countdown (red overtime) |
| Cursor SCORING | "Jury is scoring" interstitial |
| Nothing active | Welcome slide |
## 8. Reveal controller (admin) — §3 panel section
- "Build reveal" generates `stepsJson` from deliberation results (per category 3rd→2nd→1st) + audience favorite tallies (per-category winners, overall if enabled): `[{kind:'category-intro',category}, {kind:'place',category,place,projectId}, …, {kind:'audience-award',windowKey,projectId}, {kind:'thanks'}]`. Editable/rebuildable while DRAFT (e.g., after adminDecide changes order).
- Admin previews all steps privately. "Arm" → big screen shows a Results splash. "Next" advances `currentStepIndex` one step at a time. "Reset" → back to DRAFT, screen leaves reveal mode.
- Router: `liveVoting.buildReveal`, `armReveal`, `revealNext`, `resetReveal` (admin) + reveal state included in the public ceremony-state query (steps beyond `currentStepIndex` are **never** sent to the public endpoint).
## 9. Reveal visuals (the gorgeous part)
Use the `frontend-design` skill when building. Requirements: cinematic step transitions (place card slides/fades up, 1st-place moment visibly bigger than 3rd/2nd), confetti or equivalent flourish on 1st place and audience award, team name in very large Montserrat 700, category chip, no scores shown unless step includes them, safe on 16:9 projector at distance (high contrast, no small text). Prefer CSS/tailwind animation; adding `framer-motion` is acceptable if it materially raises quality. Must degrade gracefully (refresh mid-reveal lands on current step).
## 10. Results tally audit
- Jury results: existing `getResults` weighted aggregation + tie detection — dedicated tests.
- Audience awards are **counts from `AudienceFavoriteVote`**, kept separate from jury scores (separate awards). `audienceVoteWeight` blending stays available but is NOT used in the reveal unless explicitly configured; default 0.
## Out of scope (explicit)
Live ranking mode for jurors (stretch only, after everything else), automated tie-breaker revotes (admin_decides stands), audience phones showing live scores (vote-only page), session-level ceremony phase machine.
## Build order (cut line moves down, never breaks)
1. publicPaths fix + schema migration
2. Audience windows + favorite votes + IP cap + audience page + QR (audience system complete)
3. Phase model + server timers + admin panel revamp (ceremony operable)
4. Jury page phases + persisted notes + vote comments (jury complete)
5. Deliberation wiring fix + context panels (deliberation complete)
6. Big-screen ceremony view (derived states + override slides)
7. Reveal controller + reveal visuals
8. Tally audit tests → stretch: live ranking toggle
Each layer: vitest tests + `npm run build` green before the next.
## Test matrix (vitest, follows tests/helpers.ts factory pattern)
- Window: open/cast OK; wrong-category reject; cast after closesAt reject (no cron); early close reject; re-open works; OVERALL requires toggle.
- Favorite votes: one per token per window; re-vote updates while open; IP cap at 3 distinct voters; tallies correct.
- Phases: transition sequence; timing log entries with correct overranSeconds; pause/resume accumulator math.
- Notes: upsert per (round, project, user).
- Deliberation: juryMemberId resolution, hasVoted, vote→aggregate→finalize with real juror identity.
- Reveal: build from results, step advance, public endpoint never leaks un-revealed steps.
- Results: weighted jury aggregation + tie detection regression tests.

25
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "mopc-platform",
"version": "0.1.0",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mopc-platform",
"version": "0.1.0",
"version": "1.0.0",
"dependencies": {
"@anthropic-ai/sdk": "^0.78.0",
"@auth/prisma-adapter": "^2.7.4",
@@ -61,11 +61,11 @@
"motion": "^11.15.0",
"next": "^15.1.0",
"next-auth": "^5.0.0-beta.25",
"next-themes": "^0.4.6",
"nodemailer": "^7.0.7",
"openai": "^6.16.0",
"papaparse": "^5.4.1",
"pdf-parse": "^2.4.5",
"qrcode.react": "^4.2.0",
"react": "^19.0.0",
"react-day-picker": "^9.13.0",
"react-dom": "^19.0.0",
@@ -12143,16 +12143,6 @@
}
}
},
"node_modules/next-themes": {
"version": "0.4.6",
"resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.4.6.tgz",
"integrity": "sha512-pZvgD5L0IEvX5/9GWyHMf3m8BKiVQwsCMHfoFosXtXBMnaS0ZnIJ9ST4b4NqLVKDEm8QBxoNNGNaBv2JNF6XNA==",
"license": "MIT",
"peerDependencies": {
"react": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc"
}
},
"node_modules/next/node_modules/postcss": {
"version": "8.4.31",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
@@ -13428,6 +13418,15 @@
],
"license": "MIT"
},
"node_modules/qrcode.react": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/qrcode.react/-/qrcode.react-4.2.0.tgz",
"integrity": "sha512-QpgqWi8rD9DsS9EP3z7BT+5lY5SFhsqGjpgW5DY/i3mK4M9DTBNz3ErMi8BWYEfI3L0d8GIbGmcdFAS1uIRGjA==",
"license": "ISC",
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
}
},
"node_modules/qs": {
"version": "6.15.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz",

View File

@@ -1,6 +1,6 @@
{
"name": "mopc-platform",
"version": "0.1.0",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
@@ -75,11 +75,11 @@
"motion": "^11.15.0",
"next": "^15.1.0",
"next-auth": "^5.0.0-beta.25",
"next-themes": "^0.4.6",
"nodemailer": "^7.0.7",
"openai": "^6.16.0",
"papaparse": "^5.4.1",
"pdf-parse": "^2.4.5",
"qrcode.react": "^4.2.0",
"react": "^19.0.0",
"react-day-picker": "^9.13.0",
"react-dom": "^19.0.0",

View File

@@ -0,0 +1,5 @@
-- Fix: the category migration used DROP CONSTRAINT to remove the old
-- (roundId, version) uniqueness rule, but it was created as a UNIQUE INDEX
-- (not a constraint) by an earlier migration, so it was never actually dropped.
-- This blocks per-category forms from sharing a version number.
DROP INDEX IF EXISTS "EvaluationForm_roundId_version_key";

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "mentorOnboardingSentAt" TIMESTAMP(3);

View File

@@ -0,0 +1,119 @@
-- CreateEnum
CREATE TYPE "WaitlistEntryStatus" AS ENUM ('WAITING', 'PROMOTED', 'USED');
-- CreateEnum
CREATE TYPE "FinalistConfirmationStatus" AS ENUM ('PENDING', 'CONFIRMED', 'DECLINED', 'EXPIRED', 'SUPERSEDED');
-- AlterTable
ALTER TABLE "Program" ADD COLUMN "defaultAttendeeCap" INTEGER NOT NULL DEFAULT 3;
-- CreateTable
CREATE TABLE "FinalistSlotQuota" (
"id" TEXT NOT NULL,
"programId" TEXT NOT NULL,
"category" "CompetitionCategory" NOT NULL,
"quota" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "FinalistSlotQuota_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "WaitlistEntry" (
"id" TEXT NOT NULL,
"programId" TEXT NOT NULL,
"projectId" TEXT NOT NULL,
"category" "CompetitionCategory" NOT NULL,
"rank" INTEGER NOT NULL,
"status" "WaitlistEntryStatus" NOT NULL DEFAULT 'WAITING',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "WaitlistEntry_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "FinalistConfirmation" (
"id" TEXT NOT NULL,
"projectId" TEXT NOT NULL,
"category" "CompetitionCategory" NOT NULL,
"status" "FinalistConfirmationStatus" NOT NULL DEFAULT 'PENDING',
"deadline" TIMESTAMP(3) NOT NULL,
"token" TEXT NOT NULL,
"confirmedAt" TIMESTAMP(3),
"declinedAt" TIMESTAMP(3),
"declineReason" TEXT,
"expiredAt" TIMESTAMP(3),
"promotedFromWaitlistEntryId" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "FinalistConfirmation_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "AttendingMember" (
"id" TEXT NOT NULL,
"confirmationId" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"needsVisa" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "AttendingMember_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "FinalistSlotQuota_programId_idx" ON "FinalistSlotQuota"("programId");
-- CreateIndex
CREATE UNIQUE INDEX "FinalistSlotQuota_programId_category_key" ON "FinalistSlotQuota"("programId", "category");
-- CreateIndex
CREATE UNIQUE INDEX "WaitlistEntry_projectId_key" ON "WaitlistEntry"("projectId");
-- CreateIndex
CREATE INDEX "WaitlistEntry_programId_category_status_idx" ON "WaitlistEntry"("programId", "category", "status");
-- CreateIndex
CREATE UNIQUE INDEX "WaitlistEntry_programId_category_rank_key" ON "WaitlistEntry"("programId", "category", "rank");
-- CreateIndex
CREATE UNIQUE INDEX "FinalistConfirmation_projectId_key" ON "FinalistConfirmation"("projectId");
-- CreateIndex
CREATE UNIQUE INDEX "FinalistConfirmation_token_key" ON "FinalistConfirmation"("token");
-- CreateIndex
CREATE UNIQUE INDEX "FinalistConfirmation_promotedFromWaitlistEntryId_key" ON "FinalistConfirmation"("promotedFromWaitlistEntryId");
-- CreateIndex
CREATE INDEX "FinalistConfirmation_status_deadline_idx" ON "FinalistConfirmation"("status", "deadline");
-- CreateIndex
CREATE INDEX "FinalistConfirmation_category_status_idx" ON "FinalistConfirmation"("category", "status");
-- CreateIndex
CREATE INDEX "AttendingMember_userId_idx" ON "AttendingMember"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "AttendingMember_confirmationId_userId_key" ON "AttendingMember"("confirmationId", "userId");
-- AddForeignKey
ALTER TABLE "FinalistSlotQuota" ADD CONSTRAINT "FinalistSlotQuota_programId_fkey" FOREIGN KEY ("programId") REFERENCES "Program"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "WaitlistEntry" ADD CONSTRAINT "WaitlistEntry_programId_fkey" FOREIGN KEY ("programId") REFERENCES "Program"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "WaitlistEntry" ADD CONSTRAINT "WaitlistEntry_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "FinalistConfirmation" ADD CONSTRAINT "FinalistConfirmation_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "AttendingMember" ADD CONSTRAINT "AttendingMember_confirmationId_fkey" FOREIGN KEY ("confirmationId") REFERENCES "FinalistConfirmation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "AttendingMember" ADD CONSTRAINT "AttendingMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,49 @@
-- CreateEnum
CREATE TYPE "FlightDetailStatus" AS ENUM ('PENDING', 'CONFIRMED');
-- CreateTable
CREATE TABLE "Hotel" (
"id" TEXT NOT NULL,
"programId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"address" TEXT,
"link" TEXT,
"notes" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Hotel_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "FlightDetail" (
"id" TEXT NOT NULL,
"attendingMemberId" TEXT NOT NULL,
"arrivalAt" TIMESTAMP(3),
"arrivalFlightNumber" TEXT,
"arrivalAirport" TEXT,
"departureAt" TIMESTAMP(3),
"departureFlightNumber" TEXT,
"departureAirport" TEXT,
"status" "FlightDetailStatus" NOT NULL DEFAULT 'PENDING',
"adminNotes" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "FlightDetail_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Hotel_programId_key" ON "Hotel"("programId");
-- CreateIndex
CREATE UNIQUE INDEX "FlightDetail_attendingMemberId_key" ON "FlightDetail"("attendingMemberId");
-- CreateIndex
CREATE INDEX "FlightDetail_status_idx" ON "FlightDetail"("status");
-- AddForeignKey
ALTER TABLE "Hotel" ADD CONSTRAINT "Hotel_programId_fkey" FOREIGN KEY ("programId") REFERENCES "Program"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "FlightDetail" ADD CONSTRAINT "FlightDetail_attendingMemberId_fkey" FOREIGN KEY ("attendingMemberId") REFERENCES "AttendingMember"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE "MentorAssignment" ADD COLUMN "droppedAt" TIMESTAMP(3),
ADD COLUMN "droppedBy" TEXT,
ADD COLUMN "droppedReason" TEXT;

View File

@@ -0,0 +1,30 @@
-- CreateEnum
CREATE TYPE "VisaStatus" AS ENUM ('NOT_NEEDED', 'REQUESTED', 'INVITATION_SENT', 'APPOINTMENT_BOOKED', 'GRANTED', 'DENIED');
-- AlterTable
ALTER TABLE "Program" ADD COLUMN "visaStatusVisibleToMembers" BOOLEAN NOT NULL DEFAULT true;
-- CreateTable
CREATE TABLE "VisaApplication" (
"id" TEXT NOT NULL,
"attendingMemberId" TEXT NOT NULL,
"status" "VisaStatus" NOT NULL DEFAULT 'REQUESTED',
"nationality" TEXT,
"invitationSentAt" TIMESTAMP(3),
"appointmentAt" TIMESTAMP(3),
"decisionAt" TIMESTAMP(3),
"notes" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "VisaApplication_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "VisaApplication_attendingMemberId_key" ON "VisaApplication"("attendingMemberId");
-- CreateIndex
CREATE INDEX "VisaApplication_status_idx" ON "VisaApplication"("status");
-- AddForeignKey
ALTER TABLE "VisaApplication" ADD CONSTRAINT "VisaApplication_attendingMemberId_fkey" FOREIGN KEY ("attendingMemberId") REFERENCES "AttendingMember"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,109 @@
-- CreateEnum
CREATE TYPE "DietaryTag" AS ENUM ('VEGETARIAN', 'VEGAN', 'GLUTEN_FREE', 'PESCATARIAN');
-- CreateEnum
CREATE TYPE "Allergen" AS ENUM ('GLUTEN', 'CRUSTACEANS', 'EGGS', 'FISH', 'PEANUTS', 'SOYBEANS', 'MILK', 'TREE_NUTS', 'CELERY', 'MUSTARD', 'SESAME', 'SULPHITES', 'LUPIN', 'MOLLUSCS');
-- CreateTable
CREATE TABLE "LunchEvent" (
"id" TEXT NOT NULL,
"programId" TEXT NOT NULL,
"enabled" BOOLEAN NOT NULL DEFAULT false,
"eventAt" TIMESTAMP(3),
"endAt" TIMESTAMP(3),
"venue" TEXT,
"notes" TEXT,
"changeCutoffHours" INTEGER NOT NULL DEFAULT 48,
"reminderHoursBeforeDeadline" INTEGER,
"cronEnabled" BOOLEAN NOT NULL DEFAULT true,
"extraRecipients" TEXT[] DEFAULT ARRAY[]::TEXT[],
"reminderSentAt" TIMESTAMP(3),
"recapSentAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "LunchEvent_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Dish" (
"id" TEXT NOT NULL,
"lunchEventId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"sortOrder" INTEGER NOT NULL DEFAULT 0,
"dietaryTags" "DietaryTag"[],
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Dish_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "MemberLunchPick" (
"id" TEXT NOT NULL,
"attendingMemberId" TEXT NOT NULL,
"dishId" TEXT,
"allergens" "Allergen"[] DEFAULT ARRAY[]::"Allergen"[],
"allergenOther" TEXT,
"pickedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "MemberLunchPick_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "ExternalAttendee" (
"id" TEXT NOT NULL,
"lunchEventId" TEXT NOT NULL,
"projectId" TEXT,
"name" TEXT NOT NULL,
"email" TEXT,
"roleNote" TEXT,
"dishId" TEXT,
"allergens" "Allergen"[] DEFAULT ARRAY[]::"Allergen"[],
"allergenOther" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "ExternalAttendee_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "LunchEvent_programId_key" ON "LunchEvent"("programId");
-- CreateIndex
CREATE INDEX "Dish_lunchEventId_idx" ON "Dish"("lunchEventId");
-- CreateIndex
CREATE UNIQUE INDEX "MemberLunchPick_attendingMemberId_key" ON "MemberLunchPick"("attendingMemberId");
-- CreateIndex
CREATE INDEX "MemberLunchPick_dishId_idx" ON "MemberLunchPick"("dishId");
-- CreateIndex
CREATE INDEX "ExternalAttendee_lunchEventId_idx" ON "ExternalAttendee"("lunchEventId");
-- CreateIndex
CREATE INDEX "ExternalAttendee_projectId_idx" ON "ExternalAttendee"("projectId");
-- AddForeignKey
ALTER TABLE "LunchEvent" ADD CONSTRAINT "LunchEvent_programId_fkey" FOREIGN KEY ("programId") REFERENCES "Program"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Dish" ADD CONSTRAINT "Dish_lunchEventId_fkey" FOREIGN KEY ("lunchEventId") REFERENCES "LunchEvent"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "MemberLunchPick" ADD CONSTRAINT "MemberLunchPick_attendingMemberId_fkey" FOREIGN KEY ("attendingMemberId") REFERENCES "AttendingMember"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "MemberLunchPick" ADD CONSTRAINT "MemberLunchPick_dishId_fkey" FOREIGN KEY ("dishId") REFERENCES "Dish"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ExternalAttendee" ADD CONSTRAINT "ExternalAttendee_lunchEventId_fkey" FOREIGN KEY ("lunchEventId") REFERENCES "LunchEvent"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ExternalAttendee" ADD CONSTRAINT "ExternalAttendee_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ExternalAttendee" ADD CONSTRAINT "ExternalAttendee_dishId_fkey" FOREIGN KEY ("dishId") REFERENCES "Dish"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@@ -0,0 +1,31 @@
-- Drops AWARD_MASTER from the UserRole enum.
--
-- Any row still holding AWARD_MASTER is demoted to JURY_MEMBER (singular role)
-- or filtered out of the roles[] array (multi-role) before the enum swap, so
-- the type alteration is safe even if the prod migration was missed.
UPDATE "User" SET role = 'JURY_MEMBER' WHERE role = 'AWARD_MASTER';
UPDATE "User" SET roles = array_remove(roles, 'AWARD_MASTER') WHERE 'AWARD_MASTER' = ANY(roles);
CREATE TYPE "UserRole_new" AS ENUM (
'SUPER_ADMIN',
'PROGRAM_ADMIN',
'JURY_MEMBER',
'MENTOR',
'OBSERVER',
'APPLICANT',
'AUDIENCE'
);
ALTER TABLE "User" ALTER COLUMN role DROP DEFAULT;
ALTER TABLE "User"
ALTER COLUMN role TYPE "UserRole_new" USING role::text::"UserRole_new";
ALTER TABLE "User" ALTER COLUMN role SET DEFAULT 'APPLICANT';
ALTER TABLE "User" ALTER COLUMN roles DROP DEFAULT;
ALTER TABLE "User"
ALTER COLUMN roles TYPE "UserRole_new"[] USING roles::text[]::"UserRole_new"[];
ALTER TABLE "User" ALTER COLUMN roles SET DEFAULT '{}'::"UserRole_new"[];
DROP TYPE "UserRole";
ALTER TYPE "UserRole_new" RENAME TO "UserRole";

View File

@@ -0,0 +1,78 @@
-- Hand-written migration for PR8 (multi-mentor per team).
--
-- All DDL guarded with IF EXISTS / IF NOT EXISTS so the docker-entrypoint
-- retry loop is safe to re-run. No regex (the 2026-05-07 prod incident was
-- caused by Prisma 6 generating regex-based DDL that Postgres rejected).
-- No BEGIN/COMMIT blocks — Prisma wraps the migration in a transaction.
-- Phase 1: MentorAssignment — drop unique, add composite, add notification field
ALTER TABLE "MentorAssignment" DROP CONSTRAINT IF EXISTS "MentorAssignment_projectId_key";
DROP INDEX IF EXISTS "MentorAssignment_projectId_key";
CREATE UNIQUE INDEX IF NOT EXISTS "MentorAssignment_projectId_mentorId_key"
ON "MentorAssignment"("projectId", "mentorId");
CREATE INDEX IF NOT EXISTS "MentorAssignment_projectId_idx"
ON "MentorAssignment"("projectId");
ALTER TABLE "MentorAssignment" ADD COLUMN IF NOT EXISTS "notificationSentAt" TIMESTAMP(3);
-- Phase 2: MentorFile — re-scope to project (two-phase backfill)
ALTER TABLE "MentorFile" ADD COLUMN IF NOT EXISTS "projectId" TEXT;
UPDATE "MentorFile" mf
SET "projectId" = ma."projectId"
FROM "MentorAssignment" ma
WHERE mf."mentorAssignmentId" = ma."id"
AND mf."projectId" IS NULL;
ALTER TABLE "MentorFile" ALTER COLUMN "projectId" SET NOT NULL;
ALTER TABLE "MentorFile" DROP CONSTRAINT IF EXISTS "MentorFile_projectId_fkey";
ALTER TABLE "MentorFile" ADD CONSTRAINT "MentorFile_projectId_fkey"
FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
CREATE INDEX IF NOT EXISTS "MentorFile_projectId_idx" ON "MentorFile"("projectId");
-- Phase 2b: Make MentorFile.mentorAssignmentId nullable + switch its FK to SetNull
ALTER TABLE "MentorFile" ALTER COLUMN "mentorAssignmentId" DROP NOT NULL;
ALTER TABLE "MentorFile" DROP CONSTRAINT IF EXISTS "MentorFile_mentorAssignmentId_fkey";
ALTER TABLE "MentorFile" ADD CONSTRAINT "MentorFile_mentorAssignmentId_fkey"
FOREIGN KEY ("mentorAssignmentId") REFERENCES "MentorAssignment"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- Phase 3: MentorChangeRequest table
-- Postgres < 14 doesn't support CREATE TYPE ... IF NOT EXISTS, so wrap in a
-- DO block that swallows duplicate_object errors (idempotent for re-runs).
DO $$ BEGIN
CREATE TYPE "MentorChangeRequestStatus" AS ENUM ('PENDING', 'RESOLVED', 'DISMISSED');
EXCEPTION
WHEN duplicate_object THEN NULL;
END $$;
CREATE TABLE IF NOT EXISTS "MentorChangeRequest" (
"id" TEXT NOT NULL,
"projectId" TEXT NOT NULL,
"targetAssignmentId" TEXT,
"requestedByUserId" TEXT,
"reason" TEXT NOT NULL,
"status" "MentorChangeRequestStatus" NOT NULL DEFAULT 'PENDING',
"resolvedByUserId" TEXT,
"resolvedAt" TIMESTAMP(3),
"resolutionNote" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "MentorChangeRequest_pkey" PRIMARY KEY ("id")
);
ALTER TABLE "MentorChangeRequest" DROP CONSTRAINT IF EXISTS "MentorChangeRequest_projectId_fkey";
ALTER TABLE "MentorChangeRequest" ADD CONSTRAINT "MentorChangeRequest_projectId_fkey"
FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "MentorChangeRequest" DROP CONSTRAINT IF EXISTS "MentorChangeRequest_targetAssignmentId_fkey";
ALTER TABLE "MentorChangeRequest" ADD CONSTRAINT "MentorChangeRequest_targetAssignmentId_fkey"
FOREIGN KEY ("targetAssignmentId") REFERENCES "MentorAssignment"("id") ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE "MentorChangeRequest" DROP CONSTRAINT IF EXISTS "MentorChangeRequest_requestedByUserId_fkey";
ALTER TABLE "MentorChangeRequest" ADD CONSTRAINT "MentorChangeRequest_requestedByUserId_fkey"
FOREIGN KEY ("requestedByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE "MentorChangeRequest" DROP CONSTRAINT IF EXISTS "MentorChangeRequest_resolvedByUserId_fkey";
ALTER TABLE "MentorChangeRequest" ADD CONSTRAINT "MentorChangeRequest_resolvedByUserId_fkey"
FOREIGN KEY ("resolvedByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
CREATE INDEX IF NOT EXISTS "MentorChangeRequest_projectId_idx" ON "MentorChangeRequest"("projectId");
CREATE INDEX IF NOT EXISTS "MentorChangeRequest_status_idx" ON "MentorChangeRequest"("status");
CREATE INDEX IF NOT EXISTS "MentorChangeRequest_targetAssignmentId_idx" ON "MentorChangeRequest"("targetAssignmentId");

View File

@@ -0,0 +1,23 @@
-- PR8 rollback SQL (manual, only safe BEFORE any project has >1 mentor)
-- Reverses 20260522155652_multi_mentor_per_team
-- MentorChangeRequest: drop new table + enum
DROP TABLE IF EXISTS "MentorChangeRequest";
DROP TYPE IF EXISTS "MentorChangeRequestStatus";
-- MentorFile: drop projectId scope + restore mentorAssignmentId as required Cascade
ALTER TABLE "MentorFile" DROP CONSTRAINT IF EXISTS "MentorFile_projectId_fkey";
DROP INDEX IF EXISTS "MentorFile_projectId_idx";
ALTER TABLE "MentorFile" DROP COLUMN IF EXISTS "projectId";
-- Restoring NOT NULL is safe only if no rows have NULL mentorAssignmentId (true unless multi-mentor assignments were dropped post-migration)
ALTER TABLE "MentorFile" ALTER COLUMN "mentorAssignmentId" SET NOT NULL;
ALTER TABLE "MentorFile" DROP CONSTRAINT IF EXISTS "MentorFile_mentorAssignmentId_fkey";
ALTER TABLE "MentorFile" ADD CONSTRAINT "MentorFile_mentorAssignmentId_fkey"
FOREIGN KEY ("mentorAssignmentId") REFERENCES "MentorAssignment"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- MentorAssignment: restore projectId @unique + drop new fields
DROP INDEX IF EXISTS "MentorAssignment_projectId_mentorId_key";
DROP INDEX IF EXISTS "MentorAssignment_projectId_idx";
ALTER TABLE "MentorAssignment" DROP COLUMN IF EXISTS "notificationSentAt";
-- Re-adding UNIQUE will FAIL if any project has >1 mentor (intended safety signal)
ALTER TABLE "MentorAssignment" ADD CONSTRAINT "MentorAssignment_projectId_key" UNIQUE ("projectId");

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "MentorAssignment" ADD COLUMN "teamIntroducedAt" TIMESTAMP(3);

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "FinalistConfirmation" ADD COLUMN "reminderSentAt" TIMESTAMP(3);

View File

@@ -0,0 +1,33 @@
-- DropIndex
DROP INDEX "Hotel_programId_key";
-- CreateTable
CREATE TABLE "HotelStay" (
"id" TEXT NOT NULL,
"attendingMemberId" TEXT NOT NULL,
"hotelId" TEXT NOT NULL,
"roomNumber" TEXT,
"checkInAt" TIMESTAMP(3),
"checkOutAt" TIMESTAMP(3),
"notes" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "HotelStay_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "HotelStay_attendingMemberId_key" ON "HotelStay"("attendingMemberId");
-- CreateIndex
CREATE INDEX "HotelStay_hotelId_idx" ON "HotelStay"("hotelId");
-- CreateIndex
CREATE INDEX "Hotel_programId_idx" ON "Hotel"("programId");
-- AddForeignKey
ALTER TABLE "HotelStay" ADD CONSTRAINT "HotelStay_attendingMemberId_fkey" FOREIGN KEY ("attendingMemberId") REFERENCES "AttendingMember"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "HotelStay" ADD CONSTRAINT "HotelStay_hotelId_fkey" FOREIGN KEY ("hotelId") REFERENCES "Hotel"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -0,0 +1,2 @@
-- Add inviteSentAt to ExternalAttendee for dish-selection email tracking
ALTER TABLE "ExternalAttendee" ADD COLUMN "inviteSentAt" TIMESTAMP(3);

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "FinalistConfirmation" ADD COLUMN "finalDocsReminderSentAt" TIMESTAMP(3);

View File

@@ -0,0 +1,104 @@
-- CreateEnum
CREATE TYPE "LivePhase" AS ENUM ('ON_DECK', 'PRESENTING', 'QA', 'SCORING');
-- CreateEnum
CREATE TYPE "AudiencePhase" AS ENUM ('CLOSED', 'OPEN');
-- AlterTable
ALTER TABLE "LiveProgressCursor" ADD COLUMN "overrideSlide" TEXT,
ADD COLUMN "phaseDurationSeconds" INTEGER,
ADD COLUMN "phasePausedAccumMs" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "phasePausedAt" TIMESTAMP(3),
ADD COLUMN "phaseStartedAt" TIMESTAMP(3),
ADD COLUMN "projectPhase" "LivePhase" NOT NULL DEFAULT 'ON_DECK',
ADD COLUMN "timingLogJson" JSONB;
-- AlterTable
ALTER TABLE "LiveVote" ADD COLUMN "comment" TEXT;
-- AlterTable
ALTER TABLE "LiveVotingSession" ADD COLUMN "allowOverallFavorite" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "audiencePhase" "AudiencePhase" NOT NULL DEFAULT 'CLOSED',
ADD COLUMN "audienceWindowClosesAt" TIMESTAMP(3),
ADD COLUMN "audienceWindowKey" TEXT,
ADD COLUMN "audienceWindowOpenedAt" TIMESTAMP(3);
-- CreateTable
CREATE TABLE "AudienceFavoriteVote" (
"id" TEXT NOT NULL,
"sessionId" TEXT NOT NULL,
"windowKey" TEXT NOT NULL,
"projectId" TEXT NOT NULL,
"audienceVoterId" TEXT NOT NULL,
"ipAddress" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "AudienceFavoriteVote_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "LiveNote" (
"id" TEXT NOT NULL,
"roundId" TEXT NOT NULL,
"projectId" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"content" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "LiveNote_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "RevealState" (
"id" TEXT NOT NULL,
"sessionId" TEXT NOT NULL,
"status" TEXT NOT NULL DEFAULT 'DRAFT',
"stepsJson" JSONB NOT NULL,
"currentStepIndex" INTEGER NOT NULL DEFAULT -1,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "RevealState_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "AudienceFavoriteVote_sessionId_windowKey_ipAddress_idx" ON "AudienceFavoriteVote"("sessionId", "windowKey", "ipAddress");
-- CreateIndex
CREATE INDEX "AudienceFavoriteVote_sessionId_windowKey_projectId_idx" ON "AudienceFavoriteVote"("sessionId", "windowKey", "projectId");
-- CreateIndex
CREATE UNIQUE INDEX "AudienceFavoriteVote_sessionId_windowKey_audienceVoterId_key" ON "AudienceFavoriteVote"("sessionId", "windowKey", "audienceVoterId");
-- CreateIndex
CREATE INDEX "LiveNote_userId_idx" ON "LiveNote"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "LiveNote_roundId_projectId_userId_key" ON "LiveNote"("roundId", "projectId", "userId");
-- CreateIndex
CREATE UNIQUE INDEX "RevealState_sessionId_key" ON "RevealState"("sessionId");
-- AddForeignKey
ALTER TABLE "AudienceFavoriteVote" ADD CONSTRAINT "AudienceFavoriteVote_sessionId_fkey" FOREIGN KEY ("sessionId") REFERENCES "LiveVotingSession"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "AudienceFavoriteVote" ADD CONSTRAINT "AudienceFavoriteVote_audienceVoterId_fkey" FOREIGN KEY ("audienceVoterId") REFERENCES "AudienceVoter"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "AudienceFavoriteVote" ADD CONSTRAINT "AudienceFavoriteVote_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "LiveNote" ADD CONSTRAINT "LiveNote_roundId_fkey" FOREIGN KEY ("roundId") REFERENCES "Round"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "LiveNote" ADD CONSTRAINT "LiveNote_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "LiveNote" ADD CONSTRAINT "LiveNote_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "RevealState" ADD CONSTRAINT "RevealState_sessionId_fkey" FOREIGN KEY ("sessionId") REFERENCES "LiveVotingSession"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -29,7 +29,6 @@ enum UserRole {
MENTOR
OBSERVER
APPLICANT
AWARD_MASTER
AUDIENCE
}
@@ -119,7 +118,6 @@ enum NotificationChannel {
NONE
}
enum PartnerVisibility {
ADMIN_ONLY
JURY_VISIBLE
@@ -134,7 +132,6 @@ enum PartnerType {
OTHER
}
// =============================================================================
// COMPETITION / ROUND ENGINE ENUMS
// =============================================================================
@@ -172,7 +169,6 @@ enum ProjectRoundStateValue {
WITHDRAWN
}
enum CapMode {
HARD
SOFT
@@ -302,6 +298,9 @@ model User {
institution String? // User's institution/organization
metadataJson Json? @db.JsonB
// Mentor onboarding email idempotency: stamped once when MENTOR role is first added.
mentorOnboardingSentAt DateTime?
// Profile
bio String? // User bio for matching with project descriptions
profileImageKey String? // Storage key (e.g., "avatars/user123/1234567890.jpg")
@@ -348,6 +347,7 @@ model User {
resourceAccess ResourceAccess[]
submittedProjects Project[] @relation("ProjectSubmittedBy")
liveVotes LiveVote[]
liveNotes LiveNote[]
// Team membership & mentorship
teamMemberships TeamMember[]
@@ -423,6 +423,13 @@ model User {
// AI Ranking
rankingSnapshots RankingSnapshot[] @relation("TriggeredRankingSnapshots")
// Grand-finale logistics
finalistAttendances AttendingMember[]
// Mentor change requests
mentorChangeRequestsRequested MentorChangeRequest[] @relation("MentorChangeRequester")
mentorChangeRequestsResolved MentorChangeRequest[] @relation("MentorChangeResolver")
@@index([role])
@@index([status])
}
@@ -480,6 +487,10 @@ model Program {
description String?
settingsJson Json? @db.JsonB
// Grand-finale logistics
defaultAttendeeCap Int @default(3) // Max team members allowed at the grand finale per finalist team
visaStatusVisibleToMembers Boolean @default(true) // Whether team members see their own visa status on the applicant dashboard
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -493,6 +504,12 @@ model Program {
mentorMilestones MentorMilestone[]
competitions Competition[]
// Grand-finale logistics
finalistSlotQuotas FinalistSlotQuota[]
waitlistEntries WaitlistEntry[]
hotels Hotel[]
lunchEvent LunchEvent?
@@unique([name, year])
@@index([status])
}
@@ -614,7 +631,9 @@ model Project {
assignments Assignment[]
submittedBy User? @relation("ProjectSubmittedBy", fields: [submittedByUserId], references: [id], onDelete: SetNull)
teamMembers TeamMember[]
mentorAssignment MentorAssignment?
mentorAssignments MentorAssignment[]
mentorFiles MentorFile[]
mentorChangeRequests MentorChangeRequest[]
filteringResults FilteringResult[]
awardEligibilities AwardEligibility[]
awardVotes AwardVote[]
@@ -634,6 +653,15 @@ model Project {
submissionPromotions SubmissionPromotionEvent[]
notificationLogs NotificationLog[]
// Grand-finale logistics
waitlistEntry WaitlistEntry?
finalistConfirmation FinalistConfirmation?
externalLunchAttendees ExternalAttendee[]
// Grand-finale ceremony
audienceFavoriteVotes AudienceFavoriteVote[]
liveNotes LiveNote[]
@@index([programId])
@@index([status])
@@index([tags])
@@ -1165,6 +1193,13 @@ model LiveVotingSession {
audienceRequireId Boolean @default(false) // Require email/phone for audience
audienceVotingDuration Int? // Minutes (null = same as jury)
// Audience favorite-vote window (grand finale)
audiencePhase AudiencePhase @default(CLOSED)
audienceWindowKey String? // 'CATEGORY:STARTUP' | 'CATEGORY:BUSINESS_CONCEPT' | 'OVERALL'
audienceWindowOpenedAt DateTime?
audienceWindowClosesAt DateTime?
allowOverallFavorite Boolean @default(false) // admin toggle, decided day-of
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -1172,6 +1207,8 @@ model LiveVotingSession {
round Round? @relation(fields: [roundId], references: [id], onDelete: Cascade)
votes LiveVote[]
audienceVoters AudienceVoter[]
favoriteVotes AudienceFavoriteVote[]
revealState RevealState?
@@index([status])
}
@@ -1188,6 +1225,9 @@ model LiveVote {
// Criteria scores (used when votingMode="criteria")
criterionScoresJson Json? @db.JsonB // { [criterionId]: score } - null for simple mode
// Optional overall comment from the juror (grand finale)
comment String? @db.Text
// Audience voter link
audienceVoterId String?
@@ -1217,11 +1257,79 @@ model AudienceVoter {
// Relations
session LiveVotingSession @relation(fields: [sessionId], references: [id], onDelete: Cascade)
votes LiveVote[]
favoriteVotes AudienceFavoriteVote[]
@@index([sessionId])
@@index([token])
}
// One pick-one-favorite vote per audience member per voting window.
// windowKey snapshots LiveVotingSession.audienceWindowKey at cast time so
// per-category and overall votes coexist in one table.
model AudienceFavoriteVote {
id String @id @default(cuid())
sessionId String
windowKey String // 'CATEGORY:STARTUP' | 'CATEGORY:BUSINESS_CONCEPT' | 'OVERALL'
projectId String
audienceVoterId String
ipAddress String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
session LiveVotingSession @relation(fields: [sessionId], references: [id], onDelete: Cascade)
audienceVoter AudienceVoter @relation(fields: [audienceVoterId], references: [id], onDelete: Cascade)
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
@@unique([sessionId, windowKey, audienceVoterId])
@@index([sessionId, windowKey, ipAddress])
@@index([sessionId, windowKey, projectId])
}
// Per-juror per-project free-text notes taken during the live ceremony.
// Resurfaces during deliberation.
model LiveNote {
id String @id @default(cuid())
roundId String
projectId String
userId String
content String @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
round Round @relation(fields: [roundId], references: [id], onDelete: Cascade)
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([roundId, projectId, userId])
@@index([userId])
}
// Admin-driven results reveal for the big-screen ceremony view.
// Steps beyond currentStepIndex are never exposed publicly.
model RevealState {
id String @id @default(cuid())
sessionId String @unique
status String @default("DRAFT") // DRAFT | ARMED | REVEALING | DONE
stepsJson Json @db.JsonB // RevealStep[]
currentStepIndex Int @default(-1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
session LiveVotingSession @relation(fields: [sessionId], references: [id], onDelete: Cascade)
}
enum LivePhase {
ON_DECK
PRESENTING
QA
SCORING
}
enum AudiencePhase {
CLOSED
OPEN
}
// =============================================================================
// TEAM MEMBERSHIP
// =============================================================================
@@ -1250,7 +1358,7 @@ model TeamMember {
model MentorAssignment {
id String @id @default(cuid())
projectId String @unique // One mentor per project
projectId String // Team can have multiple mentors; uniqueness enforced via composite below
mentorId String // User with MENTOR role or expertise
// Assignment tracking
@@ -1258,6 +1366,16 @@ model MentorAssignment {
assignedAt DateTime @default(now())
assignedBy String? // Admin who assigned
// Per-assignment email idempotency: stamped once the MENTOR-side notification
// email has been sent (the "you've been assigned a project" email to the mentor).
notificationSentAt DateTime?
// Stamped once the TEAM has been introduced to this mentor (the "meet your
// mentor" email with mentor contact info). Fired by `activateRound` for
// MENTORING rounds and by mentor.assign when the project's MENTORING round
// is already ROUND_ACTIVE. Independent from notificationSentAt above.
teamIntroducedAt DateTime?
// AI assignment metadata
aiConfidenceScore Float?
expertiseMatchScore Float?
@@ -1267,6 +1385,11 @@ model MentorAssignment {
completionStatus String @default("in_progress") // 'in_progress' | 'completed' | 'paused'
lastViewedAt DateTime?
// Drop tracking — null while assignment is active
droppedAt DateTime?
droppedReason String? @db.Text
droppedBy String? // 'mentor' | 'admin' | 'finalist_unconfirmed'
// ── Competition/Round architecture — workspace activation ──
workspaceEnabled Boolean @default(false)
workspaceOpenAt DateTime?
@@ -1279,11 +1402,47 @@ model MentorAssignment {
milestoneCompletions MentorMilestoneCompletion[]
messages MentorMessage[]
files MentorFile[]
changeRequests MentorChangeRequest[] @relation("MentorChangeRequestTarget")
@@unique([projectId, mentorId])
@@index([projectId])
@@index([mentorId])
@@index([method])
}
// =============================================================================
// MENTOR CHANGE REQUESTS
// =============================================================================
enum MentorChangeRequestStatus {
PENDING
RESOLVED
DISMISSED
}
model MentorChangeRequest {
id String @id @default(cuid())
projectId String
targetAssignmentId String? // Optional: a specific co-mentor the request is about
requestedByUserId String?
reason String @db.Text
status MentorChangeRequestStatus @default(PENDING)
resolvedByUserId String?
resolvedAt DateTime?
resolutionNote String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
targetAssignment MentorAssignment? @relation("MentorChangeRequestTarget", fields: [targetAssignmentId], references: [id], onDelete: SetNull)
requestedBy User? @relation("MentorChangeRequester", fields: [requestedByUserId], references: [id], onDelete: SetNull)
resolvedBy User? @relation("MentorChangeResolver", fields: [resolvedByUserId], references: [id])
@@index([projectId])
@@index([status])
@@index([targetAssignmentId])
}
// =============================================================================
// FILTERING ROUND SYSTEM
// =============================================================================
@@ -1574,7 +1733,7 @@ model SpecialAward {
evaluationRoundId String?
juryGroupId String?
eligibilityMode AwardEligibilityMode @default(STAY_IN_MAIN)
decisionMode String? // "JURY_VOTE" | "AWARD_MASTER_DECISION" | "ADMIN_DECISION"
decisionMode String? // "JURY_VOTE" | "ADMIN_DECISION"
shortlistSize Int @default(10)
// Eligibility job tracking
@@ -2083,6 +2242,15 @@ model LiveProgressCursor {
activeOrderIndex Int @default(0)
isPaused Boolean @default(false)
// Per-project ceremony phase + server-stamped timer (grand finale)
projectPhase LivePhase @default(ON_DECK)
phaseStartedAt DateTime?
phaseDurationSeconds Int?
phasePausedAt DateTime?
phasePausedAccumMs Int @default(0)
timingLogJson Json? @db.JsonB // [{projectId, phase, startedAt, endedAt, configuredSeconds, overranSeconds}]
overrideSlide String? // big-screen override: 'welcome' | 'break' | 'deliberation' | 'thanks'
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -2209,6 +2377,7 @@ model Round {
notificationLogs NotificationLog[]
cohorts Cohort[]
liveCursor LiveProgressCursor?
liveNotes LiveNote[]
@@unique([competitionId, slug])
@@unique([competitionId, sortOrder])
@@ -2424,7 +2593,8 @@ model AssignmentIntent {
model MentorFile {
id String @id @default(cuid())
mentorAssignmentId String
projectId String // Primary access scope: files belong to the team
mentorAssignmentId String? // Nullable audit FK: which assignment uploaded; survives mentor drop
uploadedByUserId String
fileName String
@@ -2443,13 +2613,15 @@ model MentorFile {
createdAt DateTime @default(now())
// Relations
mentorAssignment MentorAssignment @relation(fields: [mentorAssignmentId], references: [id], onDelete: Cascade)
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade)
mentorAssignment MentorAssignment? @relation(fields: [mentorAssignmentId], references: [id], onDelete: SetNull)
uploadedBy User @relation("MentorFileUploader", fields: [uploadedByUserId], references: [id])
promotedBy User? @relation("MentorFilePromoter", fields: [promotedByUserId], references: [id])
promotedFile ProjectFile? @relation("PromotedFromMentorFile", fields: [promotedToFileId], references: [id], onDelete: SetNull)
comments MentorFileComment[]
promotionEvents SubmissionPromotionEvent[]
@@index([projectId])
@@index([mentorAssignmentId])
@@index([uploadedByUserId])
}
@@ -2623,3 +2795,298 @@ model ResultUnlockEvent {
@@index([resultLockId])
@@index([unlockedById])
}
// ─────────────────────────────────────────────────────────────────────────────
// Grand-finale logistics (PR 1: finalist confirmation flow)
// ─────────────────────────────────────────────────────────────────────────────
enum WaitlistEntryStatus {
WAITING // available for promotion
PROMOTED // moved into a finalist slot
USED // promoted and confirmation flow completed (declined or accepted)
}
enum FinalistConfirmationStatus {
PENDING // sent, awaiting team response
CONFIRMED // team accepted, attendees selected
DECLINED // team explicitly declined
EXPIRED // deadline passed without response
SUPERSEDED // admin manually overrode (e.g. unconfirmed to allow quota decrease)
}
model FinalistSlotQuota {
id String @id @default(cuid())
programId String
category CompetitionCategory
quota Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
program Program @relation(fields: [programId], references: [id], onDelete: Cascade)
@@unique([programId, category])
@@index([programId])
}
model WaitlistEntry {
id String @id @default(cuid())
programId String
projectId String @unique
category CompetitionCategory
rank Int
status WaitlistEntryStatus @default(WAITING)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
program Program @relation(fields: [programId], references: [id], onDelete: Cascade)
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
@@unique([programId, category, rank])
@@index([programId, category, status])
}
model FinalistConfirmation {
id String @id @default(cuid())
projectId String @unique
category CompetitionCategory
status FinalistConfirmationStatus @default(PENDING)
deadline DateTime
token String @unique
confirmedAt DateTime?
declinedAt DateTime?
declineReason String? // optional free-text on decline
expiredAt DateTime?
reminderSentAt DateTime? // set when the pre-deadline reminder is sent (cron)
finalDocsReminderSentAt DateTime? // set when the grand-final document-upload reminder is sent (cron)
promotedFromWaitlistEntryId String? @unique // null for original finalists
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
attendingMembers AttendingMember[]
@@index([status, deadline]) // for cron scan
@@index([category, status])
}
model AttendingMember {
id String @id @default(cuid())
confirmationId String
userId String // must be a TeamMember of the same project (validated at write time)
needsVisa Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
confirmation FinalistConfirmation @relation(fields: [confirmationId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
flightDetail FlightDetail?
visaApplication VisaApplication?
lunchPick MemberLunchPick?
hotelStay HotelStay?
@@unique([confirmationId, userId])
@@index([userId])
}
// ─────────────────────────────────────────────────────────────────────────────
// Grand-finale logistics (PR 2: hotels + flight tracking)
// ─────────────────────────────────────────────────────────────────────────────
enum FlightDetailStatus {
PENDING // team submitted details, admin not yet reviewed
CONFIRMED // admin verified booking
}
model Hotel {
id String @id @default(cuid())
programId String // many hotels per edition
name String
address String? @db.Text
link String? // external URL to hotel page / booking confirmation
notes String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
program Program @relation(fields: [programId], references: [id], onDelete: Cascade)
stays HotelStay[]
@@index([programId])
}
/// Per-attendee hotel/room assignment (1:1 with AttendingMember, mirrors FlightDetail).
model HotelStay {
id String @id @default(cuid())
attendingMemberId String @unique
hotelId String
roomNumber String?
checkInAt DateTime?
checkOutAt DateTime?
notes String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attendingMember AttendingMember @relation(fields: [attendingMemberId], references: [id], onDelete: Cascade)
hotel Hotel @relation(fields: [hotelId], references: [id], onDelete: Restrict)
@@index([hotelId])
}
model FlightDetail {
id String @id @default(cuid())
attendingMemberId String @unique // 1:1
arrivalAt DateTime?
arrivalFlightNumber String?
arrivalAirport String?
departureAt DateTime?
departureFlightNumber String?
departureAirport String?
status FlightDetailStatus @default(PENDING)
adminNotes String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attendingMember AttendingMember @relation(fields: [attendingMemberId], references: [id], onDelete: Cascade)
@@index([status])
}
// ─────────────────────────────────────────────────────────────────────────────
// Grand-finale visa tracking (PR 4)
// Process metadata only — no document storage. Passport scans / invitation
// letters / decision documents are exchanged over email; this model just
// records what stage the application is at, key dates, and free-text notes.
// ─────────────────────────────────────────────────────────────────────────────
enum VisaStatus {
NOT_NEEDED
REQUESTED
INVITATION_SENT
APPOINTMENT_BOOKED
GRANTED
DENIED
}
model VisaApplication {
id String @id @default(cuid())
attendingMemberId String @unique // 1:1
status VisaStatus @default(REQUESTED)
nationality String? // self-declared, optional
invitationSentAt DateTime?
appointmentAt DateTime?
decisionAt DateTime? // GRANTED or DENIED date
notes String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attendingMember AttendingMember @relation(fields: [attendingMemberId], references: [id], onDelete: Cascade)
@@index([status])
}
// ─────────────────────────────────────────────────────────────────────────────
// Grand-finale lunch event (PR 6)
// Single configurable lunch event per edition. Each attending member has a
// 1:1 MemberLunchPick (auto-created via lunch-pick-sync). External attendees
// can be standalone or attached to a finalist project. Allergens use the
// EU 14 regulated list; dishes carry dietary tags.
// ─────────────────────────────────────────────────────────────────────────────
enum DietaryTag {
VEGETARIAN
VEGAN
GLUTEN_FREE
PESCATARIAN
}
enum Allergen {
GLUTEN
CRUSTACEANS
EGGS
FISH
PEANUTS
SOYBEANS
MILK
TREE_NUTS
CELERY
MUSTARD
SESAME
SULPHITES
LUPIN
MOLLUSCS
}
model LunchEvent {
id String @id @default(cuid())
programId String @unique
enabled Boolean @default(false)
eventAt DateTime?
endAt DateTime?
venue String?
notes String? @db.Text
changeCutoffHours Int @default(48)
reminderHoursBeforeDeadline Int?
cronEnabled Boolean @default(true)
extraRecipients String[] @default([])
reminderSentAt DateTime?
recapSentAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
program Program @relation(fields: [programId], references: [id], onDelete: Cascade)
dishes Dish[]
externalAttendees ExternalAttendee[]
}
model Dish {
id String @id @default(cuid())
lunchEventId String
name String
sortOrder Int @default(0)
dietaryTags DietaryTag[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lunchEvent LunchEvent @relation(fields: [lunchEventId], references: [id], onDelete: Cascade)
memberPicks MemberLunchPick[]
externals ExternalAttendee[]
@@index([lunchEventId])
}
model MemberLunchPick {
id String @id @default(cuid())
attendingMemberId String @unique
dishId String?
allergens Allergen[] @default([])
allergenOther String?
pickedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attendingMember AttendingMember @relation(fields: [attendingMemberId], references: [id], onDelete: Cascade)
dish Dish? @relation(fields: [dishId], references: [id], onDelete: SetNull)
@@index([dishId])
}
model ExternalAttendee {
id String @id @default(cuid())
lunchEventId String
projectId String?
name String
email String?
roleNote String?
dishId String?
allergens Allergen[] @default([])
allergenOther String?
inviteSentAt DateTime? // when the dish-selection email was last sent (null = never invited)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lunchEvent LunchEvent @relation(fields: [lunchEventId], references: [id], onDelete: Cascade)
project Project? @relation(fields: [projectId], references: [id], onDelete: SetNull)
dish Dish? @relation(fields: [dishId], references: [id], onDelete: SetNull)
@@index([lunchEventId])
@@index([projectId])
}

View File

@@ -214,6 +214,78 @@ const NOTIFICATION_EMAIL_SETTINGS = [
sendEmail: true,
},
// Logistics notifications
{
notificationType: 'FINALIST_CONFIRMED',
category: 'logistics',
label: 'Finalist Confirmed',
description: 'Admin alert when a team confirms their grand-finale attendance',
sendEmail: true,
},
{
notificationType: 'FINALIST_DECLINED',
category: 'logistics',
label: 'Finalist Declined',
description: 'Admin alert when a team declines or an admin declines their finalist slot',
sendEmail: true,
},
{
notificationType: 'FINALIST_EXPIRED',
category: 'logistics',
label: 'Finalist Confirmation Expired',
description: 'Admin alert when a pending confirmation passes its deadline without a response',
sendEmail: true,
},
{
notificationType: 'FINALIST_WAITLIST_PROMOTED',
category: 'logistics',
label: 'Waitlist Promoted',
description: 'Admin alert when a waitlisted team is promoted to a confirmed finalist slot',
sendEmail: true,
},
{
notificationType: 'FINALIST_REMINDER',
category: 'logistics',
label: 'Confirmation Reminder',
description: 'Reminder email to the team lead when the confirmation deadline is approaching',
sendEmail: true,
},
{
notificationType: 'FINALIST_WITHDRAWN',
category: 'logistics',
label: 'Finalist Slot Withdrawn',
description: 'Notification to the team when their confirmed grand-finale slot is withdrawn by an admin',
sendEmail: true,
},
{
notificationType: 'TRAVEL_CONFIRMED',
category: 'logistics',
label: 'Travel Confirmed',
description: 'Email to the attendee when their flight and travel details are confirmed',
sendEmail: true,
},
{
notificationType: 'VISA_STATUS_UPDATE',
category: 'logistics',
label: 'Visa Status Update',
description: 'Email to the attendee when their visa application status changes',
sendEmail: true,
},
{
notificationType: 'GRAND_FINAL_DOCS_REMINDER',
category: 'logistics',
label: 'Final Documents Reminder',
description: 'Reminder to finalist teams to upload their Grand Final documents before the deadline',
sendEmail: true,
},
{
notificationType: 'GRAND_FINAL_DOCS_SUBMITTED',
category: 'logistics',
label: 'Final Documents Submitted',
description: 'Notifies the team mentor when a finalist uploads a Grand Final document',
sendEmail: false,
},
// Admin notifications (in-app only by default)
{
notificationType: 'FILTERING_COMPLETE',

View File

@@ -317,7 +317,6 @@ async function main() {
{ email: 'matt@monaco-opc.com', name: 'Matt', role: UserRole.SUPER_ADMIN, password: '195260Mp!' },
{ email: 'matt@letsbe.solutions', name: 'Matt (Applicant)', role: UserRole.APPLICANT, password: '195260Mp!' },
{ email: 'admin@monaco-opc.com', name: 'Admin', role: UserRole.PROGRAM_ADMIN, password: 'Admin123!' },
{ email: 'awards@monaco-opc.com', name: 'Award Director', role: UserRole.AWARD_MASTER, password: 'Awards123!' },
]
const staffUsers: Record<string, string> = {}

View File

@@ -0,0 +1,101 @@
/**
* One-shot: remove leaked test data from dev DB.
*
* Test runs that crashed before reaching `afterAll` left orphan test users +
* programs. This mirrors `tests/helpers.ts#cleanupTestData` with the same
* reverse-dependency order, applied to all programs whose name matches the
* test patterns.
*
* Run: npx tsx scripts/cleanup-test-pollution.ts
*/
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
const TEST_PROGRAM_PATTERNS = [
'Test Program prog-%',
'getCandidates-%',
'bulk-%',
'source-flag-%',
'mentor-files-%',
'mentor-config-%',
]
async function main() {
const programs = await prisma.program.findMany({
where: {
OR: TEST_PROGRAM_PATTERNS.map((p) => ({ name: { startsWith: p.replace('%', '') } })),
},
select: { id: true, name: true },
})
console.log(`Found ${programs.length} test programs:`)
programs.forEach((p) => console.log(` - ${p.id} ${p.name}`))
for (const program of programs) {
const programId = program.id
console.log(`\nCleaning ${program.name}...`)
// MentorAssignment isn't in cleanupTestData — kill it first
const ma = await prisma.mentorAssignment.deleteMany({
where: { project: { programId } },
})
if (ma.count > 0) console.log(` ${ma.count} MentorAssignment`)
// Mirror tests/helpers.ts#cleanupTestData order
await prisma.cohortProject.deleteMany({ where: { cohort: { round: { competition: { programId } } } } })
await prisma.cohort.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.liveProgressCursor.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.filteringResult.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.filteringRule.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.filteringJob.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.assignmentJob.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.conflictOfInterest.deleteMany({ where: { assignment: { round: { competition: { programId } } } } })
await prisma.evaluation.deleteMany({ where: { assignment: { round: { competition: { programId } } } } })
await prisma.assignment.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.evaluationForm.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.fileRequirement.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.gracePeriod.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.reminderLog.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.evaluationSummary.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.evaluationDiscussion.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.projectRoundState.deleteMany({ where: { round: { competition: { programId } } } })
await prisma.awardEligibility.deleteMany({ where: { award: { program: { id: programId } } } })
await prisma.awardVote.deleteMany({ where: { award: { program: { id: programId } } } })
await prisma.awardJuror.deleteMany({ where: { award: { program: { id: programId } } } })
await prisma.specialAward.deleteMany({ where: { programId } })
await prisma.round.deleteMany({ where: { competition: { programId } } })
await prisma.competition.deleteMany({ where: { programId } })
await prisma.projectStatusHistory.deleteMany({ where: { project: { programId } } })
await prisma.projectFile.deleteMany({ where: { project: { programId } } })
await prisma.projectTag.deleteMany({ where: { project: { programId } } })
await prisma.project.deleteMany({ where: { programId } })
await prisma.program.deleteMany({ where: { id: programId } })
console.log(' cascade complete')
}
// Delete test users (@test.local). Catch any audit-log refs first.
const testUsers = await prisma.user.findMany({
where: { email: { endsWith: '@test.local' } },
select: { id: true },
})
const testUserIds = testUsers.map((u) => u.id)
console.log(`\nDeleting ${testUserIds.length} @test.local users...`)
if (testUserIds.length > 0) {
await prisma.decisionAuditLog.deleteMany({ where: { actorId: { in: testUserIds } } })
await prisma.auditLog.deleteMany({ where: { userId: { in: testUserIds } } })
// Any remaining MentorAssignments referencing these users (e.g., from other tests)
await prisma.mentorAssignment.deleteMany({ where: { mentorId: { in: testUserIds } } })
await prisma.user.deleteMany({ where: { id: { in: testUserIds } } })
}
console.log('\nDone.')
}
main()
.then(() => prisma.$disconnect())
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})

View File

@@ -0,0 +1,33 @@
// scripts/configure-grand-final-requirements.mjs
// Usage: node scripts/configure-grand-final-requirements.mjs (dry-run, prints plan)
// node scripts/configure-grand-final-requirements.mjs --apply (writes)
import { PrismaClient } from '@prisma/client'
const p = new PrismaClient()
const APPLY = process.argv.includes('--apply')
const TARGET = [
{ name: 'Final Presentation', acceptedMimeTypes: ['application/pdf'], sortOrder: 1, renameFrom: 'PDF presentation support' },
{ name: 'Final Business Plan', acceptedMimeTypes: ['application/pdf'], sortOrder: 2 },
{ name: '1-minute Video', acceptedMimeTypes: ['video/*'], sortOrder: 3, renameFrom: '1 minute video' },
{ name: 'Executive Summary', acceptedMimeTypes: ['application/pdf'], sortOrder: 4 },
]
const run = async () => {
const round = await p.round.findFirst({ where: { roundType: 'LIVE_FINAL' }, orderBy: { sortOrder: 'desc' } })
if (!round) throw new Error('No LIVE_FINAL round')
const existing = await p.fileRequirement.findMany({ where: { roundId: round.id } })
console.log(`Round "${round.name}" (${round.id}); existing reqs: ${existing.map((r) => r.name).join(', ') || 'none'}`)
for (const t of TARGET) {
const match = existing.find((r) => r.name === t.name || (t.renameFrom && r.name === t.renameFrom))
if (match) {
console.log(`UPDATE "${match.name}" -> name="${t.name}" required=true sort=${t.sortOrder} mimes=${t.acceptedMimeTypes}`)
if (APPLY) await p.fileRequirement.update({ where: { id: match.id }, data: { name: t.name, acceptedMimeTypes: t.acceptedMimeTypes, isRequired: true, sortOrder: t.sortOrder } })
} else {
console.log(`CREATE "${t.name}" required=true sort=${t.sortOrder} mimes=${t.acceptedMimeTypes}`)
if (APPLY) await p.fileRequirement.create({ data: { roundId: round.id, name: t.name, acceptedMimeTypes: t.acceptedMimeTypes, isRequired: true, sortOrder: t.sortOrder } })
}
}
console.log(APPLY ? 'APPLIED.' : 'DRY-RUN (pass --apply to write).')
}
run().catch((e) => { console.error(e); process.exit(1) }).finally(() => p.$disconnect())

View File

@@ -58,6 +58,7 @@ export default function EditAwardPage({
const [votingEndAt, setVotingEndAt] = useState('')
const [evaluationRoundId, setEvaluationRoundId] = useState('')
const [eligibilityMode, setEligibilityMode] = useState<'STAY_IN_MAIN' | 'SEPARATE_POOL'>('STAY_IN_MAIN')
const [decisionMode, setDecisionMode] = useState<'JURY_VOTE' | 'ADMIN_DECISION'>('JURY_VOTE')
// Helper to format date for datetime-local input
const formatDateForInput = (date: Date | string | null | undefined): string => {
@@ -80,6 +81,7 @@ export default function EditAwardPage({
setVotingEndAt(formatDateForInput(award.votingEndAt))
setEvaluationRoundId(award.evaluationRoundId || '')
setEligibilityMode(award.eligibilityMode as 'STAY_IN_MAIN' | 'SEPARATE_POOL')
setDecisionMode((award.decisionMode as typeof decisionMode) || 'JURY_VOTE')
}
}, [award])
@@ -98,6 +100,7 @@ export default function EditAwardPage({
votingEndAt: votingEndAt ? new Date(votingEndAt) : undefined,
evaluationRoundId: evaluationRoundId || undefined,
eligibilityMode,
decisionMode,
})
toast.success('Award updated')
router.push(`/admin/awards/${awardId}`)
@@ -222,6 +225,22 @@ export default function EditAwardPage({
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="decisionMode">Decision Mode</Label>
<Select
value={decisionMode}
onValueChange={(v) => setDecisionMode(v as typeof decisionMode)}
>
<SelectTrigger id="decisionMode">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="JURY_VOTE">Jury Vote tallied from all jurors</SelectItem>
<SelectItem value="ADMIN_DECISION">Admin Decision admin selects winner</SelectItem>
</SelectContent>
</Select>
</div>
{scoringMode === 'RANKED' && (
<div className="space-y-2">
<Label htmlFor="maxPicks">Max Ranked Picks</Label>

View File

@@ -15,6 +15,7 @@ import {
import { Badge } from '@/components/ui/badge'
import { Skeleton } from '@/components/ui/skeleton'
import { Switch } from '@/components/ui/switch'
import { Checkbox } from '@/components/ui/checkbox'
import { Label } from '@/components/ui/label'
import {
Table,
@@ -55,6 +56,8 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import { Input } from '@/components/ui/input'
import { Progress } from '@/components/ui/progress'
import { UserAvatar } from '@/components/shared/user-avatar'
import { BulkInviteForm } from '@/components/shared/bulk-invite-form'
import { Separator } from '@/components/ui/separator'
import { AnimatedCard } from '@/components/shared/animated-container'
import { Pagination } from '@/components/shared/pagination'
import { EmailPreviewDialog } from '@/components/admin/round/email-preview-dialog'
@@ -332,20 +335,20 @@ function RoundsDndGrid({
function ConfidenceBadge({ confidence }: { confidence: number }) {
if (confidence > 0.8) {
return (
<Badge variant="outline" className="border-emerald-300 bg-emerald-50 text-emerald-700 dark:border-emerald-700 dark:bg-emerald-950/30 dark:text-emerald-400 text-xs tabular-nums">
<Badge variant="outline" className="border-emerald-300 bg-emerald-50 text-emerald-700 text-xs tabular-nums">
{Math.round(confidence * 100)}%
</Badge>
)
}
if (confidence >= 0.5) {
return (
<Badge variant="outline" className="border-amber-300 bg-amber-50 text-amber-700 dark:border-amber-700 dark:bg-amber-950/30 dark:text-amber-400 text-xs tabular-nums">
<Badge variant="outline" className="border-amber-300 bg-amber-50 text-amber-700 text-xs tabular-nums">
{Math.round(confidence * 100)}%
</Badge>
)
}
return (
<Badge variant="outline" className="border-red-300 bg-red-50 text-red-700 dark:border-red-700 dark:bg-red-950/30 dark:text-red-400 text-xs tabular-nums">
<Badge variant="outline" className="border-red-300 bg-red-50 text-red-700 text-xs tabular-nums">
{Math.round(confidence * 100)}%
</Badge>
)
@@ -363,6 +366,8 @@ export default function AwardDetailPage({
const [isPollingJob, setIsPollingJob] = useState(false)
const pollingIntervalRef = useRef<ReturnType<typeof setInterval> | null>(null)
const [selectedJurorId, setSelectedJurorId] = useState('')
const [selectedGroupId, setSelectedGroupId] = useState('')
const [selectedGroupMembers, setSelectedGroupMembers] = useState<Set<string>>(new Set())
const [includeSubmitted, setIncludeSubmitted] = useState(true)
const [addProjectDialogOpen, setAddProjectDialogOpen] = useState(false)
const [projectSearchQuery, setProjectSearchQuery] = useState('')
@@ -403,9 +408,17 @@ export default function AwardDetailPage({
// Deferred queries - only load when needed
const { data: allUsers } = trpc.user.list.useQuery(
{ role: 'JURY_MEMBER', page: 1, perPage: 100 },
{ page: 1, perPage: 100, roles: ['JURY_MEMBER'] },
{ enabled: activeTab === 'jurors' }
)
const { data: juryGroups } = trpc.juryGroup.list.useQuery(
{ competitionId: award?.competition?.id ?? '' },
{ enabled: activeTab === 'jurors' && !!award?.competition?.id }
)
const { data: selectedGroupDetail } = trpc.juryGroup.getById.useQuery(
{ id: selectedGroupId },
{ enabled: !!selectedGroupId }
)
const { data: allProjects } = trpc.project.list.useQuery(
{ programId: award?.programId ?? '', perPage: 200 },
{ enabled: !!award?.programId && addProjectDialogOpen }
@@ -484,6 +497,29 @@ export default function AwardDetailPage({
},
onError: () => toast.error('Failed to update chair status'),
})
const bulkAddJurors = trpc.specialAward.bulkAddJurors.useMutation({
onSuccess: (data) => {
utils.specialAward.listJurors.invalidate({ awardId })
toast.success(`${data.added} juror(s) added from jury group`)
setSelectedGroupId('')
setSelectedGroupMembers(new Set())
},
onError: (err) => toast.error(err.message),
})
const bulkInvite = trpc.specialAward.bulkInviteJurors.useMutation({
onSuccess: (data) => {
utils.specialAward.listJurors.invalidate({ awardId })
toast.success(`${data.created} invited, ${data.existing} already existed${data.errors > 0 ? `, ${data.errors} failed` : ''}`)
},
onError: (err) => toast.error(err.message),
})
const notifyJurors = trpc.specialAward.notifyJurors.useMutation({
onSuccess: (data) => {
const failedNote = data.failed > 0 ? ` (${data.failed} failed)` : ''
toast.success(`Reminder sent to ${data.sent} of ${data.targeted} juror(s)${failedNote}`)
},
onError: (err) => toast.error(err.message),
})
const setWinner = trpc.specialAward.setWinner.useMutation({
onSuccess: invalidateAward,
})
@@ -861,8 +897,8 @@ export default function AwardDetailPage({
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Eligible</p>
<p className="text-2xl font-bold tabular-nums">{award.eligibleCount}</p>
</div>
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-emerald-100 dark:bg-emerald-950/40">
<CheckCircle2 className="h-5 w-5 text-emerald-600 dark:text-emerald-400" />
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-emerald-100">
<CheckCircle2 className="h-5 w-5 text-emerald-600" />
</div>
</div>
</CardContent>
@@ -874,8 +910,8 @@ export default function AwardDetailPage({
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Evaluated</p>
<p className="text-2xl font-bold tabular-nums">{(award as any).totalAssessed ?? award._count.eligibilities}</p>
</div>
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-950/40">
<ListChecks className="h-5 w-5 text-blue-600 dark:text-blue-400" />
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-blue-100">
<ListChecks className="h-5 w-5 text-blue-600" />
</div>
</div>
</CardContent>
@@ -887,8 +923,8 @@ export default function AwardDetailPage({
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Jurors</p>
<p className="text-2xl font-bold tabular-nums">{award._count.jurors}</p>
</div>
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-violet-100 dark:bg-violet-950/40">
<Users className="h-5 w-5 text-violet-600 dark:text-violet-400" />
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-violet-100">
<Users className="h-5 w-5 text-violet-600" />
</div>
</div>
</CardContent>
@@ -900,8 +936,8 @@ export default function AwardDetailPage({
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Votes</p>
<p className="text-2xl font-bold tabular-nums">{award._count.votes}</p>
</div>
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-amber-100 dark:bg-amber-950/40">
<Vote className="h-5 w-5 text-amber-600 dark:text-amber-400" />
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-amber-100">
<Vote className="h-5 w-5 text-amber-600" />
</div>
</div>
</CardContent>
@@ -1306,7 +1342,7 @@ export default function AwardDetailPage({
{/* Jurors Tab */}
<TabsContent value="jurors" className="space-y-4">
<div className="flex gap-2">
<div className="flex flex-wrap items-center gap-2">
<Select value={selectedJurorId} onValueChange={setSelectedJurorId}>
<SelectTrigger className="w-64">
<SelectValue placeholder="Select a juror..." />
@@ -1326,6 +1362,168 @@ export default function AwardDetailPage({
<UserPlus className="mr-2 h-4 w-4" />
Add Juror
</Button>
{jurors && jurors.length > 0 && (
<Button
variant="outline"
onClick={() => notifyJurors.mutate({ awardId })}
disabled={notifyJurors.isPending}
className="ml-auto"
>
<Mail className="mr-2 h-4 w-4" />
{notifyJurors.isPending
? 'Sending...'
: `Send reminder to all (${jurors.length})`}
</Button>
)}
</div>
{/* Import from Jury Group */}
{juryGroups && juryGroups.length > 0 && (
<>
<Separator className="my-4" />
<div className="space-y-3">
<h3 className="text-sm font-medium flex items-center gap-2">
<Users className="h-4 w-4" />
Import from Jury Group
</h3>
<p className="text-xs text-muted-foreground">
Select a jury group and pick which members to add as jurors for this award.
</p>
<Select
value={selectedGroupId}
onValueChange={(val) => {
setSelectedGroupId(val)
setSelectedGroupMembers(new Set())
}}
>
<SelectTrigger className="w-80">
<SelectValue placeholder="Select a jury group..." />
</SelectTrigger>
<SelectContent>
{juryGroups.map((g) => (
<SelectItem key={g.id} value={g.id}>
{g.name} ({g._count.members} members)
</SelectItem>
))}
</SelectContent>
</Select>
{selectedGroupDetail && selectedGroupDetail.members.length > 0 && (() => {
const jurorUserIds = new Set(jurors?.map((j) => j.userId) || [])
const addableMembers = selectedGroupDetail.members.filter(
(m) => !jurorUserIds.has(m.user.id)
)
const alreadyAdded = selectedGroupDetail.members.filter(
(m) => jurorUserIds.has(m.user.id)
)
return (
<Card>
<CardHeader className="py-3 px-4">
<div className="flex items-center justify-between">
<CardDescription>
{addableMembers.length} available to add
{alreadyAdded.length > 0 && ` · ${alreadyAdded.length} already assigned`}
</CardDescription>
{addableMembers.length > 0 && (
<Button
variant="ghost"
size="sm"
onClick={() => {
if (selectedGroupMembers.size === addableMembers.length) {
setSelectedGroupMembers(new Set())
} else {
setSelectedGroupMembers(new Set(addableMembers.map((m) => m.user.id)))
}
}}
>
{selectedGroupMembers.size === addableMembers.length ? 'Deselect All' : 'Select All'}
</Button>
)}
</div>
</CardHeader>
<CardContent className="px-4 pb-3 space-y-2">
{addableMembers.map((m) => (
<label
key={m.user.id}
className="flex items-center gap-3 rounded-md p-2 hover:bg-muted/50 cursor-pointer"
>
<Checkbox
checked={selectedGroupMembers.has(m.user.id)}
onCheckedChange={(checked) => {
const next = new Set(selectedGroupMembers)
if (checked) next.add(m.user.id)
else next.delete(m.user.id)
setSelectedGroupMembers(next)
}}
/>
<div className="min-w-0">
<p className="text-sm font-medium">{m.user.name || 'Unnamed'}</p>
<p className="text-xs text-muted-foreground">{m.user.email}</p>
</div>
<Badge variant="outline" className="ml-auto text-xs">
{m.role}
</Badge>
</label>
))}
{alreadyAdded.map((m) => (
<div
key={m.user.id}
className="flex items-center gap-3 rounded-md p-2 opacity-50"
>
<Checkbox checked disabled />
<div className="min-w-0">
<p className="text-sm font-medium">{m.user.name || 'Unnamed'}</p>
<p className="text-xs text-muted-foreground">{m.user.email}</p>
</div>
<Badge variant="secondary" className="ml-auto text-xs">
Already added
</Badge>
</div>
))}
{addableMembers.length > 0 && (
<Button
className="w-full mt-2"
disabled={selectedGroupMembers.size === 0 || bulkAddJurors.isPending}
onClick={() => {
bulkAddJurors.mutate({
awardId,
userIds: Array.from(selectedGroupMembers),
})
}}
>
{bulkAddJurors.isPending ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<UserPlus className="mr-2 h-4 w-4" />
)}
Add {selectedGroupMembers.size} Selected Juror{selectedGroupMembers.size !== 1 ? 's' : ''}
</Button>
)}
</CardContent>
</Card>
)
})()}
</div>
</>
)}
<Separator className="my-4" />
<div className="space-y-2">
<h3 className="text-sm font-medium">Invite New Jurors by Email</h3>
<p className="text-xs text-muted-foreground">
Invite new users who don&apos;t have accounts yet. They&apos;ll receive an invitation email and be added as jurors for this award.
</p>
<BulkInviteForm
onSubmit={async (rows) => {
await bulkInvite.mutateAsync({
awardId,
invitees: rows.map((r) => ({ name: r.name || undefined, email: r.email })),
})
}}
isPending={bulkInvite.isPending}
submitLabel="Invite & Add as Jurors"
/>
</div>
{jurors && jurors.length > 0 ? (
@@ -1370,11 +1568,23 @@ export default function AwardDetailPage({
/>
</TableCell>
<TableCell className="text-right">
<Button
variant="ghost"
size="sm"
onClick={() =>
notifyJurors.mutate({ awardId, userIds: [j.userId] })
}
disabled={notifyJurors.isPending}
title="Send reminder email"
>
<Mail className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => handleRemoveJuror(j.userId)}
disabled={removeJuror.isPending}
title="Remove juror"
>
<X className="h-4 w-4" />
</Button>
@@ -1402,7 +1612,7 @@ export default function AwardDetailPage({
{/* Rounds Tab */}
<TabsContent value="rounds" className="space-y-4">
{award.eligibilityMode !== 'SEPARATE_POOL' && (
<div className="flex items-start gap-2 rounded-md border border-blue-200 bg-blue-50 p-3 text-blue-800 dark:border-blue-800 dark:bg-blue-950/30 dark:text-blue-300">
<div className="flex items-start gap-2 rounded-md border border-blue-200 bg-blue-50 p-3 text-blue-800">
<Info className="h-4 w-4 mt-0.5 shrink-0" />
<p className="text-sm">
Rounds are used in <strong>Separate Pool</strong> mode to create a dedicated evaluation track for shortlisted projects.
@@ -1410,7 +1620,7 @@ export default function AwardDetailPage({
</div>
)}
{!award.competitionId && (
<div className="flex items-start gap-2 rounded-md border border-amber-200 bg-amber-50 p-3 text-amber-800 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-300">
<div className="flex items-start gap-2 rounded-md border border-amber-200 bg-amber-50 p-3 text-amber-800">
<AlertCircle className="h-4 w-4 mt-0.5 shrink-0" />
<p className="text-sm">
Link this award to a competition first before creating rounds.
@@ -1540,16 +1750,16 @@ export default function AwardDetailPage({
return (
<TableRow
key={r.project.id}
className={isWinner ? 'bg-amber-50/80 dark:bg-amber-950/20' : ''}
className={isWinner ? 'bg-amber-50/80' : ''}
>
<TableCell>
<span className={`inline-flex h-7 w-7 items-center justify-center rounded-full text-xs font-bold ${
i === 0
? 'bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300'
? 'bg-amber-100 text-amber-800'
: i === 1
? 'bg-slate-200 text-slate-700 dark:bg-slate-700 dark:text-slate-300'
? 'bg-slate-200 text-slate-700'
: i === 2
? 'bg-orange-100 text-orange-800 dark:bg-orange-900/40 dark:text-orange-300'
? 'bg-orange-100 text-orange-800'
: 'text-muted-foreground'
}`}>
{i + 1}

View File

@@ -0,0 +1,7 @@
import { FinalsDocumentsReview } from '@/components/finals/finals-documents-review'
export const dynamic = 'force-dynamic'
export default function AdminFinalsDocumentsPage() {
return <FinalsDocumentsReview />
}

View File

@@ -1,6 +1,7 @@
'use client'
import { use, useState } from 'react'
import { BulkInviteForm } from '@/components/shared/bulk-invite-form'
import Link from 'next/link'
import type { Route } from 'next'
import { useRouter } from 'next/navigation'
@@ -94,7 +95,6 @@ export default function JuryGroupDetailPage({ params }: JuryGroupDetailPageProps
const { data: userSearchResults, isLoading: loadingUsers } = trpc.user.list.useQuery(
{
role: 'JURY_MEMBER',
search: userSearch,
page: 1,
perPage: 20,
@@ -120,6 +120,14 @@ export default function JuryGroupDetailPage({ params }: JuryGroupDetailPageProps
onError: (err) => toast.error(err.message),
})
const bulkInviteMutation = trpc.juryGroup.bulkInviteMembers.useMutation({
onSuccess: (data) => {
utils.juryGroup.getById.invalidate({ id: groupId })
toast.success(`${data.created} invited, ${data.existing} already existed${data.errors > 0 ? `, ${data.errors} failed` : ''}`)
},
onError: (err) => toast.error(err.message),
})
const removeMemberMutation = trpc.juryGroup.removeMember.useMutation({
onSuccess: () => {
utils.juryGroup.getById.invalidate({ id: groupId })
@@ -339,6 +347,28 @@ export default function JuryGroupDetailPage({ params }: JuryGroupDetailPageProps
)}
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle className="text-base">Invite New Members by Email</CardTitle>
<CardDescription>
Invite new users who don&apos;t have accounts yet. They&apos;ll receive an invitation email and be added to this jury group.
</CardDescription>
</CardHeader>
<CardContent>
<BulkInviteForm
onSubmit={async (rows) => {
await bulkInviteMutation.mutateAsync({
juryGroupId: groupId,
role: 'MEMBER',
invitees: rows.map((r) => ({ name: r.name || undefined, email: r.email })),
})
}}
isPending={bulkInviteMutation.isPending}
submitLabel="Invite & Add Members"
/>
</CardContent>
</Card>
</TabsContent>
{/* Settings Tab */}

View File

@@ -35,7 +35,7 @@ import {
import { Textarea } from '@/components/ui/textarea'
import { toast } from 'sonner'
import { cn, formatEnumLabel } from '@/lib/utils'
import { Plus, Scale, Users, Loader2, ArrowRight, CircleDot } from 'lucide-react'
import { Plus, Scale, Users, Loader2, ArrowRight, CircleDot, Trophy } from 'lucide-react'
const capModeLabels = {
HARD: 'Hard Cap',
@@ -301,10 +301,10 @@ function CompetitionJuriesSection({ competition }: CompetitionJuriesSectionProps
</div>
</div>
{/* Round assignments */}
{(group as any).rounds?.length > 0 && (
{/* Round + Special-award assignments */}
{((group as any).rounds?.length > 0 || (group as any).awards?.length > 0) && (
<div className="flex flex-wrap gap-1.5">
{(group as any).rounds.map((r: any) => (
{(group as any).rounds?.map((r: any) => (
<Badge
key={r.id}
variant="outline"
@@ -319,6 +319,21 @@ function CompetitionJuriesSection({ competition }: CompetitionJuriesSectionProps
{r.name}
</Badge>
))}
{(group as any).awards?.map((a: any) => (
<Badge
key={a.id}
variant="outline"
className={cn(
'text-[10px] gap-1',
a.status === 'VOTING_OPEN' && 'border-amber-300 bg-amber-50 text-amber-700',
a.status === 'CLOSED' && 'border-emerald-300 bg-emerald-50 text-emerald-700',
(a.status === 'DRAFT' || a.status === 'NOMINATIONS_OPEN') && 'border-slate-200 text-slate-500',
)}
>
<Trophy className="h-2.5 w-2.5" />
{a.name}
</Badge>
))}
</div>
)}

View File

@@ -75,7 +75,6 @@ const ROLE_OPTIONS = [
{ value: 'MENTOR', label: 'Mentors' },
{ value: 'OBSERVER', label: 'Observers' },
{ value: 'APPLICANT', label: 'Applicants' },
{ value: 'AWARD_MASTER', label: 'Award Masters' },
]
type AccessRule =

View File

@@ -60,7 +60,6 @@ const ROLE_OPTIONS = [
{ value: 'MENTOR', label: 'Mentors' },
{ value: 'OBSERVER', label: 'Observers' },
{ value: 'APPLICANT', label: 'Applicants' },
{ value: 'AWARD_MASTER', label: 'Award Masters' },
]
type AccessRule =

View File

@@ -0,0 +1,86 @@
'use client'
import { useState } from 'react'
import { useEdition } from '@/contexts/edition-context'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import {
CheckCircle2,
Hotel as HotelIcon,
Plane,
Salad,
ScrollText,
Stamp,
} from 'lucide-react'
import { ConfirmationsTab } from '@/components/admin/logistics/confirmations-tab'
import { TravelTab } from '@/components/admin/logistics/travel-tab'
import { HotelsTab } from '@/components/admin/logistics/hotels-tab'
import { VisasTab } from '@/components/admin/logistics/visas-tab'
import { LunchTab } from '@/components/admin/logistics/lunch-tab'
import { EmailTemplatesTab } from '@/components/admin/logistics/email-templates-tab'
export default function LogisticsPage() {
const { currentEdition } = useEdition()
const [tab, setTab] = useState('confirmations')
if (!currentEdition) {
return (
<p className="text-muted-foreground py-12 text-center text-sm">
Select an edition to view logistics.
</p>
)
}
const programId = currentEdition.id
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Logistics</h1>
<p className="text-muted-foreground">
Operational hub for the grand finale: confirmations, travel, hotels, and more.
</p>
</div>
<Tabs value={tab} onValueChange={setTab} className="space-y-6">
<TabsList className="h-auto w-full justify-start overflow-x-auto pb-2">
<TabsTrigger value="confirmations">
<CheckCircle2 className="mr-2 h-4 w-4" /> Confirmations
</TabsTrigger>
<TabsTrigger value="travel">
<Plane className="mr-2 h-4 w-4" /> Travel
</TabsTrigger>
<TabsTrigger value="hotels">
<HotelIcon className="mr-2 h-4 w-4" /> Hotels
</TabsTrigger>
<TabsTrigger value="visas">
<Stamp className="mr-2 h-4 w-4" /> Visas
</TabsTrigger>
<TabsTrigger value="lunch">
<Salad className="mr-2 h-4 w-4" /> Lunch
</TabsTrigger>
<TabsTrigger value="email-templates">
<ScrollText className="mr-2 h-4 w-4" /> Email Templates
</TabsTrigger>
</TabsList>
<TabsContent value="confirmations">
<ConfirmationsTab programId={programId} />
</TabsContent>
<TabsContent value="travel">
<TravelTab programId={programId} />
</TabsContent>
<TabsContent value="hotels">
<HotelsTab programId={programId} />
</TabsContent>
<TabsContent value="visas">
<VisasTab programId={programId} />
</TabsContent>
<TabsContent value="lunch">
<LunchTab programId={programId} />
</TabsContent>
<TabsContent value="email-templates">
<EmailTemplatesTab programId={programId} />
</TabsContent>
</Tabs>
</div>
)
}

View File

@@ -48,7 +48,24 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import { UserAvatar } from '@/components/shared/user-avatar'
import { Checkbox } from '@/components/ui/checkbox'
import {
ArrowLeft,
Save,
@@ -68,6 +85,11 @@ import {
LogIn,
Calendar,
Clock,
Link as LinkIcon,
Copy,
Check,
Plus,
X,
} from 'lucide-react'
import { getCountryName, getCountryFlag } from '@/lib/countries'
import { formatRelativeTime } from '@/lib/utils'
@@ -96,7 +118,6 @@ const roleColors: Record<string, 'default' | 'outline' | 'secondary'> = {
PROGRAM_ADMIN: 'default',
SUPER_ADMIN: 'default',
APPLICANT: 'secondary',
AWARD_MASTER: 'outline',
AUDIENCE: 'outline',
}
@@ -111,8 +132,45 @@ export default function MemberDetailPage() {
const isSuperAdmin = currentUser?.role === 'SUPER_ADMIN'
const updateUser = trpc.user.update.useMutation()
const sendInvitation = trpc.user.sendInvitation.useMutation()
const generateAccessLink = trpc.user.generateAccessLink.useMutation()
const startImpersonation = trpc.user.startImpersonation.useMutation()
const [accessLinkOpen, setAccessLinkOpen] = useState(false)
const [accessLink, setAccessLink] = useState<{
url: string
kind: 'setup' | 'magic_login'
expiresAt: Date
} | null>(null)
const [linkCopied, setLinkCopied] = useState(false)
const handleGenerateAccessLink = async () => {
try {
const result = await generateAccessLink.mutateAsync({ userId })
setAccessLink({
url: result.url,
kind: result.kind,
expiresAt: new Date(result.expiresAt),
})
setLinkCopied(false)
setAccessLinkOpen(true)
} catch (error) {
toast.error(
error instanceof Error ? error.message : 'Failed to generate access link'
)
}
}
const handleCopyAccessLink = async () => {
if (!accessLink) return
try {
await navigator.clipboard.writeText(accessLink.url)
setLinkCopied(true)
toast.success('Link copied to clipboard')
} catch {
toast.error('Could not copy — please select and copy the link manually')
}
}
// Mentor assignments (only fetched for mentors)
const { data: mentorAssignments } = trpc.mentor.listAssignments.useQuery(
{ mentorId: userId, page: 1, perPage: 50 },
@@ -137,6 +195,11 @@ export default function MemberDetailPage() {
const [maxAssignments, setMaxAssignments] = useState<string>('')
const [showSuperAdminConfirm, setShowSuperAdminConfirm] = useState(false)
const [pendingSuperAdminRole, setPendingSuperAdminRole] = useState(false)
const [pendingAdditionalRole, setPendingAdditionalRole] = useState<{
role: 'JURY_MEMBER' | 'OBSERVER' | 'MENTOR'
action: 'add' | 'remove'
} | null>(null)
const [additionalRoles, setAdditionalRoles] = useState<string[]>([])
useEffect(() => {
if (user) {
@@ -146,16 +209,19 @@ export default function MemberDetailPage() {
setStatus(user.status)
setExpertiseTags(user.expertiseTags || [])
setMaxAssignments(user.maxAssignments?.toString() || '')
setAdditionalRoles(user.roles?.filter((r: string) => r !== user.role) || [])
}
}, [user])
const handleSave = async () => {
try {
const allRoles = [role, ...additionalRoles.filter((r) => r !== role)] as Array<'SUPER_ADMIN' | 'PROGRAM_ADMIN' | 'JURY_MEMBER' | 'MENTOR' | 'OBSERVER' | 'APPLICANT' | 'AUDIENCE'>
await updateUser.mutateAsync({
id: userId,
email: email || undefined,
name: name || null,
role: role as 'SUPER_ADMIN' | 'PROGRAM_ADMIN' | 'AWARD_MASTER' | 'JURY_MEMBER' | 'MENTOR' | 'OBSERVER' | 'APPLICANT' | 'AUDIENCE',
role: role as typeof allRoles[number],
roles: allRoles,
status: status as 'NONE' | 'INVITED' | 'ACTIVE' | 'SUSPENDED',
expertiseTags,
maxAssignments: maxAssignments ? parseInt(maxAssignments) : null,
@@ -278,6 +344,21 @@ export default function MemberDetailPage() {
{user.status === 'INVITED' ? 'Resend Invite' : 'Send Invitation'}
</Button>
)}
{user.status !== 'SUSPENDED' && (
<Button
variant="outline"
onClick={handleGenerateAccessLink}
disabled={generateAccessLink.isPending}
title="Generate a one-time link to share manually if email isn't reaching them"
>
{generateAccessLink.isPending ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<LinkIcon className="mr-2 h-4 w-4" />
)}
Copy Access Link
</Button>
)}
<Button
variant="outline"
onClick={handleImpersonate}
@@ -617,11 +698,81 @@ export default function MemberDetailPage() {
<SelectItem value="MENTOR">Mentor</SelectItem>
<SelectItem value="OBSERVER">Observer</SelectItem>
<SelectItem value="APPLICANT">Applicant</SelectItem>
<SelectItem value="AWARD_MASTER">Award Master</SelectItem>
<SelectItem value="AUDIENCE">Audience</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label>Additional Roles</Label>
<p className="text-xs text-muted-foreground">
Grant additional dashboard access beyond the primary role.
Click the menu to add or remove a role you&apos;ll be
asked to confirm each change.
</p>
<div className="flex flex-wrap items-center gap-2">
{additionalRoles.length === 0 ? (
<span className="text-sm text-muted-foreground italic">
None only the primary role above
</span>
) : (
additionalRoles.map((r) => (
<Badge
key={r}
variant={roleColors[r] || 'secondary'}
className="gap-1.5 pl-2 pr-1 py-0.5"
>
{r.replace(/_/g, ' ')}
<button
type="button"
aria-label={`Remove ${r.replace(/_/g, ' ')} role`}
className="rounded-full hover:bg-foreground/10 p-0.5 transition-colors"
onClick={() =>
setPendingAdditionalRole({
role: r as 'JURY_MEMBER' | 'OBSERVER' | 'MENTOR',
action: 'remove',
})
}
>
<X className="h-3 w-3" />
</button>
</Badge>
))
)}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="sm" type="button">
<Plus className="mr-1 h-3.5 w-3.5" />
Manage roles
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-56">
<DropdownMenuLabel>Toggle additional roles</DropdownMenuLabel>
<DropdownMenuSeparator />
{(['JURY_MEMBER', 'OBSERVER', 'MENTOR'] as const)
.filter((r) => r !== role)
.map((r) => {
const isAssigned = additionalRoles.includes(r)
return (
<DropdownMenuCheckboxItem
key={r}
checked={isAssigned}
onSelect={(e) => {
e.preventDefault()
setPendingAdditionalRole({
role: r,
action: isAssigned ? 'remove' : 'add',
})
}}
>
{r.replace(/_/g, ' ')}
</DropdownMenuCheckboxItem>
)
})}
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="status">Status</Label>
<Select value={status} onValueChange={setStatus}>
@@ -791,6 +942,81 @@ export default function MemberDetailPage() {
</Tabs>
{/* Super Admin Confirmation Dialog */}
<AlertDialog
open={pendingAdditionalRole !== null}
onOpenChange={(open) => { if (!open) setPendingAdditionalRole(null) }}
>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
{pendingAdditionalRole?.action === 'add' ? 'Add' : 'Remove'}{' '}
{pendingAdditionalRole?.role.replace(/_/g, ' ')} role?
</AlertDialogTitle>
<AlertDialogDescription>
{pendingAdditionalRole?.action === 'add' ? (
<>
This will give <strong>{name || user?.name || 'this user'}</strong>{' '}
the {pendingAdditionalRole.role.replace(/_/g, ' ')} dashboard
in addition to their primary role. They&apos;ll be able to
switch between dashboards from the role switcher. Click
&ldquo;Save changes&rdquo; below to apply.
</>
) : (
<>
This will revoke the {pendingAdditionalRole?.role.replace(/_/g, ' ')}
{' '}dashboard from <strong>{name || user?.name || 'this user'}</strong>.
They&apos;ll keep their primary role and any other additional
roles. Click &ldquo;Save changes&rdquo; below to apply.
</>
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel onClick={() => setPendingAdditionalRole(null)}>
Cancel
</AlertDialogCancel>
<AlertDialogAction
onClick={async () => {
if (!pendingAdditionalRole) return
const { role: r, action } = pendingAdditionalRole
const nextAdditional =
action === 'add'
? additionalRoles.includes(r)
? additionalRoles
: [...additionalRoles, r]
: additionalRoles.filter((x) => x !== r)
const nextAllRoles = [
role,
...nextAdditional.filter((x) => x !== role),
] as Array<'SUPER_ADMIN' | 'PROGRAM_ADMIN' | 'JURY_MEMBER' | 'MENTOR' | 'OBSERVER' | 'APPLICANT' | 'AUDIENCE'>
try {
await updateUser.mutateAsync({
id: userId,
roles: nextAllRoles,
})
setAdditionalRoles(nextAdditional)
utils.user.get.invalidate({ id: userId })
utils.user.list.invalidate()
toast.success(
action === 'add'
? `${r.replace(/_/g, ' ')} role added`
: `${r.replace(/_/g, ' ')} role removed`,
)
} catch (error) {
toast.error(
error instanceof Error ? error.message : 'Failed to update roles',
)
} finally {
setPendingAdditionalRole(null)
}
}}
>
{pendingAdditionalRole?.action === 'add' ? 'Add role' : 'Remove role'}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<AlertDialog open={showSuperAdminConfirm} onOpenChange={setShowSuperAdminConfirm}>
<AlertDialogContent>
<AlertDialogHeader>
@@ -818,6 +1044,67 @@ export default function MemberDetailPage() {
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<Dialog open={accessLinkOpen} onOpenChange={setAccessLinkOpen}>
<DialogContent className="sm:max-w-lg">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<LinkIcon className="h-4 w-4" />
Access link ready
</DialogTitle>
<DialogDescription>
{accessLink?.kind === 'magic_login'
? `Share this with ${user.name || user.email} via Slack, WhatsApp, or any channel that reaches them. Clicking it will sign them in directly (their existing password is preserved) and take them to their dashboard.`
: `Share this with ${user.name || user.email} via Slack, WhatsApp, or any channel that reaches them. They'll be walked through setting a password and onboarding.`}
</DialogDescription>
</DialogHeader>
<div className="space-y-3">
<div className="rounded-md border bg-muted/40 p-3">
<Input
readOnly
value={accessLink?.url ?? ''}
onFocus={(e) => e.currentTarget.select()}
className="font-mono text-xs bg-background"
/>
</div>
<div className="flex items-center justify-between gap-2 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900">
<div className="flex items-center gap-2">
<Clock className="h-3.5 w-3.5 shrink-0" />
<span>
Expires {accessLink?.expiresAt.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })}
{' · '}consumed on first successful login
</span>
</div>
</div>
<p className="text-xs text-muted-foreground">
Don&apos;t paste this in a public channel. Anyone with the link
can sign in as this user until it&apos;s consumed.
</p>
</div>
<DialogFooter className="gap-2 sm:gap-2">
<Button variant="outline" onClick={() => setAccessLinkOpen(false)}>
Close
</Button>
<Button onClick={handleCopyAccessLink}>
{linkCopied ? (
<>
<Check className="mr-2 h-4 w-4" />
Copied
</>
) : (
<>
<Copy className="mr-2 h-4 w-4" />
Copy link
</>
)}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
)
}

View File

@@ -74,7 +74,7 @@ import { useSession } from 'next-auth/react'
import { cn } from '@/lib/utils'
type Step = 'input' | 'preview' | 'sending' | 'complete'
type Role = 'SUPER_ADMIN' | 'PROGRAM_ADMIN' | 'AWARD_MASTER' | 'JURY_MEMBER' | 'MENTOR' | 'OBSERVER'
type Role = 'SUPER_ADMIN' | 'PROGRAM_ADMIN' | 'JURY_MEMBER' | 'MENTOR' | 'OBSERVER'
interface Assignment {
projectId: string
@@ -106,7 +106,6 @@ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
const ROLE_LABELS: Record<Role, string> = {
SUPER_ADMIN: 'Super Admin',
PROGRAM_ADMIN: 'Program Admin',
AWARD_MASTER: 'Award Master',
JURY_MEMBER: 'Jury Member',
MENTOR: 'Mentor',
OBSERVER: 'Observer',
@@ -289,7 +288,7 @@ export default function MemberInvitePage() {
const availableRoles = useMemo((): Role[] => {
const roles: Role[] = []
if (isSuperAdmin) roles.push('SUPER_ADMIN')
if (isAdmin) roles.push('PROGRAM_ADMIN', 'AWARD_MASTER')
if (isAdmin) roles.push('PROGRAM_ADMIN')
roles.push('JURY_MEMBER', 'MENTOR', 'OBSERVER')
return roles
}, [isSuperAdmin, isAdmin])
@@ -423,8 +422,6 @@ export default function MemberInvitePage() {
? 'SUPER_ADMIN'
: rawRole === 'PROGRAM_ADMIN'
? 'PROGRAM_ADMIN'
: rawRole === 'AWARD_MASTER'
? 'AWARD_MASTER'
: rawRole === 'MENTOR'
? 'MENTOR'
: rawRole === 'OBSERVER'
@@ -910,7 +907,7 @@ export default function MemberInvitePage() {
</div>
{!sendInvitation && (
<div className="flex items-start gap-3 rounded-lg bg-blue-500/10 p-4 text-blue-700 dark:text-blue-400">
<div className="flex items-start gap-3 rounded-lg bg-blue-500/10 p-4 text-blue-700">
<MailX className="h-5 w-5 shrink-0 mt-0.5" />
<div>
<p className="font-medium">No invitations will be sent</p>

View File

@@ -1,5 +1,470 @@
import { redirect } from 'next/navigation'
'use client'
export default function MentorsPage() {
redirect('/admin/members')
import { useMemo, useState } from 'react'
import Link from 'next/link'
import { trpc } from '@/lib/trpc/client'
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Input } from '@/components/ui/input'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
import { ArrowUpDown, GraduationCap, Search, Users } from 'lucide-react'
import { formatEnumLabel } from '@/lib/utils'
import { MentorDetailSheet } from '@/components/admin/mentor/mentor-detail-sheet'
type SortKey = 'name' | 'load' | 'capacity' | 'lastActivity'
function formatRelativePast(date: Date | string | null): string {
if (!date) return '—'
const d = typeof date === 'string' ? new Date(date) : date
const ms = Date.now() - d.getTime()
const days = Math.floor(ms / 86_400_000)
const hours = Math.floor(ms / 3_600_000)
if (days >= 1) return `${days}d ago`
if (hours >= 1) return `${hours}h ago`
const minutes = Math.floor(ms / 60_000)
return `${Math.max(0, minutes)}m ago`
}
const STATUS_BADGE: Record<
'unassigned' | 'assigned' | 'active' | 'stalled',
{ label: string; variant: 'default' | 'secondary' | 'destructive' | 'outline' }
> = {
unassigned: { label: 'Unassigned', variant: 'outline' },
assigned: { label: 'Assigned', variant: 'secondary' },
active: { label: 'Active', variant: 'default' },
stalled: { label: 'Stalled', variant: 'destructive' },
}
type Mentor = {
id: string
name: string | null
email: string
country: string | null
expertiseTags: string[]
currentAssignments: number
completedAssignments: number
maxAssignments: number | null
capacityRemaining: number | null
lastActivityAt: Date | string | null
activeTeams: { id: string; title: string }[]
}
function MentorListPanel() {
const [search, setSearch] = useState('')
const [sortKey, setSortKey] = useState<SortKey>('load')
const [sortDir, setSortDir] = useState<'asc' | 'desc'>('asc')
const [detailMentorId, setDetailMentorId] = useState<string | null>(null)
const { data, isLoading } = trpc.mentor.getMentorPool.useQuery({})
const filtered = useMemo<Mentor[]>(() => {
if (!data) return []
const q = search.trim().toLowerCase()
let rows: Mentor[] = data.mentors
if (q) {
rows = rows.filter((m) =>
[m.name ?? '', m.email, m.country ?? '', ...m.expertiseTags]
.join(' ')
.toLowerCase()
.includes(q),
)
}
rows = [...rows].sort((a, b) => {
let av: string | number = 0
let bv: string | number = 0
switch (sortKey) {
case 'name':
av = (a.name ?? '').toLowerCase()
bv = (b.name ?? '').toLowerCase()
break
case 'load':
av = a.currentAssignments
bv = b.currentAssignments
break
case 'capacity':
av = a.capacityRemaining ?? Number.MAX_SAFE_INTEGER
bv = b.capacityRemaining ?? Number.MAX_SAFE_INTEGER
break
case 'lastActivity':
av = a.lastActivityAt ? new Date(a.lastActivityAt).getTime() : 0
bv = b.lastActivityAt ? new Date(b.lastActivityAt).getTime() : 0
break
}
if (av < bv) return sortDir === 'asc' ? -1 : 1
if (av > bv) return sortDir === 'asc' ? 1 : -1
return 0
})
return rows
}, [data, search, sortKey, sortDir])
const toggleSort = (key: SortKey) => {
if (sortKey === key) setSortDir((d) => (d === 'asc' ? 'desc' : 'asc'))
else {
setSortKey(key)
setSortDir(key === 'name' ? 'asc' : 'desc')
}
}
const SortHeader = ({
k,
children,
align = 'left',
}: {
k: SortKey
children: React.ReactNode
align?: 'left' | 'right'
}) => (
<button
type="button"
onClick={() => toggleSort(k)}
className={`flex items-center gap-1 text-sm font-medium ${align === 'right' ? 'ml-auto' : ''}`}
>
{children}
<ArrowUpDown
className={`h-3 w-3 ${sortKey === k ? 'text-foreground' : 'text-muted-foreground/50'}`}
/>
</button>
)
return (
<div className="space-y-6">
<Card>
<CardHeader className="space-y-4">
<CardTitle className="text-base">Mentor list</CardTitle>
<div className="relative">
<Search className="text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2" />
<Input
value={search}
onChange={(e) => setSearch(e.target.value)}
placeholder="Search by name, email, country, or expertise tag…"
className="pl-9"
/>
</div>
</CardHeader>
<CardContent>
{isLoading ? (
<div className="space-y-2">
{[1, 2, 3, 4, 5].map((i) => (
<Skeleton key={i} className="h-12 w-full" />
))}
</div>
) : filtered.length === 0 ? (
<div className="text-muted-foreground py-12 text-center text-sm">
{search ? 'No matching mentors.' : 'No mentors yet.'}
</div>
) : (
<div className="overflow-hidden rounded-md border">
<Table>
<TableHeader>
<TableRow>
<TableHead>
<SortHeader k="name">Mentor</SortHeader>
</TableHead>
<TableHead>Expertise</TableHead>
<TableHead>Country</TableHead>
<TableHead className="text-right">
<SortHeader k="capacity" align="right">
Capacity
</SortHeader>
</TableHead>
<TableHead>
<SortHeader k="lastActivity">Last activity</SortHeader>
</TableHead>
<TableHead>
<SortHeader k="load">Teams</SortHeader>
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filtered.map((m) => (
<TableRow
key={m.id}
className="cursor-pointer"
onClick={() => setDetailMentorId(m.id)}
>
<TableCell>
<div className="font-medium">{m.name ?? 'Unnamed'}</div>
<div className="text-muted-foreground text-xs">{m.email}</div>
</TableCell>
<TableCell>
<div className="flex flex-wrap gap-1">
{m.expertiseTags.slice(0, 4).map((tag) => (
<Badge key={tag} variant="secondary" className="text-xs">
{tag}
</Badge>
))}
{m.expertiseTags.length > 4 && (
<Badge variant="outline" className="text-xs">
+{m.expertiseTags.length - 4}
</Badge>
)}
</div>
</TableCell>
<TableCell className="text-sm">{m.country ?? '—'}</TableCell>
<TableCell className="text-right text-sm tabular-nums">
{m.capacityRemaining != null ? m.capacityRemaining : '∞'}
</TableCell>
<TableCell className="text-sm">
{formatRelativePast(m.lastActivityAt)}
</TableCell>
<TableCell>
{m.activeTeams.length === 0 ? (
<span className="text-muted-foreground text-xs"></span>
) : (
<div className="flex flex-wrap gap-1">
{m.activeTeams.slice(0, 2).map((t) => (
<Badge
key={t.id}
variant="outline"
className="max-w-[12rem] truncate text-xs"
title={t.title}
>
{t.title}
</Badge>
))}
{m.activeTeams.length > 2 && (
<Badge variant="outline" className="text-xs">
+{m.activeTeams.length - 2}
</Badge>
)}
</div>
)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
)}
</CardContent>
</Card>
<MentorDetailSheet
mentorId={detailMentorId}
open={!!detailMentorId}
onOpenChange={(next) => {
if (!next) setDetailMentorId(null)
}}
/>
</div>
)
}
type StatusFilter = 'all' | 'unassigned' | 'assigned' | 'active' | 'stalled'
function MenteeActivityPanel() {
const [search, setSearch] = useState('')
const [statusFilter, setStatusFilter] = useState<StatusFilter>('all')
const { data, isLoading } = trpc.mentor.getMenteeActivity.useQuery({})
const filtered = useMemo(() => {
if (!data) return []
const q = search.trim().toLowerCase()
return data.rows.filter((r) => {
if (statusFilter !== 'all' && r.status !== statusFilter) return false
if (!q) return true
const hay = [
r.project.title,
r.project.country ?? '',
r.teamLead?.name ?? '',
r.teamLead?.email ?? '',
r.mentor?.name ?? '',
r.mentor?.email ?? '',
]
.join(' ')
.toLowerCase()
return hay.includes(q)
})
}, [data, search, statusFilter])
const totals = data?.totals ?? { unassigned: 0, assigned: 0, active: 0, stalled: 0 }
const StatusPill = ({ value, label, count }: { value: StatusFilter; label: string; count: number }) => (
<button
type="button"
onClick={() => setStatusFilter(value)}
className={`rounded-md border px-2.5 py-1 text-xs font-medium transition-colors ${
statusFilter === value
? 'bg-primary text-primary-foreground border-primary'
: 'bg-background hover:bg-muted'
}`}
>
{label} <span className="tabular-nums opacity-80">({count})</span>
</button>
)
return (
<div className="space-y-6">
<Card>
<CardHeader className="space-y-4">
<div className="flex items-center justify-between gap-4">
<CardTitle className="text-base">Mentee teams</CardTitle>
<div className="flex flex-wrap gap-1.5">
<StatusPill
value="all"
label="All"
count={
totals.unassigned + totals.assigned + totals.active + totals.stalled
}
/>
<StatusPill value="unassigned" label="Unassigned" count={totals.unassigned} />
<StatusPill value="assigned" label="Assigned" count={totals.assigned} />
<StatusPill value="active" label="Active" count={totals.active} />
<StatusPill value="stalled" label="Stalled" count={totals.stalled} />
</div>
</div>
<div className="relative">
<Search className="text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2" />
<Input
value={search}
onChange={(e) => setSearch(e.target.value)}
placeholder="Search by project, team lead, or mentor…"
className="pl-9"
/>
</div>
</CardHeader>
<CardContent>
{isLoading ? (
<div className="space-y-2">
{[1, 2, 3, 4, 5].map((i) => (
<Skeleton key={i} className="h-14 w-full" />
))}
</div>
) : filtered.length === 0 ? (
<div className="text-muted-foreground py-12 text-center text-sm">
{search || statusFilter !== 'all'
? 'No matching teams.'
: 'No teams have requested mentorship yet.'}
</div>
) : (
<div className="overflow-hidden rounded-md border">
<Table>
<TableHeader>
<TableRow>
<TableHead>Project</TableHead>
<TableHead>Status</TableHead>
<TableHead>Mentor</TableHead>
<TableHead className="text-right">Messages</TableHead>
<TableHead className="text-right">Files</TableHead>
<TableHead>Last activity</TableHead>
<TableHead></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filtered.map((r) => {
const badge = STATUS_BADGE[r.status]
return (
<TableRow key={r.project.id}>
<TableCell>
<div className="font-medium">{r.project.title}</div>
<div className="text-muted-foreground text-xs">
{r.teamLead?.name ?? r.teamLead?.email ?? '—'}
{r.project.oceanIssue && (
<>
{' · '}
{formatEnumLabel(r.project.oceanIssue)}
</>
)}
</div>
</TableCell>
<TableCell>
<Badge variant={badge.variant} className="text-xs">
{badge.label}
</Badge>
</TableCell>
<TableCell>
{r.mentor ? (
<div className="text-sm">
<div>{r.mentor.name ?? r.mentor.email}</div>
<div className="text-muted-foreground text-xs tabular-nums">
{r.mentor.currentLoad}
{r.mentor.maxAssignments != null
? `/${r.mentor.maxAssignments}`
: ''}
{' load'}
</div>
</div>
) : (
<span className="text-muted-foreground text-sm"></span>
)}
</TableCell>
<TableCell className="text-right tabular-nums">
{r.messageCount}
</TableCell>
<TableCell className="text-right tabular-nums">{r.fileCount}</TableCell>
<TableCell className="text-sm">
{formatRelativePast(r.lastActivityAt as unknown as Date | null)}
</TableCell>
<TableCell className="text-right">
<Button asChild size="sm" variant="outline">
<Link href={`/admin/projects/${r.project.id}/mentor`}>
{r.mentor ? 'Open' : 'Assign'}
</Link>
</Button>
</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
</div>
)}
</CardContent>
</Card>
</div>
)
}
export default function MentorsListPage() {
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Mentors</h1>
<p className="text-muted-foreground">
Manage the mentor pool and track mentee teams across the program.
</p>
</div>
<Button asChild variant="outline">
<Link href="/admin/members">
<Users className="mr-2 h-4 w-4" />
Manage Members
</Link>
</Button>
</div>
<Tabs defaultValue="mentors" className="space-y-6">
<TabsList>
<TabsTrigger value="mentors">
<GraduationCap className="mr-2 h-4 w-4" /> Mentors
</TabsTrigger>
<TabsTrigger value="mentees">
<Users className="mr-2 h-4 w-4" /> Mentees & Activity
</TabsTrigger>
</TabsList>
<TabsContent value="mentors">
<MentorListPanel />
</TabsContent>
<TabsContent value="mentees">
<MenteeActivityPanel />
</TabsContent>
</Tabs>
</div>
)
}

File diff suppressed because it is too large Load Diff

View File

@@ -75,7 +75,9 @@ import {
Eye,
Plus,
X,
Mail,
} from 'lucide-react'
import { ProjectEmailDialog } from '@/components/admin/project-email-dialog'
import { toast } from 'sonner'
import { formatDateOnly } from '@/lib/utils'
import { getCountryName, getCountryFlag } from '@/lib/countries'
@@ -161,6 +163,7 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
// State for remove member confirmation
const [removingMemberId, setRemovingMemberId] = useState<string | null>(null)
const [emailDialogOpen, setEmailDialogOpen] = useState(false)
const addTeamMember = trpc.project.addTeamMember.useMutation({
onSuccess: () => {
@@ -269,6 +272,11 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
</div>
</div>
<div className="flex items-center gap-2">
<Button variant="outline" onClick={() => setEmailDialogOpen(true)}>
<Mail className="mr-2 h-4 w-4" />
Email Team
</Button>
<Button variant="outline" asChild>
<Link href={`/admin/projects/${projectId}/edit`}>
<Edit className="mr-2 h-4 w-4" />
@@ -276,6 +284,16 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
</Link>
</Button>
</div>
</div>
{project && (
<ProjectEmailDialog
open={emailDialogOpen}
onClose={() => setEmailDialogOpen(false)}
projectId={project.id}
projectTitle={project.title}
/>
)}
<Separator />
@@ -845,9 +863,10 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
} : null,
}))
for (const f of files) {
const roundId = f.requirement?.roundId ?? null
const roundName = f.requirement?.round?.name ?? 'General'
const sortOrder = f.requirement?.round?.sortOrder ?? -1
const roundId = f.requirement?.roundId ?? f.roundId ?? null
const matchedRound = roundId ? competitionRounds.find((r: any) => r.id === roundId) : null
const roundName = f.requirement?.round?.name ?? matchedRound?.name ?? 'General'
const sortOrder = f.requirement?.round?.sortOrder ?? matchedRound?.sortOrder ?? -1
const key = roundId ?? '_general'
if (!groups.has(key)) {
groups.set(key, { roundId, roundName, sortOrder, files: [] })
@@ -864,8 +883,25 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
</Card>
</AnimatedCard>
{/* Assignments Section */}
{assignments && assignments.length > 0 && (
{/* Assignments Section — grouped by round */}
{assignments && assignments.length > 0 && (() => {
// Group assignments by round
const roundGroups = new Map<string, {
roundId: string
roundName: string
assignments: typeof assignments
}>()
for (const a of assignments) {
const rId = a.round?.id ?? '_unknown'
const rName = a.round?.name ?? 'Unknown Round'
if (!roundGroups.has(rId)) {
roundGroups.set(rId, { roundId: rId, roundName: rName, assignments: [] })
}
roundGroups.get(rId)!.assignments.push(a)
}
const groups = Array.from(roundGroups.values())
return (
<AnimatedCard index={5}>
<Card>
<CardHeader>
@@ -880,7 +916,7 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
<CardDescription>
{assignments.filter((a) => a.evaluation?.status === 'SUBMITTED')
.length}{' '}
of {assignments.length} evaluations completed
of {assignments.length} evaluations completed across {groups.length} round{groups.length !== 1 ? 's' : ''}
</CardDescription>
</div>
<Button variant="outline" size="sm" asChild>
@@ -890,7 +926,17 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
</Button>
</div>
</CardHeader>
<CardContent>
<CardContent className="space-y-6">
{groups.map((group) => {
const submitted = group.assignments.filter((a) => a.evaluation?.status === 'SUBMITTED').length
return (
<div key={group.roundId}>
<div className="flex items-center justify-between mb-2">
<h4 className="text-sm font-semibold">{group.roundName}</h4>
<span className="text-xs text-muted-foreground">
{submitted} of {group.assignments.length} completed
</span>
</div>
<Table>
<TableHeader>
<TableRow>
@@ -903,7 +949,7 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
</TableRow>
</TableHeader>
<TableBody>
{assignments.map((assignment) => (
{group.assignments.map((assignment) => (
<TableRow
key={assignment.id}
className={assignment.evaluation?.status === 'SUBMITTED' ? 'cursor-pointer hover:bg-muted/50' : ''}
@@ -995,10 +1041,14 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
))}
</TableBody>
</Table>
</div>
)
})}
</CardContent>
</Card>
</AnimatedCard>
)}
)
})()}
{/* Evaluation Detail Sheet */}
<EvaluationEditSheet

View File

@@ -462,7 +462,7 @@ export default function BulkUploadPage() {
return (
<TableRow
key={row.project.id}
className={row.isComplete ? 'bg-green-50/50 dark:bg-green-950/10' : ''}
className={row.isComplete ? 'bg-green-50/50' : ''}
>
<TableCell>
<Link

View File

@@ -53,15 +53,15 @@ type TeamMemberEntry = {
}
const ROLE_COLORS: Record<string, string> = {
LEAD: 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400',
MEMBER: 'bg-teal-100 text-teal-700 dark:bg-teal-900/30 dark:text-teal-400',
ADVISOR: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400',
LEAD: 'bg-red-100 text-red-700',
MEMBER: 'bg-teal-100 text-teal-700',
ADVISOR: 'bg-blue-100 text-blue-700',
}
const ROLE_AVATAR_COLORS: Record<string, string> = {
LEAD: 'bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300',
MEMBER: 'bg-teal-100 text-teal-700 dark:bg-teal-900/40 dark:text-teal-300',
ADVISOR: 'bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300',
LEAD: 'bg-red-100 text-red-700',
MEMBER: 'bg-teal-100 text-teal-700',
ADVISOR: 'bg-blue-100 text-blue-700',
}
const ROLE_LABELS: Record<string, string> = {

View File

@@ -679,7 +679,7 @@ export default function ProjectsPage() {
<Button
variant="outline"
onClick={() => setAiTagDialogOpen(true)}
className={taggingInProgress ? 'border-amber-400 bg-amber-50 dark:bg-amber-950/20' : ''}
className={taggingInProgress ? 'border-amber-400 bg-amber-50' : ''}
>
{taggingInProgress ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin text-amber-600" />
@@ -1716,15 +1716,15 @@ export default function ProjectsPage() {
<div className="space-y-6 py-4">
{/* Progress Indicator (when running) */}
{taggingInProgress && (
<div className="p-4 rounded-lg bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-900">
<div className="p-4 rounded-lg bg-blue-50 border border-blue-200">
<div className="space-y-3">
<div className="flex items-center gap-3">
<Loader2 className="h-5 w-5 animate-spin text-blue-600" />
<div className="flex-1">
<p className="font-medium text-blue-900 dark:text-blue-100">
<p className="font-medium text-blue-900">
AI Tagging in Progress
</p>
<p className="text-sm text-blue-700 dark:text-blue-300">
<p className="text-sm text-blue-700">
{jobStatus?.status === 'PENDING'
? 'Initializing...'
: `Processing ${jobStatus?.totalProjects || 0} projects with AI...`}
@@ -1739,12 +1739,12 @@ export default function ProjectsPage() {
</div>
<div className="space-y-1">
<div className="flex justify-between text-sm">
<span className="text-blue-700 dark:text-blue-300">
<span className="text-blue-700">
{jobStatus?.processedCount || 0} of {jobStatus?.totalProjects || '?'} projects processed
{jobStatus?.taggedCount ? ` (${jobStatus.taggedCount} tagged)` : ''}
</span>
{jobStatus && jobStatus.totalProjects > 0 && (
<span className="font-medium text-blue-900 dark:text-blue-100">
<span className="font-medium text-blue-900">
{taggingProgressPercent}%
</span>
)}
@@ -1767,9 +1767,9 @@ export default function ProjectsPage() {
{taggingResult && !taggingInProgress && (
<div className={`p-4 rounded-lg border ${
taggingResult.failed > 0
? 'bg-amber-50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-900'
? 'bg-amber-50 border-amber-200'
: taggingResult.processed > 0
? 'bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-900'
? 'bg-green-50 border-green-200'
: 'bg-muted border-border'
}`}>
<div className="flex items-center gap-3 mb-3">
@@ -1804,12 +1804,12 @@ export default function ProjectsPage() {
</div>
{taggingResult.errors.length > 0 && (
<div className="mt-3 space-y-2">
<p className="text-sm font-medium text-amber-700 dark:text-amber-300">
<p className="text-sm font-medium text-amber-700">
{taggingResult.errors.length} project{taggingResult.errors.length > 1 ? 's' : ''} failed:
</p>
<div className="max-h-32 overflow-y-auto rounded bg-background/50 p-2 text-xs space-y-1">
{taggingResult.errors.map((error, i) => (
<p key={i} className="text-amber-700 dark:text-amber-300">
<p key={i} className="text-amber-700">
{error}
</p>
))}

View File

@@ -1,7 +1,8 @@
'use client'
import { useState, useEffect } from 'react'
import { useState, useEffect, useMemo } from 'react'
import Link from 'next/link'
import { useSearchParams, useRouter, usePathname } from 'next/navigation'
import { trpc } from '@/lib/trpc/client'
import {
Card,
@@ -45,8 +46,13 @@ import {
Trophy,
ArrowRight,
Hash,
Sparkles,
Loader2,
AlertTriangle,
} from 'lucide-react'
import { toast } from 'sonner'
import { formatDateOnly } from '@/lib/utils'
import { getCountryName, getCountryFlag } from '@/lib/countries'
import {
ScoreDistributionChart,
EvaluationTimelineChart,
@@ -62,33 +68,41 @@ import {
import { ExportPdfButton } from '@/components/shared/export-pdf-button'
import { AnimatedCard } from '@/components/shared/animated-container'
function ReportsOverview() {
function ReportsOverview({ scope }: { scope: string | null }) {
const { data: programs, isLoading } = trpc.program.list.useQuery({ includeStages: true })
const { data: dashStats, isLoading: statsLoading } = trpc.analytics.getDashboardStats.useQuery()
// Flatten stages from all programs
const rounds = programs?.flatMap(p =>
((p.stages ?? []) as Array<{ id: string; name: string; status: string; votingEndAt?: string | Date | null }>).map((s: { id: string; name: string; status: string; votingEndAt?: string | Date | null }) => ({ ...s, programId: p.id, programName: `${p.year} Edition` }))
) || []
// Project reporting scope (default: latest program, all rounds)
const [selectedValue, setSelectedValue] = useState<string | null>(null)
useEffect(() => {
if (programs?.length && !selectedValue) {
setSelectedValue(`all:${programs[0].id}`)
}
}, [programs, selectedValue])
const scopeInput = parseSelection(selectedValue)
const scopeInput = parseSelection(scope)
const hasScope = !!scopeInput.roundId || !!scopeInput.programId
const selectedRound = scope ? rounds.find((r) => r.id === scope) : null
const selectedScopeLabel = selectedRound
? `${selectedRound.programName}${selectedRound.name}`
: scope?.startsWith('all:')
? `${programs?.find((p) => `all:${p.id}` === scope)?.year ?? ''} Edition — All Rounds`
: 'All projects'
const { data: projectRankings, isLoading: projectsLoading } =
trpc.analytics.getProjectRankings.useQuery(
{ ...scopeInput, limit: 5000 },
{ enabled: hasScope }
)
// Applicant nationality breakdown — always runs (scope optional;
// empty scope = global view across all programs).
const { data: nationalityStats, isLoading: nationalityLoading } =
trpc.analytics.getApplicantNationalities.useQuery(scopeInput)
const nationalityScopeLabel = scopeInput.roundId
? 'in this round'
: scopeInput.programId
? `in ${programs?.find((p) => p.id === scopeInput.programId)?.year ?? ''} Edition`
: 'across all programs'
if (isLoading || statsLoading) {
return (
<div className="space-y-6">
@@ -196,6 +210,13 @@ function ReportsOverview() {
</AnimatedCard>
</div>
{/* Applicant Nationalities */}
<ApplicantNationalitiesCard
data={nationalityStats}
loading={nationalityLoading}
scopeLabel={nationalityScopeLabel}
/>
{/* Score Distribution (if any evaluations exist) */}
{dashStats?.scoreDistribution && dashStats.scoreDistribution.some(b => b.count > 0) && (
<Card>
@@ -239,26 +260,9 @@ function ReportsOverview() {
Project Reports
</CardTitle>
<CardDescription>
Summary dashboard optionally filter to a specific round
{selectedScopeLabel}
</CardDescription>
</div>
<Select value={selectedValue || ''} onValueChange={setSelectedValue}>
<SelectTrigger className="w-[280px]">
<SelectValue placeholder="All projects" />
</SelectTrigger>
<SelectContent>
{programs?.map((p) => (
<SelectItem key={`all:${p.id}`} value={`all:${p.id}`}>
{p.year} Edition All Rounds
</SelectItem>
))}
{rounds.map((round) => (
<SelectItem key={round.id} value={round.id}>
{round.programName} - {round.name}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</CardHeader>
<CardContent className="space-y-5">
@@ -271,6 +275,12 @@ function ReportsOverview() {
const evaluated = projectRankings.filter(p => p.averageScore !== null)
const scores = evaluated.map(p => p.averageScore as number)
const avgScore = scores.length ? scores.reduce((a, b) => a + b, 0) / scores.length : 0
const balancedScores = projectRankings
.map(p => p.balancedScore)
.filter((s): s is number => s != null)
const avgBalanced = balancedScores.length
? balancedScores.reduce((a, b) => a + b, 0) / balancedScores.length
: null
const minScore = scores.length ? Math.min(...scores) : 0
const maxScore = scores.length ? Math.max(...scores) : 0
const evalPercent = projectRankings.length ? Math.round((evaluated.length / projectRankings.length) * 100) : 0
@@ -281,14 +291,28 @@ function ReportsOverview() {
return (
<>
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
<div className="grid grid-cols-2 gap-3 sm:grid-cols-5">
<div className="rounded-lg border p-3 text-center">
<p className="text-xs text-muted-foreground">Total Projects</p>
<p className="text-xl font-bold tabular-nums">{projectRankings.length}</p>
</div>
<div className="rounded-lg border p-3 text-center">
<p className="text-xs text-muted-foreground">Avg Score</p>
<p className="text-xl font-bold tabular-nums">{avgScore ? avgScore.toFixed(1) : '-'}</p>
<div
className="rounded-lg border p-3 text-center"
title="Unweighted mean of all submitted juror scores"
>
<p className="text-xs text-muted-foreground">Raw Avg</p>
<p className="text-xl font-bold tabular-nums text-muted-foreground">
{avgScore ? avgScore.toFixed(1) : '-'}
</p>
</div>
<div
className="rounded-lg border p-3 text-center"
title="Juror-balanced average: per-juror z-score normalization rescaled to the 110 range"
>
<p className="text-xs text-muted-foreground">Balanced Avg</p>
<p className="text-xl font-bold tabular-nums">
{avgBalanced == null ? '-' : avgBalanced.toFixed(1)}
</p>
</div>
<div className="rounded-lg border p-3 text-center">
<p className="text-xs text-muted-foreground">Evaluated</p>
@@ -319,7 +343,7 @@ function ReportsOverview() {
{/* Top 10 ranked table */}
<div>
<p className="text-sm font-medium text-muted-foreground mb-2 flex items-center gap-1.5">
<Trophy className="h-3.5 w-3.5" /> Top 10 by Average Score
<Trophy className="h-3.5 w-3.5" /> Top 10 by Balanced Score
</p>
<div className="rounded-lg border">
<Table>
@@ -328,7 +352,18 @@ function ReportsOverview() {
<TableHead className="w-10">#</TableHead>
<TableHead>Project</TableHead>
<TableHead className="hidden sm:table-cell">Team</TableHead>
<TableHead className="text-right">Avg</TableHead>
<TableHead
className="text-right"
title="Raw average of juror scores — uncorrected for per-juror harshness"
>
Raw Avg
</TableHead>
<TableHead
className="text-right"
title="Juror-balanced average: each juror's contribution is z-score normalized against their own grading distribution, then rescaled to the 110 range. Harsh and lenient jurors contribute on equal footing."
>
Balanced
</TableHead>
<TableHead className="text-right">Evals</TableHead>
<TableHead>Status</TableHead>
</TableRow>
@@ -345,9 +380,12 @@ function ReportsOverview() {
<TableCell className="hidden sm:table-cell text-muted-foreground">
{p.teamName || '-'}
</TableCell>
<TableCell className="text-right tabular-nums">
<TableCell className="text-right tabular-nums text-muted-foreground">
{p.averageScore === null ? '-' : p.averageScore.toFixed(2)}
</TableCell>
<TableCell className="text-right tabular-nums font-semibold">
{p.balancedScore == null ? '-' : p.balancedScore.toFixed(2)}
</TableCell>
<TableCell className="text-right tabular-nums">{p.evaluationCount}</TableCell>
<TableCell>
<Badge variant="outline">{formatStatusLabel(p.status)}</Badge>
@@ -481,6 +519,140 @@ function ReportsOverview() {
)
}
type NationalityStats = {
total: number
declared: number
notDeclared: number
byCountry: Array<{ country: string; count: number }>
}
function ApplicantNationalitiesCard({
data,
loading,
scopeLabel,
}: {
data: NationalityStats | undefined
loading: boolean
scopeLabel: string
}) {
const [showAll, setShowAll] = useState(false)
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<div className="rounded-lg bg-violet-500/10 p-1.5">
<Globe className="h-4 w-4 text-violet-600" />
</div>
Applicant Nationalities
</CardTitle>
<CardDescription>
Self-declared nationality of team members on projects {scopeLabel}.
</CardDescription>
</CardHeader>
<CardContent>
{loading ? (
<div className="space-y-3">
<Skeleton className="h-12 w-full" />
<Skeleton className="h-64 w-full" />
</div>
) : !data || data.total === 0 ? (
<div className="flex flex-col items-center justify-center py-8 text-center">
<Globe className="h-10 w-10 text-muted-foreground/50" />
<p className="mt-2 text-sm text-muted-foreground">
No applicants in this scope.
</p>
</div>
) : data.declared === 0 ? (
<>
<NationalitySummary declared={data.declared} notDeclared={data.notDeclared} />
<div className="mt-4 flex flex-col items-center justify-center rounded-lg border border-dashed py-8 text-center">
<Globe className="h-8 w-8 text-muted-foreground/50" />
<p className="mt-2 text-sm text-muted-foreground">
No nationality data yet.
</p>
</div>
</>
) : (
<>
<NationalitySummary declared={data.declared} notDeclared={data.notDeclared} />
<div className="mt-4 rounded-lg border">
<Table>
<TableHeader>
<TableRow>
<TableHead>Country</TableHead>
<TableHead className="text-right w-32">Applicants</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{(showAll ? data.byCountry : data.byCountry.slice(0, 10)).map((row) => {
const name = getCountryName(row.country)
const flag = getCountryFlag(row.country)
return (
<TableRow key={row.country}>
<TableCell className="font-medium">
<span className="inline-flex items-center gap-2">
{flag && <span aria-hidden>{flag}</span>}
<span>{name}</span>
{name !== row.country && (
<span className="text-xs text-muted-foreground tabular-nums">
{row.country}
</span>
)}
</span>
</TableCell>
<TableCell className="text-right">
<Badge variant="secondary" className="tabular-nums">
{row.count}
</Badge>
</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
</div>
{data.byCountry.length > 10 && (
<div className="mt-3 flex justify-end">
<Button
variant="ghost"
size="sm"
onClick={() => setShowAll((v) => !v)}
className="gap-1 text-muted-foreground"
>
{showAll
? 'Show top 10'
: `Show all (${data.byCountry.length} countries)`}
<ArrowRight className="h-3.5 w-3.5" />
</Button>
</div>
)}
</>
)}
</CardContent>
</Card>
)
}
function NationalitySummary({ declared, notDeclared }: { declared: number; notDeclared: number }) {
return (
<div className="grid grid-cols-2 gap-3">
<div className="rounded-lg border p-3 text-center">
<p className="text-xs text-muted-foreground">Declared</p>
<p className="text-2xl font-bold tabular-nums">{declared}</p>
</div>
<div className="rounded-lg border p-3 text-center">
<p className="text-xs text-muted-foreground">Not declared</p>
<p className="text-2xl font-bold tabular-nums text-muted-foreground">
{notDeclared}
</p>
</div>
</div>
)
}
// Parse selection value: "all:programId" for edition-wide, or roundId
function parseSelection(value: string | null): { roundId?: string; programId?: string } {
if (!value) return {}
@@ -512,9 +684,7 @@ function findDefaultRound(rounds: Array<{ id: string; status?: string }>): strin
return rounds[0]?.id
}
function StageAnalytics() {
const [selectedValue, setSelectedValue] = useState<string | null>(null)
function StageAnalytics({ scope }: { scope: string | null }) {
const { data: programs, isLoading: roundsLoading } = trpc.program.list.useQuery({ includeStages: true })
// Flatten stages from all programs with program name
@@ -522,14 +692,7 @@ function StageAnalytics() {
((p.stages ?? []) as Array<{ id: string; name: string; status: string }>).map((s: { id: string; name: string; status: string }) => ({ ...s, programId: p.id, programName: `${p.year} Edition` }))
) || []
// Set default selected stage — prefer active round
useEffect(() => {
if (rounds.length && !selectedValue) {
setSelectedValue(findDefaultRound(rounds) ?? rounds[0].id)
}
}, [rounds.length, selectedValue])
const queryInput = parseSelection(selectedValue)
const queryInput = parseSelection(scope)
const hasSelection = !!queryInput.roundId || !!queryInput.programId
const { data: scoreDistribution, isLoading: scoreLoading } =
@@ -568,7 +731,7 @@ function StageAnalytics() {
{ enabled: hasSelection }
)
const selectedRound = rounds.find((r) => r.id === selectedValue)
const selectedRound = rounds.find((r) => r.id === scope)
const geoInput = queryInput.programId
? { programId: queryInput.programId }
: { programId: selectedRound?.programId || '', roundId: queryInput.roundId }
@@ -606,28 +769,6 @@ function StageAnalytics() {
return (
<div className="space-y-6">
{/* Round Selector */}
<div className="flex items-center gap-4">
<label className="text-sm font-medium">Select Round:</label>
<Select value={selectedValue || ''} onValueChange={setSelectedValue}>
<SelectTrigger className="w-[300px]">
<SelectValue placeholder="Select a round" />
</SelectTrigger>
<SelectContent>
{programs?.map((p) => (
<SelectItem key={`all:${p.id}`} value={`all:${p.id}`}>
{p.year} Edition All Rounds
</SelectItem>
))}
{rounds.map((round) => (
<SelectItem key={round.id} value={round.id}>
{round.programName} - {round.name}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{hasSelection && (
<div className="space-y-6">
{/* Row 1: Score Distribution & Status Breakdown */}
@@ -800,22 +941,10 @@ function CrossStageTab() {
)
}
function JurorConsistencyTab() {
const [selectedValue, setSelectedValue] = useState<string | null>(null)
function JurorConsistencyTab({ scope }: { scope: string | null }) {
const { isLoading: programsLoading } = trpc.program.list.useQuery({ includeStages: true })
const { data: programs, isLoading: programsLoading } = trpc.program.list.useQuery({ includeStages: true })
const stages = programs?.flatMap((p) =>
((p.stages ?? []) as Array<{ id: string; name: string; status: string }>).map((s: { id: string; name: string; status: string }) => ({ id: s.id, name: s.name, status: s.status, programId: p.id, programName: `${p.year} Edition` }))
) || []
useEffect(() => {
if (stages.length && !selectedValue) {
setSelectedValue(findDefaultRound(stages) ?? stages[0].id)
}
}, [stages.length, selectedValue])
const queryInput = parseSelection(selectedValue)
const queryInput = parseSelection(scope)
const hasSelection = !!queryInput.roundId || !!queryInput.programId
const { data: consistency, isLoading: consistencyLoading } =
@@ -830,27 +959,6 @@ function JurorConsistencyTab() {
return (
<div className="space-y-6">
<div className="flex items-center gap-4">
<label className="text-sm font-medium">Select Stage:</label>
<Select value={selectedValue || ''} onValueChange={setSelectedValue}>
<SelectTrigger className="w-[300px]">
<SelectValue placeholder="Select a stage" />
</SelectTrigger>
<SelectContent>
{programs?.map((p) => (
<SelectItem key={`all:${p.id}`} value={`all:${p.id}`}>
{p.year} Edition All Stages
</SelectItem>
))}
{stages.map((stage) => (
<SelectItem key={stage.id} value={stage.id}>
{stage.name}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{consistencyLoading && <Skeleton className="h-[400px]" />}
{consistency && (
@@ -870,26 +978,154 @@ function JurorConsistencyTab() {
}}
/>
)}
{queryInput.roundId && (
<JurorCalibrationPanel roundId={queryInput.roundId} />
)}
</div>
)
}
function DiversityTab() {
const [selectedValue, setSelectedValue] = useState<string | null>(null)
function JurorCalibrationPanel({ roundId }: { roundId: string }) {
const mutation = trpc.analytics.generateJurorCalibration.useMutation({
onError: (err) => toast.error(`Calibration analysis failed: ${err.message}`),
})
const result = mutation.data
const { data: programs, isLoading: programsLoading } = trpc.program.list.useQuery({ includeStages: true })
const stages = programs?.flatMap((p) =>
((p.stages ?? []) as Array<{ id: string; name: string; status: string }>).map((s: { id: string; name: string; status: string }) => ({ id: s.id, name: s.name, status: s.status, programId: p.id, programName: `${p.year} Edition` }))
) || []
useEffect(() => {
if (stages.length && !selectedValue) {
setSelectedValue(findDefaultRound(stages) ?? stages[0].id)
const severityStyle: Record<string, string> = {
outlier: 'bg-red-50 text-red-700 border-red-200',
notable: 'bg-amber-50 text-amber-700 border-amber-200',
normal: 'bg-muted text-muted-foreground',
}
}, [stages.length, selectedValue])
const queryInput = parseSelection(selectedValue)
return (
<Card>
<CardHeader>
<div className="flex flex-wrap items-start justify-between gap-3">
<div>
<CardTitle className="flex items-center gap-2">
<Sparkles className="h-5 w-5 text-[#de0f1e]" />
AI Juror Calibration Advisory
</CardTitle>
<CardDescription>
Plain-language explanation of the per-juror score balancing already applied to rankings.
Describes, does not prescribe the math runs regardless.
</CardDescription>
</div>
<Button
onClick={() => mutation.mutate({ roundId })}
disabled={mutation.isPending}
className="gap-2"
>
{mutation.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : <Sparkles className="h-4 w-4" />}
{mutation.isPending ? 'Analyzing…' : result ? 'Regenerate' : 'Analyze jurors'}
</Button>
</div>
</CardHeader>
<CardContent className="space-y-5">
{!result && !mutation.isPending && (
<p className="text-sm text-muted-foreground">
Run the analysis to see per-juror grading patterns, cohort stats, and the calibration
narrative for the selected round.
</p>
)}
{result && (
<>
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
<div className="rounded-lg border p-3 text-center">
<p className="text-xs text-muted-foreground">Cohort Mean</p>
<p className="text-xl font-bold tabular-nums">{result.cohortMean.toFixed(2)}</p>
</div>
<div className="rounded-lg border p-3 text-center">
<p className="text-xs text-muted-foreground">Cohort Stddev</p>
<p className="text-xl font-bold tabular-nums">{result.cohortStddev.toFixed(2)}</p>
</div>
<div className="rounded-lg border p-3 text-center">
<p className="text-xs text-muted-foreground">Evaluations</p>
<p className="text-xl font-bold tabular-nums">{result.totalEvaluations}</p>
</div>
<div className="rounded-lg border p-3 text-center">
<p className="text-xs text-muted-foreground">Jurors</p>
<p className="text-xl font-bold tabular-nums">{result.totalJurors}</p>
</div>
</div>
<div className="rounded-lg border bg-muted/30 p-4">
<p className="text-sm leading-relaxed">{result.overallSummary}</p>
{result.keyTakeaways.length > 0 && (
<ul className="mt-3 space-y-1.5 text-sm">
{result.keyTakeaways.map((t, i) => (
<li key={i} className="flex items-start gap-2">
<ArrowRight className="mt-1 h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" />
<span>{t}</span>
</li>
))}
</ul>
)}
</div>
<div className="rounded-lg border">
<Table>
<TableHeader>
<TableRow>
<TableHead>Juror</TableHead>
<TableHead className="text-right">Evals</TableHead>
<TableHead className="text-right">Mean</TableHead>
<TableHead className="text-right">Δ Cohort</TableHead>
<TableHead className="text-right" title="Juror's stddev / cohort stddev">
Influence
</TableHead>
<TableHead>Severity</TableHead>
<TableHead>Notes</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{result.jurors.map((j) => (
<TableRow key={j.userId}>
<TableCell className="font-medium">{j.name}</TableCell>
<TableCell className="text-right tabular-nums">{j.evaluationCount}</TableCell>
<TableCell className="text-right tabular-nums">{j.rawMean.toFixed(2)}</TableCell>
<TableCell
className={`text-right tabular-nums ${
j.deltaFromCohort < -0.5 ? 'text-red-600' : j.deltaFromCohort > 0.5 ? 'text-emerald-600' : ''
}`}
>
{j.deltaFromCohort > 0 ? '+' : ''}
{j.deltaFromCohort.toFixed(2)}
</TableCell>
<TableCell className="text-right tabular-nums">
{j.effectiveInfluence == null ? '-' : j.effectiveInfluence.toFixed(2)}
</TableCell>
<TableCell>
<Badge variant="outline" className={severityStyle[j.severity]}>
{j.severity === 'outlier' && <AlertTriangle className="mr-1 h-3 w-3" />}
{j.severity}
</Badge>
</TableCell>
<TableCell className="max-w-md text-sm text-muted-foreground">
{j.summary}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
<p className="text-xs text-muted-foreground">
Generated {result.generatedAt.toLocaleString()} · {result.tokensUsed} tokens · model {result.model}
</p>
</>
)}
</CardContent>
</Card>
)
}
function DiversityTab({ scope }: { scope: string | null }) {
const { isLoading: programsLoading } = trpc.program.list.useQuery({ includeStages: true })
const queryInput = parseSelection(scope)
const hasSelection = !!queryInput.roundId || !!queryInput.programId
const { data: diversity, isLoading: diversityLoading } =
@@ -904,27 +1140,6 @@ function DiversityTab() {
return (
<div className="space-y-6">
<div className="flex items-center gap-4">
<label className="text-sm font-medium">Select Stage:</label>
<Select value={selectedValue || ''} onValueChange={setSelectedValue}>
<SelectTrigger className="w-[300px]">
<SelectValue placeholder="Select a stage" />
</SelectTrigger>
<SelectContent>
{programs?.map((p) => (
<SelectItem key={`all:${p.id}`} value={`all:${p.id}`}>
{p.year} Edition All Stages
</SelectItem>
))}
{stages.map((stage) => (
<SelectItem key={stage.id} value={stage.id}>
{stage.name}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{diversityLoading && <Skeleton className="h-[400px]" />}
{diversity && (
@@ -942,10 +1157,10 @@ function DiversityTab() {
)
}
function RoundPipelineTab() {
function RoundPipelineTab({ scope }: { scope: string | null }) {
const { data: programs, isLoading } = trpc.program.list.useQuery({ includeStages: true })
const rounds = programs?.flatMap(p =>
const allRounds = programs?.flatMap(p =>
((p.stages ?? []) as Array<{ id: string; name: string; status: string; type?: string }>).map((s) => ({
...s,
programId: p.id,
@@ -953,6 +1168,16 @@ function RoundPipelineTab() {
}))
) || []
// Pipeline is inherently multi-round. Narrow to the selected program if one
// is picked (either via "all:programId" or a specific round whose program we
// can resolve). Otherwise show every round across every program.
const scopeProgramId = scope?.startsWith('all:')
? scope.slice(4)
: allRounds.find((r) => r.id === scope)?.programId
const rounds = scopeProgramId
? allRounds.filter((r) => r.programId === scopeProgramId)
: allRounds
const roundIds = rounds.map(r => r.id)
const { data: comparison, isLoading: comparisonLoading } =
@@ -1034,20 +1259,48 @@ function RoundPipelineTab() {
}
export default function ReportsPage() {
const router = useRouter()
const pathname = usePathname()
const searchParams = useSearchParams()
const urlRound = searchParams.get('round')
const { data: programs } = trpc.program.list.useQuery({ includeStages: true })
const stages = useMemo(
() => programs?.flatMap((p) =>
((p.stages ?? []) as Array<{ id: string; name: string; status: string }>).map(
(s: { id: string; name: string; status: string }) => ({
id: s.id,
name: s.name,
status: s.status,
programId: p.id,
programName: `${p.year} Edition`,
}),
),
) || [],
[programs],
)
const [pdfStageId, setPdfStageId] = useState<string | null>(null)
const { data: pdfPrograms } = trpc.program.list.useQuery({ includeStages: true })
const pdfStages = pdfPrograms?.flatMap((p) =>
((p.stages ?? []) as Array<{ id: string; name: string; status: string }>).map((s: { id: string; name: string; status: string }) => ({ id: s.id, name: s.name, status: s.status, programName: `${p.year} Edition` }))
) || []
useEffect(() => {
if (pdfStages.length && !pdfStageId) {
setPdfStageId(findDefaultRound(pdfStages) ?? pdfStages[0].id)
if (stages.length && !pdfStageId) {
setPdfStageId(findDefaultRound(stages) ?? stages[0].id)
}
}, [pdfStages.length, pdfStageId])
}, [stages.length, pdfStageId, stages])
const selectedPdfStage = pdfStages.find((r) => r.id === pdfStageId)
// Top-level selection drives every single-round tab. Persisted to the URL
// so reloads and shared links preserve the view. Defaults to the newest
// program's "All Rounds" entry.
const defaultScope = programs?.length ? `all:${programs[0].id}` : null
const scope = urlRound ?? defaultScope
const setScope = (value: string) => {
const params = new URLSearchParams(searchParams.toString())
params.set('round', value)
router.replace(`${pathname}?${params.toString()}`, { scroll: false })
}
const selectedPdfStage = stages.find((r) => r.id === pdfStageId)
return (
<div className="space-y-6">
@@ -1059,6 +1312,35 @@ export default function ReportsPage() {
</p>
</div>
{/* Top-level round selector — drives every tab below */}
<Card>
<CardContent className="p-4">
<div className="flex flex-wrap items-center gap-3">
<label className="text-sm font-medium">Viewing:</label>
<Select value={scope ?? ''} onValueChange={setScope}>
<SelectTrigger className="w-[320px]">
<SelectValue placeholder="Select a round or edition" />
</SelectTrigger>
<SelectContent>
{programs?.map((p) => (
<SelectItem key={`all:${p.id}`} value={`all:${p.id}`}>
{p.year} Edition All Rounds
</SelectItem>
))}
{stages.map((stage) => (
<SelectItem key={stage.id} value={stage.id}>
{stage.programName} {stage.name}
</SelectItem>
))}
</SelectContent>
</Select>
<p className="text-xs text-muted-foreground">
This selection applies to every tab except Cross-Round (which compares multiple rounds).
</p>
</div>
</CardContent>
</Card>
{/* Tabs */}
<Tabs defaultValue="overview" className="space-y-6">
<div className="flex items-center justify-between flex-wrap gap-4">
@@ -1094,7 +1376,7 @@ export default function ReportsPage() {
<SelectValue placeholder="Select stage for PDF" />
</SelectTrigger>
<SelectContent>
{pdfStages.map((stage) => (
{stages.map((stage) => (
<SelectItem key={stage.id} value={stage.id}>
{stage.name}
</SelectItem>
@@ -1112,11 +1394,11 @@ export default function ReportsPage() {
</div>
<TabsContent value="overview">
<ReportsOverview />
<ReportsOverview scope={scope} />
</TabsContent>
<TabsContent value="analytics">
<StageAnalytics />
<StageAnalytics scope={scope} />
</TabsContent>
<TabsContent value="cross-stage">
@@ -1124,15 +1406,15 @@ export default function ReportsPage() {
</TabsContent>
<TabsContent value="consistency">
<JurorConsistencyTab />
<JurorConsistencyTab scope={scope} />
</TabsContent>
<TabsContent value="diversity">
<DiversityTab />
<DiversityTab scope={scope} />
</TabsContent>
<TabsContent value="pipeline">
<RoundPipelineTab />
<RoundPipelineTab scope={scope} />
</TabsContent>
</Tabs>
</div>

View File

@@ -0,0 +1,543 @@
'use client'
import { use, useState, useEffect, useRef, useCallback } from 'react'
import { useRouter } from 'next/navigation'
import Link from 'next/link'
import type { Route } from 'next'
import { trpc } from '@/lib/trpc/client'
import { Card, CardContent } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import { Badge } from '@/components/ui/badge'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { MultiWindowDocViewer } from '@/components/jury/multi-window-doc-viewer'
import { ArrowLeft, Save, Send, UserCheck, Lock } from 'lucide-react'
import { toast } from 'sonner'
import type { EvaluationConfig } from '@/types/competition-configs'
import {
EvaluationFormFields,
parseCriteriaFromForm,
} from '@/components/evaluation/evaluation-form-fields'
type PageProps = {
params: Promise<{ roundId: string; userId: string; projectId: string }>
}
export default function AdminProxyEvaluatePage({ params: paramsPromise }: PageProps) {
const { roundId, userId, projectId } = use(paramsPromise)
const router = useRouter()
const utils = trpc.useUtils()
const backHref = `/admin/rounds/${roundId}/jurors/${userId}/evaluate` as Route
// Form state — mirrors the juror evaluate page
const [criteriaValues, setCriteriaValues] = useState<Record<string, number | boolean | string>>({})
const [globalScore, setGlobalScore] = useState('')
const [binaryDecision, setBinaryDecision] = useState<'' | 'accept' | 'reject'>('')
const [feedbackText, setFeedbackText] = useState('')
const isDirtyRef = useRef(false)
const evaluationIdRef = useRef<string | null>(null)
const isSubmittedRef = useRef(false)
const isSubmittingRef = useRef(false)
const [isSubmitting, setIsSubmitting] = useState(false)
const startPromiseRef = useRef<Promise<{ id: string }> | null>(null)
const autosaveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const [lastSavedAt, setLastSavedAt] = useState<Date | null>(null)
const [confirmOpen, setConfirmOpen] = useState(false)
// Juror + round + all assignments (we filter to the one matching projectId)
const { data: jurorData, isLoading: jurorLoading } =
trpc.evaluation.getJurorAssignmentsForRound.useQuery({ roundId, userId })
const assignment = jurorData?.assignments.find((a) => a.project.id === projectId)
const project = assignment?.project
const round = jurorData?.round
const juror = jurorData?.juror
// Full round config (for scoringMode / requireFeedback etc.)
const { data: fullRound } = trpc.round.getById.useQuery(
{ id: roundId },
{ enabled: !!roundId },
)
// Existing evaluation for this assignment, if any (admin-readable via evaluation.get)
const { data: existingEvaluation } = trpc.evaluation.get.useQuery(
{ assignmentId: assignment?.id ?? '' },
{ enabled: !!assignment?.id },
)
// Active form for this category
const { data: activeForm } = trpc.evaluation.getStageForm.useQuery(
{ roundId, category: project?.competitionCategory },
{ enabled: !!roundId && !!project },
)
const startMutation = trpc.evaluation.adminStart.useMutation()
const autosaveMutation = trpc.evaluation.adminAutosave.useMutation({
onSuccess: () => {
isDirtyRef.current = false
setLastSavedAt(new Date())
},
})
const submitMutation = trpc.evaluation.adminSubmitOnBehalf.useMutation({
onSuccess: () => {
isSubmittedRef.current = true
isDirtyRef.current = false
utils.evaluation.getJurorAssignmentsForRound.invalidate({ roundId, userId })
utils.evaluation.get.invalidate()
utils.analytics.getJurorWorkload.invalidate({ roundId })
toast.success(`Evaluation submitted on behalf of ${juror?.name || 'juror'}`)
router.push(backHref)
},
onError: (err) => {
toast.error(err.message)
isSubmittingRef.current = false
setIsSubmitting(false)
},
})
useEffect(() => {
if (existingEvaluation?.id) {
evaluationIdRef.current = existingEvaluation.id
}
}, [existingEvaluation?.id])
// Load existing evaluation values (draft or submitted)
useEffect(() => {
if (existingEvaluation) {
if (existingEvaluation.criterionScoresJson) {
const values: Record<string, number | boolean | string> = {}
Object.entries(existingEvaluation.criterionScoresJson).forEach(([key, value]) => {
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'string') {
values[key] = value
}
})
setCriteriaValues(values)
}
if (existingEvaluation.globalScore != null) {
setGlobalScore(existingEvaluation.globalScore.toString())
}
if (existingEvaluation.binaryDecision !== null) {
setBinaryDecision(existingEvaluation.binaryDecision ? 'accept' : 'reject')
}
if (existingEvaluation.feedbackText) {
setFeedbackText(existingEvaluation.feedbackText)
}
isDirtyRef.current = false
}
}, [existingEvaluation])
// Config
const evalConfig: EvaluationConfig | null = (fullRound?.configJson as EvaluationConfig | null) ?? null
const scoringMode = evalConfig?.scoringMode ?? 'criteria'
const requireFeedback = evalConfig?.requireFeedback ?? true
const feedbackMinLength = evalConfig?.feedbackMinLength ?? 10
const criteria = parseCriteriaFromForm(
activeForm?.criteriaJson as ReadonlyArray<Record<string, unknown>> | null | undefined,
)
// Seed midpoint values for numeric criteria on first load
const criteriaInitializedRef = useRef(false)
useEffect(() => {
if (criteriaInitializedRef.current || criteria.length === 0) return
if (existingEvaluation?.criterionScoresJson) return
criteriaInitializedRef.current = true
const defaults: Record<string, number | boolean | string> = {}
for (const c of criteria) {
if (c.type === 'numeric') {
defaults[c.id] = Math.ceil((c.minScore + c.maxScore) / 2)
}
}
if (Object.keys(defaults).length > 0) {
setCriteriaValues((prev) => ({ ...defaults, ...prev }))
}
}, [criteria, existingEvaluation?.criterionScoresJson])
const buildSavePayload = useCallback(() => {
return {
criterionScoresJson: scoringMode === 'criteria' ? criteriaValues : undefined,
globalScore: scoringMode === 'global' && globalScore ? parseInt(globalScore, 10) : null,
binaryDecision: scoringMode === 'binary' && binaryDecision ? binaryDecision === 'accept' : null,
feedbackText: feedbackText || null,
}
}, [scoringMode, criteriaValues, globalScore, binaryDecision, feedbackText])
const performAutosave = useCallback(async () => {
if (!isDirtyRef.current || isSubmittedRef.current || isSubmittingRef.current) return
if (existingEvaluation?.status === 'SUBMITTED' || existingEvaluation?.status === 'LOCKED') return
let evalId = evaluationIdRef.current
if (!evalId && assignment) {
try {
if (!startPromiseRef.current) {
startPromiseRef.current = startMutation.mutateAsync({ assignmentId: assignment.id })
}
const newEval = await startPromiseRef.current
evalId = newEval.id
evaluationIdRef.current = evalId
} catch {
return
} finally {
startPromiseRef.current = null
}
}
if (!evalId) return
autosaveMutation.mutate({ id: evalId, ...buildSavePayload() })
}, [assignment, existingEvaluation?.status, startMutation, autosaveMutation, buildSavePayload])
// Debounced autosave
useEffect(() => {
if (!isDirtyRef.current) return
if (autosaveTimerRef.current) clearTimeout(autosaveTimerRef.current)
autosaveTimerRef.current = setTimeout(() => {
performAutosave()
}, 3000)
return () => {
if (autosaveTimerRef.current) clearTimeout(autosaveTimerRef.current)
}
}, [criteriaValues, globalScore, binaryDecision, feedbackText, performAutosave])
// Save on unmount
useEffect(() => {
return () => {
if (isDirtyRef.current && !isSubmittedRef.current && evaluationIdRef.current) {
performAutosave()
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const handleCriterionChange = (key: string, value: number | boolean | string) => {
setCriteriaValues((prev) => ({ ...prev, [key]: value }))
isDirtyRef.current = true
}
const handleGlobalScoreChange = (value: string) => {
setGlobalScore(value)
isDirtyRef.current = true
}
const handleBinaryChange = (value: 'accept' | 'reject') => {
setBinaryDecision(value)
isDirtyRef.current = true
}
const handleFeedbackChange = (value: string) => {
setFeedbackText(value)
isDirtyRef.current = true
}
const handleSaveDraft = async () => {
if (!assignment) {
toast.error('Assignment not found')
return
}
let evaluationId = evaluationIdRef.current
if (!evaluationId) {
if (!startPromiseRef.current) {
startPromiseRef.current = startMutation.mutateAsync({ assignmentId: assignment.id })
}
const newEval = await startPromiseRef.current
startPromiseRef.current = null
evaluationId = newEval.id
evaluationIdRef.current = evaluationId
}
autosaveMutation.mutate(
{ id: evaluationId, ...buildSavePayload() },
{
onSuccess: () => {
isDirtyRef.current = false
setLastSavedAt(new Date())
toast.success('Draft saved', { duration: 1500 })
},
},
)
}
const validateBeforeSubmit = (): string | null => {
if (scoringMode === 'criteria') {
const requiredCriteria = criteria.filter((c) => c.type !== 'section_header' && c.required)
for (const c of requiredCriteria) {
const val = criteriaValues[c.id]
if (c.type === 'numeric' && (val === undefined || val === null)) return `Please score "${c.label}"`
if ((c.type === 'boolean' || c.type === 'advance') && val === undefined) return `Please answer "${c.label}"`
if (c.type === 'text' && (!val || (typeof val === 'string' && !val.trim()))) return `Please fill in "${c.label}"`
}
}
if (scoringMode === 'global') {
const score = parseInt(globalScore, 10)
if (isNaN(score) || score < 1 || score > 10) return 'Please enter a valid score between 1 and 10'
}
if (scoringMode === 'binary') {
if (!binaryDecision) return 'Please select accept or reject'
}
if (requireFeedback) {
if (!feedbackText.trim() || feedbackText.length < feedbackMinLength) {
return `Please provide feedback (minimum ${feedbackMinLength} characters)`
}
}
return null
}
const handleOpenConfirm = () => {
const error = validateBeforeSubmit()
if (error) {
toast.error(error)
return
}
setConfirmOpen(true)
}
const handleConfirmedSubmit = async () => {
if (autosaveTimerRef.current) {
clearTimeout(autosaveTimerRef.current)
autosaveTimerRef.current = null
}
if (!assignment) {
toast.error('Assignment not found')
return
}
isSubmittingRef.current = true
setIsSubmitting(true)
let evaluationId = evaluationIdRef.current
if (!evaluationId) {
if (!startPromiseRef.current) {
startPromiseRef.current = startMutation.mutateAsync({ assignmentId: assignment.id })
}
const newEval = await startPromiseRef.current
startPromiseRef.current = null
evaluationId = newEval.id
evaluationIdRef.current = evaluationId
}
// Compute global score from weighted criteria (same as juror page)
const numericCriteria = criteria.filter((c) => c.type === 'numeric')
let computedGlobalScore = 5
if (scoringMode === 'criteria' && numericCriteria.length > 0) {
let totalWeight = 0
let weightedSum = 0
for (const c of numericCriteria) {
const val = criteriaValues[c.id]
if (typeof val === 'number') {
const w = c.weight ?? 1
const normalized = ((val - c.minScore) / (c.maxScore - c.minScore)) * 9 + 1
weightedSum += normalized * w
totalWeight += w
}
}
if (totalWeight > 0) {
computedGlobalScore = Math.round(weightedSum / totalWeight)
}
}
submitMutation.mutate({
id: evaluationId,
criterionScoresJson: scoringMode === 'criteria' ? criteriaValues : {},
globalScore: scoringMode === 'global' ? parseInt(globalScore, 10) : computedGlobalScore,
binaryDecision: scoringMode === 'binary' ? binaryDecision === 'accept' : true,
feedbackText: feedbackText || 'No feedback provided',
})
}
if (jurorLoading || !round || !juror) {
return (
<div className="space-y-6">
<Skeleton className="h-10 w-64" />
<Skeleton className="h-64 w-full" />
</div>
)
}
if (!assignment || !project) {
return (
<div className="space-y-6">
<Button variant="ghost" size="sm" asChild>
<Link href={backHref}>
<ArrowLeft className="mr-2 h-4 w-4" />
Back to Assignments
</Link>
</Button>
<Card className="border-l-4 border-l-red-500">
<CardContent className="p-6">
<p className="font-semibold">Assignment not found</p>
<p className="text-sm text-muted-foreground mt-1">
This juror does not have an assignment for this project in the selected round.
</p>
</CardContent>
</Card>
</div>
)
}
const isSubmittedEvaluation = existingEvaluation?.status === 'SUBMITTED' || existingEvaluation?.status === 'LOCKED'
const isReadOnly = isSubmittedEvaluation
const hasCOI = assignment.conflictOfInterest?.hasConflict === true
return (
<div className="space-y-6">
<div className="flex items-center gap-4">
<Button variant="ghost" size="sm" asChild>
<Link href={backHref}>
<ArrowLeft className="mr-2 h-4 w-4" />
Back to Assignments
</Link>
</Button>
<div>
<h1 className="text-2xl font-bold tracking-tight text-brand-blue">
{isReadOnly ? 'Submitted Evaluation' : 'Fill In Evaluation'}
</h1>
<div className="flex items-center gap-2 mt-1 flex-wrap">
<p className="text-muted-foreground">{project.title}</p>
{project.competitionCategory && (
<Badge
variant="secondary"
className={
project.competitionCategory === 'STARTUP'
? 'bg-violet-100 text-violet-700 border-violet-200'
: 'bg-sky-100 text-sky-700 border-sky-200'
}
>
{project.competitionCategory === 'STARTUP' ? 'Startup' : 'Business Concept'}
</Badge>
)}
</div>
</div>
</div>
<Card className="border-l-4 border-l-amber-500 bg-amber-50/40">
<CardContent className="flex items-start gap-3 p-4">
<UserCheck className="h-5 w-5 text-amber-600 shrink-0 mt-0.5" />
<div className="flex-1 text-sm">
<p className="font-medium">
Acting on behalf of {juror.name || juror.email}
</p>
<p className="text-muted-foreground mt-1">
Window and round-active checks are bypassed for this submission. A proxy audit entry
is recorded with your admin ID and the juror&apos;s ID.
</p>
</div>
</CardContent>
</Card>
{isReadOnly && (
<Card className="border-l-4 border-l-blue-500 bg-blue-50/50">
<CardContent className="flex items-start gap-3 p-4">
<Lock className="h-5 w-5 text-blue-600 shrink-0 mt-0.5" />
<div className="flex-1">
<p className="font-medium text-sm">View-Only</p>
<p className="text-sm text-muted-foreground mt-1">
This evaluation has already been submitted. To change it, reset via the
round dashboard first.
</p>
</div>
</CardContent>
</Card>
)}
{hasCOI && !isReadOnly && (
<Card className="border-l-4 border-l-red-500 bg-red-50/40">
<CardContent className="flex items-start gap-3 p-4">
<Lock className="h-5 w-5 text-red-600 shrink-0 mt-0.5" />
<div className="flex-1 text-sm">
<p className="font-medium">Conflict of interest declared</p>
<p className="text-muted-foreground mt-1">
The juror declared a conflict on this project. Reassign via the COI review
workflow instead of submitting a proxy evaluation.
</p>
</div>
</CardContent>
</Card>
)}
<MultiWindowDocViewer roundId={roundId} projectId={projectId} />
<EvaluationFormFields
criteria={criteria}
scoringMode={scoringMode}
requireFeedback={requireFeedback}
feedbackMinLength={feedbackMinLength}
criteriaValues={criteriaValues}
globalScore={globalScore}
binaryDecision={binaryDecision}
feedbackText={feedbackText}
isReadOnly={isReadOnly || hasCOI}
lastSavedAt={lastSavedAt}
onCriterionChange={handleCriterionChange}
onGlobalScoreChange={handleGlobalScoreChange}
onBinaryChange={handleBinaryChange}
onFeedbackChange={handleFeedbackChange}
/>
{isReadOnly ? (
<div className="flex items-center">
<Button variant="outline" asChild>
<Link href={backHref}>
<ArrowLeft className="mr-2 h-4 w-4" />
Back
</Link>
</Button>
</div>
) : (
<div className="flex items-center justify-between flex-wrap gap-4">
<Button variant="outline" asChild>
<Link href={backHref}>Cancel</Link>
</Button>
<div className="flex gap-3">
<Button
variant="outline"
onClick={handleSaveDraft}
disabled={autosaveMutation.isPending || submitMutation.isPending || hasCOI}
>
<Save className="mr-2 h-4 w-4" />
{autosaveMutation.isPending ? 'Saving...' : 'Save Draft'}
</Button>
<AlertDialog open={confirmOpen} onOpenChange={setConfirmOpen}>
<AlertDialogTrigger asChild>
<Button
onClick={handleOpenConfirm}
disabled={submitMutation.isPending || isSubmitting || hasCOI}
className="bg-brand-blue hover:bg-brand-blue-light"
>
<Send className="mr-2 h-4 w-4" />
{submitMutation.isPending ? 'Submitting...' : 'Submit on behalf'}
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Submit on behalf of {juror.name || juror.email}?</AlertDialogTitle>
<AlertDialogDescription>
This will submit the evaluation as if it came from the juror. The current
voting window and round-active status will be bypassed. The audit log will
record both your admin ID and the juror&apos;s ID. This action cannot be
undone without resetting the evaluation first.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isSubmitting}>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleConfirmedSubmit}
disabled={isSubmitting}
className="bg-brand-blue hover:bg-brand-blue-light"
>
{isSubmitting ? 'Submitting...' : 'Yes, submit'}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</div>
)}
</div>
)
}

View File

@@ -0,0 +1,241 @@
'use client'
import { use } from 'react'
import Link from 'next/link'
import type { Route } from 'next'
import { trpc } from '@/lib/trpc/client'
import { Button } from '@/components/ui/button'
import { Badge } from '@/components/ui/badge'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Skeleton } from '@/components/ui/skeleton'
import {
ArrowLeft,
ArrowRight,
CheckCircle2,
Clock,
Pencil,
ShieldAlert,
UserCheck,
} from 'lucide-react'
import { cn } from '@/lib/utils'
type PageProps = {
params: Promise<{ roundId: string; userId: string }>
}
export default function AdminJurorProxyEvaluatePage({ params: paramsPromise }: PageProps) {
const { roundId, userId } = use(paramsPromise)
const { data, isLoading } = trpc.evaluation.getJurorAssignmentsForRound.useQuery({
roundId,
userId,
})
if (isLoading || !data) {
return (
<div className="space-y-6">
<Skeleton className="h-10 w-64" />
<Skeleton className="h-32 w-full" />
<Skeleton className="h-64 w-full" />
</div>
)
}
const { juror, round, assignments } = data
const pending = assignments.filter((a) => a.evaluation?.status !== 'SUBMITTED' && a.evaluation?.status !== 'LOCKED')
const completed = assignments.filter((a) => a.evaluation?.status === 'SUBMITTED' || a.evaluation?.status === 'LOCKED')
return (
<div className="space-y-6">
<div className="flex items-center gap-4">
<Button variant="ghost" size="sm" asChild>
<Link href={`/admin/rounds/${roundId}` as Route}>
<ArrowLeft className="mr-2 h-4 w-4" />
Back to Round
</Link>
</Button>
<div>
<h1 className="text-2xl font-bold tracking-tight text-brand-blue">
Proxy Evaluations
</h1>
<p className="text-muted-foreground mt-1">
Filling in on behalf of <span className="font-semibold">{juror.name || juror.email}</span>{' '}
&middot; {round.name}
</p>
</div>
</div>
<Card className="border-l-4 border-l-amber-500">
<CardContent className="flex items-start gap-3 p-4">
<UserCheck className="h-5 w-5 text-amber-600 shrink-0 mt-0.5" />
<div className="flex-1 text-sm">
<p className="font-medium">You are acting on behalf of a juror</p>
<p className="text-muted-foreground mt-1">
Each submission is recorded in the audit log with your admin ID and the juror&apos;s
ID. Voting-window and round-active checks are bypassed for proxy submissions, but
COI-declared projects cannot be proxy-submitted.
</p>
</div>
</CardContent>
</Card>
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<div>
<CardTitle className="text-base">Pending assignments</CardTitle>
<CardDescription>
{pending.length === 0
? 'No pending evaluations — this juror has completed everything assigned to them.'
: `${pending.length} project${pending.length === 1 ? '' : 's'} awaiting evaluation.`}
</CardDescription>
</div>
<Badge variant="secondary" className="shrink-0">
{completed.length}/{assignments.length} complete
</Badge>
</div>
</CardHeader>
<CardContent className="space-y-2">
{pending.length === 0 ? (
<p className="text-sm text-muted-foreground py-4 text-center">Nothing to do here.</p>
) : (
pending.map((a) => (
<AssignmentRow
key={a.id}
roundId={roundId}
userId={userId}
assignment={a}
mode="pending"
/>
))
)}
</CardContent>
</Card>
{completed.length > 0 && (
<Card>
<CardHeader>
<CardTitle className="text-base">Completed assignments</CardTitle>
<CardDescription>
Already submitted. Click to view (read-only).
</CardDescription>
</CardHeader>
<CardContent className="space-y-2">
{completed.map((a) => (
<AssignmentRow
key={a.id}
roundId={roundId}
userId={userId}
assignment={a}
mode="completed"
/>
))}
</CardContent>
</Card>
)}
</div>
)
}
type AssignmentRowProps = {
roundId: string
userId: string
assignment: {
id: string
isCompleted: boolean
project: {
id: string
title: string
competitionCategory: 'STARTUP' | 'BUSINESS_CONCEPT' | null
teamName: string | null
}
evaluation: {
id: string
status: 'NOT_STARTED' | 'DRAFT' | 'SUBMITTED' | 'LOCKED'
globalScore: number | null
binaryDecision: boolean | null
submittedAt: Date | null
} | null
conflictOfInterest: { id: string; hasConflict: boolean } | null
}
mode: 'pending' | 'completed'
}
function AssignmentRow({ roundId, userId, assignment, mode }: AssignmentRowProps) {
const { project, evaluation, conflictOfInterest } = assignment
const hasCOI = conflictOfInterest?.hasConflict === true
const statusLabel = evaluation?.status === 'SUBMITTED'
? 'Submitted'
: evaluation?.status === 'DRAFT'
? 'Draft in progress'
: evaluation?.status === 'LOCKED'
? 'Locked'
: 'Not started'
const statusColor =
evaluation?.status === 'SUBMITTED' || evaluation?.status === 'LOCKED'
? 'text-emerald-600'
: evaluation?.status === 'DRAFT'
? 'text-amber-600'
: 'text-muted-foreground'
const StatusIcon =
evaluation?.status === 'SUBMITTED' || evaluation?.status === 'LOCKED'
? CheckCircle2
: evaluation?.status === 'DRAFT'
? Pencil
: Clock
const href = `/admin/rounds/${roundId}/jurors/${userId}/evaluate/${project.id}` as Route
return (
<div
className={cn(
'flex items-center justify-between gap-3 p-3 rounded-lg border transition-colors',
mode === 'pending' ? 'hover:bg-muted/30' : 'bg-muted/20',
)}
>
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2 flex-wrap">
<p className="font-medium text-sm truncate">{project.title}</p>
{project.competitionCategory && (
<Badge
variant="secondary"
className={cn(
'shrink-0',
project.competitionCategory === 'STARTUP'
? 'bg-violet-100 text-violet-700 border-violet-200'
: 'bg-sky-100 text-sky-700 border-sky-200',
)}
>
{project.competitionCategory === 'STARTUP' ? 'Startup' : 'Business Concept'}
</Badge>
)}
{hasCOI && (
<Badge variant="destructive" className="shrink-0 gap-1">
<ShieldAlert className="h-3 w-3" />
COI declared
</Badge>
)}
</div>
<div className={cn('flex items-center gap-1.5 text-xs mt-1', statusColor)}>
<StatusIcon className="h-3.5 w-3.5" />
<span>{statusLabel}</span>
{evaluation?.status === 'SUBMITTED' && evaluation.globalScore !== null && (
<span className="ml-2 text-muted-foreground">Score: {evaluation.globalScore}/10</span>
)}
{project.teamName && (
<span className="ml-2 text-muted-foreground">&middot; {project.teamName}</span>
)}
</div>
</div>
<Button size="sm" variant={mode === 'pending' ? 'default' : 'outline'} asChild disabled={hasCOI}>
<Link href={href} aria-disabled={hasCOI} className={hasCOI ? 'pointer-events-none opacity-50' : ''}>
{mode === 'pending' ? 'Fill in' : 'View'}
<ArrowRight className="ml-1.5 h-3.5 w-3.5" />
</Link>
</Button>
</div>
)
}

View File

@@ -79,6 +79,8 @@ import {
ListChecks,
FileText,
Languages,
MonitorPlay,
Scale,
} from 'lucide-react'
import {
Tooltip,
@@ -91,6 +93,16 @@ import { ProjectStatesTable } from '@/components/admin/round/project-states-tabl
// SubmissionWindowManager removed — round dates + file requirements in Config are sufficient
import { FileRequirementsEditor } from '@/components/admin/round/file-requirements-editor'
import { FilteringDashboard } from '@/components/admin/round/filtering-dashboard'
import { MentoringRoundOverview } from '@/components/admin/round/mentoring-round-overview'
import { MentoringProjectsTable } from '@/components/admin/round/mentoring-projects-table'
import { LiveControlPanel } from '@/components/admin/live/live-control-panel'
import { DeliberationControlPanel } from '@/components/admin/deliberation/deliberation-control-panel'
import { FinalistSlotsCard } from '@/components/admin/grand-finale/finalist-slots-card'
import { WaitlistCard } from '@/components/admin/grand-finale/waitlist-card'
import { FinalistEnrollmentCard } from '@/components/admin/grand-finale/finalist-enrollment-card'
import { FinalDocsReminderButton } from '@/components/admin/grand-finale/final-docs-reminder-button'
import { FinalDocsUploadsToggle } from '@/components/admin/grand-finale/final-docs-uploads-toggle'
import { ReviewDocsPicker } from '@/components/admin/grand-finale/review-docs-picker'
import { RankingDashboard } from '@/components/admin/round/ranking-dashboard'
import { CoverageReport } from '@/components/admin/assignment/coverage-report'
import { AssignmentPreviewSheet } from '@/components/admin/assignment/assignment-preview-sheet'
@@ -121,6 +133,7 @@ import { ConfigSectionHeader } from '@/components/admin/rounds/config/config-sec
import { NotifyAdvancedButton } from '@/components/admin/round/notify-advanced-button'
import { NotifyRejectedButton } from '@/components/admin/round/notify-rejected-button'
import { BulkInviteButton } from '@/components/admin/round/bulk-invite-button'
import { SendMentorshipWelcomeButton } from '@/components/admin/round/send-mentorship-welcome-button'
import { AdvancementSummaryCard } from '@/components/admin/round/advancement-summary-card'
import { FinalizationTab } from '@/components/admin/round/finalization-tab'
@@ -145,6 +158,95 @@ const stateColors: Record<string, string> = Object.fromEntries(
Object.entries(projectStateConfig).map(([k, v]) => [k, v.bg])
)
// ═══════════════════════════════════════════════════════════════════════════
// Mentoring round: Auto-fill remaining toolbar (Projects tab)
// ═══════════════════════════════════════════════════════════════════════════
function MentoringBulkAssignToolbar({
roundId,
configJson,
}: {
roundId: string
configJson: Record<string, unknown>
}) {
const utils = trpc.useUtils()
const eligibility = (configJson.eligibility as string) ?? 'requested_only'
const isAdminSelected = eligibility === 'admin_selected'
const { data: pending } = trpc.round.getProjectsNeedingMentor.useQuery(
{ roundId },
{ enabled: !isAdminSelected, refetchInterval: 30_000 },
)
const count = pending?.count ?? 0
const eligibleTotal = pending?.eligibleTotal ?? 0
const mentorPoolSize = pending?.mentorPoolSize ?? 0
const hasNoMentors = mentorPoolSize === 0
const hasNoEligible = eligibleTotal === 0
const bulk = trpc.mentor.autoAssignBulkForRound.useMutation({
onSuccess: (result) => {
toast.success(result.message)
utils.round.getProjectsNeedingMentor.invalidate({ roundId })
utils.project.list.invalidate()
},
onError: (err) => toast.error(err.message),
})
const eligibilityLabel = eligibility.replace('_', ' ')
return (
<div className="flex items-center justify-between rounded-md border bg-muted/30 px-4 py-2.5">
<div className="text-sm">
{isAdminSelected ? (
<>
<span className="font-medium">Eligibility: admin-selected</span>
<span className="text-muted-foreground ml-2">
auto-fill is disabled. Assign each project manually.
</span>
</>
) : hasNoMentors ? (
<span className="text-muted-foreground">
No mentors in the pool yet {' '}
<Link
href="/admin/members?tab=mentors"
className="text-foreground underline-offset-2 hover:underline"
>
add mentors
</Link>{' '}
before auto-filling.
</span>
) : hasNoEligible ? (
<span className="text-muted-foreground">
No projects are eligible for mentorship in this round (
{eligibilityLabel}).
</span>
) : count > 0 ? (
<>
<span className="font-medium">{count}</span>{' '}
<span className="text-muted-foreground">
of {eligibleTotal} project{eligibleTotal === 1 ? '' : 's'} still
needs a mentor ({eligibilityLabel})
</span>
</>
) : (
<span className="text-muted-foreground">
All {eligibleTotal} eligible project{eligibleTotal === 1 ? '' : 's'}{' '}
already have a mentor.
</span>
)}
</div>
<Button
size="sm"
onClick={() => bulk.mutate({ roundId })}
disabled={isAdminSelected || count === 0 || hasNoMentors || bulk.isPending}
>
{bulk.isPending ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : null}
Auto-fill remaining
</Button>
</div>
)
}
// ═══════════════════════════════════════════════════════════════════════════
// Main Page Component
// ═══════════════════════════════════════════════════════════════════════════
@@ -514,6 +616,16 @@ export default function RoundDetailPage() {
const isFiltering = round?.roundType === 'FILTERING'
const isEvaluation = round?.roundType === 'EVALUATION'
const isMentoring = round?.roundType === 'MENTORING'
const isGrandFinale = round?.roundType === 'LIVE_FINAL'
// Mentor pool size — used by Round Details panel below to replace the
// always-empty "Jury Group" row on MENTORING rounds.
const { data: mentorPool } = trpc.mentor.getMentorPool.useQuery(
{},
{ enabled: isMentoring },
)
const mentorPoolSize = mentorPool?.poolSize ?? 0
const hasJury = ['EVALUATION', 'LIVE_FINAL', 'DELIBERATION'].includes(round?.roundType ?? '')
const hasAwards = roundAwards.length > 0
const isSimpleAdvance = ['INTAKE', 'SUBMISSION', 'MENTORING'].includes(round?.roundType ?? '')
@@ -589,7 +701,8 @@ export default function RoundDetailPage() {
action: undefined as Route | undefined,
actionLabel: undefined as string | undefined,
},
...((isEvaluation && !(config.requireDocumentUpload as boolean))
...((isEvaluation && !(config.requireDocumentUpload as boolean)) ||
(isMentoring && !(config.filePromotionEnabled as boolean) && !config.promotionTargetWindowId)
? []
: [{
label: 'File requirements set',
@@ -864,6 +977,10 @@ export default function RoundDetailPage() {
...(isFiltering ? [{ value: 'filtering', label: 'Filtering', icon: Shield }] : []),
...(isEvaluation ? [{ value: 'assignments', label: 'Assignments & Jury', icon: ClipboardList }] : []),
...(isEvaluation ? [{ value: 'ranking', label: 'Ranking', icon: BarChart3 }] : []),
...(isGrandFinale ? [{ value: 'ceremony', label: 'Ceremony', icon: MonitorPlay }] : []),
...(round?.roundType === 'DELIBERATION'
? [{ value: 'deliberation', label: 'Deliberation', icon: Scale }]
: []),
...(hasJury && !isEvaluation ? [{ value: 'jury', label: 'Jury', icon: Users }] : []),
...(showFinalization ? [{ value: 'finalization', label: 'Finalization', icon: ListChecks }] : []),
{ value: 'config', label: 'Config', icon: Settings },
@@ -1161,6 +1278,20 @@ export default function RoundDetailPage() {
<div>
<p className="text-[11px] font-semibold uppercase tracking-wider text-muted-foreground mb-2">Project Management</p>
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{isMentoring ? (
<button
onClick={() => setActiveTab('projects')}
className="flex items-start gap-3 p-4 rounded-lg border hover:-translate-y-0.5 hover:shadow-md transition-all text-left w-full"
>
<Layers className="h-5 w-5 text-[#557f8c] mt-0.5 shrink-0" />
<div>
<p className="text-sm font-medium">Assign Projects</p>
<p className="text-xs text-muted-foreground mt-0.5">
Open the Projects tab to add or auto-fill teams in this round
</p>
</div>
</button>
) : (
<Link href={poolLink}>
<button className="flex items-start gap-3 p-4 rounded-lg border hover:-translate-y-0.5 hover:shadow-md transition-all text-left w-full">
<Layers className="h-5 w-5 text-[#557f8c] mt-0.5 shrink-0" />
@@ -1172,6 +1303,7 @@ export default function RoundDetailPage() {
</div>
</button>
</Link>
)}
<button
onClick={() => setActiveTab('projects')}
@@ -1323,6 +1455,7 @@ export default function RoundDetailPage() {
<NotifyAdvancedButton roundId={roundId} />
<NotifyRejectedButton roundId={roundId} />
<BulkInviteButton roundId={roundId} />
{isMentoring && <SendMentorshipWelcomeButton roundId={roundId} />}
</div>
</div>
)}
@@ -1400,6 +1533,33 @@ export default function RoundDetailPage() {
/>
)}
{/* Mentoring-specific stats \u2014 only on MENTORING rounds */}
{isMentoring && <MentoringRoundOverview roundId={roundId} />}
{/* Grand-finale logistics \u2014 only on LIVE_FINAL rounds */}
{isGrandFinale && programId && (
<>
<FinalistEnrollmentCard programId={programId} roundId={roundId} />
<div className="flex items-center justify-between gap-2 flex-wrap">
<FinalDocsUploadsToggle roundId={roundId} />
<div className="flex gap-2">
<Button asChild variant="outline" size="sm">
<Link href="/admin/finals-documents">
<FileText className="mr-2 h-4 w-4" />
Review finalist documents
</Link>
</Button>
<FinalDocsReminderButton programId={programId} />
</div>
</div>
<ReviewDocsPicker programId={programId} roundId={roundId} />
<div className="grid gap-4 md:grid-cols-2">
<FinalistSlotsCard programId={programId} />
<WaitlistCard programId={programId} />
</div>
</>
)}
{/* Round Info + Project Breakdown */}
<div className="grid gap-4 sm:grid-cols-2">
<AnimatedCard index={2}>
@@ -1413,7 +1573,9 @@ export default function RoundDetailPage() {
{ label: 'Status', value: <span className="font-medium">{statusCfg.label}</span> },
{ label: 'Position', value: <span className="font-medium">{`Round ${(round.sortOrder ?? 0) + 1}${competition?.rounds ? ` of ${competition.rounds.length}` : ''}`}</span> },
...(round.purposeKey ? [{ label: 'Purpose', value: <span className="font-medium">{round.purposeKey}</span> }] : []),
{ label: 'Jury Group', value: <span className="font-medium">{juryGroup ? juryGroup.name : '\u2014'}</span> },
isMentoring
? { label: 'Mentor Pool', value: <Link href="/admin/mentors" className="font-medium hover:underline">{mentorPoolSize} member{mentorPoolSize === 1 ? '' : 's'}</Link> }
: { label: 'Jury Group', value: <span className="font-medium">{juryGroup ? juryGroup.name : '\u2014'}</span> },
{ label: 'Opens', value: <span className="font-medium">{round.windowOpenAt ? new Date(round.windowOpenAt).toLocaleString() : '\u2014'}</span> },
{ label: 'Closes', value: <span className="font-medium">{round.windowCloseAt ? new Date(round.windowCloseAt).toLocaleString() : '\u2014'}</span> },
].map((row, i) => (
@@ -1475,6 +1637,18 @@ export default function RoundDetailPage() {
{/* ═══════════ PROJECTS TAB ═══════════ */}
<TabsContent value="projects" className="space-y-4">
{isMentoring && (
<>
<MentoringBulkAssignToolbar roundId={roundId} configJson={config} />
<MentoringProjectsTable
roundId={roundId}
competitionId={competitionId}
competitionRounds={competition?.rounds}
currentSortOrder={round?.sortOrder}
/>
</>
)}
{!isMentoring && (
<ProjectStatesTable
competitionId={competitionId}
roundId={roundId}
@@ -1486,6 +1660,7 @@ export default function RoundDetailPage() {
setTimeout(() => setPreviewSheetOpen(true), 100)
}}
/>
)}
</TabsContent>
{/* ═══════════ FILTERING TAB ═══════════ */}
@@ -1495,6 +1670,20 @@ export default function RoundDetailPage() {
</TabsContent>
)}
{/* ═══════════ CEREMONY TAB (LIVE_FINAL) ═══════════ */}
{isGrandFinale && (
<TabsContent value="ceremony" className="space-y-4">
<LiveControlPanel roundId={roundId} competitionId={competitionId} />
</TabsContent>
)}
{/* ═══════════ DELIBERATION TAB (DELIBERATION rounds) ═══════════ */}
{round?.roundType === 'DELIBERATION' && (
<TabsContent value="deliberation" className="space-y-4">
<DeliberationControlPanel roundId={roundId} competitionId={competitionId} />
</TabsContent>
)}
{/* ═══════════ JURY TAB (non-EVALUATION jury rounds: LIVE_FINAL, DELIBERATION) ═══════════ */}
{hasJury && !isEvaluation && (
<TabsContent value="jury" className="space-y-6">
@@ -1787,8 +1976,48 @@ export default function RoundDetailPage() {
{/* 1. Jury Members & Progress (merged) */}
{!round?.juryGroupId ? (
<Card>
<CardContent className="py-8 text-center">
<p className="text-sm text-muted-foreground">Select a jury group below to get started.</p>
<CardHeader>
<div className="flex items-center justify-between">
<div>
<CardTitle className="text-base">Jury Group</CardTitle>
<CardDescription>
Select or create a jury group to get started
</CardDescription>
</div>
<Button size="sm" variant="outline" onClick={() => setCreateJuryOpen(true)}>
<Plus className="h-4 w-4 mr-1.5" />
New Jury
</Button>
</div>
</CardHeader>
<CardContent>
{juryGroups && juryGroups.length > 0 ? (
<Select
value="__none__"
onValueChange={(value) => {
if (value !== '__none__') {
assignJuryMutation.mutate({ id: roundId, juryGroupId: value })
}
}}
disabled={assignJuryMutation.isPending}
>
<SelectTrigger className="w-full sm:w-80">
<SelectValue placeholder="Select jury group..." />
</SelectTrigger>
<SelectContent>
<SelectItem value="__none__">No jury assigned</SelectItem>
{juryGroups.map((jg: any) => (
<SelectItem key={jg.id} value={jg.id}>
{jg.name} ({jg._count?.members ?? 0} members)
</SelectItem>
))}
</SelectContent>
</Select>
) : (
<p className="text-sm text-muted-foreground">
No jury groups exist yet. Create one to get started.
</p>
)}
</CardContent>
</Card>
) : (
@@ -1937,39 +2166,39 @@ export default function RoundDetailPage() {
</p>
)}
{aiAssignmentMutation.isPending && (
<div className="flex items-center gap-3 p-3 rounded-lg bg-violet-50 border border-violet-200 dark:bg-violet-950/20 dark:border-violet-800">
<div className="flex items-center gap-3 p-3 rounded-lg bg-violet-50 border border-violet-200">
<div className="relative">
<div className="h-8 w-8 rounded-full border-2 border-violet-300 border-t-violet-600 animate-spin" />
</div>
<div>
<p className="text-sm font-medium text-violet-800 dark:text-violet-200">AI is analyzing projects and jurors...</p>
<p className="text-xs text-violet-600 dark:text-violet-400">
<p className="text-sm font-medium text-violet-800">AI is analyzing projects and jurors...</p>
<p className="text-xs text-violet-600">
Matching expertise, reviewing bios, and balancing workloads
</p>
</div>
</div>
)}
{aiAssignmentMutation.error && !aiAssignmentMutation.isPending && (
<div className="flex items-center gap-3 p-3 rounded-lg bg-red-50 border border-red-200 dark:bg-red-950/20 dark:border-red-800">
<div className="flex items-center gap-3 p-3 rounded-lg bg-red-50 border border-red-200">
<AlertTriangle className="h-5 w-5 text-red-600 shrink-0" />
<div className="flex-1">
<p className="text-sm font-medium text-red-800 dark:text-red-200">
<p className="text-sm font-medium text-red-800">
AI generation failed
</p>
<p className="text-xs text-red-600 dark:text-red-400">
<p className="text-xs text-red-600">
{aiAssignmentMutation.error.message}
</p>
</div>
</div>
)}
{aiAssignmentMutation.data && !aiAssignmentMutation.isPending && (
<div className="flex items-center gap-3 p-3 rounded-lg bg-emerald-50 border border-emerald-200 dark:bg-emerald-950/20 dark:border-emerald-800">
<div className="flex items-center gap-3 p-3 rounded-lg bg-emerald-50 border border-emerald-200">
<CheckCircle2 className="h-5 w-5 text-emerald-600 shrink-0" />
<div className="flex-1">
<p className="text-sm font-medium text-emerald-800 dark:text-emerald-200">
<p className="text-sm font-medium text-emerald-800">
{aiAssignmentMutation.data.stats.assignmentsGenerated} assignments generated
</p>
<p className="text-xs text-emerald-600 dark:text-emerald-400">
<p className="text-xs text-emerald-600">
{aiAssignmentMutation.data.stats.totalJurors} jurors, {aiAssignmentMutation.data.stats.totalProjects} projects
{aiAssignmentMutation.data.fallbackUsed && ' (algorithm fallback)'}
</p>
@@ -2158,7 +2387,8 @@ export default function RoundDetailPage() {
</CardContent>
</Card>
{/* General Round Settings */}
{/* General Round Settings — hidden on MENTORING rounds (no advancement targets apply) */}
{!isMentoring && (
<Card>
<CardHeader className="border-b">
<ConfigSectionHeader
@@ -2281,6 +2511,7 @@ export default function RoundDetailPage() {
)}
</CardContent>
</Card>
)}
{/* Round-type-specific config */}
<RoundConfigForm
@@ -2449,9 +2680,9 @@ export default function RoundDetailPage() {
{/* Autosave error bar — only shows when save fails */}
{autosaveStatus === 'error' && (
<div className="fixed bottom-0 left-0 right-0 z-50 border-t bg-red-50 dark:bg-red-950/50 shadow-[0_-4px_12px_rgba(0,0,0,0.1)]">
<div className="fixed bottom-0 left-0 right-0 z-50 border-t bg-red-50 shadow-[0_-4px_12px_rgba(0,0,0,0.1)]">
<div className="container flex items-center justify-between py-3 px-4 max-w-5xl mx-auto">
<div className="flex items-center gap-2 text-sm text-red-700 dark:text-red-300">
<div className="flex items-center gap-2 text-sm text-red-700">
<AlertTriangle className="h-4 w-4" />
<span>Auto-save failed</span>
</div>

View File

@@ -2,6 +2,7 @@ import { prisma } from '@/lib/prisma'
import { requireRole } from '@/lib/auth-redirect'
import { AdminSidebar } from '@/components/layouts/admin-sidebar'
import { AdminEditionWrapper } from '@/components/layouts/admin-edition-wrapper'
import { RoleSwitcherPill } from '@/components/layouts/role-switcher'
export default async function AdminLayout({
children,
@@ -34,6 +35,12 @@ export default async function AdminLayout({
<main className="lg:pl-64">
{/* Spacer for mobile header */}
<div className="h-16 lg:hidden" />
{/* Top-bar — hosts the RoleSwitcherPill so multi-role admins
can switch dashboards from the same screen position used on
every other layout. Pill auto-hides for single-role users. */}
<div className="sticky top-0 z-30 flex h-12 items-center justify-end gap-2 border-b bg-card/80 backdrop-blur px-4">
<RoleSwitcherPill currentBasePath="/admin" />
</div>
<div className="container-app py-6 lg:py-8">{children}</div>
</main>
</div>

View File

@@ -8,69 +8,72 @@ import {
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Progress } from '@/components/ui/progress'
import { Skeleton } from '@/components/ui/skeleton'
import { AnimatedCard } from '@/components/shared/animated-container'
import {
Star,
MessageSquare,
Trophy,
Vote,
TrendingUp,
BarChart3,
Award,
ShieldCheck,
} from 'lucide-react'
import { Star, MessageSquare, Trophy, Vote, ShieldCheck } from 'lucide-react'
import { cn } from '@/lib/utils'
type EvaluationRound = {
roundId: string
roundName: string
roundType: string
evaluationCount: number
evaluations: Array<{
type Criterion = {
id?: string
type?: string
label?: string
name?: string
scale?: string
maxScore?: number
}
type Evaluation = {
id: string
submittedAt: Date | null
globalScore: number | null
criterionScores: unknown
feedbackText: string | null
criteria: unknown
}>
}
function computeRoundStats(round: EvaluationRound) {
const maxScore = round.roundType === 'LIVE_FINAL' ? 10 : 100
type EvaluationRound = {
roundId: string
roundName: string
roundType: string
evaluationCount: number
evaluations: Evaluation[]
}
const HIDDEN_CRITERION_TYPES = new Set(['boolean', 'advance'])
function parseScaleMax(scale: string | undefined, fallback = 10): number {
if (!scale) return fallback
const m = scale.match(/^\s*\d+\s*-\s*(\d+)\s*$/)
if (m) return Number(m[1])
return fallback
}
function getCriterionMax(c: Criterion): number {
if (typeof c.maxScore === 'number' && c.maxScore > 0) return c.maxScore
return parseScaleMax(c.scale)
}
function visibleCriteria(criteria: unknown): Criterion[] {
if (!Array.isArray(criteria)) return []
return (criteria as Criterion[]).filter((c) => {
if (!c) return false
if (!c.id && !c.label && !c.name) return false
if (c.type && HIDDEN_CRITERION_TYPES.has(c.type)) return false
return true
})
}
function globalScoreSummary(round: EvaluationRound) {
if (round.roundType === 'DELIBERATION') return null
const scores = round.evaluations
.map((ev) => ev.globalScore)
.filter((s): s is number => s !== null)
const avg = scores.length > 0 ? scores.reduce((a, b) => a + b, 0) / scores.length : null
const highest = scores.length > 0 ? Math.max(...scores) : null
const lowest = scores.length > 0 ? Math.min(...scores) : null
return { maxScore, avg, highest, lowest, scores }
}
function ScoreBar({ score, maxScore, color }: { score: number; maxScore: number; color: string }) {
const pct = (score / maxScore) * 100
return (
<div className="flex items-center gap-2 flex-1">
<div className="flex-1 overflow-hidden rounded-full bg-muted" style={{ height: 10 }}>
<div
className="h-full rounded-full transition-all duration-500"
style={{ width: `${pct}%`, backgroundColor: color }}
/>
</div>
<span className="text-sm font-semibold tabular-nums w-8 text-right">{score}</span>
</div>
)
}
function getScoreColor(score: number, maxScore: number): string {
const pct = score / maxScore
if (pct >= 0.8) return '#053d57'
if (pct >= 0.6) return '#1e7a8a'
if (pct >= 0.4) return '#557f8c'
if (pct >= 0.2) return '#c4453a'
return '#de0f1e'
if (scores.length === 0) return null
const max = 10
const avg = scores.reduce((a, b) => a + b, 0) / scores.length
const lowest = Math.min(...scores)
const highest = Math.max(...scores)
return { avg, lowest, highest, max }
}
function RoundIcon({ roundType, className }: { roundType: string; className?: string }) {
@@ -85,6 +88,48 @@ function roundIconBg(roundType: string) {
return 'bg-yellow-500/10'
}
function CriterionBar({ value, max }: { value: number; max: number }) {
const pct = Math.max(0, Math.min(100, (value / max) * 100))
return (
<div className="h-1.5 w-full overflow-hidden rounded-full bg-muted">
<div
className="h-full rounded-full bg-brand-blue transition-all"
style={{ width: `${pct}%` }}
/>
</div>
)
}
function NumericCriterion({ label, score, max }: { label: string; score: number | undefined; max: number }) {
return (
<div className="space-y-1">
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">{label}</span>
<span className="font-semibold tabular-nums">
{score !== undefined ? score : '—'}
<span className="text-muted-foreground font-normal text-xs"> / {max}</span>
</span>
</div>
{score !== undefined && <CriterionBar value={score} max={max} />}
</div>
)
}
function TextCriterion({ label, value }: { label: string; value: string }) {
return (
<div className="space-y-1.5">
<div className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
{label}
</div>
<div className="rounded-lg bg-muted/40 px-4 py-3 border-l-3 border-brand-teal">
<p className="text-sm italic text-muted-foreground leading-relaxed whitespace-pre-wrap">
{value}
</p>
</div>
</div>
)
}
export default function ApplicantEvaluationsPage() {
const { data: rounds, isLoading } = trpc.applicant.getMyEvaluations.useQuery()
@@ -95,14 +140,6 @@ export default function ApplicantEvaluationsPage() {
<h1 className="text-2xl font-bold">Jury Feedback</h1>
<p className="text-muted-foreground">Anonymous evaluations from jury members</p>
</div>
<div className="grid grid-cols-3 gap-px overflow-hidden rounded-lg border bg-border">
{[1, 2, 3].map((i) => (
<div key={i} className="bg-card p-4">
<Skeleton className="h-5 w-20 mb-2" />
<Skeleton className="h-8 w-16" />
</div>
))}
</div>
<div className="space-y-4">
{[1, 2].map((i) => (
<Card key={i}>
@@ -119,34 +156,14 @@ export default function ApplicantEvaluationsPage() {
const hasEvaluations = rounds && rounds.length > 0
// Compute global stats
const allScores: number[] = []
let totalEvaluations = 0
if (rounds) {
for (const round of rounds) {
totalEvaluations += round.evaluationCount
for (const ev of round.evaluations) {
if (ev.globalScore !== null && round.roundType !== 'DELIBERATION') {
// Normalize to 0-100 for live final scores
const normalized = round.roundType === 'LIVE_FINAL'
? ev.globalScore * 10
: ev.globalScore
allScores.push(normalized)
}
}
}
}
const globalAvg = allScores.length > 0
? allScores.reduce((a, b) => a + b, 0) / allScores.length
: null
const globalHighest = allScores.length > 0 ? Math.max(...allScores) : null
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-bold">Jury Feedback</h1>
<p className="text-muted-foreground">
Anonymous evaluations from jury members
{hasEvaluations
? `Anonymous evaluations from jury members across ${rounds.length} round${rounds.length === 1 ? '' : 's'}.`
: 'Anonymous evaluations from jury members.'}
</p>
</div>
@@ -164,105 +181,44 @@ export default function ApplicantEvaluationsPage() {
</Card>
) : (
<div className="space-y-6">
{/* Stats Summary Strip */}
<AnimatedCard index={0}>
<Card className="p-0 overflow-hidden">
<div className="grid grid-cols-3 divide-x divide-border">
<div className="p-4 text-center">
<div className="flex items-center justify-center gap-1.5 mb-1">
<BarChart3 className="h-3.5 w-3.5 text-blue-500" />
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Reviews</span>
</div>
<p className="text-2xl font-bold tabular-nums">{totalEvaluations}</p>
</div>
<div className="p-4 text-center">
<div className="flex items-center justify-center gap-1.5 mb-1">
<TrendingUp className="h-3.5 w-3.5 text-emerald-500" />
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Avg Score</span>
</div>
<p className="text-2xl font-bold tabular-nums">
{globalAvg !== null ? globalAvg.toFixed(1) : '—'}
{globalAvg !== null && <span className="text-sm font-normal text-muted-foreground"> / 100</span>}
</p>
</div>
<div className="p-4 text-center">
<div className="flex items-center justify-center gap-1.5 mb-1">
<Award className="h-3.5 w-3.5 text-amber-500" />
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Highest</span>
</div>
<p className="text-2xl font-bold tabular-nums">
{globalHighest !== null ? globalHighest : '—'}
{globalHighest !== null && <span className="text-sm font-normal text-muted-foreground"> / 100</span>}
</p>
</div>
</div>
</Card>
</AnimatedCard>
{/* Per-Round Cards */}
{rounds.map((round, roundIdx) => {
const { maxScore, avg, highest, lowest } = computeRoundStats(round)
const summary = globalScoreSummary(round)
return (
<AnimatedCard key={round.roundId} index={roundIdx + 1}>
<AnimatedCard key={round.roundId} index={roundIdx}>
<Card>
<CardHeader className="pb-3">
<div className="flex items-center justify-between">
<div className="flex items-start justify-between gap-3">
<CardTitle className="flex items-center gap-2.5">
<div className={cn('rounded-lg p-1.5', roundIconBg(round.roundType))}>
<RoundIcon roundType={round.roundType} />
</div>
<div>
<span>{round.roundName}</span>
{avg !== null && round.roundType !== 'DELIBERATION' && (
{summary && (
<p className="text-sm font-normal text-muted-foreground mt-0.5">
Average: <span className="font-semibold text-foreground">{avg.toFixed(1)}</span> / {maxScore}
{highest !== null && lowest !== null && highest !== lowest && (
<span className="ml-2">
Range: {lowest}{highest}
</span>
Average <span className="font-semibold text-foreground">{summary.avg.toFixed(1)}</span> / {summary.max}
{summary.lowest !== summary.highest && (
<span className="ml-2">· Lowest {summary.lowest} · Highest {summary.highest}</span>
)}
</p>
)}
</div>
</CardTitle>
<Badge variant="secondary">
{round.evaluationCount} {round.roundType === 'DELIBERATION' ? 'vote' : 'evaluation'}{round.evaluationCount !== 1 ? 's' : ''}
<Badge variant="secondary" className="shrink-0">
{round.evaluationCount} {round.roundType === 'DELIBERATION' ? 'vote' : 'review'}{round.evaluationCount !== 1 ? 's' : ''}
</Badge>
</div>
</CardHeader>
{/* Score Overview Bar — visual comparison across evaluators */}
{round.roundType !== 'DELIBERATION' && round.evaluations.some((ev) => ev.globalScore !== null) && (
<div className="px-6 pb-3">
<div className="rounded-lg bg-muted/40 p-3 space-y-2">
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Score Comparison</p>
{round.evaluations.map((ev, idx) => {
if (ev.globalScore === null) return null
return (
<div key={ev.id} className="flex items-center gap-3">
<span className="text-xs text-muted-foreground w-6 text-right shrink-0 tabular-nums">
#{idx + 1}
</span>
<ScoreBar
score={ev.globalScore}
maxScore={maxScore}
color={getScoreColor(ev.globalScore, maxScore)}
/>
</div>
)
})}
</div>
</div>
)}
<CardContent className="p-0">
<div className="divide-y">
{round.evaluations.map((ev, idx) => (
<div
key={ev.id}
className="px-6 py-4 space-y-3"
>
{round.evaluations.map((ev, idx) => {
const criteria = visibleCriteria(ev.criteria)
const scores = (ev.criterionScores ?? {}) as Record<string, unknown>
return (
<div key={ev.id} className="px-6 py-4 space-y-4">
<div className="flex items-center justify-between">
<span className="font-medium text-sm">
{round.roundType === 'DELIBERATION' ? `Juror #${idx + 1}` : `Evaluator #${idx + 1}`}
@@ -272,7 +228,7 @@ export default function ApplicantEvaluationsPage() {
<span className="flex items-center gap-1">
<Star className="h-3.5 w-3.5 text-yellow-500" />
<span className="text-sm font-bold tabular-nums">{ev.globalScore}</span>
<span className="text-xs text-muted-foreground">/ {maxScore}</span>
<span className="text-xs text-muted-foreground">/ 10</span>
</span>
)}
{ev.submittedAt && (
@@ -283,37 +239,23 @@ export default function ApplicantEvaluationsPage() {
</div>
</div>
{ev.criterionScores && ev.criteria && (
<div className="space-y-2">
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wider">Criteria Breakdown</p>
<div className="grid gap-2">
{(() => {
const criteria = ev.criteria as Array<{ id?: string; label?: string; name?: string; maxScore?: number }>
const scores = ev.criterionScores as Record<string, number>
return criteria
.filter((c) => c.id || c.label || c.name)
.map((c, ci) => {
{criteria.length > 0 && (
<div className="space-y-3">
{criteria.map((c, ci) => {
const key = c.id || String(ci)
const score = scores[key]
const cMax = c.maxScore || 10
const pct = score !== undefined ? (score / cMax) * 100 : 0
return (
<div key={ci} className="space-y-1">
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">{c.label || c.name || `Criterion ${ci + 1}`}</span>
<span className="font-semibold tabular-nums">
{score !== undefined ? score : '—'}
<span className="text-muted-foreground font-normal text-xs"> / {cMax}</span>
</span>
</div>
{score !== undefined && (
<Progress value={pct} className="h-1.5" />
)}
</div>
)
})
})()}
</div>
const label = c.label || c.name || `Criterion ${ci + 1}`
const raw = scores[key]
if (c.type === 'text') {
if (typeof raw !== 'string' || raw.trim() === '') return null
return <TextCriterion key={key} label={label} value={raw} />
}
// numeric (default)
const score = typeof raw === 'number' ? raw : undefined
const max = getCriterionMax(c)
return <NumericCriterion key={key} label={label} score={score} max={max} />
})}
</div>
)}
@@ -324,14 +266,15 @@ export default function ApplicantEvaluationsPage() {
{round.roundType === 'DELIBERATION' ? 'Result' : 'Written Feedback'}
</div>
<div className="rounded-lg bg-muted/40 px-4 py-3 border-l-3 border-brand-teal">
<p className="text-sm italic text-muted-foreground leading-relaxed">
<p className="text-sm italic text-muted-foreground leading-relaxed whitespace-pre-wrap">
{ev.feedbackText}
</p>
</div>
</div>
)}
</div>
))}
)
})}
</div>
</CardContent>
</Card>
@@ -339,7 +282,6 @@ export default function ApplicantEvaluationsPage() {
)
})}
{/* Confidentiality Footer */}
<div className="flex items-center justify-center gap-2 py-2">
<ShieldCheck className="h-4 w-4 text-muted-foreground/60" />
<p className="text-xs text-muted-foreground">

View File

@@ -1,6 +1,8 @@
'use client'
import { useState } from 'react'
import { useSession } from 'next-auth/react'
import { format } from 'date-fns'
import { trpc } from '@/lib/trpc/client'
import {
Card,
@@ -9,12 +11,18 @@ import {
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import { MentorChat } from '@/components/shared/mentor-chat'
import { WorkspaceFilesPanel } from '@/components/mentor/workspace-files-panel'
import { FinalDocumentsPanel } from '@/components/applicant/final-documents-panel'
import { RequestChangeDialog } from './request-change-dialog'
import {
MessageSquare,
UserCircle,
FileText,
UserCog,
} from 'lucide-react'
export default function ApplicantMentorPage() {
@@ -40,6 +48,8 @@ export default function ApplicantMentorPage() {
},
})
const [isChangeOpen, setIsChangeOpen] = useState(false)
if (dashLoading) {
return (
<div className="space-y-6">
@@ -71,7 +81,20 @@ export default function ApplicantMentorPage() {
)
}
const mentor = dashboardData?.project?.mentorAssignment?.mentor
const assignments = dashboardData?.project?.mentorAssignments ?? []
const hasMentors = assignments.length > 0
const primaryAssignment = assignments[0] ?? null
const primaryMentor = primaryAssignment?.mentor
const hasPendingChangeRequest = !!dashboardData?.hasPendingMentorChangeRequest
const dialogMentors = assignments
.filter((a) => !!a.mentor)
.map((a) => ({
assignmentId: a.id,
name: a.mentor?.name || a.mentor?.email || 'Mentor',
}))
const teamHeading = assignments.length > 1 ? 'Your mentor team' : 'Your mentor'
return (
<div className="space-y-6">
@@ -82,23 +105,72 @@ export default function ApplicantMentorPage() {
Mentor Communication
</h1>
<p className="text-muted-foreground">
Chat with your assigned mentor
{assignments.length > 1
? 'Chat with your assigned mentor team'
: 'Chat with your assigned mentor'}
</p>
</div>
{/* Mentor info */}
{mentor ? (
<Card className="bg-muted/50">
<CardContent className="p-4">
<div className="flex items-center gap-3">
<UserCircle className="h-10 w-10 text-muted-foreground" />
<div>
<p className="font-medium">{mentor.name || 'Mentor'}</p>
<p className="text-sm text-muted-foreground">{mentor.email}</p>
{/* Mentor list */}
{hasMentors ? (
<section className="space-y-3">
<h2 className="text-lg font-semibold tracking-tight">{teamHeading}</h2>
<div className="grid gap-3 md:grid-cols-2">
{assignments.map((assignment) => {
const mentor = assignment.mentor
if (!mentor) return null
const expertise = mentor.expertiseTags ?? []
return (
<Card key={assignment.id} className="bg-muted/50">
<CardContent className="p-4 space-y-3">
<div className="flex items-start gap-3">
<UserCircle className="h-10 w-10 text-muted-foreground shrink-0" />
<div className="min-w-0 flex-1">
<p className="font-medium truncate">
{mentor.name || 'Mentor'}
</p>
<p className="text-sm text-muted-foreground truncate">
{mentor.email}
</p>
{assignment.assignedAt && (
<p className="text-xs text-muted-foreground mt-1">
Assigned since {format(new Date(assignment.assignedAt), 'MMM d, yyyy')}
</p>
)}
</div>
</div>
{expertise.length > 0 && (
<div className="flex flex-wrap gap-1.5">
{expertise.map((tag) => (
<Badge key={tag} variant="secondary" className="font-normal">
{tag}
</Badge>
))}
</div>
)}
</CardContent>
</Card>
)
})}
</div>
{/* Request change action */}
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 pt-1">
<p className="text-sm text-muted-foreground">
{hasPendingChangeRequest
? "You have a pending mentor change request — admins will follow up soon."
: 'Need a different match? Let the program admins know.'}
</p>
<Button
variant="outline"
onClick={() => setIsChangeOpen(true)}
disabled={hasPendingChangeRequest}
>
<UserCog className="mr-2 h-4 w-4" />
{hasPendingChangeRequest ? 'Change requested' : 'Request a mentor change'}
</Button>
</div>
</section>
) : (
<Card className="bg-muted/50">
<CardContent className="flex flex-col items-center justify-center py-8">
@@ -112,12 +184,14 @@ export default function ApplicantMentorPage() {
)}
{/* Chat */}
{mentor && (
{primaryMentor && (
<Card>
<CardHeader>
<CardTitle>Messages</CardTitle>
<CardDescription>
Your conversation history with {mentor.name || 'your mentor'}
{assignments.length > 1
? 'Your conversation history with your mentor team'
: `Your conversation history with ${primaryMentor.name || 'your mentor'}`}
</CardDescription>
</CardHeader>
<CardContent>
@@ -133,6 +207,28 @@ export default function ApplicantMentorPage() {
</CardContent>
</Card>
)}
{/* Files */}
{primaryAssignment?.id && projectId && (
<WorkspaceFilesPanel
projectId={projectId}
mentorAssignmentId={primaryAssignment.id}
asApplicant
/>
)}
{/* Final Documents (self-hides when not a finalist) */}
<FinalDocumentsPanel variant="team" />
{/* Request change dialog */}
{projectId && (
<RequestChangeDialog
projectId={projectId}
mentors={dialogMentors}
open={isChangeOpen}
onOpenChange={setIsChangeOpen}
/>
)}
</div>
)
}

View File

@@ -0,0 +1,179 @@
'use client'
import { useEffect, useState } from 'react'
import { toast } from 'sonner'
import { Loader2 } from 'lucide-react'
import { trpc } from '@/lib/trpc/client'
import { Button } from '@/components/ui/button'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { Label } from '@/components/ui/label'
import { Textarea } from '@/components/ui/textarea'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
const REASON_MIN = 10
const REASON_MAX = 2000
const TARGET_ANY = '__any__'
type MentorOption = {
assignmentId: string
name: string
}
type RequestChangeDialogProps = {
projectId: string
mentors: MentorOption[]
open: boolean
onOpenChange: (open: boolean) => void
}
export function RequestChangeDialog({
projectId,
mentors,
open,
onOpenChange,
}: RequestChangeDialogProps) {
const [reason, setReason] = useState('')
const [target, setTarget] = useState<string>(TARGET_ANY)
const [touched, setTouched] = useState(false)
const utils = trpc.useUtils()
const requestChange = trpc.mentor.requestChange.useMutation({
onSuccess: async () => {
toast.success(
"Your request has been sent to the program admins. We'll review it and follow up.",
)
onOpenChange(false)
// Refresh dashboard so the disabled state for the button updates.
await utils.applicant.getMyDashboard.invalidate()
},
onError: (error) => {
toast.error(error.message || 'Could not send your request. Please try again.')
},
})
// Reset form when the dialog is closed.
useEffect(() => {
if (!open) {
setReason('')
setTarget(TARGET_ANY)
setTouched(false)
}
}, [open])
const trimmedReason = reason.trim()
const reasonTooShort = trimmedReason.length < REASON_MIN
const reasonTooLong = trimmedReason.length > REASON_MAX
const reasonInvalid = reasonTooShort || reasonTooLong
const showReasonError = touched && reasonInvalid
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
setTouched(true)
if (reasonInvalid) return
requestChange.mutate({
projectId,
targetAssignmentId: target === TARGET_ANY ? undefined : target,
reason: trimmedReason,
})
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-lg">
<DialogHeader>
<DialogTitle>Request a mentor change</DialogTitle>
<DialogDescription>
Share a few details so the program admins can follow up with you.
Your current mentor will not see this message.
</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4">
{mentors.length > 0 && (
<div className="space-y-2">
<Label htmlFor="targetMentor">About a specific mentor</Label>
<Select value={target} onValueChange={setTarget}>
<SelectTrigger id="targetMentor">
<SelectValue placeholder="Any / general" />
</SelectTrigger>
<SelectContent>
<SelectItem value={TARGET_ANY}>Any / general</SelectItem>
{mentors.map((m) => (
<SelectItem key={m.assignmentId} value={m.assignmentId}>
{m.name}
</SelectItem>
))}
</SelectContent>
</Select>
<p className="text-xs text-muted-foreground">
Optional. Use this if your request is about one of your co-mentors in particular.
</p>
</div>
)}
<div className="space-y-2">
<Label htmlFor="reason">
Why would you like a change?
</Label>
<Textarea
id="reason"
value={reason}
onChange={(e) => setReason(e.target.value)}
onBlur={() => setTouched(true)}
placeholder="Tell us why you'd like a change. The admin team will follow up."
rows={6}
maxLength={REASON_MAX}
aria-invalid={showReasonError || undefined}
required
/>
<div className="flex items-center justify-between text-xs">
{showReasonError ? (
<p className="text-destructive">
{reasonTooShort
? `Please provide at least ${REASON_MIN} characters.`
: `Please keep your message under ${REASON_MAX} characters.`}
</p>
) : (
<p className="text-muted-foreground">
{REASON_MIN}{REASON_MAX} characters.
</p>
)}
<p className="text-muted-foreground tabular-nums">
{trimmedReason.length}/{REASON_MAX}
</p>
</div>
</div>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => onOpenChange(false)}
disabled={requestChange.isPending}
>
Cancel
</Button>
<Button type="submit" disabled={requestChange.isPending}>
{requestChange.isPending && (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
)}
Send request
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)
}

View File

@@ -17,6 +17,12 @@ import { Skeleton } from '@/components/ui/skeleton'
import { Textarea } from '@/components/ui/textarea'
import { CompetitionTimelineSidebar } from '@/components/applicant/competition-timeline'
import { MentoringRequestCard } from '@/components/applicant/mentoring-request-card'
import { MentorConversationCard } from '@/components/applicant/mentor-conversation-card'
import { AttendingMembersCard } from '@/components/applicant/attending-members-card'
import { MyLogisticsCard } from '@/components/applicant/my-logistics-card'
import { FinalDocumentsBanner } from '@/components/applicant/final-documents-banner'
import { LunchBanner } from '@/components/applicant/lunch-banner'
import { ExternalAttendeesStrip } from '@/components/applicant/external-attendees-strip'
import { AnimatedCard } from '@/components/shared/animated-container'
import { ProjectLogoUpload } from '@/components/shared/project-logo-upload'
import { Progress } from '@/components/ui/progress'
@@ -201,6 +207,9 @@ export default function ApplicantDashboardPage() {
</div>
</div>
{/* Grand Final document upload banner (auto-hides for non-finalists) */}
<FinalDocumentsBanner />
{/* Active round deadline banner */}
{!isRejected && openRounds.length > 0 && (() => {
const submissionTypes = new Set(['INTAKE', 'SUBMISSION', 'MENTORING'])
@@ -215,12 +224,12 @@ export default function ApplicantDashboardPage() {
key={round.id}
className={`flex flex-col sm:flex-row items-start sm:items-center gap-3 rounded-lg border px-4 py-3 ${
isUrgent
? 'border-amber-500/50 bg-amber-50 dark:bg-amber-950/20'
? 'border-amber-500/50 bg-amber-50'
: 'border-primary/20 bg-primary/5'
}`}
>
<div className="flex items-center gap-2 min-w-0">
<Clock className={`h-4 w-4 shrink-0 ${isUrgent ? 'text-amber-600 dark:text-amber-400' : 'text-primary'}`} />
<Clock className={`h-4 w-4 shrink-0 ${isUrgent ? 'text-amber-600' : 'text-primary'}`} />
<span className="font-medium text-sm truncate">{round.name}</span>
<Badge variant={isUrgent ? 'warning' : 'default'} className="shrink-0">
{remaining > 0 ? formatCountdown(remaining) + ' left' : 'Closed'}
@@ -401,6 +410,22 @@ export default function ApplicantDashboardPage() {
</AnimatedCard>
))}
{/* Lunch banner (auto-hides when lunch event disabled or unconfigured) */}
<LunchBanner programId={project.programId} />
{/* External lunch attendees attached to this team (auto-hides if none) */}
<ExternalAttendeesStrip projectId={project.id} />
{/* Grand finale attendee roster (auto-hides until confirmation status is CONFIRMED) */}
<AttendingMembersCard />
{/* Grand-finale logistics: hotel, flight, visa (auto-hides when not a confirmed finalist) */}
<MyLogisticsCard />
{/* Conversation with assigned mentor (auto-hides when no mentor assigned) */}
<MentorConversationCard projectId={project.id} />
{/* Jury Feedback Card */}
{totalEvaluations > 0 && (
<AnimatedCard index={4}>
@@ -422,13 +447,14 @@ export default function ApplicantDashboardPage() {
</CardHeader>
<CardContent className="space-y-3">
{evaluations?.map((round) => {
const showScore = round.roundType !== 'DELIBERATION'
const scores = round.evaluations
.map((ev) => ev.globalScore)
.filter((s): s is number => s !== null)
const avgScore = scores.length > 0
const avgScore = showScore && scores.length > 0
? scores.reduce((a, b) => a + b, 0) / scores.length
: null
const maxScore = round.roundType === 'LIVE_FINAL' ? 10 : 100
const maxScore = 10
const pct = avgScore !== null ? (avgScore / maxScore) * 100 : 0
const roundIcon = round.roundType === 'LIVE_FINAL'
? <Trophy className="h-3.5 w-3.5 text-amber-500" />

View File

@@ -357,15 +357,33 @@ export default function ApplicantProjectPage() {
)}
</div>
{/* Mentor info */}
{project.mentorAssignment?.mentor && (
{(() => {
type MentorAssignment = {
droppedAt: Date | string | null
mentor: { name: string | null; email: string } | null
}
const active = (
(project.mentorAssignments as MentorAssignment[] | undefined) ?? []
).filter((a) => !a.droppedAt && a.mentor)
if (active.length === 0) return null
return (
<div className="rounded-lg border p-3 bg-muted/50">
<p className="text-sm font-medium mb-1">Assigned Mentor</p>
<p className="text-sm text-muted-foreground">
{project.mentorAssignment.mentor.name} ({project.mentorAssignment.mentor.email})
<p className="text-sm font-medium mb-1">
{active.length === 1 ? 'Assigned Mentor' : `Assigned Mentors (${active.length})`}
</p>
</div>
<ul className="space-y-0.5">
{active.map((a, idx) => (
<li key={`${a.mentor!.email}-${idx}`} className="text-sm text-muted-foreground">
{a.mentor!.name ?? a.mentor!.email}
{a.mentor!.name && (
<span className="text-xs"> ({a.mentor!.email})</span>
)}
</li>
))}
</ul>
</div>
)
})()}
{/* Tags */}
{project.tags && project.tags.length > 0 && (

View File

@@ -160,8 +160,12 @@ function AcceptInviteContent() {
setState('error')
setErrorType('AUTH_FAILED')
} else if (result?.ok) {
// Redirect to set-password (middleware will enforce this since mustSetPassword=true)
window.location.href = '/set-password'
// Let app/page.tsx route by role. Middleware will detour to
// /set-password if the user still needs to set one (first-time
// setup); for users who already had a password (admin-issued
// access link, magic-login style) it'll go straight to their
// dashboard.
window.location.href = '/'
}
} catch {
setState('error')

View File

@@ -1,579 +0,0 @@
'use client'
import { use, useRef, useState } from 'react'
import { useRouter } from 'next/navigation'
import type { Route } from 'next'
import { trpc } from '@/lib/trpc/client'
import { Button } from '@/components/ui/button'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Skeleton } from '@/components/ui/skeleton'
import { Textarea } from '@/components/ui/textarea'
import { Separator } from '@/components/ui/separator'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { toast } from 'sonner'
import {
ArrowLeft,
Trophy,
CheckCircle2,
Loader2,
ChevronDown,
ChevronUp,
FileText,
Star,
Users,
} from 'lucide-react'
import { cn } from '@/lib/utils'
import { CountryDisplay } from '@/components/shared/country-display'
import { ProjectFilesSection } from '@/components/jury/project-files-section'
export default function AwardMasterVotingPage({
params,
}: {
params: Promise<{ id: string }>
}) {
const { id: awardId } = use(params)
const router = useRouter()
// State
const [selectedProjectId, setSelectedProjectId] = useState<string | null>(
null
)
const [expandedProjectId, setExpandedProjectId] = useState<string | null>(
null
)
const [justification, setJustification] = useState('')
// Queries & mutations
const utils = trpc.useUtils()
const { data, isLoading } =
trpc.specialAward.getMyAwardDetailEnhanced.useQuery({ awardId })
const submitVote = trpc.specialAward.submitAwardMasterVote.useMutation({
onSuccess: () => {
utils.specialAward.getMyAwardDetailEnhanced.invalidate({ awardId })
toast.success('Vote submitted')
},
onError: (err) => toast.error(err.message),
})
const confirmWinner = trpc.specialAward.confirmWinner.useMutation({
onSuccess: () => {
utils.specialAward.getMyAwardDetailEnhanced.invalidate({ awardId })
toast.success('Winner confirmed and award closed')
},
onError: (err) => toast.error(err.message),
})
// Initialize selection from existing vote
const initializedRef = useRef(false)
if (data && !initializedRef.current && data.myVotes.length > 0) {
initializedRef.current = true
setSelectedProjectId(data.myVotes[0].projectId)
if (data.myVotes[0].justification) {
setJustification(data.myVotes[0].justification)
}
}
// Loading state
if (isLoading) {
return (
<div className="space-y-6">
<Skeleton className="h-9 w-48" />
<Skeleton className="h-6 w-72" />
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
{[...Array(6)].map((_, i) => (
<Skeleton key={i} className="h-44" />
))}
</div>
</div>
)
}
if (!data) return null
// Destructure data
const { award, projects, myVotes, isChair, otherVotes, totalJurors } = data
const hasVoted = myVotes.length > 0
const isVotingOpen = award.status === 'VOTING_OPEN'
const isClosed = award.status === 'CLOSED'
const selectedProject = projects.find((p) => p.id === selectedProjectId)
// Toggle project expansion
const handleProjectClick = (projectId: string) => {
if (isVotingOpen) setSelectedProjectId(projectId)
setExpandedProjectId(expandedProjectId === projectId ? null : projectId)
}
// Submit vote handler
const handleSubmitVote = () => {
if (!selectedProjectId) return
submitVote.mutate({
awardId,
projectId: selectedProjectId,
justification: justification.trim() || undefined,
})
}
// Confirm winner handler
const handleConfirmWinner = () => {
confirmWinner.mutate({ awardId })
}
// Find the winner project for closed state
const winnerProject = isClosed
? projects.find((p) => p.id === award.winnerProjectId)
: null
return (
<div className="space-y-6">
{/* Back button */}
<div className="flex items-center gap-4">
<Button
variant="ghost"
onClick={() => router.push('/award-master' as Route)}
className="-ml-4"
>
<ArrowLeft className="mr-2 h-4 w-4" />
Back
</Button>
</div>
{/* Header */}
<div>
<h1 className="text-2xl font-semibold tracking-tight flex items-center gap-2">
<Trophy className="h-6 w-6 text-amber-500" />
{award.name}
</h1>
<div className="mt-1 flex items-center gap-2">
<Badge
variant={
isVotingOpen
? 'default'
: isClosed
? 'secondary'
: 'outline'
}
>
{award.status.replace('_', ' ')}
</Badge>
{hasVoted && !isClosed && (
<Badge variant="outline" className="text-green-600">
<CheckCircle2 className="mr-1 h-3 w-3" />
Voted
</Badge>
)}
{award.competition && (
<span className="text-sm text-muted-foreground">
{award.competition.name}
</span>
)}
</div>
{award.criteriaText && (
<Card className="mt-3 bg-muted/30">
<CardContent className="py-3 px-4">
<p className="text-sm text-muted-foreground leading-relaxed">
<Star className="mr-1.5 inline h-4 w-4 text-amber-500" />
<span className="font-medium text-foreground">Criteria: </span>
{award.criteriaText}
</p>
</CardContent>
</Card>
)}
</div>
{/* Closed State */}
{isClosed ? (
<Card className="border-amber-200 bg-amber-50/50 dark:border-amber-900 dark:bg-amber-950/20">
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
<div className="rounded-full bg-amber-100 p-4 dark:bg-amber-900/40">
<Trophy className="h-12 w-12 text-amber-500" />
</div>
<p className="mt-4 text-lg font-semibold">Award Finalized</p>
{winnerProject ? (
<div className="mt-3 space-y-1">
<p className="text-xl font-bold text-[#053d57] dark:text-blue-300">
{winnerProject.title}
</p>
{winnerProject.teamName && (
<p className="text-sm text-muted-foreground">
{winnerProject.teamName}
</p>
)}
</div>
) : (
<p className="mt-2 text-sm text-muted-foreground">
This award has been finalized
</p>
)}
</CardContent>
</Card>
) : (
<>
{/* Project Grid */}
<div>
<h2 className="text-lg font-semibold mb-3">
Eligible Projects ({projects.length})
</h2>
{isVotingOpen && (
<p className="text-sm text-muted-foreground mb-4">
Click a project to select it as your pick and expand details
</p>
)}
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
{projects.map((project) => (
<div
key={project.id}
className={cn(
expandedProjectId === project.id && 'sm:col-span-2 lg:col-span-3'
)}
>
<Card
className={cn(
'cursor-pointer transition-all',
selectedProjectId === project.id
? 'ring-2 ring-primary bg-primary/5'
: 'hover:bg-muted/50'
)}
onClick={() => handleProjectClick(project.id)}
>
<CardHeader className="pb-2">
<div className="flex items-start justify-between">
<div className="flex-1 min-w-0">
<CardTitle className="text-base">
{project.title}
</CardTitle>
{project.teamName && (
<CardDescription className="mt-0.5">
{project.teamName}
</CardDescription>
)}
</div>
<div className="ml-2 shrink-0">
{expandedProjectId === project.id ? (
<ChevronUp className="h-4 w-4 text-muted-foreground" />
) : (
<ChevronDown className="h-4 w-4 text-muted-foreground" />
)}
</div>
</div>
</CardHeader>
<CardContent>
<div className="flex flex-wrap items-center gap-1.5">
{project.competitionCategory && (
<Badge variant="outline" className="text-xs">
{project.competitionCategory.replace(/_/g, ' ')}
</Badge>
)}
{project.country && (
<Badge variant="outline" className="text-xs">
<CountryDisplay country={project.country} />
</Badge>
)}
{project.evaluationScore && (
<Badge
variant="secondary"
className="text-xs bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-300"
>
<Star className="mr-0.5 h-3 w-3" />
Avg: {project.evaluationScore.avg.toFixed(1)}/10 (
{project.evaluationScore.count}{' '}
{project.evaluationScore.count === 1
? 'review'
: 'reviews'}
)
</Badge>
)}
{selectedProjectId === project.id && (
<Badge className="text-xs bg-green-100 text-green-700 dark:bg-green-950 dark:text-green-300">
<CheckCircle2 className="mr-0.5 h-3 w-3" />
Selected
</Badge>
)}
</div>
</CardContent>
</Card>
{/* Expanded Project Detail */}
{expandedProjectId === project.id && (
<Card className="mt-2 border-dashed">
<CardContent className="space-y-4 py-4">
{project.description && (
<div>
<h4 className="text-sm font-medium mb-1 flex items-center gap-1.5">
<FileText className="h-4 w-4 text-muted-foreground" />
Description
</h4>
<p className="text-sm text-muted-foreground leading-relaxed whitespace-pre-line">
{project.description}
</p>
</div>
)}
{award.evaluationRoundId && (
<div>
<h4 className="text-sm font-medium mb-2 flex items-center gap-1.5">
<FileText className="h-4 w-4 text-muted-foreground" />
Documents
</h4>
<ProjectFilesSection
projectId={project.id}
roundId={award.evaluationRoundId}
/>
</div>
)}
{project.evaluationScore && (
<Card className="bg-blue-50/50 dark:bg-blue-950/20">
<CardContent className="py-3 px-4">
<div className="flex items-center gap-2">
<Star className="h-5 w-5 text-blue-600 dark:text-blue-400" />
<div>
<p className="text-sm font-medium">
Evaluation Score
</p>
<p className="text-lg font-bold text-blue-700 dark:text-blue-300">
{project.evaluationScore.avg.toFixed(1)} / 10
</p>
<p className="text-xs text-muted-foreground">
Based on {project.evaluationScore.count}{' '}
{project.evaluationScore.count === 1
? 'evaluation'
: 'evaluations'}
</p>
</div>
</div>
</CardContent>
</Card>
)}
</CardContent>
</Card>
)}
</div>
))}
</div>
</div>
{/* Vote Section */}
{isVotingOpen && (
<Card>
<CardHeader>
<CardTitle className="text-base">Your Vote</CardTitle>
<CardDescription>
{hasVoted
? 'You can update your vote until the award is finalized'
: 'Select a project above and submit your vote'}
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{selectedProject ? (
<div className="rounded-lg border bg-muted/30 p-3">
<p className="text-sm text-muted-foreground">
Your selection
</p>
<p className="font-semibold">{selectedProject.title}</p>
{selectedProject.teamName && (
<p className="text-sm text-muted-foreground">
{selectedProject.teamName}
</p>
)}
</div>
) : (
<p className="text-sm text-muted-foreground italic">
No project selected. Click a project card above to select it.
</p>
)}
<div className="space-y-2">
<label
htmlFor="justification"
className="text-sm font-medium"
>
Justification
</label>
<Textarea
id="justification"
value={justification}
onChange={(e) => setJustification(e.target.value)}
placeholder="Why did you choose this project? (optional)"
maxLength={2000}
rows={4}
/>
<p className="text-xs text-muted-foreground text-right">
{justification.length} / 2000
</p>
</div>
<div className="flex justify-end">
<Button
onClick={handleSubmitVote}
disabled={!selectedProjectId || submitVote.isPending}
>
{submitVote.isPending ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<CheckCircle2 className="mr-2 h-4 w-4" />
)}
{hasVoted ? 'Update Vote' : 'Submit Vote'}
</Button>
</div>
</CardContent>
</Card>
)}
{/* Chair Section */}
{isChair && isVotingOpen && (
<>
<Separator />
<Card>
<CardHeader>
<CardTitle className="text-base flex items-center gap-2">
<Users className="h-5 w-5 text-muted-foreground" />
Team Votes
</CardTitle>
<CardDescription>
As chair, you can view team votes and confirm the winner
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{otherVotes.length > 0 ? (
<div className="space-y-3">
{otherVotes.map((vote) => {
const votedProject = projects.find(
(p) => p.id === vote.projectId
)
return (
<div
key={vote.userId}
className="rounded-lg border p-3 space-y-1"
>
<div className="flex items-center justify-between">
<p className="font-medium text-sm">
{vote.userName || 'Anonymous Juror'}
</p>
<Badge variant="outline" className="text-xs">
voted for
</Badge>
</div>
<p className="text-sm font-semibold">
{votedProject?.title || 'Unknown project'}
</p>
{vote.justification && (
<p className="text-sm text-muted-foreground italic">
&ldquo;{vote.justification}&rdquo;
</p>
)}
</div>
)
})}
</div>
) : (
<p className="text-sm text-muted-foreground italic">
Waiting for other team members to vote
</p>
)}
{/* Vote tally */}
<div className="rounded-lg bg-muted/30 p-3">
<p className="text-sm font-medium">Vote Summary</p>
<p className="text-sm text-muted-foreground">
{otherVotes.length + (hasVoted ? 1 : 0)} of{' '}
{totalJurors} jurors have voted
</p>
{(() => {
const allVotes = [
...otherVotes.map((v) => v.projectId),
...(hasVoted && myVotes[0]
? [myVotes[0].projectId]
: []),
]
const tally = new Map<string, number>()
for (const pid of allVotes) {
tally.set(pid, (tally.get(pid) || 0) + 1)
}
const sorted = [...tally.entries()].sort(
(a, b) => b[1] - a[1]
)
if (sorted.length === 0) return null
return (
<div className="mt-2 space-y-1">
{sorted.map(([pid, count]) => {
const proj = projects.find((p) => p.id === pid)
return (
<div
key={pid}
className="flex items-center justify-between text-sm"
>
<span>{proj?.title || 'Unknown'}</span>
<Badge variant="secondary" className="text-xs">
{count} {count === 1 ? 'vote' : 'votes'}
</Badge>
</div>
)
})}
</div>
)
})()}
</div>
{/* Confirm Winner button */}
<div className="flex justify-end">
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant="default"
disabled={!hasVoted || confirmWinner.isPending}
>
{confirmWinner.isPending ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<Trophy className="mr-2 h-4 w-4" />
)}
Confirm Winner
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
Confirm Award Winner
</AlertDialogTitle>
<AlertDialogDescription>
This will finalize the winner and close the award.
This cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={handleConfirmWinner}>
Confirm Winner
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</CardContent>
</Card>
</>
)}
</>
)}
</div>
)
}

View File

@@ -1,91 +0,0 @@
'use client'
import Link from 'next/link'
import type { Route } from 'next'
import { trpc } from '@/lib/trpc/client'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Skeleton } from '@/components/ui/skeleton'
import { Trophy } from 'lucide-react'
export default function AwardMasterDashboard() {
const { data: awards, isLoading } = trpc.specialAward.getMyAwards.useQuery()
if (isLoading) {
return (
<div className="space-y-6">
<Skeleton className="h-9 w-48" />
<div className="grid gap-4 sm:grid-cols-2">
{[...Array(2)].map((_, i) => (
<Skeleton key={i} className="h-40" />
))}
</div>
</div>
)
}
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold tracking-tight">
Award Master Dashboard
</h1>
<p className="text-muted-foreground">
Review eligible projects and select award winners
</p>
</div>
{awards && awards.length > 0 ? (
<div className="grid gap-4 sm:grid-cols-2">
{awards.map((award) => (
<Link key={award.id} href={`/award-master/awards/${award.id}` as Route}>
<Card className="transition-colors hover:bg-muted/50 cursor-pointer h-full">
<CardHeader>
<div className="flex items-start justify-between">
<CardTitle className="flex items-center gap-2">
<Trophy className="h-5 w-5 text-amber-500" />
{award.name}
</CardTitle>
<Badge
variant={
award.status === 'VOTING_OPEN' ? 'default' : 'secondary'
}
>
{award.status.replace('_', ' ')}
</Badge>
</div>
{award.description && (
<CardDescription className="line-clamp-2">
{award.description}
</CardDescription>
)}
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground">
{award._count.eligibilities} eligible projects
</p>
</CardContent>
</Card>
</Link>
))}
</div>
) : (
<Card>
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
<Trophy className="h-12 w-12 text-muted-foreground/50" />
<p className="mt-2 font-medium">No awards assigned</p>
<p className="text-sm text-muted-foreground">
You will see your awards here when they are assigned to you
</p>
</CardContent>
</Card>
)}
</div>
)
}

View File

@@ -1,24 +0,0 @@
import { requireRole } from '@/lib/auth-redirect'
import { AwardMasterNav } from '@/components/layouts/award-master-nav'
export const dynamic = 'force-dynamic'
export default async function AwardMasterLayout({
children,
}: {
children: React.ReactNode
}) {
const session = await requireRole('AWARD_MASTER', 'PROGRAM_ADMIN', 'SUPER_ADMIN')
return (
<div className="min-h-screen bg-background">
<AwardMasterNav
user={{
name: session.user.name,
email: session.user.email,
}}
/>
<main className="container-app py-6 lg:py-8">{children}</main>
</div>
)
}

View File

@@ -13,16 +13,39 @@ import {
} from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Skeleton } from '@/components/ui/skeleton'
import { Textarea } from '@/components/ui/textarea'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { toast } from 'sonner'
import {
ArrowLeft,
Trophy,
CheckCircle2,
Loader2,
GripVertical,
ChevronDown,
Users,
Tag,
Star,
Gavel,
} from 'lucide-react'
import { cn } from '@/lib/utils'
import { CountryDisplay } from '@/components/shared/country-display'
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '@/components/ui/collapsible'
import { FileViewer } from '@/components/shared/file-viewer'
import { ProjectLogo } from '@/components/shared/project-logo'
export default function JuryAwardVotingPage({
params,
@@ -40,16 +63,38 @@ export default function JuryAwardVotingPage({
utils.specialAward.getMyAwardDetail.invalidate({ awardId })
},
})
const confirmWinner = trpc.specialAward.confirmWinner.useMutation({
onSuccess: () => {
utils.specialAward.getMyAwardDetail.invalidate({ awardId })
toast.success('Winner confirmed and award closed')
},
onError: (err) => toast.error(err.message),
})
const [selectedProjectId, setSelectedProjectId] = useState<string | null>(
null
)
const [rankedIds, setRankedIds] = useState<string[]>([])
const [justification, setJustification] = useState('')
const [expandedProjects, setExpandedProjects] = useState<Set<string>>(new Set())
const toggleExpanded = (projectId: string) => {
setExpandedProjects((prev) => {
const next = new Set(prev)
if (next.has(projectId)) next.delete(projectId)
else next.add(projectId)
return next
})
}
// Initialize from existing votes
if (data && !selectedProjectId && !rankedIds.length && data.myVotes.length > 0) {
if (data.award.scoringMode === 'PICK_WINNER') {
setSelectedProjectId(data.myVotes[0]?.projectId || null)
if (data.myVotes[0]?.justification) {
setJustification(data.myVotes[0].justification)
}
} else if (data.award.scoringMode === 'RANKED') {
const sorted = [...data.myVotes]
.sort((a, b) => (a.rank || 0) - (b.rank || 0))
@@ -63,7 +108,10 @@ export default function JuryAwardVotingPage({
try {
await submitVote.mutateAsync({
awardId,
votes: [{ projectId: selectedProjectId }],
votes: [{
projectId: selectedProjectId,
justification: justification.trim() || undefined,
}],
})
toast.success('Vote submitted')
refetch()
@@ -115,9 +163,10 @@ export default function JuryAwardVotingPage({
if (!data) return null
const { award, projects, myVotes } = data
const { award, projects, myVotes, isChair, otherVotes, totalJurors } = data
const hasVoted = myVotes.length > 0
const isVotingOpen = award.status === 'VOTING_OPEN'
const isClosed = award.status === 'CLOSED'
return (
<div className="space-y-6">
@@ -165,41 +214,41 @@ export default function JuryAwardVotingPage({
/* PICK_WINNER Mode */
<div className="space-y-4">
<p className="text-sm text-muted-foreground">
Select one project as the winner
Select one project as the winner. Click the project header to expand details.
</p>
<div className="grid gap-3 sm:grid-cols-2">
<div className="space-y-3">
{projects.map((project) => (
<Card
<ProjectCard
key={project.id}
className={cn(
'cursor-pointer transition-all',
selectedProjectId === project.id
? 'ring-2 ring-primary bg-primary/5'
: 'hover:bg-muted/50'
)}
onClick={() => setSelectedProjectId(project.id)}
>
<CardHeader className="pb-2">
<CardTitle className="text-base">{project.title}</CardTitle>
<CardDescription>{project.teamName}</CardDescription>
</CardHeader>
<CardContent>
<div className="flex flex-wrap gap-1">
{project.competitionCategory && (
<Badge variant="outline" className="text-xs">
{project.competitionCategory.replace('_', ' ')}
</Badge>
)}
{project.country && (
<Badge variant="outline" className="text-xs">
<CountryDisplay country={project.country} />
</Badge>
)}
</div>
</CardContent>
</Card>
project={project}
isSelected={selectedProjectId === project.id}
isExpanded={expandedProjects.has(project.id)}
onSelect={() => setSelectedProjectId(project.id)}
onToggleExpand={() => toggleExpanded(project.id)}
/>
))}
</div>
{selectedProjectId && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-base">Justification (optional)</CardTitle>
<CardDescription>
Visible to the jury chair when they finalize the award.
</CardDescription>
</CardHeader>
<CardContent>
<Textarea
rows={3}
maxLength={2000}
placeholder="Why this project? (optional)"
value={justification}
onChange={(e) => setJustification(e.target.value)}
/>
</CardContent>
</Card>
)}
<div className="flex justify-end">
<Button
onClick={handleSubmitPickWinner}
@@ -213,48 +262,69 @@ export default function JuryAwardVotingPage({
{hasVoted ? 'Update Vote' : 'Submit Vote'}
</Button>
</div>
{isChair && totalJurors > 1 && (
<ChairPanel
award={award}
projects={projects}
otherVotes={otherVotes}
totalJurors={totalJurors}
hasVoted={hasVoted}
onConfirm={() => confirmWinner.mutate({ awardId })}
isPending={confirmWinner.isPending}
/>
)}
</div>
) : award.scoringMode === 'RANKED' ? (
/* RANKED Mode */
<div className="space-y-4">
<p className="text-sm text-muted-foreground">
Select and rank your top {award.maxRankedPicks || 5} projects. Click
to add/remove, drag to reorder.
to add/remove from your rankings. Expand each project to see full details.
</p>
{/* Selected rankings */}
{rankedIds.length > 0 && (
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-base">Your Rankings</CardTitle>
<CardTitle className="text-base">Your Rankings ({rankedIds.length}/{award.maxRankedPicks || 5})</CardTitle>
</CardHeader>
<CardContent className="space-y-2">
{rankedIds.map((id, index) => {
const project = projects.find((p) => p.id === id)
if (!project) return null
return (
<div
key={id}
className="flex items-center gap-3 rounded-lg border p-3"
>
<span className="font-bold text-lg w-8 text-center">
<Collapsible key={id} open={expandedProjects.has(id)}>
<div className="flex items-center gap-3 rounded-lg border p-3">
<span className="font-bold text-lg w-8 text-center text-brand-blue">
{index + 1}
</span>
<GripVertical className="h-4 w-4 text-muted-foreground" />
<div className="flex-1">
<p className="font-medium">{project.title}</p>
<ProjectLogo project={project} logoUrl={project.logoUrl} size="sm" fallback="initials" />
<div className="flex-1 min-w-0">
<p className="font-medium truncate">{project.title}</p>
<p className="text-sm text-muted-foreground">
{project.teamName}
{project.country && <> &middot; <CountryDisplay country={project.country} /></>}
</p>
</div>
<CollapsibleTrigger asChild>
<Button variant="ghost" size="sm" onClick={() => toggleExpanded(id)}>
<ChevronDown className={cn('h-4 w-4 transition-transform', expandedProjects.has(id) && 'rotate-180')} />
</Button>
</CollapsibleTrigger>
<Button
variant="ghost"
size="sm"
onClick={() => toggleRanked(id)}
className="text-destructive hover:text-destructive"
>
Remove
</Button>
</div>
<CollapsibleContent>
<ProjectDetails project={project} />
</CollapsibleContent>
</Collapsible>
)
})}
</CardContent>
@@ -262,36 +332,20 @@ export default function JuryAwardVotingPage({
)}
{/* Available projects */}
<div className="grid gap-3 sm:grid-cols-2">
<h3 className="text-sm font-medium text-muted-foreground">Available Projects</h3>
<div className="space-y-3">
{projects
.filter((p) => !rankedIds.includes(p.id))
.map((project) => (
<Card
<ProjectCard
key={project.id}
className="cursor-pointer hover:bg-muted/50 transition-colors"
onClick={() => toggleRanked(project.id)}
>
<CardHeader className="pb-2">
<CardTitle className="text-base">
{project.title}
</CardTitle>
<CardDescription>{project.teamName}</CardDescription>
</CardHeader>
<CardContent>
<div className="flex flex-wrap gap-1">
{project.competitionCategory && (
<Badge variant="outline" className="text-xs">
{project.competitionCategory.replace('_', ' ')}
</Badge>
)}
{project.country && (
<Badge variant="outline" className="text-xs">
<CountryDisplay country={project.country} />
</Badge>
)}
</div>
</CardContent>
</Card>
project={project}
isExpanded={expandedProjects.has(project.id)}
onSelect={() => toggleRanked(project.id)}
onToggleExpand={() => toggleExpanded(project.id)}
selectLabel={rankedIds.length < (award.maxRankedPicks || 5) ? `Add to #${rankedIds.length + 1}` : undefined}
/>
))}
</div>
@@ -325,3 +379,312 @@ export default function JuryAwardVotingPage({
</div>
)
}
/* ── Shared project detail components ── */
type ProjectData = {
id: string
title: string
teamName: string | null
description: string | null
competitionCategory: string | null
country: string | null
tags: string[]
logoKey?: string | null
logoUrl?: string | null
evaluationScore?: { avg: number; count: number } | null
files: Array<{
id: string
fileName: string
fileType: string
mimeType: string
size: number
bucket: string
objectKey: string
version: number
isLate: boolean
pageCount?: number | null
detectedLang?: string | null
langConfidence?: number | null
analyzedAt?: Date | string | null
createdAt: Date
}>
teamMembers: Array<{
id: string
role: string
user: { name: string | null; email: string }
}>
}
type OtherVote = {
userId: string
userName: string | null
projectId: string
justification: string | null
}
function ProjectDetails({ project }: { project: ProjectData }) {
return (
<div className="px-4 pb-4 pt-2 space-y-4 border-t mt-2">
{project.evaluationScore && (
<div className="flex items-center gap-2 rounded-md bg-blue-50/50 px-3 py-2">
<Star className="h-4 w-4 text-blue-600 shrink-0" />
<div className="text-sm">
<span className="font-semibold text-blue-700">
{project.evaluationScore.avg.toFixed(1)} / 10
</span>
<span className="text-muted-foreground ml-2">
from {project.evaluationScore.count}{' '}
{project.evaluationScore.count === 1 ? 'evaluation' : 'evaluations'}
</span>
</div>
</div>
)}
{project.description && (
<p className="text-sm text-muted-foreground whitespace-pre-line">{project.description}</p>
)}
{project.tags.length > 0 && (
<div className="flex items-center gap-2 flex-wrap">
<Tag className="h-3.5 w-3.5 text-muted-foreground shrink-0" />
{project.tags.map((tag) => (
<Badge key={tag} variant="secondary" className="text-xs">{tag}</Badge>
))}
</div>
)}
{project.teamMembers.length > 0 && (
<div>
<div className="flex items-center gap-2 mb-1.5">
<Users className="h-3.5 w-3.5 text-muted-foreground" />
<span className="text-xs font-medium text-muted-foreground">Team Members</span>
</div>
<div className="flex flex-wrap gap-2">
{project.teamMembers.map((m) => (
<Badge key={m.id} variant="outline" className="text-xs">
{m.user.name || m.user.email}
{m.role !== 'MEMBER' && ` (${m.role.toLowerCase()})`}
</Badge>
))}
</div>
</div>
)}
{project.files.length > 0 && (
<div onClick={(e) => e.stopPropagation()}>
<FileViewer files={project.files as Parameters<typeof FileViewer>[0]['files']} projectId={project.id} />
</div>
)}
{!project.description && project.tags.length === 0 && project.files.length === 0 && project.teamMembers.length === 0 && (
<p className="text-sm text-muted-foreground italic">No additional details available</p>
)}
</div>
)
}
function ProjectCard({
project,
isSelected,
isExpanded,
onSelect,
onToggleExpand,
selectLabel,
}: {
project: ProjectData
isSelected?: boolean
isExpanded: boolean
onSelect: () => void
onToggleExpand: () => void
selectLabel?: string
}) {
return (
<Card
className={cn(
'transition-all',
isSelected ? 'ring-2 ring-primary bg-primary/5' : ''
)}
>
<div className="flex items-start gap-3 p-4">
<ProjectLogo project={project} logoUrl={project.logoUrl} size="sm" fallback="initials" />
<div className="flex-1 min-w-0">
<button
onClick={onToggleExpand}
className="flex items-center gap-2 text-left w-full group"
>
<ChevronDown className={cn(
'h-4 w-4 text-muted-foreground transition-transform shrink-0',
isExpanded && 'rotate-180'
)} />
<div className="min-w-0">
<h3 className="font-semibold text-sm group-hover:text-brand-blue transition-colors">
{project.title}
</h3>
<p className="text-xs text-muted-foreground mt-0.5">
{project.teamName}
{project.country && <> &middot; <CountryDisplay country={project.country} /></>}
</p>
</div>
</button>
<div className="flex flex-wrap gap-1 mt-2 ml-6">
{project.competitionCategory && (
<Badge variant="outline" className="text-xs">
{project.competitionCategory.replace('_', ' ')}
</Badge>
)}
</div>
</div>
<Button
size="sm"
variant={isSelected ? 'default' : 'outline'}
onClick={(e) => { e.stopPropagation(); onSelect() }}
className="shrink-0"
>
{isSelected ? (
<><CheckCircle2 className="mr-1 h-3.5 w-3.5" /> Selected</>
) : (
selectLabel || 'Select'
)}
</Button>
</div>
{isExpanded && <ProjectDetails project={project} />}
</Card>
)
}
function ChairPanel({
award,
projects,
otherVotes,
totalJurors,
hasVoted,
onConfirm,
isPending,
}: {
award: { id: string; status: string }
projects: ProjectData[]
otherVotes: OtherVote[]
totalJurors: number
hasVoted: boolean
onConfirm: () => void
isPending: boolean
}) {
const projectMap = new Map(projects.map((p) => [p.id, p]))
const tally = new Map<string, number>()
for (const v of otherVotes) {
tally.set(v.projectId, (tally.get(v.projectId) ?? 0) + 1)
}
const ranked = Array.from(tally.entries())
.map(([projectId, votes]) => ({
project: projectMap.get(projectId),
votes,
}))
.filter((r) => r.project)
.sort((a, b) => b.votes - a.votes)
const votedCount = new Set(otherVotes.map((v) => v.userId)).size + (hasVoted ? 1 : 0)
const isClosed = award.status === 'CLOSED'
return (
<Card className="border-amber-200">
<CardHeader>
<div className="flex items-center gap-2">
<Gavel className="h-5 w-5 text-amber-600" />
<CardTitle className="text-base">Chair tools</CardTitle>
</div>
<CardDescription>
{votedCount} of {totalJurors} jurors have voted. As the chair you
can review their picks and finalize the award.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{ranked.length === 0 ? (
<p className="text-sm text-muted-foreground italic">
No other juror votes yet.
</p>
) : (
<div className="space-y-2">
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
Tally so far
</p>
{ranked.map(({ project, votes }) => (
<div key={project!.id} className="flex items-center justify-between rounded-md border px-3 py-2">
<span className="text-sm font-medium truncate">{project!.title}</span>
<Badge variant="secondary">{votes} {votes === 1 ? 'vote' : 'votes'}</Badge>
</div>
))}
</div>
)}
{otherVotes.length > 0 && (
<div className="space-y-2">
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
Justifications
</p>
{otherVotes.map((v) => {
const project = projectMap.get(v.projectId)
return (
<div key={v.userId} className="rounded-md border p-3">
<div className="flex items-center justify-between gap-2">
<span className="text-sm font-medium">
{v.userName || 'Anonymous juror'}
</span>
<span className="text-xs text-muted-foreground truncate">
{project?.title || 'Unknown project'}
</span>
</div>
{v.justification && (
<p className="text-xs text-muted-foreground mt-2 whitespace-pre-line">
{v.justification}
</p>
)}
</div>
)
})}
</div>
)}
{!isClosed && (
<div className="flex justify-end pt-2">
<AlertDialog>
<AlertDialogTrigger asChild>
<Button disabled={!hasVoted || isPending}>
{isPending ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<Trophy className="mr-2 h-4 w-4" />
)}
Confirm winner & close award
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Finalize the award?</AlertDialogTitle>
<AlertDialogDescription>
The project with the most votes will be set as the
winner. If there&apos;s a tie, your own vote breaks it.
Voting will close immediately and this can&apos;t be
reopened from this page.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={onConfirm}>
Confirm
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)}
{!hasVoted && (
<p className="text-xs text-muted-foreground text-right">
You must submit your own vote before finalizing.
</p>
)}
</CardContent>
</Card>
)
}

View File

@@ -1,76 +1,142 @@
'use client'
import { use, useState } from 'react'
import { use, useEffect, useMemo, useRef, useState } from 'react'
import { trpc } from '@/lib/trpc/client'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Textarea } from '@/components/ui/textarea'
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'
import { ChevronDown, ChevronUp } from 'lucide-react'
import { LiveVotingForm } from '@/components/jury/live-voting-form'
import { remainingSeconds, formatClock } from '@/lib/live-timer'
import { Clock, Mic2, MessageCircleQuestion, PenLine, Sparkles } from 'lucide-react'
import { toast } from 'sonner'
const PHASE_META: Record<string, { label: string; icon: typeof Mic2 }> = {
PRESENTING: { label: 'Presentation', icon: Mic2 },
QA: { label: 'Q&A', icon: MessageCircleQuestion },
SCORING: { label: 'Scoring open', icon: PenLine },
}
function PhaseCountdown({ phase }: { phase: {
phaseStartedAt: Date | string | null
phaseDurationSeconds: number | null
phasePausedAt: Date | string | null
phasePausedAccumMs: number
} }) {
const [, tick] = useState(0)
useEffect(() => {
const id = setInterval(() => tick((t) => t + 1), 1000)
return () => clearInterval(id)
}, [])
const remaining = remainingSeconds(phase)
if (remaining === null) return null
const over = remaining < 0
return (
<Badge
variant={over ? 'destructive' : 'secondary'}
className={`gap-1 tabular-nums text-sm ${over ? 'animate-pulse' : ''}`}
>
<Clock className="h-3.5 w-3.5" />
{formatClock(remaining)}
{over && <span className="font-semibold">OVER</span>}
{phase.phasePausedAt && <span>· paused</span>}
</Badge>
)
}
export default function JuryLivePage({ params: paramsPromise }: { params: Promise<{ roundId: string }> }) {
const params = use(paramsPromise)
const utils = trpc.useUtils()
const [notes, setNotes] = useState('')
const [priorDataOpen, setPriorDataOpen] = useState(false)
const { data: cursor } = trpc.live.getCursor.useQuery({ roundId: params.roundId })
// Fetch live voting session data
const { data: sessionData } = trpc.liveVoting.getSessionForVoting.useQuery(
{ sessionId: params.roundId },
{ enabled: !!params.roundId, refetchInterval: 2000 }
const { data: cursor } = trpc.live.getCursor.useQuery(
{ roundId: params.roundId },
{ refetchInterval: 2000 }
)
const { data: sessionData } = trpc.liveVoting.getSessionForVotingByRound.useQuery(
{ roundId: params.roundId },
{ refetchInterval: 2000 }
)
const { data: myNotes } = trpc.live.getMyNotes.useQuery({ roundId: params.roundId })
// Placeholder for prior data - this would need to be implemented in evaluation router
const priorData = null as { averageScore?: number; evaluationCount?: number; strengths?: string; weaknesses?: string } | null
const submitVoteMutation = trpc.liveVoting.vote.useMutation({
onSuccess: () => {
utils.liveVoting.getSessionForVoting.invalidate()
toast.success('Vote submitted successfully')
},
onError: (err: any) => {
toast.error(err.message)
},
// ── Persisted notes (autosave, keyed per project) ────────────────────────
const [noteDrafts, setNoteDrafts] = useState<Record<string, string>>({})
const [noteStatus, setNoteStatus] = useState<'idle' | 'saving' | 'saved'>('idle')
const saveTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
const saveNote = trpc.live.saveNote.useMutation({
onSuccess: () => setNoteStatus('saved'),
onError: () => setNoteStatus('idle'),
})
const handleVoteSubmit = (vote: { score: number; criterionScores?: Record<string, number> }) => {
const projectId = cursor?.activeProject?.id || sessionData?.currentProject?.id
if (!projectId) return
const activeProject = cursor?.activeProject ?? null
const activeProjectId = activeProject?.id ?? null
const sessionId = sessionData?.session?.id || params.roundId
const savedNoteFor = useMemo(() => {
const map: Record<string, string> = {}
for (const n of myNotes ?? []) map[n.projectId] = n.content
return map
}, [myNotes])
const currentDraft =
activeProjectId != null
? noteDrafts[activeProjectId] ?? savedNoteFor[activeProjectId] ?? ''
: ''
const handleNoteChange = (value: string) => {
if (!activeProjectId) return
setNoteDrafts((d) => ({ ...d, [activeProjectId]: value }))
setNoteStatus('saving')
if (saveTimer.current) clearTimeout(saveTimer.current)
const projectId = activeProjectId
saveTimer.current = setTimeout(() => {
saveNote.mutate({ roundId: params.roundId, projectId, content: value })
}, 800)
}
// ── Voting ───────────────────────────────────────────────────────────────
const submitVoteMutation = trpc.liveVoting.vote.useMutation({
onSuccess: () => {
utils.liveVoting.getSessionForVotingByRound.invalidate()
toast.success('Vote submitted')
},
onError: (err) => toast.error(err.message),
})
const handleVoteSubmit = (vote: {
score: number
criterionScores?: Record<string, number>
comment?: string
}) => {
if (!activeProjectId || !sessionData?.session?.id) return
submitVoteMutation.mutate({
sessionId,
projectId,
sessionId: sessionData.session.id,
projectId: activeProjectId,
score: vote.score,
criterionScores: vote.criterionScores,
comment: vote.comment,
})
}
// Extract voting mode and criteria from session
const votingMode = (sessionData?.session?.votingMode ?? 'simple') as 'simple' | 'criteria'
const criteria = (sessionData?.session?.criteriaJson as Array<{
id: string
label: string
description?: string
scale: number
weight: number
}> | undefined)
const criteria = sessionData?.session?.criteriaJson as
| Array<{ id: string; label: string; description?: string; scale: number; weight: number }>
| undefined
const activeProject = cursor?.activeProject || sessionData?.currentProject
const phase = cursor?.projectPhase ?? 'ON_DECK'
const categoryLabel =
activeProject?.competitionCategory === 'STARTUP'
? 'Startup'
: activeProject?.competitionCategory === 'BUSINESS_CONCEPT'
? 'Business Concept'
: null
if (!activeProject) {
return (
<div className="space-y-6">
<Card>
<CardContent className="flex flex-col items-center justify-center py-12">
<p className="text-muted-foreground">Waiting for ceremony to begin...</p>
<Sparkles className="mb-3 h-8 w-8 text-brand-teal/60" />
<p className="font-medium">Waiting for the ceremony to begin</p>
<p className="mt-2 text-sm text-muted-foreground">
The admin will control which project is displayed
Projects will appear here automatically as they take the stage
</p>
</CardContent>
</Card>
@@ -78,105 +144,116 @@ export default function JuryLivePage({ params: paramsPromise }: { params: Promis
)
}
// ── ON_DECK: "Up next" banner, no scoring yet ───────────────────────────
if (phase === 'ON_DECK') {
return (
<div className="space-y-6">
{/* Current Project Display */}
<Card className="overflow-hidden border-0 bg-gradient-to-r from-[#053d57] to-[#0a5a7c] text-white">
<CardContent className="py-12 text-center">
<p className="text-xs font-semibold uppercase tracking-[0.3em] text-white/70">
Up next
</p>
<h1 className="mt-3 text-3xl font-bold sm:text-4xl">{activeProject.title}</h1>
{activeProject.teamName && (
<p className="mt-2 text-lg text-white/80">{activeProject.teamName}</p>
)}
{categoryLabel && (
<Badge className="mt-4 bg-white/15 text-white hover:bg-white/15">{categoryLabel}</Badge>
)}
<p className="mt-6 text-sm text-white/60">Presentation starting shortly</p>
</CardContent>
</Card>
{activeProject.description && (
<Card>
<CardHeader>
<div className="flex items-start justify-between">
<div>
<CardTitle className="text-2xl">{activeProject.title}</CardTitle>
<CardDescription className="mt-2">
Live project presentation
</CardDescription>
</div>
{votingMode === 'criteria' && (
<Badge variant="secondary">Criteria Voting</Badge>
)}
</div>
<CardTitle className="text-base">About this project</CardTitle>
</CardHeader>
<CardContent>
{activeProject.description && (
<p className="text-muted-foreground">{activeProject.description}</p>
)}
<p className="text-sm text-muted-foreground">{activeProject.description}</p>
</CardContent>
</Card>
)}
</div>
)
}
{/* Prior Jury Data (Collapsible) */}
{priorData && (
<Collapsible open={priorDataOpen} onOpenChange={setPriorDataOpen}>
<Card>
<CollapsibleTrigger asChild>
<CardHeader className="cursor-pointer hover:bg-muted/50">
<div className="flex items-center justify-between">
<CardTitle className="text-lg">Prior Evaluation Data</CardTitle>
{priorDataOpen ? (
<ChevronUp className="h-5 w-5" />
) : (
<ChevronDown className="h-5 w-5" />
)}
</div>
</CardHeader>
</CollapsibleTrigger>
<CollapsibleContent>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
<div>
<p className="text-sm font-medium text-muted-foreground">Average Score</p>
<p className="mt-1 text-2xl font-bold">
{priorData.averageScore?.toFixed(1) || 'N/A'}
</p>
</div>
<div>
<p className="text-sm font-medium text-muted-foreground">Evaluations</p>
<p className="mt-1 text-2xl font-bold">{priorData.evaluationCount || 0}</p>
</div>
</div>
{priorData.strengths && (
<div>
<p className="text-sm font-medium text-muted-foreground">Key Strengths</p>
<p className="mt-1 text-sm">{priorData.strengths}</p>
</div>
)}
{priorData.weaknesses && (
<div>
<p className="text-sm font-medium text-muted-foreground">Areas for Improvement</p>
<p className="mt-1 text-sm">{priorData.weaknesses}</p>
</div>
)}
</CardContent>
</CollapsibleContent>
</Card>
</Collapsible>
)}
const phaseMeta = PHASE_META[phase] ?? PHASE_META.PRESENTING
const PhaseIcon = phaseMeta.icon
{/* Notes Section */}
return (
<div className="space-y-6">
{/* Current Project + phase */}
<Card>
<CardHeader>
<div className="flex flex-wrap items-start justify-between gap-3">
<div>
<CardTitle className="text-2xl">{activeProject.title}</CardTitle>
<CardDescription className="mt-1">
{activeProject.teamName}
{categoryLabel ? ` · ${categoryLabel}` : ''}
</CardDescription>
</div>
<div className="flex items-center gap-2">
<Badge variant={phase === 'SCORING' ? 'default' : 'outline'} className="gap-1.5">
<PhaseIcon className="h-3.5 w-3.5" />
{phaseMeta.label}
</Badge>
{cursor && <PhaseCountdown phase={cursor} />}
</div>
</div>
</CardHeader>
{activeProject.description && (
<CardContent>
<p className="text-sm text-muted-foreground">{activeProject.description}</p>
</CardContent>
)}
</Card>
{/* Notes — persisted, autosaved */}
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<div>
<CardTitle>Your Notes</CardTitle>
<CardDescription>Optional notes for this project</CardDescription>
<CardDescription>Private resurfaced during deliberation</CardDescription>
</div>
<span className="text-xs text-muted-foreground">
{noteStatus === 'saving' ? 'Saving…' : noteStatus === 'saved' ? 'Saved' : ''}
</span>
</div>
</CardHeader>
<CardContent>
<Textarea
value={notes}
onChange={(e) => setNotes(e.target.value)}
placeholder="Add your observations and comments..."
value={currentDraft}
onChange={(e) => handleNoteChange(e.target.value)}
placeholder="Observations during the presentation and Q&A…"
rows={4}
/>
</CardContent>
</Card>
{/* Voting Form */}
{/* Scoring — available from presentation start, spotlighted at SCORING.
Keyed on vote presence: the form initializes its editing state from
existingVote, which arrives async after mount. */}
<LiveVotingForm
key={`${activeProject.id}-${sessionData?.userVote?.votedAt ?? 'fresh'}`}
projectId={activeProject.id}
votingMode={votingMode}
criteria={criteria}
existingVote={sessionData?.userVote ? {
existingVote={
sessionData?.userVote
? {
score: sessionData.userVote.score,
criterionScoresJson: sessionData.userVote.criterionScoresJson as Record<string, number> | undefined
} : null}
criterionScoresJson: sessionData.userVote.criterionScoresJson as
| Record<string, number>
| undefined,
comment: sessionData.userVote.comment,
}
: null
}
onVoteSubmit={handleVoteSubmit}
disabled={submitVoteMutation.isPending}
highlighted={phase === 'SCORING'}
/>
</div>
)

View File

@@ -44,7 +44,7 @@ export default function JuryRoundDetailPage() {
Back
</Button>
<div>
<h1 className="text-2xl font-bold tracking-tight text-brand-blue dark:text-foreground">
<h1 className="text-2xl font-bold tracking-tight text-brand-blue">
{round?.name || 'Round Details'}
</h1>
<p className="text-muted-foreground mt-1">

View File

@@ -5,20 +5,19 @@ import { useRouter } from 'next/navigation'
import Link from 'next/link'
import type { Route } from 'next'
import { trpc } from '@/lib/trpc/client'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Card, CardContent } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Slider } from '@/components/ui/slider'
import { Textarea } from '@/components/ui/textarea'
import { Label } from '@/components/ui/label'
import { Skeleton } from '@/components/ui/skeleton'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
import { cn } from '@/lib/utils'
import { MultiWindowDocViewer } from '@/components/jury/multi-window-doc-viewer'
import { Badge } from '@/components/ui/badge'
import { COIDeclarationDialog } from '@/components/forms/coi-declaration-dialog'
import { ArrowLeft, Save, Send, AlertCircle, ThumbsUp, ThumbsDown, Clock, CheckCircle2, ShieldAlert, Lock } from 'lucide-react'
import { ArrowLeft, Save, Send, AlertCircle, Clock, ShieldAlert, Lock } from 'lucide-react'
import { toast } from 'sonner'
import type { EvaluationConfig } from '@/types/competition-configs'
import {
EvaluationFormFields,
parseCriteriaFromForm,
} from '@/components/evaluation/evaluation-form-fields'
type PageProps = {
params: Promise<{ roundId: string; projectId: string }>
@@ -148,33 +147,10 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
const requireFeedback = evalConfig?.requireFeedback ?? true
const feedbackMinLength = evalConfig?.feedbackMinLength ?? 10
// Parse criteria from the active form
const criteria = (activeForm?.criteriaJson ?? []).map((c) => {
const type = (c as any).type || 'numeric'
let minScore = 1
let maxScore = 10
if (type === 'numeric' && c.scale) {
const parts = c.scale.split('-').map(Number)
if (parts.length === 2 && !isNaN(parts[0]) && !isNaN(parts[1])) {
minScore = parts[0]
maxScore = parts[1]
}
}
return {
id: c.id,
label: c.label,
description: c.description,
type: type as 'numeric' | 'text' | 'boolean' | 'advance' | 'section_header',
weight: c.weight,
minScore,
maxScore,
required: (c as any).required ?? true,
trueLabel: (c as any).trueLabel || 'Yes',
falseLabel: (c as any).falseLabel || 'No',
maxLength: (c as any).maxLength || 1000,
placeholder: (c as any).placeholder || '',
}
})
// Parse criteria from the active form (shared with admin proxy flow)
const criteria = parseCriteriaFromForm(
activeForm?.criteriaJson as ReadonlyArray<Record<string, unknown>> | null | undefined,
)
// Initialize numeric criteria with midpoint values so slider visual matches stored value.
const criteriaInitializedRef = useRef(false)
@@ -484,7 +460,7 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
</div>
<Card className="border-l-4 border-l-amber-500">
<CardContent className="flex items-start gap-4 p-6">
<div className="rounded-xl bg-amber-50 dark:bg-amber-950/40 p-3">
<div className="rounded-xl bg-amber-50 p-3">
<Clock className="h-6 w-6 text-amber-600" />
</div>
<div>
@@ -519,7 +495,7 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
</Link>
</Button>
<div>
<h1 className="text-2xl font-bold tracking-tight text-brand-blue dark:text-foreground">
<h1 className="text-2xl font-bold tracking-tight text-brand-blue">
Evaluate Project
</h1>
<p className="text-muted-foreground mt-1">{project.title}</p>
@@ -550,7 +526,7 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
</Link>
</Button>
<div>
<h1 className="text-2xl font-bold tracking-tight text-brand-blue dark:text-foreground">
<h1 className="text-2xl font-bold tracking-tight text-brand-blue">
Evaluate Project
</h1>
<p className="text-muted-foreground mt-1">{project.title}</p>
@@ -558,7 +534,7 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
</div>
<Card className="border-l-4 border-l-amber-500">
<CardContent className="flex items-start gap-4 p-6">
<div className="rounded-xl bg-amber-50 dark:bg-amber-950/40 p-3">
<div className="rounded-xl bg-amber-50 p-3">
<ShieldAlert className="h-6 w-6 text-amber-600" />
</div>
<div>
@@ -597,7 +573,7 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
</Button>
)}
<div>
<h1 className="text-2xl font-bold tracking-tight text-brand-blue dark:text-foreground">
<h1 className="text-2xl font-bold tracking-tight text-brand-blue">
{isReadOnly ? 'Submitted Evaluation' : 'Evaluate Project'}
</h1>
<div className="flex items-center gap-2 mt-1">
@@ -607,8 +583,8 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
variant="secondary"
className={
project.competitionCategory === 'STARTUP'
? 'bg-violet-100 text-violet-700 border-violet-200 dark:bg-violet-950 dark:text-violet-300'
: 'bg-sky-100 text-sky-700 border-sky-200 dark:bg-sky-950 dark:text-sky-300'
? 'bg-violet-100 text-violet-700 border-violet-200'
: 'bg-sky-100 text-sky-700 border-sky-200'
}
>
{project.competitionCategory === 'STARTUP' ? 'Startup' : 'Business Concept'}
@@ -619,7 +595,7 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
</div>
{isReadOnly && (
<Card className="border-l-4 border-l-blue-500 bg-blue-50/50 dark:bg-blue-950/20">
<Card className="border-l-4 border-l-blue-500 bg-blue-50/50">
<CardContent className="flex items-start gap-3 p-4">
<Lock className="h-5 w-5 text-blue-600 shrink-0 mt-0.5" />
<div className="flex-1">
@@ -650,330 +626,23 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
</Card>
)}
<Card>
<CardHeader>
<div className="flex items-start justify-between">
<div>
<CardTitle>Evaluation Form</CardTitle>
<CardDescription>
{scoringMode === 'criteria'
? 'Complete all required fields below'
: `Provide your assessment using the ${scoringMode} scoring method`}
</CardDescription>
</div>
{lastSavedAt && (
<span className="text-xs text-muted-foreground flex items-center gap-1">
<CheckCircle2 className="h-3 w-3 text-emerald-500" />
Saved {lastSavedAt.toLocaleTimeString()}
</span>
)}
</div>
</CardHeader>
<CardContent className="space-y-6">
{/* Criteria-based scoring with mixed types */}
{scoringMode === 'criteria' && criteria && criteria.length > 0 && (
<div className="space-y-4">
{criteria.map((criterion) => {
if (criterion.type === 'section_header') {
return (
<div key={criterion.id} className="border-b pb-2 pt-4 first:pt-0">
<h3 className="font-semibold text-lg">{criterion.label}</h3>
{criterion.description && (
<p className="text-sm text-muted-foreground mt-1">{criterion.description}</p>
)}
</div>
)
}
if (criterion.type === 'advance') {
const currentValue = criteriaValues[criterion.id]
return (
<div key={criterion.id} className="space-y-3 p-5 border-2 border-brand-blue/30 rounded-xl bg-brand-blue/5">
<div className="space-y-1">
<Label className="text-base font-semibold text-brand-blue">
{criterion.label}
<span className="text-destructive ml-1">*</span>
</Label>
{criterion.description && (
<p className="text-sm text-muted-foreground">{criterion.description}</p>
)}
</div>
<div className="flex gap-4">
<button
type="button"
disabled={isReadOnly}
onClick={() => handleCriterionChange(criterion.id, true)}
className={cn(
'flex-1 h-14 rounded-xl border-2 flex items-center justify-center text-base font-semibold transition-all',
currentValue === true
? 'border-emerald-500 bg-emerald-50 text-emerald-700 shadow-sm ring-2 ring-emerald-200'
: 'border-border hover:border-emerald-300 hover:bg-emerald-50/50',
isReadOnly && 'opacity-60 cursor-default'
)}
>
<ThumbsUp className="mr-2 h-5 w-5" />
{criterion.trueLabel || 'Yes'}
</button>
<button
type="button"
disabled={isReadOnly}
onClick={() => handleCriterionChange(criterion.id, false)}
className={cn(
'flex-1 h-14 rounded-xl border-2 flex items-center justify-center text-base font-semibold transition-all',
currentValue === false
? 'border-red-500 bg-red-50 text-red-700 shadow-sm ring-2 ring-red-200'
: 'border-border hover:border-red-300 hover:bg-red-50/50',
isReadOnly && 'opacity-60 cursor-default'
)}
>
<ThumbsDown className="mr-2 h-5 w-5" />
{criterion.falseLabel || 'No'}
</button>
</div>
</div>
)
}
if (criterion.type === 'boolean') {
const currentValue = criteriaValues[criterion.id]
return (
<div key={criterion.id} className="space-y-3 p-4 border rounded-lg">
<div className="space-y-1">
<Label className="text-base font-medium">
{criterion.label}
{criterion.required && <span className="text-destructive ml-1">*</span>}
</Label>
{criterion.description && (
<p className="text-sm text-muted-foreground">{criterion.description}</p>
)}
</div>
<div className="flex gap-3">
<button
type="button"
disabled={isReadOnly}
onClick={() => handleCriterionChange(criterion.id, true)}
className={cn(
'flex-1 h-12 rounded-lg border-2 flex items-center justify-center text-sm font-medium transition-all',
currentValue === true
? 'border-emerald-500 bg-emerald-50 text-emerald-700 dark:bg-emerald-950/40 dark:text-emerald-400'
: 'border-border hover:border-emerald-300 hover:bg-emerald-50/50',
isReadOnly && 'opacity-60 cursor-default'
)}
>
<ThumbsUp className="mr-2 h-4 w-4" />
{criterion.trueLabel}
</button>
<button
type="button"
disabled={isReadOnly}
onClick={() => handleCriterionChange(criterion.id, false)}
className={cn(
'flex-1 h-12 rounded-lg border-2 flex items-center justify-center text-sm font-medium transition-all',
currentValue === false
? 'border-red-500 bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-400'
: 'border-border hover:border-red-300 hover:bg-red-50/50',
isReadOnly && 'opacity-60 cursor-default'
)}
>
<ThumbsDown className="mr-2 h-4 w-4" />
{criterion.falseLabel}
</button>
</div>
</div>
)
}
if (criterion.type === 'text') {
const currentValue = (criteriaValues[criterion.id] as string) || ''
return (
<div key={criterion.id} className="space-y-3 p-4 border rounded-lg">
<div className="space-y-1">
<Label className="text-base font-medium">
{criterion.label}
{criterion.required && <span className="text-destructive ml-1">*</span>}
</Label>
{criterion.description && (
<p className="text-sm text-muted-foreground">{criterion.description}</p>
)}
</div>
<Textarea
value={currentValue}
onChange={(e) => handleCriterionChange(criterion.id, e.target.value)}
placeholder={criterion.placeholder || 'Enter your response...'}
rows={4}
maxLength={criterion.maxLength}
disabled={isReadOnly}
<EvaluationFormFields
criteria={criteria}
scoringMode={scoringMode}
requireFeedback={requireFeedback}
feedbackMinLength={feedbackMinLength}
criteriaValues={criteriaValues}
globalScore={globalScore}
binaryDecision={binaryDecision}
feedbackText={feedbackText}
isReadOnly={isReadOnly}
lastSavedAt={lastSavedAt}
onCriterionChange={handleCriterionChange}
onGlobalScoreChange={handleGlobalScoreChange}
onBinaryChange={handleBinaryChange}
onFeedbackChange={handleFeedbackChange}
/>
<p className="text-xs text-muted-foreground text-right">
{currentValue.length}/{criterion.maxLength}
</p>
</div>
)
}
// Default: numeric criterion
const min = criterion.minScore ?? 1
const max = criterion.maxScore ?? 10
const currentValue = criteriaValues[criterion.id]
const displayValue = typeof currentValue === 'number' ? currentValue : undefined
const sliderValue = typeof currentValue === 'number' ? currentValue : Math.ceil((min + max) / 2)
return (
<div key={criterion.id} className="space-y-3 p-4 border rounded-lg">
<div className="flex items-start justify-between gap-4">
<div className="space-y-1">
<Label className="text-base font-medium">
{criterion.label}
{criterion.required && <span className="text-destructive ml-1">*</span>}
</Label>
{criterion.description && (
<p className="text-sm text-muted-foreground">{criterion.description}</p>
)}
</div>
<span className="shrink-0 rounded-md bg-muted px-2.5 py-1 text-sm font-bold tabular-nums">
{displayValue !== undefined ? displayValue : '\u2014'}/{max}
</span>
</div>
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground w-4">{min}</span>
<Slider
min={min}
max={max}
step={1}
value={[sliderValue]}
onValueChange={(v) => handleCriterionChange(criterion.id, v[0])}
className="flex-1"
disabled={isReadOnly}
/>
<span className="text-xs text-muted-foreground w-4">{max}</span>
</div>
<div className="flex gap-1 flex-wrap">
{Array.from({ length: max - min + 1 }, (_, i) => i + min).map((num) => (
<button
key={num}
type="button"
disabled={isReadOnly}
onClick={() => handleCriterionChange(criterion.id, num)}
className={cn(
'w-9 h-9 rounded-md text-sm font-medium transition-colors',
displayValue !== undefined && displayValue === num
? 'bg-primary text-primary-foreground'
: displayValue !== undefined && displayValue > num
? 'bg-primary/20 text-primary'
: 'bg-muted hover:bg-muted/80',
isReadOnly && 'cursor-default'
)}
>
{num}
</button>
))}
</div>
</div>
)
})}
</div>
)}
{/* Global scoring */}
{scoringMode === 'global' && (
<div className="space-y-3">
<div className="flex items-center justify-between">
<Label>
Overall Score <span className="text-destructive">*</span>
</Label>
<span className="rounded-md bg-muted px-2.5 py-1 text-sm font-bold tabular-nums">
{globalScore || '\u2014'}/10
</span>
</div>
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">1</span>
<Slider
min={1}
max={10}
step={1}
value={[globalScore ? parseInt(globalScore, 10) : 5]}
onValueChange={(v) => handleGlobalScoreChange(v[0].toString())}
className="flex-1"
disabled={isReadOnly}
/>
<span className="text-xs text-muted-foreground">10</span>
</div>
<div className="flex gap-1 flex-wrap">
{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((num) => {
const current = globalScore ? parseInt(globalScore, 10) : 0
return (
<button
key={num}
type="button"
disabled={isReadOnly}
onClick={() => handleGlobalScoreChange(num.toString())}
className={cn(
'w-9 h-9 rounded-md text-sm font-medium transition-colors',
current === num
? 'bg-primary text-primary-foreground'
: current > num
? 'bg-primary/20 text-primary'
: 'bg-muted hover:bg-muted/80',
isReadOnly && 'cursor-default'
)}
>
{num}
</button>
)
})}
</div>
</div>
)}
{/* Binary decision */}
{scoringMode === 'binary' && (
<div className="space-y-2">
<Label>
Decision <span className="text-destructive">*</span>
</Label>
<RadioGroup value={binaryDecision} onValueChange={(v) => handleBinaryChange(v as 'accept' | 'reject')} disabled={isReadOnly}>
<div className="flex items-center space-x-2 p-4 border rounded-lg hover:bg-emerald-50/50">
<RadioGroupItem value="accept" id="accept" />
<Label htmlFor="accept" className="flex items-center gap-2 cursor-pointer flex-1">
<ThumbsUp className="h-4 w-4 text-emerald-600" />
<span>Accept This project should advance</span>
</Label>
</div>
<div className="flex items-center space-x-2 p-4 border rounded-lg hover:bg-red-50/50">
<RadioGroupItem value="reject" id="reject" />
<Label htmlFor="reject" className="flex items-center gap-2 cursor-pointer flex-1">
<ThumbsDown className="h-4 w-4 text-red-600" />
<span>Reject This project should not advance</span>
</Label>
</div>
</RadioGroup>
</div>
)}
{/* Feedback */}
<div className="space-y-2">
<Label htmlFor="feedbackText">
General Comment / Feedback
{requireFeedback && <span className="text-destructive ml-1">*</span>}
</Label>
<Textarea
id="feedbackText"
value={feedbackText}
onChange={(e) => handleFeedbackChange(e.target.value)}
placeholder="Provide your feedback on the project..."
rows={8}
disabled={isReadOnly}
/>
{requireFeedback && (
<p className="text-xs text-muted-foreground">
Minimum {feedbackMinLength} characters ({feedbackText.length}/{feedbackMinLength})
</p>
)}
</div>
</CardContent>
</Card>
{isReadOnly ? (
<div className="flex items-center">

View File

@@ -98,8 +98,8 @@ export default function JuryProjectDetailPage() {
variant="secondary"
className={
project.competitionCategory === 'STARTUP'
? 'bg-violet-100 text-violet-700 border-violet-200 dark:bg-violet-950 dark:text-violet-300'
: 'bg-sky-100 text-sky-700 border-sky-200 dark:bg-sky-950 dark:text-sky-300'
? 'bg-violet-100 text-violet-700 border-violet-200'
: 'bg-sky-100 text-sky-700 border-sky-200'
}
>
{project.competitionCategory === 'STARTUP' ? 'Startup' : 'Business Concept'}

View File

@@ -1,150 +1,326 @@
'use client';
'use client'
import { use } from 'react';
import { trpc } from '@/lib/trpc/client';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { DeliberationRankingForm } from '@/components/jury/deliberation-ranking-form';
import { CheckCircle2 } from 'lucide-react';
import { toast } from 'sonner';
import { use, useState } from 'react'
import Link from 'next/link'
import { trpc } from '@/lib/trpc/client'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '@/components/ui/collapsible'
import { DeliberationRankingForm } from '@/components/jury/deliberation-ranking-form'
import { LiveVotingForm } from '@/components/jury/live-voting-form'
import { CheckCircle2, ChevronDown, FileText, PenLine, StickyNote } from 'lucide-react'
import { toast } from 'sonner'
export default function JuryDeliberationPage({ params: paramsPromise }: { params: Promise<{ sessionId: string }> }) {
const params = use(paramsPromise);
const utils = trpc.useUtils();
const CATEGORY_LABEL: Record<string, string> = {
BUSINESS_CONCEPT: 'Business Concepts',
STARTUP: 'Startups',
}
/**
* Per-project review context during deliberation: the juror's finale scores
* (revisable in place — "keep" is simply not touching them), their ceremony
* notes, and a pointer to the project documents.
*/
function ProjectReviewCard({
project,
roundId,
finaleInputs,
votingMode,
criteria,
}: {
project: { id: string; title: string; teamName?: string | null }
roundId: string
finaleInputs: any
votingMode: 'simple' | 'criteria'
criteria?: Array<{ id: string; label: string; description?: string; scale: number; weight: number }>
}) {
const utils = trpc.useUtils()
const [open, setOpen] = useState(false)
const myVote = finaleInputs?.votes?.find((v: any) => v.projectId === project.id)
const myNote = finaleInputs?.notes?.find((n: any) => n.projectId === project.id)
const voteMutation = trpc.liveVoting.vote.useMutation({
onSuccess: () => {
utils.liveVoting.getMyFinaleInputs.invalidate({ roundId })
toast.success('Score updated')
},
onError: (err) => toast.error(err.message),
})
return (
<Collapsible open={open} onOpenChange={setOpen}>
<Card>
<CollapsibleTrigger asChild>
<CardHeader className="cursor-pointer py-4 hover:bg-muted/40">
<div className="flex items-center justify-between">
<div>
<CardTitle className="text-base">{project.title}</CardTitle>
{project.teamName && (
<CardDescription className="mt-0.5">{project.teamName}</CardDescription>
)}
</div>
<div className="flex items-center gap-2">
{myVote ? (
<Badge variant="secondary" className="tabular-nums">
My score: {myVote.score}/10
</Badge>
) : (
<Badge variant="outline">Not scored</Badge>
)}
<ChevronDown className={`h-4 w-4 transition-transform ${open ? 'rotate-180' : ''}`} />
</div>
</div>
</CardHeader>
</CollapsibleTrigger>
<CollapsibleContent>
<CardContent className="space-y-4 border-t pt-4">
{myNote?.content && (
<div className="rounded-lg bg-muted/40 p-3">
<p className="mb-1 flex items-center gap-1.5 text-xs font-semibold text-muted-foreground">
<StickyNote className="h-3.5 w-3.5" />
Your ceremony notes
</p>
<p className="whitespace-pre-wrap text-sm">{myNote.content}</p>
</div>
)}
<div>
<p className="mb-2 flex items-center gap-1.5 text-xs font-semibold text-muted-foreground">
<PenLine className="h-3.5 w-3.5" />
Your grand-finale score edit to revise, or leave as-is to keep it
</p>
{finaleInputs?.session?.id ? (
<LiveVotingForm
key={`${project.id}-${myVote?.votedAt ?? 'fresh'}`}
projectId={project.id}
votingMode={votingMode}
criteria={criteria}
existingVote={
myVote
? {
score: myVote.score,
criterionScoresJson: myVote.criterionScoresJson as
| Record<string, number>
| undefined,
comment: myVote.comment,
}
: null
}
onVoteSubmit={(vote) =>
voteMutation.mutate({
sessionId: finaleInputs.session.id,
projectId: project.id,
score: vote.score,
criterionScores: vote.criterionScores,
comment: vote.comment,
})
}
disabled={voteMutation.isPending}
/>
) : (
<p className="text-sm text-muted-foreground">No finale voting session found.</p>
)}
</div>
<Button asChild variant="outline" size="sm">
<Link href="/jury/finals-documents">
<FileText className="mr-2 h-3.5 w-3.5" />
Open project documents
</Link>
</Button>
</CardContent>
</CollapsibleContent>
</Card>
</Collapsible>
)
}
export default function JuryDeliberationPage({
params: paramsPromise,
}: {
params: Promise<{ sessionId: string }>
}) {
const params = use(paramsPromise)
const utils = trpc.useUtils()
const { data: me } = trpc.user.me.useQuery()
const { data: session, isLoading } = trpc.deliberation.getSession.useQuery(
{ sessionId: params.sessionId },
{ refetchInterval: 10_000 },
);
{ refetchInterval: 10_000 }
)
// The deliberation session points at its round; finale inputs live on the
// LIVE_FINAL round's voting session — resolve via my ceremony context.
const { data: ceremony } = trpc.live.getMyCeremonyContext.useQuery()
const finaleRoundId = ceremony?.liveRoundId ?? null
const { data: finaleInputs } = trpc.liveVoting.getMyFinaleInputs.useQuery(
{ roundId: finaleRoundId ?? '' },
{ enabled: !!finaleRoundId }
)
const submitVoteMutation = trpc.deliberation.submitVote.useMutation({
onSuccess: () => {
utils.deliberation.getSession.invalidate();
toast.success('Vote submitted successfully');
},
onError: (err) => {
toast.error(err.message);
}
});
const [submitting, setSubmitting] = useState(false)
const submitVoteMutation = trpc.deliberation.submitVote.useMutation()
const handleSubmitVote = (votes: Array<{ projectId: string; rank?: number; isWinnerPick?: boolean }>) => {
votes.forEach((vote) => {
submitVoteMutation.mutate({
const handleSubmitVote = async (
votes: Array<{ projectId: string; rank?: number; isWinnerPick?: boolean }>
) => {
setSubmitting(true)
try {
for (const vote of votes) {
await submitVoteMutation.mutateAsync({
sessionId: params.sessionId,
juryMemberId: '', // TODO: resolve current user's jury member ID from session participants
projectId: vote.projectId,
rank: vote.rank,
isWinnerPick: vote.isWinnerPick
});
});
};
isWinnerPick: vote.isWinnerPick,
})
}
toast.success('Your ranking has been submitted')
utils.deliberation.getSession.invalidate({ sessionId: params.sessionId })
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Failed to submit vote')
} finally {
setSubmitting(false)
}
}
if (isLoading) {
if (isLoading || !me) {
return (
<div className="space-y-6">
<Card>
<CardContent className="flex items-center justify-center py-12">
<p className="text-muted-foreground">Loading session...</p>
<p className="text-muted-foreground">Loading session</p>
</CardContent>
</Card>
</div>
);
)
}
if (!session) {
return (
<div className="space-y-6">
<Card>
<CardContent className="flex items-center justify-center py-12">
<p className="text-muted-foreground">Session not found</p>
</CardContent>
</Card>
</div>
);
)
}
const hasVoted = false; // TODO: check if current user has voted in this session
const isParticipant = (session.participants ?? []).some(
(p: any) => p.user?.user?.id === me.id
)
const hasVoted = (session.votes ?? []).some(
(v: any) => v.juryMember?.user?.id === me.id && v.runoffRound === 0
)
const projects = ((session as any).projects ?? []) as Array<{
id: string
title: string
teamName?: string | null
}>
const votingMode = (finaleInputs?.session?.votingMode ?? 'simple') as 'simple' | 'criteria'
const criteria = finaleInputs?.session?.criteriaJson as
| Array<{ id: string; label: string; description?: string; scale: number; weight: number }>
| undefined
if (session.status !== 'VOTING') {
return (
<div className="space-y-6">
const header = (
<Card>
<CardHeader>
<CardTitle>Deliberation Session</CardTitle>
<CardDescription>
{session.round?.name} - {session.category}
</CardDescription>
<div className="flex items-start justify-between">
<div>
<CardTitle>Deliberation {CATEGORY_LABEL[session.category] ?? session.category}</CardTitle>
<CardDescription className="mt-1">{session.round?.name}</CardDescription>
</div>
<Badge>{session.status}</Badge>
</div>
</CardHeader>
<CardContent className="flex flex-col items-center justify-center py-12">
</Card>
)
const reviewSection = projects.length > 0 && finaleRoundId && (
<div className="space-y-3">
<div>
<h2 className="text-lg font-semibold">Review Before You Rank</h2>
<p className="text-sm text-muted-foreground">
Your grand-finale scores, notes and the project documents revise a score or keep it.
</p>
</div>
{projects.map((p) => (
<ProjectReviewCard
key={p.id}
project={p}
roundId={finaleRoundId}
finaleInputs={finaleInputs}
votingMode={votingMode}
criteria={criteria}
/>
))}
</div>
)
if (session.status !== 'VOTING' && session.status !== 'RUNOFF') {
return (
<div className="space-y-6">
{header}
<Card>
<CardContent className="flex flex-col items-center justify-center py-10">
<p className="text-muted-foreground">
{session.status === 'DELIB_OPEN'
? 'Voting has not started yet. Please wait for the admin to open voting.'
? 'Voting has not started yet — you can already review the projects below.'
: session.status === 'TALLYING'
? 'Voting is closed. Results are being tallied.'
: 'This session is locked.'}
</p>
</CardContent>
</Card>
{session.status === 'DELIB_OPEN' && reviewSection}
</div>
);
)
}
if (hasVoted) {
if (!isParticipant) {
return (
<div className="space-y-6">
{header}
<Card>
<CardHeader>
<div className="flex items-start justify-between">
<div>
<CardTitle>Deliberation Session</CardTitle>
<CardDescription className="mt-1">
{session.round?.name} - {session.category}
</CardDescription>
</div>
<Badge>{session.status}</Badge>
</div>
</CardHeader>
<CardContent className="flex flex-col items-center justify-center py-12">
<CheckCircle2 className="mb-4 h-12 w-12 text-green-600" />
<p className="font-medium">Vote Submitted</p>
<p className="mt-1 text-sm text-muted-foreground">
Thank you for your participation in this deliberation
</p>
</CardContent>
</Card>
</div>
);
}
return (
<div className="space-y-6">
<Card>
<CardHeader>
<div className="flex items-start justify-between">
<div>
<CardTitle>Deliberation Session</CardTitle>
<CardDescription className="mt-1">
{session.round?.name} - {session.category}
</CardDescription>
</div>
<Badge>{session.status}</Badge>
</div>
</CardHeader>
<CardContent>
<CardContent className="flex flex-col items-center justify-center py-10">
<p className="text-muted-foreground">
{session.mode === 'SINGLE_WINNER_VOTE'
? 'Select your top choice for this category.'
: 'Rank all projects from best to least preferred.'}
You are not a participant of this deliberation session.
</p>
</CardContent>
</Card>
</div>
)
}
return (
<div className="space-y-6">
{header}
{hasVoted ? (
<Card>
<CardContent className="flex flex-col items-center justify-center py-10">
<CheckCircle2 className="mb-3 h-12 w-12 text-green-600" />
<p className="font-medium">Ranking Submitted</p>
<p className="mt-1 text-sm text-muted-foreground">
Thank you the chair will review the collective result.
</p>
</CardContent>
</Card>
) : (
<>
{reviewSection}
<div>
<h2 className="mb-2 text-lg font-semibold">
{session.mode === 'SINGLE_WINNER_VOTE' ? 'Pick Your Winner' : 'Your Ranking'}
</h2>
<DeliberationRankingForm
projects={session.results?.map((r) => r.project) ?? []}
projects={projects}
mode={session.mode}
onSubmit={handleSubmitVote}
disabled={submitVoteMutation.isPending}
disabled={submitting}
/>
</div>
);
</>
)}
</div>
)
}

View File

@@ -54,7 +54,7 @@ export default function JuryAssignmentsPage() {
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold tracking-tight text-brand-blue dark:text-foreground">
<h1 className="text-2xl font-bold tracking-tight text-brand-blue">
My Assignments
</h1>
<p className="text-muted-foreground mt-1">

View File

@@ -0,0 +1,7 @@
import { FinalsDocumentsReview } from '@/components/finals/finals-documents-review'
export const dynamic = 'force-dynamic'
export default function FinalsDocumentsPage() {
return <FinalsDocumentsReview />
}

View File

@@ -27,7 +27,10 @@ import {
BarChart3,
Waves,
Send,
Trophy,
FileText,
} from 'lucide-react'
import { userCanReviewFinals, getOpenFinaleRound } from '@/server/services/final-documents'
import { formatDateOnly } from '@/lib/utils'
import { CountdownTimer } from '@/components/shared/countdown-timer'
import { AnimatedCard } from '@/components/shared/animated-container'
@@ -41,6 +44,70 @@ function getGreeting(): string {
return 'Good evening'
}
/**
* Prominent entry point to the finalist documents review, shown only to
* Grand-Final jury members (and admins). Rendered at the top of the dashboard
* regardless of whether the juror has individual assignments, so finals jurors
* can always find the teams' files in one obvious place.
*/
async function FinalsJuryBanner() {
const session = await auth()
const userId = session?.user?.id
if (!userId) return null
const program = await prisma.program.findFirst({
where: { status: 'ACTIVE' },
orderBy: { year: 'desc' },
select: { id: true },
})
if (!program) return null
const canReview = await userCanReviewFinals(prisma, userId, session.user.role, program.id)
if (!canReview) return null
const round = await getOpenFinaleRound(prisma, program.id)
const teamCount = round
? await prisma.projectRoundState.count({ where: { roundId: round.id } })
: 0
return (
<AnimatedCard index={0}>
<Card className="overflow-hidden border-0 shadow-lg">
<div className="rounded-lg bg-gradient-to-r from-brand-blue to-brand-teal p-[1px]">
<CardContent className="flex flex-col gap-4 rounded-[7px] bg-background p-5 sm:flex-row sm:items-center sm:justify-between">
<div className="flex items-start gap-4">
<div className="shrink-0 rounded-xl bg-gradient-to-br from-brand-blue to-brand-teal p-3 shadow-sm">
<Trophy className="h-6 w-6 text-white" />
</div>
<div>
<p className="text-[11px] font-semibold uppercase tracking-wider text-brand-teal">
Grand Final
</p>
<h2 className="text-lg font-bold text-brand-blue">Finalist Documents</h2>
<p className="mt-0.5 max-w-md text-sm text-muted-foreground">
{teamCount > 0 ? `All ${teamCount} finalist teams ` : 'Every finalist teams '}
pitch decks, business plans, executive summaries and videos in one place.
</p>
</div>
</div>
<Button
asChild
size="lg"
className="w-full shrink-0 bg-brand-blue shadow-md hover:bg-brand-blue-light sm:w-auto"
>
<Link href="/jury/finals-documents">
<FileText className="mr-2 h-4 w-4" />
Review Finalist Documents
<ArrowRight className="ml-2 h-4 w-4" />
</Link>
</Button>
</CardContent>
</div>
</Card>
</AnimatedCard>
)
}
async function JuryDashboardContent() {
const session = await auth()
const userId = session?.user?.id
@@ -49,8 +116,8 @@ async function JuryDashboardContent() {
return null
}
// Get assignments, grace periods, and feature flags in parallel
const [assignments, gracePeriods, compareFlag] = await Promise.all([
// Get assignments, grace periods, feature flags, and award juror records in parallel
const [assignments, gracePeriods, compareFlag, myAwardJurorRecords] = await Promise.all([
prisma.assignment.findMany({
where: { userId },
include: {
@@ -109,10 +176,47 @@ async function JuryDashboardContent() {
},
}),
prisma.systemSettings.findUnique({ where: { key: 'jury_compare_enabled' } }),
prisma.awardJuror.findMany({
where: { userId },
include: {
award: {
select: {
id: true,
name: true,
description: true,
status: true,
votingStartAt: true,
votingEndAt: true,
scoringMode: true,
maxRankedPicks: true,
_count: { select: { eligibilities: { where: { eligible: true } } } },
},
},
},
}),
])
const juryCompareEnabled = compareFlag?.value === 'true'
// Check which awards the user has already voted on
const awardIds = myAwardJurorRecords.map((r) => r.award.id)
const myAwardVotes = awardIds.length > 0
? await prisma.awardVote.groupBy({
by: ['awardId'],
where: { userId, awardId: { in: awardIds } },
_count: { id: true },
})
: []
const votedAwardIds = new Set(myAwardVotes.filter((v) => v._count.id > 0).map((v) => v.awardId))
// Awards where voting is open
const activeAwards = myAwardJurorRecords.filter(
(r) => r.award.status === 'VOTING_OPEN'
)
const upcomingAwards = myAwardJurorRecords.filter(
(r) => r.award.status === 'NOMINATIONS_OPEN'
)
// Calculate stats
const totalAssignments = assignments.length
const completedAssignments = assignments.filter(
@@ -216,15 +320,15 @@ async function JuryDashboardContent() {
},
]
// Zero-assignment state: compact welcome card
if (totalAssignments === 0) {
// Zero-assignment state: compact welcome card (but still show awards if any)
if (totalAssignments === 0 && activeAwards.length === 0 && upcomingAwards.length === 0) {
return (
<AnimatedCard index={0}>
<Card className="overflow-hidden">
<div className="h-1 w-full bg-gradient-to-r from-brand-teal/40 via-brand-blue/40 to-brand-teal/40" />
<CardContent className="py-8 px-6">
<div className="flex flex-col items-center text-center mb-6">
<div className="rounded-2xl bg-gradient-to-br from-brand-teal/10 to-brand-blue/10 p-4 mb-3 dark:from-brand-teal/20 dark:to-brand-blue/20">
<div className="rounded-2xl bg-gradient-to-br from-brand-teal/10 to-brand-blue/10 p-4 mb-3">
<ClipboardList className="h-8 w-8 text-brand-teal/60" />
</div>
<p className="text-lg font-semibold">No assignments yet</p>
@@ -235,13 +339,13 @@ async function JuryDashboardContent() {
<div className={`grid gap-3 max-w-md mx-auto ${juryCompareEnabled ? 'sm:grid-cols-2' : ''}`}>
<Link
href="/jury/competitions"
className="group flex items-center gap-3 rounded-xl border border-border/60 p-3 transition-all duration-200 hover:border-brand-blue/30 hover:bg-brand-blue/5 hover:-translate-y-0.5 hover:shadow-md dark:hover:border-brand-teal/30 dark:hover:bg-brand-teal/5"
className="group flex items-center gap-3 rounded-xl border border-border/60 p-3 transition-all duration-200 hover:border-brand-blue/30 hover:bg-brand-blue/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-lg bg-blue-50 p-2 transition-colors group-hover:bg-blue-100 dark:bg-blue-950/40">
<ClipboardList className="h-4 w-4 text-blue-600 dark:text-blue-400" />
<div className="rounded-lg bg-blue-50 p-2 transition-colors group-hover:bg-blue-100">
<ClipboardList className="h-4 w-4 text-blue-600" />
</div>
<div className="text-left">
<p className="font-semibold text-sm group-hover:text-brand-blue dark:group-hover:text-brand-teal transition-colors">All Assignments</p>
<p className="font-semibold text-sm group-hover:text-brand-blue transition-colors">All Assignments</p>
<p className="text-xs text-muted-foreground">View evaluations</p>
</div>
</Link>
@@ -250,7 +354,7 @@ async function JuryDashboardContent() {
href="/jury/competitions"
className="group flex items-center gap-3 rounded-xl border border-border/60 p-3 transition-all duration-200 hover:border-brand-teal/30 hover:bg-brand-teal/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-lg bg-teal-50 p-2 transition-colors group-hover:bg-teal-100 dark:bg-teal-950/40">
<div className="rounded-lg bg-teal-50 p-2 transition-colors group-hover:bg-teal-100">
<GitCompare className="h-4 w-4 text-brand-teal" />
</div>
<div className="text-left">
@@ -268,6 +372,82 @@ async function JuryDashboardContent() {
return (
<>
{/* Active Awards Banner */}
{activeAwards.length > 0 && (
<AnimatedCard index={0}>
<Card className="overflow-hidden border-0 shadow-lg">
<div className="bg-gradient-to-r from-amber-400 to-amber-500 p-[1px] rounded-lg">
<div className="rounded-[7px] bg-background">
<CardHeader className="pb-2 pt-4 px-5">
<div className="flex items-center gap-2.5">
<div className="rounded-lg bg-amber-100 p-1.5">
<Trophy className="h-4 w-4 text-amber-600" />
</div>
<CardTitle className="text-lg">Special Awards Voting Open</CardTitle>
</div>
</CardHeader>
<CardContent className="px-5 pb-4 space-y-3">
{activeAwards.map((record) => {
const award = record.award
const deadline = award.votingEndAt ? new Date(award.votingEndAt) : null
const isUrgent = deadline && (deadline.getTime() - now.getTime()) < 24 * 60 * 60 * 1000
const hasVoted = votedAwardIds.has(award.id)
return (
<div
key={award.id}
className={cn(
'rounded-xl border p-4 space-y-3 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md',
hasVoted
? 'border-green-200/60 bg-green-50/30'
: isUrgent
? 'border-red-200 bg-red-50/50'
: 'border-amber-200/60 bg-amber-50/30'
)}
>
<div className="flex items-start justify-between">
<div>
<h3 className={cn('font-semibold', hasVoted ? 'text-green-700' : 'text-amber-700')}>{award.name}</h3>
<p className="text-xs text-muted-foreground mt-0.5">
{award._count.eligibilities} project{award._count.eligibilities !== 1 ? 's' : ''} to review
{record.isChair && ' · You are the Chair'}
</p>
</div>
{hasVoted ? (
<Badge className="bg-green-100 text-green-800 border-green-300">
<CheckCircle2 className="mr-1 h-3 w-3" />
Submitted
</Badge>
) : (
<Badge className="bg-amber-100 text-amber-800 border-amber-300">
Vote Now
</Badge>
)}
</div>
{deadline && (
<CountdownTimer deadline={deadline} label="Voting closes:" />
)}
<Button asChild size="sm" className={cn(
'w-full shadow-sm',
hasVoted
? 'bg-green-600 hover:bg-green-700 text-white'
: 'bg-amber-600 hover:bg-amber-700 text-white'
)}>
<Link href={`/jury/awards/${award.id}`}>
{hasVoted ? 'Edit Rankings' : 'Review & Vote'}
<ArrowRight className="ml-2 h-4 w-4" />
</Link>
</Button>
</div>
)
})}
</CardContent>
</div>
</div>
</Card>
</AnimatedCard>
)}
{/* Hero CTA - Jump to next evaluation */}
{nextUnevaluated && activeRemaining > 0 && (
<AnimatedCard index={0}>
@@ -338,8 +518,8 @@ async function JuryDashboardContent() {
<CardHeader className="pb-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2.5">
<div className="rounded-lg bg-brand-blue/10 p-1.5 dark:bg-brand-blue/20">
<ClipboardList className="h-4 w-4 text-brand-blue dark:text-brand-teal" />
<div className="rounded-lg bg-brand-blue/10 p-1.5">
<ClipboardList className="h-4 w-4 text-brand-blue" />
</div>
<CardTitle className="text-lg">My Assignments</CardTitle>
</div>
@@ -373,14 +553,14 @@ async function JuryDashboardContent() {
href={`/jury/competitions/${assignment.round.id}/projects/${assignment.project.id}`}
className="flex-1 min-w-0 group"
>
<p className="text-sm font-medium truncate group-hover:text-brand-blue dark:group-hover:text-brand-teal transition-colors">
<p className="text-sm font-medium truncate group-hover:text-brand-blue transition-colors">
{assignment.project.title}
</p>
<div className="flex items-center gap-2 mt-1">
<span className="text-xs text-muted-foreground truncate">
{assignment.project.teamName}
</span>
<Badge variant="secondary" className="text-[10px] px-1.5 py-0 bg-brand-blue/5 text-brand-blue/80 dark:bg-brand-teal/10 dark:text-brand-teal/80 border-0">
<Badge variant="secondary" className="text-[10px] px-1.5 py-0 bg-brand-blue/5 text-brand-blue/80 border-0">
{assignment.round.name}
</Badge>
</div>
@@ -392,7 +572,7 @@ async function JuryDashboardContent() {
Done
</Badge>
) : isDraft && isVotingOpen ? (
<Badge className="text-xs bg-amber-100 text-amber-800 border-amber-300 dark:bg-amber-950 dark:text-amber-300 dark:border-amber-700 animate-pulse">
<Badge className="text-xs bg-amber-100 text-amber-800 border-amber-300 animate-pulse">
<Send className="mr-1 h-3 w-3" />
Ready to submit
</Badge>
@@ -457,7 +637,7 @@ async function JuryDashboardContent() {
<Card>
<CardHeader className="pb-3">
<div className="flex items-center gap-2.5">
<div className="rounded-lg bg-brand-teal/10 p-1.5 dark:bg-brand-teal/20">
<div className="rounded-lg bg-brand-teal/10 p-1.5">
<Zap className="h-4 w-4 text-brand-teal" />
</div>
<CardTitle className="text-lg">Quick Actions</CardTitle>
@@ -467,13 +647,13 @@ async function JuryDashboardContent() {
<div className={`grid gap-3 ${juryCompareEnabled ? 'sm:grid-cols-2' : ''}`}>
<Link
href="/jury/competitions"
className="group flex items-center gap-4 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:border-brand-blue/30 hover:bg-brand-blue/5 hover:-translate-y-0.5 hover:shadow-md dark:hover:border-brand-teal/30 dark:hover:bg-brand-teal/5"
className="group flex items-center gap-4 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:border-brand-blue/30 hover:bg-brand-blue/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-xl bg-blue-50 p-3 transition-colors group-hover:bg-blue-100 dark:bg-blue-950/40 dark:group-hover:bg-blue-950/60">
<ClipboardList className="h-5 w-5 text-blue-600 dark:text-blue-400" />
<div className="rounded-xl bg-blue-50 p-3 transition-colors group-hover:bg-blue-100">
<ClipboardList className="h-5 w-5 text-blue-600" />
</div>
<div className="text-left">
<p className="font-semibold text-sm group-hover:text-brand-blue dark:group-hover:text-brand-teal transition-colors">All Assignments</p>
<p className="font-semibold text-sm group-hover:text-brand-blue transition-colors">All Assignments</p>
<p className="text-xs text-muted-foreground mt-0.5">View and manage evaluations</p>
</div>
</Link>
@@ -482,7 +662,7 @@ async function JuryDashboardContent() {
href="/jury/competitions"
className="group flex items-center gap-4 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:border-brand-teal/30 hover:bg-brand-teal/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-xl bg-teal-50 p-3 transition-colors group-hover:bg-teal-100 dark:bg-teal-950/40 dark:group-hover:bg-teal-950/60">
<div className="rounded-xl bg-teal-50 p-3 transition-colors group-hover:bg-teal-100">
<GitCompare className="h-5 w-5 text-brand-teal" />
</div>
<div className="text-left">
@@ -506,8 +686,8 @@ async function JuryDashboardContent() {
<div className="h-1 w-full bg-gradient-to-r from-brand-blue via-brand-teal to-brand-blue" />
<CardHeader className="pb-3">
<div className="flex items-center gap-2.5">
<div className="rounded-lg bg-brand-blue/10 p-1.5 dark:bg-brand-blue/20">
<Waves className="h-4 w-4 text-brand-blue dark:text-brand-teal" />
<div className="rounded-lg bg-brand-blue/10 p-1.5">
<Waves className="h-4 w-4 text-brand-blue" />
</div>
<div>
<CardTitle className="text-lg">Active Voting Stages</CardTitle>
@@ -536,13 +716,13 @@ async function JuryDashboardContent() {
className={cn(
'rounded-xl border p-4 space-y-3 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md',
isUrgent
? 'border-red-200 bg-red-50/50 dark:border-red-900 dark:bg-red-950/20'
: 'border-border/60 bg-muted/20 dark:bg-muted/10'
? 'border-red-200 bg-red-50/50'
: 'border-border/60 bg-muted/20'
)}
>
<div className="flex items-start justify-between">
<div>
<h3 className="font-semibold text-brand-blue dark:text-brand-teal">{round.name}</h3>
<h3 className="font-semibold text-brand-blue">{round.name}</h3>
<p className="text-xs text-muted-foreground mt-0.5">
{program.name} &middot; {program.year}
</p>
@@ -602,7 +782,7 @@ async function JuryDashboardContent() {
<AnimatedCard index={8}>
<Card>
<CardContent className="flex flex-col items-center justify-center py-6 text-center">
<div className="rounded-2xl bg-brand-teal/10 p-3 mb-2 dark:bg-brand-teal/20">
<div className="rounded-2xl bg-brand-teal/10 p-3 mb-2">
<Clock className="h-6 w-6 text-brand-teal/70" />
</div>
<p className="font-semibold text-sm">No active voting stages</p>
@@ -620,7 +800,7 @@ async function JuryDashboardContent() {
<Card>
<CardHeader className="pb-3">
<div className="flex items-center gap-2.5">
<div className="rounded-lg bg-brand-teal/10 p-1.5 dark:bg-brand-teal/20">
<div className="rounded-lg bg-brand-teal/10 p-1.5">
<BarChart3 className="h-4 w-4 text-brand-teal" />
</div>
<CardTitle className="text-lg">Round Summary</CardTitle>
@@ -636,7 +816,7 @@ async function JuryDashboardContent() {
<div className="flex items-center justify-between text-sm">
<span className="font-medium truncate">{round.name}</span>
<div className="flex items-baseline gap-1 shrink-0 ml-2">
<span className="font-bold tabular-nums text-brand-blue dark:text-brand-teal">{pct}%</span>
<span className="font-bold tabular-nums text-brand-blue">{pct}%</span>
<span className="text-xs text-muted-foreground">({done}/{total})</span>
</div>
</div>
@@ -738,7 +918,7 @@ export default async function JuryDashboardPage() {
<div className="space-y-4">
{/* Header */}
<div>
<h1 className="text-2xl font-bold tracking-tight text-brand-blue dark:text-foreground">
<h1 className="text-2xl font-bold tracking-tight text-brand-blue">
{getGreeting()}, {session?.user?.name || 'Juror'}
</h1>
<p className="text-muted-foreground mt-0.5">
@@ -749,6 +929,11 @@ export default async function JuryDashboardPage() {
{/* Preferences banner (shown when juror has unconfirmed preferences) */}
<JuryPreferencesBanner />
{/* Grand-Final finalist documents — prominent entry for finals jurors */}
<Suspense fallback={null}>
<FinalsJuryBanner />
</Suspense>
{/* Content */}
<Suspense fallback={<DashboardSkeleton />}>
<JuryDashboardContent />

View File

@@ -41,6 +41,7 @@ import {
import { formatDateOnly } from '@/lib/utils'
import { AnimatedCard } from '@/components/shared/animated-container'
import { CountryDisplay } from '@/components/shared/country-display'
import { RecentMessagesCard } from '@/components/mentor/recent-messages-card'
// Status badge colors
const statusColors: Record<string, 'default' | 'secondary' | 'destructive' | 'outline'> = {
@@ -117,6 +118,9 @@ export default function MentorDashboard() {
</p>
</div>
{/* Recent unread messages from teams */}
<RecentMessagesCard />
{/* Stats */}
<div className="grid gap-4 md:grid-cols-3">
<AnimatedCard index={0}>

View File

@@ -2,6 +2,7 @@
import { Suspense, use, useState, useEffect } from 'react'
import { useRouter } from 'next/navigation'
import { useSession } from 'next-auth/react'
import { trpc } from '@/lib/trpc/client'
import {
Card,
@@ -31,6 +32,7 @@ import { AnimatedCard } from '@/components/shared/animated-container'
import { FileViewer } from '@/components/shared/file-viewer'
import { MentorChat } from '@/components/shared/mentor-chat'
import { ProjectLogoWithUrl } from '@/components/shared/project-logo-with-url'
import { DropAssignmentDialog } from '@/components/mentor/drop-assignment-dialog'
import {
ArrowLeft,
AlertCircle,
@@ -76,6 +78,7 @@ const statusColors: Record<string, 'default' | 'secondary' | 'destructive' | 'ou
function ProjectDetailContent({ projectId }: { projectId: string }) {
const router = useRouter()
const { data: session } = useSession()
const { data: project, isLoading, error } = trpc.mentor.getProjectDetail.useQuery({
projectId,
})
@@ -91,14 +94,18 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
},
})
// TODO(PR8 Task 9): show co-mentors. For now we pick the first assignment
// to keep tracking + chat working unchanged.
const primaryAssignment = project?.mentorAssignments?.[0] ?? null
// Track view when project loads
const trackView = trpc.mentor.trackView.useMutation()
useEffect(() => {
if (project?.mentorAssignment?.id) {
trackView.mutate({ mentorAssignmentId: project.mentorAssignment.id })
if (primaryAssignment?.id) {
trackView.mutate({ mentorAssignmentId: primaryAssignment.id })
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [project?.mentorAssignment?.id])
}, [primaryAssignment?.id])
if (isLoading) {
return <ProjectDetailSkeleton />
@@ -132,8 +139,15 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
const teamLead = project.teamMembers?.find((m) => m.role === 'LEAD')
const otherMembers = project.teamMembers?.filter((m) => m.role !== 'LEAD') || []
const mentorAssignmentId = project.mentorAssignment?.id
const mentorAssignment = primaryAssignment
const mentorAssignmentId = mentorAssignment?.id
const programId = project.program?.id
const viewerIsAssignedMentor =
!!mentorAssignment && session?.user?.id === mentorAssignment.mentor?.id
const canDrop =
viewerIsAssignedMentor &&
!mentorAssignment.droppedAt &&
mentorAssignment.completionStatus !== 'completed'
return (
<div className="space-y-6">
@@ -179,6 +193,12 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
)}
</div>
</div>
{canDrop && mentorAssignmentId && (
<DropAssignmentDialog
assignmentId={mentorAssignmentId}
projectTitle={project.title}
/>
)}
</div>
{project.assignedAt && (
@@ -324,6 +344,25 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{(() => {
const emails = (project.teamMembers ?? [])
.map((m) => m.user.email)
.filter((e): e is string => !!e)
if (emails.length === 0) return null
const mailto = `mailto:${emails.join(',')}?subject=${encodeURIComponent(
`MOPC Mentorship — ${project.title}`,
)}`
return (
<div className="flex justify-end">
<Button variant="outline" size="sm" asChild>
<a href={mailto}>
<Mail className="mr-2 h-4 w-4" />
Email all team members
</a>
</Button>
</div>
)
})()}
{/* Team Lead */}
{teamLead && (
<div className="p-4 rounded-lg border bg-muted/30">
@@ -461,7 +500,7 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
<CardContent>
<MentorChat
messages={mentorMessages || []}
currentUserId={project.mentorAssignment?.mentor?.id || ''}
currentUserId={primaryAssignment?.mentor?.id || ''}
onSendMessage={async (message) => {
await sendMessage.mutateAsync({ projectId, message })
}}
@@ -576,7 +615,7 @@ function MilestonesSection({
<div
key={milestone.id}
className={`flex items-start gap-3 p-3 rounded-lg border transition-all duration-200 hover:-translate-y-0.5 hover:shadow-sm ${
isCompleted ? 'bg-green-50/50 border-green-200 dark:bg-green-950/20 dark:border-green-900' : ''
isCompleted ? 'bg-green-50/50 border-green-200' : ''
}`}
>
<Checkbox

View File

@@ -1,20 +1,30 @@
'use client'
import { useParams, useRouter } from 'next/navigation'
import { useSession } from 'next-auth/react'
import { trpc } from '@/lib/trpc/client'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Badge } from '@/components/ui/badge'
import { Skeleton } from '@/components/ui/skeleton'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/tooltip'
import { WorkspaceChat } from '@/components/mentor/workspace-chat'
import { FilePromotionPanel } from '@/components/mentor/file-promotion-panel'
import { ArrowLeft, MessageSquare, FileText, Upload } from 'lucide-react'
import { WorkspaceFilesPanel } from '@/components/mentor/workspace-files-panel'
import { FinalDocumentsPanel } from '@/components/applicant/final-documents-panel'
import { ArrowLeft, MessageSquare, FileText, Upload, Users } from 'lucide-react'
import { toast } from 'sonner'
export default function MentorWorkspaceDetailPage() {
const params = useParams()
const router = useRouter()
const { data: session } = useSession()
const projectId = params.projectId as string
// Get mentor assignment for this project
@@ -26,6 +36,22 @@ export default function MentorWorkspaceDetailPage() {
{ enabled: !!projectId }
)
// Co-mentor visibility (PR8 multi-mentor): show who else is on the team.
// Gracefully tolerates stale tabs where the caller no longer has access
// (assignment dropped) — query just returns nothing in that case.
const { data: projectMentors } = trpc.mentor.getProjectMentors.useQuery(
{ projectId },
{ enabled: !!projectId, retry: false }
)
const currentUserId = session?.user?.id
const coMentors = (projectMentors ?? []).filter(
a => a.mentor.id !== currentUserId
)
const coMentorNames = coMentors.map(a => a.mentor.name ?? 'Unnamed mentor')
const visibleCoMentors = coMentorNames.slice(0, 3)
const hiddenCoMentors = coMentorNames.slice(3)
if (isLoading) {
return (
<div className="space-y-6">
@@ -69,6 +95,37 @@ export default function MentorWorkspaceDetailPage() {
{project.teamName && (
<p className="text-muted-foreground mt-1">{project.teamName}</p>
)}
{coMentors.length > 0 && (
<div className="mt-2 flex items-center gap-1.5 text-sm text-muted-foreground">
<Users className="h-3.5 w-3.5 shrink-0" />
<span>
You + {coMentors.length} co-mentor
{coMentors.length === 1 ? '' : 's'}:{' '}
<span className="text-foreground">
{visibleCoMentors.join(', ')}
</span>
{hiddenCoMentors.length > 0 && (
<>
{' '}
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<span className="cursor-help underline decoration-dotted underline-offset-2">
+{hiddenCoMentors.length} more
</span>
</TooltipTrigger>
<TooltipContent>
<div className="text-xs">
{hiddenCoMentors.join(', ')}
</div>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</>
)}
</span>
</div>
)}
</div>
</div>
@@ -102,25 +159,24 @@ export default function MentorWorkspaceDetailPage() {
</TabsContent>
<TabsContent value="files" className="mt-6">
{assignment ? (
<WorkspaceFilesPanel
projectId={projectId}
mentorAssignmentId={assignment.id}
/>
) : (
<Card>
<CardHeader>
<CardTitle>Workspace Files</CardTitle>
<CardDescription>
Files shared in the mentor workspace
</CardDescription>
</CardHeader>
<CardContent className="text-center py-8">
<FileText className="h-12 w-12 text-muted-foreground/50 mx-auto mb-3" />
<p className="text-sm text-muted-foreground">
File listing feature coming soon
</p>
<p className="text-sm text-muted-foreground">Loading workspace</p>
</CardContent>
</Card>
)}
</TabsContent>
<TabsContent value="promotion" className="mt-6">
{assignment ? (
<FilePromotionPanel mentorAssignmentId={assignment.id} />
<FilePromotionPanel projectId={projectId} />
) : (
<Card>
<CardContent className="text-center py-8">
@@ -131,6 +187,9 @@ export default function MentorWorkspaceDetailPage() {
)}
</TabsContent>
</Tabs>
{/* Final Documents (self-hides when not a finalist) */}
<FinalDocumentsPanel variant="mentor" projectId={projectId} />
</div>
)
}

View File

@@ -6,10 +6,13 @@ export const dynamic = 'force-dynamic'
export default async function ObserverProjectDetailPage({
params,
searchParams,
}: {
params: Promise<{ projectId: string }>
searchParams: Promise<{ round?: string }>
}) {
const { projectId } = await params
const sp = await searchParams
return <ObserverProjectDetail projectId={projectId} />
return <ObserverProjectDetail projectId={projectId} initialRoundId={sp.round} />
}

View File

@@ -0,0 +1,425 @@
'use client'
import { Suspense, use, useEffect, useMemo, useState } from 'react'
import Link from 'next/link'
import { trpc } from '@/lib/trpc/client'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
import { Switch } from '@/components/ui/switch'
import { Skeleton } from '@/components/ui/skeleton'
import { Textarea } from '@/components/ui/textarea'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { AlertCircle, CheckCircle2, Loader2, PartyPopper, XCircle } from 'lucide-react'
import { TRPCClientError } from '@trpc/client'
interface PageProps {
params: Promise<{ token: string }>
}
function formatDeadline(d: Date): string {
const main = new Intl.DateTimeFormat(undefined, {
dateStyle: 'long',
timeStyle: 'short',
}).format(d)
const tzPart = new Intl.DateTimeFormat(undefined, { timeZoneName: 'short' })
.formatToParts(d)
.find((p) => p.type === 'timeZoneName')?.value
return tzPart ? `${main} (${tzPart})` : main
}
function CountdownLabel({ deadline }: { deadline: Date }) {
const [now, setNow] = useState<number>(Date.now())
useEffect(() => {
const id = setInterval(() => setNow(Date.now()), 1000)
return () => clearInterval(id)
}, [])
const ms = deadline.getTime() - now
if (ms <= 0) return <span className="text-destructive font-medium">expired</span>
const totalSec = Math.floor(ms / 1000)
const hours = Math.floor(totalSec / 3600)
const minutes = Math.floor((totalSec % 3600) / 60)
const seconds = totalSec % 60
if (hours >= 24) {
const days = Math.floor(hours / 24)
const remHours = hours % 24
return (
<span className="font-medium tabular-nums">
{days}d {remHours}h remaining
</span>
)
}
return (
<span className="font-medium tabular-nums">
{hours.toString().padStart(2, '0')}:{minutes.toString().padStart(2, '0')}:
{seconds.toString().padStart(2, '0')} remaining
</span>
)
}
function FriendlyError({
title,
message,
icon: Icon,
}: {
title: string
message: string
icon: typeof AlertCircle
}) {
return (
<Card className="mx-auto max-w-xl">
<CardHeader>
<div className="flex items-center gap-2">
<Icon className="text-muted-foreground h-5 w-5" />
<CardTitle>{title}</CardTitle>
</div>
</CardHeader>
<CardContent>
<p className="text-muted-foreground">{message}</p>
</CardContent>
</Card>
)
}
function FinalistConfirmContent({ token }: { token: string }) {
const { data, isLoading, error } = trpc.finalist.getByToken.useQuery({ token }, { retry: false })
const confirmMutation = trpc.finalist.confirm.useMutation()
const declineMutation = trpc.finalist.decline.useMutation()
const [selected, setSelected] = useState<Set<string>>(new Set())
const [visa, setVisa] = useState<Record<string, boolean>>({})
const [declineReason, setDeclineReason] = useState('')
const [submitState, setSubmitState] = useState<'idle' | 'confirmed' | 'declined' | 'error'>(
'idle',
)
const [submitError, setSubmitError] = useState<string | null>(null)
// Default-select all team members once data arrives
useEffect(() => {
if (data?.project.teamMembers && selected.size === 0 && submitState === 'idle') {
const cap = data.project.program.defaultAttendeeCap
const initial = new Set(
data.project.teamMembers.slice(0, cap).map((tm) => tm.userId),
)
setSelected(initial)
}
}, [data, selected.size, submitState])
// ── Loading
if (isLoading) {
return (
<div className="mx-auto max-w-xl space-y-4">
<Skeleton className="h-8 w-2/3" />
<Skeleton className="h-32 w-full" />
<Skeleton className="h-48 w-full" />
</div>
)
}
// ── Token errors → friendly states
if (error) {
const msg = error.message ?? ''
if (/expired/i.test(msg)) {
return (
<FriendlyError
icon={AlertCircle}
title="This link has expired"
message="If your team still wants to attend, please contact us at info@monaco-opc.com."
/>
)
}
if (/signature|malformed|payload/i.test(msg)) {
return (
<FriendlyError
icon={AlertCircle}
title="This link is not valid"
message="Please check your email or contact us at info@monaco-opc.com."
/>
)
}
return (
<FriendlyError
icon={AlertCircle}
title="Something went wrong"
message={msg || 'Please try again or contact us at info@monaco-opc.com.'}
/>
)
}
if (!data) {
return (
<FriendlyError
icon={AlertCircle}
title="Confirmation not found"
message="Please check your email link or contact us at info@monaco-opc.com."
/>
)
}
// ── Status branches: only PENDING is interactive
if (submitState === 'confirmed' || data.status === 'CONFIRMED') {
return (
<Card className="mx-auto max-w-xl">
<CardHeader>
<div className="flex items-center gap-2">
<PartyPopper className="text-primary h-5 w-5" />
<CardTitle>You&apos;re in!</CardTitle>
</div>
</CardHeader>
<CardContent>
<p className="mb-2">
Your team&apos;s attendance for <strong>{data.project.title}</strong> is confirmed.
</p>
<p className="text-muted-foreground text-sm">
We&apos;ll be in touch shortly with travel and lunch logistics. You can edit your team
selection and view hotel, flight, and visa details from your dashboard.
</p>
<Button asChild className="mt-4">
<Link href="/applicant">Go to my dashboard</Link>
</Button>
</CardContent>
</Card>
)
}
if (submitState === 'declined' || data.status === 'DECLINED') {
return (
<FriendlyError
icon={XCircle}
title="Your team has declined"
message="If this was a mistake, please contact us at info@monaco-opc.com."
/>
)
}
if (data.status === 'EXPIRED') {
return (
<FriendlyError
icon={AlertCircle}
title="The confirmation deadline has passed"
message="If your team still wants to attend, please contact us at info@monaco-opc.com."
/>
)
}
if (data.status === 'SUPERSEDED') {
return (
<FriendlyError
icon={AlertCircle}
title="This confirmation is no longer active"
message="Please contact us at info@monaco-opc.com for details."
/>
)
}
// ── PENDING: render the form
const cap = data.project.program.defaultAttendeeCap
const deadline = new Date(data.deadline)
const overCap = selected.size > cap
const noneSelected = selected.size === 0
const toggle = (userId: string, checked: boolean) => {
setSelected((prev) => {
const next = new Set(prev)
if (checked) next.add(userId)
else next.delete(userId)
return next
})
}
const toggleVisa = (userId: string, checked: boolean) => {
setVisa((prev) => ({ ...prev, [userId]: checked }))
}
const handleConfirm = async () => {
setSubmitError(null)
try {
await confirmMutation.mutateAsync({
token,
attendingUserIds: Array.from(selected),
visaFlags: Object.fromEntries(
Array.from(selected).map((uid) => [uid, !!visa[uid]]),
),
})
setSubmitState('confirmed')
} catch (err) {
setSubmitState('error')
const msg =
err instanceof TRPCClientError ? err.message : err instanceof Error ? err.message : 'Failed'
setSubmitError(msg)
}
}
const handleDecline = async () => {
setSubmitError(null)
try {
await declineMutation.mutateAsync({
token,
reason: declineReason.trim() || undefined,
})
setSubmitState('declined')
} catch (err) {
setSubmitState('error')
const msg =
err instanceof TRPCClientError ? err.message : err instanceof Error ? err.message : 'Failed'
setSubmitError(msg)
}
}
return (
<div className="mx-auto max-w-xl space-y-6">
<Card className="border-primary/40 bg-primary/5">
<CardHeader>
<div className="flex items-center gap-2">
<PartyPopper className="text-primary h-5 w-5" />
<CardTitle>Congratulations!</CardTitle>
</div>
</CardHeader>
<CardContent className="space-y-2">
<p>
Your project <strong>{data.project.title}</strong> is a finalist for the Monaco Ocean
Protection Challenge grand finale.
</p>
<div className="bg-background border-amber-300 mt-3 rounded-md border-l-4 p-3">
<p className="text-sm">
<strong>Confirm by {formatDeadline(deadline)}.</strong>
</p>
<p className="text-muted-foreground mt-1 text-xs">
<CountdownLabel deadline={deadline} />
</p>
</div>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle className="text-base">Who from your team will attend?</CardTitle>
<p className="text-muted-foreground text-sm">
You can select up to <strong>{cap}</strong> team members. Indicate who needs visa
support so we can prepare documents in time.
</p>
</CardHeader>
<CardContent>
<ul className="space-y-3">
{data.project.teamMembers.map((tm) => {
const checked = selected.has(tm.userId)
return (
<li key={tm.userId} className="flex items-start justify-between gap-4">
<label className="flex flex-1 items-start gap-3 cursor-pointer">
<Checkbox
checked={checked}
onCheckedChange={(c) => toggle(tm.userId, c === true)}
className="mt-0.5"
/>
<div>
<div className="font-medium">{tm.user.name ?? tm.user.email}</div>
<div className="text-muted-foreground text-xs">
{tm.user.email}
{tm.role && tm.role !== 'MEMBER' ? ` · ${tm.role.toLowerCase()}` : ''}
</div>
</div>
</label>
{checked && (
<label className="flex items-center gap-2 text-sm">
<span className="text-muted-foreground">Needs visa?</span>
<Switch
checked={!!visa[tm.userId]}
onCheckedChange={(c) => toggleVisa(tm.userId, c)}
/>
</label>
)}
</li>
)
})}
</ul>
{overCap && (
<p className="text-destructive mt-3 text-sm">
Please select no more than {cap} member{cap === 1 ? '' : 's'}.
</p>
)}
</CardContent>
</Card>
{submitError && (
<div className="border-destructive bg-destructive/10 text-destructive rounded-md border p-3 text-sm">
{submitError}
</div>
)}
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="ghost" className="text-muted-foreground">
We can&apos;t attend
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Decline finalist slot?</AlertDialogTitle>
<AlertDialogDescription>
If your team can&apos;t attend, we&apos;ll offer the slot to a waitlisted team. This
action can&apos;t be undone from this page.
</AlertDialogDescription>
</AlertDialogHeader>
<div className="space-y-2">
<label className="text-muted-foreground text-sm" htmlFor="decline-reason">
Reason (optional, helps us improve future editions)
</label>
<Textarea
id="decline-reason"
value={declineReason}
onChange={(e) => setDeclineReason(e.target.value)}
placeholder="e.g. logistics conflict, team disbanded, no longer interested"
rows={3}
/>
</div>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleDecline}
disabled={declineMutation.isPending}
className="bg-destructive hover:bg-destructive/90"
>
{declineMutation.isPending ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
'Decline finalist slot'
)}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<Button
size="lg"
onClick={handleConfirm}
disabled={overCap || noneSelected || confirmMutation.isPending}
>
{confirmMutation.isPending ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> Confirming
</>
) : (
<>
<CheckCircle2 className="mr-2 h-4 w-4" />
Confirm Attendance
</>
)}
</Button>
</div>
</div>
)
}
export default function FinalistConfirmPage({ params }: PageProps) {
const { token } = use(params)
return (
<Suspense fallback={<Skeleton className="h-64 w-full" />}>
<FinalistConfirmContent token={token} />
</Suspense>
)
}

View File

@@ -0,0 +1,535 @@
'use client'
/**
* Big-screen ceremony view — projected on stage at the grand finale.
* Award-night broadcast aesthetic: deep layered ocean field, extreme
* Montserrat scale contrast, red as a scalpel accent, gold reserved for the
* winner moment. Pure derivation of server state (poll 2s), full-bleed over
* the public layout, no interactive chrome.
*/
import { use, useEffect, useMemo, useState } from 'react'
import { motion, AnimatePresence } from 'motion/react'
import { QRCodeSVG } from 'qrcode.react'
import { trpc } from '@/lib/trpc/client'
import { remainingSeconds, formatClock } from '@/lib/live-timer'
const CATEGORY_LABEL: Record<string, string> = {
BUSINESS_CONCEPT: 'Business Concepts',
STARTUP: 'Startups',
}
const WINDOW_TITLE: Record<string, string> = {
'CATEGORY:BUSINESS_CONCEPT': 'Vote for your favorite Business Concept',
'CATEGORY:STARTUP': 'Vote for your favorite Startup',
OVERALL: 'Vote for your favorite project of the night',
}
function useTick() {
const [, tick] = useState(0)
useEffect(() => {
const id = setInterval(() => tick((t) => t + 1), 1000)
return () => clearInterval(id)
}, [])
}
// ─── Atmosphere ──────────────────────────────────────────────────────────────
function OceanField({ children }: { children: React.ReactNode }) {
return (
<div className="fixed inset-0 z-50 overflow-hidden bg-[#021f2e] font-[Montserrat,sans-serif] text-white">
{/* Layered ocean-light gradients */}
<div
className="absolute inset-0"
style={{
background:
'radial-gradient(120% 90% at 50% 110%, #0a5a7c 0%, #053d57 45%, #021f2e 100%)',
}}
/>
<motion.div
className="absolute -inset-x-1/4 top-[-40%] h-[80%] opacity-25"
style={{
background:
'radial-gradient(50% 100% at 50% 0%, rgba(85,127,140,0.9) 0%, transparent 70%)',
}}
animate={{ x: ['-8%', '8%', '-8%'] }}
transition={{ repeat: Infinity, duration: 18, ease: 'easeInOut' }}
/>
{/* Grain for projector richness */}
<div
className="pointer-events-none absolute inset-0 opacity-[0.05] mix-blend-overlay"
style={{
backgroundImage:
"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
}}
/>
{children}
</div>
)
}
function StatusBar({ programName, label }: { programName: string | null; label?: string | null }) {
return (
<div className="absolute inset-x-0 top-0 flex items-center justify-between px-12 py-8">
<p className="text-sm font-semibold uppercase tracking-[0.4em] text-white/50">
{programName ?? 'Monaco Ocean Protection Challenge'}
</p>
{label && (
<p className="flex items-center gap-3 text-sm font-semibold uppercase tracking-[0.4em] text-white/50">
<span className="inline-block h-2.5 w-2.5 animate-pulse rounded-full bg-[#de0f1e]" />
{label}
</p>
)}
</div>
)
}
function SignatureRule() {
return (
<div className="mx-auto flex w-48 items-center gap-0">
<div className="h-px flex-1 bg-white/25" />
<div className="h-[3px] w-10 bg-[#de0f1e]" />
<div className="h-px flex-1 bg-white/25" />
</div>
)
}
const slideIn = {
initial: { opacity: 0, y: 36, scale: 0.985, filter: 'blur(6px)' },
animate: { opacity: 1, y: 0, scale: 1, filter: 'blur(0px)' },
exit: { opacity: 0, y: -24, scale: 0.99, filter: 'blur(4px)' },
transition: { duration: 0.6, ease: [0.22, 1, 0.36, 1] as const },
}
// ─── Slides ──────────────────────────────────────────────────────────────────
function StaticSlide({ kind, programName }: { kind: string; programName: string | null }) {
const copy: Record<string, { eyebrow: string; title: string; sub?: string }> = {
welcome: {
eyebrow: programName ?? 'Monaco Ocean Protection Challenge',
title: 'Grand Finale',
sub: 'Welcome',
},
break: { eyebrow: 'Intermission', title: 'Back shortly', sub: 'Enjoy the break' },
deliberation: {
eyebrow: 'The jury has retired',
title: 'Deliberation in progress',
sub: 'Results follow shortly',
},
thanks: { eyebrow: programName ?? 'Grand Finale', title: 'Thank you', sub: 'See you next year' },
}
const c = copy[kind] ?? copy.welcome
return (
<div className="flex h-full flex-col items-center justify-center gap-8 px-16 text-center">
<p className="text-lg font-semibold uppercase tracking-[0.5em] text-white/50">{c.eyebrow}</p>
<h1 className="text-[clamp(4rem,10vw,9rem)] font-extrabold leading-none tracking-tight">
{c.title}
</h1>
<SignatureRule />
{c.sub && <p className="text-2xl font-light text-white/70">{c.sub}</p>}
</div>
)
}
function PhaseSlide({
state,
}: {
state: {
phase: {
projectPhase: string
phaseStartedAt: string | Date | null
phaseDurationSeconds: number | null
phasePausedAt: string | Date | null
phasePausedAccumMs: number
} | null
activeProject: { title: string; teamName: string | null; competitionCategory: string | null } | null
}
}) {
useTick()
const phase = state.phase
const project = state.activeProject
if (!phase || !project) return <StaticSlide kind="welcome" programName={null} />
const remaining = remainingSeconds(phase)
const over = remaining !== null && remaining < 0
const category = project.competitionCategory
? CATEGORY_LABEL[project.competitionCategory]
: null
if (phase.projectPhase === 'ON_DECK') {
return (
<div className="flex h-full flex-col items-center justify-center gap-10 px-16 text-center">
<motion.p
initial={{ opacity: 0, y: -16 }}
animate={{ opacity: 1, y: 0 }}
className="text-xl font-semibold uppercase tracking-[0.5em] text-[#557f8c]"
>
Up next
</motion.p>
<motion.h1
initial={{ opacity: 0, y: 30, scale: 0.96 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
transition={{ type: 'spring', stiffness: 80, damping: 16, delay: 0.15 }}
className="max-w-[90vw] text-[clamp(3.5rem,9vw,8rem)] font-extrabold leading-[1.02] tracking-tight"
>
{project.teamName ?? project.title}
</motion.h1>
<SignatureRule />
<div className="space-y-2">
{project.teamName && <p className="text-3xl font-light text-white/80">{project.title}</p>}
{category && (
<p className="text-lg font-semibold uppercase tracking-[0.35em] text-white/45">
{category}
</p>
)}
</div>
</div>
)
}
if (phase.projectPhase === 'SCORING') {
return (
<div className="flex h-full flex-col items-center justify-center gap-8 px-16 text-center">
<p className="text-lg font-semibold uppercase tracking-[0.5em] text-white/50">
{project.teamName ?? project.title}
</p>
<h1 className="text-[clamp(3rem,7vw,6rem)] font-extrabold tracking-tight">
The jury is scoring
</h1>
<SignatureRule />
<motion.div
className="flex gap-3"
initial="hidden"
animate="visible"
variants={{ visible: { transition: { staggerChildren: 0.25 } } }}
>
{[0, 1, 2].map((i) => (
<motion.span
key={i}
className="h-3 w-3 rounded-full bg-[#557f8c]"
animate={{ opacity: [0.25, 1, 0.25] }}
transition={{ repeat: Infinity, duration: 1.6, delay: i * 0.3 }}
/>
))}
</motion.div>
</div>
)
}
// PRESENTING / QA
const phaseLabel = phase.projectPhase === 'QA' ? 'Q&A' : 'Presentation'
return (
<div className="flex h-full flex-col items-center justify-center gap-8 px-16 text-center">
<div className="space-y-3">
{category && (
<p className="text-base font-semibold uppercase tracking-[0.4em] text-white/45">
{category}
</p>
)}
<h1 className="max-w-[92vw] text-[clamp(3rem,8vw,7rem)] font-extrabold leading-[1.03] tracking-tight">
{project.teamName ?? project.title}
</h1>
{project.teamName && (
<p className="text-2xl font-light text-white/70">{project.title}</p>
)}
</div>
<SignatureRule />
<div className="space-y-2">
<p className="text-lg font-semibold uppercase tracking-[0.45em] text-[#557f8c]">
{phaseLabel}
</p>
{remaining !== null && (
<motion.p
className={`text-[clamp(4rem,9vw,8rem)] font-bold tabular-nums leading-none ${
over ? 'text-[#de0f1e]' : 'text-white'
}`}
animate={over ? { opacity: [1, 0.55, 1] } : {}}
transition={over ? { repeat: Infinity, duration: 1.2 } : {}}
style={over ? { textShadow: '0 0 60px rgba(222,15,30,0.55)' } : {}}
>
{formatClock(remaining)}
</motion.p>
)}
{phase.phasePausedAt && (
<p className="text-base font-semibold uppercase tracking-[0.35em] text-white/45">
paused
</p>
)}
</div>
</div>
)
}
function AudienceVoteSlide({
windowKey,
closesAt,
voteCount,
voteUrl,
}: {
windowKey: string | null
closesAt: string | Date | null
voteCount: number
voteUrl: string
}) {
useTick()
const secondsLeft = closesAt
? Math.max(0, Math.floor((new Date(closesAt).getTime() - Date.now()) / 1000))
: null
return (
<div className="flex h-full items-center justify-center gap-24 px-20">
<motion.div
animate={{ scale: [1, 1.015, 1] }}
transition={{ repeat: Infinity, duration: 4, ease: 'easeInOut' }}
className="shrink-0 rounded-[2.5rem] bg-white p-10 shadow-[0_0_120px_rgba(85,127,140,0.45)]"
>
{voteUrl && <QRCodeSVG value={voteUrl} size={400} />}
</motion.div>
<div className="max-w-3xl space-y-8">
<p className="text-lg font-semibold uppercase tracking-[0.45em] text-[#de0f1e]">
Audience vote open now
</p>
<h1 className="text-[clamp(2.5rem,5.5vw,4.5rem)] font-extrabold leading-tight tracking-tight">
{WINDOW_TITLE[windowKey ?? ''] ?? 'Vote for your favorite'}
</h1>
<p className="text-2xl font-light text-white/70">
Scan the code with your phone one vote each
</p>
<div className="flex items-end gap-14 pt-2">
{secondsLeft !== null && (
<div>
<p className="text-sm font-semibold uppercase tracking-[0.35em] text-white/45">
Closes in
</p>
<p
className={`text-7xl font-bold tabular-nums ${
secondsLeft <= 30 ? 'text-[#de0f1e]' : ''
}`}
>
{formatClock(secondsLeft)}
</p>
</div>
)}
<div>
<p className="text-sm font-semibold uppercase tracking-[0.35em] text-white/45">
Votes cast
</p>
<motion.p
key={voteCount}
initial={{ scale: 1.25, color: '#de0f1e' }}
animate={{ scale: 1, color: '#ffffff' }}
className="text-7xl font-bold tabular-nums"
>
{voteCount}
</motion.p>
</div>
</div>
</div>
</div>
)
}
// ─── Reveal ──────────────────────────────────────────────────────────────────
function Confetti({ gold }: { gold?: boolean }) {
const pieces = useMemo(
() =>
Array.from({ length: 56 }, (_, i) => ({
left: ((i * 137.5) % 100),
delay: (i % 14) * 0.09,
duration: 2.6 + ((i * 7) % 10) / 6,
size: 7 + ((i * 13) % 9),
rotate: (i * 73) % 360,
color: gold
? ['#e8c34a', '#de0f1e', '#ffffff', '#f0d98c'][i % 4]
: ['#de0f1e', '#557f8c', '#ffffff', '#9fc3cf'][i % 4],
})),
[gold]
)
return (
<div className="pointer-events-none absolute inset-0 overflow-hidden">
{pieces.map((p, i) => (
<motion.span
key={i}
className="absolute top-[-5%] block"
style={{
left: `${p.left}%`,
width: p.size,
height: p.size * 0.45,
backgroundColor: p.color,
borderRadius: 1,
}}
initial={{ y: '-10vh', rotate: p.rotate, opacity: 0 }}
animate={{ y: '115vh', rotate: p.rotate + 540, opacity: [0, 1, 1, 0.8] }}
transition={{ duration: p.duration, delay: p.delay, ease: 'easeIn' }}
/>
))}
</div>
)
}
type RevealStep = {
kind: string
category?: string
place?: number
title?: string
subtitle?: string
}
function RevealSlide({ step }: { step: RevealStep }) {
const isWinner = step.kind === 'place' && step.place === 1
const isAudience = step.kind === 'audience-award' || step.kind === 'overall-favorite'
if (step.kind === 'category-intro') {
return (
<div className="flex h-full flex-col items-center justify-center gap-8 px-16 text-center">
<p className="text-lg font-semibold uppercase tracking-[0.5em] text-white/50">Results</p>
<h1 className="text-[clamp(4rem,9vw,8rem)] font-extrabold tracking-tight">
{step.title ?? CATEGORY_LABEL[step.category ?? ''] ?? ''}
</h1>
<SignatureRule />
</div>
)
}
if (step.kind === 'thanks') {
return <StaticSlide kind="thanks" programName={null} />
}
return (
<div className="relative flex h-full flex-col items-center justify-center gap-10 px-16 text-center">
{(isWinner || isAudience) && <Confetti gold={isWinner} />}
{isWinner && (
<div
className="pointer-events-none absolute inset-0"
style={{
background:
'radial-gradient(55% 45% at 50% 52%, rgba(232,195,74,0.16) 0%, transparent 70%)',
}}
/>
)}
<motion.p
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5 }}
className={`text-xl font-semibold uppercase tracking-[0.5em] ${
isAudience ? 'text-[#de0f1e]' : isWinner ? 'text-[#e8c34a]' : 'text-[#557f8c]'
}`}
>
{step.subtitle ?? ''}
</motion.p>
<motion.h1
initial={{ opacity: 0, y: 60, scale: 0.92 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
transition={{ type: 'spring', stiffness: 70, damping: 14, delay: 0.35 }}
className={`max-w-[92vw] font-extrabold leading-[1.02] tracking-tight ${
isWinner
? 'text-[clamp(4.5rem,11vw,10rem)]'
: 'text-[clamp(3.5rem,8vw,7.5rem)]'
}`}
style={isWinner ? { textShadow: '0 0 90px rgba(232,195,74,0.35)' } : undefined}
>
{step.title ?? ''}
</motion.h1>
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: 0.8 }}
>
<SignatureRule />
</motion.div>
</div>
)
}
function ResultsSplash() {
return (
<div className="flex h-full flex-col items-center justify-center gap-8 px-16 text-center">
<motion.p
animate={{ opacity: [0.4, 1, 0.4] }}
transition={{ repeat: Infinity, duration: 2.4 }}
className="text-lg font-semibold uppercase tracking-[0.5em] text-[#de0f1e]"
>
The moment has come
</motion.p>
<h1 className="text-[clamp(4rem,10vw,9rem)] font-extrabold tracking-tight">Results</h1>
<SignatureRule />
</div>
)
}
// ─── Page ────────────────────────────────────────────────────────────────────
export default function CeremonyPage({
params: paramsPromise,
}: {
params: Promise<{ roundId: string }>
}) {
const params = use(paramsPromise)
const { data: state } = trpc.liveVoting.getCeremonyState.useQuery(
{ roundId: params.roundId },
{ refetchInterval: 2000 }
)
const voteUrl =
typeof window !== 'undefined'
? `${window.location.origin}/vote/competition/${params.roundId}`
: ''
if (!state) {
return (
<OceanField>
<div className="flex h-full items-center justify-center" />
</OceanField>
)
}
// Display precedence: override → reveal → audience window → phase → welcome
const reveal = state.reveal
const revealStep =
reveal && (reveal.status === 'REVEALING' || reveal.status === 'DONE')
? ((reveal.steps[reveal.currentStepIndex] ?? null) as RevealStep | null)
: null
let slideKey: string
let slide: React.ReactNode
let statusLabel: string | null = null
if (state.overrideSlide) {
slideKey = `override-${state.overrideSlide}`
slide = <StaticSlide kind={state.overrideSlide} programName={state.programName} />
} else if (reveal && reveal.status === 'ARMED') {
slideKey = 'reveal-armed'
slide = <ResultsSplash />
statusLabel = 'Results'
} else if (revealStep) {
slideKey = `reveal-${reveal!.currentStepIndex}`
slide = <RevealSlide step={revealStep} />
statusLabel = 'Results'
} else if (state.audience.open) {
slideKey = `audience-${state.audience.windowKey}`
slide = (
<AudienceVoteSlide
windowKey={state.audience.windowKey}
closesAt={state.audience.closesAt}
voteCount={state.audience.voteCount}
voteUrl={voteUrl}
/>
)
statusLabel = 'Live'
} else if (state.phase && state.activeProject) {
slideKey = `phase-${state.phase.projectPhase}-${state.activeProject.title}`
slide = <PhaseSlide state={state} />
statusLabel = 'Live'
} else {
slideKey = 'welcome'
slide = <StaticSlide kind="welcome" programName={state.programName} />
}
return (
<OceanField>
<StatusBar programName={state.programName} label={statusLabel} />
<AnimatePresence mode="wait">
<motion.div key={slideKey} className="absolute inset-0" {...slideIn}>
{slide}
</motion.div>
</AnimatePresence>
</OceanField>
)
}

View File

@@ -0,0 +1,327 @@
'use client'
import { Suspense, use, useEffect, useState } from 'react'
import { trpc } from '@/lib/trpc/client'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
import { Skeleton } from '@/components/ui/skeleton'
import { Textarea } from '@/components/ui/textarea'
import { Badge } from '@/components/ui/badge'
import { Label } from '@/components/ui/label'
import { AlertCircle, CheckCircle2, Loader2, Salad, UtensilsCrossed } from 'lucide-react'
const ALLERGENS = [
'GLUTEN', 'CRUSTACEANS', 'EGGS', 'FISH', 'PEANUTS', 'SOYBEANS', 'MILK',
'TREE_NUTS', 'CELERY', 'MUSTARD', 'SESAME', 'SULPHITES', 'LUPIN', 'MOLLUSCS',
] as const
type Allergen = (typeof ALLERGENS)[number]
interface PageProps {
params: Promise<{ token: string }>
}
function formatTag(t: string): string {
return t.replace('_', ' ').toLowerCase()
}
function formatWhen(d: Date): string {
return new Intl.DateTimeFormat(undefined, {
dateStyle: 'long',
timeStyle: 'short',
}).format(d)
}
function CountdownLabel({ deadline }: { deadline: Date }) {
const [now, setNow] = useState<number>(Date.now())
useEffect(() => {
const id = setInterval(() => setNow(Date.now()), 1000)
return () => clearInterval(id)
}, [])
const ms = deadline.getTime() - now
if (ms <= 0) return <span className="text-destructive font-medium">closed</span>
const totalSec = Math.floor(ms / 1000)
const hours = Math.floor(totalSec / 3600)
const minutes = Math.floor((totalSec % 3600) / 60)
const seconds = totalSec % 60
if (hours >= 24) {
const days = Math.floor(hours / 24)
return (
<span className="font-medium tabular-nums">
{days}d {hours % 24}h remaining
</span>
)
}
return (
<span className="font-medium tabular-nums">
{hours.toString().padStart(2, '0')}:{minutes.toString().padStart(2, '0')}:
{seconds.toString().padStart(2, '0')} remaining
</span>
)
}
function FriendlyError({ title, message }: { title: string; message: string }) {
return (
<Card className="mx-auto max-w-xl">
<CardHeader>
<div className="flex items-center gap-2">
<AlertCircle className="text-muted-foreground h-5 w-5" />
<CardTitle>{title}</CardTitle>
</div>
</CardHeader>
<CardContent>
<p className="text-muted-foreground">{message}</p>
</CardContent>
</Card>
)
}
function DishPickContent({ token }: { token: string }) {
const { data, isLoading, error } = trpc.lunch.getExternalByToken.useQuery(
{ token },
{ retry: false },
)
const setPick = trpc.lunch.setExternalPick.useMutation()
const [dishId, setDishId] = useState<string>('')
const [allergens, setAllergens] = useState<Allergen[]>([])
const [allergenOther, setAllergenOther] = useState<string>('')
const [hydrated, setHydrated] = useState(false)
const [saved, setSaved] = useState(false)
const [submitError, setSubmitError] = useState<string | null>(null)
useEffect(() => {
if (!hydrated && data) {
setDishId(data.external.dishId ?? '')
setAllergens((data.external.allergens as Allergen[]) ?? [])
setAllergenOther(data.external.allergenOther ?? '')
setHydrated(true)
}
}, [data, hydrated])
if (isLoading) {
return (
<div className="mx-auto max-w-xl space-y-4">
<Skeleton className="h-8 w-2/3" />
<Skeleton className="h-32 w-full" />
<Skeleton className="h-48 w-full" />
</div>
)
}
if (error) {
const msg = error.message ?? ''
if (/expired/i.test(msg)) {
return (
<FriendlyError
title="This link has expired"
message="Please contact us at info@monaco-opc.com and we'll sort out your lunch."
/>
)
}
if (/signature|malformed|parseable/i.test(msg)) {
return (
<FriendlyError
title="This link is not valid"
message="Please check your email or contact us at info@monaco-opc.com."
/>
)
}
return (
<FriendlyError
title="Something went wrong"
message={msg || 'Please try again or contact us at info@monaco-opc.com.'}
/>
)
}
if (!data) {
return (
<FriendlyError
title="Not found"
message="Please check your email link or contact us at info@monaco-opc.com."
/>
)
}
const deadline = data.changeDeadline ? new Date(data.changeDeadline) : null
const deadlinePassed = deadline ? new Date() > deadline : false
const eventAt = data.event.eventAt ? new Date(data.event.eventAt) : null
const handleSave = async () => {
setSubmitError(null)
try {
await setPick.mutateAsync({
token,
dishId: dishId || null,
allergens,
allergenOther: allergenOther.trim() || null,
})
setSaved(true)
} catch (err) {
setSubmitError(err instanceof Error ? err.message : 'Failed to save')
}
}
const eventCard = (
<Card className="border-primary/40 bg-primary/5">
<CardHeader>
<div className="flex items-center gap-2">
<UtensilsCrossed className="text-primary h-5 w-5" />
<CardTitle>
{data.event.venue ? `Lunch at ${data.event.venue}` : 'Lunch'}
</CardTitle>
</div>
</CardHeader>
<CardContent className="space-y-1 text-sm">
<p>
Hi <strong>{data.external.name}</strong>, please choose your dish below.
</p>
{eventAt && (
<p className="text-muted-foreground">
<strong>When:</strong> {formatWhen(eventAt)}
</p>
)}
{data.event.notes && (
<p className="text-muted-foreground">{data.event.notes}</p>
)}
{deadline && !deadlinePassed && (
<p className="text-muted-foreground pt-1">
Choose by {formatWhen(deadline)} · <CountdownLabel deadline={deadline} />
</p>
)}
</CardContent>
</Card>
)
// Past the change deadline → read-only.
if (deadlinePassed) {
const chosen = data.dishes.find((d) => d.id === data.external.dishId)
return (
<div className="mx-auto max-w-xl space-y-6">
{eventCard}
<FriendlyError
title="Dish selection is now closed"
message={
chosen
? `Your choice is "${chosen.name}". To change it, please contact us at info@monaco-opc.com.`
: 'The deadline to choose a dish has passed. Please contact us at info@monaco-opc.com.'
}
/>
</div>
)
}
return (
<div className="mx-auto max-w-xl space-y-6">
{eventCard}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2 text-base">
<Salad className="h-4 w-4 text-emerald-600" /> Your dish
</CardTitle>
</CardHeader>
<CardContent className="space-y-6">
<RadioGroup value={dishId} onValueChange={setDishId} className="gap-2">
{data.dishes.map((d) => (
<label
key={d.id}
htmlFor={`dish-${d.id}`}
className="hover:bg-muted/50 flex cursor-pointer items-start gap-3 rounded-md border p-3"
>
<RadioGroupItem id={`dish-${d.id}`} value={d.id} className="mt-0.5" />
<div>
<div className="font-medium">{d.name}</div>
{d.dietaryTags.length > 0 && (
<div className="mt-1 flex flex-wrap gap-1">
{d.dietaryTags.map((t) => (
<Badge key={t} variant="secondary" className="text-xs">
{formatTag(t)}
</Badge>
))}
</div>
)}
</div>
</label>
))}
{data.dishes.length === 0 && (
<p className="text-muted-foreground text-sm">
No dishes have been published yet. Please check back later.
</p>
)}
</RadioGroup>
<div>
<Label className="text-sm">Allergens</Label>
<div className="mt-2 grid grid-cols-2 gap-2 sm:grid-cols-3">
{ALLERGENS.map((a) => (
<label key={a} className="flex items-center gap-2 text-sm">
<Checkbox
checked={allergens.includes(a)}
onCheckedChange={(v) =>
setAllergens(
v ? [...allergens, a] : allergens.filter((x) => x !== a),
)
}
/>
{formatTag(a)}
</label>
))}
</div>
</div>
<div>
<Label className="text-sm">Other allergens / dietary notes</Label>
<Textarea
value={allergenOther}
onChange={(e) => {
setAllergenOther(e.target.value)
setSaved(false)
}}
rows={2}
className="mt-1"
placeholder="e.g. severe nut allergy, no shellfish"
/>
</div>
</CardContent>
</Card>
{submitError && (
<div className="border-destructive bg-destructive/10 text-destructive rounded-md border p-3 text-sm">
{submitError}
</div>
)}
<div className="flex items-center justify-between gap-4">
{saved && !setPick.isPending ? (
<span className="flex items-center gap-2 text-sm text-emerald-600">
<CheckCircle2 className="h-4 w-4" /> Saved you can change it until the deadline.
</span>
) : (
<span />
)}
<Button size="lg" onClick={handleSave} disabled={setPick.isPending}>
{setPick.isPending ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> Saving
</>
) : (
<>
<CheckCircle2 className="mr-2 h-4 w-4" /> Save my choice
</>
)}
</Button>
</div>
</div>
)
}
export default function LunchPickPage({ params }: PageProps) {
const { token } = use(params)
return (
<Suspense fallback={<Skeleton className="h-64 w-full" />}>
<DishPickContent token={token} />
</Suspense>
)
}

View File

@@ -1,88 +1,274 @@
'use client';
'use client'
import { use, useEffect, useState } from 'react';
import { trpc } from '@/lib/trpc/client';
import { Card, CardContent } from '@/components/ui/card';
import { AudienceVoteCard } from '@/components/public/audience-vote-card';
import { toast } from 'sonner';
/**
* Audience voting page — reached by scanning the QR code on the big screen.
* Zero-instruction flow: scan → (auto token) → wait → tap your favorite →
* done. Votes can be changed until the window closes. Uses ONLY public
* procedures: attendees have no account.
*/
export default function AudienceVotePage({ params: paramsPromise }: { params: Promise<{ roundId: string }> }) {
const params = use(paramsPromise);
const utils = trpc.useUtils();
const [hasVoted, setHasVoted] = useState(false);
import { use, useEffect, useState } from 'react'
import { motion, AnimatePresence } from 'motion/react'
import { trpc } from '@/lib/trpc/client'
import { formatClock } from '@/lib/live-timer'
import { Check, Heart, Hourglass, Vote } from 'lucide-react'
import { toast } from 'sonner'
const { data: cursor } = trpc.live.getCursor.useQuery({ roundId: params.roundId });
const submitVoteMutation = trpc.liveVoting.castAudienceVote.useMutation({
onSuccess: () => {
setHasVoted(true);
// Store in localStorage to prevent duplicate votes
if (cursor?.activeProject?.id) {
localStorage.setItem(`voted-${params.roundId}-${cursor.activeProject.id}`, 'true');
const WINDOW_TITLE: Record<string, string> = {
'CATEGORY:BUSINESS_CONCEPT': 'Pick your favorite Business Concept',
'CATEGORY:STARTUP': 'Pick your favorite Startup',
OVERALL: 'Pick your favorite project of the night',
}
toast.success('Vote submitted! Thank you for participating.');
},
onError: (err) => {
toast.error(err.message);
}
});
// Check localStorage on mount
function useCountdown(closesAt: string | Date | null | undefined) {
const [, tick] = useState(0)
useEffect(() => {
if (cursor?.activeProject?.id) {
const voted = localStorage.getItem(`voted-${params.roundId}-${cursor.activeProject.id}`);
if (voted === 'true') {
setHasVoted(true);
const id = setInterval(() => tick((t) => t + 1), 1000)
return () => clearInterval(id)
}, [])
if (!closesAt) return null
return Math.max(0, Math.floor((new Date(closesAt).getTime() - Date.now()) / 1000))
}
export default function AudienceVotePage({
params: paramsPromise,
}: {
params: Promise<{ roundId: string }>
}) {
const params = use(paramsPromise)
const utils = trpc.useUtils()
const { data: context, isLoading: contextLoading } =
trpc.liveVoting.getAudienceContextByRound.useQuery({ roundId: params.roundId })
const sessionId = context?.sessionId ?? null
// ── Anonymous voter token, persisted per session in this browser ─────────
const [token, setToken] = useState<string | null>(null)
const register = trpc.liveVoting.registerAudienceVoter.useMutation({
onSuccess: (res) => {
if (sessionId) localStorage.setItem(`mopc-audience-${sessionId}`, res.token)
setToken(res.token)
},
})
useEffect(() => {
if (!sessionId || !context?.allowAudienceVotes) return
const stored = localStorage.getItem(`mopc-audience-${sessionId}`)
if (stored) {
setToken(stored)
} else if (!register.isPending && !token) {
register.mutate({ sessionId })
}
}, [cursor?.activeProject?.id, params.roundId]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [sessionId, context?.allowAudienceVotes])
const handleVote = () => {
if (!cursor?.activeProject?.id) return;
const { data: win } = trpc.liveVoting.getAudienceWindow.useQuery(
{ sessionId: sessionId ?? '', token: token ?? undefined },
{ enabled: !!sessionId, refetchInterval: 3000 }
)
submitVoteMutation.mutate({
projectId: cursor.activeProject.id,
sessionId: params.roundId,
score: 1,
token: `audience-${Date.now()}`
});
};
const [selected, setSelected] = useState<string | null>(null)
const cast = trpc.liveVoting.castFavoriteVote.useMutation({
onSuccess: () => {
utils.liveVoting.getAudienceWindow.invalidate()
setSelected(null)
toast.success('Vote recorded!')
},
onError: (err) => toast.error(err.message),
})
if (!cursor?.activeProject) {
const secondsLeft = useCountdown(win?.closesAt)
const open = !!win?.open && (secondsLeft === null || secondsLeft > 0)
const myVote = win?.myVoteProjectId ?? null
// Reset local selection when a new window opens
useEffect(() => {
setSelected(null)
}, [win?.windowKey])
if (contextLoading) {
return <CenteredState icon={Hourglass} title="Loading…" />
}
if (!context) {
return (
<div className="container mx-auto flex min-h-screen items-center justify-center p-4">
<Card className="w-full max-w-2xl">
<CardContent className="flex flex-col items-center justify-center py-12">
<p className="text-center text-lg text-muted-foreground">
No project is currently being presented
</p>
<p className="mt-2 text-center text-sm text-muted-foreground">
Please wait for the ceremony to begin
</p>
</CardContent>
</Card>
</div>
);
}
return (
<div className="container mx-auto flex min-h-screen items-center justify-center p-4">
<div className="w-full">
<div className="mb-8 text-center">
<h1 className="text-4xl font-bold text-[#053d57]">Monaco Ocean Protection Challenge</h1>
<p className="mt-2 text-lg text-muted-foreground">Live Audience Voting</p>
</div>
<AudienceVoteCard
project={cursor.activeProject}
onVote={handleVote}
hasVoted={hasVoted}
<CenteredState
icon={Vote}
title="No vote here yet"
subtitle="This voting link isn't active. Keep an eye on the big screen!"
/>
<p className="mt-6 text-center text-sm text-muted-foreground">
Live voting in progress
</p>
</div>
</div>
);
)
}
if (!context.allowAudienceVotes) {
return (
<CenteredState
icon={Vote}
title="Audience voting is not open"
subtitle="Voting will be enabled during the event."
/>
)
}
return (
<div className="mx-auto max-w-lg">
{/* Gala header */}
<div className="-mx-4 -mt-8 mb-6 bg-gradient-to-br from-[#021f2e] via-[#053d57] to-[#0a5a7c] px-6 py-8 text-center text-white sm:rounded-b-2xl">
<p className="text-[11px] font-semibold uppercase tracking-[0.35em] text-white/60">
{context.programName ?? 'Grand Finale'}
</p>
<h1 className="mt-2 text-2xl font-bold">Audience Vote</h1>
{open && secondsLeft !== null && (
<div className="mx-auto mt-3 inline-flex items-center gap-2 rounded-full bg-white/10 px-4 py-1.5 text-sm tabular-nums">
<span className="inline-block h-2 w-2 animate-pulse rounded-full bg-[#de0f1e]" />
closes in {formatClock(secondsLeft)}
</div>
)}
</div>
<AnimatePresence mode="wait">
{!open ? (
<motion.div
key="waiting"
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
className="py-10 text-center"
>
<motion.div
animate={{ y: [0, -6, 0] }}
transition={{ repeat: Infinity, duration: 2.4, ease: 'easeInOut' }}
className="mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-[#053d57]/8"
>
<Hourglass className="h-7 w-7 text-[#053d57]" />
</motion.div>
<h2 className="text-lg font-semibold text-[#053d57]">
Voting opens after the presentations
</h2>
<p className="mx-auto mt-2 max-w-xs text-sm text-muted-foreground">
Keep this page open the ballot appears here the moment voting starts.
</p>
</motion.div>
) : (
<motion.div
key={`open-${win?.windowKey}`}
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
className="space-y-3 pb-28"
>
<h2 className="text-center text-lg font-semibold text-[#053d57]">
{WINDOW_TITLE[win?.windowKey ?? ''] ?? 'Pick your favorite'}
</h2>
<p className="text-center text-xs text-muted-foreground">
One vote you can change it until voting closes
</p>
<div className="space-y-2.5 pt-2">
{(win?.projects ?? []).map((project) => {
const isPicked = (selected ?? myVote) === project.id
return (
<button
key={project.id}
onClick={() => setSelected(project.id)}
className={`w-full rounded-2xl border-2 p-4 text-left transition-all active:scale-[0.99] ${
isPicked
? 'border-[#de0f1e] bg-[#053d57] text-white shadow-lg'
: 'border-border bg-card hover:border-[#557f8c]'
}`}
>
<div className="flex items-center gap-3">
<div
className={`flex h-9 w-9 shrink-0 items-center justify-center rounded-full ${
isPicked ? 'bg-[#de0f1e]' : 'bg-[#053d57]/8'
}`}
>
{isPicked ? (
<Check className="h-5 w-5 text-white" />
) : (
<Heart className="h-4 w-4 text-[#557f8c]" />
)}
</div>
<div className="min-w-0">
<p className="truncate font-semibold">
{project.teamName ?? project.title}
</p>
{project.teamName && (
<p
className={`truncate text-xs ${
isPicked ? 'text-white/70' : 'text-muted-foreground'
}`}
>
{project.title}
</p>
)}
</div>
</div>
</button>
)
})}
</div>
{/* Pinned confirm bar */}
<AnimatePresence>
{selected && selected !== myVote && (
<motion.div
initial={{ y: 80 }}
animate={{ y: 0 }}
exit={{ y: 80 }}
className="fixed inset-x-0 bottom-0 z-40 border-t bg-background/95 p-4 pb-[max(1rem,env(safe-area-inset-bottom))] backdrop-blur"
>
<div className="mx-auto max-w-lg">
<button
onClick={() =>
sessionId &&
token &&
cast.mutate({ sessionId, token, projectId: selected })
}
disabled={cast.isPending || !token}
className="w-full rounded-xl bg-[#de0f1e] py-3.5 font-semibold text-white shadow-lg transition-transform active:scale-[0.98] disabled:opacity-60"
>
{cast.isPending
? 'Submitting…'
: myVote
? 'Change my vote'
: 'Confirm my vote'}
</button>
</div>
</motion.div>
)}
</AnimatePresence>
{myVote && (!selected || selected === myVote) && (
<div className="pt-2 text-center">
<span className="inline-flex items-center gap-1.5 rounded-full bg-green-600/10 px-4 py-1.5 text-sm font-medium text-green-700">
<Check className="h-4 w-4" />
Vote recorded tap another to change it
</span>
</div>
)}
</motion.div>
)}
</AnimatePresence>
</div>
)
}
function CenteredState({
icon: Icon,
title,
subtitle,
}: {
icon: typeof Vote
title: string
subtitle?: string
}) {
return (
<div className="py-16 text-center">
<div className="mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-[#053d57]/8">
<Icon className="h-7 w-7 text-[#053d57]" />
</div>
<h2 className="text-lg font-semibold text-[#053d57]">{title}</h2>
{subtitle && (
<p className="mx-auto mt-2 max-w-xs text-sm text-muted-foreground">{subtitle}</p>
)}
</div>
)
}

View File

@@ -106,7 +106,6 @@ export default function ProfileSettingsPage() {
const handleSaveProfile = async () => {
try {
await updateProfile.mutateAsync({
email: email || undefined,
name: name || undefined,
bio,
phoneNumber: phoneNumber || null,
@@ -229,11 +228,13 @@ export default function ProfileSettingsPage() {
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
readOnly
disabled
placeholder="you@example.com"
/>
<p className="text-xs text-muted-foreground">
This will be used for login and all notification emails.
Used for login and notifications. Contact an administrator to
change your email address.
</p>
</div>

Some files were not shown because too many files have changed in this diff Show More