diff --git a/ui/src/sources/components/SourceForm.js b/ui/src/sources/components/SourceForm.js index c12cc2acb..98b9228cd 100644 --- a/ui/src/sources/components/SourceForm.js +++ b/ui/src/sources/components/SourceForm.js @@ -32,7 +32,7 @@ export const SourceForm = React.createClass({ 'default': this.sourceDefault.checked, telegraf: this.sourceTelegraf.value, insecureSkipVerify: this.sourceInsecureSkipVerify ? this.sourceInsecureSkipVerify.checked : false, - metaUrl: this.metaUrl.value.trim(), + metaUrl: this.metaUrl && this.metaUrl.value.trim(), } this.props.onSubmit(newSource) diff --git a/ui/src/sources/containers/SourcePage.js b/ui/src/sources/containers/SourcePage.js index 8dce7e1b7..17148b1f0 100644 --- a/ui/src/sources/containers/SourcePage.js +++ b/ui/src/sources/containers/SourcePage.js @@ -38,6 +38,7 @@ export const SourcePage = React.createClass({ return { source: {}, editMode: this.props.params.id !== undefined, + error: '', }; }, @@ -70,20 +71,34 @@ export const SourcePage = React.createClass({ return } + // if there is a type on source it has already been created + if (newSource.type) { + return + } + createSource(newSource).then(({data: sourceFromServer}) => { this.props.addSourceAction(sourceFromServer) this.setState({source: sourceFromServer}) + }).catch(({data: error}) => { + // dont want to flash this until they submit + this.setState({error: error.message}) }) }, handleSubmit(newSource) { - const {router, params, addFlashMessage} = this.props; + const {router, params, addFlashMessage} = this.props + const {error} = this.state + + if (error) { + return addFlashMessage({type: 'error', text: error}) + } + updateSource(newSource).then(({data: sourceFromServer}) => { this.props.updateSourceAction(sourceFromServer); router.push(`/sources/${params.sourceID}/manage-sources`); - addFlashMessage({type: 'success', text: 'The source info saved'}); + addFlashMessage({type: 'success', text: 'The source info saved'}) }).catch(() => { - addFlashMessage({type: 'error', text: 'There was a problem updating the source. Check the settings'}); + addFlashMessage({type: 'error', text: 'There was a problem updating the source. Check the settings'}) }); },