import * as types from "../actionTypes/actionTypes" import {eventFormInitialValue} from "../state/addEventInitialValue" export default (state = eventFormInitialValue, 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 = Object.keys(data).reduce((prev, elem) => { return prev.concat({ ...data[elem], // id: elem }); }, []); 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; } }