import { createElement } from "react"; import type { LucideIcon } from "lucide-react"; import { AlertTriangle, Bell, CircleDollarSign, Clock, Inbox, MessageSquare, ShieldAlert, UserPlus, Wrench, X, } from "lucide-react"; import { Link } from "react-router"; import { Text } from "@/components/ui/text"; import type { NotificationItem } from "@/domain/notifications/types/notification-feed"; import { workOrderViewUrl } from "@/domain/notifications/utils/notification-target-url"; import { isDismissable } from "@/domain/notifications/utils/visible-notification-sections"; const REASON_ICONS: Record = { "severity-critical": AlertTriangle, sla: AlertTriangle, mentions: MessageSquare, unassigned: Inbox, "due-soon": Clock, "no-vendor": Wrench, "aveta-missing": ShieldAlert, activity: MessageSquare, "vendor-conflict": Wrench, }; const ICON_PROPS = { size: 15, "aria-hidden": true, className: "shrink-0", style: { color: "var(--color-text-muted)", marginTop: 2 }, } as const; // Recent activity mixes comments, assignments and uplift decisions; where the row leads tells them apart. function ItemIcon({ item }: { item: NotificationItem }) { if (item.reason === "activity" && item.target.tab === "uplifts") { return ; } if (item.reason === "activity" && item.target.tab !== "comments") { return ; } return createElement(REASON_ICONS[item.reason] ?? Bell, ICON_PROPS); } type NotificationRowProps = { item: NotificationItem; unread: boolean; onOpen: (item: NotificationItem, url?: string) => void; onDismiss: (item: NotificationItem) => void; }; /** A vendor conflict spans several work orders, so each one stays reachable from the row. */ function WorkOrderLinks({ item, onOpen }: Pick) { if (item.reason !== "vendor-conflict" || item.workOrders.length === 0) { return null; } return ( {item.workOrders.map((workOrder) => { const url = workOrderViewUrl(workOrder.id); return ( { event.preventDefault(); onOpen(item, url); }} className="text-xs underline-offset-2 hover:underline" style={{ color: "var(--color-primary)" }} > {workOrder.number != null ? `WO #${workOrder.number}` : `WO ${workOrder.id}`} ); })} ); } export function NotificationRow({ item, unread, onOpen, onDismiss }: NotificationRowProps) { return (
  • {isDismissable(item) && ( )}
  • ); }