From 7089515e47fb6f7e9aa3db4bbbac2d3300ff0048 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 11 Aug 2024 15:32:47 +0900 Subject: feat(frontend): improve error handling of login form --- frontend/app/routes/_index.tsx | 25 ++++--- frontend/app/routes/login.tsx | 150 +++++++++++++++++++++++++++-------------- 2 files changed, 114 insertions(+), 61 deletions(-) (limited to 'frontend/app/routes') diff --git a/frontend/app/routes/_index.tsx b/frontend/app/routes/_index.tsx index ec87e86..9f9c2bb 100644 --- a/frontend/app/routes/_index.tsx +++ b/frontend/app/routes/_index.tsx @@ -2,6 +2,7 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { Link } from "@remix-run/react"; import "@fortawesome/fontawesome-svg-core/styles.css"; import { ensureUserNotLoggedIn } from "../.server/auth"; +import BorderedContainer from "../components/BorderedContainer"; export const meta: MetaFunction = () => [ { title: "iOSDC Japan 2024 Albatross.swift" }, @@ -23,19 +24,21 @@ export default function Index() {
iOSDC Japan 2024
-
- Swift - Code Battle -
+
Swift Code Battle
-

- Swift コードバトルは指示された動作をする Swift - コードをより短く書けた方が勝ち、という 1 対 1 - の対戦コンテンツです。8/22(木)day0 前夜祭では 8/12 - に実施された予選を勝ち抜いたプレイヤーによるトーナメント形式での Swift - コードバトルを実施します。ここでは短いコードが正義です!可読性も保守性も放り投げた、イベントならではのコードをお楽しみください! -

+
+ +

+ Swift コードバトルは指示された動作をする Swift + コードをより短く書けた方が勝ち、という 1 対 1 + の対戦コンテンツです。8/22(木)day0 前夜祭では 8/12 + に実施された予選を勝ち抜いたプレイヤーによるトーナメント形式での + Swift + コードバトルを実施します。ここでは短いコードが正義です!可読性も保守性も放り投げた、イベントならではのコードをお楽しみください! +

+
+
[ { title: "Login | iOSDC Japan 2024 Albatross.swift" }, @@ -15,7 +18,42 @@ export async function loader({ request }: LoaderFunctionArgs) { } export async function action({ request }: ActionFunctionArgs) { - await login(request); + const formData = await request.clone().formData(); + const username = String(formData.get("username")); + const password = String(formData.get("password")); + if (username === "" || password === "") { + return json( + { + message: "ユーザー名またはパスワードが誤っています", + errors: { + username: + username === "" ? "ユーザー名を入力してください" : undefined, + password: + password === "" ? "パスワードを入力してください" : undefined, + }, + }, + { status: 400 }, + ); + } + + try { + await login(request); + } catch (error) { + if (error instanceof Error) { + return json( + { + message: error.message, + errors: { + username: undefined, + password: undefined, + }, + }, + { status: 400 }, + ); + } else { + throw error; + } + } return null; } @@ -24,56 +62,68 @@ export default function Login() { const searchParams = new URLSearchParams(location.search); const registrationToken = searchParams.get("registration_token"); + const loginErrors = useActionData(); + return (
-
-

Login

-
- - -
-
- - -
- - -
+
+ +
+

+ fortee アカウントでログイン +

+

+ fortee + のアカウントをお持ちでない場合は、イベントスタッフにお声がけください。 +

+ {loginErrors?.message && ( +

{loginErrors.message}

+ )} +
+ + + {loginErrors?.errors?.username && ( +

+ {loginErrors.errors.username} +

+ )} +
+
+ + + {loginErrors?.errors?.password && ( +

+ {loginErrors.errors.password} +

+ )} +
+ +
+ ログイン +
+
+
+
); } -- cgit v1.2.3-70-g09d2