const React = require('react'); const {Modal, Button, FormGroup, FormControl, ControlLabel, HelpBlock} = require('react-bootstrap'); const validUrl = require('valid-url'); class NewTeamModal extends React.Component { constructor() { super(); this.state = { teamName: '', teamUrl: '', saveStarted: false }; } getTeamNameValidationError() { if (!this.state.saveStarted) { return null; } return this.state.teamName.length > 0 ? null : 'Name is required.'; } getTeamNameValidationState() { return this.getTeamNameValidationError() === null ? null : 'error'; } handleTeamNameChange(e) { this.setState({ teamName: e.target.value }); } getTeamUrlValidationError() { if (!this.state.saveStarted) { return null; } if (this.state.teamUrl.length === 0) { return 'URL is required.'; } if (!validUrl.isUri(this.state.teamUrl)) { return 'URL should start with http:// or https://.'; } return null; } getTeamUrlValidationState() { return this.getTeamUrlValidationError() === null ? null : 'error'; } handleTeamUrlChange(e) { this.setState({ teamUrl: e.target.value }); } getError() { return this.getTeamNameValidationError() || this.getTeamUrlValidationError(); } validateForm() { return this.getTeamNameValidationState() === null && this.getTeamUrlValidationState() === null; } save() { this.setState({ saveStarted: true }, () => { if (this.validateForm()) { this.props.onSave({ url: this.state.teamUrl, name: this.state.teamName }); } }); } render() { return ( { switch (e.key) { case 'Enter': this.save(); // The add button from behind this might still be focused e.preventDefault(); e.stopPropagation(); break; case 'Escape': this.props.onClose(); break; } }} > {'Add Server'}
{'Server Display Name'} {'The name of the server displayed on your desktop app tab bar.'} {'Team URL'} {'The URL of your Mattermost server. Must start with http:// or https://.'}
{this.getError()}
); } } NewTeamModal.propTypes = { onClose: React.PropTypes.func, onSave: React.PropTypes.func }; module.exports = NewTeamModal;