From c807a2657b04ec7d6add08a98bea7c4edba9f37c Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Wed, 5 Jul 2023 10:24:01 +0100 Subject: [PATCH] adjusted cookie to check for login type before components mounts --- src/components/AuthPages/Login/index.jsx | 16 +++++++++++++--- src/components/MyTasks/index.jsx | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/components/AuthPages/Login/index.jsx b/src/components/AuthPages/Login/index.jsx index 76ddfa2..aca1aee 100644 --- a/src/components/AuthPages/Login/index.jsx +++ b/src/components/AuthPages/Login/index.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useLayoutEffect, 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"; @@ -17,7 +17,7 @@ import { updateUserDetails } from "../../../store/UserDetails"; export default function Login() { const dispatch = useDispatch(); - let [loginType, setLoginType] = useState(document.cookie.includes("loginType=family")? 'family': document.cookie.includes("loginType=full") ? 'full' : 'full'); + let [loginType, setLoginType] = useState(''); const [checked, setValue] = useState(false); const [loginLoading, setLoginLoading] = useState(false); @@ -38,7 +38,7 @@ export default function Login() { let expirationDate = new Date(currentDate.getTime() + (24 * 60 * 60 * 1000)); // Convert the expiration date to the appropriate format let expirationDateString = expirationDate.toUTCString(); - document.cookie = `loginType=${name}; expires=${expirationDateString}; path=/login;`; + document.cookie = `loginType=${name}; expires=${expirationDateString}; path=/;`; }; // email @@ -148,6 +148,16 @@ export default function Login() { // document.cookie ="loginType=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; // }, []); + useLayoutEffect(()=>{ // checks the cookie in order to set the login type before components mounts + if(document.cookie.includes("loginType=family")){ + setLoginType('family') + }else if(document.cookie.includes("loginType=full")){ + setLoginType('full') + }else{ + setLoginType('full') + } + },[]) + useEffect(() => { setMail(""); setPassword(""); diff --git a/src/components/MyTasks/index.jsx b/src/components/MyTasks/index.jsx index 4d47341..0d4c831 100644 --- a/src/components/MyTasks/index.jsx +++ b/src/components/MyTasks/index.jsx @@ -45,15 +45,17 @@ export default function MyTasks({ My Tasks - + {ActiveJobList?.data?.length > 0 && userDetails.account_type == 'FAMILY' && + + }