Skip to content

Commit 3302195

Browse files
Merge pull request #1280 from doctorhilarius/self-service-opps
WIP -- Self service opps pt 3
2 parents 3091e5e + 8f601d9 commit 3302195

File tree

6 files changed

+124
-33
lines changed

6 files changed

+124
-33
lines changed

src/actions/challenges.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ import {
4646
DELETE_CHALLENGE_PENDING,
4747
DELETE_CHALLENGE_SUCCESS,
4848
DELETE_CHALLENGE_FAILURE,
49-
LOAD_CHALLENGE_RESOURCES
49+
LOAD_CHALLENGE_RESOURCES,
50+
CHALLENGE_STATUS
5051
} from '../config/constants'
5152
import { loadProject } from './projects'
5253
import { removeChallengeFromPhaseProduct, saveChallengeAsPhaseProduct } from '../services/projects'
@@ -87,7 +88,7 @@ export function loadChallengesByPage (page, projectId, status, filterChallengeNa
8788
}
8889
if (selfService) {
8990
filters.selfService = true
90-
if (userHandle) {
91+
if (userHandle && filters.status.toUpperCase() !== CHALLENGE_STATUS.DRAFT) {
9192
filters.selfServiceCopilot = userHandle
9293
}
9394
}

src/components/ChallengeEditor/ChallengeView/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const ChallengeView = ({
3838
onLaunchChallenge,
3939
onCloseTask,
4040
projectPhases,
41-
assignYourselfCopilit
41+
assignYourselfCopilot,
42+
showRejectChallengeModal
4243
}) => {
4344
const selectedType = _.find(metadata.challengeTypes, { id: challenge.typeId })
4445
const challengeTrack = _.find(metadata.challengeTracks, { id: challenge.trackId })
@@ -75,7 +76,7 @@ const ChallengeView = ({
7576
const reviewerFromResources = reviewerResource ? reviewerResource.memberHandle : ''
7677
let copilot, reviewer
7778
if (challenge) {
78-
copilot = challenge.copilot
79+
copilot = challenge.copilot || (challenge.legacy && challenge.legacy.selfServiceCopilot)
7980
reviewer = challenge.reviewer
8081
}
8182
copilot = copilot || copilotFromResources
@@ -135,7 +136,7 @@ const ChallengeView = ({
135136
<CopilotField challenge={{
136137
copilot,
137138
selfService: challenge.legacy.selfService
138-
}} copilots={metadata.members} assignYourselfCopilit={assignYourselfCopilit} readOnly />
139+
}} copilots={metadata.members} assignYourselfCopilot={assignYourselfCopilot} showRejectChallengeModal={showRejectChallengeModal} readOnly />
139140
<div className={cn(styles.row, styles.topRow)}>
140141
<div className={styles.col}>
141142
<span><span
@@ -262,7 +263,8 @@ ChallengeView.propTypes = {
262263
onLaunchChallenge: PropTypes.func,
263264
onCloseTask: PropTypes.func,
264265
projectPhases: PropTypes.arrayOf(PropTypes.object),
265-
assignYourselfCopilit: PropTypes.func.isRequired
266+
assignYourselfCopilot: PropTypes.func.isRequired,
267+
showRejectChallengeModal: PropTypes.func.isRequired
266268
}
267269

268270
export default withRouter(ChallengeView)

src/components/ChallengeEditor/ChallengeViewTabs/index.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ const ChallengeViewTabs = ({
4444
cancelChallenge,
4545
onCloseTask,
4646
projectPhases,
47-
assignYourselfCopilit
47+
assignYourselfCopilot,
48+
showRejectChallengeModal,
49+
loggedInUser
4850
}) => {
4951
const [selectedTab, setSelectedTab] = useState(0)
5052

@@ -84,6 +86,7 @@ const ChallengeViewTabs = ({
8486
const isSelfService = challenge.legacy.selfService
8587
const isDraft = challenge.status.toUpperCase() === CHALLENGE_STATUS.DRAFT
8688
const launchText = `${isSelfService && isDraft ? 'Approve and ' : ''}Launch`
89+
const isCopilot = challenge.legacy.selfServiceCopilot === loggedInUser.handle
8790

8891
return (
8992
<div className={styles.list}>
@@ -112,9 +115,9 @@ const ChallengeViewTabs = ({
112115
styles.actionButtonsRight
113116
)}
114117
>
115-
{(challenge.status === 'Draft' || challenge.status === 'New') && !isSelfService &&
118+
{(isDraft || challenge.status === 'New') && !isSelfService &&
116119
(<div className={styles['cancel-button']}><CancelDropDown challenge={challenge} onSelectMenu={cancelChallenge} /></div>)}
117-
{challenge.status === 'Draft' && (
120+
{isDraft && (!isSelfService || isCopilot) && (
118121
<div className={styles.button}>
119122
{challenge.legacyId || isTask ? (
120123
<PrimaryButton
@@ -147,14 +150,15 @@ const ChallengeViewTabs = ({
147150
{enableEdit && !isSelfService && (
148151
<PrimaryButton text={'Edit'} type={'info'} submit link={`./edit`} />
149152
)}
150-
{isSelfService && isDraft &&
151-
(
153+
{isSelfService && isDraft && isCopilot && (
154+
<div className={styles.button}>
152155
<PrimaryButton
153156
text={'Reject challenge'}
154157
type={'danger'}
155-
onClick={onLaunchChallenge} // TODO
158+
onClick={showRejectChallengeModal}
156159
/>
157-
)}
160+
</div>
161+
)}
158162
<PrimaryButton text={'Back'} type={'info'} submit link={`..`} />
159163
</div>
160164
</div>
@@ -222,7 +226,8 @@ const ChallengeViewTabs = ({
222226
onLaunchChallenge={onLaunchChallenge}
223227
onCloseTask={onCloseTask}
224228
projectPhases={projectPhases}
225-
assignYourselfCopilit={assignYourselfCopilit}
229+
assignYourselfCopilot={assignYourselfCopilot}
230+
showRejectChallengeModal={showRejectChallengeModal}
226231
/>
227232
)}
228233
{selectedTab === 1 && (
@@ -260,7 +265,9 @@ ChallengeViewTabs.propTypes = {
260265
cancelChallenge: PropTypes.func.isRequired,
261266
onCloseTask: PropTypes.func,
262267
projectPhases: PropTypes.arrayOf(PropTypes.object),
263-
assignYourselfCopilit: PropTypes.func.isRequired
268+
assignYourselfCopilot: PropTypes.func.isRequired,
269+
showRejectChallengeModal: PropTypes.func.isRequired,
270+
loggedInUser: PropTypes.object.isRequired
264271
}
265272

266273
export default ChallengeViewTabs

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import cn from 'classnames'
66
import _ from 'lodash'
77
import CopilotCard from '../../CopilotCard'
88

9-
const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly, assignYourselfCopilit }) => {
9+
const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly, assignYourselfCopilot }) => {
1010
let errMessage = 'Please set a copilot'
1111
const selectedCopilot = _.find(copilots, { handle: challenge.copilot })
1212
const copilotFee = _.find(challenge.prizeSets, p => p.type === 'copilot', [])
@@ -20,10 +20,10 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly, assignYou
2020
</div>
2121
{(selectedCopilot || selfService) && (<div className={cn(styles.field, styles.col2)}>
2222
{(selectedCopilot && <CopilotCard copilot={selectedCopilot} selectedCopilot='' key={selectedCopilot.handle} />)}
23-
{(selfService && <PrimaryButton
23+
{(selfService && !selectedCopilot && <PrimaryButton
2424
text={'Assign Yourself'}
2525
type={'info'}
26-
onClick={assignYourselfCopilit}
26+
onClick={assignYourselfCopilot}
2727
/>)}
2828
</div>)}
2929
</div>
@@ -65,7 +65,7 @@ CopilotField.propTypes = {
6565
challenge: PropTypes.shape().isRequired,
6666
onUpdateOthers: PropTypes.func,
6767
readOnly: PropTypes.bool,
68-
assignYourselfCopilit: PropTypes.func.isRequired
68+
assignYourselfCopilot: PropTypes.func.isRequired
6969
}
7070

7171
export default CopilotField

src/components/ChallengeEditor/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,8 @@ class ChallengeEditor extends Component {
12331233
projectDetail,
12341234
attachments,
12351235
projectPhases,
1236-
challengeId
1236+
challengeId,
1237+
assignYourselfCopilot
12371238
} = this.props
12381239
if (_.isEmpty(challenge)) {
12391240
return <div>Error loading challenge</div>
@@ -1514,7 +1515,7 @@ class ChallengeEditor extends Component {
15141515
/>
15151516
)}
15161517
{projectDetail.version === 'v4' && <MilestoneField milestones={activeProjectMilestones} onUpdateSelect={this.onUpdateSelect} projectId={projectDetail.id} selectedMilestoneId={selectedMilestoneId} />}
1517-
<CopilotField challenge={challenge} copilots={metadata.members} onUpdateOthers={this.onUpdateOthers} />
1518+
<CopilotField challenge={challenge} copilots={metadata.members} onUpdateOthers={this.onUpdateOthers} assignYourselfCopilot={assignYourselfCopilot} />
15181519
<ReviewTypeField
15191520
reviewers={metadata.members}
15201521
challenge={challenge}
@@ -1694,7 +1695,8 @@ ChallengeEditor.propTypes = {
16941695
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
16951696
deleteChallenge: PropTypes.func.isRequired,
16961697
loggedInUser: PropTypes.shape().isRequired,
1697-
projectPhases: PropTypes.arrayOf(PropTypes.object).isRequired
1698+
projectPhases: PropTypes.arrayOf(PropTypes.object).isRequired,
1699+
assignYourselfCopilot: PropTypes.func.isRequired
16981700
}
16991701

17001702
export default withRouter(ChallengeEditor)

0 commit comments

Comments
 (0)