@@ -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
273289export default ChallengeViewTabs
0 commit comments