"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { updatePassword } from "@/actions/settings"; import { Loader2 } from "lucide-react"; export function PasswordForm() { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(null); setSuccess(false); const formData = new FormData(e.currentTarget); const currentPassword = formData.get("currentPassword") as string; const newPassword = formData.get("newPassword") as string; const confirmPassword = formData.get("confirmPassword") as string; if (newPassword !== confirmPassword) { setError("New passwords do not match"); setLoading(false); return; } if (newPassword.length < 8) { setError("Password must be at least 8 characters"); setLoading(false); return; } try { await updatePassword({ currentPassword, newPassword }); setSuccess(true); (e.target as HTMLFormElement).reset(); setTimeout(() => setSuccess(false), 3000); } catch (err) { setError(err instanceof Error ? err.message : "Failed to update password"); } finally { setLoading(false); } } return (

Must be at least 8 characters

{error && (
{error}
)} {success && (
Password updated successfully!
)}
); }