Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/calendar/CalendarConnectionsPage.tsx
T

139 lines
6.2 KiB
TypeScript

import { Form, Link } from "react-router";
import { useTranslation } from "react-i18next";
import { FeatherCalendarClock, FeatherPlus } from "@subframe/core";
import type { CalendarConnectionListVM } from "@hivegrid/view-models";
import { Alert } from "~/ui/components/Alert";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
import { Button } from "~/ui/components/Button";
import { EmptyState } from "~/ui/components/EmptyState";
import { Table } from "~/ui/components/Table";
import { useLocaleFormatters } from "~/locale/format";
import { PageBackLink, PageIntro } from "../shared/PageShell";
import { PageHeader, statusBadgeTone } from "../automation/automationUi";
/**
* AK-P16a · interim calendar-connections settings screen (AD-28, archetype A6).
* Renders the server-built CalendarConnectionListVM; the Google connect action
* stays a plain POST (`intent=connect`) owned by the route. Final Subframe
* optics follow David's D-P16 delta (design-nachzug).
*/
export interface CalendarConnectionsPageProps {
vm: CalendarConnectionListVM;
csrf: string | null;
/** Path back to the integrations catalog (settings/integrations). */
backHref: string;
/** Inside the Erweiterungen hub (AK-SET-01) the hub owns the header. */
embedded?: boolean;
}
export function CalendarConnectionsPage({ vm, csrf, backHref, embedded = false }: CalendarConnectionsPageProps): 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.calendar.connections" />;
}
const { rows, canConnect, isConfigured, emptyHeadlineKey, emptyBodyKey, notConfiguredKey } = vm.data;
const errored = rows.filter((row) => row.status === "error");
// AK-SET-01: hoisted so the connect button survives in both the standalone
// header and the hub's intro row.
const connectAction =
canConnect && isConfigured ? (
<Form method="post">
{csrf ? <input type="hidden" name="csrf" value={csrf} /> : null}
<input type="hidden" name="intent" value="connect" />
<Button type="submit" icon={<FeatherPlus />} data-ui-id="ui.calendar.connections.connect">
{t("calendar.connections.connectButton")}
</Button>
</Form>
) : undefined;
return (
<div className="flex w-full flex-col" data-ui-id="ui.calendar.connections">
{embedded ? null : (
<PageHeader
icon={<FeatherCalendarClock className="text-heading-3 font-heading-3 text-icon-neutral-secondary" />}
title={t("calendar.connections.title")}
subtitle={t("calendar.connections.subtitle")}
actions={connectAction}
/>
)}
<div className="flex w-full flex-col gap-4 p-6 mobile:p-4">
{embedded ? (
<div className="mobile:flex-col mobile:items-start flex w-full items-start justify-between gap-4">
<PageIntro uiId="ui.calendar.connections.intro">{t("calendar.connections.subtitle")}</PageIntro>
{connectAction ? <div className="flex items-center gap-2">{connectAction}</div> : null}
</div>
) : (
<PageBackLink to={backHref} label={t("integrations.connections.back")} uiId="ui.calendar.connections.back" />
)}
{!isConfigured ? (
<div data-ui-id="ui.calendar.connections.notConfigured">
<Alert variant="warning" title={t(notConfiguredKey)} />
</div>
) : null}
{/* Re-connect banner (hierarchy §8): at least one broken connection. */}
{errored.length > 0 ? (
<Alert
variant="error"
title={t("calendar.connections.banner.title", { count: errored.length })}
description={errored[0]?.lastErrorText ?? undefined}
data-ui-id="ui.calendar.connections.banner"
/>
) : null}
{rows.length === 0 ? (
<div data-ui-id="ui.calendar.connections.empty">
<EmptyState outlined fillContainer title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
</div>
) : (
<div className="w-full overflow-x-auto rounded-lg border border-solid border-border-default bg-surface-neutral-primary shadow-sm" data-ui-id="ui.calendar.connections.list">
<Table
header={
<Table.HeaderRow>
<Table.HeaderCell>{t("calendar.connections.table.account")}</Table.HeaderCell>
<Table.HeaderCell>{t("calendar.connections.table.direction")}</Table.HeaderCell>
<Table.HeaderCell>{t("calendar.connections.table.lastSync")}</Table.HeaderCell>
<Table.HeaderCell>{t("calendar.connections.table.status")}</Table.HeaderCell>
</Table.HeaderRow>
}
>
{rows.map((row) => (
<Table.Row key={row.id} data-row-id={row.id}>
<Table.Cell>
<Link
to={row.detailHref}
className="whitespace-nowrap text-body-small-medium-150 font-body-small-medium-150 text-text-neutral-primary no-underline hover:text-text-feedback-link-default"
>
{row.externalAccountEmail}
</Link>
</Table.Cell>
<Table.Cell>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">{t(row.syncDirectionKey)}</span>
</Table.Cell>
<Table.Cell>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
{row.lastSyncAt ? formatters.dateTime(row.lastSyncAt) : t("calendar.detail.neverSynced")}
</span>
</Table.Cell>
<Table.Cell>
<span data-status={row.status}>
<BadgeFeedback farbe={statusBadgeTone(row.status)} size="small">
{t(row.statusKey)}
</BadgeFeedback>
</span>
</Table.Cell>
</Table.Row>
))}
</Table>
</div>
)}
</div>
</div>
);
}