({
isOpen,
onClose,
onSuccess,
}: ChangePasswordModalProps)
| 10 | } |
| 11 | |
| 12 | export function ChangePasswordModal({ |
| 13 | isOpen, |
| 14 | onClose, |
| 15 | onSuccess, |
| 16 | }: ChangePasswordModalProps) { |
| 17 | const [currentPassword, setCurrentPassword] = useState(""); |
| 18 | const [newPassword, setNewPassword] = useState(""); |
| 19 | const [confirmPassword, setConfirmPassword] = useState(""); |
| 20 | const [showCurrent, setShowCurrent] = useState(false); |
| 21 | const [showNew, setShowNew] = useState(false); |
| 22 | const [showConfirm, setShowConfirm] = useState(false); |
| 23 | const [loading, setLoading] = useState(false); |
| 24 | const [error, setError] = useState<string | null>(null); |
| 25 | |
| 26 | const resetForm = () => { |
| 27 | setCurrentPassword(""); |
| 28 | setNewPassword(""); |
| 29 | setConfirmPassword(""); |
| 30 | setError(null); |
| 31 | }; |
| 32 | |
| 33 | const handleClose = () => { |
| 34 | resetForm(); |
| 35 | onClose(); |
| 36 | }; |
| 37 | |
| 38 | const handleSubmit = async (e: React.FormEvent) => { |
| 39 | e.preventDefault(); |
| 40 | setError(null); |
| 41 | |
| 42 | // Validation |
| 43 | if (!currentPassword || !newPassword || !confirmPassword) { |
| 44 | setError("All fields are required"); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | if (newPassword !== confirmPassword) { |
| 49 | setError("New passwords do not match"); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | if (newPassword.length < 6) { |
| 54 | setError("New password must be at least 6 characters"); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | setLoading(true); |
| 59 | |
| 60 | try { |
| 61 | const res = await fetch("/api/system", { |
| 62 | method: "POST", |
| 63 | headers: { "Content-Type": "application/json" }, |
| 64 | body: JSON.stringify({ |
| 65 | action: "change_password", |
| 66 | data: { currentPassword, newPassword }, |
| 67 | }), |
| 68 | }); |
| 69 |
nothing calls this directly
no outgoing calls
no test coverage detected