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") // valid_from/valid_to nur hier: die Angaben zur Einheit zeigen sie, // der Druck braucht sie nicht. .select(["id", "org_number", "name", "parent_id", "unit_type", "valid_from", "valid_to"]) // Zum Stichtag — sonst zeigt die Struktursicht zum 01.01.2020 // Einheiten, die es damals nicht gab (D.06). .where("valid_from", "<=", asOf) .where((eb) => eb.or([eb("valid_to", "is", null), eb("valid_to", ">", asOf)])) .orderBy("org_number") .execute(), ]); return { org, units }; }); return ( ); }