137 lines
4.1 KiB
TypeScript
137 lines
4.1 KiB
TypeScript
"use client";
|
|
|
|
import type React from "react";
|
|
|
|
import { useState } from "react";
|
|
import Link from "next/link";
|
|
import { useAuth } from "@/contexts/auth-context";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from "@/components/ui/card";
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import { AlertCircle } from "lucide-react";
|
|
|
|
export default function RegisterPage() {
|
|
const { register, isLoading } = useAuth();
|
|
const [email, setEmail] = useState("");
|
|
const [name, setName] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [confirmPassword, setConfirmPassword] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
setError("");
|
|
|
|
if (!email || !name || !password || !confirmPassword) {
|
|
setError("All fields are required");
|
|
return;
|
|
}
|
|
|
|
if (password !== confirmPassword) {
|
|
setError("Passwords do not match");
|
|
return;
|
|
}
|
|
|
|
console.log(email);
|
|
|
|
await register(email, password, name);
|
|
};
|
|
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-background px-4">
|
|
<Card className="w-full max-w-md">
|
|
<CardHeader className="space-y-2">
|
|
<CardTitle className="text-2xl">Create Account</CardTitle>
|
|
<CardDescription>
|
|
Join MangaMochi to track your favorite manga
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
{error && (
|
|
<Alert variant="destructive">
|
|
<AlertCircle className="h-4 w-4" />
|
|
<AlertDescription>{error}</AlertDescription>
|
|
</Alert>
|
|
)}
|
|
|
|
<div className="space-y-2">
|
|
<label htmlFor="email" className="text-sm font-medium">
|
|
Email
|
|
</label>
|
|
<Input
|
|
id="email"
|
|
type="email"
|
|
placeholder="you@example.com"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
disabled={isLoading}
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<label htmlFor="name" className="text-sm font-medium">
|
|
Name
|
|
</label>
|
|
<Input
|
|
id="name"
|
|
type="text"
|
|
placeholder="Your name"
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value)}
|
|
disabled={isLoading}
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<label htmlFor="password" className="text-sm font-medium">
|
|
Password
|
|
</label>
|
|
<Input
|
|
id="password"
|
|
type="password"
|
|
placeholder="At least 6 characters"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
disabled={isLoading}
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<label htmlFor="confirmPassword" className="text-sm font-medium">
|
|
Confirm Password
|
|
</label>
|
|
<Input
|
|
id="confirmPassword"
|
|
type="password"
|
|
placeholder="Confirm your password"
|
|
value={confirmPassword}
|
|
onChange={(e) => setConfirmPassword(e.target.value)}
|
|
disabled={isLoading}
|
|
/>
|
|
</div>
|
|
|
|
<Button type="submit" className="w-full" disabled={isLoading}>
|
|
{isLoading ? "Creating account..." : "Create Account"}
|
|
</Button>
|
|
|
|
<p className="text-center text-sm text-muted-foreground">
|
|
Already have an account?{" "}
|
|
<Link href="/login" className="text-primary hover:underline">
|
|
Sign in
|
|
</Link>
|
|
</p>
|
|
</form>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|