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
+25
-68
@@ -1,26 +1,17 @@
|
||||
// AK-P16b · booking-pages list route (M06 Block E.1). bookings.read_all to view;
|
||||
// editing requires bookings.admin (enforced in the editor). Shows each page's public
|
||||
// URL with copy (DoD 3). Functional table; bespoke polish follows D-P16.
|
||||
// URL with copy (DoD 3). Interim ~/ui screen (AD-28); final polish follows D-P16.
|
||||
|
||||
import { type LoaderFunctionArgs, useLoaderData } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { buildBookingPagesListVM, type BookingPageListRow as BookingPageListRowVM, type BookingPagesListVM } from "@hivegrid/view-models";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { loadBookingContext, requireBookingPermission, BOOKING_PERMISSIONS } from "~/modules/booking/routes/bookingAccess.server";
|
||||
import { BOOKING_MODULE_KEY, bookingPageEditPath, bookingPageNewPath, publicBookingPath, notFoundResponse } from "~/modules/booking/routes/bookingRoutePaths";
|
||||
import { listBookingPages } from "~/modules/booking/db/booking.db.server";
|
||||
import { BookingPagesPage } from "~/components/screens/booking/BookingPagesPage";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
|
||||
interface PageRow {
|
||||
id: string;
|
||||
title: string;
|
||||
slug: string;
|
||||
durationMinutes: number;
|
||||
isPublished: boolean;
|
||||
providerCount: number;
|
||||
editHref: string;
|
||||
publicPath: string;
|
||||
}
|
||||
type LoaderData = { title: string; tenantSlug: string; canCreate: boolean; rows: PageRow[]; newHref: string };
|
||||
type LoaderData = { title: string; vm: BookingPagesListVM };
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const { t } = await getTranslations(request);
|
||||
@@ -31,67 +22,33 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
throw notFoundResponse();
|
||||
}
|
||||
const tenantSlug = params.tenant ?? "";
|
||||
const origin = new URL(request.url).origin;
|
||||
const pages = await listBookingPages(ctx.tenantId);
|
||||
const rows: PageRow[] = pages.map((p) => ({
|
||||
id: p.id,
|
||||
title: p.title,
|
||||
slug: p.slug,
|
||||
durationMinutes: p.durationMinutes,
|
||||
isPublished: p.isPublished,
|
||||
providerCount: p.providerCount,
|
||||
editHref: bookingPageEditPath(tenantSlug, p.id),
|
||||
publicPath: publicBookingPath(tenantSlug, p.slug),
|
||||
}));
|
||||
return Response.json({
|
||||
title: `${t("bookings.pages.title")} | ${process.env.APP_NAME}`,
|
||||
tenantSlug,
|
||||
canCreate: ctx.permissions.includes(BOOKING_PERMISSIONS.admin),
|
||||
const rows: BookingPageListRowVM[] = pages.map((p) => {
|
||||
const publicPath = publicBookingPath(tenantSlug, p.slug);
|
||||
return {
|
||||
id: p.id,
|
||||
title: p.title,
|
||||
slug: p.slug,
|
||||
durationMinutes: p.durationMinutes,
|
||||
isPublished: p.isPublished,
|
||||
providerCount: p.providerCount,
|
||||
editHref: bookingPageEditPath(tenantSlug, p.id),
|
||||
publicPath,
|
||||
publicUrl: `${origin}${publicPath}`,
|
||||
};
|
||||
});
|
||||
const vm = buildBookingPagesListVM({
|
||||
rows,
|
||||
canCreate: ctx.permissions.includes(BOOKING_PERMISSIONS.admin),
|
||||
newHref: bookingPageNewPath(tenantSlug),
|
||||
} satisfies LoaderData);
|
||||
});
|
||||
return Response.json({ title: `${t("bookings.pages.title")} | ${process.env.APP_NAME}`, vm } satisfies LoaderData);
|
||||
};
|
||||
|
||||
export default function BookingPagesListRoute() {
|
||||
const { t } = useTranslation();
|
||||
const { rows, canCreate, newHref } = useLoaderData<LoaderData>();
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-4xl px-4 py-10" data-ui-id="ui.booking.pages.list">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-foreground text-xl font-semibold">{t("bookings.pages.title")}</h1>
|
||||
{canCreate ? (
|
||||
<a href={newHref} className="rounded border px-3 py-1 text-sm" data-ui-id="ui.booking.pages.new">
|
||||
{t("bookings.pages.new")}
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div className="mt-10 text-center" data-ui-id="ui.booking.pages.empty">
|
||||
<p className="text-foreground font-medium">{t("bookings.pages.empty.headline")}</p>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t("bookings.pages.empty.body")}</p>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="mt-6 divide-border divide-y" data-ui-id="ui.booking.pages.items">
|
||||
{rows.map((row) => (
|
||||
<li key={row.id} className="flex items-center justify-between py-3" data-row-id={row.id}>
|
||||
<div>
|
||||
<a className="font-medium underline" href={row.editHref}>
|
||||
{row.title}
|
||||
</a>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
/{row.slug} · {row.durationMinutes}min · {row.providerCount} · {row.isPublished ? t("bookings.pages.published") : t("bookings.pages.unpublished")}
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" className="rounded border px-2 py-1 text-xs" onClick={() => navigator.clipboard?.writeText(`${window.location.origin}${row.publicPath}`)}>
|
||||
{t("bookings.pages.copyUrl")}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
const { vm } = useLoaderData<LoaderData>();
|
||||
return <BookingPagesPage vm={vm} />;
|
||||
}
|
||||
|
||||
export function ErrorBoundary() {
|
||||
|
||||
Reference in new issue
Block a user