040c0ff4ca
Consolidate the config screens under a single /setup hub with permission- gated tabs (Devices/Tariff/Subscriptions/Site/Users/Roles/Shifts), collapsing the top nav to Booth·Shift·Setup; old top-level paths redirect. Users: add optional profile metadata (full name, phone, email, address) on create/edit. Theme: a light palette saved to the user's profile (users.theme), toggled in the header beside the language switch and applied on load like the language preference. Both ride on a single additive migration (0008). Shift history: a new GET /api/shifts folds the signed shift_z_report chain into completed shifts, SCOPED server-side — operators see only their own; holders of shift:cash see all with an operator + date-range filter. Surfaced as the Shifts tab; an operator cannot read another operator's takings (param spoofing is ignored). These three features share the router, api client and i18n catalogs, so they land together. Verified live: theme persists across reload, metadata round- trips to the DB, and shift scoping holds (operator self-only, admin all+filter). Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { QueryClientProvider } from "@tanstack/react-query";
|
|
import { RouterProvider } from "@tanstack/react-router";
|
|
import { fetchMe, type SessionUser } from "./api.js";
|
|
import { Login } from "./Login.js";
|
|
import { queryClient } from "./lib/query.js";
|
|
import { setLanguage } from "./lib/i18n/index.js";
|
|
import { applyTheme } from "./lib/theme.js";
|
|
import { router } from "./router.js";
|
|
|
|
// App root: bootstraps the session (cookie-based, from /api/auth/me), then hands
|
|
// off to TanStack Router inside the QueryClient provider. The router renders the
|
|
// terminal chrome + screens; auth gating stays here (Login until signed in), and
|
|
// the signed-in user flows into the router context for role-based route guards.
|
|
// See wiki/entities/react-vite-spa.md and local-jwt-auth.md.
|
|
|
|
export function App() {
|
|
const [user, setUser] = useState<SessionUser | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
fetchMe()
|
|
.then(setUser)
|
|
.finally(() => setLoading(false));
|
|
}, []);
|
|
|
|
// Apply the signed-in user's preferred language + theme whenever they resolve/
|
|
// change (login, bootstrap, or a toggle). Albanian + dark are the defaults before
|
|
// auth resolves; on logout, fall back to dark so the Login screen is consistent.
|
|
useEffect(() => {
|
|
if (user) {
|
|
setLanguage(user.language);
|
|
applyTheme(user.theme);
|
|
} else {
|
|
applyTheme("dark");
|
|
}
|
|
}, [user]);
|
|
|
|
if (loading) {
|
|
return <div className="flex h-screen items-center justify-center text-term-muted">loading…</div>;
|
|
}
|
|
if (!user) {
|
|
return (
|
|
<QueryClientProvider client={queryClient}>
|
|
<Login onLoggedIn={setUser} />
|
|
</QueryClientProvider>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<QueryClientProvider client={queryClient}>
|
|
<RouterProvider router={router} context={{ user, setUser }} />
|
|
</QueryClientProvider>
|
|
);
|
|
}
|