Skip to content

Fix season year bug; add leagues column and guarded delete to /admin/season - #133

Merged
chrisparsons83 merged 3 commits into
mainfrom
claude/season-creation-year-bug-0g46lp
Jul 20, 2026
Merged

Fix season year bug; add leagues column and guarded delete to /admin/season#133
chrisparsons83 merged 3 commits into
mainfrom
claude/season-creation-year-bug-0g46lp

Conversation

@chrisparsons83

Copy link
Copy Markdown
Owner

Summary

Fixes the season-creation year bug on /admin/season and 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 createSeason action 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". Restored new Date().getFullYear().

2. "Leagues" column
Added a column showing how many leagues are attached to each season. League and Season aren't FK-related — they're linked by matching year — so counts come from a single groupBy (getLeagueCountsByYear) mapped to year → count.

3. Guarded Delete button
Added a deleteSeason action + button (with a confirm dialog, matching the existing DraftSlotRow pattern). 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. SeasonWeek rows cascade automatically; leagues are untouched.

Review follow-ups (addressed)

  • Delete guard uses a lightweight prisma.league.count (getLeagueCountForYear) instead of fetching every league with its teams/users just to check existence.
  • Blocked deleting the active season, which would otherwise leave getCurrentSeason() returning null and break admin pages that depend on it.

Verification

  • npx tsc --noEmit clean for the touched files.
  • Manual: creating a season now yields the current year (2026); the Leagues column reflects per-year league counts; delete works for empty non-active seasons and is rejected (button hidden + server guard) for active seasons or seasons with leagues.

🤖 Generated with Claude Code


Generated by Claude Code

claude added 3 commits July 20, 2026 18:21
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
@chrisparsons83
chrisparsons83 merged commit 7baabc4 into main Jul 20, 2026
7 checks passed
@chrisparsons83
chrisparsons83 deleted the claude/season-creation-year-bug-0g46lp branch July 20, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants