import PropTypes from 'prop-types'; import { injectIntl } from 'react-intl'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { connect } from 'react-redux'; import spring from 'react-motion/lib/spring'; import { setupAntennaEditor, setupExcludeAntennaEditor, clearAntennaSuggestions, resetAntennaEditor } from '../../actions/antennas'; import Motion from '../ui/util/optional_motion'; import Account from './components/account'; import EditAntennaForm from './components/edit_antenna_form'; import Search from './components/search'; const mapStateToProps = (state) => ({ accountIds: state.getIn(['antennaEditor', 'accounts', 'items']), searchAccountIds: state.getIn(['antennaEditor', 'suggestions', 'items']), }); const mapDispatchToProps = (dispatch, { isExclude }) => ({ onInitialize: antennaId => dispatch(isExclude ? setupExcludeAntennaEditor(antennaId) : setupAntennaEditor(antennaId)), onClear: () => dispatch(clearAntennaSuggestions()), onReset: () => dispatch(resetAntennaEditor()), }); class AntennaEditor extends ImmutablePureComponent { static propTypes = { antennaId: PropTypes.string.isRequired, isExclude: PropTypes.bool.isRequired, onClose: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, onInitialize: PropTypes.func.isRequired, onClear: PropTypes.func.isRequired, onReset: PropTypes.func.isRequired, accountIds: ImmutablePropTypes.list.isRequired, searchAccountIds: ImmutablePropTypes.list.isRequired, }; componentDidMount () { const { onInitialize, antennaId } = this.props; onInitialize(antennaId); } componentWillUnmount () { const { onReset } = this.props; onReset(); } render () { const { accountIds, searchAccountIds, onClear, isExclude } = this.props; const showSearch = searchAccountIds.size > 0; return (