const initialState = { getQuickNotifications: [], totalForQuick: 0, notifications: [], }; const notificationsReducer = (state = initialState, action) => { switch (action.type) { case "GET_QUICKNOTIFICATIONS": return { ...state, getQuickNotifications: action.payload.getQuickNotifications || [], totalForQuick: (action.payload.getQuickNotifications || []).filter( (notification) => notification.read === false ).length, }; case "GET_SETNOTIFICATIONREAD": return { ...state, setNotificationRead: action.payload.setNotificationRead, //totalForQuick: state.totalForQuick >= 1 ? state.totalForQuick - 1 : 0, }; case "GET_ALLNOTIFICATION": return { ...state, notifications: action.payload.getAllNotifications || [], }; case "GET_NOTIFICATIONREMOVE": return { ...state, notificationRemove: action.payload.notificationRemove, }; } return state; }; export default notificationsReducer;