import React, { useEffect, useState } from "react"; import { useNavigate } from "react-router"; import { useAuth } from "../../Contexts/AuthContext"; import Loader from "../../Components/BackdropLoader/Loader"; import "./new-password.css"; function NewPassword() { const [newPassword, setNewPassword] = useState(); const [confirmNewPassword, setConfirmNewPassword] = useState(); const [error, setError] = useState(); const [disable, setDisable] = useState(true); const navigate = useNavigate(); const { loading, newPasswordHandler } = useAuth(); const onNewPasswordChange = (e) => { setNewPassword(e.target.value); }; const onConfirmNewPasswordChange = (e) => { setConfirmNewPassword(e.target.value); }; const passwordUpdateFormSubmit = (e) => { e.preventDefault(); if (newPassword !== confirmNewPassword) { return setError("Passwords do not match!"); } newPasswordHandler(newPassword) .then(() => { console.log("Success"); navigate("/companies"); }) .catch(() => { console.log("Failed!"); setError("There was some problem setting the new password."); }); }; const onCancelClicked = (e) => { e.preventDefault(); navigate("/"); }; const determineDisable = () => { if (newPassword && confirmNewPassword) { setDisable(false); return; } setDisable(true); }; useEffect(() => { determineDisable(); }, [newPassword, confirmNewPassword]); return (
{loading && }

Reset your Password

{error && (
{error}
)}
); } export default NewPassword;