import React, { useState } from 'react'; import { useAuth } from '../context/AuthContext'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from './ui/dialog'; import { Button } from './ui/button'; import { Input } from './ui/input'; import { Label } from './ui/label'; import { toast } from 'sonner'; import { Lock } from 'lucide-react'; const ChangePasswordDialog = ({ open, onOpenChange }) => { const { changePassword } = useAuth(); const [loading, setLoading] = useState(false); const [formData, setFormData] = useState({ currentPassword: '', newPassword: '', confirmPassword: '' }); const handleInputChange = (e) => { const { name, value } = e.target; setFormData(prev => ({ ...prev, [name]: value })); }; const handleSubmit = async (e) => { e.preventDefault(); if (formData.newPassword.length < 6) { toast.error('New password must be at least 6 characters'); return; } if (formData.newPassword !== formData.confirmPassword) { toast.error('New passwords do not match'); return; } setLoading(true); try { await changePassword(formData.currentPassword, formData.newPassword); toast.success('Password changed successfully!'); // Reset form setFormData({ currentPassword: '', newPassword: '', confirmPassword: '' }); // Close dialog onOpenChange(false); } catch (error) { const errorMessage = error.response?.data?.detail || 'Failed to change password'; toast.error(errorMessage); } finally { setLoading(false); } }; return (
Change Password
Update your password to keep your account secure.
); }; export default ChangePasswordDialog;