createTopics.js 882 B

12345678910111213141516171819202122232425262728293031323334
  1. import * as actionTypes from '../../../constants/admin';
  2. import initialState from '../../initialState';
  3. export default function topic(state = initialState.topicId, {payload, type, error}) {
  4. switch (type) { // payload.type -> type
  5. case actionTypes.CREATE_TOPICS_REQUEST: {
  6. return {
  7. ...state,
  8. isFetching: true,
  9. // payload
  10. }
  11. }
  12. case actionTypes.CREATE_TOPICS_REQUEST_SUCCESS: {
  13. const {data:{topic}}=payload
  14. return {
  15. ...state,
  16. isFetching: false,
  17. topic
  18. }
  19. }
  20. case actionTypes.CREATE_TOPICS_REQUEST_FAILURE: {
  21. return {
  22. ...state,
  23. isFetching: false,
  24. error
  25. }
  26. }
  27. default: {
  28. return state;
  29. }
  30. }
  31. }