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 React, { useState } from "react";
import { Link, useNavigate } from "react-router-dom"; import { Link, useNavigate } from "react-router-dom";
import linkedInLogo from "../../../assets/images/Linkedin.png";
import appleLogo from "../../../assets/images/apple-black.svg"; import appleLogo from "../../../assets/images/apple-black.svg";
import facebookLogo from "../../../assets/images/facebook-4.svg"; import facebookLogo from "../../../assets/images/facebook-4.svg";
import googleLogo from "../../../assets/images/google-logo.svg"; import googleLogo from "../../../assets/images/google-logo.svg";
import linkedInLogo from "../../../assets/images/Linkedin.png";
import WrenchBoard from "../../../assets/images/wrenchboard.png"; import WrenchBoard from "../../../assets/images/wrenchboard.png";
import usersService from "../../../services/UsersService"; import usersService from "../../../services/UsersService";
import InputCom from "../../Helpers/Inputs/InputCom"; import InputCom from "../../Helpers/Inputs/InputCom";
@@ -55,24 +55,27 @@ export default function Login() {
// FUNCTION TO HANDLE USER LOGIN // FUNCTION TO HANDLE USER LOGIN
const doLogin = ({ target: { name } }) => { const doLogin = ({ target: { name } }) => {
setMsgError("");
setLoginLoading(true); setLoginLoading(true);
let postData = {}; // Post Data for API let postData = {}; // Post Data for API
if (!email || !password) { if (!email || !password) {
setLoginLoading(false); 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; return;
} }
if (name == "userlogin") { if (name == "userlogin") { // Post Data Info for normal Login
// Post Data Info for normal Login
postData = { postData = {
username: email, username: email,
password: password, password: password,
sessionid: "STARTING", sessionid: "STARTING",
action: 11025,
}; };
} else { } else if (name == "familylogin") { // Post Data Info for family Login
postData = { postData = {
// Post Data Info for family Login
username: email, username: email,
pin: password, pin: password,
sessionid: "20067A92714", sessionid: "20067A92714",
@@ -81,9 +84,7 @@ export default function Login() {
}; };
} }
userApi userApi.logInUser(postData).then((res) => {
.logInUser(postData)
.then((res) => {
if (res.status != 200 || res.data.internal_return < 0) { if (res.status != 200 || res.data.internal_return < 0) {
// setMsgError("Wrong, email/password"); // setMsgError("Wrong, email/password");
setLoginError(true); setLoginError(true);
@@ -99,15 +100,13 @@ export default function Login() {
navigate("/", { replace: true }); navigate("/", { replace: true });
setLoginLoading(false); setLoginLoading(false);
}, 2000); }, 2000);
}) }).catch((error) => {
.catch((error) => {
setMsgError("Unable to login, try again"); setMsgError("Unable to login, try again");
setLoginLoading(false); setLoginLoading(false);
}) }).finally(() => {
.finally(() => {
setTimeout(() => { setTimeout(() => {
setLoginError(false); setLoginError(false);
setMsgError(null); setMsgError('');
setLoginLoading(false); setLoginLoading(false);
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT)); }, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT));
}); });
@@ -238,8 +237,16 @@ export default function Login() {
<BrandBtn link="#" imgSrc={appleLogo} brand="Apple" /> <BrandBtn link="#" imgSrc={appleLogo} brand="Apple" />
</div> </div>
<div className="sm:flex sm:justify-between sm:items-center sm:space-x-2"> <div className="sm:flex sm:justify-between sm:items-center sm:space-x-2">
<BrandBtn link="#" imgSrc={facebookLogo} brand="Facebook" /> <BrandBtn
<BrandBtn link="#" imgSrc={linkedInLogo} brand="LinkedIn" /> link="#"
imgSrc={facebookLogo}
brand="Facebook"
/>
<BrandBtn
link="#"
imgSrc={linkedInLogo}
brand="LinkedIn"
/>
</div> </div>
</div> </div>
</div> </div>