import React, { Component } from 'react'; import { string, bool, func } from 'prop-types'; import { compose } from 'redux'; import { FormattedMessage, injectIntl, intlShape } from 'react-intl'; import { reduxForm, propTypes as formPropTypes } from 'redux-form'; import classNames from 'classnames'; import { Form, TextInputField, SecondaryButton, IconSpinner } from '../../components'; import * as propTypes from '../../util/propTypes'; import css from './SendMessageForm.css'; const BLUR_TIMEOUT_MS = 100; const IconSendMessageMobile = () => { return ( ); }; const IconSendMessageDesktop = () => { return ( ); }; class SendMessageFormComponent extends Component { constructor(props) { super(props); this.handleFocus = this.handleFocus.bind(this); this.handleBlur = this.handleBlur.bind(this); this.blurTimeoutId = null; } handleFocus() { this.props.onFocus(); window.clearTimeout(this.blurTimeoutId); } handleBlur() { // We only trigger a blur if another focus event doesn't come // within a timeout. This enables keeping the focus synced when // focus is switched between the message area and the submit // button. this.blurTimeoutId = window.setTimeout(() => { this.props.onBlur(); }, BLUR_TIMEOUT_MS); } render() { const { rootClassName, className, messagePlaceholder, form, handleSubmit, submitting, inProgress, sendMessageError, invalid, } = this.props; const classes = classNames(rootClassName || css.root, className); const submitInProgress = submitting || inProgress; const submitDisabled = invalid || submitInProgress; return (
{sendMessageError ? (

) : null}
{sendMessageError ? (

) : null}
); } } SendMessageFormComponent.defaultProps = { rootClassName: null, className: null, inProgress: false, messagePlaceholder: null, onFocus: () => null, onBlur: () => null, sendMessageError: null, }; SendMessageFormComponent.propTypes = { ...formPropTypes, rootClassName: string, className: string, inProgress: bool, messagePlaceholder: string, onFocus: func, onBlur: func, sendMessageError: propTypes.error, // from injectIntl intl: intlShape.isRequired, }; const defaultFormName = 'SendMessageForm'; const SendMessageForm = compose(reduxForm({ form: defaultFormName }), injectIntl)( SendMessageFormComponent ); SendMessageForm.displayName = 'SendMessageForm'; export default SendMessageForm;