From 50d8e225e200f33ed64a1d326e47a9fc9f554cbb Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 23 Oct 2023 20:04:37 +0200 Subject: [PATCH] moved logout button to user profile --- public/locales/de/translation.json | 7 +++++ public/locales/en/translation.json | 8 +++++- src/App.js | 1 + src/Components/AppRoutes/index.js | 7 +++-- src/Components/DashboardLayout/index.js | 6 ++-- src/Components/PageContent/index.js | 4 ++- src/Components/SideMenu/index.js | 20 ------------- src/Contexts/RoboticsRobot.js | 37 ------------------------- src/Pages/UserProfile/index.js | 30 +++++++++++++++++++- src/utils.js | 1 + 10 files changed, 55 insertions(+), 66 deletions(-) delete mode 100644 src/Contexts/RoboticsRobot.js diff --git a/public/locales/de/translation.json b/public/locales/de/translation.json index e2bed92..f7e4ff8 100644 --- a/public/locales/de/translation.json +++ b/public/locales/de/translation.json @@ -394,6 +394,13 @@ "title": "Name für den neuen API-Schlüssel", "okText": "Erstellen" } + }, + "logout": { + "title": "Abmelden", + "popconfirm": { + "title": "Sind Sie sicher, dass Sie sich abmelden wollen?", + "description": "Sie werden von allen Geräten abgemeldet" + } } }, "icon": { "viewApiDoc": "Api-Dokumentation anschauen" }, diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index f1a5c23..45d60b2 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -406,7 +406,6 @@ "repeatNewPassword": "Repeat new password", "language": "Language" }, - "button": { "createApiKey": { "title": "Create New API Key", @@ -414,6 +413,13 @@ "title": "Name for the new API key", "okText": "Create" } + }, + "logout": { + "title": "Logout", + "popconfirm": { + "title": "Are you sure you want to logout?", + "description": "You will be logged out of all sessions" + } } }, "icon": { "viewApiDoc": "View API Documentation" }, diff --git a/src/App.js b/src/App.js index da6b0e9..f9dd862 100644 --- a/src/App.js +++ b/src/App.js @@ -19,6 +19,7 @@ import ScannerProvider from "./Contexts/ScannerContext"; export default function App() { const [notificationApi, notificationContextHolder] = notification.useNotification(); + const { userSession, setUserSession } = UseUserSession(); const [isWebSocketReady, setIsWebSocketReady] = useState(false); diff --git a/src/Components/AppRoutes/index.js b/src/Components/AppRoutes/index.js index a993a31..fcf5d94 100644 --- a/src/Components/AppRoutes/index.js +++ b/src/Components/AppRoutes/index.js @@ -48,7 +48,7 @@ function SuspenseFallback({ children }) { ); } -export default function AppRoutes() { +export default function AppRoutes({ userSession, setUserSession }) { const appContext = useAppContext(); console.info("appRoutes"); @@ -178,7 +178,10 @@ export default function AppRoutes() { path={Constants.ROUTE_PATHS.USER_PROFILE} element={ - + } /> diff --git a/src/Components/DashboardLayout/index.js b/src/Components/DashboardLayout/index.js index a3e3e02..df22ab8 100644 --- a/src/Components/DashboardLayout/index.js +++ b/src/Components/DashboardLayout/index.js @@ -47,8 +47,6 @@ export default function DashboardLayout({ userSession, setUserSession }) { > @@ -59,8 +57,6 @@ export default function DashboardLayout({ userSession, setUserSession }) { > @@ -69,6 +65,8 @@ export default function DashboardLayout({ userSession, setUserSession }) { diff --git a/src/Components/PageContent/index.js b/src/Components/PageContent/index.js index af42492..2c4f046 100644 --- a/src/Components/PageContent/index.js +++ b/src/Components/PageContent/index.js @@ -7,6 +7,8 @@ import { BreakpointLgWidth } from "../../utils"; export default function PageContent({ isSideMenuCollapsed, setIsSideMenuCollapsed, + userSession, + setUserSession, }) { return ( - + ); diff --git a/src/Components/SideMenu/index.js b/src/Components/SideMenu/index.js index bcffadb..82dcba1 100644 --- a/src/Components/SideMenu/index.js +++ b/src/Components/SideMenu/index.js @@ -5,7 +5,6 @@ import { DesktopOutlined, FileTextOutlined, HistoryOutlined, - LogoutOutlined, RobotOutlined, ScanOutlined, SettingOutlined, @@ -32,8 +31,6 @@ import { useWebSocketContext } from "../../Contexts/WebSocketContext"; import { SentMessagesCommands } from "../../Handlers/WebSocketMessageHandler"; export function SideMenuContent({ - userSession, - setUserSession, setIsSideMenuCollapsed, contentFirstRender, }) { @@ -267,23 +264,6 @@ export function SideMenuContent({ label: ` ${sideBarContext.username}`, icon: , key: Constants.ROUTE_PATHS.USER_PROFILE, - }, - { - label: t("sideMenu.logout"), - icon: , - key: "/logout", - onClick: () => { - setUserSession(); - window.location.href = "/"; - - fetch(`${Constants.API_ADDRESS}/user/auth/logout`, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - "X-Authorization": userSession, - }, - }).catch(console.error); - }, } ); diff --git a/src/Contexts/RoboticsRobot.js b/src/Contexts/RoboticsRobot.js deleted file mode 100644 index fc8c104..0000000 --- a/src/Contexts/RoboticsRobot.js +++ /dev/null @@ -1,37 +0,0 @@ -import { createContext, useContext, useState } from "react"; - -const preview = { - robots: [], - robotsTotalPages: 0, - unauthorizedRobots: [], - unauthorizedRobotsTotalPages: 0, -}; - -const RoboticsRobot = createContext(preview); - -export const useRoboticsRobotContext = () => useContext(RoboticsRobot); - -export function RoboticsRobotProvider({ children }) { - const [robots, setRobots] = useState([]); - const [robotsTotalPages, setRobotsTotalPages] = useState(0); - const [unauthorizedRobots, setUnauthorizedRobots] = useState([]); - const [unauthorizedRobotsTotalPages, setUnauthorizedRobotsTotalPages] = - useState(0); - - return ( - - {children} - - ); -} diff --git a/src/Pages/UserProfile/index.js b/src/Pages/UserProfile/index.js index 0cce430..5bb6f14 100644 --- a/src/Pages/UserProfile/index.js +++ b/src/Pages/UserProfile/index.js @@ -35,6 +35,7 @@ import { FileTextOutlined, InfoCircleOutlined, KeyOutlined, + LogoutOutlined, NotificationOutlined, } from "@ant-design/icons"; import { MyUserAvatar } from "../../Components/MyAvatar"; @@ -49,7 +50,7 @@ import { MyShowHiddenIcon, } from "../../Components/MyIcon"; -export default function UserProfile() { +export default function UserProfile({ userSession, setUserSession }) { const webSocketContext = useWebSocketContext(); const appContext = useAppContext(); const sideBarContext = useSideBarContext(); @@ -524,6 +525,33 @@ export default function UserProfile() { + + + { + setUserSession(); + window.location.href = "/"; + + fetch(`${Constants.API_ADDRESS}/user/auth/logout`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + "X-Authorization": userSession, + }, + }).catch(console.error); + }} + > + + + diff --git a/src/utils.js b/src/utils.js index d054398..c51547d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -232,6 +232,7 @@ export function GetUuid() { /** * user session */ + export function UseUserSession() { const getUserSession = () => { return getUserSessionFromLocalStorage();