// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. const SettingItemMin = require('./setting_item_min.jsx'); const SettingItemMax = require('./setting_item_max.jsx'); const Client = require('../utils/client.jsx'); const Utils = require('../utils/utils.jsx'); export default class GeneralTab extends React.Component { constructor(props) { super(props); this.handleNameSubmit = this.handleNameSubmit.bind(this); this.handleClose = this.handleClose.bind(this); this.onUpdateSection = this.onUpdateSection.bind(this); this.updateName = this.updateName.bind(this); this.state = {name: this.props.teamDisplayName, serverError: '', clientError: ''}; } handleNameSubmit(e) { e.preventDefault(); let state = {serverError: '', clientError: ''}; let valid = true; const name = this.state.name.trim(); if (!name) { state.clientError = 'This field is required'; valid = false; } else if (name === this.props.teamDisplayName) { state.clientError = 'Please choose a new name for your team'; valid = false; } else { state.clientError = ''; } this.setState(state); if (!valid) { return; } let data = {}; data.new_name = name; Client.updateTeamDisplayName(data, function nameChangeSuccess() { this.props.updateSection(''); $('#team_settings').modal('hide'); window.location.reload(); }.bind(this), function nameChangeFail(err) { state.serverError = err.message; this.setState(state); }.bind(this) ); } componentWillReceiveProps(newProps) { if (newProps.team && newProps.teamDisplayName) { this.setState({name: newProps.teamDisplayName}); } } handleClose() { this.setState({clientError: '', serverError: ''}); this.props.updateSection(''); } componentDidMount() { $('#team_settings').on('hidden.bs.modal', this.handleClose); } componentWillUnmount() { $('#team_settings').off('hidden.bs.modal', this.handleClose); } onUpdateSection(e) { e.preventDefault(); if (this.props.activeSection === 'name') { this.props.updateSection(''); } else { this.props.updateSection('name'); } } updateName(e) { e.preventDefault(); this.setState({name: e.target.value}); } render() { let clientError = null; let serverError = null; if (this.state.clientError) { clientError = this.state.clientError; } if (this.state.serverError) { serverError = this.state.serverError; } let nameSection; if (this.props.activeSection === 'name') { let inputs = []; let teamNameLabel = 'Team Name'; if (Utils.isMobile()) { teamNameLabel = ''; } inputs.push(
); nameSection = ( ); } else { let describe = this.state.name; nameSection = ( ); } return (

General Settings

General Settings

{nameSection}
); } } GeneralTab.propTypes = { updateSection: React.PropTypes.func.isRequired, team: React.PropTypes.object.isRequired, activeSection: React.PropTypes.string.isRequired, teamDisplayName: React.PropTypes.string.isRequired };