1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Alert, Button, Table } from 'react-bootstrap';
4 import { withTranslation } from 'react-i18next';
5 import { useNavigate } from 'react-router-dom';
7 import Icon from '../common/Icon';
8 import { isRunner } from '../../helpers/Participant';
9 import i18n from '../../i18n';
11 const getIcon = participant => {
12 if (!isRunner(participant)) {
15 if (participant.placement === 1) {
16 return <Icon.FIRST_PLACE className="text-gold" size="lg" />;
18 if (participant.placement === 2) {
19 return <Icon.SECOND_PLACE className="text-silver" size="lg" />;
21 if (participant.placement === 3) {
22 return <Icon.THIRD_PLACE className="text-bronze" size="lg" />;
24 return participant.placement;
27 const Participation = ({ user }) => {
28 const navigate = useNavigate();
30 if (!user || !user.participation || !user.participation.length) {
31 return <Alert variant="info">
32 {i18n.t('users.participationEmpty')}
35 return <Table className="participation align-middle">
38 <th>{i18n.t('participants.tournament')}</th>
39 <th>{i18n.t('participants.placement')}</th>
40 <th>{i18n.t('participants.roles')}</th>
44 {user.participation.map(p => <tr key={p.id}>
47 onClick={() => navigate(`/tournaments/${p.tournament_id}`)}
55 {!p.tournament.locked && isRunner(p) ?
56 <span title={i18n.t('participants.placementSubjectToChange')}> *</span>
60 {p.roles ? p.roles.map((role, index) =>
62 {index === 0 ? '' : ', '}
63 {i18n.t(`participants.roleNames.${role}`)}
72 Participation.propTypes = {
73 user: PropTypes.shape({
74 participation: PropTypes.arrayOf(PropTypes.shape({
80 export default withTranslation()(Participation);