From d00368854cf4d83b1b9d96bbfb80dbb25e353de7 Mon Sep 17 00:00:00 2001 From: Claudemir Todo Bom Date: Sun, 19 May 2024 17:49:29 -0300 Subject: [PATCH] frontend: Revert to 0.1.3 state --- frontend/src/App.js | 26 ++++----------- frontend/src/context/Socket/SocketContext.js | 9 ++--- frontend/src/hooks/useAuth.js/index.js | 8 ++--- frontend/src/layout/index.js | 35 +++++++++++--------- frontend/src/pages/Login/index.js | 4 +-- 5 files changed, 33 insertions(+), 49 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index d1f34301..57fa6935 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -131,25 +131,13 @@ const App = () => { }, [mode]); useEffect(() => { - getPublicSetting("primaryColorLight") - .then((color) => { color && setPrimaryColorLight(color) }) - .catch((error) => { console.log("Error reading setting", error); }); - getPublicSetting("primaryColorDark") - .then((color) => { color && setPrimaryColorDark(color) }) - .catch((error) => { console.log("Error reading setting", error); }); - getPublicSetting("appLogoLight") - .then((file) => { file && setAppLogoLight(file) }, (_) => { }) - .catch((error) => { console.log("Error reading setting", error); }); - getPublicSetting("appLogoDark") - .then((file) => { file && setAppLogoDark(file) }) - .catch((error) => { console.log("Error reading setting", error); }); - getPublicSetting("appLogoFavicon") - .then((file) => { file && setAppLogoFavicon(file) }) - .catch((error) => { console.log("Error reading setting", error); }); - getPublicSetting("appName").then((name) => { setAppName(name || "ticketz") }) - .catch((error) => { console.log("Error reading setting", error); setAppName("whitelabel chat") }); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + getPublicSetting("primaryColorLight").then((color) => { color && setPrimaryColorLight(color) }); + getPublicSetting("primaryColorDark").then((color) => { color && setPrimaryColorDark(color) }); + getPublicSetting("appLogoLight").then((file) => { file && setAppLogoLight(file)}); + getPublicSetting("appLogoDark").then((file) => { file && setAppLogoDark(file)}); + getPublicSetting("appLogoFavicon").then((file) => { file && setAppLogoFavicon(file)}); + getPublicSetting("appName").then((name) => { setAppName(name || "ticketz")}); + }, [getPublicSetting]); return ( <> diff --git a/frontend/src/context/Socket/SocketContext.js b/frontend/src/context/Socket/SocketContext.js index f3251bea..7cd627b3 100644 --- a/frontend/src/context/Socket/SocketContext.js +++ b/frontend/src/context/Socket/SocketContext.js @@ -1,7 +1,7 @@ import { createContext } from "react"; import openSocket from "socket.io-client"; import { getBackendURL } from "../../services/config"; -import { isExpired } from "react-jwt"; +import { isExpired, decodeToken } from "react-jwt"; class ManagedSocket { constructor(socketManager) { @@ -106,13 +106,8 @@ const socketManager = { } if ( isExpired(token) ) { - console.warn("Expired token, waiting for refresh"); + console.warn("Expired token, reload after refresh"); setTimeout(() => { - const currentToken = JSON.parse(localStorage.getItem("token")); - if (isExpired(currentToken)) { - localStorage.removeItem("token"); - localStorage.removeItem("companyId"); - } window.location.reload(); },1000); return new DummySocket(); diff --git a/frontend/src/hooks/useAuth.js/index.js b/frontend/src/hooks/useAuth.js/index.js index 25a33b3a..86b7bfac 100644 --- a/frontend/src/hooks/useAuth.js/index.js +++ b/frontend/src/hooks/useAuth.js/index.js @@ -67,7 +67,7 @@ const useAuth = () => { setIsAuth(true); setUser(data.user); } catch (err) { - toastError(err?.message); + toastError(err); } } setLoading(false); @@ -152,7 +152,7 @@ Entre em contato com o Suporte para mais informações! `); //quebra linha } catch (err) { - toastError(err?.message); + toastError(err); setLoading(false); } }; @@ -172,7 +172,7 @@ Entre em contato com o Suporte para mais informações! `); setLoading(false); history.push("/login"); } catch (err) { - toastError(err?.message); + toastError(err); setLoading(false); } }; @@ -182,7 +182,7 @@ Entre em contato com o Suporte para mais informações! `); const { data } = await api.get("/auth/me"); return data; } catch (err) { - toastError(err?.message); + toastError(err); } }; diff --git a/frontend/src/layout/index.js b/frontend/src/layout/index.js index fb4e8003..24fa8388 100644 --- a/frontend/src/layout/index.js +++ b/frontend/src/layout/index.js @@ -45,7 +45,6 @@ import Brightness4Icon from '@material-ui/icons/Brightness4'; import Brightness7Icon from '@material-ui/icons/Brightness7'; import LanguageIcon from '@material-ui/icons/Language'; import { getBackendURL } from "../services/config"; -import NestedMenuItem from "material-ui-nested-menu-item"; const drawerWidth = 240; @@ -301,6 +300,11 @@ const LoggedInLayout = ({ children, themeToggle }) => { setMenuOpen(true); }; + const handleLanguageMenu = (event) => { + setAnchorEl(event.currentTarget); + setLanguageOpen(true); + }; + const handleCloseProfileMenu = () => { setAnchorEl(null); setMenuOpen(false); @@ -423,6 +427,10 @@ const LoggedInLayout = ({ children, themeToggle }) => { )} + + {theme.mode === 'dark' ? : } + + {
+ + + { {i18n.t("mainDrawer.appBar.user.profile")} - - {theme.mode === 'dark' ? i18n.t("mainDrawer.appBar.user.lightmode") : i18n.t("mainDrawer.appBar.user.darkmode")} - - - { - Object.keys(messages).map((m) => ( - handleChooseLanguage(m)}> - {messages[m].translations.mainDrawer.appBar.i18n.language} - - )) - } - {i18n.t("about.aboutthe")} {currentUser?.super ? "ticketz" : theme.appName} diff --git a/frontend/src/pages/Login/index.js b/frontend/src/pages/Login/index.js index b222a4d9..548db56c 100644 --- a/frontend/src/pages/Login/index.js +++ b/frontend/src/pages/Login/index.js @@ -103,9 +103,7 @@ const Login = () => { (data) => { setAllowSignup(data === "enabled"); } - ).catch((error) => { - console.log("Error reading setting",error); - }); + ) // eslint-disable-next-line react-hooks/exhaustive-deps }, []);