import { BrowserRouter, Routes, Route, Navigate, useLocation } from 'react-router-dom';
import { BusinessProvider, useBusiness } from './context/BusinessContext';
import Sidebar from './components/Sidebar';
import Businesses from './pages/Businesses';
import Providers from './pages/Providers';
import GlobalSms from './pages/GlobalSms';
import Events from './pages/Events';
import Templates from './pages/Templates';
import { Link } from 'react-router-dom';
function SubLayout({ children }) {
const { activeBusinessId } = useBusiness();
return (
);
}
// Guard: redirect to / if no active business in session
// Also enforce cURL-first: redirect to global-sms if no cURL is saved yet.
function BusinessGuard({ children, isGlobalSmsRoute }) {
const { activeBusinessId, loading, hasGlobalSms } = useBusiness();
const location = useLocation();
if (loading) {
return (
);
}
if (!activeBusinessId) {
return ;
}
if (!hasGlobalSms && !isGlobalSmsRoute && !location.pathname.endsWith('/settings')) {
// Only allow global SMS page if cURL constraint is not met yet
// Optionally allow settings, but strictly planning says "must go to Global SMS first".
// We enforce only global SMS by redirecting other pages.
return ;
}
return children;
}
export default function App() {
return (
} />
} />
} />
} />
} />
} />
);
}