Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 1x 1x | /**
* @file AppRouter.tsx
* @description
* Application routing for Smart Supply Pro.
*
* @design
* - Public routes (login, OAuth callback, logout-success, home/landing) render
* *outside* of the application shell to keep the unauthenticated UI minimal.
* - Authenticated routes render *inside* `AppShell` (SAP/Fiori-style chrome),
* and are protected by `RequireAuth`.
* - A single 404 fallback (NotFoundPage) handles unknown routes.
*
* @notes
* - We intentionally removed the legacy `Topbar.tsx`. The AppBar / nav lives in
* `AppShell`, which wraps all authenticated pages.
* - If the authentication context is still resolving on first load, we render a
* centered progress indicator to avoid guard flicker.
*/
import * as React from 'react';
import { Routes, Route } from 'react-router-dom';
import { Box, CircularProgress } from '@mui/material';
import { useAuth } from '../hooks/useAuth';
import { RequireAuth } from '../features/auth';
import AppShell from '../app/layout/AppShell';
// Public pages
import Home from '../pages/home/Home';
import LoginPage from '../pages/auth/LoginPage';
import AuthCallback from '../pages/auth/AuthCallback';
import LogoutSuccess from '../pages/auth/LogoutSuccess';
import NotFoundPage from '../pages/system/NotFoundPage';
import { AppPublicShell } from '../app/public-shell';
// Authenticated pages
import Dashboard from '../pages/dashboard/Dashboard';
import InventoryBoard from '../pages/inventory/InventoryBoard';
import SuppliersBoard from '../pages/suppliers/SuppliersBoard';
import LogoutPage from '../pages/auth/LogoutPage';
import Analytics from '../pages/analytics/Analytics';
const LoadingScreen: React.FC = () => (
<Box sx={{ display: 'grid', placeItems: 'center', height: '100dvh' }}>
<CircularProgress />
</Box>
);
/**
* Top-level router. Decides between public vs. authenticated route groups.
*/
const AppRouter: React.FC = () => {
const { loading } = useAuth();
// During initial auth bootstrap (e.g., session cookie check), avoid rendering routes.
if (loading) return <LoadingScreen />;
return (
<>
<Routes>
{/**
* PUBLIC ROUTES (no AppShell)
*/}
<Route element={<AppPublicShell />}>
<Route path="/" element={<Home />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/auth" element={<AuthCallback />} />
<Route path="/logout-success" element={<LogoutSuccess />} />
</Route>
{/* Make /logout public: it's safe & avoids RequireAuth race during cleanup */}
<Route path="/logout" element={<LogoutPage />} />
{/**
* AUTHENTICATED ROUTES (inside AppShell)
* - Children below render within AppShell's AppBar+Drawer+Content layout.
* - Each child is additionally protected with RequireAuth for safety.
*/}
<Route element={<AppShell />}>
<Route
path="/dashboard"
element={
<RequireAuth allowDemo>
<Dashboard />
</RequireAuth>
}
/>
{/**
* Inventory route (read-only in demo – write ops blocked by backend/dialogs).
* Demo users are allowed to access for viewing, but cannot modify data.
* @enterprise Guarded route: requires auth, allowDemo enables demo user access.
*/}
<Route
path="/inventory"
element={
<RequireAuth allowDemo>
<InventoryBoard />
</RequireAuth>
}
/>
<Route
path="/suppliers"
element={
<RequireAuth allowDemo>
<SuppliersBoard />
</RequireAuth>
}
/>
<Route
path="/analytics/:section?"
element={
<RequireAuth allowDemo>
<Analytics />
</RequireAuth>
}
/>
</Route>
{/**
* 404 FALLBACK: unknown paths (public)
* - Offers a button to go to Dashboard if logged-in, or Login otherwise.
*/}
<Route path="*" element={<NotFoundPage />} />
</Routes>
</>
);
};
export default AppRouter;
|