1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Badge, Button } from 'react-bootstrap';
4 import { useTranslation } from 'react-i18next';
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';
12 const ApplicationsButton = ({ tournament }) => {
13 const [showDialog, setShowDialog] = React.useState(false);
15 const { t } = useTranslation();
16 const { user } = useUser();
18 if (!user || !tournament.accept_applications || !mayHandleApplications(user, tournament)) {
22 const pending = getPendingApplications(tournament);
26 onClick={() => setShowDialog(true)}
27 title={t('tournaments.applications')}
30 <Icon.APPLICATIONS title="" />
34 <Badge>{pending.length}</Badge>
39 onHide={() => setShowDialog(false)}
41 tournament={tournament}
46 ApplicationsButton.propTypes = {
47 tournament: PropTypes.shape({
48 accept_applications: PropTypes.bool,
53 export default ApplicationsButton;