From 4c4db14eac9d137b77e204c261345ce7376b3570 Mon Sep 17 00:00:00 2001 From: SundasNoreen Date: Mon, 19 Jun 2023 18:00:06 +0500 Subject: [PATCH 1/2] feat: binded show notification tray status with the backend api --- .../data/__factories__/notifications.factory.js | 2 +- src/Notifications/data/redux.test.js | 2 +- src/Notifications/data/selectors.js | 2 +- src/Notifications/data/slice.js | 6 +++--- src/Notifications/data/thunks.js | 6 +++--- src/learning-header/AuthenticatedUserDropdown.jsx | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Notifications/data/__factories__/notifications.factory.js b/src/Notifications/data/__factories__/notifications.factory.js index f919167..29645bf 100644 --- a/src/Notifications/data/__factories__/notifications.factory.js +++ b/src/Notifications/data/__factories__/notifications.factory.js @@ -8,7 +8,7 @@ Factory.define('notificationsCount') grades: 10, authoring: 5, }) - .attr('showNotificationTray', true); + .attr('showNotificationsTray', true); Factory.define('notification') .sequence('id') diff --git a/src/Notifications/data/redux.test.js b/src/Notifications/data/redux.test.js index f17e6bf..fd19943 100644 --- a/src/Notifications/data/redux.test.js +++ b/src/Notifications/data/redux.test.js @@ -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); diff --git a/src/Notifications/data/selectors.js b/src/Notifications/data/selectors.js index b8d72c2..151c4f1 100644 --- a/src/Notifications/data/selectors.js +++ b/src/Notifications/data/selectors.js @@ -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; diff --git a/src/Notifications/data/slice.js b/src/Notifications/data/slice.js index 8751475..412cc4d 100644 --- a/src/Notifications/data/slice.js +++ b/src/Notifications/data/slice.js @@ -16,7 +16,7 @@ const initialState = { apps: {}, notifications: {}, tabsCount: {}, - showNotificationTray: false, + showNotificationsTray: false, pagination: { count: 10, numPages: 1, @@ -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) => { diff --git a/src/Notifications/data/thunks.js b/src/Notifications/data/thunks.js index 3ffbb82..5ee3894 100644 --- a/src/Notifications/data/thunks.js +++ b/src/Notifications/data/thunks.js @@ -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, }; }; @@ -70,7 +70,7 @@ export const fetchAppsNotificationCount = () => ( ...normalisedData, countByAppName: data.countByAppName, count: data.count, - showNotificationTray: data.showNotificationTray, + showNotificationsTray: data.showNotificationsTray, })); } catch (error) { if (getHttpErrorStatus(error) === 403) { diff --git a/src/learning-header/AuthenticatedUserDropdown.jsx b/src/learning-header/AuthenticatedUserDropdown.jsx index 2ac7beb..0060c50 100644 --- a/src/learning-header/AuthenticatedUserDropdown.jsx +++ b/src/learning-header/AuthenticatedUserDropdown.jsx @@ -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(); @@ -35,7 +35,7 @@ const AuthenticatedUserDropdown = ({ intl, username }) => { return ( <> {intl.formatMessage(messages.help)} - {showNotificationTray && } + {showNotificationsTray && } From 2d737aae7f80767a8a531822fcbc60fa9c97e260 Mon Sep 17 00:00:00 2001 From: ayeshoali Date: Tue, 20 Jun 2023 13:31:15 +0500 Subject: [PATCH 2/2] refactor: fixed data updation in redux --- src/Notifications/data/thunks.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Notifications/data/thunks.js b/src/Notifications/data/thunks.js index 5ee3894..f87e2e1 100644 --- a/src/Notifications/data/thunks.js +++ b/src/Notifications/data/thunks.js @@ -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, - showNotificationsTray: data.showNotificationsTray, - })); + dispatch(fetchNotificationsCountSuccess({ ...normalisedData })); } catch (error) { if (getHttpErrorStatus(error) === 403) { dispatch(fetchNotificationsCountDenied());