Prevent leaving tournament team after reg has closed

Closes #2850
This commit is contained in:
Kalle
2026-05-24 16:31:21 +03:00
parent 0a7112d831
commit 67a162afd6
2 changed files with 48 additions and 15 deletions

View File

@@ -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,

View File

@@ -259,21 +259,7 @@ function TournamentRegisterInfoTabs() {
{isRegularMemberOfATeam ? (
<div className="stack md items-center">
<Alert>{t("tournament:pre.inATeam")}</Alert>
{teamMemberOf && teamMemberOf.checkIns.length === 0 ? (
<FormWithConfirm
dialogHeading={`Leave "${tournament.teamMemberOfByUser(user)?.name}"?`}
fields={[["_action", "LEAVE_TEAM"]]}
submitButtonText="Leave"
>
<SendouButton
className="small-text"
variant="minimal-destructive"
type="submit"
>
Leave the team
</SendouButton>
</FormWithConfirm>
) : null}
<LeaveTeamControl />
</div>
) : showAddIGNAlert ? (
<div>
@@ -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 (
<SendouPopover
trigger={
<SendouButton className="small-text" variant="minimal-destructive">
Leave the team
</SendouButton>
}
>
{checkedIn
? "Your team has checked in. Contact the TO to leave the team."
: "Registration has closed. Contact the TO to leave the team."}
</SendouPopover>
);
}
return (
<FormWithConfirm
dialogHeading={`Leave "${teamMemberOf.name}"?`}
fields={[["_action", "LEAVE_TEAM"]]}
submitButtonText="Leave"
>
<SendouButton
className="small-text"
variant="minimal-destructive"
type="submit"
>
Leave the team
</SendouButton>
</FormWithConfirm>
);
}
function PleaseLogIn() {
const { t } = useTranslation(["tournament"]);