From 93a7ae9c1e15ef9f05df155f8a5dcb5cffa9dcb8 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sat, 16 Apr 2022 10:52:40 +0300 Subject: [PATCH] Can unregister from tournament before start --- app/components/tournament/TeamRoster.tsx | 48 ++++++++++++++++--- .../$organization.$tournament/manage-team.tsx | 41 +++++++++------- app/styles/tournament.css | 2 + .../tournament-before-start.spec.ts | 17 +++++-- 4 files changed, 83 insertions(+), 25 deletions(-) diff --git a/app/components/tournament/TeamRoster.tsx b/app/components/tournament/TeamRoster.tsx index 006584a1c..ae3cb1444 100644 --- a/app/components/tournament/TeamRoster.tsx +++ b/app/components/tournament/TeamRoster.tsx @@ -1,11 +1,15 @@ -import { Form, useTransition } from "@remix-run/react"; +import { Form, useMatches, useTransition } from "@remix-run/react"; +import { tournamentHasNotStarted } from "~/core/tournament/validators"; import { useUser } from "~/hooks/common"; +import { FindTournamentByNameForUrlI } from "~/services/tournament"; import { Avatar } from "../Avatar"; import { Button } from "../Button"; +import { SubmitButton } from "../SubmitButton"; export function TeamRoster({ team, - deleteMode: deleteMode, + showUnregister = false, + deleteMode = false, }: { team: { id: string; @@ -21,19 +25,51 @@ export function TeamRoster({ }[]; }; deleteMode?: boolean; + showUnregister?: boolean; }) { + const [, parentRoute] = useMatches(); + const tournament = parentRoute.data as FindTournamentByNameForUrlI; const user = useUser(); const showDeleteButtons = (userToDeleteId: string) => { - // TODO: - const tournamentHasStarted = false; + return ( + tournamentHasNotStarted(tournament) && + deleteMode && + userToDeleteId !== user?.id + ); + }; - return !tournamentHasStarted && deleteMode && userToDeleteId !== user?.id; + const showUnregisterButton = () => { + return tournamentHasNotStarted(tournament) && showUnregister; }; return (