]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/rounds/LockButton.js
38411ebb0b1b83d27c13f9927fdb21943fe33b1e
[alttp.git] / resources / js / components / rounds / LockButton.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 LockDialog from './LockDialog';
7 import Icon from '../common/Icon';
8 import { mayLockRound } from '../../helpers/permissions';
9 import { withUser } from '../../helpers/UserContext';
10 import i18n from '../../i18n';
11
12 const LockButton = ({
13         round,
14         tournament,
15         user,
16 }) => {
17         const [showDialog, setShowDialog] = useState(false);
18
19         if (!mayLockRound(user, tournament, round)) {
20                 if (round.locked) {
21                         return <Icon.LOCKED title={i18n.t('rounds.locked')} />;
22                 } else {
23                         return <Icon.UNLOCKED title={i18n.t('rounds.unlocked')} />;
24                 }
25         }
26
27         return <>
28                 <LockDialog
29                         onHide={() => setShowDialog(false)}
30                         round={round}
31                         show={showDialog}
32                         tournament={tournament}
33                 />
34                 <Button
35                         onClick={() => setShowDialog(true)}
36                         size="sm"
37                         title={round.locked ? i18n.t('rounds.locked') : i18n.t('rounds.unlocked') }
38                         variant="outline-secondary"
39                 >
40                         {round.locked ?
41                                 <Icon.LOCKED title="" />
42                         :
43                                 <Icon.UNLOCKED title="" />
44                         }
45                 </Button>
46         </>;
47 };
48
49 LockButton.propTypes = {
50         round: PropTypes.shape({
51                 locked: PropTypes.bool,
52         }),
53         tournament: PropTypes.shape({
54         }),
55         user: PropTypes.shape({
56         }),
57 };
58
59 export default withTranslation()(withUser(LockButton));