227 lines
10 KiB
TypeScript
227 lines
10 KiB
TypeScript
import { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Description as DialogDescription, Title as DialogTitle } from "@radix-ui/react-dialog";
|
|
import { FeatherArchive, FeatherEye, FeatherLock, FeatherShield } from "@subframe/core";
|
|
import type { ChatAuditOverviewVM } from "@hivegrid/view-models";
|
|
|
|
import { useLocaleFormatters } from "~/locale/format";
|
|
import { Alert } from "~/ui/components/Alert";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Card } from "~/ui/components/Card";
|
|
import { Dialog } from "~/ui/components/Dialog";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { Table } from "~/ui/components/Table";
|
|
import { TextArea } from "~/ui/components/TextArea";
|
|
|
|
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageIntro, PageShell } from "../shared/PageShell";
|
|
|
|
export type ChatAuditOverviewActions = Readonly<{
|
|
onStartSession: (reason: string) => void | Promise<void>;
|
|
onEndSession: () => void | Promise<void>;
|
|
onOpenChannel: (href: string) => void | Promise<void>;
|
|
onArchiveChannel: (chatId: string) => void | Promise<void>;
|
|
}>;
|
|
|
|
export function ChatAuditOverviewPage({
|
|
vm,
|
|
actions,
|
|
busy = false,
|
|
actionErrorKey = null,
|
|
embedded = false,
|
|
}: {
|
|
readonly vm: ChatAuditOverviewVM;
|
|
readonly actions: ChatAuditOverviewActions;
|
|
readonly busy?: boolean;
|
|
readonly actionErrorKey?: string | null;
|
|
/** Inside the Compliance hub (AK-SET-01) the hub owns the header. */
|
|
readonly embedded?: boolean;
|
|
}): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
const [reason, setReason] = useState("");
|
|
const [archiveCandidate, setArchiveCandidate] = useState<{ id: string; title: string } | null>(null);
|
|
const data = vm.status === "ready" ? vm.data : null;
|
|
|
|
return (
|
|
<PageShell uiId="ui.chat.audit.page" className="bg-surface-neutral-primary mobile:[&_button]:min-h-11 mobile:[&_button]:min-w-11">
|
|
{embedded ? null : (
|
|
<PageHeader
|
|
icon={<FeatherShield className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={t("chat.audit.title")}
|
|
subtitle={t("chat.audit.description")}
|
|
actions={
|
|
data?.session ? (
|
|
<Button variant="tertiary" onClick={() => void actions.onEndSession()} disabled={busy}>
|
|
{t("chat.audit.session.end")}
|
|
</Button>
|
|
) : null
|
|
}
|
|
/>
|
|
)}
|
|
<PageBody>
|
|
{embedded ? (
|
|
<div className="mobile:flex-col mobile:items-start flex w-full items-start justify-between gap-4">
|
|
<PageIntro uiId="ui.chat.audit.intro">{t("chat.audit.description")}</PageIntro>
|
|
{data?.session ? (
|
|
<Button variant="tertiary" onClick={() => void actions.onEndSession()} disabled={busy}>
|
|
{t("chat.audit.session.end")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
) : null}
|
|
<Alert
|
|
variant="warning"
|
|
notDismissible
|
|
title={t("chat.audit.readOnly.title")}
|
|
description={t("chat.audit.readOnly.description")}
|
|
data-ui-id="ui.chat.audit.readOnlyNotice"
|
|
/>
|
|
|
|
{actionErrorKey ? <Alert variant="error" notDismissible title={t("chat.audit.errors.title")} description={t(actionErrorKey)} /> : null}
|
|
|
|
{!data?.session ? (
|
|
<Card size="large" data-ui-id="ui.chat.audit.reasonGate">
|
|
<div className="flex w-full flex-col items-start gap-4">
|
|
<div className="flex items-start gap-3">
|
|
<FeatherLock aria-hidden="true" />
|
|
<div className="flex flex-col items-start gap-1">
|
|
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("chat.audit.reason.title")}</span>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("chat.audit.reason.help")}</span>
|
|
</div>
|
|
</div>
|
|
<TextArea showLabel label={t("chat.audit.reason.label")} helpText={t("chat.audit.reason.maxLength")}>
|
|
<TextArea.Input
|
|
value={reason}
|
|
maxLength={500}
|
|
required
|
|
onChange={(event) => setReason(event.currentTarget.value)}
|
|
placeholder={t("chat.audit.reason.placeholder")}
|
|
aria-label={t("chat.audit.reason.label")}
|
|
data-ui-id="ui.chat.audit.reasonInput"
|
|
/>
|
|
</TextArea>
|
|
<Button
|
|
variant="warning"
|
|
icon={<FeatherEye />}
|
|
disabled={busy || reason.trim().length === 0}
|
|
loading={busy}
|
|
onClick={() => void actions.onStartSession(reason)}
|
|
data-ui-id="ui.chat.audit.startSession"
|
|
>
|
|
{t("chat.audit.session.start")}
|
|
</Button>
|
|
</div>
|
|
</Card>
|
|
) : (
|
|
<>
|
|
<Alert
|
|
variant="information"
|
|
notDismissible
|
|
title={t("chat.audit.session.active")}
|
|
description={t("chat.audit.session.activeDescription", {
|
|
reason: data.session.reason,
|
|
expiresAt: formatters.date(data.session.expiresAtIso, { dateStyle: "medium", timeStyle: "short" }),
|
|
})}
|
|
data-ui-id="ui.chat.audit.sessionActive"
|
|
/>
|
|
|
|
{data.channels.length === 0 ? (
|
|
<EmptyState outlined title={t(data.keys.emptyTitle)} body={t(data.keys.emptyBody)} data-ui-id="ui.chat.audit.empty" />
|
|
) : (
|
|
<div className="w-full overflow-x-auto" data-ui-id="ui.chat.audit.channelList">
|
|
<Table
|
|
header={
|
|
<Table.HeaderRow>
|
|
<Table.HeaderCell>{t("chat.audit.columns.channel")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("chat.audit.columns.kind")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("chat.audit.columns.members")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("chat.audit.columns.visibility")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("chat.audit.columns.lastActivity")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("chat.audit.columns.action")}</Table.HeaderCell>
|
|
</Table.HeaderRow>
|
|
}
|
|
>
|
|
{data.channels.map((channel) => (
|
|
<Table.Row key={channel.id}>
|
|
<Table.Cell>
|
|
<div className="flex flex-col items-start gap-1">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{channel.title}</span>
|
|
{channel.participantLabels.length > 0 ? (
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{channel.participantLabels.join(", ")}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<BadgeFeedback farbe="subtle-neutral">{t(channel.kindLabelKey)}</BadgeFeedback>
|
|
</Table.Cell>
|
|
<Table.Cell>{t("chat.audit.memberCount", { count: channel.memberCount })}</Table.Cell>
|
|
<Table.Cell>{t(channel.isPrivate ? "chat.audit.visibility.private" : "chat.audit.visibility.public")}</Table.Cell>
|
|
<Table.Cell>
|
|
{channel.lastMessageAtIso
|
|
? formatters.date(channel.lastMessageAtIso, { dateStyle: "medium", timeStyle: "short" })
|
|
: t("chat.audit.noActivity")}
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<div className="flex items-center gap-2">
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
icon={<FeatherEye />}
|
|
onClick={() => void actions.onOpenChannel(channel.detailHref)}
|
|
aria-label={t("chat.audit.openChannelLabel", { channel: channel.title })}
|
|
>
|
|
{t("chat.audit.openChannel")}
|
|
</Button>
|
|
{channel.canArchive ? (
|
|
<Button
|
|
variant="destructive"
|
|
size="small"
|
|
icon={<FeatherArchive />}
|
|
disabled={busy}
|
|
onClick={() => setArchiveCandidate({ id: channel.id, title: channel.title })}
|
|
aria-label={t("chat.audit.actions.archiveLabel", { channel: channel.title })}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
</Table.Cell>
|
|
</Table.Row>
|
|
))}
|
|
</Table>
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
|
|
<Dialog open={archiveCandidate !== null} onOpenChange={(open: boolean) => (open ? undefined : setArchiveCandidate(null))}>
|
|
<Dialog.Content className="w-[420px] max-w-[90vw] p-4" aria-label={t("chat.audit.confirm.archive.title")} data-ui-id="ui.chat.audit.archiveConfirm">
|
|
<div className="flex flex-col gap-4">
|
|
<div className="flex flex-col gap-1">
|
|
<DialogTitle>{t("chat.audit.confirm.archive.title")}</DialogTitle>
|
|
<DialogDescription>{t("chat.audit.confirm.archive.bodyNamed", { channel: archiveCandidate?.title ?? "" })}</DialogDescription>
|
|
</div>
|
|
<div className="flex justify-end gap-2">
|
|
<Button variant="tertiary" disabled={busy} onClick={() => setArchiveCandidate(null)}>
|
|
{t("shared.cancel")}
|
|
</Button>
|
|
<Button
|
|
variant="destructive"
|
|
loading={busy}
|
|
onClick={() => {
|
|
if (archiveCandidate) void actions.onArchiveChannel(archiveCandidate.id);
|
|
setArchiveCandidate(null);
|
|
}}
|
|
>
|
|
{t("shared.confirm")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|