6982a8040d
Server-component schedule page backed by a pure data layer (src/db/grid.ts): gridForWeek() returns positions + instances (->slots->assignments), and defaultWeekStart() defaults to the earliest upcoming published instance so a seeded DB shows data on first load. Week nav via ?week=YYYY-MM-DD (server rendered, no client state). Fixes two latent bugs that kept the grid empty/incorrect: - tz: weekdayInTz()/nextSundaysInTz() built Date.UTC(y,mo-1,d) from a LOCAL date string and read its weekday; for America/New_York (UTC-5) UTC midnight lands the previous evening, so the seed materialized instances on Mondays and the default week was off by one. weekdayInTz now builds the local-midnight instant via utcOffsetMs; nextSundaysInTz uses weekdayInTz + addDaysISO. - grid: occursOn (date mode) was run through dateInTimezone(), reinterpreting the UTC instant as wall-clock and shifting a day early; now extracts the UTC calendar date directly (occursOnISO). - schedule-grid: <table className=... collapse ...> set visibility: collapse (Tailwind 'collapse'), hiding the whole grid server-rendered-but-invisible; changed to border-collapse. E2E: new schedule-grid.spec.ts + shell.spec.ts grid assertion. Full suite green: tsc, eslint, 178 unit tests, next build, 6/6 Playwright.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { gridForWeek, defaultWeekStart } from "@/db/grid";
|
|
import { WeekNav } from "@/components/app/week-nav";
|
|
import { ScheduleGrid } from "@/components/app/schedule-grid";
|
|
|
|
export const metadata = { title: "Schedule" };
|
|
|
|
/**
|
|
* Scheduling grid (unit D7). Read-only: rows = instances, cols = positions,
|
|
* with week navigation via `?week=YYYY-MM-DD` (a Sunday). Defaults to the week
|
|
* of the earliest upcoming published instance so a seeded DB shows data at once.
|
|
*/
|
|
export default async function SchedulePage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ week?: string }>;
|
|
}) {
|
|
const { week: paramWeek } = await searchParams;
|
|
// Validate the param is a YYYY-MM-DD string; fall back to the default week.
|
|
const weekStart =
|
|
typeof paramWeek === "string" && /^\d{4}-\d{2}-\d{2}$/.test(paramWeek)
|
|
? paramWeek
|
|
: await defaultWeekStart();
|
|
|
|
const week = await gridForWeek(weekStart);
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
<div>
|
|
<h1 className="text-lg font-semibold tracking-tight">Schedule</h1>
|
|
<p className="text-sm text-muted-foreground">
|
|
Service instances for the week and who is on each position.
|
|
</p>
|
|
</div>
|
|
|
|
<WeekNav weekStart={weekStart} />
|
|
<ScheduleGrid week={week} />
|
|
</div>
|
|
);
|
|
}
|