action for normal login added

This commit is contained in:
victorAnumudu
2023-05-23 15:12:09 +01:00
parent 25c3c15145
commit 882be3573c
+23 -16
View File
@@ -1,9 +1,9 @@
import React, { useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import linkedInLogo from "../../../assets/images/Linkedin.png";
import appleLogo from "../../../assets/images/apple-black.svg";
import facebookLogo from "../../../assets/images/facebook-4.svg";
import googleLogo from "../../../assets/images/google-logo.svg";
import linkedInLogo from "../../../assets/images/Linkedin.png";
import WrenchBoard from "../../../assets/images/wrenchboard.png";
import usersService from "../../../services/UsersService";
import InputCom from "../../Helpers/Inputs/InputCom";
@@ -55,24 +55,27 @@ export default function Login() {
// FUNCTION TO HANDLE USER LOGIN
const doLogin = ({ target: { name } }) => {
setMsgError("");
setLoginLoading(true);
let postData = {}; // Post Data for API
if (!email || !password) {
setLoginLoading(false);
setMsgError("Please fill in the fields");
setMsgError("Please fill all the fields");
setTimeout(() => {
setMsgError("");
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT));
return;
}
if (name == "userlogin") {
// Post Data Info for normal Login
if (name == "userlogin") { // Post Data Info for normal Login
postData = {
username: email,
password: password,
sessionid: "STARTING",
action: 11025,
};
} else {
} else if (name == "familylogin") { // Post Data Info for family Login
postData = {
// Post Data Info for family Login
username: email,
pin: password,
sessionid: "20067A92714",
@@ -81,9 +84,7 @@ export default function Login() {
};
}
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);
@@ -99,15 +100,13 @@ 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(null);
setMsgError('');
setLoginLoading(false);
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT));
});
@@ -238,8 +237,16 @@ export default function Login() {
<BrandBtn link="#" imgSrc={appleLogo} brand="Apple" />
</div>
<div className="sm:flex sm:justify-between sm:items-center sm:space-x-2">
<BrandBtn link="#" imgSrc={facebookLogo} brand="Facebook" />
<BrandBtn link="#" imgSrc={linkedInLogo} brand="LinkedIn" />
<BrandBtn
link="#"
imgSrc={facebookLogo}
brand="Facebook"
/>
<BrandBtn
link="#"
imgSrc={linkedInLogo}
brand="LinkedIn"
/>
</div>
</div>
</div>