2026-05-03 19:51:57 -05:00
|
|
|
|
|
|
|
|
import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
|
|
|
|
|
import { useAuth } from '@/hooks/useAuth';
|
|
|
|
|
import Layout from '@/components/layout/Layout';
|
2026-05-04 20:12:57 -05:00
|
|
|
import AppNavigation from '@/components/layout/Sidebar';
|
2026-05-03 19:51:57 -05:00
|
|
|
import { ReleaseNotesDialog } from '@/components/ReleaseNotesDialog';
|
|
|
|
|
import LoginPage from '@/pages/LoginPage';
|
|
|
|
|
import AdminPage from '@/pages/AdminPage';
|
|
|
|
|
import TrackerPage from '@/pages/TrackerPage';
|
2026-05-04 13:14:32 -05:00
|
|
|
import CalendarPage from '@/pages/CalendarPage';
|
2026-05-04 16:38:03 -05:00
|
|
|
import SummaryPage from '@/pages/SummaryPage';
|
2026-05-03 19:51:57 -05:00
|
|
|
import BillsPage from '@/pages/BillsPage';
|
|
|
|
|
import CategoriesPage from '@/pages/CategoriesPage';
|
|
|
|
|
import SettingsPage from '@/pages/SettingsPage';
|
|
|
|
|
import StatusPage from '@/pages/StatusPage';
|
2026-05-04 13:14:32 -05:00
|
|
|
import AnalyticsPage from '@/pages/AnalyticsPage';
|
2026-05-03 19:51:57 -05:00
|
|
|
import ReleaseNotesPage from '@/pages/ReleaseNotesPage';
|
2026-05-04 20:12:57 -05:00
|
|
|
import AboutPage from '@/pages/AboutPage';
|
2026-05-03 19:51:57 -05:00
|
|
|
import DataPage from '@/pages/DataPage';
|
|
|
|
|
import ProfilePage from '@/pages/ProfilePage';
|
|
|
|
|
|
|
|
|
|
function RequireAuth({ children, role }) {
|
|
|
|
|
const { user, singleUserMode } = useAuth();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
|
|
// Loading state
|
|
|
|
|
if (user === undefined) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center justify-center min-h-screen bg-background text-muted-foreground text-sm">
|
|
|
|
|
Loading...
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Single-user mode bypass
|
|
|
|
|
if (singleUserMode && role === 'user') return children;
|
|
|
|
|
|
|
|
|
|
// Not authenticated
|
|
|
|
|
if (!user) {
|
|
|
|
|
return <Navigate to="/login" state={{ from: location }} replace />;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 20:40:48 -05:00
|
|
|
const roleAllowed = !role || user.role === role || (role === 'user' && user.role === 'admin');
|
|
|
|
|
|
2026-05-04 23:34:24 -05:00
|
|
|
if (role === 'user' && user.is_default_admin) {
|
|
|
|
|
return <Navigate to="/admin" replace />;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 19:51:57 -05:00
|
|
|
// Role mismatch
|
2026-05-03 20:40:48 -05:00
|
|
|
if (!roleAllowed) {
|
2026-05-03 19:51:57 -05:00
|
|
|
return <Navigate to={user.role === 'admin' ? '/admin' : '/'} replace />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return children;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-04 20:12:57 -05:00
|
|
|
function AdminShell({ children }) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="min-h-screen bg-[radial-gradient(circle_at_top_left,oklch(var(--primary)/0.10),transparent_34rem),linear-gradient(180deg,oklch(var(--background)),oklch(var(--muted)/0.28))] text-foreground">
|
|
|
|
|
<AppNavigation adminMode />
|
|
|
|
|
<main className="mx-auto max-w-5xl px-4 py-6 sm:px-6 lg:px-8 lg:py-8">
|
|
|
|
|
{children}
|
|
|
|
|
</main>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 19:51:57 -05:00
|
|
|
export default function App() {
|
|
|
|
|
const { user } = useAuth();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{/* Release notes (only for user role) */}
|
|
|
|
|
{user?.role === 'user' && <ReleaseNotesDialog />}
|
|
|
|
|
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route path="/login" element={<LoginPage />} />
|
2026-05-04 20:12:57 -05:00
|
|
|
<Route path="/about" element={<AboutPage />} />
|
|
|
|
|
<Route path="/release-notes" element={<ReleaseNotesPage />} />
|
2026-05-03 19:51:57 -05:00
|
|
|
|
|
|
|
|
<Route
|
|
|
|
|
path="/admin"
|
|
|
|
|
element={
|
|
|
|
|
<RequireAuth role="admin">
|
|
|
|
|
<AdminPage />
|
|
|
|
|
</RequireAuth>
|
|
|
|
|
}
|
|
|
|
|
/>
|
2026-05-09 16:25:12 -05:00
|
|
|
<Route
|
|
|
|
|
path="/admin/about"
|
|
|
|
|
element={
|
|
|
|
|
<RequireAuth role="admin">
|
|
|
|
|
<AdminShell>
|
|
|
|
|
<AboutPage />
|
|
|
|
|
</AdminShell>
|
|
|
|
|
</RequireAuth>
|
|
|
|
|
}
|
|
|
|
|
/>
|
2026-05-04 20:12:57 -05:00
|
|
|
<Route
|
|
|
|
|
path="/admin/status"
|
|
|
|
|
element={
|
|
|
|
|
<RequireAuth role="admin">
|
|
|
|
|
<AdminShell>
|
|
|
|
|
<StatusPage />
|
|
|
|
|
</AdminShell>
|
|
|
|
|
</RequireAuth>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path="/status"
|
|
|
|
|
element={
|
|
|
|
|
<RequireAuth role="admin">
|
|
|
|
|
<Navigate to="/admin/status" replace />
|
|
|
|
|
</RequireAuth>
|
|
|
|
|
}
|
|
|
|
|
/>
|
2026-05-03 19:51:57 -05:00
|
|
|
|
|
|
|
|
<Route
|
|
|
|
|
element={
|
|
|
|
|
<RequireAuth role="user">
|
|
|
|
|
<Layout />
|
|
|
|
|
</RequireAuth>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Route index element={<TrackerPage />} />
|
2026-05-04 13:14:32 -05:00
|
|
|
<Route path="calendar" element={<CalendarPage />} />
|
2026-05-04 16:38:03 -05:00
|
|
|
<Route path="summary" element={<SummaryPage />} />
|
2026-05-03 19:51:57 -05:00
|
|
|
<Route path="bills" element={<BillsPage />} />
|
|
|
|
|
<Route path="categories" element={<CategoriesPage />} />
|
2026-05-04 13:14:32 -05:00
|
|
|
<Route path="analytics" element={<AnalyticsPage />} />
|
2026-05-03 19:51:57 -05:00
|
|
|
<Route path="settings" element={<SettingsPage />} />
|
|
|
|
|
<Route path="data" element={<DataPage />} />
|
|
|
|
|
<Route path="profile" element={<ProfilePage />} />
|
|
|
|
|
<Route path="*" element={<Navigate to="/" replace />} />
|
|
|
|
|
</Route>
|
|
|
|
|
</Routes>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|