'use client'; import { useState } from 'react'; import axios from 'axios'; import Cookies from 'js-cookie'; import SuccessToast from '../Success'; export const PasswordSettings = ({ onError }: { onError: (message: string) => void }) => { const [oldPassword, setOldPassword] = useState(''); const [password, setPassword] = useState(''); const [passwordConfirm, setPasswordConfirm] = useState(''); const [success, setSuccess] = useState(''); const handleSave = async () => { if (password !== passwordConfirm) return onError('Passwords do not match'); if (oldPassword === password) return onError('New password must be different'); try { const response = await axios.post('/api/user/change/password', { token: Cookies.get('token'), old_password: oldPassword, password, }); if (response.data.message !== 'Password updated successfully') { onError('Failed to update password'); } setSuccess('Password updated successfully'); setOldPassword(''); setPassword(''); setPasswordConfirm(''); } catch (error: any) { onError(error.response?.data?.error || 'An error occurred'); } }; return (

Password Settings

Manage your password

setOldPassword(e.target.value)} className="input w-full" />
setPassword(e.target.value)} className="input w-full" />
setPasswordConfirm(e.target.value)} className="input w-full" />
setSuccess('')} />
); };