Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 2x 2x 42x 42x 42x 42x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x | import { memo } from "react";
import {
MessageSquare,
Clock,
Star,
Bell,
Check,
Trash2,
MoreVertical,
} from "lucide-react";
import { Button } from "../ui/button";
import { DropdownMenu } from "../ui/dropdown-menu";
import type { NotificationItem } from "../../lib/api/notifications";
import { formatRelativeDate } from "../../lib/format-date";
export interface NotificationRowProps {
notification: NotificationItem;
isSelected: boolean;
onSelect: (id: string, checked: boolean) => void;
onRead: (id: string) => void;
onDelete: (id: string) => void;
onClick: (notification: NotificationItem) => void;
}
const categoryConfig: Record<
string,
{ icon: typeof Bell; iconBg: string; badgeBg: string; label: string }
> = {
enquiry: {
icon: MessageSquare,
iconBg: "bg-info-light",
badgeBg: "bg-info-light text-info",
label: "Enquiry",
},
reminder: {
icon: Clock,
iconBg: "bg-warning-light",
badgeBg: "bg-warning-light text-warning",
label: "Reminder",
},
milestone: {
icon: Star,
iconBg: "bg-success-light",
badgeBg: "bg-success-light text-success",
label: "Milestone",
},
other: {
icon: Bell,
iconBg: "bg-background-muted",
badgeBg: "bg-background-muted text-foreground-muted",
label: "Other",
},
};
export const NotificationRow = memo(function NotificationRow({
notification,
isSelected,
onSelect,
onRead,
onDelete,
onClick,
}: NotificationRowProps) {
const isUnread = !notification.readAt;
const config = categoryConfig[notification.category] || categoryConfig.other;
const TypeIcon = config.icon;
return (
<button
type="button"
className={`flex items-center gap-3 sm:gap-4 p-3 border rounded-lg transition-colors cursor-pointer w-full text-left ${
isUnread
? "bg-primary-50 border-primary-300 hover:bg-primary-100/70"
: "bg-background-elevated border-border-default hover:bg-background-muted/50"
}`}
onClick={() => onClick(notification)}
>
{/* Checkbox */}
<input
type="checkbox"
checked={isSelected}
onChange={(e) => {
e.stopPropagation();
onSelect(notification.id, e.target.checked);
}}
onClick={(e) => e.stopPropagation()}
className="h-4 w-4 rounded border-border-strong text-primary-600 focus:ring-primary-500/40 shrink-0 cursor-pointer"
/>
{/* Unread dot */}
{isUnread ? (
<span className="h-1.5 w-1.5 rounded-full bg-primary-600 shrink-0" />
) : (
<span className="h-1.5 w-1.5 shrink-0" />
)}
{/* Type icon */}
<div
className={`h-8 w-8 rounded-full flex items-center justify-center shrink-0 ${config.iconBg}`}
>
<TypeIcon className="h-4 w-4" />
</div>
{/* Title + body */}
<div className="flex flex-col min-w-0 flex-1">
<span
className={`text-sm truncate ${
isUnread
? "font-semibold text-foreground-default"
: "font-medium text-foreground-muted"
}`}
title={notification.title}
>
{notification.title}
</span>
{notification.body && (
<span className="text-xs text-foreground-subtle truncate">
{notification.body}
</span>
)}
</div>
{/* Right section: category badge + timestamp + actions — fixed width for alignment */}
<div className="hidden sm:flex items-center gap-2 shrink-0 w-[260px] justify-end">
<span
className={`px-2 py-0.5 text-xs font-medium rounded-full shrink-0 ${config.badgeBg}`}
>
{config.label}
</span>
<span className="text-xs text-foreground-subtle w-20 text-right shrink-0">
{formatRelativeDate(notification.dateCreated, { granularity: "time" })}
</span>
<div className="flex items-center gap-1 w-[72px] justify-end">
{isUnread && (
<Button
variant="ghost"
size="sm"
title="Mark as read"
className="p-2"
onClick={(e) => {
e.stopPropagation();
onRead(notification.id);
}}
>
<Check className="h-4 w-4" />
</Button>
)}
<Button
variant="ghost"
size="sm"
title="Delete"
className="p-2 text-foreground-muted hover:text-error"
onClick={(e) => {
e.stopPropagation();
onDelete(notification.id);
}}
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
</div>
{/* Mobile overflow menu — stopPropagation prevents row click when using dropdown */}
{/* biome-ignore lint/a11y/noStaticElementInteractions: event propagation boundary for nested interactive element */}
<div
className="flex sm:hidden shrink-0"
onClick={(e) => e.stopPropagation()}
onKeyDown={(e) => e.stopPropagation()}
>
<DropdownMenu
trigger={
<Button variant="ghost" size="sm" className="p-2">
<MoreVertical className="h-4 w-4" />
</Button>
}
items={[
...(isUnread
? [
{
label: "Mark as read",
icon: <Check className="h-4 w-4" />,
onClick: () => onRead(notification.id),
},
]
: []),
{
label: "Delete",
icon: <Trash2 className="h-4 w-4" />,
onClick: () => onDelete(notification.id),
variant: "destructive" as const,
},
]}
/>
</div>
</button>
);
});
|