diff --git a/src/components/ChallengeEditor/ChallengePrizes-Field/index.js b/src/components/ChallengeEditor/ChallengePrizes-Field/index.js index 24fb5f83..5897a08b 100644 --- a/src/components/ChallengeEditor/ChallengePrizes-Field/index.js +++ b/src/components/ChallengeEditor/ChallengePrizes-Field/index.js @@ -8,7 +8,12 @@ import PrizeInput from '../../PrizeInput' import styles from './ChallengePrizes-Field.module.scss' import cn from 'classnames' import { PrimaryButton } from '../../Buttons' -import { CHALLENGE_PRIZE_TYPE, VALIDATION_VALUE_TYPE, PRIZE_SETS_TYPE, CHALLENGE_TYPES_WITH_MULTIPLE_PRIZES } from '../../../config/constants' +import { + CHALLENGE_PRIZE_TYPE, + VALIDATION_VALUE_TYPE, + PRIZE_SETS_TYPE, + CHALLENGE_TYPES_WITH_MULTIPLE_PRIZES +} from '../../../config/constants' import { validateValue } from '../../../util/input-check' class ChallengePrizesField extends Component { @@ -26,7 +31,10 @@ class ChallengePrizesField extends Component { addNewPrize () { const challengePrize = this.getChallengePrize() - challengePrize.prizes = [...challengePrize.prizes, { type: CHALLENGE_PRIZE_TYPE.USD, value: 1 }] + challengePrize.prizes = [ + ...challengePrize.prizes, + { type: CHALLENGE_PRIZE_TYPE.USD, value: 1 } + ] this.onUpdateValue(challengePrize) } @@ -38,7 +46,10 @@ class ChallengePrizesField extends Component { onUpdateInput (value, index) { const challengePrize = this.getChallengePrize() - challengePrize.prizes[index].value = validateValue(value, VALIDATION_VALUE_TYPE.INTEGER) + challengePrize.prizes[index].value = validateValue( + value, + VALIDATION_VALUE_TYPE.INTEGER + ) if (parseInt(challengePrize.prizes[index].value) > 1000000) { challengePrize.prizes[index].value = '1000000' } @@ -48,60 +59,102 @@ class ChallengePrizesField extends Component { onUpdateValue (challengePrize) { const type = PRIZE_SETS_TYPE.CHALLENGE_PRIZES const { onUpdateOthers, challenge } = this.props - const existingPrizes = challenge.prizeSets ? challenge.prizeSets.filter(p => p.type !== type) : [] + const existingPrizes = challenge.prizeSets + ? challenge.prizeSets.filter(p => p.type !== type) + : [] - onUpdateOthers({ field: 'prizeSets', value: [...existingPrizes, challengePrize] }) + onUpdateOthers({ + field: 'prizeSets', + value: [...existingPrizes, challengePrize] + }) } getChallengePrize () { const type = PRIZE_SETS_TYPE.CHALLENGE_PRIZES - return (this.props.challenge.prizeSets && this.props.challenge.prizeSets.length && this.props.challenge.prizeSets.find(p => p.type === type)) || { type, prizes: [{ type: CHALLENGE_PRIZE_TYPE.USD, value: 0 }] } + return ( + (this.props.challenge.prizeSets && + this.props.challenge.prizeSets.length && + this.props.challenge.prizeSets.find(p => p.type === type)) || { + type, + prizes: [{ type: CHALLENGE_PRIZE_TYPE.USD, value: 0 }] + } + ) } renderPrizes () { const { currentPrizeIndex } = this.state const { readOnly, challenge } = this.props - const allowMultiplePrizes = _.includes(CHALLENGE_TYPES_WITH_MULTIPLE_PRIZES, challenge.type) - return _.map(this.getChallengePrize().prizes, (prize, index, { length }) => ( -