import React, { Component } from 'react'; import { string, bool, func } from 'prop-types'; import { compose } from 'redux'; import { FormattedMessage, injectIntl, intlShape } from 'react-intl'; import { Form as FinalForm } from 'react-final-form'; import classNames from 'classnames'; import { Form, FieldTextInput, SecondaryButton } from '../../components'; import { propTypes } from '../../util/types'; import css from './SendMessageForm.css'; const BLUR_TIMEOUT_MS = 100; const IconSendMessage = () => { 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() { return ( { const { rootClassName, className, messagePlaceholder, handleSubmit, inProgress, sendMessageError, invalid, form, formId, } = formRenderProps; const classes = classNames(rootClassName || css.root, className); const submitInProgress = inProgress; const submitDisabled = invalid || submitInProgress; return (
handleSubmit(values, form)}>
{sendMessageError ? (

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