177 lines
7.7 KiB
TypeScript
177 lines
7.7 KiB
TypeScript
// VA-P23 interim-UI (AD-28) — mailbox connect settings screen composed from
|
|
// ~/ui: PageShell header, provider connect actions, mailbox cards with status
|
|
// badge, initial-sync progress and Klartext errors. Presentational; the route
|
|
// owns loader/action, mutations POST via plain Forms (csrf prop, same pattern
|
|
// as CalendarConnectionsPage). Final Subframe optics = tracked design-nachzug.
|
|
|
|
import { Form } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import { FeatherMail, FeatherPlus } from "@subframe/core";
|
|
import type { EmailMailboxListVM, EmailMailboxRow, EmailMailboxStatus } 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 { useLocaleFormatters } from "~/locale/format";
|
|
import { PAGE_HEADER_ICON_CLASS, PageBackLink, PageBody, PageHeader, PageIntro, PageShell } from "../shared/PageShell";
|
|
|
|
export type EmailMailboxSettingsPageProps = {
|
|
vm: EmailMailboxListVM;
|
|
csrf: string | null;
|
|
flash: "connected" | "error" | 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;
|
|
};
|
|
|
|
function statusBadgeTone(status: EmailMailboxStatus): "subtle-positive" | "subtle-negative" | "subtle-neutral" {
|
|
if (status === "active") return "subtle-positive";
|
|
if (status === "error" || status === "revoked") return "subtle-negative";
|
|
return "subtle-neutral";
|
|
}
|
|
|
|
function MailboxCard({ row, csrf }: { row: EmailMailboxRow; csrf: string | null }) {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
return (
|
|
<div className="flex w-full flex-col gap-2 rounded-lg border border-solid border-border-default bg-surface-neutral-primary p-4" data-row-id={row.id}>
|
|
<div className="flex w-full flex-wrap items-start justify-between gap-2">
|
|
<div className="flex flex-col gap-1">
|
|
<div className="flex items-center gap-2">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.emailAddress}</span>
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">
|
|
{t(row.providerKey)}
|
|
</BadgeFeedback>
|
|
</div>
|
|
{row.lastSyncAt ? (
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{t("emailInbox.settings.lastSync")}: {formatters.dateTime(row.lastSyncAt)}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<span data-status={row.status}>
|
|
<BadgeFeedback farbe={statusBadgeTone(row.status)} size="small">
|
|
{t(row.statusKey)}
|
|
</BadgeFeedback>
|
|
</span>
|
|
{row.isOwn ? (
|
|
<Form method="post">
|
|
{csrf ? <input type="hidden" name="csrf" value={csrf} /> : null}
|
|
<input type="hidden" name="intent" value="disconnect" />
|
|
<input type="hidden" name="mailboxId" value={row.id} />
|
|
<Button type="submit" variant="destructive" size="small" data-ui-id="ui.email.settings.disconnect">
|
|
{t("emailInbox.settings.disconnect")}
|
|
</Button>
|
|
</Form>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
{row.initialSync.status !== "completed" ? (
|
|
<span
|
|
className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary"
|
|
data-ui-id="ui.email.settings.initialSync"
|
|
data-sync-status={row.initialSync.status}
|
|
>
|
|
{t(row.initialSync.statusKey)}
|
|
{row.initialSync.progressPercent !== null && ` — ${row.initialSync.progressPercent}%`}
|
|
{row.initialSync.fetchedCount !== null && ` (${t("emailInbox.settings.initialSync.fetched", { count: row.initialSync.fetchedCount })})`}
|
|
</span>
|
|
) : null}
|
|
{row.lastErrorText ? (
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-feedback-negative" data-ui-id="ui.email.settings.error">
|
|
{row.lastErrorText.startsWith("emailInbox.") ? t(row.lastErrorText) : row.lastErrorText}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function EmailMailboxSettingsPage({ vm, csrf, flash, backHref, embedded = false }: EmailMailboxSettingsPageProps) {
|
|
const { t } = useTranslation();
|
|
|
|
if (vm.status !== "ready" || !vm.data) {
|
|
return <PageShell uiId="ui.email.settings" />;
|
|
}
|
|
const { rows, canConnect, configuredProviders, emptyHeadlineKey, emptyBodyKey, notConfiguredKey } = vm.data;
|
|
const anyConfigured = configuredProviders.gmail || configuredProviders.microsoft;
|
|
|
|
// AK-SET-01: hoisted so the connect buttons survive in both the standalone
|
|
// header and the hub's intro row.
|
|
const connectActions =
|
|
canConnect && anyConfigured ? (
|
|
<>
|
|
{configuredProviders.gmail ? (
|
|
<Form method="post">
|
|
{csrf ? <input type="hidden" name="csrf" value={csrf} /> : null}
|
|
<input type="hidden" name="intent" value="connect-gmail" />
|
|
<Button type="submit" icon={<FeatherPlus />} data-ui-id="ui.email.settings.connect.gmail">
|
|
{t("emailInbox.settings.connectGmail")}
|
|
</Button>
|
|
</Form>
|
|
) : null}
|
|
{configuredProviders.microsoft ? (
|
|
<Form method="post">
|
|
{csrf ? <input type="hidden" name="csrf" value={csrf} /> : null}
|
|
<input type="hidden" name="intent" value="connect-microsoft" />
|
|
<Button type="submit" icon={<FeatherPlus />} data-ui-id="ui.email.settings.connect.microsoft">
|
|
{t("emailInbox.settings.connectMicrosoft")}
|
|
</Button>
|
|
</Form>
|
|
) : null}
|
|
</>
|
|
) : null
|
|
;
|
|
|
|
return (
|
|
<PageShell uiId="ui.email.settings">
|
|
{embedded ? null : (
|
|
<PageHeader
|
|
icon={<FeatherMail className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={t("emailInbox.settings.title")}
|
|
subtitle={t("emailInbox.settings.subtitle")}
|
|
actions={connectActions}
|
|
/>
|
|
)}
|
|
<PageBody>
|
|
{embedded ? (
|
|
<div className="mobile:flex-col mobile:items-start flex w-full items-start justify-between gap-4">
|
|
<PageIntro uiId="ui.email.settings.intro">{t("emailInbox.settings.subtitle")}</PageIntro>
|
|
{connectActions ? <div className="flex items-center gap-2">{connectActions}</div> : null}
|
|
</div>
|
|
) : (
|
|
<PageBackLink to={backHref} label={t("integrations.connections.back")} uiId="ui.email.settings.back" />
|
|
)}
|
|
{flash === "connected" ? (
|
|
<div data-ui-id="ui.email.settings.flash.connected">
|
|
<Alert variant="success" title={t("emailInbox.settings.flash.connected")} />
|
|
</div>
|
|
) : null}
|
|
{flash === "error" ? (
|
|
<div data-ui-id="ui.email.settings.flash.error">
|
|
<Alert variant="error" title={t("emailInbox.settings.flash.error")} />
|
|
</div>
|
|
) : null}
|
|
{!anyConfigured ? (
|
|
<div data-ui-id="ui.email.settings.notConfigured">
|
|
<Alert variant="warning" title={t(notConfiguredKey)} />
|
|
</div>
|
|
) : null}
|
|
|
|
{rows.length === 0 ? (
|
|
<div data-ui-id="ui.email.settings.empty">
|
|
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
|
</div>
|
|
) : (
|
|
<div className="flex w-full flex-col gap-3" data-ui-id="ui.email.settings.list">
|
|
{rows.map((row) => (
|
|
<MailboxCard key={row.id} row={row} csrf={csrf} />
|
|
))}
|
|
</div>
|
|
)}
|
|
</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|