]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/applications/Item.js
svg dungeon tracker
[alttp.git] / resources / js / components / applications / Item.js
1 import axios from 'axios';
2 import PropTypes from 'prop-types';
3 import React from 'react';
4 import { Button, ListGroup } from 'react-bootstrap';
5 import { withTranslation } from 'react-i18next';
6 import toastr from 'toastr';
7
8 import Icon from '../common/Icon';
9 import Box from '../users/Box';
10 import i18n from '../../i18n';
11
12 const accept = async (tournament, application) => {
13         try {
14                 await axios.post(`/api/application/${application.id}/accept`);
15                 toastr.success(i18n.t('applications.acceptSuccess'));
16         } catch (e) {
17                 toastr.error(i18n.t('applications.acceptError'));
18         }
19 };
20
21 const reject = async (tournament, application) => {
22         try {
23                 await axios.post(`/api/application/${application.id}/reject`);
24                 toastr.success(i18n.t('applications.rejectSuccess'));
25         } catch (e) {
26                 toastr.error(i18n.t('applications.rejectError'));
27         }
28 };
29
30 const Item = ({ application, tournament }) =>
31 <ListGroup.Item className="d-flex justify-content-between align-items-center">
32         <Box discriminator user={application.user} />
33         <div className="button-bar">
34                 <Button
35                         onClick={() => accept(tournament, application)}
36                         title={i18n.t('applications.accept')}
37                         variant="success"
38                 >
39                         <Icon.ACCEPT title="" />
40                 </Button>
41                 <Button
42                         onClick={() => reject(tournament, application)}
43                         title={i18n.t('applications.reject')}
44                         variant="danger"
45                 >
46                         <Icon.REJECT title="" />
47                 </Button>
48         </div>
49 </ListGroup.Item>;
50
51 Item.propTypes = {
52         application: PropTypes.shape({
53                 user: PropTypes.shape({
54                 }),
55         }),
56         tournament: PropTypes.shape({
57         }),
58 };
59
60 export default withTranslation()(Item);