import { Routes, Route, Link, useLocation, Navigate } from "react-router-dom"; import { useEffect, useState } from "react"; import { AppointmentsPage } from "./pages/Appointments.js"; import { ClientsPage } from "./pages/Clients.js"; import { ServicesPage } from "./pages/Services.js"; import { StaffPage } from "./pages/Staff.js"; import { InvoicesPage } from "./pages/Invoices.js"; import { BookPage } from "./pages/Book.js"; import { ReportsPage } from "./pages/Reports.js"; import { GroupBookingPage } from "./pages/GroupBooking.js"; import { SettingsPage } from "./pages/Settings.js"; import { CustomerPortal } from "./portal/CustomerPortal.js"; import { DevLoginSelector, getDevUser } from "./pages/DevLoginSelector.js"; import { DevSessionIndicator } from "./components/DevSessionIndicator.js"; import { BrandingProvider, useBranding } from "./BrandingContext.js"; import { GlobalSearch } from "./components/GlobalSearch.js"; const NAV_LINKS = [ { to: "/admin", label: "Appointments" }, { to: "/admin/clients", label: "Clients" }, { to: "/admin/services", label: "Services" }, { to: "/admin/staff", label: "Staff" }, { to: "/admin/invoices", label: "Invoices" }, { to: "/admin/group-bookings", label: "Group Bookings" }, { to: "/admin/reports", label: "Reports" }, { to: "/admin/settings", label: "Settings" }, { to: "/", label: "Customer Portal" }, ]; function AdminLayout() { const location = useLocation(); const { branding } = useBranding(); const logoSrc = branding.logoBase64 && branding.logoMimeType ? `data:${branding.logoMimeType};base64,${branding.logoBase64}` : null; return (
} /> } /> } /> } /> } /> } /> } /> } /> } />
); } export function App() { const location = useLocation(); const [authDisabled, setAuthDisabled] = useState(null); useEffect(() => { fetch("/api/dev/config") .then((r) => r.json()) .then((data) => setAuthDisabled(data.authDisabled === true)) .catch(() => setAuthDisabled(false)); }, []); // Show login selector page if (location.pathname === "/login") { return ; } // While checking auth config, render nothing briefly if (authDisabled === null) return null; // If auth is disabled and no dev user is selected, redirect to login selector if (authDisabled && !getDevUser() && location.pathname !== "/login") { return ; } return ( {location.pathname.startsWith("/admin") ? ( <> } /> {authDisabled && } ) : ( <> {authDisabled && } )} ); }