"use client" import { useState } from "react" import { useRouter } from "next/navigation" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { Eye, EyeOff, Loader2, CheckCircle } from "lucide-react" import Link from "next/link" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Alert, AlertDescription } from "@/components/ui/alert" import { registerSchema, type RegisterInput } from "@/lib/validation" export default function SignUpPage() { const [showPassword, setShowPassword] = useState(false) const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState("") const [success, setSuccess] = useState(false) const router = useRouter() const form = useForm({ resolver: zodResolver(registerSchema), defaultValues: { name: "", email: "", password: "", }, }) const onSubmit = async (data: RegisterInput) => { setIsLoading(true) setError("") setSuccess(false) try { const response = await fetch("/api/auth/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), }) const result = await response.json() if (!response.ok) { setError(result.error || "Registration failed") return } setSuccess(true) form.reset() // Redirect to login page after successful registration setTimeout(() => { router.push("/login") }, 2000) } catch (error) { setError("An unexpected error occurred") } finally { setIsLoading(false) } } if (success) { return (

Account Created!

Your account has been successfully created. You will be redirected to the sign in page.

) } return (
Create Account Enter your information to create a new account {error && ( {error} )}
( Full Name )} /> ( Email )} /> ( Password

Password must contain at least 8 characters with uppercase, lowercase, and a number.

)} />
Already have an account? Sign in

By creating an account, you agree to our{" "} {" "} and{" "}

) }