]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/rounds/LockButton.js
a7a60fb1ae44ef1026269bb604027e7dc1b7b9c4
[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                 />
33                 <Button
34                         onClick={() => setShowDialog(true)}
35                         size="sm"
36                         title={round.locked ? i18n.t('rounds.locked') : i18n.t('rounds.unlocked') }
37                         variant="outline-secondary"
38                 >
39                         {round.locked ?
40                                 <Icon.LOCKED title="" />
41                         :
42                                 <Icon.UNLOCKED title="" />
43                         }
44                 </Button>
45         </>;
46 };
47
48 LockButton.propTypes = {
49         round: PropTypes.shape({
50                 locked: PropTypes.bool,
51         }),
52         tournament: PropTypes.shape({
53         }),
54         user: PropTypes.shape({
55         }),
56 };
57
58 export default withTranslation()(withUser(LockButton));