Fix season year bug; add leagues column and guarded delete to /admin/season - #133
Merged
Merged
Conversation
The /admin/season "Create Season for Current Year" button was creating a season for 2024 due to leftover hardcoded debug code. Restore the intended current-year computation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QcPeaeJKyjcgMCS5RDcERk
Show the number of leagues attached to each season (matched by year) and allow deleting a season, but only when it has no leagues attached. The server-side action enforces the guard; the Delete button is hidden for seasons with leagues. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QcPeaeJKyjcgMCS5RDcERk
Use a lightweight prisma count instead of fetching every league (with its teams and users) just to check for existence, and prevent deleting the active season, which would leave the app with no current season. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QcPeaeJKyjcgMCS5RDcERk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the season-creation year bug on
/admin/seasonand adds two admin conveniences: a leagues-attached count column and a guarded delete button.Changes
1. Fix "Create Season" always making a 2024 season
The
createSeasonaction had leftover debug code (new Date('2024-04-01')) with the real line commented out, so every new season came out as 2024 despite the button reading "Create Season for Current Year". Restorednew Date().getFullYear().2. "Leagues" column
Added a column showing how many leagues are attached to each season.
LeagueandSeasonaren't FK-related — they're linked by matchingyear— so counts come from a singlegroupBy(getLeagueCountsByYear) mapped toyear → count.3. Guarded Delete button
Added a
deleteSeasonaction + button (with a confirm dialog, matching the existingDraftSlotRowpattern). Deletion is only allowed for a season that is not active and has 0 leagues attached; the server action enforces both guards and the button is hidden otherwise.SeasonWeekrows cascade automatically; leagues are untouched.Review follow-ups (addressed)
prisma.league.count(getLeagueCountForYear) instead of fetching every league with its teams/users just to check existence.getCurrentSeason()returning null and break admin pages that depend on it.Verification
npx tsc --noEmitclean for the touched files.🤖 Generated with Claude Code
Generated by Claude Code