{"size": 828, "ext": "js", "max_stars_repo_path": "app/containers/UsersPage/reducer.js", "max_stars_repo_name": "duydinh77/todoApp", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/containers/UsersPage/reducer.js", "max_issues_repo_name": "duydinh77/todoApp", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/containers/UsersPage/reducer.js", "max_forks_repo_name": "duydinh77/todoApp", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.3783783784, "max_line_length": 58, "alphanum_fraction": 0.6280193237}
/*
 *
 * UsersPage reducer
 *
 */
import produce from 'immer';
import * as actions from './constants';

export const initialState = {
  isFetching: false,
  users: [],
  totalUsers: 0,
  errors: [],
};

/* eslint-disable default-case, no-param-reassign */
const usersPageReducer = (state = initialState, action) =>
  produce(state, draft => {
    switch (action.type) {
      case actions.FETCH_USERS:
        draft.totalUsers = 0;
        draft.isFetching = true;
        break;
      case actions.FETCH_USERS_SUCCESS:
        draft.isFetching = false;
        draft.users = action.data.data;
        draft.totalUsers = action.data.total;
        break;
      case actions.FETCH_USERS_FAILURE:
        draft.isFetching = false;
        draft.errors = action.errors;
        break;
    }
  });

export default usersPageReducer;
