diff --git a/app/features/tournament/actions/to.$id.register.server.ts b/app/features/tournament/actions/to.$id.register.server.ts index 07c0c7eb8..527159089 100644 --- a/app/features/tournament/actions/to.$id.register.server.ts +++ b/app/features/tournament/actions/to.$id.register.server.ts @@ -183,6 +183,10 @@ export const action: ActionFunction = async ({ request, params }) => { teamMemberOf.checkIns.length === 0, "You cannot leave after checking in", ); + errorToastIfFalsy( + tournament.registrationOpen, + "Registration has closed, contact the TO to leave the team", + ); await TournamentTeamRepository.leave({ teamId: teamMemberOf.id, diff --git a/app/features/tournament/routes/to.$id.register.tsx b/app/features/tournament/routes/to.$id.register.tsx index 1db01a842..7b772412d 100644 --- a/app/features/tournament/routes/to.$id.register.tsx +++ b/app/features/tournament/routes/to.$id.register.tsx @@ -259,21 +259,7 @@ function TournamentRegisterInfoTabs() { {isRegularMemberOfATeam ? (
{t("tournament:pre.inATeam")} - {teamMemberOf && teamMemberOf.checkIns.length === 0 ? ( - - - Leave the team - - - ) : null} +
) : showAddIGNAlert ? (
@@ -309,6 +295,49 @@ function TournamentRegisterInfoTabs() { ); } +function LeaveTeamControl() { + const user = useUser(); + const tournament = useTournament(); + + const teamMemberOf = tournament.teamMemberOfByUser(user); + if (!teamMemberOf) return null; + + const checkedIn = teamMemberOf.checkIns.length > 0; + const cannotLeave = checkedIn || !tournament.registrationOpen; + + if (cannotLeave) { + return ( + + Leave the team + + } + > + {checkedIn + ? "Your team has checked in. Contact the TO to leave the team." + : "Registration has closed. Contact the TO to leave the team."} + + ); + } + + return ( + + + Leave the team + + + ); +} + function PleaseLogIn() { const { t } = useTranslation(["tournament"]);