feat: integrated notifications tray with backend apis (#363)

* feat: integrated notifications tray with backend apis

* test: updates test cases

* refactor: loader added and resolves minor nits

* test: fixes test cases related to pagination

* refactor: moved pagination to normalised data
This commit is contained in:
ayesha waris
2023-07-10 13:18:44 +05:00
committed by GitHub
parent 42e831a693
commit 0ce451cfd2
15 changed files with 146 additions and 149 deletions

View File

@@ -23,7 +23,7 @@ import {
markNotificationsAsReadFailure,
} from './slice';
import {
getNotifications, getNotificationCounts, markNotificationSeen, markAllNotificationRead, markNotificationRead,
getNotificationsList, getNotificationCounts, markNotificationSeen, markAllNotificationRead, markNotificationRead,
} from './api';
import { getHttpErrorStatus } from '../utils';
@@ -35,21 +35,26 @@ const normalizeNotificationCounts = ({ countByAppName, count, showNotificationsT
};
};
const normalizeNotifications = ({ notifications }) => {
const newNotificationIds = notifications.map(notification => notification.id.toString());
const notificationsKeyValuePair = notifications.reduce((acc, obj) => { acc[obj.id] = obj; return acc; }, {});
const normalizeNotifications = (data) => {
const newNotificationIds = data.results.map(notification => notification.id.toString());
const notificationsKeyValuePair = data.results.reduce((acc, obj) => { acc[obj.id] = obj; return acc; }, {});
const pagination = {
numPages: data.numPages,
currentPage: data.currentPage,
hasMorePages: !!data.next,
};
return {
newNotificationIds, notificationsKeyValuePair,
newNotificationIds, notificationsKeyValuePair, pagination,
};
};
export const fetchNotificationList = ({ appName, page, pageSize }) => (
export const fetchNotificationList = ({ appName, page }) => (
async (dispatch) => {
try {
dispatch(fetchNotificationRequest({ appName }));
const data = await getNotifications(appName, page, pageSize);
const data = await getNotificationsList(appName, page);
const normalisedData = normalizeNotifications((camelCaseObject(data)));
dispatch(fetchNotificationSuccess({ ...normalisedData, numPages: data.numPages, currentPage: data.currentPage }));
dispatch(fetchNotificationSuccess({ ...normalisedData }));
} catch (error) {
if (getHttpErrorStatus(error) === 403) {
dispatch(fetchNotificationDenied(appName));