/** * * InputSearch * */ import React from 'react'; import { FormattedMessage } from 'react-intl'; import { includes, isEmpty, map, toLower } from 'lodash'; import cn from 'classnames'; import PropTypes from 'prop-types'; import InputSearchLi from 'components/InputSearchLi'; import styles from './styles.scss'; class InputSearch extends React.Component { // eslint-disable-line react/prefer-stateless-function state = { errors: [], value: '', users: this.props.values, filteredUsers: this.props.values }; componentWillReceiveProps(nextProps) { if (nextProps.didDeleteUser !== this.props.didDeleteUser) { this.setState({ users: nextProps.values, filteredUsers: nextProps.values }); } if (nextProps.didGetUsers !== this.props.didGetUsers) { this.setState({ users: nextProps.values, filteredUsers: nextProps.values }); } } handleChange = ({ target }) => { const filteredUsers = isEmpty(target.value) ? this.state.users : this.state.users.filter((user) => { if (includes(toLower(user.name), toLower(target.value))) { return user; } }); this.setState({ value: target.value, filteredUsers }); } render() { return (
{(message) => ( )}
); } } InputSearch.defaultProps = { labelValues: { number: 0, }, values: [], }; InputSearch.propTypes = { didDeleteUser: PropTypes.bool.isRequired, didGetUsers: PropTypes.bool.isRequired, label: PropTypes.string.isRequired, labelValues: PropTypes.object, name: PropTypes.string.isRequired, onClickDelete: PropTypes.func.isRequired, values: PropTypes.array, }; export default InputSearch;