use updateSourceAction correctly
parent
5acf147bfe
commit
718e5fdca2
|
@ -4,7 +4,10 @@ import {connect} from 'react-redux'
|
||||||
|
|
||||||
import {createSource, updateSource} from 'shared/apis'
|
import {createSource, updateSource} from 'shared/apis'
|
||||||
import SourceForm from 'src/sources/components/SourceForm'
|
import SourceForm from 'src/sources/components/SourceForm'
|
||||||
import {addSource as addSourceAction} from 'src/shared/actions/sources'
|
import {
|
||||||
|
addSource as addSourceAction,
|
||||||
|
updateSource as updateSourceAction,
|
||||||
|
} from 'src/shared/actions/sources'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
func,
|
func,
|
||||||
|
@ -32,24 +35,6 @@ export const CreateSource = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleNewSource(e) {
|
|
||||||
e.preventDefault()
|
|
||||||
const source = {
|
|
||||||
url: this.sourceURL.value.trim(),
|
|
||||||
name: this.sourceName.value,
|
|
||||||
username: this.sourceUser.value,
|
|
||||||
password: this.sourcePassword.value,
|
|
||||||
isDefault: true,
|
|
||||||
telegraf: this.sourceTelegraf.value,
|
|
||||||
insecureSkipVerify: this.sourceInsecureSkipVerify ? this.sourceInsecureSkipVerify.checked : false,
|
|
||||||
metaUrl: this.metaUrl && this.metaUrl.value.trim(),
|
|
||||||
}
|
|
||||||
createSource(source).then(({data: sourceFromServer}) => {
|
|
||||||
this.props.addSourceAction(sourceFromServer)
|
|
||||||
this.redirectToApp(sourceFromServer)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
redirectToApp(source) {
|
redirectToApp(source) {
|
||||||
const {redirectPath} = this.props.location.query
|
const {redirectPath} = this.props.location.query
|
||||||
if (!redirectPath) {
|
if (!redirectPath) {
|
||||||
|
@ -104,7 +89,7 @@ export const CreateSource = React.createClass({
|
||||||
|
|
||||||
updateSource(newSource).then(({data: sourceFromServer}) => {
|
updateSource(newSource).then(({data: sourceFromServer}) => {
|
||||||
this.props.updateSourceAction(sourceFromServer)
|
this.props.updateSourceAction(sourceFromServer)
|
||||||
this.redirectToApp(newSource)
|
this.redirectToApp(sourceFromServer)
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// give a useful error message to the user
|
// give a useful error message to the user
|
||||||
})
|
})
|
||||||
|
@ -142,4 +127,4 @@ function mapStateToProps(_) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps, {addSourceAction})(withRouter(CreateSource))
|
export default connect(mapStateToProps, {addSourceAction, updateSourceAction})(withRouter(CreateSource))
|
||||||
|
|
Loading…
Reference in New Issue