From 3349811c590b8bfd99b9e82df924b421bf9b21b3 Mon Sep 17 00:00:00 2001 From: prafullnavkar-nxg Date: Mon, 30 Oct 2023 15:40:19 +0530 Subject: [PATCH 1/3] fix profile dropdown issue and navigation issue in login --- apps/OpenSign/src/components/Header.js | 7 +- apps/OpenSign/src/routes/Login.js | 1293 ++++++++++-------------- 2 files changed, 559 insertions(+), 741 deletions(-) diff --git a/apps/OpenSign/src/components/Header.js b/apps/OpenSign/src/components/Header.js index 84a7e97e8..f15af8a65 100644 --- a/apps/OpenSign/src/components/Header.js +++ b/apps/OpenSign/src/components/Header.js @@ -82,7 +82,10 @@ const Header = ({ showSidebar }) => { /> -
+
@@ -103,7 +106,7 @@ const Header = ({ showSidebar }) => { {username && username}
)} -
+
diff --git a/apps/OpenSign/src/routes/Login.js b/apps/OpenSign/src/routes/Login.js index 8eea2dba7..ed9b0baeb 100644 --- a/apps/OpenSign/src/routes/Login.js +++ b/apps/OpenSign/src/routes/Login.js @@ -1,4 +1,4 @@ -import React, { Component, useState } from "react"; +import React, { useEffect, useState } from "react"; import Parse from "parse"; import "../styles/toast.css"; import "../styles/loader.css"; @@ -8,11 +8,12 @@ import axios from "axios"; import Title from "../components/Title"; import GoogleSignInBtn from "../components/LoginGoogle"; import LoginFacebook from "../components/LoginFacebook"; -import { NavLink, Navigate } from "react-router-dom"; +import { NavLink, useNavigate } from "react-router-dom"; import login_img from "../assets/images/login_img.svg"; -class Login extends Component { - state = { +function Login(props) { + const navigate = useNavigate(); + const [state, setState] = useState({ email: "", toastColor: "#5cb85c", toastDescription: "", @@ -28,32 +29,54 @@ class Login extends Component { loading: false, thirdpartyLoader: false, orgModal: false, - roleModal: false, ReqOtp: "" - }; + }); - handleChange = (event) => { + const image = props?.appInfo?.applogo || undefined; + + useEffect(() => { + if (localStorage.getItem("accesstoken")) { + setState({ ...state, loading: true }); + GetLoginData(); + } + props.fetchAppInfo( + localStorage.getItem("domain"), + localStorage.getItem("BaseUrl12"), + localStorage.getItem("AppID12") + ); + // eslint-disable-next-line + }, []); + useEffect(() => { + resize(); + window.addEventListener("resize", resize()); + return () => { + window.removeEventListener("resize", resize()); + }; + // eslint-disable-next-line + }, []); + const handleChange = (event) => { const { name, value } = event.target; - this.setState({ [name]: value }); + setState({ ...state, [name]: value }); }; - resize = () => { + const resize = () => { let currentHideNav = window.innerWidth <= 760; - if (currentHideNav !== this.state.hideNav) { - this.setState({ hideNav: currentHideNav }); + if (currentHideNav !== state.hideNav) { + setState({ ...state, hideNav: currentHideNav }); } }; - handleSubmit = async (event) => { + const handleSubmit = async (event) => { + localStorage.removeItem("accesstoken"); event.preventDefault(); - const { email, password } = this.state; + const { email, password } = state; if (email && password) { try { - this.setState({ loading: true }); + setState({ ...state, loading: true }); let baseUrl = localStorage.getItem("baseUrl"); let parseAppId = localStorage.getItem("parseAppId"); - localStorage.setItem("appLogo", this.props.appInfo.applogo); - localStorage.setItem("appName", this.props.appInfo.appname); + localStorage.setItem("appLogo", props.appInfo.applogo); + localStorage.setItem("appName", props.appInfo.appname); Parse.serverURL = localStorage.getItem("baseUrl"); Parse.initialize(localStorage.getItem("parseAppId")); // Pass the username and password to logIn function @@ -75,8 +98,8 @@ class Login extends Component { // Check extended class user role and tenentId try { let userRoles = []; - if (this.props.appInfo.settings) { - let userSettings = this.props.appInfo.settings; + if (props.appInfo.settings) { + let userSettings = props.appInfo.settings; //Get Current user roles let url = `${baseUrl}functions/UserGroups`; @@ -160,7 +183,7 @@ class Login extends Component { } }); if (tenentInfo.length) { - this.props.showTenantName( + props.showTenantName( tenentInfo[0].tenentName || "" ); localStorage.setItem( @@ -170,11 +193,6 @@ class Login extends Component { } localStorage.setItem("showpopup", true); - localStorage.setItem( - "IncludedApps", - JSON.stringify(tenentInfo) - ); - localStorage.setItem( "PageLanding", element.pageId @@ -187,8 +205,8 @@ class Login extends Component { "pageType", element.pageType ); - this.setState({ loading: false }); - window.location = "/"; + setState({ ...state, loading: false }); + navigate("/"); } else { extendedInfo.forEach((x) => { if (x.TenantId) { @@ -205,7 +223,7 @@ class Login extends Component { } }); if (tenentInfo.length) { - this.props.showTenantName( + props.showTenantName( tenentInfo[0].tenentName || "" ); localStorage.setItem( @@ -225,7 +243,7 @@ class Login extends Component { "pageType", element.pageType ); - this.setState({ loading: false }); + setState({ ...state, loading: false }); if ( process.env .REACT_APP_ENABLE_SUBSCRIPTION @@ -248,16 +266,19 @@ class Login extends Component { localStorage.removeItem( "userDetails" ); - - window.location = `/${element.pageType}/${element.pageId}`; + navigate( + `/${element.pageType}/${element.pageId}` + ); } else { - window.location = `/subscription`; + navigate(`/subscription`); } } else { - window.location = `/subscription`; + navigate(`/subscription`); } } else { - window.location = `/${element.pageType}/${element.pageId}`; + navigate( + `/${element.pageType}/${element.pageId}` + ); } } } else { @@ -273,7 +294,7 @@ class Login extends Component { "pageType", element.pageType ); - this.setState({ loading: false }); + setState({ ...state, loading: false }); if ( process.env.REACT_APP_ENABLE_SUBSCRIPTION ) { @@ -289,10 +310,12 @@ class Login extends Component { ); const billingDate = ""; if (billingDate) { - window.location = `/subscription`; + navigate(`/subscription`); } } else { - window.location = `/${element.pageType}/${element.pageId}`; + navigate( + `/${element.pageType}/${element.pageId}` + ); } } }, @@ -300,27 +323,22 @@ class Login extends Component { /* alert( "You dont have access to this application." ); */ - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: - "You dont have access to this application." - }, - () => { - var x = - document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace( - "show", - "" - ); - }, 5000); - localStorage.setItem("accesstoken", null); - } - ); - + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: + "You dont have access to this application." + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace( + "show", + "" + ); + }, 2000); + localStorage.setItem("accesstoken", null); console.error( "Error while fetching Follow", error @@ -330,103 +348,87 @@ class Login extends Component { } }); } else { - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: "User Role Not Found." - }, - () => { - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, 5000); - } - ); - } - } else { - this.setState( - { + setState({ + ...state, loading: false, toastColor: "#d9534f", toastDescription: "User Role Not Found." - }, - () => { - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, 5000); - } - ); - } - }) - .catch((err) => { - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: `Does not have permissions to access this application.` - }, - () => { - var x = document.getElementById("snackbar"); + }); + const x = document.getElementById("snackbar"); x.className = "show"; setTimeout(function () { x.className = x.className.replace("show", ""); - }, 5000); + }, 2000); } - ); + } else { + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: "User Role Not Found." + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace("show", ""); + }, 2000); + } + }) + .catch((err) => { + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: `Does not have permissions to access this application.` + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace("show", ""); + }, 2000); }); } } catch (error) { - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: `${error.message}` - }, - () => { - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, 5000); - } - ); - + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: `${error.message}` + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace("show", ""); + }, 2000); console.log(error); } } }) .catch((error) => { - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: "Login failed: Invalid username or password." - }, - () => { - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, 5000); - } - ); + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: "Login failed: Invalid username or password." + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace("show", ""); + }, 2000); console.error("Error while logging in user", error); }); } catch (error) { console.log(error.message); - this.setState({ loading: false }); + setState({ ...state, loading: false }); } } }; - setThirdpartyLoader = (value) => { - this.setState({ thirdpartyLoader: value }); + const setThirdpartyLoader = (value) => { + setState({ ...state, thirdpartyLoader: value }); }; - thirdpartyLoginfn = async (sessionToken, billingDate) => { + const thirdpartyLoginfn = async (sessionToken, billingDate) => { const baseUrl = localStorage.getItem("BaseUrl12"); const parseAppId = localStorage.getItem("AppID12"); const res = await axios.get(baseUrl + "users/me", { @@ -454,8 +456,8 @@ class Login extends Component { // Check extended class user role and tenentId try { let userRoles = []; - if (this.props.appInfo.settings) { - let userSettings = this.props.appInfo.settings; + if (props.appInfo.settings) { + let userSettings = props.appInfo.settings; //Get Current user roles let url = `${baseUrl}functions/UserGroups`; @@ -535,7 +537,7 @@ class Login extends Component { } }); if (tenentInfo.length) { - this.props.showTenantName( + props.showTenantName( tenentInfo[0].tenentName || "" ); localStorage.setItem( @@ -545,11 +547,6 @@ class Login extends Component { } localStorage.setItem("showpopup", true); - localStorage.setItem( - "IncludedApps", - JSON.stringify(tenentInfo) - ); - localStorage.setItem( "PageLanding", element.pageId @@ -562,9 +559,9 @@ class Login extends Component { "pageType", element.pageType ); - this.setThirdpartyLoader(false); - this.setState({ loading: false }); - window.location = "/"; + setThirdpartyLoader(false); + setState({ ...state, loading: false }); + navigate(`/`); } else { extendedInfo.forEach((x) => { if (x.TenantId) { @@ -580,7 +577,7 @@ class Login extends Component { } }); if (tenentInfo.length) { - this.props.showTenantName( + props.showTenantName( tenentInfo[0].tenentName || "" ); localStorage.setItem( @@ -600,17 +597,19 @@ class Login extends Component { "pageType", element.pageType ); - this.setThirdpartyLoader(false); - this.setState({ loading: false }); + setThirdpartyLoader(false); + setState({ ...state, loading: false }); if (billingDate) { if (billingDate > new Date()) { localStorage.removeItem("userDetails"); - window.location = `/${element.pageType}/${element.pageId}`; + navigate( + `/${element.pageType}/${element.pageId}` + ); } else { - window.location = `/subscription`; + navigate(`/subscription`); } } else { - window.location = `/subscription`; + navigate(`/subscription`); } } } else { @@ -620,18 +619,19 @@ class Login extends Component { element.menuId ); localStorage.setItem("pageType", element.pageType); - this.setState({ loading: false }); - this.setThirdpartyLoader(false); + setState({ ...state, loading: false }); + setThirdpartyLoader(false); if (billingDate) { if (billingDate > new Date()) { localStorage.removeItem("userDetails"); - - window.location = `/${element.pageType}/${element.pageId}`; + navigate( + `/${element.pageType}/${element.pageId}` + ); } else { - window.location = `/subscription`; + navigate(`/subscription`); } } else { - window.location = `/subscription`; + navigate(`/subscription`); } } }, @@ -639,631 +639,262 @@ class Login extends Component { /* alert( "You dont have access to this application." ); */ - this.setThirdpartyLoader(false); + setThirdpartyLoader(false); - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: - "You dont have access to this application." - }, - () => { - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, 5000); - localStorage.setItem("accesstoken", null); - } - ); + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: + "You dont have access to this application." + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace("show", ""); + }, 2000); + localStorage.setItem("accesstoken", null); console.error("Error while fetching Follow", error); } ); } }); } else { - this.setThirdpartyLoader(false); - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: "User Role Not Found." - }, - () => { - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, 5000); - } - ); - } - } else { - this.setThirdpartyLoader(false); - this.setState( - { + setThirdpartyLoader(false); + setState({ + ...state, loading: false, toastColor: "#d9534f", toastDescription: "User Role Not Found." - }, - () => { - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, 5000); - } - ); - } - }) - .catch((err) => { - this.setThirdpartyLoader(false); - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: `Does not have permissions to access this application.` - }, - () => { - var x = document.getElementById("snackbar"); + }); + + const x = document.getElementById("snackbar"); x.className = "show"; setTimeout(function () { x.className = x.className.replace("show", ""); - }, 5000); + }, 2000); } - ); + } else { + setThirdpartyLoader(false); + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: "User Role Not Found." + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace("show", ""); + }, 2000); + } + }) + .catch((err) => { + setThirdpartyLoader(false); + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: `Does not have permissions to access this application.` + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace("show", ""); + }, 2000); }); } } catch (error) { - this.setThirdpartyLoader(false); - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: `${error.message}` - }, - () => { - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, 5000); - } - ); - + setThirdpartyLoader(false); + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: `${error.message}` + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace("show", ""); + }, 2000); console.log(error); } } }; - GetLoginData = async () => { + const GetLoginData = async () => { try { Parse.serverURL = localStorage.getItem("baseUrl"); Parse.initialize(localStorage.getItem("parseAppId")); - await Parse.User.become(localStorage.getItem("accesstoken")).then( - async (user) => { - let _usss = user.toJSON(); - localStorage.setItem("UserInformation", JSON.stringify(_usss)); - localStorage.setItem("username", _usss.name); - localStorage.setItem("accesstoken", _usss.sessionToken); - localStorage.setItem("scriptId", true); - if (_usss.ProfilePic) { - localStorage.setItem("profileImg", _usss.ProfilePic); - } else { - localStorage.setItem("profileImg", ""); - } - try { - let userRoles = []; + const user = await Parse.User.become(localStorage.getItem("accesstoken")); + let _usss = user.toJSON(); + localStorage.setItem("UserInformation", JSON.stringify(_usss)); + localStorage.setItem("username", _usss.name); + localStorage.setItem("accesstoken", _usss.sessionToken); + localStorage.setItem("scriptId", true); + if (_usss.ProfilePic) { + localStorage.setItem("profileImg", _usss.ProfilePic); + } else { + localStorage.setItem("profileImg", ""); + } + let userRoles = []; - if (localStorage.getItem("userSettings")) { - let userSettings = localStorage.getItem("userSettings"); + if (localStorage.getItem("userSettings")) { + let userSettings = localStorage.getItem("userSettings"); - //Get Current user roles - let url = `${localStorage.getItem( - "baseUrl" - )}functions/UserGroups`; - const headers1 = { - "Content-Type": "application/json", - "X-Parse-Application-Id": localStorage.getItem("parseAppId"), - sessionToken: _usss.sessionToken - }; + //Get Current user roles + let url = `${localStorage.getItem("baseUrl")}functions/UserGroups`; + const headers1 = { + "Content-Type": "application/json", + "X-Parse-Application-Id": localStorage.getItem("parseAppId"), + sessionToken: _usss.sessionToken + }; - let body = { - appname: localStorage.getItem("_appName") - }; + let body = { + appname: localStorage.getItem("_appName") + }; - await axios - .post(url, JSON.stringify(body), { headers: headers1 }) - .then((roles) => { - if (roles) { - userRoles = roles.data.result; - let _currentRole = ""; - if (userRoles.length > 1) { - if ( - userRoles[0] === - `${localStorage.getItem("_appName")}_appeditor` - ) { - _currentRole = userRoles[1]; - } else { - _currentRole = userRoles[0]; - } - } else { - _currentRole = userRoles[0]; - } - let SettingsUser = JSON.parse(userSettings); - SettingsUser.forEach(async (element) => { - if (element.role === _currentRole) { - let _role = _currentRole.replace( - `${localStorage.getItem("_appName")}_`, - "" - ); - localStorage.setItem("_user_role", _role); + await axios + .post(url, JSON.stringify(body), { headers: headers1 }) + .then((roles) => { + if (roles) { + userRoles = roles.data.result; + let _currentRole = ""; + if (userRoles.length > 1) { + if ( + userRoles[0] === + `${localStorage.getItem("_appName")}_appeditor` + ) { + _currentRole = userRoles[1]; + } else { + _currentRole = userRoles[0]; + } + } else { + _currentRole = userRoles[0]; + } + let SettingsUser = JSON.parse(userSettings); + SettingsUser.forEach(async (element) => { + if (element.role === _currentRole) { + let _role = _currentRole.replace( + `${localStorage.getItem("_appName")}_`, + "" + ); + localStorage.setItem("_user_role", _role); - // Get TenentID from Extendend Class - localStorage.setItem( - "extended_class", - element.extended_class - ); + // Get TenentID from Extendend Class + localStorage.setItem( + "extended_class", + element.extended_class + ); - const extendedClass = Parse.Object.extend( - element.extended_class - ); - let query = new Parse.Query(extendedClass); - query.equalTo("UserId", Parse.User.current()); - query.include("TenantId"); - await query.find().then( - (results) => { - let tenentInfo = []; - if (results) { - let extendedInfo_stringify = - JSON.stringify(results); - let extendedInfo = JSON.parse( - extendedInfo_stringify - ); - if (extendedInfo.length > 1) { - extendedInfo.forEach((x) => { - if (x.TenantId) { - let obj = { - tenentId: x.TenantId.objectId, - tenentName: x.TenantId.TenantName || "" - }; - tenentInfo.push(obj); - } - }); - - localStorage.setItem("showpopup", true); - localStorage.setItem( - "IncludedApps", - JSON.stringify(tenentInfo) - ); - - localStorage.setItem( - "PageLanding", - element.pageId - ); - localStorage.setItem( - "defaultmenuid", - element.menuId - ); - localStorage.setItem( - "pageType", - element.pageType - ); - window.location = `/`; - } else { - extendedInfo.forEach((x) => { - if (x.TenantId) { - let obj = { - tenentId: x.TenantId.objectId, - tenentName: x.TenantId.TenantName || "" - }; - localStorage.setItem( - "TenetId", - x.TenantId.objectId - ); - tenentInfo.push(obj); - } - }); - localStorage.setItem( - "PageLanding", - element.pageId - ); - localStorage.setItem( - "defaultmenuid", - element.menuId - ); - localStorage.setItem( - "pageType", - element.pageType - ); - window.location = `/${element.pageType}/${element.pageId}`; - } - } else { - localStorage.setItem( - "PageLanding", - element.pageId - ); - localStorage.setItem( - "defaultmenuid", - element.menuId - ); - localStorage.setItem( - "pageType", - element.pageType - ); - window.location = `/${element.pageType}/${element.pageId}`; + const extendedClass = Parse.Object.extend( + element.extended_class + ); + let query = new Parse.Query(extendedClass); + query.equalTo("UserId", Parse.User.current()); + query.include("TenantId"); + await query.find().then( + (results) => { + let tenentInfo = []; + if (results) { + let extendedInfo_stringify = JSON.stringify(results); + let extendedInfo = JSON.parse(extendedInfo_stringify); + if (extendedInfo.length > 1) { + extendedInfo.forEach((x) => { + if (x.TenantId) { + let obj = { + tenentId: x.TenantId.objectId, + tenentName: x.TenantId.TenantName || "" + }; + tenentInfo.push(obj); } - }, - (error) => { - this.setState( - { - loading: false, - toastColor: "#d9534f", - toastDescription: - "You don`t have access to this application." - }, - () => { - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function () { - x.className = x.className.replace("show", ""); - }, 5000); - localStorage.setItem("accesstoken", null); - localStorage.removeItem("SwitcherApp"); - } - ); + }); - console.error("Error while fetching Follow", error); - } - ); + localStorage.setItem("showpopup", true); + localStorage.setItem("PageLanding", element.pageId); + localStorage.setItem("defaultmenuid", element.menuId); + localStorage.setItem("pageType", element.pageType); + navigate("/"); + } else { + extendedInfo.forEach((x) => { + if (x.TenantId) { + let obj = { + tenentId: x.TenantId.objectId, + tenentName: x.TenantId.TenantName || "" + }; + localStorage.setItem( + "TenetId", + x.TenantId.objectId + ); + tenentInfo.push(obj); + } + }); + localStorage.setItem("PageLanding", element.pageId); + localStorage.setItem("defaultmenuid", element.menuId); + localStorage.setItem("pageType", element.pageType); + navigate(`/${element.pageType}/${element.pageId}`); + } + } else { + localStorage.setItem("PageLanding", element.pageId); + localStorage.setItem("defaultmenuid", element.menuId); + localStorage.setItem("pageType", element.pageType); + navigate(`/${element.pageType}/${element.pageId}`); } - }); - } else { - console.log("User Role Not Found."); - localStorage.removeItem("SwitcherApp"); - } - }) - .catch((err) => { - this.setState({ roleModal: true }); - localStorage.removeItem("SwitcherApp"); - }); + }, + (error) => { + setState({ + ...state, + loading: false, + toastColor: "#d9534f", + toastDescription: + "You don`t have access to this application." + }); + const x = document.getElementById("snackbar"); + x.className = "show"; + setTimeout(function () { + x.className = x.className.replace("show", ""); + }, 2000); + localStorage.setItem("accesstoken", null); + console.error("Error while fetching Follow", error); + } + ); + } + }); + } else { + console.log("User Role Not Found."); } - } catch (error) { - localStorage.removeItem("SwitcherApp"); - } - } - ); + }) + .catch((err) => { + setState({ ...state, loading: false }); + console.log("err", err); + }); + } } catch (error) { + setState({ ...state, loading: false }); console.log("err", error); } }; - sendAddRoleRequest = (e) => { - try { - e.preventDefault(); - let _user = JSON.parse(localStorage.getItem("UserInformation")); - Parse.serverURL = localStorage.getItem("baseUrl"); - Parse.initialize(localStorage.getItem("parseAppId")); - const role_req = Parse.Object.extend("partners_Request"); - const myNewObject = new role_req(); - myNewObject.set("AppName", localStorage.getItem("_appName")); - myNewObject.set("Status", "Pending"); - myNewObject.set("UserId", { - __type: "Pointer", - className: "_User", - objectId: _user.objectId - }); - myNewObject.set("TenetId", { - __type: "Pointer", - className: "partners_Tenant", - objectId: localStorage.getItem("TenetId") - }); - /* myNewObject.set("AppId", { - __type: "Pointer", - className: "elearning_BuildConfig", - objectId: localStorage.getItem("TenetId") - }); */ - myNewObject - .save() - .then((result) => { - if (result) { - alert("Request sended successfully."); - this.setState({ roleModal: false }); - } - }) - .catch((err) => { - alert(err.message); - this.setState({ roleModal: false }); - }); - } catch (error) { - alert(error.message); - this.setState({ roleModal: false }); - } + const togglePasswordVisibility = () => { + setState({ ...state, passwordVisible: !state.passwordVisible }); }; - componentDidMount() { - window.addEventListener("resize", this.resize.bind(this)); - if ( - localStorage.getItem("accesstoken") && - localStorage.getItem("SwitcherApp") - ) { - this.GetLoginData(); - } - this.props.fetchAppInfo( - localStorage.getItem("domain"), - localStorage.getItem("BaseUrl12"), - localStorage.getItem("AppID12") - ); - this.resize(); - } - - render() { - if ( - localStorage.getItem("accesstoken") && - localStorage.getItem("pageType") - ) { - let _redirect = `/${localStorage.getItem( - "pageType" - )}/${localStorage.getItem("PageLanding")}`; - return ; - } - - const { email, password, passwordVisible } = this.state; - let image = this.props.appInfo.applogo; - let settings = this.props.appInfo.settings || undefined; - const togglePasswordVisibility = () => { - this.setState((prevState) => ({ - passwordVisible: !prevState.passwordVisible - })); - }; - return ( -
- {settings && - settings.map((x) => { - return x.pageType === "microapp" ? ( -