diff --git a/frontend/src/components/NotificationCenter.tsx b/frontend/src/components/NotificationCenter.tsx index 635fd9d1..132f8c5e 100644 --- a/frontend/src/components/NotificationCenter.tsx +++ b/frontend/src/components/NotificationCenter.tsx @@ -5,15 +5,18 @@ import { Bell, Settings, X } from 'lucide-react'; import { useNotifications } from '@/hooks/useApi'; import { useWebPush } from '@/hooks/useWebPush'; import { formatDistanceToNow } from 'date-fns'; -import { ru } from 'date-fns/locale'; +import { ru } from 'date-fns/locale/ru'; export function NotificationCenter() { const [isOpen, setIsOpen] = useState(false); const [showSettings, setShowSettings] = useState(false); const dropdownRef = useRef(null); - const { notifications, unreadCount, markAsRead, markAllAsRead, loading } = useNotifications(); + const { notifications: notificationsData, unreadCount, markAsRead, markAllAsRead, loading } = useNotifications(); const { isSupported, isSubscribed, subscribe, unsubscribe, permission, isLoading: pushLoading } = useWebPush(); + + // Обеспечиваем что notifications всегда массив + const notifications = Array.isArray(notificationsData) ? notificationsData : []; // Закрытие при клике вне компонента useEffect(() => { diff --git a/frontend/src/hooks/useApi.ts b/frontend/src/hooks/useApi.ts index 07bf6c02..22bbaf9c 100644 --- a/frontend/src/hooks/useApi.ts +++ b/frontend/src/hooks/useApi.ts @@ -180,10 +180,13 @@ export function useNotifications() { try { const data = await apiClient.getNotifications(); const notifs = data.results || data; - setNotifications(notifs); - setUnreadCount(notifs.filter((n: any) => !n.is_read).length); + // Убеждаемся что notifs это массив + const notificationsArray = Array.isArray(notifs) ? notifs : []; + setNotifications(notificationsArray); + setUnreadCount(notificationsArray.filter((n: any) => !n.is_read).length); } catch (err) { setError(err as Error); + setNotifications([]); // В случае ошибки устанавливаем пустой массив } finally { setLoading(false); }