Skip to content

Commit cb57a78

Browse files
authored
Merge pull request #1031 from dashu-baba/issue-1007
Fixed issue #1007
2 parents f2408b2 + 5653cc6 commit cb57a78

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

src/components/ChallengeEditor/ReviewType-Field/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import _ from 'lodash'
12
import React from 'react'
23
import PropTypes from 'prop-types'
34
import Select from '../../Select'
@@ -9,10 +10,11 @@ import { DES_TRACK_ID, REVIEW_TYPES, MESSAGE, QA_TRACK_ID } from '../../../confi
910
const ReviewTypeField = ({ reviewers, challenge, onUpdateOthers, onUpdateSelect }) => {
1011
const isDesignChallenge = challenge.trackId === DES_TRACK_ID
1112
const isQAChallenge = challenge.trackId === QA_TRACK_ID
13+
const isTask = _.get(challenge, 'task.isTask', false)
1214
const defaultReviewType = isDesignChallenge ? REVIEW_TYPES.INTERNAL : REVIEW_TYPES.COMMUNITY
1315
const reviewType = challenge.reviewType ? challenge.reviewType.toUpperCase() : defaultReviewType
1416
const isCommunity = reviewType === REVIEW_TYPES.COMMUNITY
15-
const isInternal = reviewType === REVIEW_TYPES.INTERNAL
17+
const isInternal = reviewType === REVIEW_TYPES.INTERNAL || isTask
1618
const communityOption = (disabled) => (<div className={styles.tcRadioButton}>
1719
<input
1820
name='community'
@@ -59,7 +61,7 @@ const ReviewTypeField = ({ reviewers, challenge, onUpdateOthers, onUpdateSelect
5961
{ communityOption(true) }
6062
</Tooltip>
6163
}
62-
{ !isDesignChallenge &&
64+
{ !isDesignChallenge && !isTask &&
6365
communityOption()
6466
}
6567
</div>

src/components/ChallengeEditor/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ class ChallengeEditor extends Component {
776776
}
777777

778778
collectChallengeData (status) {
779-
const { attachments } = this.props
779+
const { attachments, metadata } = this.props
780780
const challenge = pick([
781781
'phases',
782782
'typeId',
@@ -793,6 +793,7 @@ class ChallengeEditor extends Component {
793793
'prizeSets',
794794
'winners'
795795
], this.state.challenge)
796+
const isTask = _.find(metadata.challengeTypes, { id: challenge.typeId, isTask: true })
796797
challenge.legacy = _.assign(this.state.challenge.legacy, {
797798
reviewType: challenge.reviewType
798799
})
@@ -803,6 +804,10 @@ class ChallengeEditor extends Component {
803804
return { ...p, prizes }
804805
})
805806
challenge.status = status
807+
if (status === 'Active' && isTask) {
808+
challenge.startDate = moment().format()
809+
}
810+
806811
if (this.state.challenge.id) {
807812
challenge.attachmentIds = _.map(attachments, item => item.id)
808813
}
@@ -837,7 +842,7 @@ class ChallengeEditor extends Component {
837842
const avlTemplates = this.getAvailableTimelineTemplates()
838843
// chooses first available timeline template or fallback template for the new challenge
839844
const defaultTemplate = avlTemplates && avlTemplates.length > 0 ? avlTemplates[0] : STD_DEV_TIMELINE_TEMPLATE
840-
845+
const isTask = _.find(metadata.challengeTypes, { id: typeId, isTask: true })
841846
const newChallenge = {
842847
status: 'New',
843848
projectId: this.props.projectId,
@@ -846,7 +851,7 @@ class ChallengeEditor extends Component {
846851
trackId,
847852
startDate: moment().add(1, 'days').format(),
848853
legacy: {
849-
reviewType: isDesignChallenge ? REVIEW_TYPES.INTERNAL : REVIEW_TYPES.COMMUNITY
854+
reviewType: isTask || isDesignChallenge ? REVIEW_TYPES.INTERNAL : REVIEW_TYPES.COMMUNITY
850855
},
851856
descriptionFormat: 'markdown',
852857
timelineTemplateId: defaultTemplate.id,
@@ -859,6 +864,10 @@ class ChallengeEditor extends Component {
859864
}
860865
try {
861866
const action = await createChallenge(newChallenge)
867+
if (isTask) {
868+
await this.updateResource(action.challengeDetails.id, 'Reviewer', action.challengeDetails.createdBy, action.challengeDetails.reviewer)
869+
action.challengeDetails.reviewer = action.challengeDetails.createdBy
870+
}
862871
const draftChallenge = {
863872
data: action.challengeDetails
864873
}
@@ -1399,7 +1408,7 @@ class ChallengeEditor extends Component {
13991408
<GroupsField groups={metadata.groups} onUpdateMultiSelect={this.onUpdateMultiSelect} challenge={challenge} />
14001409
</React.Fragment>
14011410
)}
1402-
{
1411+
{!isTask && (
14031412
<div className={styles.PhaseRow}>
14041413
<PhaseInput
14051414
withDates
@@ -1414,7 +1423,7 @@ class ChallengeEditor extends Component {
14141423
readOnly={false}
14151424
/>
14161425
</div>
1417-
}
1426+
)}
14181427
{
14191428
this.state.isDeleteLaunch && !this.state.isConfirm && (
14201429
<ConfirmationModal

src/components/ChallengesComponent/ChallengeCard/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,15 @@ class ChallengeCard extends React.Component {
220220
const { challenge } = this.props
221221
try {
222222
this.setState({ isSaving: true })
223-
// call action to update the challenge with a new status
224-
await partiallyUpdateChallengeDetails(challenge.id, {
223+
const isTask = _.get(challenge, 'task.isTask', false)
224+
const payload = {
225225
status: 'Active'
226-
})
226+
}
227+
if (isTask) {
228+
payload.startDate = moment().format()
229+
}
230+
// call action to update the challenge with a new status
231+
await partiallyUpdateChallengeDetails(challenge.id, payload)
227232
this.setState({ isLaunch: true, isConfirm: challenge.id, isSaving: false })
228233
} catch (e) {
229234
const error = _.get(e, 'response.data.message', 'Unable to activate the challenge')

src/containers/ChallengeEditor/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from 'lodash'
22
import React, { Component } from 'react'
33
import PropTypes from 'prop-types'
44
import { withRouter, Route } from 'react-router-dom'
5+
import moment from 'moment'
56
import ChallengeEditorComponent from '../../components/ChallengeEditor'
67
import ChallengeViewComponent from '../../components/ChallengeEditor/ChallengeView'
78
import Loader from '../../components/Loader'
@@ -156,13 +157,18 @@ class ChallengeEditor extends Component {
156157
async activateChallenge () {
157158
const { partiallyUpdateChallengeDetails } = this.props
158159
if (this.state.isLaunching) return
159-
const { challengeDetails } = this.props
160+
const { challengeDetails, metadata } = this.props
161+
const isTask = _.find(metadata.challengeTypes, { id: challengeDetails.typeId, isTask: true })
160162
try {
161163
this.setState({ isLaunching: true })
162-
// call action to update the challenge status
163-
const action = await partiallyUpdateChallengeDetails(challengeDetails.id, {
164+
const payload = {
164165
status: 'Active'
165-
})
166+
}
167+
if (isTask) {
168+
payload.startDate = moment().format()
169+
}
170+
// call action to update the challenge status
171+
const action = await partiallyUpdateChallengeDetails(challengeDetails.id, payload)
166172
this.setState({
167173
isLaunching: false,
168174
showLaunchModal: false,

0 commit comments

Comments
 (0)