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