// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. const AsyncClient = require('../utils/async_client.jsx'); const Client = require('../utils/client.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: ''}; } 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}; } let channelTerm = 'Channel'; if (this.props.channel.channelType === 'P') { channelTerm = 'Group'; } return ( {title}

{`Describe how this ${channelTerm} should be used.`}