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:
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user