NGU-Web/src/App.tsx
Aidan Dona e8aab4d7ec Planning Center: compare a People list with the site's people and apply what an admin picks
Migration 085 adds people.pco_id and Site settings' list. Data ->
Planning Center fetches the list, suggests matches (linked, same email,
same name), shows each field that would change (Planning Center wins),
and applies the chosen links, updates and new unpublished people in one
transaction. Needs PCO_APP_ID and PCO_SECRET.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 00:46:29 -05:00

160 lines
7 KiB
TypeScript

import {
BrowserRouter,
Routes,
Route,
Outlet,
Navigate,
} from "react-router-dom"
import { lazy, Suspense } from "react"
/*Components*/
import Layout from "./components/Layout.tsx"
/*Libraries*/
import { AuthProvider, RequireAuth } from "./lib/auth.tsx"
import RequireRole from "./pages/admin/RequireRole.tsx"
/*Pages*/
// Every page, the front page included, and all of the admin, is
// fetched when first visited: a visitor never downloads the admin,
// and a page's own parts come with it. The front page's data is asked
// for by its HTML before this runs (pageMeta.js, preload). Layout and
// AdminLayout wrap their <Outlet /> in <Suspense>, so the header stays
// put while a page loads.
/* A page's chunk can be missing when a deploy replaced the build while
this tab still ran the old one. Reload once to pick up the new
build; if that doesn't help, let the error surface. */
const CHUNK_RELOAD = "site-chunk-reload"
const lazyPage = (load) =>
lazy(() =>
load()
.then((page) => {
try {
sessionStorage.removeItem(CHUNK_RELOAD)
} catch {}
return page
})
.catch((err) => {
const key = CHUNK_RELOAD
let reloaded = false
try {
reloaded = sessionStorage.getItem(key) === "1"
sessionStorage.setItem(key, "1")
} catch {}
if (!reloaded) {
window.location.reload()
return new Promise(() => {})
}
throw err
}),
)
// Every page at its address (Pages → Page management): its sections.
const PageAtPath = lazyPage(() => import("./pages/PageAtPath.tsx"))
// The front page: its sections, in the front page's layout.
const SitePage = lazyPage(() => import("./pages/SitePage.tsx"))
// Profile accounts (076): signing in, an invite's welcome, the profile.
const SignIn = lazyPage(() => import("./pages/SignIn.tsx"))
const AccountWelcome = lazyPage(() => import("./pages/AccountWelcome.tsx"))
const Account = lazyPage(() => import("./pages/Account.tsx"))
/*Entity Pages*/
const EventDetail = lazyPage(() => import("./pages/EventDetail.tsx"))
const OrganizationDetail = lazyPage(
() => import("./pages/OrganizationDetail.tsx"),
)
const TeamDetail = lazyPage(() => import("./pages/TeamDetail.tsx"))
const AwardDetail = lazyPage(() => import("./pages/AwardDetail.tsx"))
const PersonDetail = lazyPage(() => import("./pages/PersonDetail.tsx"))
const BlogPost = lazyPage(() => import("./pages/BlogPost.tsx"))
const DirectoryPage = lazyPage(() => import("./pages/DirectoryPage.tsx"))
const SchedulePresent = lazyPage(() => import("./pages/SchedulePresent.tsx"))
/*Admin Pages*/
const AdminLayout = lazyPage(() => import("./pages/admin/AdminLayout.tsx"))
const AdminLogin = lazyPage(() => import("./pages/admin/AdminLogin.tsx"))
const AdminPanel = lazyPage(() => import("./pages/admin/AdminPanel.tsx"))
const AdminHome = lazyPage(() => import("./pages/admin/AdminHome.tsx"))
const AdminFeedback = lazyPage(() => import("./pages/admin/AdminFeedback.tsx"))
const AdminMedia = lazyPage(() => import("./pages/admin/AdminMedia.tsx"))
const AdminClips = lazyPage(() => import("./pages/admin/AdminClips.tsx"))
const AdminVideoFrames = lazyPage(() => import("./pages/admin/AdminVideoFrames.tsx"))
const AdminNewsletter = lazyPage(() => import("./pages/admin/AdminNewsletter.tsx"))
const AdminProfiles = lazyPage(() => import("./pages/admin/AdminProfiles.tsx"))
const AdminConvert = lazyPage(() => import("./pages/admin/AdminConvert.tsx"))
const AdminPco = lazyPage(() => import("./pages/admin/AdminPco.tsx"))
const EntityList = lazyPage(() => import("./pages/admin/EntityList.tsx"))
const EntityEdit = lazyPage(() => import("./pages/admin/EntityEdit.tsx"))
export default function App() {
return (
<BrowserRouter>
{/* The whole app: the site shows a profile link and hidden pages by who's signed in. */}
<AuthProvider>
<Routes>
{/* Layout renders the nav once and swaps page content into <Outlet /> */}
<Route element={<Layout />}>
<Route index element={<SitePage key="home" id="home" />} />
<Route path="/events/:id" element={<EventDetail />} />
<Route path="/regions/:id" element={<OrganizationDetail />} />
<Route path="/groups/:id" element={<OrganizationDetail />} />
<Route path="/partners/:id" element={<OrganizationDetail />} />
<Route path="/organizations/:id" element={<OrganizationDetail />} />
<Route path="/teams/:id" element={<TeamDetail />} />
<Route path="/awards/:id" element={<AwardDetail />} />
<Route path="/people/:id" element={<PersonDetail />} />
<Route path="/blog/:id" element={<BlogPost />} />
<Route path="/directory/:id" element={<DirectoryPage />} />
<Route path="sign-in" element={<SignIn />} />
<Route path="account" element={<Account />} />
<Route path="account/welcome" element={<AccountWelcome />} />
{/* Every page of the site: Pages → Page management (PageAtPath). */}
<Route path="*" element={<PageAtPath />} />
</Route>
{/* A schedule as a slideshow for a screen: full screen, no Layout. */}
<Route
path="/events/:id/present"
element={
<Suspense fallback={null}>
<SchedulePresent />
</Suspense>
}
/>
<Route
element={
<Suspense fallback={null}>
<Outlet />
</Suspense>
}
>
<Route path="/admin/login" element={<AdminLogin />} />
<Route element={<RequireAuth />}>
<Route path="/admin" element={<AdminLayout />}>
<Route index element={<Navigate to="/admin/home" replace />} />
<Route path="home" element={<AdminHome />} />
<Route element={<RequireRole role="superadmin" />}>
<Route path="panel" element={<AdminPanel />} />
</Route>
<Route path="feedback" element={<AdminFeedback />} />
<Route path="data-requests" element={<AdminFeedback kind="privacy" />} />
<Route path="requests" element={<AdminFeedback kind="content" />} />
<Route path="media" element={<AdminMedia />} />
<Route path="newsletter" element={<AdminNewsletter />} />
<Route path="convert" element={<AdminConvert />} />
<Route element={<RequireRole role="editor" />}>
<Route path="thumbnails" element={<AdminVideoFrames />} />
</Route>
<Route element={<RequireRole role="admin" />}>
<Route path="clips" element={<AdminClips />} />
<Route path="profiles" element={<AdminProfiles />} />
<Route path="pco" element={<AdminPco />} />
</Route>
<Route path=":entity" element={<EntityList />} />
<Route path=":entity/:id" element={<EntityEdit />} />
</Route>
</Route>
</Route>
</Routes>
</AuthProvider>
</BrowserRouter>
)
}