123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import * as types from "../actionTypes/actionTypes"
- import initialState from "../state/addEventInitialValue";
- export default (state = initialState, action) => {
- switch (action.type) {
- //POST
- case types.POST_NEW_EVENT_REQUEST_SUCCESS: {
- console.log('reducer add event success', action.payload)
- return {
- state,
- addEventMessage: "New event has been added"
- }
- }
- case types.POST_NEW_EVENT_REQUEST_FAIL: {
- console.log('reducer add event fail', action.payload)
- return { ...state, error: action.payload }
- }
- // GET ALL EVENTS
- case types.GET_EVENTS_REQUEST: {
- return state;
- }
- case types.GET_EVENTS_REQUEST_SUCCESS: {
- const { data } = action.payload;
- const eventList = data.events
- return { ...state, eventList };
- }
- case types.GET_EVENTS_REQUEST_FAIL: {
- return state;
- }
- // REMOVE
- case types.REMOVE_EVENT_REQUEST: {
- return state;
- }
- case types.REMOVE_EVENT_REQUEST_SUCCESS: {
- const { id } = action.payload;
- return {
- ...state,
- eventList: state.eventList.filter(el => el.id !== id)
- };
- }
- case types.REMOVE_EVENT_REQUEST_FAIL: {
- return state;
- }
- default:
- return state;
- }
- }
|