mattermost-desktop/src/browser/components/NewTeamModal.jsx

121 lines
3 KiB
React
Raw Normal View History

2016-12-25 07:44:44 -08:00
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: ''
};
}
shouldComponentUpdate() {
return true;
}
getTeamNameValidationState() {
return this.state.teamName.length > 0 ? '' : 'error';
}
handleTeamNameChange(e) {
this.setState({
teamName: e.target.value
});
}
getTeamUrlValidationState() {
if (this.state.teamUrl.length === 0) {
return 'error';
}
if (!validUrl.isUri(this.state.teamUrl)) {
return 'error';
}
return '';
}
handleTeamUrlChange(e) {
this.setState({
teamUrl: e.target.value
});
}
validateForm() {
return this.getTeamNameValidationState() === '' &&
this.getTeamUrlValidationState() === '';
}
render() {
return (
2017-01-16 14:51:36 -08:00
<Modal.Dialog
id='newServerModal'
>
2016-12-25 07:44:44 -08:00
<Modal.Header>
<Modal.Title>{'Add Server'}</Modal.Title>
2016-12-25 07:44:44 -08:00
</Modal.Header>
<Modal.Body>
<form>
<FormGroup
validationState={this.getTeamNameValidationState()}
>
<ControlLabel>{'Server Display Name'}</ControlLabel>
2016-12-25 07:44:44 -08:00
<FormControl
2017-01-16 14:51:36 -08:00
id='teamNameInput'
2016-12-25 07:44:44 -08:00
type='text'
value={this.state.teamName}
placeholder='Server Name'
2016-12-25 07:44:44 -08:00
onChange={this.handleTeamNameChange.bind(this)}
/>
<FormControl.Feedback/>
<HelpBlock>{'The name of the server displayed on your desktop app tab bar.'}</HelpBlock>
2016-12-25 07:44:44 -08:00
</FormGroup>
<FormGroup
validationState={this.getTeamUrlValidationState()}
>
<ControlLabel>{'Team URL'}</ControlLabel>
<FormControl
2017-01-16 14:51:36 -08:00
id='teamUrlInput'
2016-12-25 07:44:44 -08:00
type='text'
value={this.state.teamUrl}
placeholder='https://example.com'
2016-12-25 07:44:44 -08:00
onChange={this.handleTeamUrlChange.bind(this)}
/>
<FormControl.Feedback/>
<HelpBlock>{'The URL of your Mattermost server. Must start with http:// or https://.'}</HelpBlock>
2016-12-25 07:44:44 -08:00
</FormGroup>
</form>
</Modal.Body>
<Modal.Footer>
<Button
2017-01-16 14:51:36 -08:00
id='cancelNewServerModal'
2016-12-25 07:44:44 -08:00
onClick={this.props.onClose}
>{'Cancel'}</Button>
<Button
2017-01-16 14:51:36 -08:00
id='saveNewServerModal'
2016-12-25 07:44:44 -08:00
onClick={() => {
this.props.onSave({
url: this.state.teamUrl,
name: this.state.teamName
});
}}
disabled={!this.validateForm()}
bsStyle='primary'
>{'Add'}</Button>
</Modal.Footer>
</Modal.Dialog>
);
}
}
NewTeamModal.propTypes = {
onClose: React.PropTypes.func,
onSave: React.PropTypes.func
};
module.exports = NewTeamModal;