From a4d45e257785a0d4e15379a07c9ec326a05bbd26 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sat, 25 Dec 2021 23:01:29 +0200 Subject: [PATCH] Remove rest useFetchers --- app/components/icons/CheckIn.tsx | 13 ++++++++++ .../ActionSectionBeforeStartContent.tsx | 25 +++++++++++------- app/routes/to/$organization.$tournament.tsx | 26 ++++++++++++++++++- .../manage-roster.tsx | 5 +--- 4 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 app/components/icons/CheckIn.tsx diff --git a/app/components/icons/CheckIn.tsx b/app/components/icons/CheckIn.tsx new file mode 100644 index 000000000..b8b05bf3a --- /dev/null +++ b/app/components/icons/CheckIn.tsx @@ -0,0 +1,13 @@ +export function CheckInIcon({ className }: { className?: string }) { + return ( + + + + + ); +} diff --git a/app/components/tournament/ActionSectionBeforeStartContent.tsx b/app/components/tournament/ActionSectionBeforeStartContent.tsx index 967e568bb..00b96228a 100644 --- a/app/components/tournament/ActionSectionBeforeStartContent.tsx +++ b/app/components/tournament/ActionSectionBeforeStartContent.tsx @@ -1,16 +1,17 @@ // TODO: Warning: Text content did not match. Server: "57" Client: "56" import * as React from "react"; -import { useFetcher, useLoaderData } from "remix"; +import { useTransition, useLoaderData, Form } from "remix"; import { checkInClosesDate, TOURNAMENT_TEAM_ROSTER_MIN_SIZE, } from "~/constants"; +import { TournamentAction } from "~/routes/to/$organization.$tournament"; import type { FindTournamentByNameForUrlI } from "~/services/tournament"; import { Unpacked } from "~/utils"; import { Button } from "../Button"; import { AlertIcon } from "../icons/Alert"; -import { CheckmarkIcon } from "../icons/Checkmark"; +import { CheckInIcon } from "../icons/CheckIn"; import { ErrorIcon } from "../icons/Error"; import { SuccessIcon } from "../icons/Success"; import { ActionSectionWrapper } from "./ActionSectionWrapper"; @@ -20,7 +21,7 @@ export function ActionSectionBeforeStartContent({ }: { ownTeam: Unpacked; }) { - const fetcher = useFetcher(); + const transition = useTransition(); const tournament = useLoaderData(); const timeInMinutesBeforeCheckInCloses = () => { @@ -111,21 +112,25 @@ export function ActionSectionBeforeStartContent({ Check-in closes in less than a minute )} - + + - + ); } diff --git a/app/routes/to/$organization.$tournament.tsx b/app/routes/to/$organization.$tournament.tsx index fd4b72c00..09d84d884 100644 --- a/app/routes/to/$organization.$tournament.tsx +++ b/app/routes/to/$organization.$tournament.tsx @@ -3,6 +3,7 @@ import { LinksFunction, LoaderFunction, + ActionFunction, MetaFunction, NavLink, Outlet, @@ -15,10 +16,11 @@ import { InfoBanner } from "~/components/tournament/InfoBanner"; import { isTournamentAdmin } from "~/core/tournament/permissions"; import { tournamentHasStarted } from "~/core/tournament/utils"; import { + checkIn, findTournamentByNameForUrl, FindTournamentByNameForUrlI, } from "~/services/tournament"; -import { makeTitle } from "~/utils"; +import { makeTitle, requireUser } from "~/utils"; import type { MyCSSProperties } from "~/utils"; import { useUser } from "~/utils/hooks"; import tournamentStylesUrl from "../../styles/tournament.css"; @@ -27,6 +29,28 @@ export const links: LinksFunction = () => { return [{ rel: "stylesheet", href: tournamentStylesUrl }]; }; +export enum TournamentAction { + CHECK_IN = "CHECK_IN", +} + +export const action: ActionFunction = async ({ request, context }) => { + const data = Object.fromEntries(await request.formData()); + const user = requireUser(context); + + switch (data._action) { + case TournamentAction.CHECK_IN: { + invariant(typeof data.teamId === "string", "Invalid type for teamId"); + + await checkIn({ teamId: data.teamId, userId: user.id }); + break; + } + default: { + throw new Response("Bad Request", { status: 400 }); + } + } + return new Response(undefined, { status: 200 }); +}; + export const loader: LoaderFunction = ({ params }) => { invariant( typeof params.organization === "string", diff --git a/app/routes/to/$organization.$tournament/manage-roster.tsx b/app/routes/to/$organization.$tournament/manage-roster.tsx index 4fb7290d0..75aed19b7 100644 --- a/app/routes/to/$organization.$tournament/manage-roster.tsx +++ b/app/routes/to/$organization.$tournament/manage-roster.tsx @@ -85,10 +85,7 @@ export const action: ActionFunction = async ({ return new Response("Player deleted from team", { status: 200 }); } default: { - return new Response(undefined, { - status: 405, - headers: { Allow: "POST, DELETE" }, - }); + throw new Response("Bad Request", { status: 400 }); } } };