fixed notification system and added a new tenant notifications receipt table to track read status and filter messages by scope.

This commit is contained in:
Codex Agent
2025-12-17 10:57:19 +01:00
parent 0aae494945
commit d64839ba2f
31 changed files with 1089 additions and 127 deletions

View File

@@ -16,6 +16,7 @@ export type NotificationCenterValue = {
totalCount: number;
loading: boolean;
refresh: () => Promise<void>;
setFilters: (filters: { status?: 'new' | 'read' | 'dismissed' | 'all'; scope?: 'all' | 'uploads' | 'tips' | 'general' }) => void;
markAsRead: (id: number) => Promise<void>;
dismiss: (id: number) => Promise<void>;
eventToken: string;
@@ -30,6 +31,10 @@ export function NotificationCenterProvider({ eventToken, children }: { eventToke
const [notifications, setNotifications] = React.useState<GuestNotificationItem[]>([]);
const [unreadCount, setUnreadCount] = React.useState(0);
const [loadingNotifications, setLoadingNotifications] = React.useState(true);
const [filters, setFiltersState] = React.useState<{ status?: 'new' | 'read' | 'dismissed' | 'all'; scope?: 'all' | 'uploads' | 'tips' | 'general' }>({
status: 'new',
scope: 'all',
});
const etagRef = React.useRef<string | null>(null);
const fetchLockRef = React.useRef(false);
const [lastFetchedAt, setLastFetchedAt] = React.useState<Date | null>(null);
@@ -59,7 +64,11 @@ export function NotificationCenterProvider({ eventToken, children }: { eventToke
}
try {
const result = await fetchGuestNotifications(eventToken, etagRef.current);
const statusFilter = filters.status && filters.status !== 'all' ? (filters.status === 'new' ? 'unread' : filters.status) : undefined;
const result = await fetchGuestNotifications(eventToken, etagRef.current, {
status: statusFilter as any,
scope: filters.scope,
});
if (!result.notModified) {
setNotifications(result.notifications);
setUnreadCount(result.unreadCount);
@@ -217,6 +226,11 @@ export function NotificationCenterProvider({ eventToken, children }: { eventToke
[eventToken, loadNotifications]
);
const setFilters = React.useCallback((next: { status?: 'new' | 'read' | 'dismissed' | 'all'; scope?: 'all' | 'uploads' | 'tips' | 'general' }) => {
setFiltersState((prev) => ({ ...prev, ...next }));
void loadNotifications({ silent: true });
}, [loadNotifications]);
const refresh = React.useCallback(async () => {
await Promise.all([loadNotifications(), refreshQueue()]);
}, [loadNotifications, refreshQueue]);
@@ -232,6 +246,7 @@ export function NotificationCenterProvider({ eventToken, children }: { eventToke
totalCount,
loading,
refresh,
setFilters,
markAsRead,
dismiss,
eventToken,