// AK-P3 Interim-UI (AD-28) — Notification-Center preview screen composed from // ~/ui. Pure presentational component: renders the (live-merged) VM passed as a // prop; mark-read/bulk-clear run through injected action callbacks (M014), the // SSE subscription lives in the hosting route (useNotificationsStream). Final // Subframe optics land as a tracked design-nachzug once David's D-P3 ships. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherBell } from "@subframe/core"; import type { NotificationCenterItemVM, NotificationCenterVM } 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 { Tabs } from "~/ui/components/Tabs"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { APP_TIME_ZONE } from "~/locale/format"; export type NotificationCenterActions = { onMarkRead: (deliveryId: string) => void; onMarkAllRead: () => void; /** Deeplink click: host marks the delivery read (if unread) and navigates. */ onOpen: (item: NotificationCenterItemVM) => void; }; export type NotificationCenterPageProps = { vm: NotificationCenterVM; /** i18n key describing the SSE connection state (sr-only live region). */ connectionStatusKey: string; actions: NotificationCenterActions; }; type BadgeFarbe = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral"; function statusFarbe(status: string): BadgeFarbe { switch (status) { case "READ": return "subtle-positive"; case "FAILED": return "subtle-negative"; case "PENDING": return "subtle-warning"; default: return "subtle-neutral"; } } export function NotificationCenterPage({ vm, connectionStatusKey, actions }: NotificationCenterPageProps) { const { t, i18n } = useTranslation(); const [activeTab, setActiveTab] = useState<"all" | "unread">("all"); const header = ( } title={t("notifications.center.title")} subtitle={t("notifications.center.diagnostics")} actions={ vm.status === "ready" && vm.data && vm.data.unreadCount > 0 ? ( ) : undefined } /> ); // Loading / not-ready: keep the marker so the shell + e2e see a stable surface. if (vm.status !== "ready" || !vm.data) { return ( {header} ); } const { items, totalCount, unreadCount, emptyHeadlineKey, emptyBodyKey, unreadEmptyKey } = vm.data; const visibleItems = activeTab === "unread" ? items.filter((item) => !item.isRead) : items; const numberFormatter = new Intl.NumberFormat(i18n.language); return ( {header} {t(connectionStatusKey)} {totalCount === 0 ? (
) : ( <>
setActiveTab("all")} role="tab" aria-selected={activeTab === "all"}> {`${t("notifications.center.tabs.all")} (${numberFormatter.format(totalCount)})`} setActiveTab("unread")} role="tab" aria-selected={activeTab === "unread"} > {`${t("notifications.center.tabs.unread")} (${numberFormatter.format(unreadCount)})`}
{visibleItems.length === 0 ? (
) : (
    {visibleItems.map((item) => ( ))}
)} )}
); } function NotificationCard({ item, onMarkRead, onOpen, }: { item: NotificationCenterItemVM; onMarkRead: (deliveryId: string) => void; onOpen: (item: NotificationCenterItemVM) => void; }) { const { t, i18n } = useTranslation(); const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "medium", timeStyle: "short" }); const baseMessageLabel = i18n.exists(item.messageKey) ? String(t(item.messageKey)) : String(t("notifications.center.unknownMessage")); // Subject context (e.g. task title) is appended and ellipsis-truncated via CSS. const messageLabel = item.subjectLabel ? `${baseMessageLabel}: ${item.subjectLabel}` : baseMessageLabel; const enumLabel = (key: string, fallbackKey: string) => (i18n.exists(key) ? String(t(key)) : String(t(fallbackKey))); const formatTimestamp = (iso: string | null) => iso ? dateTimeFormatter.format(new Date(iso)) : String(t("notifications.center.timestamps.notRecorded")); return (
  • {item.deeplinkHref ? ( { // Let modified clicks (new tab etc.) keep native anchor behavior. if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0) return; event.preventDefault(); onOpen(item); }} > {messageLabel} ) : ( {messageLabel} )} {item.tagKey && item.tagTone ? ( {t(item.tagKey)} ) : null} {enumLabel(item.categoryKey, "notifications.center.categories.unknown")} ·{" "} {enumLabel(item.channelKey, "notifications.center.channels.unknown")} · {formatTimestamp(item.sentAtIso ?? item.createdAtIso)}
    {enumLabel(item.statusKey, "notifications.center.statuses.unknown")}
    {item.bounceKey ? (
    ) : null} {!item.isRead ? (
    ) : null}
  • ); }