import React, { useState } from "react"; import { toast } from "react-toastify"; import axios from "axios"; // Settings Change Password Component const Settings = () => { const [passwords, setPasswords] = useState({ oldPassword: "", newPassword: "", confirmPassword: "", }); // Handle input changes const handleChange = (e) => { setPasswords({ ...passwords, [e.target.name]: e.target.value }); }; // Submit the form to the backend const handleSubmit = async (e) => { // Step 1: Prevent the page from reloading e.preventDefault(); // Step 2: Check if the new password and confirm password are the same if (passwords.newPassword !== passwords.confirmPassword) { toast.error("New passwords do not match!"); return; } try { // Step 3: Send the old and new password to the server const res = await axios.post( `${import.meta.env.VITE_APP_API_URL}/general/changePassword`, { oldPassword: passwords.oldPassword, newPassword: passwords.newPassword, }, { withCredentials: true } ); // Step 4: If everything is good, show success message if (res.status === 200) { toast.success("Password updated successfully!"); // Clear the form inputs setPasswords({ oldPassword: "", newPassword: "", confirmPassword: "" }); } } catch (error) { // Step 5: If there is an error (like wrong old password), show it console.log(error); toast.error(error.response?.data?.message || "Failed to update password"); } }; return (

Account Settings

Change Password

); }; export default Settings;