// // A modal popup to add a new provider. // import React from 'react' import { FormGroup, ControlLabel, FormControl, HelpBlock, Button, ButtonToolbar, Modal } from 'react-bootstrap' import Spinner from 'components/spinner' import Validate from 'lib/validate' import Provider from 'models/provider' export default class AddProviderModal extends React.Component { static get defaultProps() {return{ title: 'Add a provider', onClose: null }} constructor(props) { super(props) this.state = { validationState: null, // one of 'success', 'error', 'warning' errorMsg: null, domain: "", working: false, // true if waiting for something } this.accept = this.accept.bind(this) this.cancel = this.cancel.bind(this) this.changed = this.changed.bind(this) } accept(e=null) { if (e) { e.preventDefault() // don't reload the page please! } if (this.state.domain) { this.setState({working: true}) Provider.setup(this.state.domain).then( provider => { this.props.onClose(provider) // this.setState({working: false}) }, error => { this.setState({ validationState: 'warning', errorMsg: error, working: false }) } ) } } cancel() { this.props.onClose() } changed(e) { let domain = e.target.value let newState = null let newMsg = null if (domain.length > 0) { let msg = Validate.domain(domain) newState = msg ? 'error' : 'success' newMsg = msg } this.setState({ domain: domain, validationState: newState, errorMsg: newMsg }) } render() { let help = null let addButton = null if (this.state.errorMsg) { help = {this.state.errorMsg} } else { help =   } if (this.state.working) { addButton = } else if (this.state.validationState == 'warning') { addButton = } else if (this.state.validationState == 'error') { addButton = } else { addButton = } let form =
Domain {help} {addButton}
return( {this.props.title} {form} ) } }