diff --git a/app/components/MyForm.tsx b/app/components/MyForm.tsx new file mode 100644 index 000000000..39824a8c9 --- /dev/null +++ b/app/components/MyForm.tsx @@ -0,0 +1,27 @@ +import { Form, FormProps, useTransition } from "remix"; + +interface MyFormProps extends FormProps { + hiddenFields?: Record; +} + +/** + * Wrapper around Remix's Form that has default method of "post", + * creates elements for each key/value pair in hiddenFields + * and disables the form when it's submitting. + */ +export function MyForm(props: MyFormProps) { + const { hiddenFields, children, ...rest } = props; + + const transition = useTransition(); + return ( +
+
+ {hiddenFields && + Object.entries(hiddenFields).map(([key, value]) => ( + + ))} + {children} +
+
+ ); +} diff --git a/app/routes/to/$organization.$tournament/join-team.tsx b/app/routes/to/$organization.$tournament/join-team.tsx index 2d93ec1a5..656b1d276 100644 --- a/app/routes/to/$organization.$tournament/join-team.tsx +++ b/app/routes/to/$organization.$tournament/join-team.tsx @@ -1,22 +1,22 @@ +import type { ActionFunction, LinksFunction, LoaderFunction } from "remix"; import { json, - useLoaderData, redirect, - Form, - useNavigate, + useLoaderData, useMatches, + useNavigate, useTransition, } from "remix"; -import type { LoaderFunction, LinksFunction, ActionFunction } from "remix"; +import invariant from "tiny-invariant"; +import { Button } from "~/components/Button"; +import { MyForm } from "~/components/MyForm"; import { FindTournamentByNameForUrlI, findTournamentWithInviteCodes, joinTeam, } from "~/services/tournament"; import styles from "~/styles/tournament-join-team.css"; -import invariant from "tiny-invariant"; import { getUser, requireUser } from "~/utils"; -import { Button } from "~/components/Button"; export const links: LinksFunction = () => { return [{ rel: "stylesheet", href: styles }]; @@ -165,13 +165,12 @@ function Contents({ data }: { data: ResponseObject }) {
{data.inviterName} invited you to join {data.teamName} for this tournament. Accept invite? -
- - +
- +
); default: diff --git a/app/routes/to/$organization.$tournament/register.tsx b/app/routes/to/$organization.$tournament/register.tsx index e64869a4a..1e9f84d85 100644 --- a/app/routes/to/$organization.$tournament/register.tsx +++ b/app/routes/to/$organization.$tournament/register.tsx @@ -1,7 +1,6 @@ import { Prisma } from ".prisma/client"; import { ActionFunction, - Form, LinksFunction, redirect, useActionData, @@ -13,6 +12,7 @@ import { import invariant from "tiny-invariant"; import { Button } from "~/components/Button"; import ErrorMessage from "~/components/ErrorMessage"; +import { MyForm } from "~/components/MyForm"; import { createTournamentTeam, FindTournamentByNameForUrlI, @@ -119,47 +119,40 @@ export default function RegisterPage() {

Register now

-
-
- - - - -
+ + + + +
+ + {transition.state === "idle" && ( - {transition.state === "idle" && ( - - )} -
-
-
+ )} +
+
); diff --git a/app/styles/global.css b/app/styles/global.css index b5f205b39..ce1cbe375 100644 --- a/app/styles/global.css +++ b/app/styles/global.css @@ -155,7 +155,7 @@ label { } fieldset { - all: unset; + all: inherit; } select {