-
Notifications
You must be signed in to change notification settings - Fork 43
feat: implement real-time notification system with event subscription… #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jayking40
wants to merge
1
commit into
Stellar-VaultLink:main
Choose a base branch
from
Jayking40:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
invofi/apps/frontend/src/components/notifications/NotificationBell.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| 'use client'; | ||
|
|
||
| // ── NotificationBell (issue #255) ───────────────────────────────────────────── | ||
| // Bell icon with unread-count badge; toggles the NotificationPanel on click. | ||
|
|
||
| import { useState } from 'react'; | ||
| import { Bell } from 'lucide-react'; | ||
| import { cn } from '@/lib/utils'; | ||
| import { useNotifications } from './NotificationProvider'; | ||
| import { NotificationPanel } from './NotificationPanel'; | ||
|
|
||
| export function NotificationBell() { | ||
| const { unreadCount } = useNotifications(); | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
| const toggle = () => setOpen((v) => !v); | ||
| const close = () => setOpen(false); | ||
|
|
||
| return ( | ||
| <div className="relative"> | ||
| <button | ||
| id="notification-bell" | ||
| onClick={toggle} | ||
| className={cn( | ||
| 'relative flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground', | ||
| open && 'bg-accent text-foreground', | ||
| )} | ||
| aria-label={ | ||
| unreadCount > 0 | ||
| ? `Notifications — ${unreadCount} unread` | ||
| : 'Notifications' | ||
| } | ||
| aria-haspopup="dialog" | ||
| aria-expanded={open} | ||
| > | ||
| <Bell className="h-5 w-5" /> | ||
|
|
||
| {/* Unread badge */} | ||
| {unreadCount > 0 && ( | ||
| <span | ||
| aria-hidden | ||
| className={cn( | ||
| 'absolute -right-0.5 -top-0.5 flex h-4 min-w-[16px] items-center justify-center rounded-full bg-blue-600 px-1 text-[9px] font-bold leading-none text-white ring-1 ring-background', | ||
| unreadCount > 9 && 'min-w-[20px]', | ||
| )} | ||
| > | ||
| {unreadCount > 99 ? '99+' : unreadCount} | ||
| </span> | ||
| )} | ||
| </button> | ||
|
|
||
| <NotificationPanel open={open} onClose={close} /> | ||
| </div> | ||
| ); | ||
| } |
118 changes: 118 additions & 0 deletions
118
invofi/apps/frontend/src/components/notifications/NotificationItem.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| 'use client'; | ||
|
|
||
| // ── NotificationItem (issue #255) ───────────────────────────────────────────── | ||
| // A single row in the notification panel. | ||
|
|
||
| import { Bell, CheckCircle, AlertTriangle, TrendingUp, Info, X } from 'lucide-react'; | ||
| import { formatDistanceToNow } from 'date-fns'; | ||
| import { cn } from '@/lib/utils'; | ||
| import type { AppNotification, NotificationCategory } from '@/types'; | ||
|
|
||
| const CATEGORY_ICON: Record<NotificationCategory, React.ElementType> = { | ||
| offer: TrendingUp, | ||
| repayment: CheckCircle, | ||
| alert: AlertTriangle, | ||
| info: Info, | ||
| }; | ||
|
|
||
| const CATEGORY_COLOR: Record<NotificationCategory, string> = { | ||
| offer: 'text-blue-500 bg-blue-50 dark:bg-blue-950/40', | ||
| repayment: 'text-green-500 bg-green-50 dark:bg-green-950/40', | ||
| alert: 'text-amber-500 bg-amber-50 dark:bg-amber-950/40', | ||
| info: 'text-muted-foreground bg-muted', | ||
| }; | ||
|
|
||
| interface NotificationItemProps { | ||
| notification: AppNotification; | ||
| onMarkRead: (id: string) => void; | ||
| onDismiss: (id: string) => void; | ||
| /** Optional click handler for navigating to the relevant invoice/offer. */ | ||
| onClick?: (notification: AppNotification) => void; | ||
| } | ||
|
|
||
| export function NotificationItem({ | ||
| notification, | ||
| onMarkRead, | ||
| onDismiss, | ||
| onClick, | ||
| }: NotificationItemProps) { | ||
| const Icon = CATEGORY_ICON[notification.category] ?? Bell; | ||
| const colorClass = CATEGORY_COLOR[notification.category]; | ||
|
|
||
| const handleClick = () => { | ||
| if (!notification.read) onMarkRead(notification.id); | ||
| onClick?.(notification); | ||
| }; | ||
|
|
||
| const handleDismiss = (e: React.MouseEvent) => { | ||
| e.stopPropagation(); | ||
| onDismiss(notification.id); | ||
| }; | ||
|
|
||
| const timeAgo = (() => { | ||
| try { | ||
| return formatDistanceToNow(new Date(notification.createdAt), { addSuffix: true }); | ||
| } catch { | ||
| return ''; | ||
| } | ||
| })(); | ||
|
|
||
| return ( | ||
| <div | ||
| role="listitem" | ||
| className={cn( | ||
| 'group relative flex items-start gap-3 rounded-lg px-3 py-2.5 transition-colors cursor-pointer', | ||
| notification.read | ||
| ? 'hover:bg-muted/60' | ||
| : 'bg-blue-50/50 dark:bg-blue-950/20 hover:bg-blue-50 dark:hover:bg-blue-950/30', | ||
| )} | ||
| onClick={handleClick} | ||
| aria-label={`${notification.title}${notification.read ? '' : ' (unread)'}`} | ||
| > | ||
| {/* Category icon */} | ||
| <span | ||
| className={cn( | ||
| 'mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full', | ||
| colorClass, | ||
| )} | ||
| aria-hidden | ||
| > | ||
| <Icon className="h-3.5 w-3.5" /> | ||
| </span> | ||
|
|
||
| {/* Content */} | ||
| <div className="min-w-0 flex-1"> | ||
| <p | ||
| className={cn( | ||
| 'text-sm leading-snug', | ||
| notification.read ? 'text-foreground/70 font-normal' : 'text-foreground font-medium', | ||
| )} | ||
| > | ||
| {notification.title} | ||
| </p> | ||
| <p className="mt-0.5 text-xs text-muted-foreground line-clamp-2">{notification.body}</p> | ||
| {timeAgo && ( | ||
| <p className="mt-1 text-[10px] text-muted-foreground/60">{timeAgo}</p> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Unread dot */} | ||
| {!notification.read && ( | ||
| <span | ||
| className="mt-1.5 h-2 w-2 shrink-0 rounded-full bg-blue-500" | ||
| aria-label="Unread" | ||
| /> | ||
| )} | ||
|
|
||
| {/* Dismiss button (visible on hover) */} | ||
| <button | ||
| onClick={handleDismiss} | ||
| className="absolute right-2 top-2 hidden h-5 w-5 items-center justify-center rounded text-muted-foreground hover:text-foreground group-hover:flex transition-colors" | ||
| aria-label={`Dismiss notification: ${notification.title}`} | ||
| id={`dismiss-notification-${notification.id}`} | ||
| > | ||
| <X className="h-3 w-3" /> | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Make notification actions keyboard accessible.
The clickable row is a non-focusable
div. Keyboard users cannot mark it read or follow its invoice link.The dismiss button uses
hidden group-hover:flex. It stays hidden until pointer hover, so keyboard users cannot focus it.Use a focusable semantic control for the row. Keep the dismiss action as a separate button. Show the dismiss button on keyboard focus with a focus-visible or focus-within state.
🤖 Prompt for AI Agents