From d683e4d028384df08dc81b36626ba7138b214337 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Tue, 27 Feb 2024 19:33:18 -0500 Subject: [PATCH] update form ui closes #47 --- components/Alert.tsx | 2 +- components/JoinParty.tsx | 49 ++++++++++++++++++++++++++++-------- components/NameForm.tsx | 54 +++++++++++++++++++++++++++------------- 3 files changed, 77 insertions(+), 28 deletions(-) diff --git a/components/Alert.tsx b/components/Alert.tsx index a78fcac..02de003 100644 --- a/components/Alert.tsx +++ b/components/Alert.tsx @@ -47,7 +47,7 @@ export default function Alert({ children }: { children: ReactNode }) { ); } -function toSentence(children: ReactNode) { +export function toSentence(children: ReactNode) { if (!children) { return; } diff --git a/components/JoinParty.tsx b/components/JoinParty.tsx index 4a4bc66..36fae79 100644 --- a/components/JoinParty.tsx +++ b/components/JoinParty.tsx @@ -3,6 +3,7 @@ import { Controller, SubmitHandler, useForm } from "react-hook-form"; import { useSWRConfig } from "swr"; import { PartyJoinBody } from "@/lib/party"; +import { toSentence } from "./Alert"; export default function JoinParty() { const { mutate } = useSWRConfig(); @@ -31,24 +32,52 @@ export default function JoinParty() { }; return ( -
-
+ +
( - field.onChange(e.target.value.toUpperCase())} - className="input input-bordered" - placeholder="Party Code" - required - /> + )} />
-

{errors.code?.message}

+

+ {toSentence(errors.code?.message)} +

); } diff --git a/components/NameForm.tsx b/components/NameForm.tsx index c3a61d6..fb49eaf 100644 --- a/components/NameForm.tsx +++ b/components/NameForm.tsx @@ -3,6 +3,7 @@ import { Controller, SubmitHandler, useForm } from "react-hook-form"; import { useSWRConfig } from "swr"; import { UserBody } from "@/lib/user"; +import { toSentence } from "./Alert"; export default function NameForm() { const { mutate } = useSWRConfig(); @@ -31,23 +32,42 @@ export default function NameForm() { }; return ( -
-

Set Username

-

Please choose a username.

- ( - - )} - /> -

{errors.name?.message}

- + +

Choose Your Username

+
+ ( + + )} + /> + +
+

{toSentence(errors.name?.message)}

); }