Skip to content

Commit f580ee8

Browse files
authored
Merge pull request #951 from topcoder-platform/MP-390_members-stats-fix
MP-390 - Fix wording & winning icon for member stats -> dev
2 parents fc095a7 + 503a433 commit f580ee8

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

src/apps/profiles/src/components/tc-achievements/MemberStatsBlock/MemberStatsBlock.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getRatingColor, MemberStats, UserProfile } from '~/libs/core'
66
import { IconOutline } from '~/libs/ui'
77

88
import { useFetchActiveTracks } from '../../../hooks'
9-
import { WinnerIcon } from '../../../lib'
9+
import { formatPlural, WinnerIcon } from '../../../lib'
1010
import { MemberProfileContextValue, useMemberProfileContext } from '../../../member-profile/MemberProfile.context'
1111

1212
import styles from './MemberStatsBlock.module.scss'
@@ -45,13 +45,18 @@ const MemberStatsBlock: FC<MemberStatsBlockProps> = props => {
4545
<div className={styles.trackDetails}>
4646
{!track.isDSTrack && ((track.submissions || track.wins) > 0) && (
4747
<>
48-
<WinnerIcon className='icon-xxxl' />
48+
{track.wins > 0 && (
49+
<WinnerIcon className='icon-xxxl' />
50+
)}
4951
<span className={styles.trackStats}>
5052
<span className={styles.count}>
5153
{track.wins || track.submissions}
5254
</span>
5355
<span className={styles.label}>
54-
{track.wins > 0 ? 'Wins' : 'Submissions'}
56+
{formatPlural(
57+
track.wins || track.submissions || 0,
58+
track.wins > 0 ? 'Win' : 'Submission',
59+
)}
5560
</span>
5661
</span>
5762
</>

src/apps/profiles/src/components/tc-achievements/StatsSummaryBlock/StatsSummaryBlock.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { find, get } from 'lodash'
44

55
import { getRatingColor } from '~/libs/core'
66

7-
import { numberToFixed } from '../../../lib'
7+
import { formatPlural, numberToFixed } from '../../../lib'
88
import { TracksSummaryStats } from '../../../config'
99

1010
import styles from './StatsSummaryBlock.module.scss'
@@ -49,7 +49,10 @@ const StatsSummaryBlock: FC<StatsSummaryBlockProps> = props => {
4949
</span>
5050
<span className={styles.summaryItemLabel}>
5151
<span className='body-small'>
52-
{props.trackTitle === 'Single Round Match' ? 'Competitions' : 'Challenges'}
52+
{formatPlural(
53+
props.challenges || 0,
54+
props.trackTitle === 'Single Round Match' ? 'Competition' : 'Challenge',
55+
)}
5356
</span>
5457
</span>
5558
</div>
@@ -61,7 +64,7 @@ const StatsSummaryBlock: FC<StatsSummaryBlockProps> = props => {
6164
</span>
6265
<span className={styles.summaryItemLabel}>
6366
<span className='body-small'>
64-
Wins
67+
{formatPlural(props.wins || 0, 'Win')}
6568
</span>
6669
</span>
6770
</div>
@@ -73,7 +76,7 @@ const StatsSummaryBlock: FC<StatsSummaryBlockProps> = props => {
7376
</span>
7477
<span className={styles.summaryItemLabel}>
7578
<span className='body-small'>
76-
Submissions
79+
{formatPlural(props.submissions || 0, 'Submission')}
7780
</span>
7881
</span>
7982
</div>

src/apps/profiles/src/components/tc-achievements/SubTrackSummaryCard/SubTrackSummaryCard.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import classNames from 'classnames'
33

44
import { IconSolid } from '~/libs/ui'
55

6-
import { subTrackLabelToHumanName, WinnerIcon } from '../../../lib'
6+
import { formatPlural, subTrackLabelToHumanName, WinnerIcon } from '../../../lib'
77

88
import styles from './SubTrackSummaryCard.module.scss'
99

@@ -29,7 +29,9 @@ const SubTrackSummaryCard: FC<SubTrackSummaryCardProps> = props => (
2929
{props.wins}
3030
</span>
3131
<span className={styles.statsItemLabel}>
32-
<span className='label'>wins</span>
32+
<span className='label'>
33+
{formatPlural(props.wins || 0, 'Win')}
34+
</span>
3335
</span>
3436
</div>
3537
)}
@@ -38,7 +40,9 @@ const SubTrackSummaryCard: FC<SubTrackSummaryCardProps> = props => (
3840
{props.submissions}
3941
</span>
4042
<span className={styles.statsItemLabel}>
41-
<span className='label'>submissions</span>
43+
<span className='label'>
44+
{formatPlural(props.submissions || 0, 'Submission')}
45+
</span>
4246
</span>
4347
</div>
4448
</div>

src/apps/profiles/src/lib/helpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,15 @@ export function isValidURL(urlToValidate: string): boolean {
113113

114114
return true
115115
}
116+
117+
/**
118+
* Creates the string with the number of items and the word describing the item
119+
* possibly in plural form.
120+
*
121+
* @param {number} count - The number of entities
122+
* @param {string} baseWord - The base word that describes the entity
123+
* @returns {string}
124+
*/
125+
export function formatPlural(count: number, baseWord: string): string {
126+
return `${baseWord}${count === 1 ? '' : 's'}`
127+
}

0 commit comments

Comments
 (0)