Skip to content

Commit 3b90fe6

Browse files
Merge pull request #1283 from doctorhilarius/self-service-opps
Self service opps - Approve then Launch
2 parents 6cda335 + 8cd71aa commit 3b90fe6

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

src/components/ChallengeEditor/ChallengeViewTabs/index.js

Lines changed: 24 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,8 +86,12 @@ 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`
8989
const isCopilot = challenge.legacy.selfServiceCopilot === loggedInUser.handle
90+
const canApprove = isCopilot && isDraft && isSelfService
91+
// only the copilot can launch AND
92+
// if this isn't self-service, permit launching if the challenge is draft
93+
// OR if this is self-service, permit launching if the challenge is approved
94+
const canLaunch = isCopilot && ((!isSelfService && isDraft) || challenge.status.toUpperCase() === CHALLENGE_STATUS.APPROVED)
9095

9196
return (
9297
<div className={styles.list}>
@@ -117,12 +122,12 @@ const ChallengeViewTabs = ({
117122
>
118123
{(isDraft || challenge.status === 'New') && !isSelfService &&
119124
(<div className={styles['cancel-button']}><CancelDropDown challenge={challenge} onSelectMenu={cancelChallenge} /></div>)}
120-
{isDraft && (!isSelfService || isCopilot) && (
125+
{canLaunch && (
121126
<div className={styles.button}>
122127
{challenge.legacyId || isTask ? (
123128
<PrimaryButton
124-
text={launchText}
125-
type={'info'}
129+
text='Launch'
130+
type='info'
126131
onClick={onLaunchChallenge}
127132
/>
128133
) : (
@@ -133,6 +138,15 @@ const ChallengeViewTabs = ({
133138
)}
134139
</div>
135140
)}
141+
{canApprove && (
142+
<div className={styles.button}>
143+
<PrimaryButton
144+
text='Approve'
145+
type='info'
146+
onClick={onApproveChallenge}
147+
/>
148+
</div>
149+
)}
136150
{isTask && challenge.status === 'Active' && (
137151
<div className={styles.button}>
138152
{assignedMemberDetails ? (
@@ -153,8 +167,8 @@ const ChallengeViewTabs = ({
153167
{isSelfService && isDraft && isCopilot && (
154168
<div className={styles.button}>
155169
<PrimaryButton
156-
text={'Reject challenge'}
157-
type={'danger'}
170+
text='Reject challenge'
171+
type='danger'
158172
onClick={showRejectChallengeModal}
159173
/>
160174
</div>
@@ -228,6 +242,7 @@ const ChallengeViewTabs = ({
228242
projectPhases={projectPhases}
229243
assignYourselfCopilot={assignYourselfCopilot}
230244
showRejectChallengeModal={showRejectChallengeModal}
245+
onApproveChallenge={onApproveChallenge}
231246
/>
232247
)}
233248
{selectedTab === 1 && (
@@ -267,7 +282,8 @@ ChallengeViewTabs.propTypes = {
267282
projectPhases: PropTypes.arrayOf(PropTypes.object),
268283
assignYourselfCopilot: PropTypes.func.isRequired,
269284
showRejectChallengeModal: PropTypes.func.isRequired,
270-
loggedInUser: PropTypes.object.isRequired
285+
loggedInUser: PropTypes.object.isRequired,
286+
onApproveChallenge: PropTypes.func
271287
}
272288

273289
export default ChallengeViewTabs

src/components/ChallengesComponent/ChallengeList/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class ChallengeList extends Component {
224224
{
225225
challenges.length > 0 && (
226226
<div className={styles.header}>
227-
<div className={styles.col1}>Challenges Name</div>
227+
<div className={styles.col1}>Challenge Name</div>
228228
<div className={styles.col2}>Last Updated</div>
229229
<div className={styles.col2}>Status</div>
230230
{(selectedTab === 0) && (<div className={styles.col3}>Current phase</div>)}

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)