Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/components/ChallengeEditor/ChallengeViewTabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const ChallengeViewTabs = ({
projectPhases,
assignYourselfCopilot,
showRejectChallengeModal,
loggedInUser
loggedInUser,
onApproveChallenge
}) => {
const [selectedTab, setSelectedTab] = useState(0)

Expand Down Expand Up @@ -85,8 +86,12 @@ const ChallengeViewTabs = ({

const isSelfService = challenge.legacy.selfService
const isDraft = challenge.status.toUpperCase() === CHALLENGE_STATUS.DRAFT
const launchText = `${isSelfService && isDraft ? 'Approve and ' : ''}Launch`
const isCopilot = challenge.legacy.selfServiceCopilot === loggedInUser.handle
const canApprove = isCopilot && isDraft && isSelfService
// only the copilot can launch AND
// if this isn't self-service, permit launching if the challenge is draft
// OR if this is self-service, permit launching if the challenge is approved
const canLaunch = isCopilot && ((!isSelfService && isDraft) || challenge.status.toUpperCase() === CHALLENGE_STATUS.APPROVED)

return (
<div className={styles.list}>
Expand Down Expand Up @@ -117,12 +122,12 @@ const ChallengeViewTabs = ({
>
{(isDraft || challenge.status === 'New') && !isSelfService &&
(<div className={styles['cancel-button']}><CancelDropDown challenge={challenge} onSelectMenu={cancelChallenge} /></div>)}
{isDraft && (!isSelfService || isCopilot) && (
{canLaunch && (
<div className={styles.button}>
{challenge.legacyId || isTask ? (
<PrimaryButton
text={launchText}
type={'info'}
text='Launch'
type='info'
onClick={onLaunchChallenge}
/>
) : (
Expand All @@ -133,6 +138,15 @@ const ChallengeViewTabs = ({
)}
</div>
)}
{canApprove && (
<div className={styles.button}>
<PrimaryButton
text='Approve'
type='info'
onClick={onApproveChallenge}
/>
</div>
)}
{isTask && challenge.status === 'Active' && (
<div className={styles.button}>
{assignedMemberDetails ? (
Expand All @@ -153,8 +167,8 @@ const ChallengeViewTabs = ({
{isSelfService && isDraft && isCopilot && (
<div className={styles.button}>
<PrimaryButton
text={'Reject challenge'}
type={'danger'}
text='Reject challenge'
type='danger'
onClick={showRejectChallengeModal}
/>
</div>
Expand Down Expand Up @@ -228,6 +242,7 @@ const ChallengeViewTabs = ({
projectPhases={projectPhases}
assignYourselfCopilot={assignYourselfCopilot}
showRejectChallengeModal={showRejectChallengeModal}
onApproveChallenge={onApproveChallenge}
/>
)}
{selectedTab === 1 && (
Expand Down Expand Up @@ -267,7 +282,8 @@ ChallengeViewTabs.propTypes = {
projectPhases: PropTypes.arrayOf(PropTypes.object),
assignYourselfCopilot: PropTypes.func.isRequired,
showRejectChallengeModal: PropTypes.func.isRequired,
loggedInUser: PropTypes.object.isRequired
loggedInUser: PropTypes.object.isRequired,
onApproveChallenge: PropTypes.func
}

export default ChallengeViewTabs
2 changes: 1 addition & 1 deletion src/components/ChallengesComponent/ChallengeList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class ChallengeList extends Component {
{
challenges.length > 0 && (
<div className={styles.header}>
<div className={styles.col1}>Challenges Name</div>
<div className={styles.col1}>Challenge Name</div>
<div className={styles.col2}>Last Updated</div>
<div className={styles.col2}>Status</div>
{(selectedTab === 0) && (<div className={styles.col3}>Current phase</div>)}
Expand Down
1 change: 1 addition & 0 deletions src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const CHALLENGE_STATUS = {
ACTIVE: 'ACTIVE',
NEW: 'NEW',
DRAFT: 'DRAFT',
APPROVED: 'APPROVED',
COMPLETED: 'COMPLETED',
CANCELLED: 'CANCELLED'
}
Expand Down
16 changes: 16 additions & 0 deletions src/containers/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ChallengeEditor extends Component {
this.closeRejectModal = this.closeRejectModal.bind(this)
this.rejectChallenge = this.rejectChallenge.bind(this)
this.onChangeCancelReason = this.onChangeCancelReason.bind(this)
this.onApproveChallenge = this.onApproveChallenge.bind(this)
}

componentDidMount () {
Expand Down Expand Up @@ -203,6 +204,20 @@ class ChallengeEditor extends Component {
}
}

async onApproveChallenge () {
const { partiallyUpdateChallengeDetails, challengeDetails } = this.props
const newStatus = 'Approved'
await partiallyUpdateChallengeDetails(challengeDetails.id, {
status: newStatus
})
this.setState({
challengeDetails: {
...challengeDetails,
status: newStatus
}
})
}

async cancelChallenge (challenge, cancelReason) {
const { partiallyUpdateChallengeDetails, history } = this.props

Expand Down Expand Up @@ -580,6 +595,7 @@ class ChallengeEditor extends Component {
assignYourselfCopilot={this.assignYourselfCopilot}
showRejectChallengeModal={this.showRejectChallengeModal}
loggedInUser={loggedInUser}
onApproveChallenge={this.onApproveChallenge}
/>
)}
/>
Expand Down