]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/tournament/ApplyButton.js
improved user context
[alttp.git] / resources / js / components / tournament / ApplyButton.js
index bd944c903d53556595b3d3ebb8600f1d74d1aa2b..8bbd98ec12556daf57572178e50781c615896a84 100644 (file)
@@ -6,8 +6,8 @@ import { withTranslation } from 'react-i18next';
 import toastr from 'toastr';
 
 import Icon from '../common/Icon';
-import { isApplicant, isDeniedApplicant, mayApply } from '../../helpers/permissions';
-import { withUser } from '../../helpers/UserContext';
+import { isApplicant, isDeniedApplicant, isRunner, mayApply } from '../../helpers/permissions';
+import { useUser } from '../../hooks/user';
 import i18n from '../../i18n';
 
 const apply = async tournament => {
@@ -29,8 +29,10 @@ const getTitle = (user, tournament) => {
        return i18n.t('tournaments.apply');
 };
 
-const ApplyButton = ({ tournament, user }) => {
-       if (!tournament.accept_applications) return null;
+const ApplyButton = ({ tournament }) => {
+       const { user } = useUser();
+
+       if (!user || !tournament.accept_applications || isRunner(user, tournament)) return null;
 
        return <span className="d-inline-block" title={getTitle(user, tournament)}>
                <Button
@@ -48,8 +50,6 @@ ApplyButton.propTypes = {
                accept_applications: PropTypes.bool,
                id: PropTypes.number,
        }),
-       user: PropTypes.shape({
-       }),
 };
 
-export default withTranslation()(withUser(ApplyButton));
+export default withTranslation()(ApplyButton);