import React from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import sortBy from 'lodash/sortBy'; import Admin from './../admin' import { fetchEntities } from '../actions/index' interface ModalSelectProps { fetchEntities: any; fetchOptions: string; header: string; options: any[]; pages: any[]; property: string; func: any; } interface ModalSelectState { fetching: boolean; options: any[]; searchText: string; } class ModalSelect extends React.Component { constructor(props) { super(props); this.state = { fetching: !!this.props.fetchOptions, options: this.props.options || [], searchText: "" }; } componentDidMount() { if (this.props.fetchOptions) { this.props.fetchEntities(this.props.fetchOptions).then(() => { this.setState({ fetching: false, options: this.props[this.props.fetchOptions] }); }); } } render() { return(
{ Admin.renderSpinner(this.state.fetching) } { Admin.renderGrayedOut(this.state.fetching) } { this.renderHeader() }
); } renderHeader() { if (this.props.header) { return(

{ this.props.header }

); } else { return null; } } } const mapStateToProps = (reducers, props) => { return reducers.standardReducer; }; function mapDispatchToProps(dispatch) { return bindActionCreators({ fetchEntities }, dispatch); } export default connect(mapStateToProps, mapDispatchToProps)(ModalSelect);