@@ -30,6 +30,8 @@ import {
30
30
replaceResourceInRole
31
31
} from '../../actions/challenges'
32
32
33
+ import { loadProject } from '../../actions/projects'
34
+
33
35
import { connect } from 'react-redux'
34
36
import { SUBMITTER_ROLE_UUID , MESSAGE } from '../../config/constants'
35
37
import { patchChallenge } from '../../services/challenges'
@@ -59,6 +61,7 @@ class ChallengeEditor extends Component {
59
61
this . closeSuccessModal = this . closeSuccessModal . bind ( this )
60
62
this . onCloseTask = this . onCloseTask . bind ( this )
61
63
this . closeTask = this . closeTask . bind ( this )
64
+ this . fetchProjectDetails = this . fetchProjectDetails . bind ( this )
62
65
}
63
66
64
67
componentDidMount ( ) {
@@ -86,7 +89,6 @@ class ChallengeEditor extends Component {
86
89
loadGroups ( )
87
90
loadResourceRoles ( )
88
91
this . fetchChallengeDetails ( match , loadChallengeDetails , loadResources )
89
-
90
92
// this.unlisten = this.props.history.listen(() => {
91
93
// const { isLoading } = this.props
92
94
// if (!isLoading) {
@@ -112,12 +114,23 @@ class ChallengeEditor extends Component {
112
114
}
113
115
}
114
116
117
+ async fetchProjectDetails ( newMatch ) {
118
+ let projectId = _ . get ( newMatch . params , 'projectId' , null )
119
+ projectId = projectId ? parseInt ( projectId ) : null
120
+ if ( projectId ) {
121
+ await this . props . loadProject ( projectId )
122
+ }
123
+ }
124
+
115
125
async fetchChallengeDetails ( newMatch , loadChallengeDetails , loadResources ) {
116
126
let projectId = _ . get ( newMatch . params , 'projectId' , null )
117
127
projectId = projectId ? parseInt ( projectId ) : null
118
128
const challengeId = _ . get ( newMatch . params , 'challengeId' , null )
119
129
await loadResources ( challengeId )
120
130
loadChallengeDetails ( projectId , challengeId )
131
+ if ( ! challengeId ) {
132
+ this . fetchProjectDetails ( newMatch )
133
+ }
121
134
}
122
135
123
136
isEditable ( ) {
@@ -413,7 +426,8 @@ ChallengeEditor.propTypes = {
413
426
partiallyUpdateChallengeDetails : PropTypes . func . isRequired ,
414
427
createChallenge : PropTypes . func . isRequired ,
415
428
deleteChallenge : PropTypes . func . isRequired ,
416
- replaceResourceInRole : PropTypes . func
429
+ replaceResourceInRole : PropTypes . func ,
430
+ loadProject : PropTypes . func
417
431
// members: PropTypes.arrayOf(PropTypes.shape())
418
432
}
419
433
@@ -450,7 +464,8 @@ const mapDispatchToProps = {
450
464
partiallyUpdateChallengeDetails,
451
465
deleteChallenge,
452
466
createChallenge,
453
- replaceResourceInRole
467
+ replaceResourceInRole,
468
+ loadProject
454
469
}
455
470
456
471
export default withRouter ( connect ( mapStateToProps , mapDispatchToProps ) ( ChallengeEditor ) )
0 commit comments