1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { withTranslation } from 'react-i18next';
5 import Icon from '../common/Icon';
6 import Box from '../users/Box';
7 import { formatTime } from '../../helpers/Result';
8 import { findResult } from '../../helpers/Participant';
9 import { maySeeResults } from '../../helpers/permissions';
10 import { withUser } from '../../helpers/UserContext';
12 const getIcon = (result, index) => {
13 if (!result || !result.has_finished) {
14 return <Icon.PENDING className="text-muted" size="lg" />;
17 return <Icon.FORFEIT className="text-danger" size="lg" />;
20 return <Icon.FIRST_PLACE className="text-gold" size="lg" />;
23 return <Icon.SECOND_PLACE className="text-silver" size="lg" />;
26 return <Icon.THIRD_PLACE className="text-bronze" size="lg" />;
28 return <Icon.FINISHED className="text-success" size="lg" />;
31 const getTime = (user, tournament, round, result) => {
32 if (!result || !maySeeResults(user, tournament, round)) {
36 return formatTime(result);
51 const result = findResult(participant, round);
52 return <div className="result">
53 <Box user={participant.user} />
54 <div className="status">
55 <span className="time">
56 {getTime(user, tournament, round, result)}
58 {getIcon(result, index)}
64 index: PropTypes.number,
65 participant: PropTypes.shape({
66 user: PropTypes.shape({
69 round: PropTypes.shape({
71 tournament: PropTypes.shape({
73 user: PropTypes.shape({
77 export default withTranslation()(withUser(Item));