"use client"; import { useState } from "react"; import { changePassword } from "./actions"; export function ChangePasswordForm() { const [success, setSuccess] = useState(false); const [error, setError] = useState(""); const [pending, setPending] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); const form = e.currentTarget; const fd = new FormData(form); const newPw = fd.get("newPassword") as string; const confirmPw = fd.get("confirmPassword") as string; if (newPw !== confirmPw) { setError("New passwords do not match"); return; } setPending(true); setSuccess(false); setError(""); const result = await changePassword(fd); setPending(false); if ("error" in result) { setError(result.error); } else { setSuccess(true); form.reset(); } } return (
{error && (

{error}

)} {success && (

Password changed successfully.

)}
); }