finished header notifications
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { fetchActiveNotifications, NotificationBody } from '@/app/actions/notificationActions';
|
||||
|
||||
export interface UseActiveNotifications {
|
||||
notifications: NotificationBody[],
|
||||
unreadCount: number
|
||||
}
|
||||
|
||||
export const useActiveNotifications = () => {
|
||||
return useQuery({
|
||||
queryKey: ['activeNotifications'],
|
||||
queryFn: () => {
|
||||
return fetchActiveNotifications()
|
||||
},
|
||||
select: (data: UseActiveNotifications | null) => {
|
||||
if (!data) {
|
||||
return {
|
||||
notifications: [],
|
||||
unreadCount: 0
|
||||
}
|
||||
}
|
||||
return data;
|
||||
},
|
||||
retry: false,
|
||||
refetchInterval: 10000
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { fetchAllNotifications, NotificationBody } from '@/app/actions/notificationActions';
|
||||
|
||||
export interface UseAllNotifications {
|
||||
notifications: NotificationBody[],
|
||||
unreadCount: number
|
||||
}
|
||||
|
||||
export const useAllNotifications = () => {
|
||||
return useQuery({
|
||||
queryKey: ['allNotifications'],
|
||||
queryFn: () => {
|
||||
return fetchAllNotifications()
|
||||
},
|
||||
select: (data: UseAllNotifications | null) => {
|
||||
if (!data) {
|
||||
return {
|
||||
notifications: [],
|
||||
unreadCount: 0
|
||||
}
|
||||
}
|
||||
return data;
|
||||
},
|
||||
retry: false,
|
||||
refetchInterval: 10000
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user