1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { useTranslation } from 'react-i18next';
5 import EditButton from './EditButton';
6 import LockButton from './LockButton';
7 import SeedButton from './SeedButton';
8 import SeedCode from './SeedCode';
9 import SeedRolledBy from './SeedRolledBy';
10 import List from '../results/List';
11 import ReportButton from '../results/ReportButton';
12 import { mayEditRound, mayReportResult, isRunner } from '../../helpers/permissions';
13 import { isComplete } from '../../helpers/Round';
14 import { hasFinishedRound } from '../../helpers/User';
15 import { useUser } from '../../hooks/user';
17 const getClassName = (round, tournament, user) => {
18 const classNames = ['round'];
20 classNames.push('is-locked');
22 classNames.push('is-unlocked');
24 if (isComplete(tournament, round)) {
25 classNames.push('is-complete');
27 classNames.push('is-incomplete');
29 if (hasFinishedRound(user, round)) {
30 classNames.push('has-finished');
31 } else if (isRunner(user, tournament)) {
32 classNames.push('has-not-finished');
34 return classNames.join(' ');
41 const { t } = useTranslation();
42 const { user } = useUser();
44 return <li className={getClassName(round, tournament, user)}>
46 <h3>{round.title}</h3>
48 <div className="d-flex">
49 <div className="info">
51 {tournament.show_numbers && round.number ? `#${round.number} ` : ''}
52 {t('rounds.date', { date: new Date(round.created_at) })}
55 {round.code && round.code.length ?
57 <SeedCode code={round.code} game={round.game || 'alttpr'} />
63 tournament={tournament}
66 <SeedRolledBy round={round} />
68 {mayReportResult(user, tournament) ?
69 <p className="report">
72 tournament={tournament}
77 {tournament.type === 'open-async' && round.results && round.results.length ?
78 <p>{t('rounds.numberOfResults', { count: round.results.length })}</p>
80 <div className="button-bar">
81 <LockButton round={round} tournament={tournament} />
82 {mayEditRound(user, tournament, round) ?
83 <EditButton round={round} tournament={tournament} />
87 <List round={round} tournament={tournament} />
93 round: PropTypes.shape({
94 code: PropTypes.arrayOf(PropTypes.string),
95 created_at: PropTypes.string,
96 game: PropTypes.string,
97 locked: PropTypes.bool,
98 number: PropTypes.number,
99 results: PropTypes.arrayOf(PropTypes.shape({
101 seed: PropTypes.string,
102 title: PropTypes.string,
104 tournament: PropTypes.shape({
105 participants: PropTypes.arrayOf(PropTypes.shape({
107 show_numbers: PropTypes.bool,
108 type: PropTypes.string,