Skip to content

Commit db18d64

Browse files
require approving before launching for self service challenges
1 parent 4eddce9 commit db18d64

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

src/components/ChallengeEditor/ChallengeViewTabs/index.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const ChallengeViewTabs = ({
4646
projectPhases,
4747
assignYourselfCopilot,
4848
showRejectChallengeModal,
49-
loggedInUser
49+
loggedInUser,
50+
onApproveChallenge
5051
}) => {
5152
const [selectedTab, setSelectedTab] = useState(0)
5253

@@ -85,7 +86,9 @@ const ChallengeViewTabs = ({
8586

8687
const isSelfService = challenge.legacy.selfService
8788
const isDraft = challenge.status.toUpperCase() === CHALLENGE_STATUS.DRAFT
88-
const launchText = `${isSelfService && isDraft ? 'Approve and ' : ''}Launch`
89+
// if this isn't self-service, permit launching if the challenge is draft
90+
// OR if this is self-service, permit launching if the challenge is approved
91+
const canLaunch = (!isSelfService && isDraft) || challenge.status.toUpperCase() === CHALLENGE_STATUS.APPROVED
8992
const isCopilot = challenge.legacy.selfServiceCopilot === loggedInUser.handle
9093

9194
return (
@@ -117,12 +120,12 @@ const ChallengeViewTabs = ({
117120
>
118121
{(isDraft || challenge.status === 'New') && !isSelfService &&
119122
(<div className={styles['cancel-button']}><CancelDropDown challenge={challenge} onSelectMenu={cancelChallenge} /></div>)}
120-
{isDraft && (!isSelfService || isCopilot) && (
123+
{canLaunch && (
121124
<div className={styles.button}>
122125
{challenge.legacyId || isTask ? (
123126
<PrimaryButton
124-
text={launchText}
125-
type={'info'}
127+
text='Launch'
128+
type='info'
126129
onClick={onLaunchChallenge}
127130
/>
128131
) : (
@@ -133,6 +136,15 @@ const ChallengeViewTabs = ({
133136
)}
134137
</div>
135138
)}
139+
{isDraft && isSelfService && (
140+
<div className={styles.button}>
141+
<PrimaryButton
142+
text='Approve'
143+
type='info'
144+
onClick={onApproveChallenge}
145+
/>
146+
</div>
147+
)}
136148
{isTask && challenge.status === 'Active' && (
137149
<div className={styles.button}>
138150
{assignedMemberDetails ? (
@@ -153,8 +165,8 @@ const ChallengeViewTabs = ({
153165
{isSelfService && isDraft && isCopilot && (
154166
<div className={styles.button}>
155167
<PrimaryButton
156-
text={'Reject challenge'}
157-
type={'danger'}
168+
text='Reject challenge'
169+
type='danger'
158170
onClick={showRejectChallengeModal}
159171
/>
160172
</div>
@@ -228,6 +240,7 @@ const ChallengeViewTabs = ({
228240
projectPhases={projectPhases}
229241
assignYourselfCopilot={assignYourselfCopilot}
230242
showRejectChallengeModal={showRejectChallengeModal}
243+
onApproveChallenge={onApproveChallenge}
231244
/>
232245
)}
233246
{selectedTab === 1 && (
@@ -267,7 +280,8 @@ ChallengeViewTabs.propTypes = {
267280
projectPhases: PropTypes.arrayOf(PropTypes.object),
268281
assignYourselfCopilot: PropTypes.func.isRequired,
269282
showRejectChallengeModal: PropTypes.func.isRequired,
270-
loggedInUser: PropTypes.object.isRequired
283+
loggedInUser: PropTypes.object.isRequired,
284+
onApproveChallenge: PropTypes.func
271285
}
272286

273287
export default ChallengeViewTabs

src/config/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export const CHALLENGE_STATUS = {
167167
ACTIVE: 'ACTIVE',
168168
NEW: 'NEW',
169169
DRAFT: 'DRAFT',
170+
APPROVED: 'APPROVED',
170171
COMPLETED: 'COMPLETED',
171172
CANCELLED: 'CANCELLED'
172173
}

src/containers/ChallengeEditor/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ChallengeEditor extends Component {
7777
this.closeRejectModal = this.closeRejectModal.bind(this)
7878
this.rejectChallenge = this.rejectChallenge.bind(this)
7979
this.onChangeCancelReason = this.onChangeCancelReason.bind(this)
80+
this.onApproveChallenge = this.onApproveChallenge.bind(this)
8081
}
8182

8283
componentDidMount () {
@@ -203,6 +204,20 @@ class ChallengeEditor extends Component {
203204
}
204205
}
205206

207+
async onApproveChallenge () {
208+
const { partiallyUpdateChallengeDetails, challengeDetails } = this.props
209+
const newStatus = 'Approved'
210+
await partiallyUpdateChallengeDetails(challengeDetails.id, {
211+
status: newStatus
212+
})
213+
this.setState({
214+
challengeDetails: {
215+
...challengeDetails,
216+
status: newStatus
217+
}
218+
})
219+
}
220+
206221
async cancelChallenge (challenge, cancelReason) {
207222
const { partiallyUpdateChallengeDetails, history } = this.props
208223

@@ -580,6 +595,7 @@ class ChallengeEditor extends Component {
580595
assignYourselfCopilot={this.assignYourselfCopilot}
581596
showRejectChallengeModal={this.showRejectChallengeModal}
582597
loggedInUser={loggedInUser}
598+
onApproveChallenge={this.onApproveChallenge}
583599
/>
584600
)}
585601
/>

0 commit comments

Comments
 (0)