mega-plant/components/PlantMapLoader.tsx
David 14ec899ca9 Sites: a real Sites list, with the unbooked lines bookable to a site
The container lines (MPLANT04/MPLANT05) have no matching plant item, so they
sat unbooked forever with no way to account for them. They can now be booked
to a SITE instead.

`sites` is a new PocketBase collection derived from the invoices — each
distinct invoice site becomes a site, created as invoices are imported. They
are never hand-typed, and never deleted: a site can carry notes and hold line
bookings, so removing one would orphan that history.

/sites lists every site with its revenue ex VAT, its VAT, the total billed,
how many invoices and machines it carries, and how many lines are still
outstanding. Each row links to a detail page listing the site's invoices and
every line item with its ex-VAT/VAT/total split. Nav: Dashboard is now a
group with Overview and Sites.

Booking a line to a site posts NO income — there is no machine to carry it —
it only marks the line accounted for, so it stops showing as unbooked. Exactly
one of booked_asset / booked_site is ever set, and a line with neither is what
surfaces as unbooked everywhere.

One container per site, as specified: once a machine-less line has taken a
site, that site is withheld from the next one's picker and shown disabled
("already has one") rather than hidden. Free sites sort to the top. The rule is
enforced server-side too, so it does not depend on the UI being the only way in —
re-posting a taken site is refused with 409. Verified: booking The Hills, then
trying again, then taking West Park, and the remaining line sees 8 free and 2
taken. Clearing a booking frees its site.

The site picker only appears on lines that need it — no machine, or one already
booked to a site — so fully-booked rows keep a single control.

Also fixed the Sidebar's group-active check, which derived its prefix from the
first child. For a group whose first child is "/" that yields "/" and matched
every route, so Dashboard would have been highlighted on every page.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-10-02 16:24:06 +02:00

43 lines
1.9 KiB
TypeScript

"use client";
import dynamic from "next/dynamic";
import { Loader2, MapPinned } from "lucide-react";
/**
* Leaflet reads `window` at module scope, so it cannot be evaluated during SSR.
* `next/dynamic` with `ssr: false` keeps it out of the server bundle entirely —
* this file is the client boundary that makes that possible (App Router only
* allows `ssr: false` inside a Client Component).
*/
const PlantMap = dynamic(() => import("./PlantMap").then((m) => m.PlantMap), {
ssr: false,
loading: () => <MapSkeleton />,
});
function MapSkeleton() {
return (
<div className="grid lg:grid-cols-[minmax(0,1fr)_340px] gap-4 items-start">
<div className="relative rounded-2xl overflow-hidden border border-gray-200 dark:border-white/5 shadow-sm bg-gray-100 dark:bg-[#1e2732] h-[52vh] min-h-[320px] lg:h-[calc(100vh-15rem)] lg:min-h-[560px] grid place-items-center">
<div className="text-center">
<Loader2 className="w-6 h-6 mx-auto text-[#30638E] animate-spin" />
<p className="mt-2 text-xs text-gray-500 dark:text-gray-400">Loading map…</p>
</div>
</div>
<div className="rounded-2xl border border-gray-200 dark:border-white/5 bg-white dark:bg-[#131a21] shadow-sm overflow-hidden">
<div className="p-4 border-b border-gray-100 dark:border-white/5">
<div className="h-4 w-20 rounded bg-gray-200 dark:bg-white/10 animate-pulse" />
<div className="mt-3 h-11 rounded-lg bg-gray-100 dark:bg-white/5 animate-pulse" />
</div>
<div className="p-4 space-y-3">
{Array.from({ length: 6 }).map((_, i) => (
<div key={i} className="h-9 rounded bg-gray-100 dark:bg-white/5 animate-pulse" />
))}
</div>
</div>
</div>
);
}
export function PlantMapLoader(props: React.ComponentProps<typeof import("./PlantMap").PlantMap>) {
return <PlantMap {...props} />;
}