This commit is contained in:
Ebube
2023-05-26 03:40:06 +01:00
parent ad68c2e98e
commit 68627a1792
4 changed files with 133 additions and 141 deletions
+28 -17
View File
@@ -9,7 +9,7 @@ import usersService from "../../../services/UsersService";
import InputCom from "../../Helpers/Inputs/InputCom";
import AuthLayout from "../AuthLayout";
// import { GoogleOAuthProvider } from '@react-oauth/google';
import { googleLogout, useGoogleLogin } from '@react-oauth/google';
import { googleLogout, useGoogleLogin } from "@react-oauth/google";
import { useDispatch } from "react-redux";
import { updateUserDetails } from "../../../store/UserDetails";
@@ -35,7 +35,7 @@ export default function Login() {
const handleLoginType = ({ target: { name } }) => {
if (name == "full") {
setLoginType({ [name]: true, family: false });
} else if(name='family') {
} else if ((name = "family")) {
setLoginType({ [name]: false, family: true });
}
};
@@ -56,7 +56,7 @@ export default function Login() {
// FUNCTION TO HANDLE USER LOGIN
const doLogin = ({ target: { name } }) => {
setMsgError("");
setLoginError(false)
setLoginError(false);
setLoginLoading(true);
let postData; // Post Data for API
if (!email || !password) {
@@ -68,7 +68,8 @@ export default function Login() {
return;
}
if (name == "loginfull") { // Post Data Info for normal Login
if (name == "loginfull") {
// Post Data Info for normal Login
postData = {
username: email,
password: password,
@@ -76,7 +77,8 @@ export default function Login() {
login_mode: 1100,
action: 11025,
};
} else if (name == "loginfamily") { // Post Data Info for family Login
} else if (name == "loginfamily") {
// Post Data Info for family Login
postData = {
username: email,
pin: password,
@@ -84,7 +86,7 @@ export default function Login() {
login_mode: 1105,
action: 11025,
};
}else{
} else {
setLoginLoading(false);
setMsgError("Invalid Login Type. Consider refreshing the page");
setTimeout(() => {
@@ -92,7 +94,9 @@ export default function Login() {
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT));
return;
}
userApi.logInUser(postData).then((res) => {
userApi
.logInUser(postData)
.then((res) => {
if (res.status != 200 || res.data.internal_return < 0) {
// setMsgError("Wrong, email/password");
setLoginError(true);
@@ -108,13 +112,15 @@ export default function Login() {
navigate("/", { replace: true });
setLoginLoading(false);
}, 2000);
}).catch((error) => {
})
.catch((error) => {
setMsgError("Unable to login, try again");
setLoginLoading(false);
}).finally(() => {
})
.finally(() => {
setTimeout(() => {
setLoginError(false);
setMsgError('');
setMsgError("");
setLoginLoading(false);
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT));
});
@@ -129,13 +135,13 @@ export default function Login() {
// );
// console.log(userInfo);
},
onError: errorResponse => console.log(errorResponse),
onError: (errorResponse) => console.log(errorResponse),
});
useEffect(()=>{
setMail('')
setPassword('')
},[loginType.full, loginType.family])
useEffect(() => {
setMail("");
setPassword("");
}, [loginType.full, loginType.family]);
return (
<>
@@ -194,7 +200,7 @@ export default function Login() {
{/* for login component */}
{
loginType.full ? (
//user login compoenent
//user login component
<div className="p-2 input-area border-2 border-[#4687ba]">
<div className="input-item mb-5">
<InputCom
@@ -258,7 +264,12 @@ export default function Login() {
</button>
</div>
<div className="sm:flex sm:justify-between sm:items-center sm:space-x-2">
<BrandBtn link="#" imgSrc={googleLogo} brand="Google" onClick={googleLogin} />
<BrandBtn
link="#"
imgSrc={googleLogo}
brand="Google"
onClick={googleLogin}
/>
<BrandBtn link="#" imgSrc={appleLogo} brand="Apple" />
</div>
<div className="sm:flex sm:justify-between sm:items-center sm:space-x-2">