Handle creation error
parent
3f08f69c3e
commit
df02bf2fee
|
@ -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)
|
||||
|
|
|
@ -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'})
|
||||
});
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue