Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"react-chartjs-2": "^5.3.1",
"react-dom": "^19.2.0",
"react-resizable-panels": "^3.0.6",
"react-router-dom": "^7.13.0",
"recharts": "^2.15.4"
},
"devDependencies": {
Expand Down
20 changes: 18 additions & 2 deletions webapp/src/app/routes/AppRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { MainPage } from '@pages';
import { MainPage } from "@/pages";
import { lazy } from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { AdminRoute } from "./lib/ProtectedRoute";

const AdminPage = lazy(() => import("@/pages/admin"));
const LoginPage = lazy(() => import("@/pages/login"));

export function AppRouter() {
return <MainPage />;
return (
<BrowserRouter>
<Routes>
<Route path="" element={<MainPage />} />
<Route path="login" element={<LoginPage />} />
<Route element={<AdminRoute />}>
<Route path="admin" element={<AdminPage />} />
</Route>
</Routes>
</BrowserRouter>
);
}
17 changes: 17 additions & 0 deletions webapp/src/app/routes/lib/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useAuth } from "@/app/providers/AuthProvider";
import { Navigate, Outlet, useLocation } from "react-router-dom";

/**
* Route guard for admin routes.
* Redirect to login page if not authenticated.
*/
export function AdminRoute() {
const { isAuthenticated } = useAuth();
const location = useLocation();

if (!isAuthenticated) {
return <Navigate to="/login" state={{ from: location }} replace />;
}

return <Outlet />;
}
11 changes: 7 additions & 4 deletions webapp/src/pages/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { useApi } from "@providers";
import { DashboardPopover, Map, MapSidebar } from "@/widgets";
import { Header } from "@components";
import { useApi } from "@providers";
import { SidebarProvider } from "@ui/sidebar";
import { DashboardPopover, MapSidebar, Map } from "@/widgets";
import { useEffect, useState } from "react";

import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
} from "@/components/ui/resizable"
} from "@/components/ui/resizable";
import { useNavigate } from "react-router-dom";

export interface MainPageProps {
userData?: unknown;
}

export function MainPage() {
const navigate = useNavigate();
const client = useApi();
const [data, setData] = useState<unknown | null>(null);

Expand All @@ -23,10 +25,11 @@ export function MainPage() {
.then((json) => setData(json.data))
.catch((err) => console.error("fetchData error", err));
}, []);

return (
<div className="flex flex-col h-screen">
<Header
onLogin={() => console.log("Login clicked")}
onLogin={() => navigate('/login')}
onLogout={() => console.log("Logout clicked")}
isLogin={false} />

Expand Down
7 changes: 7 additions & 0 deletions webapp/src/pages/admin/AdminPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function AdminPage() {
return (
<div className="flex flex-col h-screen bg-background items-center justify-center">
<h1>Admin Page</h1>
</div>
);
}
1 change: 1 addition & 0 deletions webapp/src/pages/admin/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AdminPage as default } from "./AdminPage";
3 changes: 1 addition & 2 deletions webapp/src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { LoginPage } from './LoginPage';
export { MainPage } from './MainPage';
export { MainPage } from "./MainPage";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function LoginPage() {
return (
<div>
<div className="flex flex-col h-screen bg-background items-center justify-center">
<h1>Login Page</h1>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions webapp/src/pages/login/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LoginPage as default } from "./LoginPage";