{intl.formatMessage(messages.noNotificationsMessage)}
} @@ -74,10 +79,14 @@ function NotificationTray({ NotificationTray.propTypes = { intl: intlShape.isRequired, toggleNotificationTray: PropTypes.func, + onNotificationSeen: PropTypes.func, + upgradeNotificationCurrentState: PropTypes.string.isRequired, + setupgradeNotificationCurrentState: PropTypes.func.isRequired, }; NotificationTray.defaultProps = { toggleNotificationTray: null, + onNotificationSeen: null, }; export default injectIntl(NotificationTray); diff --git a/src/courseware/course/NotificationTrigger.jsx b/src/courseware/course/NotificationTrigger.jsx index 3486ae4e..f6799533 100644 --- a/src/courseware/course/NotificationTrigger.jsx +++ b/src/courseware/course/NotificationTrigger.jsx @@ -1,12 +1,31 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; +import { getLocalStorage, setLocalStorage } from '../../data/localStorage'; import NotificationIcon from './NotificationIcon'; import messages from './messages'; -function NotificationTrigger({ intl, toggleNotificationTray, isNotificationTrayVisible }) { +function NotificationTrigger({ + intl, toggleNotificationTray, isNotificationTrayVisible, notificationStatus, setNotificationStatus, + upgradeNotificationCurrentState, +}) { + /* Re-show a red dot beside the notification trigger for each of the 7 UpgradeNotification stages + The upgradeNotificationCurrentState prop will be available after UpgradeNotification mounts. Once available, + compare with the last state they've seen, and if it's different then set dot back to red */ + function UpdateUpgradeNotificationLastSeen() { + if (upgradeNotificationCurrentState) { + if (getLocalStorage('upgradeNotificationLastSeen') !== upgradeNotificationCurrentState) { + setNotificationStatus('active'); + setLocalStorage('notificationStatus', 'active'); + setLocalStorage('upgradeNotificationLastSeen', upgradeNotificationCurrentState); + } + } + } + + useEffect(() => { UpdateUpgradeNotificationLastSeen(); }); + return ( ); } @@ -23,7 +41,10 @@ function NotificationTrigger({ intl, toggleNotificationTray, isNotificationTrayV NotificationTrigger.propTypes = { intl: intlShape.isRequired, toggleNotificationTray: PropTypes.func.isRequired, + notificationStatus: PropTypes.string.isRequired, + setNotificationStatus: PropTypes.func.isRequired, isNotificationTrayVisible: PropTypes.func.isRequired, + upgradeNotificationCurrentState: PropTypes.string.isRequired, }; export default injectIntl(NotificationTrigger); diff --git a/src/courseware/course/NotificationTrigger.test.jsx b/src/courseware/course/NotificationTrigger.test.jsx index 32cbab75..e48588c4 100644 --- a/src/courseware/course/NotificationTrigger.test.jsx +++ b/src/courseware/course/NotificationTrigger.test.jsx @@ -4,27 +4,51 @@ import { render, initializeTestStore, screen, fireEvent, } from '../../setupTest'; import NotificationTrigger from './NotificationTrigger'; +import { getLocalStorage } from '../../data/localStorage'; describe('Notification Trigger', () => { let mockData; + // let mockDataSameState; + // let mockDataDifferentState; const courseMetadata = Factory.build('courseMetadata'); - beforeAll(async () => { + beforeEach(async () => { await initializeTestStore({ courseMetadata, excludeFetchCourse: true, excludeFetchSequence: true }); mockData = { toggleNotificationTray: () => {}, isNotificationTrayVisible: () => {}, + notificationStatus: 'active', + setNotificationStatus: () => {}, + upgradeNotificationCurrentState: 'FPDdaysLeft', }; }); - it('renders notification trigger with icon', async () => { + it('renders notification trigger icon with red dot when notificationStatus is active', async () => { const { container } = render(