]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/applications/Button.js
tracker layout
[alttp.git] / resources / js / components / applications / Button.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Badge, Button } from 'react-bootstrap';
4 import { useTranslation } from 'react-i18next';
5
6 import Dialog from './Dialog';
7 import Icon from '../common/Icon';
8 import { mayHandleApplications } from '../../helpers/permissions';
9 import { getPendingApplications } from '../../helpers/Tournament';
10 import { useUser } from '../../hooks/user';
11
12 const ApplicationsButton = ({ tournament }) => {
13         const [showDialog, setShowDialog] = React.useState(false);
14
15         const { t } = useTranslation();
16         const { user } = useUser();
17
18         if (!user || !tournament.accept_applications || !mayHandleApplications(user, tournament)) {
19                 return null;
20         }
21
22         const pending = getPendingApplications(tournament);
23
24         return <>
25                 <Button
26                         onClick={() => setShowDialog(true)}
27                         title={t('tournaments.applications')}
28                         variant="primary"
29                 >
30                         <Icon.APPLICATIONS title="" />
31                         {pending.length ?
32                                 <>
33                                         {' '}
34                                         <Badge>{pending.length}</Badge>
35                                 </>
36                         : null}
37                 </Button>
38                 <Dialog
39                         onHide={() => setShowDialog(false)}
40                         show={showDialog}
41                         tournament={tournament}
42                 />
43         </>;
44 };
45
46 ApplicationsButton.propTypes = {
47         tournament: PropTypes.shape({
48                 accept_applications: PropTypes.bool,
49                 id: PropTypes.number,
50         }),
51 };
52
53 export default ApplicationsButton;