From 636651aa386b975037e08465cfef0d8374f5f09b Mon Sep 17 00:00:00 2001 From: Ebube Date: Mon, 24 Apr 2023 23:39:40 +0100 Subject: [PATCH] Complete format and api call(70%) --- .env | 2 + .../AuthPages/ForgotPassword/index.jsx | 105 +++++++++++++++++- src/components/AuthPages/Login/index.jsx | 2 - src/components/AuthPages/SignUp/index.jsx | 2 +- src/middleware/AuthRoute.jsx | 1 - src/services/UsersService.js | 14 ++- 6 files changed, 111 insertions(+), 15 deletions(-) diff --git a/.env b/.env index 426eb40..26a2207 100644 --- a/.env +++ b/.env @@ -21,6 +21,8 @@ REACT_APP_SESSION_EXPIRE_MINUTES=300000 REACT_APP_SESSION_EXPIRE_CHECKER=60000 REACT_APP_LOGIN_ERROR_TIMEOUT=7000 +REACT_APP_SIGNUP_ERROR_TIMEOUT=7000 +REACT_APP_RESET_START_ERROR_TIMEOUT=5000 #apigate.lotus.g1.wrenchboard.com:76.209.103.227 #apigate.orion.g1.wrenchboard.com:76.209.103.227 diff --git a/src/components/AuthPages/ForgotPassword/index.jsx b/src/components/AuthPages/ForgotPassword/index.jsx index e526c4e..0eabcec 100644 --- a/src/components/AuthPages/ForgotPassword/index.jsx +++ b/src/components/AuthPages/ForgotPassword/index.jsx @@ -1,10 +1,67 @@ -import React from "react"; -import { Link } from 'react-router-dom'; +import React, { useState } from "react"; +import { Link, useNavigate } from 'react-router-dom'; import WrenchBoard from "../../../assets/images/wrenchboard.png" import InputCom from "../../Helpers/Inputs/InputCom"; import AuthLayout from "../AuthLayout"; +import usersService from "../../../services/UsersService"; export default function ForgotPassword() { + const [checked, setValue] = useState(false); + const [resetLoading, setResetLoading] = useState(false) + // email + const [email, setMail] = useState(""); + const [msgError, setMsgError] = useState(''); + + const navigate = useNavigate(); + const userApi = new usersService(); + + const handleEmail = (e) => { + setMail(e?.target.value); + }; + + const humanChecker = () => { + setValue(!checked); + }; + + const resetHandler = async () => { + if (email == '') { + setMsgError('Please fill in fields') + } else if (!checked){ + setMsgError('Check if you are human') + } + + if (email != '' && checked) { + const reqData = { email } + setResetLoading(true) + try { + const res = await userApi.StartResetPassword(reqData) + if (res.status === 200) { + const { data } = res + if (data.status == -1) { + setMsgError('reset was not successful') + setResetLoading(false) + return + } + if (data.status > 0) { + setResetLoading(false) + console.log('Success', data) + } + } + } catch (error) { + setResetLoading(false) + setMsgError('An error occurred') + throw new Error(error) + } finally { + setTimeout(() => { + setMsgError(null) + }, process.env.REACT_APP_RESET_START_ERROR_TIMEOUT) + } + } + setTimeout(() => { + setMsgError(null) + }, process.env.REACT_APP_RESET_START_ERROR_TIMEOUT) + } + return ( <>
-
+

@@ -27,25 +84,61 @@ export default function ForgotPassword() { Enter your email to reset your password.

-
+
+ {msgError &&
{msgError}
} + {/* hCaptha clone for the time being */} +
+
+
+ {/* Checkbox */} +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
-
+