From cf9265c127fe9a97b34a833f9104867cab544b1b Mon Sep 17 00:00:00 2001 From: Chneemann Date: Tue, 13 Oct 2026 04:48:30 +0200 Subject: [PATCH] feat(auth): enable submit buttons only when form fields are complete --- app/(auth)/login/page.tsx | 49 ++++++++++++++++++------------ app/(auth)/register/page.tsx | 59 +++++++++++++++++++++++++++--------- 2 files changed, 73 insertions(+), 35 deletions(-) diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index 00a3491..b1b8aa2 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -1,6 +1,6 @@ /** * @file app/(auth)/login/page.tsx - * @description Client component providing a user login interface utilizing the auth service and ActionButton. + * @description Client component providing a user login interface utilizing the auth service, ActionButton, and form completion tracking. */ "use client"; @@ -14,7 +14,7 @@ import { Loader2, UserCheck, KeyRound } from "lucide-react"; /** * Renders the login page containing the authentication form, error handling, - * and navigation links for user sign-in. + * input completion checks, and navigation links for user sign-in. * * @returns {JSX.Element} The rendered login page component. */ @@ -25,13 +25,24 @@ export default function LoginPage() { "credentials" | "guest" | null >(null); + // Controlled form state tracking for input completion validation + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + + const isFormValid = email.trim() !== "" && password.trim() !== ""; + /** - * Clears active error state when user modifies input fields. + * Clears active error state and updates local state values when user modifies input fields. + * + * @param {React.ChangeEvent} e - The input change event. */ - const handleInputChange = () => { + const handleInputChange = (e: React.ChangeEvent) => { if (error) { setError(null); } + const { name, value } = e.target; + if (name === "email") setEmail(value); + if (name === "password") setPassword(value); }; /** @@ -39,19 +50,19 @@ export default function LoginPage() { * Redirects to the summary page upon success or sets an error message on failure. * * @async - * @param {string} email - The email address for login. - * @param {string} password - The account password. + * @param {string} emailAddress - The email address for login. + * @param {string} pass - The account password. * @param {"credentials" | "guest"} type - The authentication trigger source type. */ const handleSignIn = async ( - email: string, - password: string, + emailAddress: string, + pass: string, type: "credentials" | "guest", ) => { setError(null); setLoadingType(type); - const result = await loginUser(email, password); + const result = await loginUser(emailAddress, pass); if (result.error) { setError(result.error); @@ -65,13 +76,11 @@ export default function LoginPage() { * Handles traditional credential-based form submissions. * * @async - * @param {React.SubmitEvent} e - The form submission event. + * @param {React.FormEvent} e - The form submission event. */ - const handleSubmit = async (e: React.SubmitEvent) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - const formData = new FormData(e.currentTarget); - const email = formData.get("email") as string; - const password = formData.get("password") as string; + if (!isFormValid) return; await handleSignIn(email, password, "credentials"); }; @@ -134,11 +143,7 @@ export default function LoginPage() { )} -
+
)} - +