Skip to content

Unassign copilot #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2022
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
8 changes: 5 additions & 3 deletions src/components/ChallengeEditor/ChallengeView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const ChallengeView = ({
onCloseTask,
projectPhases,
assignYourselfCopilot,
showRejectChallengeModal
showRejectChallengeModal,
loggedInUser
}) => {
const selectedType = _.find(metadata.challengeTypes, { id: challenge.typeId })
const challengeTrack = _.find(metadata.challengeTracks, { id: challenge.trackId })
Expand Down Expand Up @@ -136,7 +137,7 @@ const ChallengeView = ({
<CopilotField challenge={{
copilot,
selfService: challenge.legacy.selfService
}} copilots={challengeResources} assignYourselfCopilot={assignYourselfCopilot} showRejectChallengeModal={showRejectChallengeModal} readOnly />
}} copilots={challengeResources} assignYourselfCopilot={assignYourselfCopilot} showRejectChallengeModal={showRejectChallengeModal} readOnly loggedInUser={loggedInUser} />
<div className={cn(styles.row, styles.topRow)}>
<div className={styles.col}>
<span><span
Expand Down Expand Up @@ -264,7 +265,8 @@ ChallengeView.propTypes = {
onCloseTask: PropTypes.func,
projectPhases: PropTypes.arrayOf(PropTypes.object),
assignYourselfCopilot: PropTypes.func.isRequired,
showRejectChallengeModal: PropTypes.func.isRequired
showRejectChallengeModal: PropTypes.func.isRequired,
loggedInUser: PropTypes.object
}

export default withRouter(ChallengeView)
1 change: 1 addition & 0 deletions src/components/ChallengeEditor/ChallengeViewTabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ const ChallengeViewTabs = ({
assignYourselfCopilot={assignYourselfCopilot}
showRejectChallengeModal={showRejectChallengeModal}
onApproveChallenge={onApproveChallenge}
loggedInUser={loggedInUser}
/>
)}
{selectedTab === 1 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;

div {
margin-right: 13px;
Expand Down
30 changes: 19 additions & 11 deletions src/components/ChallengeEditor/Copilot-Field/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import React from 'react'
import PropTypes from 'prop-types'
import { PrimaryButton } from '../../Buttons'
import styles from './Copilot-Field.module.scss'
import cn from 'classnames'
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

import { PrimaryButton } from '../../Buttons'
import CopilotCard from '../../CopilotCard'

const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly, assignYourselfCopilot }) => {
import styles from './Copilot-Field.module.scss'

const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly, assignYourselfCopilot, loggedInUser }) => {
let errMessage = 'Please set a copilot'
const handleProperty = copilots.handle ? 'handle' : 'memberHandle'
const selectedCopilot = _.find(copilots, { [handleProperty]: challenge.copilot })
const selectedCopilotHandle = selectedCopilot ? selectedCopilot[handleProperty] : undefined
const copilotFee = _.find(challenge.prizeSets, p => p.type === 'copilot', [])
const selfService = challenge.selfService
const copilotIsSelf = loggedInUser && selectedCopilotHandle === loggedInUser.handle
const assignButtonText = `${selectedCopilot && copilotIsSelf ? 'Una' : 'A'}ssign Yourself`
const showAssignButton = loggedInUser && (!selectedCopilotHandle || copilotIsSelf)

if (readOnly) {
return (
Expand All @@ -22,11 +27,13 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly, assignYou
</div>
{(selectedCopilot || selfService) && (<div className={cn(styles.field, styles.col2)}>
{(selectedCopilot && <CopilotCard copilot={selectedCopilot} selectedCopilot={challenge.copilot} key={selectedCopilotHandle} />)}
{(selfService && !selectedCopilot && <PrimaryButton
text='Assign Yourself'
type='info'
onClick={assignYourselfCopilot}
/>)}
{((selfService && showAssignButton) && <div>
<PrimaryButton
text={assignButtonText}
type='info'
onClick={assignYourselfCopilot}
/>
</div>)}
</div>)}
</div>
)
Expand Down Expand Up @@ -67,7 +74,8 @@ CopilotField.propTypes = {
challenge: PropTypes.shape().isRequired,
onUpdateOthers: PropTypes.func,
readOnly: PropTypes.bool,
assignYourselfCopilot: PropTypes.func.isRequired
assignYourselfCopilot: PropTypes.func.isRequired,
loggedInUser: PropTypes.object
}

export default CopilotField
5 changes: 3 additions & 2 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,8 @@ class ChallengeEditor extends Component {
projectPhases,
challengeId,
assignYourselfCopilot,
challengeResources
challengeResources,
loggedInUser
} = this.props
if (_.isEmpty(challenge)) {
return <div>Error loading challenge</div>
Expand Down Expand Up @@ -1517,7 +1518,7 @@ class ChallengeEditor extends Component {
/>
)}
{projectDetail.version === 'v4' && <MilestoneField milestones={activeProjectMilestones} onUpdateSelect={this.onUpdateSelect} projectId={projectDetail.id} selectedMilestoneId={selectedMilestoneId} />}
<CopilotField challenge={challenge} copilots={copilotResources} onUpdateOthers={this.onUpdateOthers} assignYourselfCopilot={assignYourselfCopilot} />
<CopilotField challenge={challenge} copilots={copilotResources} onUpdateOthers={this.onUpdateOthers} assignYourselfCopilot={assignYourselfCopilot} loggedInUser={loggedInUser} />
<ReviewTypeField
reviewers={metadata.members}
challenge={challenge}
Expand Down
24 changes: 13 additions & 11 deletions src/containers/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import {
partiallyUpdateChallengeDetails,
deleteChallenge,
createChallenge,
replaceResourceInRole,
createResource
replaceResourceInRole
} from '../../actions/challenges'

import { loadSubmissions } from '../../actions/challengeSubmissions'
Expand Down Expand Up @@ -338,23 +337,28 @@ class ChallengeEditor extends Component {
}

async assignYourselfCopilot () {
const { challengeDetails, loggedInUser, metadata, createResource } = this.props
const { challengeDetails, loggedInUser, metadata, replaceResourceInRole } = this.props

// create the role resource
// get the resource roles and new/old resource values
const copilotRole = getResourceRoleByName(metadata.resourceRoles, 'Copilot')
const approverRole = getResourceRoleByName(metadata.resourceRoles, 'Approver')
const screenerRole = getResourceRoleByName(metadata.resourceRoles, 'Primary Screener')
const copilotHandle = loggedInUser.handle
await createResource(challengeDetails.id, copilotRole.id, copilotHandle)
await createResource(challengeDetails.id, approverRole.id, copilotHandle)
await createResource(challengeDetails.id, screenerRole.id, copilotHandle)
const challengeId = challengeDetails.id
const oldPilot = challengeDetails.legacy.selfServiceCopilot
const newPilot = oldPilot === copilotHandle ? null : copilotHandle

// replace the roles
await replaceResourceInRole(challengeId, copilotRole.id, newPilot, oldPilot)
await replaceResourceInRole(challengeId, approverRole.id, newPilot, oldPilot)
await replaceResourceInRole(challengeId, screenerRole.id, newPilot, oldPilot)

this.setState({
challengeDetails: {
...challengeDetails,
legacy: {
...challengeDetails.legacy,
selfServiceCopilot: copilotHandle
selfServiceCopilot: newPilot
}
}
})
Expand Down Expand Up @@ -608,7 +612,6 @@ class ChallengeEditor extends Component {
}

ChallengeEditor.propTypes = {
createResource: PropTypes.func.isRequired,
match: PropTypes.shape({
path: PropTypes.string,
params: PropTypes.shape({
Expand Down Expand Up @@ -713,8 +716,7 @@ const mapDispatchToProps = {
deleteChallenge,
createChallenge,
replaceResourceInRole,
loadProject,
createResource
loadProject
}

export default withRouter(
Expand Down