From 4ce71d05d28761c29d5d29ba48db26cebf0f03c5 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Tue, 21 Oct 2025 22:27:14 -0700 Subject: [PATCH] feat: prevent users from owning multiple teams in same league --- app/routes/leagues/$leagueId.settings.tsx | 27 +++++++++++++++---- app/routes/leagues/__tests__/README.md | 5 ++-- .../leagues/__tests__/team-management.test.ts | 20 ++++++++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/app/routes/leagues/$leagueId.settings.tsx b/app/routes/leagues/$leagueId.settings.tsx index 4d06100..37e1eaf 100644 --- a/app/routes/leagues/$leagueId.settings.tsx +++ b/app/routes/leagues/$leagueId.settings.tsx @@ -258,6 +258,14 @@ export async function action(args: Route.ActionArgs) { return { error: "Only admins can assign team owners" }; } + // Check if user is already assigned to a team in this season + const teams = await findTeamsBySeasonId(season.id); + const userAlreadyHasTeam = teams.some(team => team.ownerId === userClerkId); + + if (userAlreadyHasTeam) { + return { error: "This user is already assigned to a team in this league" }; + } + try { await assignTeamOwner(teamId, userClerkId); return { success: true, message: "Owner assigned successfully" }; @@ -934,11 +942,20 @@ export default function LeagueSettings({ loaderData, actionData }: Route.Compone - {allUsers.map((user: any) => ( - - {user.displayName || user.username || user.email} - - ))} + {allUsers.map((user: any) => { + // Check if user already owns a team in this league + const userOwnsTeam = teams.some((t: any) => t.ownerId === user.clerkId); + return ( + + {user.username || user.email} + {userOwnsTeam && " (already in league)"} + + ); + })}