"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 { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { updateUserPassword } from "@/lib/actions/admin"; export function ChangePasswordDialog({ userId, userLabel, open, onOpenChange, }: { userId: string; userLabel: string; open: boolean; onOpenChange: (open: boolean) => void; }) { const [password, setPassword] = useState(""); const [confirm, setConfirm] = useState(""); const [error, setError] = useState(); const [pending, setPending] = useState(false); function handleOpenChange(next: boolean) { if (next) { setPassword(""); setConfirm(""); setError(undefined); } onOpenChange(next); } async function handleSave() { if (password.length < 8) { setError("Password must be at least 8 characters"); return; } if (password !== confirm) { setError("Passwords don't match"); return; } setPending(true); setError(undefined); const result = await updateUserPassword(userId, password); setPending(false); if (result?.error) { setError(result.error); return; } onOpenChange(false); } return ( Change password Set a new password for {userLabel}.
setPassword(e.target.value)} />
setConfirm(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleSave()} />
{error &&

{error}

}
); }