diff --git a/apps/OpenSign/src/layout/HomeLayout.js b/apps/OpenSign/src/layout/HomeLayout.js index b13a51a6a..43565a80f 100644 --- a/apps/OpenSign/src/layout/HomeLayout.js +++ b/apps/OpenSign/src/layout/HomeLayout.js @@ -34,7 +34,6 @@ const HomeLayout = () => { }); if (user) { checkIsSubscribed(); - setIsLoader(false); } else { setIsUserValid(false); } @@ -48,10 +47,6 @@ const HomeLayout = () => { async function checkIsSubscribed() { const currentUser = Parse.User.current(); - // const userSettings = appInfo.settings; - // const setting = userSettings.find((x) => x.role === _currentRole); - // const redirectUrl = - // location?.state?.from || `/${setting.pageType}/${setting.pageId}`; const user = await Parse.Cloud.run("getUserDetails", { email: currentUser.get("email") }); @@ -59,24 +54,12 @@ const HomeLayout = () => { if (_user.TenantId) { localStorage.setItem("TenetId", _user.TenantId.objectId); } - // localStorage.setItem("PageLanding", setting.pageId); - // localStorage.setItem("defaultmenuid", setting.menuId); - // localStorage.setItem("pageType", setting.pageType); if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) { - // const LocalUserDetails = { - // name: _user.Name, - // email: _user.Email, - // phone: _user.Phone, - // company: _user.Company - // }; - // localStorage.setItem("userDetails", JSON.stringify(LocalUserDetails)); const billingDate = _user.Next_billing_date && _user.Next_billing_date; if (billingDate) { if (billingDate > new Date()) { - // localStorage.removeItem("userDetails"); - // Redirect to the appropriate URL after successful login - // navigate(redirectUrl); setIsUserValid(true); + setIsLoader(false); return true; } else { navigate(`/subscription`); @@ -86,9 +69,8 @@ const HomeLayout = () => { } } else { setIsUserValid(true); + setIsLoader(false); return true; - // Redirect to the appropriate URL after successful login - // navigate(redirectUrl); } } const showSidebar = () => { @@ -244,7 +226,7 @@ const HomeLayout = () => { return (
-
+ {!isLoader &&
}
{isUserValid ? ( <> @@ -269,7 +251,6 @@ const HomeLayout = () => { <>
-
{ - const navigate = useNavigate(); + // const navigate = useNavigate(); const [yearlyVisible, setYearlyVisible] = useState(false); const [isLoader, setIsLoader] = useState(true); @@ -35,12 +35,12 @@ const PlanSubscriptions = () => { company + phone; useEffect(() => { - if (localStorage.getItem("accesstoken")) { + // if (localStorage.getItem("accesstoken")) { setIsLoader(false); setYearlyVisible(false); - } else { - navigate("/", { replace: true }); - } + // } else { + // navigate("/", { replace: true }); + // } // eslint-disable-next-line }, []); @@ -108,7 +108,7 @@ const PlanSubscriptions = () => { : "" } text-sm text-center my-2`} > -

{ ) : ( {item.subtitle} )} -

+
diff --git a/apps/OpenSign/src/primitives/Validate.js b/apps/OpenSign/src/primitives/Validate.js index 86993d8b3..21fd208c5 100644 --- a/apps/OpenSign/src/primitives/Validate.js +++ b/apps/OpenSign/src/primitives/Validate.js @@ -15,7 +15,7 @@ const Validate = () => { sessionToken: localStorage.getItem("accesstoken") }); if (user) { - setIsUserValid(true); + checkIsSubscribed(); } else { setIsUserValid(false); } @@ -24,7 +24,33 @@ const Validate = () => { setIsUserValid(false); } })(); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + + async function checkIsSubscribed() { + const currentUser = Parse.User.current(); + console.log("currentUser ", currentUser) + const user = await Parse.Cloud.run("getUserDetails", { + email: currentUser.get("email") + }); + const _user = user?.toJSON(); + + if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) { + const billingDate = _user.Next_billing_date && _user.Next_billing_date; + if (billingDate) { + if (billingDate > new Date()) { + setIsUserValid(true); + return true; + } else { + // navigate(`/subscription`); + } + } else { + // navigate(`/subscription`); + } + } else { + setIsUserValid(true); + } + } const handleLoginBtn = () => { try { Parse.User.logOut();