"use client" import { useState } from "react" import { Button } from "@/cosmic/elements/Button" import { Loader2 } from "lucide-react" import { useRouter } from "next/navigation" import { Input } from "@/cosmic/elements/Input" import { Label } from "@/cosmic/elements/Label" interface ResetPasswordFormProps { token: string onSubmit: (token: string, formData: FormData) => Promise } export default function ResetPasswordForm({ token, onSubmit, }: ResetPasswordFormProps) { const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState("") const router = useRouter() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError("") try { const formData = new FormData(e.currentTarget) const password = formData.get("password") as string const confirmPassword = formData.get("confirmPassword") as string if (password !== confirmPassword) { throw new Error("Passwords do not match") } const result = await onSubmit(token, formData) if (result.error) { throw new Error(result.error) } // Redirect to login with success message router.push( "/login?success=Password reset successful. Please login with your new password." ) } catch (err: any) { setError(err.message || "An error occurred") } finally { setIsLoading(false) } } return (

Reset Your Password

{error && (
{error}
)}

Password must be at least 8 characters long and contain both letters and numbers

) }