2020-12-03 04:22:51 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { connect } from 'react-redux'
|
2020-12-16 22:29:06 +00:00
|
|
|
import {
|
|
|
|
fetchChatConversationAccountSuggestions,
|
|
|
|
clearChatConversationAccountSuggestions,
|
|
|
|
} from '../actions/chats'
|
2020-12-03 04:22:51 +00:00
|
|
|
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 {
|
|
|
|
|
2020-12-22 06:36:38 +00:00
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object
|
|
|
|
}
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
state = {
|
|
|
|
query: '',
|
|
|
|
}
|
|
|
|
|
|
|
|
onChange = (query) => {
|
|
|
|
this.setState({ query })
|
|
|
|
this.props.onChange(query)
|
|
|
|
}
|
|
|
|
|
|
|
|
handleOnCreateChatConversation = (accountId) => {
|
2020-12-22 06:36:38 +00:00
|
|
|
this.props.onCreateChatConversation(accountId, this.context.router.history)
|
2020-12-16 22:29:06 +00:00
|
|
|
this.props.onClearChatConversationAccountSuggestions()
|
|
|
|
|
|
|
|
if (this.props.isModal && !!this.props.onCloseModal) {
|
|
|
|
this.props.onCloseModal()
|
|
|
|
}
|
2020-12-03 04:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { query, suggestionsIds } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form>
|
2020-12-20 17:27:24 +00:00
|
|
|
<div className={[_s.d, _s.bgPrimary, _s.w100PC, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.px15, _s.pt10].join(' ')}>
|
|
|
|
<Input
|
|
|
|
title='Search for a user'
|
|
|
|
value={query}
|
|
|
|
onChange={this.onChange}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-12-03 04:22:51 +00:00
|
|
|
|
2020-12-20 17:27:24 +00:00
|
|
|
<div className={[_s.d, _s.pt10].join(' ')}>
|
|
|
|
<div className={[_s.d].join(' ')}>
|
|
|
|
<Text weight='bold' size='small' color='secondary' className={[_s.d, _s.px15, _s.ml15, _s.mt5, _s.mb15].join(' ')}>
|
|
|
|
Search results ({suggestionsIds.size})
|
|
|
|
</Text>
|
|
|
|
{
|
|
|
|
suggestionsIds &&
|
|
|
|
suggestionsIds.map((accountId) => (
|
|
|
|
<Account
|
|
|
|
compact
|
2020-12-21 23:30:46 +00:00
|
|
|
noClick
|
2020-12-20 17:27:24 +00:00
|
|
|
key={`chat-conversation-account-create-${accountId}`}
|
|
|
|
id={accountId}
|
|
|
|
onActionClick={() => this.handleOnCreateChatConversation(accountId)}
|
|
|
|
actionIcon='add'
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
2020-12-03 04:22:51 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
suggestionsIds: state.getIn(['chats', 'createChatConversationSuggestionIds']),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2020-12-16 22:29:06 +00:00
|
|
|
onChange(value) {
|
2020-12-03 04:22:51 +00:00
|
|
|
dispatch(fetchChatConversationAccountSuggestions(value))
|
|
|
|
},
|
2020-12-22 06:36:38 +00:00
|
|
|
onCreateChatConversation(accountId, routerHistory) {
|
|
|
|
dispatch(createChatConversation(accountId, routerHistory))
|
2020-12-03 04:22:51 +00:00
|
|
|
},
|
2020-12-16 22:29:06 +00:00
|
|
|
onClearChatConversationAccountSuggestions() {
|
|
|
|
dispatch(clearChatConversationAccountSuggestions())
|
|
|
|
}
|
2020-12-03 04:22:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
ChatConversationCreate.propTypes = {
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
onCreateChatConversation: PropTypes.func.isRequired,
|
|
|
|
isModal: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ChatConversationCreate)
|