From ea965971f1e6200b6b62f7b2b1835970906f8a10 Mon Sep 17 00:00:00 2001 From: Theis Gaedigk Date: Sun, 28 Sep 2025 16:07:39 +0200 Subject: [PATCH] Refactor Dashboard and Login components: add URL synchronization in Dashboard, update Login form submission handling --- admin/src/Layout/Dashboard.tsx | 19 +++++++++ admin/src/Layout/Layout.tsx | 1 + admin/src/Layout/Login.tsx | 72 +++++++++++++++++----------------- 3 files changed, 57 insertions(+), 35 deletions(-) diff --git a/admin/src/Layout/Dashboard.tsx b/admin/src/Layout/Dashboard.tsx index 1b53d6d..fd37bb6 100644 --- a/admin/src/Layout/Dashboard.tsx +++ b/admin/src/Layout/Dashboard.tsx @@ -1,5 +1,6 @@ import React from "react"; import { useState } from "react"; +import { useEffect } from "react"; import { Box, Heading, Text, Flex, Button } from "@chakra-ui/react"; import Sidebar from "./Sidebar"; import UserTable from "../components/UserTable"; @@ -17,6 +18,24 @@ const Dashboard: React.FC = ({ onLogout }) => { const [activeView, setActiveView] = useState(""); + useEffect(() => { + if (typeof window === "undefined") return; + const raw = window.location.pathname.slice(1); + if (raw) { + setActiveView(decodeURIComponent(raw)); + } + }, []); + + // Sync URL when activeView changes, without reloading + useEffect(() => { + if (typeof window === "undefined") return; + if (!activeView) return; + const desired = `/${encodeURIComponent(activeView)}`; + if (window.location.pathname !== desired) { + window.history.replaceState(null, "", desired); + } + }, [activeView]); + return ( { const handleLogout = () => { Cookies.remove("token"); + window.location.pathname = "/"; setIsLoggedIn(false); }; diff --git a/admin/src/Layout/Login.tsx b/admin/src/Layout/Login.tsx index 818c9dd..813a7e6 100644 --- a/admin/src/Layout/Login.tsx +++ b/admin/src/Layout/Login.tsx @@ -24,41 +24,43 @@ const Login: React.FC<{ onSuccess: () => void }> = ({ onSuccess }) => { return (
- - - Login - - Bitte unten Ihre Admin Zugangsdaten eingeben. - - - - - - username - setUsername(e.target.value)} - /> - - - password - setPassword(e.target.value)} - /> - - - - - {isError && ( - - )} - - - +
e.preventDefault()}> + + + Login + + Bitte unten Ihre Admin Zugangsdaten eingeben. + + + + + + username + setUsername(e.target.value)} + /> + + + password + setPassword(e.target.value)} + /> + + + + + {isError && ( + + )} + + + +
); };