Skip to content

Commit

Permalink
Merge pull request #355 from openedx/sundas/INF-903
Browse files Browse the repository at this point in the history
feat: binded show notification tray status with the backend api
  • Loading branch information
sundasnoreen12 authored Jun 20, 2023
2 parents 911cea6 + 2d737aa commit 022515d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Factory.define('notificationsCount')
grades: 10,
authoring: 5,
})
.attr('showNotificationTray', true);
.attr('showNotificationsTray', true);

Factory.define('notification')
.sequence('id')
Expand Down
2 changes: 1 addition & 1 deletion src/Notifications/data/redux.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Notification Redux', () => {
expect(notifications.apps).toEqual({});
expect(notifications.notifications).toEqual({});
expect(notifications.tabsCount).toEqual({});
expect(notifications.showNotificationTray).toEqual(false);
expect(notifications.showNotificationsTray).toEqual(false);
expect(notifications.pagination.count).toEqual(10);
expect(notifications.pagination.numPages).toEqual(1);
expect(notifications.pagination.currentPage).toEqual(1);
Expand Down
2 changes: 1 addition & 1 deletion src/Notifications/data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const selectNotificationTabs = () => state => state.notifications.appsId;

export const selectSelectedAppNotificationIds = (appName) => state => state.notifications.apps[appName] ?? [];

export const selectShowNotificationTray = () => state => state.notifications.showNotificationTray;
export const selectShowNotificationTray = () => state => state.notifications.showNotificationsTray;

export const selectNotifications = () => state => state.notifications.notifications;

Expand Down
6 changes: 3 additions & 3 deletions src/Notifications/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const initialState = {
apps: {},
notifications: {},
tabsCount: {},
showNotificationTray: false,
showNotificationsTray: false,
pagination: {
count: 10,
numPages: 1,
Expand Down Expand Up @@ -62,12 +62,12 @@ const slice = createSlice({
},
fetchNotificationsCountSuccess: (state, { payload }) => {
const {
countByAppName, appIds, apps, count, showNotificationTray,
countByAppName, appIds, apps, count, showNotificationsTray,
} = payload;
state.tabsCount = { count, ...countByAppName };
state.appsId = appIds;
state.apps = apps;
state.showNotificationTray = showNotificationTray;
state.showNotificationsTray = showNotificationsTray;
state.notificationStatus = RequestStatus.LOADED;
},
markNotificationsAsSeenRequest: (state) => {
Expand Down
11 changes: 3 additions & 8 deletions src/Notifications/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import {
} from './api';
import { getHttpErrorStatus } from '../utils';

const normalizeNotificationCounts = ({ countByAppName, count, showNotificationTray }) => {
const normalizeNotificationCounts = ({ countByAppName, count, showNotificationsTray }) => {
const appIds = Object.keys(countByAppName);
const apps = appIds.reduce((acc, appId) => { acc[appId] = []; return acc; }, {});
return {
countByAppName, appIds, apps, count, showNotificationTray,
countByAppName, appIds, apps, count, showNotificationsTray,
};
};

Expand Down Expand Up @@ -66,12 +66,7 @@ export const fetchAppsNotificationCount = () => (
dispatch(fetchNotificationsCountRequest());
const data = await getNotificationCounts();
const normalisedData = normalizeNotificationCounts((camelCaseObject(data)));
dispatch(fetchNotificationsCountSuccess({
...normalisedData,
countByAppName: data.countByAppName,
count: data.count,
showNotificationTray: data.showNotificationTray,
}));
dispatch(fetchNotificationsCountSuccess({ ...normalisedData }));
} catch (error) {
if (getHttpErrorStatus(error) === 403) {
dispatch(fetchNotificationsCountDenied());
Expand Down
4 changes: 2 additions & 2 deletions src/learning-header/AuthenticatedUserDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { RequestStatus } from '../Notifications/data/slice';
import messages from './messages';

const AuthenticatedUserDropdown = ({ intl, username }) => {
const showNotificationTray = useSelector(selectShowNotificationTray());
const showNotificationsTray = useSelector(selectShowNotificationTray());
const notificationStatus = useSelector(selectNotificationStatus());
const dispatch = useDispatch();

Expand All @@ -35,7 +35,7 @@ const AuthenticatedUserDropdown = ({ intl, username }) => {
return (
<>
<a className="text-gray-700" href={`${getConfig().SUPPORT_URL}`}>{intl.formatMessage(messages.help)}</a>
{showNotificationTray && <Notifications />}
{showNotificationsTray && <Notifications />}
<Dropdown className="user-dropdown ml-3">
<Dropdown.Toggle variant="outline-primary">
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" />
Expand Down

0 comments on commit 022515d

Please sign in to comment.