_ = require 'underscore' React = require 'react' classnames = require 'classnames' {AccountStore} = require 'nylas-exports' {Menu, ButtonDropdown} = require 'nylas-component-kit' class AccountContactField extends React.Component @displayName: 'AccountContactField' @propTypes: value: React.PropTypes.object accounts: React.PropTypes.array.isRequired onChange: React.PropTypes.func.isRequired _onChooseContact: (contact) => accountId = contact.accountId from = [contact] @props.onChange({accountId, from}) @refs.dropdown.toggleDropdown() _renderAccountSelector: -> return unless @props.value label = @props.value.toString() multipleAccounts = @props.accounts.length > 1 hasAliases = @props.accounts[0]?.aliases.length > 0 if multipleAccounts or hasAliases {label}} menu={@_renderAccounts(@props.accounts)} /> else @_renderAccountSpan(label) _renderMenuItem: (contact) => className = classnames( 'contact': true 'is-alias': contact.isAlias ) {contact.toString()} _renderAccounts: (accounts) => items = AccountStore.aliasesFor(accounts) contact.id} itemContent={@_renderMenuItem} onSelect={@_onChooseContact} /> _renderAccountSpan: (label) -> {label} render: => From: {@_renderAccountSelector()} module.exports = AccountContactField