// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import * as AsyncClient from '../utils/async_client.jsx'; import * as Client from '../utils/client.jsx'; import Constants from '../utils/constants.jsx'; import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'mm-intl'; const Modal = ReactBootstrap.Modal; const holders = defineMessages({ error: { id: 'edit_channel_purpose_modal.error', defaultMessage: 'This channel purpose is too long, please enter a shorter one' } }); 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; } const data = { channel_id: this.props.channel.id, channel_purpose: ReactDOM.findDOMNode(this.refs.purpose).value.trim() }; Client.updateChannelPurpose(data, () => { 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 = (