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 { getUserName } from '../../helpers/User';
11 import i18n from '../../i18n';
13 const getEntryDate = entry => {
14 const dateStr = moment(entry.created_at).fromNow();
16 ? `${entry.user.username} ${dateStr}`
20 const getEntryDetailsUsername = entry => {
21 if (!entry || !entry.details || !entry.details.user) return 'Anonymous';
22 return getUserName(entry.details.user);
25 const getEntryRoundNumber = entry =>
26 (entry && entry.details && entry.details.round && entry.details.round.number) || '?';
28 const getEntryResultComment = entry => {
29 if (!entry || !entry.details || !entry.details.result || !entry.details.result.comment) {
32 return entry.details.result.comment;
35 const getEntryResultTime = entry => {
36 if (!entry || !entry.details || !entry.details.result) return 'ERROR';
37 const result = entry.details.result;
38 if (result.forfeit) return 'DNF XX';
39 return formatTime(result);
42 const getEntryDescription = entry => {
44 case 'application.accepted':
45 case 'application.received':
46 case 'application.rejected':
48 `protocol.description.${entry.type}`,
51 username: getEntryDetailsUsername(entry),
54 case 'result.comment': {
55 const comment = getEntryResultComment(entry);
56 const number = getEntryRoundNumber(entry);
57 return <Trans i18nKey={`protocol.description.${entry.type}`}>
59 <Spoiler>{{comment}}</Spoiler>,
62 case 'result.report': {
63 const number = getEntryRoundNumber(entry);
64 const time = getEntryResultTime(entry);
65 return <Trans i18nKey={`protocol.description.${entry.type}`}>
67 <Spoiler>{{time}}</Spoiler>,
75 `protocol.description.${entry.type}`,
78 number: getEntryRoundNumber(entry),
81 case 'tournament.close':
82 case 'tournament.discord':
83 case 'tournament.lock':
84 case 'tournament.open':
85 case 'tournament.unlock':
87 `protocol.description.${entry.type}`,
91 return i18n.t('protocol.description.unknown', entry);
95 const getEntryIcon = entry => {
98 return <Icon.RESULT />;
102 case 'tournament.close':
103 case 'tournament.lock':
104 return <Icon.LOCKED />;
106 case 'tournament.open':
107 case 'tournament.unlock':
108 return <Icon.UNLOCKED />;
109 case 'tournament.discord':
110 return <Icon.DISCORD />;
112 return <Icon.PROTOCOL />;
116 const Item = ({ entry }) =>
117 <ListGroup.Item className="d-flex align-items-center">
118 <div className="pe-3 text-muted">
119 {getEntryIcon(entry)}
123 {getEntryDescription(entry)}
126 className="text-muted"
127 title={moment(entry.created_at).format('LLLL')}
129 {getEntryDate(entry)}
135 entry: PropTypes.shape({
136 created_at: PropTypes.string,
140 Item.defaultProps = {
144 export default withTranslation()(Item);