@@ -30,6 +30,8 @@ import {
3030 replaceResourceInRole
3131} from '../../actions/challenges'
3232
33+ import { loadProject } from '../../actions/projects'
34+
3335import { connect } from 'react-redux'
3436import { SUBMITTER_ROLE_UUID , MESSAGE } from '../../config/constants'
3537import { patchChallenge } from '../../services/challenges'
@@ -59,6 +61,7 @@ class ChallengeEditor extends Component {
5961 this . closeSuccessModal = this . closeSuccessModal . bind ( this )
6062 this . onCloseTask = this . onCloseTask . bind ( this )
6163 this . closeTask = this . closeTask . bind ( this )
64+ this . fetchProjectDetails = this . fetchProjectDetails . bind ( this )
6265 }
6366
6467 componentDidMount ( ) {
@@ -86,7 +89,6 @@ class ChallengeEditor extends Component {
8689 loadGroups ( )
8790 loadResourceRoles ( )
8891 this . fetchChallengeDetails ( match , loadChallengeDetails , loadResources )
89-
9092 // this.unlisten = this.props.history.listen(() => {
9193 // const { isLoading } = this.props
9294 // if (!isLoading) {
@@ -112,12 +114,23 @@ class ChallengeEditor extends Component {
112114 }
113115 }
114116
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+
115125 async fetchChallengeDetails ( newMatch , loadChallengeDetails , loadResources ) {
116126 let projectId = _ . get ( newMatch . params , 'projectId' , null )
117127 projectId = projectId ? parseInt ( projectId ) : null
118128 const challengeId = _ . get ( newMatch . params , 'challengeId' , null )
119129 await loadResources ( challengeId )
120130 loadChallengeDetails ( projectId , challengeId )
131+ if ( ! challengeId ) {
132+ this . fetchProjectDetails ( newMatch )
133+ }
121134 }
122135
123136 isEditable ( ) {
@@ -413,7 +426,8 @@ ChallengeEditor.propTypes = {
413426 partiallyUpdateChallengeDetails : PropTypes . func . isRequired ,
414427 createChallenge : PropTypes . func . isRequired ,
415428 deleteChallenge : PropTypes . func . isRequired ,
416- replaceResourceInRole : PropTypes . func
429+ replaceResourceInRole : PropTypes . func ,
430+ loadProject : PropTypes . func
417431 // members: PropTypes.arrayOf(PropTypes.shape())
418432}
419433
@@ -450,7 +464,8 @@ const mapDispatchToProps = {
450464 partiallyUpdateChallengeDetails,
451465 deleteChallenge,
452466 createChallenge,
453- replaceResourceInRole
467+ replaceResourceInRole,
468+ loadProject
454469}
455470
456471export default withRouter ( connect ( mapStateToProps , mapDispatchToProps ) ( ChallengeEditor ) )
0 commit comments