Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,8 @@ class ChallengeEditor extends Component {

async createNewChallenge () {
if (!this.props.isNew) return
const { metadata, createChallenge, projectDetail } = this.props
const { metadata, createChallenge, projectDetail, location } = this.props
const params = new URLSearchParams(location.search)
const { name, trackId, typeId } = this.state.challenge
const { timelineTemplates } = metadata
const isDesignChallenge = trackId === DES_TRACK_ID
Expand Down Expand Up @@ -839,7 +840,7 @@ class ChallengeEditor extends Component {
terms: [{ id: DEFAULT_TERM_UUID, roleId: SUBMITTER_ROLE_UUID }]
// prizeSets: this.getDefaultPrizeSets()
}
if (projectDetail.terms) {
if (params.get('beta') === 'true' && projectDetail.terms) {
const currTerms = new Set(newChallenge.terms.map(term => term.id))
newChallenge.terms.push(
...projectDetail.terms
Expand Down
21 changes: 18 additions & 3 deletions src/containers/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
replaceResourceInRole
} from '../../actions/challenges'

import { loadProject } from '../../actions/projects'

import { connect } from 'react-redux'
import { SUBMITTER_ROLE_UUID, MESSAGE } from '../../config/constants'
import { patchChallenge } from '../../services/challenges'
Expand Down Expand Up @@ -59,6 +61,7 @@ class ChallengeEditor extends Component {
this.closeSuccessModal = this.closeSuccessModal.bind(this)
this.onCloseTask = this.onCloseTask.bind(this)
this.closeTask = this.closeTask.bind(this)
this.fetchProjectDetails = this.fetchProjectDetails.bind(this)
}

componentDidMount () {
Expand Down Expand Up @@ -86,7 +89,6 @@ class ChallengeEditor extends Component {
loadGroups()
loadResourceRoles()
this.fetchChallengeDetails(match, loadChallengeDetails, loadResources)

// this.unlisten = this.props.history.listen(() => {
// const { isLoading } = this.props
// if (!isLoading) {
Expand All @@ -112,12 +114,23 @@ class ChallengeEditor extends Component {
}
}

async fetchProjectDetails (newMatch) {
let projectId = _.get(newMatch.params, 'projectId', null)
projectId = projectId ? parseInt(projectId) : null
if (projectId) {
await this.props.loadProject(projectId)
}
}

async fetchChallengeDetails (newMatch, loadChallengeDetails, loadResources) {
let projectId = _.get(newMatch.params, 'projectId', null)
projectId = projectId ? parseInt(projectId) : null
const challengeId = _.get(newMatch.params, 'challengeId', null)
await loadResources(challengeId)
loadChallengeDetails(projectId, challengeId)
if (!challengeId) {
this.fetchProjectDetails(newMatch)
}
}

isEditable () {
Expand Down Expand Up @@ -413,7 +426,8 @@ ChallengeEditor.propTypes = {
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
createChallenge: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired,
replaceResourceInRole: PropTypes.func
replaceResourceInRole: PropTypes.func,
loadProject: PropTypes.func
// members: PropTypes.arrayOf(PropTypes.shape())
}

Expand Down Expand Up @@ -450,7 +464,8 @@ const mapDispatchToProps = {
partiallyUpdateChallengeDetails,
deleteChallenge,
createChallenge,
replaceResourceInRole
replaceResourceInRole,
loadProject
}

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(ChallengeEditor))