notificationsReducer.js
814 Bytes
import { FETCH_NOTIFICATIONS_FAIL, FETCH_NOTIFICATIONS_REQUEST, FETCH_NOTIFICATIONS_SUCCESS, CLEAR_ERRORS } from "../constants/notificationConstants";
export const getNotificationsReducer = (state = { loading: true, success: false, notifications: null }, action) => {
switch (action.type) {
case FETCH_NOTIFICATIONS_REQUEST:
return {
loading: true,
};
case FETCH_NOTIFICATIONS_SUCCESS:
return {
loading: false,
notifications: action.payload
};
case FETCH_NOTIFICATIONS_FAIL:
return {
loading: false,
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};