/** * @file app/(auth)/register/page.tsx * @description Client component providing a user registration interface with client-side validation, field completion checks, autocomplete, and ActionButton integration. */ "use client"; import Link from "next/link"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { registerUser } from "@/lib/services/auth.service"; import { ActionButton } from "@/app/components/ui/buttons/ActionButton"; import { Loader2, UserPlus } from "lucide-react"; import { JSX } from "react/jsx-runtime"; /** * Renders the registration page featuring a sign-up form, client-side validation, * input completion tracking, error feedback, and routing logic upon successful account creation. * * @returns {JSX.Element} The rendered registration page component. */ export default function RegisterPage(): JSX.Element { const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const router = useRouter(); // Controlled form state tracking for input completion validation const [firstName, setFirstName] = useState(""); const [lastName, setLastName] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const isFormValid = firstName.trim() !== "" && lastName.trim() !== "" && email.trim() !== "" && password.trim() !== "" && confirmPassword.trim() !== ""; /** * Clears active error state and updates corresponding input values on user modification. * * @param {React.ChangeEvent} e - The input change event. */ const handleInputChange = (e: React.ChangeEvent) => { if (error) { setError(null); } const { name, value } = e.target; if (name === "firstName") setFirstName(value); if (name === "lastName") setLastName(value); if (name === "email") setEmail(value); if (name === "password") setPassword(value); if (name === "confirmPassword") setConfirmPassword(value); }; /** * Handles user registration form submission, validates password equality, delegates registration * to the auth service, and navigates to the summary page upon success. * * @async * @param {React.FormEvent} event - The form submission event. * @returns {Promise} Resolves when registration handling completes. */ async function handleSubmit( event: React.FormEvent, ): Promise { event.preventDefault(); if (!isFormValid) return; setError(null); const formData = new FormData(event.currentTarget); const payload = Object.fromEntries(formData.entries()); // Client-side password matching check if (payload.password !== payload.confirmPassword) { setError("Passwords do not match."); return; } setLoading(true); const result = await registerUser(payload); if (result.error) { setError(result.error); setLoading(false); } else { router.push("/summary"); } } return (
{/* Background Ambient Glow */} ); }