61 lines
2.1 KiB
TypeScript
61 lines
2.1 KiB
TypeScript
import clsx from "clsx";
|
|
import { useTranslation } from "react-i18next";
|
|
import { UI_ACTION_IDS } from "~/application/ui/uiRegistry";
|
|
import { BellIcon } from "~/components/ui/icons/vendor";
|
|
|
|
interface Props {
|
|
unseenCount?: number;
|
|
to: string;
|
|
/**
|
|
* AK-P3 (AD-28): when provided the bell opens the notifications drawer
|
|
* instead of navigating; the tenant NavBar wires this together with the
|
|
* live SSE unseen count. Hosts without a drawer (admin) keep the link.
|
|
*/
|
|
onOpen?: () => void;
|
|
}
|
|
|
|
export default function NotificationsButton({ unseenCount, to, onOpen }: Props) {
|
|
const { t } = useTranslation();
|
|
|
|
const className = clsx(
|
|
"text-muted-foreground bg-secondary hover:bg-secondary/90 border-border relative inline-flex items-center rounded-full border p-2 font-medium shadow-inner focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
);
|
|
|
|
const content = (
|
|
<>
|
|
<span className="relative inline-block h-5 w-5 overflow-hidden rounded-full">
|
|
<BellIcon className="h-5 w-5" />
|
|
</span>
|
|
{typeof unseenCount === "number" && unseenCount > 0 && (
|
|
<span className="absolute inset-0 -mr-6 object-right-top" data-ui-id="ui.notifications.bell.count">
|
|
<div className="inline-flex items-center rounded-full border-2 border-white bg-red-500 px-1.5 py-0.5 text-xs font-semibold leading-4 text-white">
|
|
{unseenCount}
|
|
</div>
|
|
</span>
|
|
)}
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<div className="relative">
|
|
<div className="inline-flex divide-x divide-gray-300 rounded-sm shadow-none">
|
|
{onOpen ? (
|
|
<button
|
|
type="button"
|
|
onClick={onOpen}
|
|
data-ui-id={UI_ACTION_IDS.notifications}
|
|
aria-label={t("shell.notifications.ariaLabel")}
|
|
className={className}
|
|
>
|
|
{content}
|
|
</button>
|
|
) : (
|
|
<a href={to} data-ui-id={UI_ACTION_IDS.notifications} aria-label={t("shell.notifications.ariaLabel")} className={className}>
|
|
{content}
|
|
</a>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|