From 18f1aedd337936fab991c2f3d21e61c7dda2d71a Mon Sep 17 00:00:00 2001 From: Vips19 Date: Thu, 17 Jun 2021 01:28:33 +0530 Subject: [PATCH 1/2] fix issue #1176 --- .../Copilot-Field/Copilot-Field.module.scss | 8 +++++ .../ChallengeEditor/Copilot-Field/index.js | 33 ++++++++++++------- src/components/ChallengeEditor/index.js | 1 + 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss b/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss index 1a272eed..0210aef7 100644 --- a/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss +++ b/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss @@ -30,6 +30,14 @@ white-space: nowrap; display: flex; align-items: center; + span { + color: $tc-red; + } + } + + &.col2.error { + color: $tc-red; + margin-top: -25px; } &.col2 { diff --git a/src/components/ChallengeEditor/Copilot-Field/index.js b/src/components/ChallengeEditor/Copilot-Field/index.js index 4d092d22..ba8905d1 100644 --- a/src/components/ChallengeEditor/Copilot-Field/index.js +++ b/src/components/ChallengeEditor/Copilot-Field/index.js @@ -6,8 +6,9 @@ import _ from 'lodash' import CopilotCard from '../../CopilotCard' const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => { + let errMessage = 'Please set a copilot' + const selectedCopilot = _.find(copilots, { handle: challenge.copilot }) if (readOnly) { - const selectedCopilot = _.find(copilots, { handle: challenge.copilot }) return (
@@ -20,17 +21,27 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => { ) } return ( -
-
- -
-
- { - _.map(copilots, copilot => ( - )) - } + <> +
+
+ +
+
+ { + _.map(copilots, copilot => ( + )) + } +
-
+ {!readOnly && challenge.submitTriggered && !selectedCopilot && ( +
+
+
+ {errMessage} +
+
+ )} + ) } diff --git a/src/components/ChallengeEditor/index.js b/src/components/ChallengeEditor/index.js index 2d4bdef7..d8335ceb 100644 --- a/src/components/ChallengeEditor/index.js +++ b/src/components/ChallengeEditor/index.js @@ -727,6 +727,7 @@ class ChallengeEditor extends Component { 'trackId', 'typeId', 'name', + 'copilot', 'description', 'tags', 'prizeSets' From 5cebacd4a85acb3a0898f0db380030c79d8bdd9a Mon Sep 17 00:00:00 2001 From: Vips19 Date: Thu, 17 Jun 2021 02:59:34 +0530 Subject: [PATCH 2/2] update disable logic based on copilot prize --- .../Copilot-Field/Copilot-Field.module.scss | 3 --- .../ChallengeEditor/Copilot-Field/index.js | 6 ++++-- src/components/ChallengeEditor/index.js | 21 ++++++++++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss b/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss index 0210aef7..d50a3f10 100644 --- a/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss +++ b/src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss @@ -30,9 +30,6 @@ white-space: nowrap; display: flex; align-items: center; - span { - color: $tc-red; - } } &.col2.error { diff --git a/src/components/ChallengeEditor/Copilot-Field/index.js b/src/components/ChallengeEditor/Copilot-Field/index.js index ba8905d1..38607cdd 100644 --- a/src/components/ChallengeEditor/Copilot-Field/index.js +++ b/src/components/ChallengeEditor/Copilot-Field/index.js @@ -8,6 +8,8 @@ import CopilotCard from '../../CopilotCard' const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => { let errMessage = 'Please set a copilot' const selectedCopilot = _.find(copilots, { handle: challenge.copilot }) + const copilotFee = _.find(challenge.prizeSets, p => p.type === 'copilot', []) + console.log(copilotFee) if (readOnly) { return (
@@ -24,7 +26,7 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => { <>
- +
{ @@ -33,7 +35,7 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => { }
- {!readOnly && challenge.submitTriggered && !selectedCopilot && ( + {!readOnly && challenge.submitTriggered && parseInt(copilotFee.prizes[0].value) > 0 && !selectedCopilot && (
diff --git a/src/components/ChallengeEditor/index.js b/src/components/ChallengeEditor/index.js index d8335ceb..1892bbf5 100644 --- a/src/components/ChallengeEditor/index.js +++ b/src/components/ChallengeEditor/index.js @@ -706,6 +706,14 @@ class ChallengeEditor extends Component { }) } + checkValidCopilot () { + const copilotFee = _.find(this.state.challenge.prizeSets, p => p.type === PRIZE_SETS_TYPE.COPILOT_PAYMENT, []) + if (copilotFee && parseInt(copilotFee.prizes[0].value) > 0 && !this.state.challenge.copilot) { + return false + } + return true + } + isValidChallenge () { const { challenge } = this.state if (this.props.isNew) { @@ -723,11 +731,14 @@ class ChallengeEditor extends Component { return false } + if (!this.checkValidCopilot()) { + return false + } + const requiredFields = [ 'trackId', 'typeId', 'name', - 'copilot', 'description', 'tags', 'prizeSets' @@ -1377,11 +1388,15 @@ class ChallengeEditor extends Component {
*/}
- + { !this.state.hasValidationErrors ? ( + + ) : ( + + )}
{isDraft && (
- {challenge.legacyId || isTask ? ( + {(challenge.legacyId || isTask) && !this.state.hasValidationErrors ? ( ) : (