251208:0010 Backend & Frontend Debug
Some checks failed
Spec Validation / validate-markdown (push) Has been cancelled
Spec Validation / validate-diagrams (push) Has been cancelled
Spec Validation / check-todos (push) Has been cancelled

This commit is contained in:
2025-12-08 00:10:37 +07:00
parent 32d820ea6b
commit dcd126d704
99 changed files with 2775 additions and 1480 deletions

View File

@@ -0,0 +1,31 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { notificationService } from '@/lib/services/notification.service';
import { toast } from 'sonner';
export const notificationKeys = {
all: ['notifications'] as const,
unread: () => [...notificationKeys.all, 'unread'] as const,
};
export function useNotifications() {
return useQuery({
queryKey: notificationKeys.unread(),
queryFn: notificationService.getUnread,
refetchInterval: 60 * 1000, // Poll every 1 minute
staleTime: 30 * 1000,
});
}
export function useMarkNotificationRead() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: notificationService.markAsRead,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: notificationKeys.unread() });
},
onError: () => {
toast.error("Failed to mark notification as read");
}
});
}