Guest User

Untitled

a guest
Jul 4th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {FETCH_USERS, FETCH_USERS_SUCCESS, FETCH_USERS_FAILURE, RESET} from '../actions/userActions.js';
  2. const INITIAL_STATE = {
  3.     userList: {
  4.         users: [],
  5.         user: {},
  6.         showUserFormModal: false,
  7.         error: null,
  8.         loading: false
  9.     }
  10. };
  11.  
  12. export default function reducer(state = INITIAL_STATE, action) {
  13.     switch (action.type) {
  14.         case FETCH_USERS: {
  15.             return {
  16.                 ...state, userList: {users: [], error: null, loading: true}
  17.             };
  18.         }
  19.         case FETCH_USERS_SUCCESS: {
  20.             return {
  21.                 ...state, userList: {users: action.payload, error: null, loading: false}
  22.             };
  23.         }
  24.         case FETCH_USERS_FAILURE: {
  25.             return {
  26.                 ...state, userList: {users: [], error: action.payload, loading: false}
  27.             };
  28.         }
  29.         case RESET: {
  30.             return {
  31.                 ...state, userList: {users: [], error: action.payload, loading: action.payload}
  32.             };
  33.         }
  34.         default: {
  35.             return state;
  36.         }
  37.     }
  38. };
Advertisement
Add Comment
Please, Sign In to add comment