Skip to content

Commit 43bcc90

Browse files
authored
Merge pull request #1182 from Vips19/feature/fix-issue-1176
fix issue #1176
2 parents 6729ff7 + 5cebacd commit 43bcc90

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
display: flex;
3232
align-items: center;
3333
}
34+
35+
&.col2.error {
36+
color: $tc-red;
37+
margin-top: -25px;
38+
}
3439

3540
&.col2 {
3641
align-self: flex-end;

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import _ from 'lodash'
66
import CopilotCard from '../../CopilotCard'
77

88
const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => {
9+
let errMessage = 'Please set a copilot'
10+
const selectedCopilot = _.find(copilots, { handle: challenge.copilot })
11+
const copilotFee = _.find(challenge.prizeSets, p => p.type === 'copilot', [])
12+
console.log(copilotFee)
913
if (readOnly) {
10-
const selectedCopilot = _.find(copilots, { handle: challenge.copilot })
1114
return (
1215
<div className={styles.row}>
1316
<div className={cn(styles.field, styles.col1)}>
@@ -20,17 +23,27 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => {
2023
)
2124
}
2225
return (
23-
<div className={styles.row}>
24-
<div className={cn(styles.field, styles.col1)}>
25-
<label htmlFor='copilot'>Copilot :</label>
26-
</div>
27-
<div className={cn(styles.field, styles.col2)}>
28-
{
29-
_.map(copilots, copilot => (
30-
<CopilotCard copilot={copilot} selectedCopilot={challenge.copilot} key={copilot.handle} onUpdateOthers={onUpdateOthers} />))
31-
}
26+
<>
27+
<div className={styles.row}>
28+
<div className={cn(styles.field, styles.col1)}>
29+
<label htmlFor='copilot'>Copilot :</label>
30+
</div>
31+
<div className={cn(styles.field, styles.col2)}>
32+
{
33+
_.map(copilots, copilot => (
34+
<CopilotCard copilot={copilot} selectedCopilot={challenge.copilot} key={copilot.handle} onUpdateOthers={onUpdateOthers} />))
35+
}
36+
</div>
3237
</div>
33-
</div>
38+
{!readOnly && challenge.submitTriggered && parseInt(copilotFee.prizes[0].value) > 0 && !selectedCopilot && (
39+
<div className={styles.row}>
40+
<div className={cn(styles.field, styles.col1)} />
41+
<div className={cn(styles.field, styles.col2, styles.error)}>
42+
{errMessage}
43+
</div>
44+
</div>
45+
)}
46+
</>
3447
)
3548
}
3649

src/components/ChallengeEditor/index.js

Lines changed: 18 additions & 2 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,6 +731,10 @@ 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',
@@ -1376,11 +1388,15 @@ class ChallengeEditor extends Component {
13761388
<OutlineButton text={isSaving ? 'Saving...' : 'Save'} type={'success'} onClick={this.onSaveChallenge} />
13771389
</div> */}
13781390
<div className={styles.button}>
1379-
<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+
)}
13801396
</div>
13811397
{isDraft && (
13821398
<div className={styles.button}>
1383-
{challenge.legacyId || isTask ? (
1399+
{(challenge.legacyId || isTask) && !this.state.hasValidationErrors ? (
13841400
<PrimaryButton text={'Launch as Active'} type={'info'} onClick={this.toggleLaunch} />
13851401
) : (
13861402
<Tooltip content={MESSAGE.NO_LEGACY_CHALLENGE}>

0 commit comments

Comments
 (0)