import React from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import Modal from 'react-modal' import _ from 'lodash' import Admin from './../admin' import NewEntity from './new-entity' import { fetchEntities } from '../actions/index' const ModalStyles = { overlay: { background: 'rgba(0, 0, 0, 0.50)' }, content: { background: '#F5F6F7', margin: 'auto', maxWidth: 1000, height: 558, padding: 0, border: 'none' } }; interface UsersIndexProps { fetchEntities: any; users: any[]; } interface UsersIndexState extends ComponentState { modalOpen: boolean; users: any[]; } class UsersIndex extends React.Component { constructor(props) { super(props); this.state = { fetching: true, users: [], modalOpen: false, searchText: "", searchProperty: "name" }; } componentDidMount() { this.props.fetchEntities("users").then(() => { this.setState({ fetching: false, users: this.props.users }); }); } clickNew() { this.setState({ modalOpen: true }); } closeModal() { this.setState({ modalOpen: false }); } redirect(id) { window.location.pathname = `admin/users/${id}`; } reloadUsers() { this.setState({ modalOpen: false, fetching: true }); this.props.fetchEntities("users").then(() => { this.setState({ fetching: false, users: this.props.users }); }); } render() { var filteredUsers = Admin.filterSearchText(this.state.users, this.state.searchText, this.state.searchProperty); return(

Users

{ this.renderAddButton() }
{ Admin.renderSpinner(this.state.fetching) } { Admin.renderGrayedOut(this.state.fetching) } { _.sortBy(filteredUsers, [Admin.commonSort.bind(this)]).map((user, index) => { return( ); }) }
Name
Title
Team
Permissions
{ user.name } { user.title } { user.team } { user.permission }
); } renderAddButton() { if (Admin.currentUser.access >= Admin.permissions["Administrator"]) { return( Add User ); } else { return null; } } componentDidUpdate() { $('.match-height-layout').matchHeight(); } } const mapStateToProps = (reducers, props) => { return { users: reducers.standardReducer.users }; }; function mapDispatchToProps(dispatch) { return bindActionCreators({ fetchEntities }, dispatch); } export default connect(mapStateToProps, mapDispatchToProps)(UsersIndex);