diff --git a/src/components/Notification.tsx b/src/components/Notification.tsx index 6b478ab..a21d4fe 100644 --- a/src/components/Notification.tsx +++ b/src/components/Notification.tsx @@ -2,7 +2,9 @@ import { getToken } from '@/config/func' import { useSocket } from '@/pages/pager/hooks/useSocket' import { type FC, useEffect, useCallback, useState } from 'react' import type { NotificationPayload } from '@/types/notification.types' +import { NotificationSubject } from '@/types/notification.types' import NotificationItem from '@/components/NotificationItem' +import { useQueryClient } from '@tanstack/react-query' interface NotificationItemData extends NotificationPayload { id: string @@ -12,6 +14,7 @@ interface NotificationItemData extends NotificationPayload { const Notification: FC = () => { const [notifications, setNotifications] = useState([]) const [audioEnabled, setAudioEnabled] = useState(false) + const queryClient = useQueryClient() const token = getToken() const socketUrl = `${import.meta.env.VITE_SOCKET_URL}/notifications` @@ -65,7 +68,14 @@ const Notification: FC = () => { timestamp: Date.now(), } setNotifications((prev) => [...prev, newNotification]) - }, []) + + // Refetch بر اساس نوع نوتیفیکیشن + if (data.subject === NotificationSubject.PAGER_CREATED) { + queryClient.invalidateQueries({ queryKey: ['pagers'] }) + } else if (data.subject === NotificationSubject.ORDER_CREATED) { + queryClient.invalidateQueries({ queryKey: ['orders'] }) + } + }, [queryClient]) const handleRemoveNotification = useCallback((id: string) => { setNotifications((prev) => prev.filter((notif) => notif.id !== id))