From ce6fa305ff41e910771736274bbd6a34c9f26967 Mon Sep 17 00:00:00 2001 From: doctorhilarius Date: Fri, 28 Jan 2022 15:35:03 -0800 Subject: [PATCH] unassign copilot --- .../ChallengeEditor/ChallengeView/index.js | 8 +++-- .../ChallengeViewTabs/index.js | 1 + .../Copilot-Field/Copilot-Field.module.scss | 1 + .../ChallengeEditor/Copilot-Field/index.js | 30 ++++++++++++------- src/components/ChallengeEditor/index.js | 5 ++-- src/containers/ChallengeEditor/index.js | 24 ++++++++------- 6 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/components/ChallengeEditor/ChallengeView/index.js b/src/components/ChallengeEditor/ChallengeView/index.js index 9138aed8..aa7141b3 100644 --- a/src/components/ChallengeEditor/ChallengeView/index.js +++ b/src/components/ChallengeEditor/ChallengeView/index.js @@ -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 }) @@ -136,7 +137,7 @@ const ChallengeView = ({ + }} copilots={challengeResources} assignYourselfCopilot={assignYourselfCopilot} showRejectChallengeModal={showRejectChallengeModal} readOnly loggedInUser={loggedInUser} />
)} {selectedTab === 1 && ( diff --git a/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss b/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss index d50a3f10..c288cf00 100644 --- a/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss +++ b/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss @@ -44,6 +44,7 @@ display: flex; flex-direction: row; flex-wrap: wrap; + width: 100%; div { margin-right: 13px; diff --git a/src/components/ChallengeEditor/Copilot-Field/index.js b/src/components/ChallengeEditor/Copilot-Field/index.js index 27708d71..9e6392c8 100644 --- a/src/components/ChallengeEditor/Copilot-Field/index.js +++ b/src/components/ChallengeEditor/Copilot-Field/index.js @@ -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 ( @@ -22,11 +27,13 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly, assignYou
{(selectedCopilot || selfService) && (
{(selectedCopilot && )} - {(selfService && !selectedCopilot && )} + {((selfService && showAssignButton) &&
+ +
)}
)}
) @@ -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 diff --git a/src/components/ChallengeEditor/index.js b/src/components/ChallengeEditor/index.js index 9ade3ca7..1f0b67ba 100644 --- a/src/components/ChallengeEditor/index.js +++ b/src/components/ChallengeEditor/index.js @@ -1235,7 +1235,8 @@ class ChallengeEditor extends Component { projectPhases, challengeId, assignYourselfCopilot, - challengeResources + challengeResources, + loggedInUser } = this.props if (_.isEmpty(challenge)) { return
Error loading challenge
@@ -1517,7 +1518,7 @@ class ChallengeEditor extends Component { /> )} {projectDetail.version === 'v4' && } - +