From fd26d70e7edb20aa142a68d6e14464fcc10293be Mon Sep 17 00:00:00 2001
From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com>
Date: Sat, 25 Dec 2021 22:33:15 +0200
Subject: [PATCH] Check-in/check-out to local action function
---
README.md | 1 -
.../api/tournamentTeam/$teamId/check-in.ts | 12 ----
.../api/tournamentTeam/$teamId/check-out.ts | 12 ----
.../to/$organization.$tournament/seeds.tsx | 55 +++++++++++++------
4 files changed, 38 insertions(+), 42 deletions(-)
delete mode 100644 app/routes/api/tournamentTeam/$teamId/check-in.ts
delete mode 100644 app/routes/api/tournamentTeam/$teamId/check-out.ts
diff --git a/README.md b/README.md
index c8cadbb57..b2d804982 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,6 @@ sendou.ink/
│ ├── hooks/ -- React hooks
│ ├── models/ -- Calls to database
│ ├── routes/ -- Routes see: https://remix.run/docs/en/v1/guides/routing
-│ │ └── api/ -- API routes that don't belong to any one page / situations when one route has many APIs
│ ├── services/ -- Functions that loaders etc. call that typically work with multiple models
│ ├── styles/ -- All .css files of the project for styling
│ ├── utils/ -- Random helper functions used in many places
diff --git a/app/routes/api/tournamentTeam/$teamId/check-in.ts b/app/routes/api/tournamentTeam/$teamId/check-in.ts
deleted file mode 100644
index 3bdade21c..000000000
--- a/app/routes/api/tournamentTeam/$teamId/check-in.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import type { ActionFunction } from "remix";
-import { checkIn } from "~/services/tournament";
-import { requireUser } from "~/utils";
-
-export const action: ActionFunction = async ({ params, context }) => {
- const teamId = params.teamId!;
- const user = requireUser(context);
-
- await checkIn({ teamId, userId: user.id });
-
- return new Response(undefined, { status: 200 });
-};
diff --git a/app/routes/api/tournamentTeam/$teamId/check-out.ts b/app/routes/api/tournamentTeam/$teamId/check-out.ts
deleted file mode 100644
index b384112e8..000000000
--- a/app/routes/api/tournamentTeam/$teamId/check-out.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import type { ActionFunction } from "remix";
-import { checkOut } from "~/services/tournament";
-import { requireUser } from "~/utils";
-
-export const action: ActionFunction = async ({ params, context }) => {
- const teamId = params.teamId!;
- const user = requireUser(context);
-
- await checkOut({ teamId, userId: user.id });
-
- return new Response(undefined, { status: 200 });
-};
diff --git a/app/routes/to/$organization.$tournament/seeds.tsx b/app/routes/to/$organization.$tournament/seeds.tsx
index ea0d0154f..8fc317c48 100644
--- a/app/routes/to/$organization.$tournament/seeds.tsx
+++ b/app/routes/to/$organization.$tournament/seeds.tsx
@@ -19,7 +19,6 @@ import {
ActionFunction,
Form,
LinksFunction,
- useFetcher,
useMatches,
useTransition,
} from "remix";
@@ -31,6 +30,8 @@ import { Draggable } from "~/components/Draggable";
import { TOURNAMENT_TEAM_ROSTER_MIN_SIZE } from "~/constants";
import { checkInHasStarted } from "~/core/tournament/utils";
import {
+ checkIn,
+ checkOut,
FindTournamentByNameForUrlI,
updateSeeds,
} from "~/services/tournament";
@@ -40,11 +41,16 @@ import { useTimeoutState } from "~/utils/hooks";
enum Action {
UPDATE_SEEDS = "UPDATE_SEEDS",
+ CHECK_IN = "CHECK_IN",
+ CHECK_OUT = "CHECK_OUT",
}
export const action: ActionFunction = async ({ context, request }) => {
const data = Object.fromEntries(await request.formData());
invariant(typeof data._action === "string", "Invalid type for _action");
+
+ const user = requireUser(context);
+
switch (data._action) {
case Action.UPDATE_SEEDS: {
invariant(typeof data.seeds === "string", "Invalid type for seeds");
@@ -54,17 +60,33 @@ export const action: ActionFunction = async ({ context, request }) => {
);
const newSeeds = JSON.parse(data.seeds);
- const user = requireUser(context);
-
await updateSeeds({
tournamentId: data.tournamentId,
userId: user.id,
newSeeds,
});
- return new Response(undefined, { status: 200 });
+ break;
+ }
+ // TODO: broken
+ case Action.CHECK_IN: {
+ invariant(typeof data.teamId === "string", "Invalid type for seeds");
+
+ await checkIn({ teamId: data.teamId, userId: user.id });
+ break;
+ }
+ case Action.CHECK_OUT: {
+ invariant(typeof data.teamId === "string", "Invalid type for seeds");
+
+ await checkOut({ teamId: data.teamId, userId: user.id });
+ break;
+ }
+ default: {
+ throw new Response("Bad Request", { status: 400 });
}
}
+
+ return new Response(undefined, { status: 200 });
};
export const links: LinksFunction = () => {
@@ -204,7 +226,6 @@ function SeedAlert({
hidden: !teamOrderChanged,
})}
type="submit"
- loadingText="Saving..."
loading={transition.state !== "idle"}
>
Save seeds
@@ -268,44 +289,44 @@ function RowContents({
}
function CheckOutButton({ teamId }: { teamId: string }) {
- const fetcher = useFetcher();
+ const transition = useTransition();
return (
-
+
+
-
+
);
}
function CheckInButton({ teamId }: { teamId: string }) {
- const fetcher = useFetcher();
+ const transition = useTransition();
return (
-
+
+
-
+
);
}