Merge branch 'manage-family-page' of WrenchBoard/Users-Wrench into master

This commit is contained in:
2023-05-21 22:56:23 +00:00
committed by Gogs
+62 -45
View File
@@ -52,49 +52,64 @@ export default function Login() {
const navigate = useNavigate();
const userApi = new usersService();
const doLogin = async () => {
try {
if (email !== "" && password !== "") {
var postData = {
username: email,
password: password,
sessionid: "STARTING",
};
const loginResult = await userApi.logInUser(postData); // just for a test
//debugger;
// if (email === "support@mermsemr.com") {
if (
loginResult.data.status > 0 &&
loginResult.data.internal_return == 100 &&
loginResult.data.session != ""
) {
// just for a start
localStorage.setItem("member_id", `${loginResult.data.member_id}`);
localStorage.setItem("uid", `${loginResult.data.uid}`);
localStorage.setItem("session_token", `${loginResult.data.session}`);
localStorage.setItem("session", `${loginResult.data.session}`);
setLoginLoading(true);
// userApi.getUserReminders(); //testing
dispatch(updateUserDetails(loginResult.data));
setTimeout(() => {
navigate("/", { replace: true });
setLoginLoading(false);
}, 2000);
} else {
// toast.error("Invalid Credential");
setLoginError(true);
}
} else {
setMsgError("Please fill in the fields");
}
} catch (error) {
setMsgError("An error occurred");
} finally {
setTimeout(() => {
setLoginError(false);
setMsgError(null);
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT));
// FUNCTION TO HANDLE USER LOGIN
const doLogin = ({ target: { name } }) => {
setLoginLoading(true);
let postData = {}; // Post Data for API
if (!email || !password) {
setLoginLoading(false);
setMsgError("Please fill in the fields");
return;
}
if (name == "userlogin") {
// Post Data Info for normal Login
postData = {
username: email,
password: password,
sessionid: "STARTING",
};
} else {
postData = {
// Post Data Info for family Login
username: email,
pin: password,
sessionid: "20067A92714",
login_mode: 1105,
action: 11025,
};
}
userApi
.logInUser(postData)
.then((res) => {
if (res.status != 200 || res.data.internal_return < 0) {
// setMsgError("Wrong, email/password");
setLoginError(true);
setLoginLoading(false);
return;
}
localStorage.setItem("member_id", `${res.data.member_id}`);
localStorage.setItem("uid", `${res.data.uid}`);
localStorage.setItem("session_token", `${res.data.session}`);
// localStorage.setItem("session", `${res.data.session}`);
dispatch(updateUserDetails(res.data));
setTimeout(() => {
navigate("/", { replace: true });
setLoginLoading(false);
}, 2000);
})
.catch((error) => {
setMsgError("Unable to login, try again");
setLoginLoading(false);
})
.finally(() => {
setTimeout(() => {
setLoginError(false);
setMsgError(null);
setLoginLoading(false);
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT));
});
};
return (
@@ -204,8 +219,10 @@ export default function Login() {
<div className="signin-area mb-3.5">
<div className="flex justify-center">
<button
name="userlogin"
onClick={doLogin}
type="button"
disabled={loginLoading}
className={`btn-login rounded-[0.475rem] mb-6 text-xl text-white flex justify-center bg-[#4687ba] hover:bg-[#009ef7] transition-all duration-300 items-center text-[15px]`}
>
{loginLoading ? (
@@ -276,9 +293,9 @@ export default function Login() {
<div className="signin-area mb-1.5">
<div className="flex justify-center">
<button
onClick={() => {
console.log("working");
}}
name="familylogin"
onClick={doLogin}
disabled={loginLoading}
type="button"
className={`btn-login rounded-[0.475rem] text-xl text-white flex justify-center bg-[#4687ba] hover:bg-[#009ef7] transition-all duration-300 items-center text-[15px]`}
>