152 lines
7.5 KiB
TypeScript
152 lines
7.5 KiB
TypeScript
import { useState } from "react";
|
|
import { Form } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import { FeatherCalendarClock } from "@subframe/core";
|
|
import type { CalendarConnectionDetailVM } from "@hivegrid/view-models";
|
|
import { Alert } from "~/ui/components/Alert";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Dialog } from "~/ui/components/Dialog";
|
|
import { Table } from "~/ui/components/Table";
|
|
import { useLocaleFormatters } from "~/locale/format";
|
|
import { PAGE_HEADER_ICON_CLASS, PageBackLink, PageBody, PageHeader, PageShell } from "../shared/PageShell";
|
|
import { statusBadgeTone } from "../automation/automationUi";
|
|
|
|
/**
|
|
* AK-P16a · interim calendar-connection detail screen (AD-28, archetype A6+A2):
|
|
* selected calendars, sync status and the last-50 conflict log in Klartext
|
|
* (DoD 4). Disconnect confirms via a real Dialog (XS 420) and POSTs the
|
|
* existing `intent=disconnect` action. Final Subframe optics follow David's
|
|
* D-P16 delta (design-nachzug).
|
|
*/
|
|
|
|
export interface CalendarConnectionDetailPageProps {
|
|
vm: CalendarConnectionDetailVM;
|
|
csrf: string | null;
|
|
backHref: string;
|
|
}
|
|
|
|
export function CalendarConnectionDetailPage({ vm, csrf, backHref }: CalendarConnectionDetailPageProps): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
const [confirmingDisconnect, setConfirmingDisconnect] = useState(false);
|
|
|
|
if (vm.status !== "ready" || !vm.data) {
|
|
return <PageShell uiId="ui.calendar.detail" />;
|
|
}
|
|
const { externalAccountEmail, status, statusKey, syncDirection, lastSyncAt, lastErrorText, selectedCalendars, conflicts, conflictsEmptyKey, canManage } = vm.data;
|
|
|
|
return (
|
|
<PageShell uiId="ui.calendar.detail">
|
|
<PageHeader
|
|
icon={<FeatherCalendarClock className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={externalAccountEmail}
|
|
subtitle={`${t(`calendar.connection.direction.${syncDirection}`)} · ${
|
|
lastSyncAt ? t("calendar.detail.lastSyncAt", { value: formatters.dateTime(lastSyncAt) }) : t("calendar.detail.neverSynced")
|
|
}`}
|
|
actions={
|
|
<>
|
|
<span data-status={status}>
|
|
<BadgeFeedback farbe={statusBadgeTone(status)}>{t(statusKey)}</BadgeFeedback>
|
|
</span>
|
|
{canManage ? (
|
|
<Button variant="destructive" onClick={() => setConfirmingDisconnect(true)} data-ui-id="ui.calendar.detail.disconnect">
|
|
{t("calendar.detail.disconnect")}
|
|
</Button>
|
|
) : null}
|
|
</>
|
|
}
|
|
/>
|
|
<PageBody>
|
|
<PageBackLink to={backHref} label={t("calendar.detail.back")} uiId="ui.calendar.detail.back" />
|
|
|
|
{/* Re-connect banner on a broken connection (hierarchy §8). */}
|
|
{status === "error" && lastErrorText ? <Alert variant="error" title={t("calendar.detail.errorBanner")} description={lastErrorText} /> : null}
|
|
|
|
<div className="flex w-full flex-col gap-2 rounded-lg border border-solid border-border-default bg-surface-neutral-primary p-4" data-ui-id="ui.calendar.detail.calendars">
|
|
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("calendar.detail.calendarsHeading")}</span>
|
|
{selectedCalendars.length === 0 ? (
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("calendar.detail.noCalendars")}</span>
|
|
) : (
|
|
<ul className="flex w-full flex-col gap-1">
|
|
{selectedCalendars.map((cal) => (
|
|
<li key={cal.externalCalendarId} className="flex items-center gap-2" data-row-id={cal.externalCalendarId}>
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{cal.name}</span>
|
|
{cal.isPrimary ? (
|
|
<BadgeFeedback farbe="subtle-information" size="small">
|
|
{t("calendar.detail.primaryBadge")}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex w-full flex-col gap-2" data-ui-id="ui.calendar.detail.conflicts">
|
|
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("calendar.detail.conflictsHeading")}</span>
|
|
{conflicts.length === 0 ? (
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t(conflictsEmptyKey)}</span>
|
|
) : (
|
|
<div className="w-full overflow-x-auto rounded-lg border border-solid border-border-default bg-surface-neutral-primary shadow-sm">
|
|
<Table
|
|
header={
|
|
<Table.HeaderRow>
|
|
<Table.HeaderCell>{t("calendar.detail.conflictTable.occurredAt")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("calendar.detail.conflictTable.description")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("calendar.detail.conflictTable.resolution")}</Table.HeaderCell>
|
|
</Table.HeaderRow>
|
|
}
|
|
>
|
|
{conflicts.map((conflict) => (
|
|
<Table.Row key={conflict.id} data-row-id={conflict.id}>
|
|
<Table.Cell>
|
|
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
|
|
{formatters.dateTime(conflict.occurredAt)}
|
|
</span>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-primary">{conflict.descriptionText}</span>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">
|
|
{t(conflict.resolutionKey)}
|
|
</BadgeFeedback>
|
|
</Table.Cell>
|
|
</Table.Row>
|
|
))}
|
|
</Table>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Disconnect confirm (XS 420) — POSTs the route's disconnect intent. */}
|
|
<Dialog open={confirmingDisconnect} onOpenChange={(open: boolean) => (open ? undefined : setConfirmingDisconnect(false))}>
|
|
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
|
|
<div className="flex w-full flex-col gap-6" data-ui-id="ui.calendar.detail.disconnectConfirm">
|
|
<div className="flex flex-col gap-2">
|
|
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("calendar.detail.disconnectConfirm.title")}</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
|
{t("calendar.detail.disconnectConfirm.body")}
|
|
</span>
|
|
</div>
|
|
<div className="flex w-full items-center justify-end gap-2">
|
|
<Button variant="tertiary" onClick={() => setConfirmingDisconnect(false)}>
|
|
{t("shared.cancel")}
|
|
</Button>
|
|
<Form method="post">
|
|
{csrf ? <input type="hidden" name="csrf" value={csrf} /> : null}
|
|
<input type="hidden" name="intent" value="disconnect" />
|
|
<Button type="submit" variant="destructive" data-ui-id="ui.calendar.detail.disconnectSubmit">
|
|
{t("calendar.detail.disconnect")}
|
|
</Button>
|
|
</Form>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|