Skip to content

Commit

Permalink
Finishing touches for new action reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
arivepr committed Aug 10, 2023
1 parent a89c8aa commit ffb9320
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 70 deletions.
7 changes: 3 additions & 4 deletions src/components/NotificationsDrawer/NotificationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [<DropdownItem key="read" onClick={onCheckboxToggle}>{`Mark as ${!notification.read ? 'read' : 'unread'}`}</DropdownItem>];
Expand Down
8 changes: 4 additions & 4 deletions src/redux/action-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
55 changes: 2 additions & 53 deletions src/redux/chromeReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -344,7 +339,7 @@ export function toggleNotificationsReducer(state: ChromeState) {
...state,
notifications: {
...state.notifications,
data: [],
data: testData,

Check failure on line 342 in src/redux/chromeReducers.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
isExpanded: !state.notifications?.isExpanded,
},
};
Expand Down Expand Up @@ -398,49 +393,3 @@ export function markAllNotificationsAsUnread(state: ChromeState): ChromeState {
};
}

Check failure on line 395 in src/redux/chromeReducers.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
// 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;
// }
// }
11 changes: 2 additions & 9 deletions src/redux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
loginReducer,
markAccessRequestRequestReducer,
markActiveProduct,
// notificationsReducer,
markNotificationAsRead,
markNotificationAsUnread,
markAllNotificationsAsRead,

Check failure on line 20 in src/redux/index.ts

View workflow job for this annotation

GitHub Actions / lint

Member 'markAllNotificationsAsRead' of the import declaration should be sorted alphabetically
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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')) || {};

Check failure on line 151 in src/redux/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
return {
chrome: (
Expand All @@ -172,8 +166,7 @@ export default function (): {
scalprumConfig: {},
moduleRoutes: [],
notifications: {
//TODO: Figure out why this is the difference from chromeReducers
data: [],
data: [],

Check failure on line 169 in src/redux/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
isExpanded: false,
count: 0,
},
Expand Down

0 comments on commit ffb9320

Please sign in to comment.