import { useState, useEffect } from "react"; import axios from "axios"; import { useParams } from "react-router-dom"; import { toast } from "react-toastify"; import Navbar from "./Navbar"; import Footer from "./Footer"; const ResetPassword = () => { const { userId, token } = useParams(); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [message, setMessage] = useState(""); const BASE_URL = import.meta.env.VITE_REACT_APP_SECRET; const handleResetPassword = async () => { try { if (!password || password.trim() === "") { setMessage("Password not entered"); toast.error("Password not entered"); // Use toast.error instead of toast.success return; } const response = await axios.post( `${BASE_URL}/users/resetpassword/${userId}/${token}`, { userId, token, password } ); if (password !== confirmPassword) { setMessage("Passwords do not match."); toast.error("Passwords do not match."); return; } else { setMessage("Password reset successfull"); toast.success(response.data.message); } } catch (error) { console.error("Reset Password Error:", error); } }; useEffect(() => { // Clear any existing toasts when the component mounts toast.dismiss(); }, []); return ( <>



{" "} Reset Password


Enter your new password:

setPassword(e.target.value)} placeholder="Enter your new password" style={{ display: "flex", gap: "35px" }} />
setConfirmPassword(e.target.value)} placeholder="Confirm your new password" />

{message}