invalid query client when get notification
This commit is contained in:
@@ -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<NotificationItemData[]>([])
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user