Skip to content

Fixed issue #1007 #1031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 12, 2021
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
6 changes: 4 additions & 2 deletions src/components/ChallengeEditor/ReviewType-Field/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash'
import React from 'react'
import PropTypes from 'prop-types'
import Select from '../../Select'
Expand All @@ -9,10 +10,11 @@ import { DES_TRACK_ID, REVIEW_TYPES, MESSAGE, QA_TRACK_ID } from '../../../confi
const ReviewTypeField = ({ reviewers, challenge, onUpdateOthers, onUpdateSelect }) => {
const isDesignChallenge = challenge.trackId === DES_TRACK_ID
const isQAChallenge = challenge.trackId === QA_TRACK_ID
const isTask = _.get(challenge, 'task.isTask', false)
const defaultReviewType = isDesignChallenge ? REVIEW_TYPES.INTERNAL : REVIEW_TYPES.COMMUNITY
const reviewType = challenge.reviewType ? challenge.reviewType.toUpperCase() : defaultReviewType
const isCommunity = reviewType === REVIEW_TYPES.COMMUNITY
const isInternal = reviewType === REVIEW_TYPES.INTERNAL
const isInternal = reviewType === REVIEW_TYPES.INTERNAL || isTask
const communityOption = (disabled) => (<div className={styles.tcRadioButton}>
<input
name='community'
Expand Down Expand Up @@ -59,7 +61,7 @@ const ReviewTypeField = ({ reviewers, challenge, onUpdateOthers, onUpdateSelect
{ communityOption(true) }
</Tooltip>
}
{ !isDesignChallenge &&
{ !isDesignChallenge && !isTask &&
communityOption()
}
</div>
Expand Down
19 changes: 14 additions & 5 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ class ChallengeEditor extends Component {
}

collectChallengeData (status) {
const { attachments } = this.props
const { attachments, metadata } = this.props
const challenge = pick([
'phases',
'typeId',
Expand All @@ -793,6 +793,7 @@ class ChallengeEditor extends Component {
'prizeSets',
'winners'
], this.state.challenge)
const isTask = _.find(metadata.challengeTypes, { id: challenge.typeId, isTask: true })
challenge.legacy = _.assign(this.state.challenge.legacy, {
reviewType: challenge.reviewType
})
Expand All @@ -803,6 +804,10 @@ class ChallengeEditor extends Component {
return { ...p, prizes }
})
challenge.status = status
if (status === 'Active' && isTask) {
challenge.startDate = moment().format()
}

if (this.state.challenge.id) {
challenge.attachmentIds = _.map(attachments, item => item.id)
}
Expand Down Expand Up @@ -837,7 +842,7 @@ class ChallengeEditor extends Component {
const avlTemplates = this.getAvailableTimelineTemplates()
// chooses first available timeline template or fallback template for the new challenge
const defaultTemplate = avlTemplates && avlTemplates.length > 0 ? avlTemplates[0] : STD_DEV_TIMELINE_TEMPLATE

const isTask = _.find(metadata.challengeTypes, { id: typeId, isTask: true })
const newChallenge = {
status: 'New',
projectId: this.props.projectId,
Expand All @@ -846,7 +851,7 @@ class ChallengeEditor extends Component {
trackId,
startDate: moment().add(1, 'days').format(),
legacy: {
reviewType: isDesignChallenge ? REVIEW_TYPES.INTERNAL : REVIEW_TYPES.COMMUNITY
reviewType: isTask || isDesignChallenge ? REVIEW_TYPES.INTERNAL : REVIEW_TYPES.COMMUNITY
},
descriptionFormat: 'markdown',
timelineTemplateId: defaultTemplate.id,
Expand All @@ -859,6 +864,10 @@ class ChallengeEditor extends Component {
}
try {
const action = await createChallenge(newChallenge)
if (isTask) {
await this.updateResource(action.challengeDetails.id, 'Reviewer', action.challengeDetails.createdBy, action.challengeDetails.reviewer)
action.challengeDetails.reviewer = action.challengeDetails.createdBy
}
const draftChallenge = {
data: action.challengeDetails
}
Expand Down Expand Up @@ -1399,7 +1408,7 @@ class ChallengeEditor extends Component {
<GroupsField groups={metadata.groups} onUpdateMultiSelect={this.onUpdateMultiSelect} challenge={challenge} />
</React.Fragment>
)}
{
{!isTask && (
<div className={styles.PhaseRow}>
<PhaseInput
withDates
Expand All @@ -1414,7 +1423,7 @@ class ChallengeEditor extends Component {
readOnly={false}
/>
</div>
}
)}
{
this.state.isDeleteLaunch && !this.state.isConfirm && (
<ConfirmationModal
Expand Down
11 changes: 8 additions & 3 deletions src/components/ChallengesComponent/ChallengeCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,15 @@ class ChallengeCard extends React.Component {
const { challenge } = this.props
try {
this.setState({ isSaving: true })
// call action to update the challenge with a new status
await partiallyUpdateChallengeDetails(challenge.id, {
const isTask = _.get(challenge, 'task.isTask', false)
const payload = {
status: 'Active'
})
}
if (isTask) {
payload.startDate = moment().format()
}
// call action to update the challenge with a new status
await partiallyUpdateChallengeDetails(challenge.id, payload)
this.setState({ isLaunch: true, isConfirm: challenge.id, isSaving: false })
} catch (e) {
const error = _.get(e, 'response.data.message', 'Unable to activate the challenge')
Expand Down
14 changes: 10 additions & 4 deletions src/containers/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'lodash'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withRouter, Route } from 'react-router-dom'
import moment from 'moment'
import ChallengeEditorComponent from '../../components/ChallengeEditor'
import ChallengeViewComponent from '../../components/ChallengeEditor/ChallengeView'
import Loader from '../../components/Loader'
Expand Down Expand Up @@ -156,13 +157,18 @@ class ChallengeEditor extends Component {
async activateChallenge () {
const { partiallyUpdateChallengeDetails } = this.props
if (this.state.isLaunching) return
const { challengeDetails } = this.props
const { challengeDetails, metadata } = this.props
const isTask = _.find(metadata.challengeTypes, { id: challengeDetails.typeId, isTask: true })
try {
this.setState({ isLaunching: true })
// call action to update the challenge status
const action = await partiallyUpdateChallengeDetails(challengeDetails.id, {
const payload = {
status: 'Active'
})
}
if (isTask) {
payload.startDate = moment().format()
}
// call action to update the challenge status
const action = await partiallyUpdateChallengeDetails(challengeDetails.id, payload)
this.setState({
isLaunching: false,
showLaunchModal: false,
Expand Down