Merge branch 'dev_v1-admin' into debian12_v1-admin

This commit is contained in:
2025-09-28 16:08:20 +02:00
3 changed files with 57 additions and 35 deletions

View File

@@ -1,5 +1,6 @@
import React from "react"; import React from "react";
import { useState } from "react"; import { useState } from "react";
import { useEffect } from "react";
import { Box, Heading, Text, Flex, Button } from "@chakra-ui/react"; import { Box, Heading, Text, Flex, Button } from "@chakra-ui/react";
import Sidebar from "./Sidebar"; import Sidebar from "./Sidebar";
import UserTable from "../components/UserTable"; import UserTable from "../components/UserTable";
@@ -17,6 +18,24 @@ const Dashboard: React.FC<DashboardProps> = ({ onLogout }) => {
const [activeView, setActiveView] = useState(""); 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 ( return (
<Flex h="100vh"> <Flex h="100vh">
<Sidebar <Sidebar

View File

@@ -39,6 +39,7 @@ const Layout: React.FC = () => {
const handleLogout = () => { const handleLogout = () => {
Cookies.remove("token"); Cookies.remove("token");
window.location.pathname = "/";
setIsLoggedIn(false); setIsLoggedIn(false);
}; };

View File

@@ -24,6 +24,7 @@ const Login: React.FC<{ onSuccess: () => void }> = ({ onSuccess }) => {
return ( return (
<div className="min-h-screen flex items-center justify-center p-4"> <div className="min-h-screen flex items-center justify-center p-4">
<form onSubmit={(e) => e.preventDefault()}>
<Card.Root maxW="sm"> <Card.Root maxW="sm">
<Card.Header> <Card.Header>
<Card.Title>Login</Card.Title> <Card.Title>Login</Card.Title>
@@ -54,11 +55,12 @@ const Login: React.FC<{ onSuccess: () => void }> = ({ onSuccess }) => {
{isError && ( {isError && (
<MyAlert status="error" title={errorMsg} description={errorDsc} /> <MyAlert status="error" title={errorMsg} description={errorDsc} />
)} )}
<Button onClick={() => handleLogin()} variant="solid"> <Button type="submit" onClick={() => handleLogin()} variant="solid">
Login Login
</Button> </Button>
</Card.Footer> </Card.Footer>
</Card.Root> </Card.Root>
</form>
</div> </div>
); );
}; };