import { useState } from "react"; import { useForm } from "react-hook-form"; import { Settings } from "lucide-react"; import { SettingsDialog } from "@/components/settings-dialog"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { Link } from "react-router-dom"; import { useRegister } from "@/hooks/use-auth"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; import { ApiError } from "@/lib/api"; import { toast } from "sonner"; const registerSchema = z.object({ email: z.string().email("Invalid email address"), password: z.string().min(6, "Password must be at least 6 characters"), confirmPassword: z.string().min(6, "Password must be at least 6 characters"), }).refine((data) => data.password === data.confirmPassword, { message: "Passwords don't match", path: ["confirmPassword"], }); type RegisterFormValues = z.infer; export default function RegisterPage() { const { mutate: register, isPending } = useRegister(); const form = useForm({ resolver: zodResolver(registerSchema), defaultValues: { email: "", password: "", confirmPassword: "", }, }); const onSubmit = (data: RegisterFormValues) => { register({ email: data.email, password: data.password, }, { onError: (error: any) => { if (error instanceof ApiError) { toast.error(error.message); } else { toast.error("Failed to register"); } }, }); }; const [settingsOpen, setSettingsOpen] = useState(false); return (
Create an account Enter your email below to create your account
( Email )} /> ( Password )} /> ( Confirm Password )} />

Already have an account?{" "} Sign in

); }