Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+13
-49
@@ -1,26 +1,27 @@
|
||||
// AK-P16b · bookings list route (M06 Block C). Loader builds BookingListVM from the
|
||||
// tenant's appointments, server-side owner-filtered (read_own → own provider rows
|
||||
// only, DoD 6). Module off -> locked empty; missing bookings.read_own -> 404.
|
||||
// Baseline functional table (data-ui-id markers); bespoke polish follows D-P16.
|
||||
// Interim ~/ui screen with tab buckets (AD-28); final polish follows D-P16.
|
||||
|
||||
import { type LoaderFunctionArgs, useLoaderData } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { buildBookingListVM, bookingStatusKey, type BookingListRow, type BookingListVM } from "@hivegrid/view-models";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { loadBookingContext, requireBookingPermission, canReadAllBookings, BOOKING_PERMISSIONS } from "~/modules/booking/routes/bookingAccess.server";
|
||||
import { BOOKING_MODULE_KEY, bookingDetailPath, notFoundResponse } from "~/modules/booking/routes/bookingRoutePaths";
|
||||
import { BOOKING_MODULE_KEY, bookingDetailPath, bookingPagesListPath, notFoundResponse } from "~/modules/booking/routes/bookingRoutePaths";
|
||||
import { listAppointmentsForTenant } from "~/modules/booking/db/booking.db.server";
|
||||
import { BookingListPage } from "~/components/screens/booking/BookingListPage";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
|
||||
type LoaderData = { title: string; vm: BookingListVM };
|
||||
type LoaderData = { title: string; vm: BookingListVM; nowIso: string; pagesHref: string | null };
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const { t } = await getTranslations(request);
|
||||
const ctx = await loadBookingContext({ request, params });
|
||||
const title = `${t("bookings.list.title")} | ${process.env.APP_NAME}`;
|
||||
|
||||
const nowIso = new Date().toISOString();
|
||||
if (!ctx.hasModule) {
|
||||
return Response.json({ title, vm: buildBookingListVM({ rows: [] }) } satisfies LoaderData);
|
||||
return Response.json({ title, vm: buildBookingListVM({ rows: [] }), nowIso, pagesHref: null } satisfies LoaderData);
|
||||
}
|
||||
try {
|
||||
requireBookingPermission(ctx, BOOKING_PERMISSIONS.readOwn);
|
||||
@@ -29,6 +30,10 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
}
|
||||
|
||||
const tenantSlug = params.tenant ?? "";
|
||||
// Reachability (DoD B.6): the booking-pages admin list has no sidebar entry of
|
||||
// its own — it is linked inline from here, only for users who may view it
|
||||
// (bookings.read_all mirrors the pages route's own loader gate).
|
||||
const pagesHref = canReadAllBookings(ctx) ? bookingPagesListPath(tenantSlug) : null;
|
||||
const appointments = await listAppointmentsForTenant({ tenantId: ctx.tenantId, ownerUserId: canReadAllBookings(ctx) ? null : ctx.userId });
|
||||
const rows: BookingListRow[] = appointments.map((a) => ({
|
||||
id: a.id,
|
||||
@@ -43,53 +48,12 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
detailHref: bookingDetailPath(tenantSlug, a.id),
|
||||
}));
|
||||
|
||||
return Response.json({ title, vm: buildBookingListVM({ rows }) } satisfies LoaderData);
|
||||
return Response.json({ title, vm: buildBookingListVM({ rows }), nowIso, pagesHref } satisfies LoaderData);
|
||||
};
|
||||
|
||||
export default function BookingsListRoute() {
|
||||
const { t } = useTranslation();
|
||||
const { vm } = useLoaderData<LoaderData>();
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <main className="mx-auto max-w-5xl px-4 py-10" data-ui-id="ui.booking.list" />;
|
||||
}
|
||||
const { rows, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-4 py-10" data-ui-id="ui.booking.list">
|
||||
<h1 className="text-foreground text-xl font-semibold">{t("bookings.list.title")}</h1>
|
||||
{rows.length === 0 ? (
|
||||
<div className="mt-10 text-center" data-ui-id="ui.booking.list.empty">
|
||||
<p className="text-foreground font-medium">{t(emptyHeadlineKey)}</p>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t(emptyBodyKey)}</p>
|
||||
</div>
|
||||
) : (
|
||||
<table className="mt-6 w-full text-sm" data-ui-id="ui.booking.list.table">
|
||||
<thead>
|
||||
<tr className="text-muted-foreground text-left">
|
||||
<th className="py-2">{t("bookings.list.columns.when")}</th>
|
||||
<th>{t("bookings.list.columns.customer")}</th>
|
||||
<th>{t("bookings.list.columns.page")}</th>
|
||||
<th>{t("bookings.list.columns.status")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-border divide-y">
|
||||
{rows.map((row) => (
|
||||
<tr key={row.id} data-row-id={row.id}>
|
||||
<td className="py-2">
|
||||
<a className="underline" href={row.detailHref}>
|
||||
{new Date(row.startAtIso).toLocaleString()}
|
||||
</a>
|
||||
</td>
|
||||
<td>{row.customerName || row.customerEmail}</td>
|
||||
<td>{row.pageTitle}</td>
|
||||
<td data-status={row.status}>{t(row.statusKey)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
const { vm, nowIso, pagesHref } = useLoaderData<LoaderData>();
|
||||
return <BookingListPage vm={vm} nowIso={nowIso} pagesHref={pagesHref} />;
|
||||
}
|
||||
|
||||
export function ErrorBoundary() {
|
||||
|
||||
Reference in new issue
Block a user