// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import ReactDOM from 'react-dom'; import * as AsyncClient from 'utils/async_client.jsx'; import Client from 'utils/web_client.jsx'; import Constants from 'utils/constants.jsx'; import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl'; import {Modal} from 'react-bootstrap'; const holders = defineMessages({ error: { id: 'edit_channel_purpose_modal.error', defaultMessage: 'This channel purpose is too long, please enter a shorter one' } }); import React from 'react'; export default class EditChannelPurposeModal extends React.Component { constructor(props) { super(props); this.handleHide = this.handleHide.bind(this); this.handleSave = this.handleSave.bind(this); this.state = {serverError: ''}; } componentDidUpdate() { if (this.props.show) { $(ReactDOM.findDOMNode(this.refs.purpose)).focus(); } } handleHide() { this.setState({serverError: ''}); if (this.props.onModalDismissed) { this.props.onModalDismissed(); } } handleSave() { if (!this.props.channel) { return; } Client.updateChannelPurpose( this.props.channel.id, ReactDOM.findDOMNode(this.refs.purpose).value.trim(), () => { AsyncClient.getChannel(this.props.channel.id); this.handleHide(); }, (err) => { if (err.id === 'api.context.invalid_param.app_error') { this.setState({serverError: this.props.intl.formatMessage(holders.error)}); } else { this.setState({serverError: err.message}); } } ); } render() { if (!this.props.show) { return null; } let serverError = null; if (this.state.serverError) { serverError = (