import { useState } from "react"; import { Link, useLocation, useNavigate } from "react-router-dom"; import WrenchBoard from "../../../assets/images/wrenchboard.png"; import usersService from "../../../services/UsersService"; import InputCom from "../../Helpers/Inputs/InputCom"; import AuthLayout from "../AuthLayout"; const VerifyPassword = () => { const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [msgError, setMsgError] = useState(""); const [linkLoader, setLinkLoader] = useState(false); const [linkSuccess, setLinkSuccess] = useState(true); const [showPassword, setShowPassword] = useState(false); const navigate = useNavigate(); const location = useLocation(); const queryParams = new URLSearchParams(location?.search); const token = queryParams.get("passlink"); const userApi = new usersService(); // To Show and Hide Password const togglePasswordVisibility = () => { setShowPassword(!showPassword); }; // little checker for the validity of the token if (token?.length != 64) { setLinkSuccess(false); } // Password const handlePassword = (e) => { let { name, value } = e?.target; if (name == "password") setPassword(value); if (name == "confirm_password") setConfirmPassword(value); }; const completeReset = async () => { try { if (password !== "" && confirmPassword !== "") { if (password === confirmPassword) { setLinkLoader(true); var reqData = { sessionid: "DUMMY-CANNOT_BE_EMPTY", reset_link: token, newpass: password, step: 300, action: 730, }; const res = await userApi?.CompleteResetPassword(reqData); if (res.status === 200) { const { data } = res; if (data?.status > 0 && data?.email) { setTimeout(() => { navigate("/login", { replace: true }); setLinkLoader(false); }, 2000); } else if (data && data?.status == "Invalid Request") { setLinkLoader(false); setLinkSuccess(false); } else { setLinkLoader(false); setMsgError("An error occurred"); } } else { setLinkLoader(false); setLinkSuccess(false); } } else { setLinkLoader(false); setMsgError("Passwords does not match"); } } else { setMsgError("Please fill in fields"); } } catch (error) { setLinkLoader(false); setLinkSuccess(false); throw new Error(error); } finally { setTimeout(() => { setMsgError(null); }, process.env.REACT_APP_SIGNUP_ERROR_TIMEOUT); } }; return ( <>
wrenchboard

{linkSuccess ? "Password Reset" : "Invalid verification link"}

{linkSuccess && ( Enter a new password to reset )} {linkSuccess && ( We'll send an email to confirm reset )}
{/* If the verification was a success */} {linkSuccess ? ( navigate("/login")} /> ) : ( navigate("/login")} /> )}
); }; export default VerifyPassword; const SuccessfulComponent = ({ onSubmit, navigateHandler, showPassword, onClick, password, confirmPassword, handlePassword, msgErr, loader, }) => (
{/* INPUT */}
{msgErr && (
{msgErr}
)}
); const ErrorComponent = ({ onClick }) => (

This error occurs because you have already used this link or the link has broken/expired. Start with the reset process again. If it doesn't work, try to create the account from the start.

);