{"size": 1133, "ext": "js", "max_stars_repo_path": "client/src/state-management/containers/ConfirmedUserContainer.js", "max_stars_repo_name": "kajogo777/IllustrationAidsPlatform", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/state-management/containers/ConfirmedUserContainer.js", "max_issues_repo_name": "kajogo777/IllustrationAidsPlatform", "max_issues_repo_issues_event_min_datetime": "2018-02-03T15:11:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T19:02:08.000Z", "max_forks_repo_path": "client/src/state-management/containers/ConfirmedUserContainer.js", "max_forks_repo_name": "kajogo777/IllustrationAidsPlatform", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 24, "max_forks_count": null, "avg_line_length": 27.6341463415, "max_line_length": 113, "alphanum_fraction": 0.680494263}
import { connect }from 'react-redux';
import UniversalContainer from './UniversalContainer';
import { fetchConfirmedUsers, deleteUser, filterUsers, clearFilter, updateUser } from '../actions/users-actions';

function filterRows(list, filters){
  const filterKeys = Object.keys(filters);
  return list.filter((row) => {
    return filterKeys.reduce((acc, key) => acc && row[key].toLowerCase().indexOf(filters[key]) !== -1, true);
  });
}

function mapStateToProps (state){
  return {
    confirmed_users: filterRows(state.userStore.confirmed_users, state.userStore.filters)
  };
}

function mapDispatchToProps (dispatch){
  return {
    onLoad: () => {
      dispatch(fetchConfirmedUsers())
    },
    deleteUser: (user) => {
      dispatch(deleteUser(user))
    },
    updateUser: (id, user) => {
      dispatch(updateUser(id, user))
    },
    filterUsers: (field, value) => {
      dispatch(filterUsers(field, value))
    },
    clearFilter: () => {
      dispatch(clearFilter())
    }
  };
}

const ConfirmedUserContainer = connect(mapStateToProps, mapDispatchToProps)(UniversalContainer);

export default ConfirmedUserContainer;
