From ffb93200e0b96f3d78f20e46127cc743a39d58e9 Mon Sep 17 00:00:00 2001 From: Alexander Rivera Date: Thu, 10 Aug 2023 17:42:38 -0400 Subject: [PATCH] Finishing touches for new action reducers --- .../NotificationsDrawer/NotificationItem.tsx | 7 +-- src/redux/action-types.ts | 8 +-- src/redux/chromeReducers.ts | 55 +------------------ src/redux/index.ts | 11 +--- 4 files changed, 11 insertions(+), 70 deletions(-) diff --git a/src/components/NotificationsDrawer/NotificationItem.tsx b/src/components/NotificationsDrawer/NotificationItem.tsx index 422ea1b908..f1a39f556d 100644 --- a/src/components/NotificationsDrawer/NotificationItem.tsx +++ b/src/components/NotificationsDrawer/NotificationItem.tsx @@ -13,20 +13,19 @@ import { } from '@patternfly/react-core'; import { useDispatch } from 'react-redux'; import { Notifications } from '../../redux/store'; -import { MARK_NOTIFICATION_AS_READ, MARK_NOTIFICATION_AS_UNREAD } from '../../redux/action-types'; +import { markNotificationAsRead, markNotificationAsUnread } from '../../redux/actions'; const NotificationItem = ({ notification }: { notification: Notifications['data'][0] }) => { const [isDropdownOpen, setIsDropdownOpen] = useState(false); const dispatch = useDispatch(); - console.log('This is my current notification item: ', notification); const onDropdownToggle = (isOpen: boolean) => { setIsDropdownOpen(isOpen); }; const onCheckboxToggle = () => { - if (!notification.read) dispatch({ type: MARK_NOTIFICATION_AS_READ, payload: notification.id }); - else dispatch({ type: MARK_NOTIFICATION_AS_UNREAD, payload: notification.id }); + if (!notification.read) dispatch(markNotificationAsRead(notification.id)); + else dispatch(markNotificationAsUnread(notification.id)); }; const dropdownItems = [{`Mark as ${!notification.read ? 'read' : 'unread'}`}]; diff --git a/src/redux/action-types.ts b/src/redux/action-types.ts index 28ca3c4da6..1e2dfee273 100644 --- a/src/redux/action-types.ts +++ b/src/redux/action-types.ts @@ -42,7 +42,7 @@ export const SET_GATEWAY_ERROR = '@@chrome/set-gateway-error'; export const TOGGLE_NOTIFICATIONS_DRAWER = '@@chrome/toggle-notifications-drawer'; -export const MARK_NOTIFICATION_AS_READ = '@@chrome/mark_notification_as_read'; -export const MARK_NOTIFICATION_AS_UNREAD = '@@chrome/mark_notification_as_unread'; -export const MARK_ALL_NOTIFICATION_AS_READ = '@@chrome/mark_all_notification_as_read'; -export const MARK_ALL_NOTIFICATION_AS_UNREAD = '@@chrome/mark_all_notification_as_unread'; +export const MARK_NOTIFICATION_AS_READ = '@@chrome/mark-notification-as-read'; +export const MARK_NOTIFICATION_AS_UNREAD = '@@chrome/mark-notification-as-unread'; +export const MARK_ALL_NOTIFICATION_AS_READ = '@@chrome/mark-all-notification-as-read'; +export const MARK_ALL_NOTIFICATION_AS_UNREAD = '@@chrome/mark-all-notification-as-unread'; diff --git a/src/redux/chromeReducers.ts b/src/redux/chromeReducers.ts index ee022b4776..5aed0eb26a 100644 --- a/src/redux/chromeReducers.ts +++ b/src/redux/chromeReducers.ts @@ -5,12 +5,7 @@ import { ChromeModule, NavItem, Navigation } from '../@types/types'; import { ITLess, generateRoutesList, highlightItems, isBeta, levelArray } from '../utils/common'; import { ThreeScaleError } from '../utils/responseInterceptors'; import { AccessRequest, ChromeState, NotificationData } from './store'; -import { - MARK_ALL_NOTIFICATION_AS_READ, - MARK_ALL_NOTIFICATION_AS_UNREAD, - MARK_NOTIFICATION_AS_READ, - MARK_NOTIFICATION_AS_UNREAD, -} from './action-types'; +import { testData } from './notificationTestData'; export function contextSwitcherBannerReducer(state: ChromeState): ChromeState { return { @@ -344,7 +339,7 @@ export function toggleNotificationsReducer(state: ChromeState) { ...state, notifications: { ...state.notifications, - data: [], + data: testData, isExpanded: !state.notifications?.isExpanded, }, }; @@ -398,49 +393,3 @@ export function markAllNotificationsAsUnread(state: ChromeState): ChromeState { }; } -// export function notificationsReducer(state: ChromeState, action: { type: string; payload?: number }): ChromeState { -// switch (action.type) { -// case MARK_NOTIFICATION_AS_READ: -// return { -// ...state, -// notifications: { -// isExpanded: state.notifications?.isExpanded || false, -// count: state.notifications?.count || 0, -// data: (state.notifications?.data || []).map((notification: NotificationData) => -// notification.id === action.payload ? { ...notification, read: true } : notification -// ), -// }, -// }; -// case MARK_NOTIFICATION_AS_UNREAD: -// return { -// ...state, -// notifications: { -// isExpanded: state.notifications?.isExpanded || false, -// count: state.notifications?.count || 0, -// data: (state.notifications?.data || []).map((notification: NotificationData) => -// notification.id === action.payload ? { ...notification, read: false } : notification -// ), -// }, -// }; -// case MARK_ALL_NOTIFICATION_AS_READ: -// return { -// ...state, -// notifications: { -// isExpanded: state.notifications?.isExpanded || false, -// count: state.notifications?.count || 0, -// data: (state.notifications?.data || []).map((notification) => ({ ...notification, read: true })), -// }, -// }; -// case MARK_ALL_NOTIFICATION_AS_UNREAD: -// return { -// ...state, -// notifications: { -// isExpanded: state.notifications?.isExpanded || false, -// count: state.notifications?.count || 0, -// data: (state.notifications?.data || []).map((notification) => ({ ...notification, read: false })), -// }, -// }; -// default: -// return state; -// } -// } diff --git a/src/redux/index.ts b/src/redux/index.ts index a6975ce29d..9f490f5a3a 100644 --- a/src/redux/index.ts +++ b/src/redux/index.ts @@ -15,7 +15,6 @@ import { loginReducer, markAccessRequestRequestReducer, markActiveProduct, - // notificationsReducer, markNotificationAsRead, markNotificationAsUnread, markAllNotificationsAsRead, @@ -112,11 +111,7 @@ const reducers = { [MARK_NOTIFICATION_AS_READ]: markNotificationAsRead, [MARK_NOTIFICATION_AS_UNREAD]: markNotificationAsUnread, [MARK_ALL_NOTIFICATION_AS_READ]: markAllNotificationsAsRead, - [MARK_ALL_NOTIFICATION_AS_UNREAD]:markAllNotificationsAsUnread, - // [MARK_NOTIFICATION_AS_READ]: notificationsReducer, - // [MARK_NOTIFICATION_AS_UNREAD]: notificationsReducer, - // [MARK_ALL_NOTIFICATION_AS_READ]: notificationsReducer, - // [MARK_ALL_NOTIFICATION_AS_UNREAD]: notificationsReducer, + [MARK_ALL_NOTIFICATION_AS_UNREAD]: markAllNotificationsAsUnread, }; const globalFilter = { @@ -153,7 +148,6 @@ export default function (): { chrome: (state: ChromeState, action: AnyAction) => ChromeState; globalFilter: (state: GlobalFilterState, action: AnyAction) => ChromeState; } { - // const chromeInitialState = JSON.parse(localStorage.getItem('chrome')) || {}; return { chrome: ( @@ -172,8 +166,7 @@ export default function (): { scalprumConfig: {}, moduleRoutes: [], notifications: { - //TODO: Figure out why this is the difference from chromeReducers - data: [], + data: [], isExpanded: false, count: 0, },