"use client" import { useState } from "react" export default function ChangePasswordForm() { const [currentPassword, setCurrentPassword] = useState("") const [newPassword, setNewPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") const [error, setError] = useState("") const [success, setSuccess] = useState("") const [loading, setLoading] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError("") setSuccess("") if (newPassword !== confirmPassword) { setError("New passwords do not match") return } if (newPassword.length < 6) { setError("Password must be at least 6 characters") return } setLoading(true) try { const response = await fetch("/api/profile/change-password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ currentPassword, newPassword, }), }) const data = await response.json() if (!response.ok) { setError(data.error || "Failed to change password") } else { setSuccess("Password changed successfully!") setCurrentPassword("") setNewPassword("") setConfirmPassword("") setTimeout(() => { setSuccess("") }, 3000) } } catch { setError("An error occurred. Please try again.") } finally { setLoading(false) } } return (
) }