Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
display: flex;
align-items: center;
}

&.col2.error {
color: $tc-red;
margin-top: -25px;
}

&.col2 {
align-self: flex-end;
Expand Down
35 changes: 24 additions & 11 deletions src/components/ChallengeEditor/Copilot-Field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ 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 })
const copilotFee = _.find(challenge.prizeSets, p => p.type === 'copilot', [])
console.log(copilotFee)
if (readOnly) {
const selectedCopilot = _.find(copilots, { handle: challenge.copilot })
return (
<div className={styles.row}>
<div className={cn(styles.field, styles.col1)}>
Expand All @@ -20,17 +23,27 @@ const CopilotField = ({ copilots, challenge, onUpdateOthers, readOnly }) => {
)
}
return (
<div className={styles.row}>
<div className={cn(styles.field, styles.col1)}>
<label htmlFor='copilot'>Copilot :</label>
</div>
<div className={cn(styles.field, styles.col2)}>
{
_.map(copilots, copilot => (
<CopilotCard copilot={copilot} selectedCopilot={challenge.copilot} key={copilot.handle} onUpdateOthers={onUpdateOthers} />))
}
<>
<div className={styles.row}>
<div className={cn(styles.field, styles.col1)}>
<label htmlFor='copilot'>Copilot :</label>
</div>
<div className={cn(styles.field, styles.col2)}>
{
_.map(copilots, copilot => (
<CopilotCard copilot={copilot} selectedCopilot={challenge.copilot} key={copilot.handle} onUpdateOthers={onUpdateOthers} />))
}
</div>
</div>
</div>
{!readOnly && challenge.submitTriggered && parseInt(copilotFee.prizes[0].value) > 0 && !selectedCopilot && (
<div className={styles.row}>
<div className={cn(styles.field, styles.col1)} />
<div className={cn(styles.field, styles.col2, styles.error)}>
{errMessage}
</div>
</div>
)}
</>
)
}

Expand Down
20 changes: 18 additions & 2 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -723,6 +731,10 @@ class ChallengeEditor extends Component {
return false
}

if (!this.checkValidCopilot()) {
return false
}

const requiredFields = [
'trackId',
'typeId',
Expand Down Expand Up @@ -1376,11 +1388,15 @@ class ChallengeEditor extends Component {
<OutlineButton text={isSaving ? 'Saving...' : 'Save'} type={'success'} onClick={this.onSaveChallenge} />
</div> */}
<div className={styles.button}>
<PrimaryButton text={isSaving ? 'Saving...' : 'Save Draft'} type={'info'} onClick={this.createDraftHandler} />
{ !this.state.hasValidationErrors ? (
<PrimaryButton text={isSaving ? 'Saving...' : 'Save Draft'} type={'info'} onClick={this.createDraftHandler} />
) : (
<PrimaryButton text={'Save Draft'} type={'disabled'} />
)}
</div>
{isDraft && (
<div className={styles.button}>
{challenge.legacyId || isTask ? (
{(challenge.legacyId || isTask) && !this.state.hasValidationErrors ? (
<PrimaryButton text={'Launch as Active'} type={'info'} onClick={this.toggleLaunch} />
) : (
<Tooltip content={MESSAGE.NO_LEGACY_CHALLENGE}>
Expand Down