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

@@ -1,27 +1,24 @@
import React from 'react';
import { useQuery } from '@tanstack/react-query';
import { useEventContext } from '../../context/EventContext';
import { listGuestNotifications } from '../../api';
import { listNotificationLogs } from '../../api';
/**
* Badge count for notifications bell in the mobile shell.
* Fetches guest notifications for the active event and returns count.
* Uses tenant notification logs so the badge matches the notifications screen.
*/
export function useNotificationsBadge() {
const { activeEvent } = useEventContext();
const slug = activeEvent?.slug;
const { data: count = 0 } = useQuery<number>({
queryKey: ['mobile', 'notifications', 'badge', slug],
enabled: Boolean(slug),
queryKey: ['mobile', 'notifications', 'badge', 'tenant'],
staleTime: 60_000,
queryFn: async () => {
if (!slug) {
return 0;
const logs = await listNotificationLogs({ perPage: 1 });
const meta: any = logs.meta ?? {};
if (typeof meta.unread_count === 'number') {
return meta.unread_count;
}
const notifications = await listGuestNotifications(slug);
return Array.isArray(notifications) ? notifications.length : 0;
return Array.isArray(logs.data) ? logs.data.filter((log) => log.is_read === false).length : 0;
},
retry: 1,
});
return React.useMemo(() => ({ count }), [count]);