108 lines
4.4 KiB
TypeScript
108 lines
4.4 KiB
TypeScript
// AK-P3 Interim-UI (AD-28) — topbar notifications drawer composed from ~/ui
|
|
// (real Drawer, not a card fake — D07). Pure presentational: the host (NavBar)
|
|
// owns the SSE subscription and open state; items arrive as VM props, clicks
|
|
// follow validated deeplinks. Final Subframe optics land as a tracked
|
|
// design-nachzug once David's D-P3 ships.
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
import type { NotificationCenterItemVM } from "@hivegrid/view-models";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Drawer } from "~/ui/components/Drawer";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { APP_TIME_ZONE } from "~/locale/format";
|
|
import { AppLink } from "~/components/app/AppLink";
|
|
|
|
const DRAWER_MAX_ITEMS = 10;
|
|
|
|
export type NotificationsDrawerProps = {
|
|
open: boolean;
|
|
items: readonly NotificationCenterItemVM[];
|
|
/** Href of the full notification center route ("show all"). */
|
|
allHref: string;
|
|
onClose: () => void;
|
|
};
|
|
|
|
export function NotificationsDrawer({ open, items, allHref, onClose }: NotificationsDrawerProps) {
|
|
const { t, i18n } = useTranslation();
|
|
const visibleItems = items.slice(0, DRAWER_MAX_ITEMS);
|
|
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "short", timeStyle: "short" });
|
|
|
|
return (
|
|
<Drawer open={open} onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onClose())}>
|
|
<Drawer.Content>
|
|
<div className="flex w-96 max-w-full flex-col gap-6 p-6" data-ui-id="ui.notifications.drawer">
|
|
<div className="flex items-start justify-between gap-4">
|
|
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("notifications.center.drawer.title")}</span>
|
|
<Button variant="tertiary" size="small" onClick={onClose} data-ui-id="ui.notifications.drawer.close">
|
|
{t("notifications.center.drawer.close")}
|
|
</Button>
|
|
</div>
|
|
|
|
{visibleItems.length === 0 ? (
|
|
<div data-ui-id="ui.notifications.drawer.empty">
|
|
<EmptyState title={t("notifications.center.drawer.empty")} body={t("notifications.center.emptyHelper")} />
|
|
</div>
|
|
) : (
|
|
<ul className="flex list-none flex-col gap-3 p-0" aria-label={String(t("notifications.center.listLabel"))}>
|
|
{visibleItems.map((item) => (
|
|
<DrawerItem key={item.id} item={item} formatter={dateTimeFormatter} />
|
|
))}
|
|
</ul>
|
|
)}
|
|
|
|
<div className="flex justify-end">
|
|
<AppLink href={allHref} className="no-underline" data-ui-id="ui.notifications.drawer.showAll">
|
|
<Button variant="secondary">{t("notifications.center.drawer.showAll")}</Button>
|
|
</AppLink>
|
|
</div>
|
|
</div>
|
|
</Drawer.Content>
|
|
</Drawer>
|
|
);
|
|
}
|
|
|
|
function DrawerItem({ item, formatter }: { item: NotificationCenterItemVM; formatter: Intl.DateTimeFormat }) {
|
|
const { t, i18n } = useTranslation();
|
|
const messageLabel = i18n.exists(item.messageKey) ? String(t(item.messageKey)) : String(t("notifications.center.unknownMessage"));
|
|
const timestampIso = item.sentAtIso ?? item.createdAtIso;
|
|
|
|
const body = (
|
|
<div className="flex flex-col gap-0">
|
|
<span
|
|
className={
|
|
item.isRead
|
|
? "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"
|
|
: "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary"
|
|
}
|
|
>
|
|
{messageLabel}
|
|
</span>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{timestampIso ? formatter.format(new Date(timestampIso)) : String(t("notifications.center.timestamps.notRecorded"))}
|
|
</span>
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<li
|
|
className="flex items-start justify-between gap-3 rounded-md border border-solid border-border-default p-3"
|
|
data-row-id={item.id}
|
|
data-read={item.isRead}
|
|
>
|
|
{item.deeplinkHref ? (
|
|
<AppLink href={item.deeplinkHref} className="no-underline" data-ui-id="ui.notifications.drawer.deeplink">
|
|
{body}
|
|
</AppLink>
|
|
) : (
|
|
body
|
|
)}
|
|
{!item.isRead ? (
|
|
<BadgeFeedback farbe="subtle-warning" size="small">
|
|
{t("notifications.center.statuses.unread")}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
</li>
|
|
);
|
|
}
|