Merge branch 'reset-password' of MyFit/users-myfit into master
This commit is contained in:
@@ -3,34 +3,49 @@ import { Link, useNavigate } from 'react-router-dom';
|
|||||||
import titleShape from "../../../assets/images/shape/title-shape-two.svg";
|
import titleShape from "../../../assets/images/shape/title-shape-two.svg";
|
||||||
import InputCom from "../../Helpers/Inputs/InputCom";
|
import InputCom from "../../Helpers/Inputs/InputCom";
|
||||||
import AuthLayout from "../AuthLayout";
|
import AuthLayout from "../AuthLayout";
|
||||||
|
import usersService from "../../../services/UsersService";
|
||||||
|
|
||||||
export default function ForgotPassword() {
|
export default function ForgotPassword() {
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [validation, setValidation] = useState("")
|
const [validation, setValidation] = useState("")
|
||||||
const [buttonDisabled, setButtonDisabled] = useState(true)
|
const [buttonDisabled, setButtonDisabled] = useState(true)
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const user = new usersService()
|
||||||
|
|
||||||
// email
|
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const handleEmail = (e) => {
|
const handleEmail = (e) => {
|
||||||
setEmail(e.target.value);
|
setEmail(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function validationChecker(email) {
|
function validationChecker(email) {
|
||||||
const emailCheck = /^[^0-9][a-zA-Z0-9._%+-]+@[a-zA-Z]+(\.[a-zA-Z]+)+$/;
|
const emailCheck = /^[^0-9][a-zA-Z0-9._%+-]+@[a-zA-Z]+(\.[a-zA-Z]+)+$/;
|
||||||
if (email === "") {
|
if (email === "") {
|
||||||
setValidation("email is required");
|
setValidation("email is required");
|
||||||
|
|
||||||
} else if (!email.match(emailCheck)) {
|
} else if (!email.match(emailCheck)) {
|
||||||
setValidation('Please input a valid email address');
|
setValidation('Please input a valid email address');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
setValidation("");
|
setValidation("");
|
||||||
setButtonDisabled(false)
|
setButtonDisabled(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async() => {
|
||||||
|
const resetEmail = {
|
||||||
|
username: email,
|
||||||
|
stage: 100
|
||||||
|
}
|
||||||
|
const reset = await user.resetPassword(resetEmail);
|
||||||
|
setLoading(true)
|
||||||
|
if (reset.status == 200){
|
||||||
|
setTimeout(() => {
|
||||||
|
navigate("/verify-you", {replace : true});
|
||||||
|
setLoading(false)
|
||||||
|
}, 2000);
|
||||||
|
}else{
|
||||||
|
setValidation('An error occurred')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
validationChecker(email)
|
validationChecker(email)
|
||||||
}, [email])
|
}, [email])
|
||||||
@@ -61,21 +76,21 @@ export default function ForgotPassword() {
|
|||||||
inputHandler={handleEmail}
|
inputHandler={handleEmail}
|
||||||
value={email}
|
value={email}
|
||||||
/>
|
/>
|
||||||
{validation && <p className="my-5 font-bold text-red-500">{validation}</p>}
|
{validation && <p className="my-5 text-center font-light italic subpixel-antialiased tracking-wide text-red-500">{validation}</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="signin-area mb-3.5">
|
<div className="signin-area mb-3.5">
|
||||||
|
|
||||||
<button
|
<button
|
||||||
className="w-full rounded-[50px] mb-5 h-[58px] text-xl text-white font-bold flex justify-center bg-purple items-center"
|
className="w-full rounded-[50px] h-[58px] text-xl text-white font-bold flex justify-center bg-purple items-center"
|
||||||
disabled={buttonDisabled}
|
disabled={buttonDisabled}
|
||||||
onClick={() => navigate("/verify-you")}
|
onClick={handleSubmit}
|
||||||
>
|
>
|
||||||
Send Code
|
{loading ? <div className="signup btn-loader"></div> : <span>Send Code</span>}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<Link to="/"
|
<Link to="/"
|
||||||
className="my-40 font-bold flex justify-center text-red-500 items-center"
|
className="mt-5 cursor-default font-bold flex justify-center subpixel-antialiased tracking-wide text-white items-center h-[58px] rounded-[50px] bg-[#1a3544a2]"
|
||||||
>
|
>
|
||||||
Back to Home
|
Back to Home
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ class usersService {
|
|||||||
console.log("Er are here anyway");
|
console.log("Er are here anyway");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset Password
|
||||||
|
resetPassword(reqData) {
|
||||||
|
return this.postAuxEnd('/resetpass', reqData);
|
||||||
|
}
|
||||||
|
|
||||||
logInUser(reqData) {
|
logInUser(reqData) {
|
||||||
localStorage.setItem("session_token", ``);
|
localStorage.setItem("session_token", ``);
|
||||||
return this.postAuxEnd("/login", reqData);
|
return this.postAuxEnd("/login", reqData);
|
||||||
@@ -128,7 +133,7 @@ class usersService {
|
|||||||
if (error.response) {
|
if (error.response) {
|
||||||
//response status is an error code
|
//response status is an error code
|
||||||
console.log("ERROR-------------------------------------------------------");
|
console.log("ERROR-------------------------------------------------------");
|
||||||
console.log(error.response.status);
|
console.log(error.response.status, 'err');
|
||||||
console.log("ERROR-------------------------------------------------------");
|
console.log("ERROR-------------------------------------------------------");
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
//response not received though the request was sent
|
//response not received though the request was sent
|
||||||
|
|||||||
Reference in New Issue
Block a user