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
35 changes: 15 additions & 20 deletions src/components/ChallengeEditor/ChallengeReviewer-Field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import cn from 'classnames'
import { PrimaryButton, OutlineButton } from '../../Buttons'
import { REVIEW_OPPORTUNITY_TYPE_LABELS, REVIEW_OPPORTUNITY_TYPES, VALIDATION_VALUE_TYPE, MARATHON_TYPE_ID, DES_TRACK_ID, CHALLENGE_PRIZE_TYPE } from '../../../config/constants'
import { REVIEW_OPPORTUNITY_TYPE_LABELS, REVIEW_OPPORTUNITY_TYPES, VALIDATION_VALUE_TYPE, MARATHON_TYPE_ID, DES_TRACK_ID } from '../../../config/constants'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The import of CHALLENGE_PRIZE_TYPE has been removed, but it is still used in the code. Ensure that this constant is either re-imported or that its usage is removed or replaced.

import { loadScorecards, loadDefaultReviewers, loadWorkflows, replaceResourceInRole, createResource, deleteResource } from '../../../actions/challenges'
import styles from './ChallengeReviewer-Field.module.scss'
import { validateValue } from '../../../util/input-check'
import AssignedMemberField from '../AssignedMember-Field'
import { getResourceRoleByName } from '../../../util/tc'
import { isEqual } from 'lodash'
import { getPrizeType } from '../../../util/prize'

const ResourceToPhaseNameMap = {
Reviewer: 'Review',
Expand Down Expand Up @@ -960,8 +959,7 @@ class ChallengeReviewerField extends Component {
}

getFirstPlacePrizeValue (challenge) {
const prizeSets = challenge.prizeSets || []
const placementPrizeSet = prizeSets.find(set => set.type === 'PLACEMENT')
const placementPrizeSet = challenge.prizeSets.find(set => set.type === 'PLACEMENT')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The change assumes challenge.prizeSets is always defined, which may not be the case. Consider adding a check to ensure challenge.prizeSets is defined before calling .find() to avoid potential runtime errors.

if (placementPrizeSet && placementPrizeSet.prizes && placementPrizeSet.prizes[0] && placementPrizeSet.prizes[0].value) {
return placementPrizeSet.prizes[0].value
}
Expand All @@ -973,23 +971,20 @@ class ChallengeReviewerField extends Component {
const { error } = this.state
const { scorecards = [], defaultReviewers = [], workflows = [] } = metadata
const reviewers = challenge.reviewers || []
const prizeType = getPrizeType(challenge.prizeSets)
const firstPlacePrize = prizeType === CHALLENGE_PRIZE_TYPE.POINT ? 0 : this.getFirstPlacePrizeValue(challenge)
const firstPlacePrize = this.getFirstPlacePrizeValue(challenge)
const estimatedSubmissionsCount = 2 // Estimate assumes two submissions
const reviewersCost = prizeType === CHALLENGE_PRIZE_TYPE.POINT
? '0.00'
: reviewers
.filter((r) => !this.isAIReviewer(r))
.reduce((sum, r) => {
const fixedAmount = parseFloat(r.fixedAmount || 0)
const baseCoefficient = parseFloat(r.baseCoefficient || 0)
const incrementalCoefficient = parseFloat(r.incrementalCoefficient || 0)
const reviewerCost = fixedAmount + (baseCoefficient + incrementalCoefficient * estimatedSubmissionsCount) * firstPlacePrize

const count = parseInt(r.memberReviewerCount) || 1
return sum + reviewerCost * count
}, 0)
.toFixed(2)
const reviewersCost = reviewers
.filter((r) => !this.isAIReviewer(r))
.reduce((sum, r) => {
const fixedAmount = parseFloat(r.fixedAmount || 0)
const baseCoefficient = parseFloat(r.baseCoefficient || 0)
const incrementalCoefficient = parseFloat(r.incrementalCoefficient || 0)
const reviewerCost = fixedAmount + (baseCoefficient + incrementalCoefficient * estimatedSubmissionsCount) * firstPlacePrize

const count = parseInt(r.memberReviewerCount) || 1
return sum + reviewerCost * count
}, 0)
.toFixed(2)

if (isLoading) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
border-right-width: 0;
}

.pointsLabel {
@include roboto-medium;
color: $tc-black;
}

.checkpointSelect {
max-width: 85px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const CheckpointPrizesField = ({ challenge, onUpdateOthers, readOnly }) => {
const checkpointPrize = prizeSets.find(p => p.type === type) || { type: PRIZE_SETS_TYPE.CHECKPOINT_PRIZES, prizes: [], 'description': 'Checkpoint Prizes' }
const number = _.get(checkpointPrize, 'prizes.length') || DEFAULT_CHECKPOINT_PRIZE_COUNT
const amount = _.get(checkpointPrize, 'prizes.length') ? checkpointPrize.prizes[0].value : DEFAULT_CHECKPOINT_PRIZE
const prizeType = getPrizeType(prizeSets)
const prizeType = _.get(checkpointPrize, 'prizes[0].type') || getPrizeType(prizeSets)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The use of _.get(checkpointPrize, 'prizes[0].type') assumes that prizes is an array and that prizes[0] exists. Consider adding a check to ensure prizes is an array and has at least one element to avoid potential runtime errors.


// update the check point prize with default values if it's not already defined
if (_.get(checkpointPrize, 'prizes.length') === 0) {
Expand Down Expand Up @@ -54,7 +54,9 @@ const CheckpointPrizesField = ({ challenge, onUpdateOthers, readOnly }) => {
<div>
<div className={styles.checkpointPrizeInputContainer}>
<div className={styles.checkpointPrizeAmountContainer}>
<FontAwesomeIcon className={styles.dollarIcon} icon={faDollarSign} />
{prizeType === CHALLENGE_PRIZE_TYPE.POINT
? <span className={styles.pointsLabel}>Pts</span>
: <FontAwesomeIcon className={styles.dollarIcon} icon={faDollarSign} />}
</div>
<input id='checkpointPrize' name='checkpointPrize' type='text' placeholder='' value={amount} maxLength='7' required onChange={(e) => onChange(number, e.target.value)} />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
The input element uses type='text' for a field that appears to represent a numeric value (amount). Consider using type='number' to leverage built-in browser validation and improve user experience.

</div>
Expand Down
Loading