Skip to content

Commit 5cebacd

Browse files
committed
update disable logic based on copilot prize
1 parent 18f1aed commit 5cebacd

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/components/ChallengeEditor/Copilot-Field/Copilot-Field.module.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
white-space: nowrap;
3131
display: flex;
3232
align-items: center;
33-
span {
34-
color: $tc-red;
35-
}
3633
}
3734

3835
&.col2.error {

src/components/ChallengeEditor/Copilot-Field/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import CopilotCard from '../../CopilotCard'
88
const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => {
99
let errMessage = 'Please set a copilot'
1010
const selectedCopilot = _.find(copilots, { handle: challenge.copilot })
11+
const copilotFee = _.find(challenge.prizeSets, p => p.type === 'copilot', [])
12+
console.log(copilotFee)
1113
if (readOnly) {
1214
return (
1315
<div className={styles.row}>
@@ -24,7 +26,7 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => {
2426
<>
2527
<div className={styles.row}>
2628
<div className={cn(styles.field, styles.col1)}>
27-
<label htmlFor='copilot'>Copilot {!readOnly && (<span>*</span>)} :</label>
29+
<label htmlFor='copilot'>Copilot :</label>
2830
</div>
2931
<div className={cn(styles.field, styles.col2)}>
3032
{
@@ -33,7 +35,7 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => {
3335
}
3436
</div>
3537
</div>
36-
{!readOnly && challenge.submitTriggered && !selectedCopilot && (
38+
{!readOnly && challenge.submitTriggered && parseInt(copilotFee.prizes[0].value) > 0 && !selectedCopilot && (
3739
<div className={styles.row}>
3840
<div className={cn(styles.field, styles.col1)} />
3941
<div className={cn(styles.field, styles.col2, styles.error)}>

src/components/ChallengeEditor/index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,14 @@ class ChallengeEditor extends Component {
706706
})
707707
}
708708

709+
checkValidCopilot () {
710+
const copilotFee = _.find(this.state.challenge.prizeSets, p => p.type === PRIZE_SETS_TYPE.COPILOT_PAYMENT, [])
711+
if (copilotFee && parseInt(copilotFee.prizes[0].value) > 0 && !this.state.challenge.copilot) {
712+
return false
713+
}
714+
return true
715+
}
716+
709717
isValidChallenge () {
710718
const { challenge } = this.state
711719
if (this.props.isNew) {
@@ -723,11 +731,14 @@ class ChallengeEditor extends Component {
723731
return false
724732
}
725733

734+
if (!this.checkValidCopilot()) {
735+
return false
736+
}
737+
726738
const requiredFields = [
727739
'trackId',
728740
'typeId',
729741
'name',
730-
'copilot',
731742
'description',
732743
'tags',
733744
'prizeSets'
@@ -1377,11 +1388,15 @@ class ChallengeEditor extends Component {
13771388
<OutlineButton text={isSaving ? 'Saving...' : 'Save'} type={'success'} onClick={this.onSaveChallenge} />
13781389
</div> */}
13791390
<div className={styles.button}>
1380-
<PrimaryButton text={isSaving ? 'Saving...' : 'Save Draft'} type={'info'} onClick={this.createDraftHandler} />
1391+
{ !this.state.hasValidationErrors ? (
1392+
<PrimaryButton text={isSaving ? 'Saving...' : 'Save Draft'} type={'info'} onClick={this.createDraftHandler} />
1393+
) : (
1394+
<PrimaryButton text={'Save Draft'} type={'disabled'} />
1395+
)}
13811396
</div>
13821397
{isDraft && (
13831398
<div className={styles.button}>
1384-
{challenge.legacyId || isTask ? (
1399+
{(challenge.legacyId || isTask) && !this.state.hasValidationErrors ? (
13851400
<PrimaryButton text={'Launch as Active'} type={'info'} onClick={this.toggleLaunch} />
13861401
) : (
13871402
<Tooltip content={MESSAGE.NO_LEGACY_CHALLENGE}>

0 commit comments

Comments
 (0)