import { Suspense } from "react"; import { OrgChartClient } from "@/components/orgchart/OrgChartClient"; import type { OrgUnitNode } from "@/components/orgchart/types"; import { todayIso } from "@/lib/format"; import { loadOrgAsOf } from "@/lib/orgchart-data"; import { parseIsoDateParam } from "@/lib/reports"; import { currentUserId } from "@/lib/auth/session"; import { withUser } from "@/lib/db"; type SearchParams = { asOf?: string; focus?: string }; const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; export default async function OrgChartPage({ searchParams }: { searchParams: Promise }) { const params = await searchParams; const today = todayIso(); const asOf = parseIsoDateParam(params.asOf) ?? today; // Only ever used to match against ids already on the page, but validated // so a junk value can't reach the client as an arbitrary string. const focusId = params.focus && UUID.test(params.focus) ? params.focus : null; const { org, units } = await withUser(await currentUserId(), async (tx) => { const [org, units] = await Promise.all([ loadOrgAsOf(tx, asOf), tx.selectFrom("org_units").select(["id", "org_number", "name", "parent_id", "unit_type"]).orderBy("org_number").execute(), ]); return { org, units }; }); return ( ); }