// 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 * as Utils from '../utils/utils.jsx'; const Modal = ReactBootstrap.Modal; 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.message === 'Invalid channel_purpose parameter') { this.setState({serverError: 'This channel purpose is too long, please enter a shorter one'}); } else { this.setState({serverError: err.message}); } } ); } render() { if (!this.props.show) { return null; } let serverError = null; if (this.state.serverError) { serverError = (

); } let title = {'Edit Purpose'}; if (this.props.channel.display_name) { title = {'Edit Purpose for '}{this.props.channel.display_name}; } return ( {title}

{`Describe how this ${Utils.getChannelTerm(this.props.channel.channelType)} should be used. This text appears in the channel list in the "More..." menu and helps others decide whether to join.`}