adminMainPageReducer.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import * as types from "../actionTypes/actionTypes"
  2. import {eventFormInitialValue} from "../state/addEventInitialValue"
  3. export default (state = eventFormInitialValue, action) => {
  4. switch (action.type) {
  5. //POST
  6. case types.POST_NEW_EVENT_REQUEST_SUCCESS: {
  7. console.log('reducer add event success', action.payload)
  8. return {
  9. state,
  10. addEventMessage: "New event has been added"
  11. }
  12. }
  13. case types.POST_NEW_EVENT_REQUEST_FAIL: {
  14. console.log('reducer add event fail', action.payload)
  15. return { ...state, error: action.payload }
  16. }
  17. // GET ALL EVENTS
  18. case types.GET_EVENTS_REQUEST: {
  19. return state;
  20. }
  21. case types.GET_EVENTS_REQUEST_SUCCESS: {
  22. const { data } = action.payload;
  23. const eventList = Object.keys(data).reduce((prev, elem) => {
  24. return prev.concat({
  25. ...data[elem],
  26. // id: elem
  27. });
  28. }, []);
  29. return { ...state, eventList };
  30. }
  31. case types.GET_EVENTS_REQUEST_FAIL: {
  32. return state;
  33. }
  34. // REMOVE
  35. case types.REMOVE_EVENT_REQUEST: {
  36. return state;
  37. }
  38. case types.REMOVE_EVENT_REQUEST_SUCCESS: {
  39. const { id } = action.payload;
  40. return {
  41. ...state,
  42. eventList: state.eventList.filter(el => el.id !== id)
  43. };
  44. }
  45. case types.REMOVE_EVENT_REQUEST_FAIL: {
  46. return state;
  47. }
  48. default:
  49. return state;
  50. }
  51. }