1 import moment from 'moment';
2 import PropTypes from 'prop-types';
3 import React from 'react';
4 import { ListGroup } from 'react-bootstrap';
5 import { Trans, withTranslation } from 'react-i18next';
7 import Icon from '../common/Icon';
8 import Spoiler from '../common/Spoiler';
9 import { formatTime } from '../../helpers/Result';
10 import i18n from '../../i18n';
12 const getEntryDate = entry => {
13 const dateStr = moment(entry.created_at).fromNow();
15 ? `${entry.user.username} ${dateStr}`
19 const getEntryRoundNumber = entry =>
20 (entry && entry.details && entry.details.round && entry.details.round.number) || '?';
22 const getEntryResultTime = entry => {
23 if (!entry || !entry.details || !entry.details.result) return 'ERROR';
24 const result = entry.details.result;
25 if (result.forfeit) return 'DNF XX';
26 return formatTime(result);
29 const getEntryDescription = entry => {
31 case 'result.report': {
32 const time = getEntryResultTime(entry);
33 return <Trans i18nKey={`protocol.description.${entry.type}`}>
34 <Spoiler>{{time}}</Spoiler>,
41 `protocol.description.${entry.type}`,
44 number: getEntryRoundNumber(entry),
47 case 'tournament.lock':
49 `protocol.description.${entry.type}`,
53 return i18n.t('protocol.description.unknown', entry);
57 const getEntryIcon = entry => {
60 return <Icon.PROTOCOL />;
64 const Item = ({ entry }) =>
65 <ListGroup.Item className="d-flex align-items-center">
66 <div className="pe-3 text-muted">
71 {getEntryDescription(entry)}
74 className="text-muted"
75 title={moment(entry.created_at).format('LLLL')}
83 entry: PropTypes.shape({
84 created_at: PropTypes.string,
92 export default withTranslation()(Item);