Files

113 lines
5.0 KiB
TypeScript

import { Link } from "react-router";
import { useTranslation } from "react-i18next";
import { FeatherCalendarClock, FeatherPlus } from "@subframe/core";
import type { BookingPagesListVM } from "@hivegrid/view-models";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
import { Button } from "~/ui/components/Button";
import { CopyToClipboardButton } from "~/ui/components/CopyToClipboardButton";
import { EmptyState } from "~/ui/components/EmptyState";
import { Table } from "~/ui/components/Table";
import { useLocaleFormatters } from "~/locale/format";
import { PageHeader } from "../automation/automationUi";
/**
* AK-P16b · interim booking-pages list (AD-28, archetype A2): title/slug/
* duration/providers/publish state + copyable public URL per page. Final
* Subframe optics follow David's D-P16 delta (design-nachzug).
*/
export interface BookingPagesPageProps {
vm: BookingPagesListVM;
}
export function BookingPagesPage({ vm }: BookingPagesPageProps): React.JSX.Element {
const { t } = useTranslation();
const formatters = useLocaleFormatters();
if (vm.status !== "ready" || !vm.data) {
return <div className="flex w-full flex-col" data-ui-id="ui.booking.pages.list" />;
}
const { rows, canCreate, newHref, emptyHeadlineKey, emptyBodyKey } = vm.data;
return (
<div className="flex w-full flex-col" data-ui-id="ui.booking.pages.list">
<PageHeader
icon={<FeatherCalendarClock className="text-heading-3 font-heading-3 text-icon-neutral-secondary" />}
title={t("bookings.pages.title")}
subtitle={t("bookings.pages.subtitle")}
actions={
canCreate ? (
<Link to={newHref} className="no-underline" data-ui-id="ui.booking.pages.new">
<Button icon={<FeatherPlus />}>{t("bookings.pages.new")}</Button>
</Link>
) : undefined
}
/>
<div className="mobile:p-4 flex w-full flex-col gap-4 p-6">
{rows.length === 0 ? (
<div data-ui-id="ui.booking.pages.empty">
<EmptyState outlined fillContainer title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
</div>
) : (
<div
className="border-border-default bg-surface-neutral-primary w-full overflow-x-auto rounded-lg border border-solid shadow-sm"
data-ui-id="ui.booking.pages.items"
>
<Table
header={
<Table.HeaderRow>
<Table.HeaderCell>{t("bookings.pages.columns.title")}</Table.HeaderCell>
<Table.HeaderCell>{t("bookings.pages.columns.slug")}</Table.HeaderCell>
<Table.HeaderCell>{t("bookings.pages.columns.duration")}</Table.HeaderCell>
<Table.HeaderCell>{t("bookings.pages.columns.providers")}</Table.HeaderCell>
<Table.HeaderCell>{t("bookings.pages.columns.status")}</Table.HeaderCell>
<Table.HeaderCell>{t("bookings.pages.columns.publicUrl")}</Table.HeaderCell>
</Table.HeaderRow>
}
>
{rows.map((row) => (
<Table.Row key={row.id} data-row-id={row.id} clickable>
<Table.Cell>
<Link
to={row.editHref}
className="text-body-small-medium-150 font-body-small-medium-150 text-text-neutral-primary hover:text-text-feedback-link-default whitespace-nowrap no-underline"
>
{row.title}
</Link>
</Table.Cell>
<Table.Cell>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">/{row.slug}</span>
</Table.Cell>
<Table.Cell>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
{t("bookings.pages.durationMinutes", { count: row.durationMinutes, value: formatters.number(row.durationMinutes) })}
</span>
</Table.Cell>
<Table.Cell>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
{formatters.number(row.providerCount)}
</span>
</Table.Cell>
<Table.Cell>
<BadgeFeedback farbe={row.isPublished ? "subtle-positive" : "subtle-neutral"} size="small">
{row.isPublished ? t("bookings.pages.published") : t("bookings.pages.unpublished")}
</BadgeFeedback>
</Table.Cell>
<Table.Cell>
<CopyToClipboardButton
clipboardText={row.publicUrl}
tooltipText={t("bookings.pages.copyUrl")}
successKey="bookings.pages.toast.publicUrlCopied"
/>
</Table.Cell>
</Table.Row>
))}
</Table>
</div>
)}
</div>
</div>
);
}