]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/tournament/Detail.js
tournament monitors
[alttp.git] / resources / js / components / tournament / Detail.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Button, Col, Container, Row } from 'react-bootstrap';
4 import { withTranslation } from 'react-i18next';
5
6 import Scoreboard from './Scoreboard';
7 import Protocol from '../protocol/Protocol';
8 import Rounds from '../rounds/List';
9 import Box from '../users/Box';
10 import {
11         isRunner,
12         mayAddRounds,
13         mayViewProtocol,
14 } from '../../helpers/permissions';
15 import {
16         getTournamentAdmins,
17         getTournamentMonitors,
18         hasRunners,
19         hasTournamentAdmins,
20         hasTournamentMonitors,
21 } from '../../helpers/Tournament';
22 import { withUser } from '../../helpers/UserContext';
23 import i18n from '../../i18n';
24
25 const getClassName = (tournament, user) => {
26         const classNames = ['tournament'];
27         if (tournament.locked) {
28                 classNames.push('is-locked');
29         } else {
30                 classNames.push('is-active');
31         }
32         if (isRunner(user, tournament)) {
33                 classNames.push('is-runner');
34         }
35         return classNames.join(' ');
36 };
37
38 const Detail = ({
39         addRound,
40         tournament,
41         user,
42 }) => <Container className={getClassName(tournament, user)} fluid>
43         <Row>
44                 <Col lg={8} xl={9}>
45                         <div className="d-flex align-items-center justify-content-between">
46                                 <h1>{tournament.title}</h1>
47                                 {mayViewProtocol(user, tournament) ?
48                                         <Protocol id={tournament.id} />
49                                 : null}
50                         </div>
51                 </Col>
52         </Row>
53         <Row>
54                 <Col lg={{ order: 2, span: 4 }} xl={{ order: 2, span: 3 }}>
55                         <div className="d-flex align-items-center justify-content-between">
56                                 <h2>{i18n.t('tournaments.scoreboard')}</h2>
57                         </div>
58                         {hasRunners(tournament) ?
59                                 <Scoreboard tournament={tournament} />
60                         : null}
61                         {hasTournamentAdmins(tournament) ?
62                                 <>
63                                         <div className="d-flex align-items-center justify-content-between">
64                                                 <h2>{i18n.t('tournaments.admins')}</h2>
65                                         </div>
66                                         {getTournamentAdmins(tournament).map(p =>
67                                                 <p key={p.id}><Box user={p.user} /></p>
68                                         )}
69                                 </>
70                         : null}
71                         {hasTournamentMonitors(tournament) ?
72                                 <>
73                                         <div className="d-flex align-items-center justify-content-between">
74                                                 <h2>{i18n.t('tournaments.monitors')}</h2>
75                                         </div>
76                                         {getTournamentMonitors(tournament).map(p =>
77                                                 <p key={p.id}><Box user={p.user} /></p>
78                                         )}
79                                 </>
80                         : null}
81                 </Col>
82                 <Col lg={{ order: 1, span: 8 }} xl={{ order: 1, span: 9 }}>
83                         <div className="d-flex align-items-center justify-content-between">
84                                 <h2>{i18n.t('rounds.heading')}</h2>
85                                 {addRound && mayAddRounds(user, tournament) ?
86                                         <Button onClick={addRound}>
87                                                 {i18n.t('rounds.new')}
88                                         </Button>
89                                 : null}
90                         </div>
91                         {tournament.rounds ?
92                                 <Rounds rounds={tournament.rounds} tournament={tournament} />
93                         : null}
94                 </Col>
95         </Row>
96 </Container>;
97
98 Detail.propTypes = {
99         addRound: PropTypes.func,
100         tournament: PropTypes.shape({
101                 id: PropTypes.number,
102                 participants: PropTypes.arrayOf(PropTypes.shape({
103                 })),
104                 rounds: PropTypes.arrayOf(PropTypes.shape({
105                 })),
106                 title: PropTypes.string,
107         }),
108         user: PropTypes.shape({
109         }),
110 };
111
112 export default withTranslation()(withUser(Detail));