]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/rounds/SeedButton.js
1d68b6a833ca129caa9b481cf40182b8df488c46
[alttp.git] / resources / js / components / rounds / SeedButton.js
1 import PropTypes from 'prop-types';
2 import React, { useState } from 'react';
3 import { Button } from 'react-bootstrap';
4 import { withTranslation } from 'react-i18next';
5
6 import SeedDialog from './SeedDialog';
7 import { maySetSeed } from '../../helpers/permissions';
8 import { withUser } from '../../helpers/UserContext';
9 import i18n from '../../i18n';
10
11 const SeedButton = ({ round, tournament, user }) => {
12         const [showDialog, setShowDialog] = useState(false);
13
14         if (round.seed) {
15                 return (
16                         <Button href={round.seed} target="_blank" variant="primary">
17                                 {i18n.t('rounds.seed')}
18                         </Button>
19                 );
20         }
21         if (maySetSeed(user, tournament)) {
22                 return <>
23                         <SeedDialog
24                                 onHide={() => setShowDialog(false)}
25                                 round={round}
26                                 show={showDialog}
27                         />
28                         <Button onClick={() => setShowDialog(true)} variant="outline-primary">
29                                 {i18n.t('rounds.setSeed')}
30                         </Button>
31                 </>;
32         }
33         return i18n.t('rounds.noSeed');
34 };
35
36 SeedButton.propTypes = {
37         round: PropTypes.shape({
38                 seed: PropTypes.string,
39         }),
40         tournament: PropTypes.shape({
41         }),
42         user: PropTypes.shape({
43         }),
44 };
45
46 export default withTranslation()(withUser(SeedButton));