From 075e6dd9eaf4bc265affa6ecaabbe1b76c21a227 Mon Sep 17 00:00:00 2001 From: schererleander Date: Wed, 2 Jul 2025 22:18:28 +0200 Subject: feat: add app pages and layout --- src/app/signup/page.tsx | 208 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 src/app/signup/page.tsx (limited to 'src/app/signup/page.tsx') diff --git a/src/app/signup/page.tsx b/src/app/signup/page.tsx new file mode 100644 index 0000000..ab5b4d4 --- /dev/null +++ b/src/app/signup/page.tsx @@ -0,0 +1,208 @@ +"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{" "} + +

+
+
+
+
+ ) +} \ No newline at end of file -- cgit v1.3.1