/* eslint-disable react-hooks/exhaustive-deps */ import React, { useCallback, useEffect, useRef, useState, } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useIntl } from '@edx/frontend-platform/i18n'; import classNames from 'classnames'; import { Badge, Icon, IconButton, OverlayTrigger, Popover, } from '@edx/paragon'; import { NotificationsNone, Settings } from '@edx/paragon/icons'; import { selectNotificationTabsCount } from './data/selectors'; import { resetNotificationState } from './data/thunks'; import { useIsOnLargeScreen, useIsOnMediumScreen } from './data/hook'; import NotificationTabs from './NotificationTabs'; import messages from './messages'; const Notifications = () => { const intl = useIntl(); const dispatch = useDispatch(); const popoverRef = useRef(null); const buttonRef = useRef(null); const [enableNotificationTray, setEnableNotificationTray] = useState(false); const notificationCounts = useSelector(selectNotificationTabsCount()); const isOnMediumScreen = useIsOnMediumScreen(); const isOnLargeScreen = useIsOnLargeScreen(); const hideNotificationTray = useCallback(() => { setEnableNotificationTray(prevState => !prevState); }, []); const handleClickOutsideNotificationTray = useCallback((event) => { if (!popoverRef.current?.contains(event.target) && !buttonRef.current?.contains(event.target)) { setEnableNotificationTray(false); } }, []); useEffect(() => { document.addEventListener('mousedown', handleClickOutsideNotificationTray); return () => { document.removeEventListener('mousedown', handleClickOutsideNotificationTray); dispatch(resetNotificationState()); }; }, []); return (
{intl.formatMessage(messages.notificationTitle)}
)} >
{notificationCounts?.count > 0 && ( {notificationCounts.count} )}
); }; export default Notifications;