1 import axios from 'axios';
2 import PropTypes from 'prop-types';
3 import React from 'react';
4 import { Button, Modal } from 'react-bootstrap';
5 import { withTranslation } from 'react-i18next';
6 import toastr from 'toastr';
8 import DiscordSelect from '../common/DiscordSelect';
9 import Icon from '../common/Icon';
10 import ToggleSwitch from '../common/ToggleSwitch';
11 import i18n from '../../i18n';
13 const open = async tournament => {
15 await axios.post(`/api/tournaments/${tournament.id}/open`);
16 toastr.success(i18n.t('tournaments.openSuccess'));
18 toastr.error(i18n.t('tournaments.openError'));
22 const close = async tournament => {
24 await axios.post(`/api/tournaments/${tournament.id}/close`);
25 toastr.success(i18n.t('tournaments.closeSuccess'));
27 toastr.error(i18n.t('tournaments.closeError'));
31 const lock = async tournament => {
33 await axios.post(`/api/tournaments/${tournament.id}/lock`);
34 toastr.success(i18n.t('tournaments.lockSuccess'));
36 toastr.error(i18n.t('tournaments.lockError'));
40 const unlock = async tournament => {
42 await axios.post(`/api/tournaments/${tournament.id}/unlock`);
43 toastr.success(i18n.t('tournaments.unlockSuccess'));
45 toastr.error(i18n.t('tournaments.unlockError'));
49 const setDiscord = async (tournament, guild_id) => {
51 await axios.post(`/api/tournaments/${tournament.id}/discord`, { guild_id });
52 toastr.success(i18n.t('tournaments.discordSuccess'));
54 toastr.error(i18n.t('tournaments.discordError'));
58 const SettingsDialog = ({
63 <Modal className="settings-dialog" onHide={onHide} show={show}>
64 <Modal.Header closeButton>
66 {i18n.t('tournaments.settings')}
70 <div className="d-flex align-items-center justify-content-between mb-3">
71 <span>{i18n.t('tournaments.open')}</span>
73 onChange={({ target: { value } }) => value ? open(tournament) : close(tournament)}
74 value={tournament.accept_applications}
77 <div className="d-flex align-items-center justify-content-between mb-3">
78 <span>{i18n.t('tournaments.locked')}</span>
80 onChange={({ target: { value } }) => value ? lock(tournament) : unlock(tournament)}
81 value={tournament.locked}
84 <div className="d-flex align-items-center justify-content-between">
86 <p>{i18n.t('tournaments.discord')}</p>
89 href="https://discordapp.com/oauth2/authorize?client_id=951113702839549982&scope=bot"
95 {i18n.t('tournaments.inviteBot')}
100 onChange={({ target: { value } }) => setDiscord(tournament, value)}
101 value={tournament.discord}
106 <Button onClick={onHide} variant="secondary">
107 {i18n.t('button.close')}
112 SettingsDialog.propTypes = {
113 onHide: PropTypes.func,
114 show: PropTypes.bool,
115 tournament: PropTypes.shape({
116 accept_applications: PropTypes.bool,
117 discord: PropTypes.string,
118 locked: PropTypes.bool,
122 export default withTranslation()(SettingsDialog);