/** * @file app/(auth)/register/page.tsx * @description Client component rendering the registration page, handling form submissions, client-side validation, form completion checks, error handling, autocomplete, and navigation. */ "use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import Image from "next/image"; import { registerUser } from "@/lib/services/auth.service"; /** Renders the user registration interface, manages sign-up form state, and requires all fields to be filled before submission. */ export default function RegisterPage() { const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const router = useRouter(); const [username, setUsername] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const isFormValid = username.trim() !== "" && email.trim() !== "" && password.trim() !== "" && confirmPassword.trim() !== ""; /** Clears active error state when user modifies input fields. */ const handleInputChange = () => { if (error) { setError(null); } }; /** Handles user registration form submission, validates form data via auth service, and navigates to summary page on successful registration. */ async function handleSubmit(event: React.SubmitEvent) { event.preventDefault(); if (!isFormValid) return; setError(null); const formData = new FormData(event.currentTarget); const payload = Object.fromEntries(formData.entries()); // Client-side password matching validation 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("/"); } } return (
Waveform Logo

Create an Account

Get started with Waveform now.

{/* Error Message */} {error && (
{error}
)} {/* Form */}
{ setUsername(e.target.value); handleInputChange(); }} placeholder="username" maxLength={50} autoComplete="username" className="w-full bg-neutral-900 border border-neutral-800 rounded-lg px-3 py-2 text-foreground placeholder-neutral-500 outline-none focus:border-accent transition-colors text-sm" />
{ setEmail(e.target.value); handleInputChange(); }} placeholder="name@example.com" maxLength={255} autoComplete="email" className="w-full bg-neutral-900 border border-neutral-800 rounded-lg px-3 py-2 text-foreground placeholder-neutral-500 outline-none focus:border-accent transition-colors text-sm" />
{ setPassword(e.target.value); handleInputChange(); }} placeholder="•••••••••••••" maxLength={72} autoComplete="new-password" className="w-full bg-neutral-900 border border-neutral-800 rounded-lg px-3 py-2 text-foreground placeholder-neutral-500 outline-none focus:border-accent transition-colors text-sm" />
{ setConfirmPassword(e.target.value); handleInputChange(); }} placeholder="•••••••••••••" maxLength={72} autoComplete="new-password" className="w-full bg-neutral-900 border border-neutral-800 rounded-lg px-3 py-2 text-foreground placeholder-neutral-500 outline-none focus:border-accent transition-colors text-sm" />

Already have an account?{" "} Sign In

); }