import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import { fetchChatConversationAccountSuggestions, clearChatConversationAccountSuggestions, } from '../actions/chats' import { createChatConversation } from '../actions/chat_conversations' import Account from '../components/account' import Button from '../components/button' import Input from '../components/input' import Form from '../components/form' import Text from '../components/text' class ChatConversationCreate extends React.PureComponent { state = { query: '', } onChange = (query) => { this.setState({ query }) this.props.onChange(query) } handleOnCreateChatConversation = (accountId) => { this.props.onCreateChatConversation(accountId) this.props.onClearChatConversationAccountSuggestions() if (this.props.isModal && !!this.props.onCloseModal) { this.props.onCloseModal() } } render() { const { query, suggestionsIds } = this.props return (
Search results ({suggestionsIds.size}) { suggestionsIds && suggestionsIds.map((accountId) => ( this.handleOnCreateChatConversation(accountId)} actionIcon='add' /> )) }
) } } const mapStateToProps = (state) => ({ suggestionsIds: state.getIn(['chats', 'createChatConversationSuggestionIds']), }) const mapDispatchToProps = (dispatch) => ({ onChange(value) { dispatch(fetchChatConversationAccountSuggestions(value)) }, onCreateChatConversation(accountId) { dispatch(createChatConversation(accountId)) }, onClearChatConversationAccountSuggestions() { dispatch(clearChatConversationAccountSuggestions()) } }) ChatConversationCreate.propTypes = { onChange: PropTypes.func.isRequired, onCreateChatConversation: PropTypes.func.isRequired, isModal: PropTypes.bool, } export default connect(mapStateToProps, mapDispatchToProps)(ChatConversationCreate)