v1.0.0
This commit is contained in:
68
frontend/src/App.jsx
Normal file
68
frontend/src/App.jsx
Normal file
@@ -0,0 +1,68 @@
|
||||
import { Routes, Route, Navigate, Outlet } from 'react-router-dom';
|
||||
import { useAuth } from './auth/AuthContext.jsx';
|
||||
import { useHouseholdContext } from './household/HouseholdContext.jsx';
|
||||
import Login from './pages/Login.jsx';
|
||||
import Register from './pages/Register.jsx';
|
||||
import ForgotPassword from './pages/ForgotPassword.jsx';
|
||||
import ResetPassword from './pages/ResetPassword.jsx';
|
||||
import JoinInvite from './pages/JoinInvite.jsx';
|
||||
import Onboarding from './pages/Onboarding.jsx';
|
||||
import Dashboard from './pages/Dashboard.jsx';
|
||||
import AddExpense from './pages/AddExpense.jsx';
|
||||
import History from './pages/History.jsx';
|
||||
import Stats from './pages/Stats.jsx';
|
||||
import Settings from './pages/Settings.jsx';
|
||||
import BottomNav from './components/BottomNav.jsx';
|
||||
import OfflineBanner from './components/OfflineBanner.jsx';
|
||||
import InstallBanner from './components/InstallBanner.jsx';
|
||||
|
||||
function RequireAuth() {
|
||||
const { isAuthenticated } = useAuth();
|
||||
if (!isAuthenticated) return <Navigate to="/login" replace />;
|
||||
return <Outlet />;
|
||||
}
|
||||
|
||||
function RequireHousehold() {
|
||||
const { households, householdsLoading } = useHouseholdContext();
|
||||
if (householdsLoading) return <div className="page-loading">Ładowanie…</div>;
|
||||
if (households.length === 0) return <Navigate to="/onboarding" replace />;
|
||||
return <Outlet />;
|
||||
}
|
||||
|
||||
function Layout() {
|
||||
return (
|
||||
<div className="app-shell">
|
||||
<OfflineBanner />
|
||||
<InstallBanner />
|
||||
<main className="app-content">
|
||||
<Outlet />
|
||||
</main>
|
||||
<BottomNav />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/register" element={<Register />} />
|
||||
<Route path="/forgot-password" element={<ForgotPassword />} />
|
||||
<Route path="/reset-password" element={<ResetPassword />} />
|
||||
<Route path="/join/:code" element={<JoinInvite />} />
|
||||
<Route element={<RequireAuth />}>
|
||||
<Route path="/onboarding" element={<Onboarding />} />
|
||||
<Route element={<RequireHousehold />}>
|
||||
<Route element={<Layout />}>
|
||||
<Route path="/" element={<Dashboard />} />
|
||||
<Route path="/add" element={<AddExpense />} />
|
||||
<Route path="/history" element={<History />} />
|
||||
<Route path="/stats" element={<Stats />} />
|
||||
<Route path="/settings" element={<Settings />} />
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user