feat: add in-app notification system with real-time delivery
Introduces a full in-app notification system with three types (simple, boolean with server-side callbacks, navigate), three scopes (user, trip, admin), fan-out persistence per recipient, and real-time push via WebSocket. Includes a notification bell in the navbar, dropdown, dedicated /notifications page, and a dev-only admin tab for testing all notification variants. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
20
client/src/hooks/useInAppNotificationListener.ts
Normal file
20
client/src/hooks/useInAppNotificationListener.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useEffect } from 'react'
|
||||
import { addListener, removeListener } from '../api/websocket'
|
||||
import { useNotificationStore } from '../store/notificationStore'
|
||||
|
||||
export function useNotificationListener(): void {
|
||||
const handleNew = useNotificationStore(s => s.handleNewNotification)
|
||||
const handleUpdated = useNotificationStore(s => s.handleUpdatedNotification)
|
||||
|
||||
useEffect(() => {
|
||||
const listener = (event: Record<string, unknown>) => {
|
||||
if (event.type === 'notification:new') {
|
||||
handleNew(event.notification as any)
|
||||
} else if (event.type === 'notification:updated') {
|
||||
handleUpdated(event.notification as any)
|
||||
}
|
||||
}
|
||||
addListener(listener)
|
||||
return () => removeListener(listener)
|
||||
}, [handleNew, handleUpdated])
|
||||
}
|
||||
Reference in New Issue
Block a user