73 lines
3.6 KiB
TypeScript
73 lines
3.6 KiB
TypeScript
// R-P5 Interim-UI (AD-28) — reusable Connection-Card (D-P5: app card with status
|
|
// traffic light, Klartext health hint, last sync time and the lifecycle buttons
|
|
// Verbinden/Re-Sync/Reconnect/Trennen). All later app connections (P14/P15/P16/
|
|
// P20) render through this card. Pure presentational; callbacks injected.
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { Link } from "react-router";
|
|
import type { ConnectionRow } from "@hivegrid/view-models";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Card } from "~/ui/components/Card";
|
|
import { LinkButton } from "~/ui/components/LinkButton";
|
|
import { connectionStatusBadge } from "./integrationsBadges";
|
|
|
|
export type ConnectionCardProps = {
|
|
row: ConnectionRow;
|
|
canDisconnect: boolean;
|
|
canManualSync: boolean;
|
|
canReconnect: boolean;
|
|
submitting: boolean;
|
|
onManualSync: (connectionId: string) => void;
|
|
onReconnect: (row: ConnectionRow) => void;
|
|
onDisconnect: (row: ConnectionRow) => void;
|
|
};
|
|
|
|
export function ConnectionCard({ row, canDisconnect, canManualSync, canReconnect, submitting, onManualSync, onReconnect, onDisconnect }: ConnectionCardProps) {
|
|
const { t, i18n } = useTranslation();
|
|
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
|
const unhealthy = row.status === "degraded" || row.status === "broken";
|
|
const revoked = row.status === "revoked";
|
|
|
|
return (
|
|
<Card data-row-id={row.id} data-status={row.status} data-ui-id="ui.integrations.app.connectionCard">
|
|
<div className="flex w-full flex-wrap items-start justify-between gap-2">
|
|
<div className="flex flex-col gap-0">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.label}</span>
|
|
{row.healthMessageKey ? (
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t(row.healthMessageKey)}</span>
|
|
) : null}
|
|
</div>
|
|
<BadgeFeedback farbe={connectionStatusBadge(row.status)} size="small">
|
|
{t(row.statusKey)}
|
|
</BadgeFeedback>
|
|
</div>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{t("integrations.connections.column.lastCheck")}: {row.lastHealthCheckIso ? dateFormatter.format(new Date(row.lastHealthCheckIso)) : "—"}
|
|
</span>
|
|
<div className="flex w-full flex-wrap items-center justify-between gap-2">
|
|
<Link to={row.syncsHref} className="contents no-underline">
|
|
<LinkButton variant="subtle">{t("integrations.connections.actions.history")}</LinkButton>
|
|
</Link>
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
{canManualSync && !revoked ? (
|
|
<Button variant="secondary" size="small" loading={submitting} onClick={() => onManualSync(row.id)} data-ui-id="ui.integrations.app.resync">
|
|
{t("integrations.connections.actions.resync")}
|
|
</Button>
|
|
) : null}
|
|
{canReconnect && (unhealthy || revoked) ? (
|
|
<Button variant="secondary" size="small" onClick={() => onReconnect(row)} data-ui-id="ui.integrations.app.reconnect">
|
|
{t("integrations.connections.actions.reconnect")}
|
|
</Button>
|
|
) : null}
|
|
{canDisconnect && !revoked ? (
|
|
<Button variant="destructive" size="small" onClick={() => onDisconnect(row)} data-ui-id="ui.integrations.app.disconnect">
|
|
{t("integrations.connections.actions.disconnect")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
);
|
|
}
|