Compare commits
2 Commits
7ecd9dad3f
...
b6ebfcd631
Author | SHA1 | Date | |
---|---|---|---|
b6ebfcd631 | |||
ea965971f1 |
@@ -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<DashboardProps> = ({ 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 (
|
||||
<Flex h="100vh">
|
||||
<Sidebar
|
||||
|
@@ -39,6 +39,7 @@ const Layout: React.FC = () => {
|
||||
|
||||
const handleLogout = () => {
|
||||
Cookies.remove("token");
|
||||
window.location.pathname = "/";
|
||||
setIsLoggedIn(false);
|
||||
};
|
||||
|
||||
|
@@ -24,6 +24,7 @@ const Login: React.FC<{ onSuccess: () => void }> = ({ onSuccess }) => {
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center p-4">
|
||||
<form onSubmit={(e) => e.preventDefault()}>
|
||||
<Card.Root maxW="sm">
|
||||
<Card.Header>
|
||||
<Card.Title>Login</Card.Title>
|
||||
@@ -54,11 +55,12 @@ const Login: React.FC<{ onSuccess: () => void }> = ({ onSuccess }) => {
|
||||
{isError && (
|
||||
<MyAlert status="error" title={errorMsg} description={errorDsc} />
|
||||
)}
|
||||
<Button onClick={() => handleLogin()} variant="solid">
|
||||
<Button type="submit" onClick={() => handleLogin()} variant="solid">
|
||||
Login
|
||||
</Button>
|
||||
</Card.Footer>
|
||||
</Card.Root>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user