feat(realtime): implement SSE realtime notifications; publish events from resolvers; remove polling in chat/sidebar/supplies/warehouse and wire realtime refetch
This commit is contained in:
@ -35,6 +35,7 @@ import {
|
||||
} from '@/graphql/mutations'
|
||||
import { GET_SUPPLY_ORDERS } from '@/graphql/queries'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useRealtime } from '@/hooks/useRealtime'
|
||||
|
||||
// Типы для данных заказов
|
||||
interface SupplyOrderItem {
|
||||
@ -167,7 +168,15 @@ export function RealSupplyOrdersTab() {
|
||||
const { data, loading, error, refetch } = useQuery(GET_SUPPLY_ORDERS, {
|
||||
fetchPolicy: 'cache-and-network',
|
||||
notifyOnNetworkStatusChange: true,
|
||||
pollInterval: 30000, // 🔔 Опрашиваем каждые 30 секунд для получения новых заказов
|
||||
})
|
||||
|
||||
// Realtime: обновление списка заказов
|
||||
useRealtime({
|
||||
onEvent: (evt) => {
|
||||
if (evt.type === 'supply-order:new' || evt.type === 'supply-order:updated') {
|
||||
refetch()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
// Мутация для обновления статуса заказа
|
||||
|
@ -11,6 +11,7 @@ import { Button } from '@/components/ui/button'
|
||||
import { GET_PENDING_SUPPLIES_COUNT } from '@/graphql/queries'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useSidebar } from '@/hooks/useSidebar'
|
||||
import { useRealtime } from '@/hooks/useRealtime'
|
||||
|
||||
import { AllSuppliesTab } from './fulfillment-supplies/all-supplies-tab'
|
||||
import { RealSupplyOrdersTab } from './fulfillment-supplies/real-supply-orders-tab'
|
||||
@ -39,12 +40,19 @@ export function SuppliesDashboard() {
|
||||
const [statisticsData, setStatisticsData] = useState<any>(null)
|
||||
|
||||
// Загружаем счетчик поставок, требующих одобрения
|
||||
const { data: pendingData } = useQuery(GET_PENDING_SUPPLIES_COUNT, {
|
||||
pollInterval: 30000, // Обновляем каждые 30 секунд
|
||||
const { data: pendingData, refetch: refetchPending } = useQuery(GET_PENDING_SUPPLIES_COUNT, {
|
||||
fetchPolicy: 'cache-first',
|
||||
errorPolicy: 'ignore',
|
||||
})
|
||||
|
||||
useRealtime({
|
||||
onEvent: (evt) => {
|
||||
if (evt.type === 'supply-order:new' || evt.type === 'supply-order:updated') {
|
||||
refetchPending()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const pendingCount = pendingData?.pendingSuppliesCount
|
||||
// ✅ ПРАВИЛЬНО: Настраиваем уведомления по типам организаций
|
||||
const hasPendingItems = (() => {
|
||||
|
Reference in New Issue
Block a user