1 import axios from 'axios';
2 import PropTypes from 'prop-types';
3 import React from 'react';
4 import { Button, Col, Modal, Row } from 'react-bootstrap';
5 import { withTranslation } from 'react-i18next';
6 import toastr from 'toastr';
8 import DiscordForm from './DiscordForm';
9 import DiscordSelect from '../common/DiscordSelect';
10 import Icon from '../common/Icon';
11 import ToggleSwitch from '../common/ToggleSwitch';
12 import i18n from '../../i18n';
14 const open = async tournament => {
16 await axios.post(`/api/tournaments/${tournament.id}/open`);
17 toastr.success(i18n.t('tournaments.openSuccess'));
19 toastr.error(i18n.t('tournaments.openError'));
23 const close = async tournament => {
25 await axios.post(`/api/tournaments/${tournament.id}/close`);
26 toastr.success(i18n.t('tournaments.closeSuccess'));
28 toastr.error(i18n.t('tournaments.closeError'));
32 const lock = async tournament => {
34 await axios.post(`/api/tournaments/${tournament.id}/lock`);
35 toastr.success(i18n.t('tournaments.lockSuccess'));
37 toastr.error(i18n.t('tournaments.lockError'));
41 const unlock = async tournament => {
43 await axios.post(`/api/tournaments/${tournament.id}/unlock`);
44 toastr.success(i18n.t('tournaments.unlockSuccess'));
46 toastr.error(i18n.t('tournaments.unlockError'));
50 const setDiscord = async (tournament, guild_id) => {
52 await axios.post(`/api/tournaments/${tournament.id}/discord`, { guild_id });
53 toastr.success(i18n.t('tournaments.discordSuccess'));
55 toastr.error(i18n.t('tournaments.discordError'));
59 const inviteUrl = 'https://discordapp.com/oauth2/authorize?client_id=951113702839549982&scope=bot';
61 const SettingsDialog = ({
67 className="settings-dialog"
70 size={tournament.discord ? 'lg' : 'md'}
72 <Modal.Header closeButton>
74 {i18n.t('tournaments.settings')}
79 <Col sm={tournament.discord ? 6 : 12}>
80 <div className="d-flex align-items-center justify-content-between mb-3">
81 <span>{i18n.t('tournaments.open')}</span>
83 onChange={({ target: { value } }) => value
84 ? open(tournament) : close(tournament)}
85 value={tournament.accept_applications}
88 <div className="d-flex align-items-center justify-content-between mb-3">
89 <span>{i18n.t('tournaments.locked')}</span>
91 onChange={({ target: { value } }) => value
92 ? lock(tournament) : unlock(tournament)}
93 value={tournament.locked}
96 <div className="d-flex align-items-center justify-content-between">
98 <p>{i18n.t('tournaments.discord')}</p>
99 {!tournament.discord ?
108 {i18n.t('tournaments.inviteBot')}
114 onChange={({ target: { value } }) => setDiscord(tournament, value)}
115 value={tournament.discord}
119 {tournament.discord ?
121 <DiscordForm tournament={tournament} />
127 <Button onClick={onHide} variant="secondary">
128 {i18n.t('button.close')}
133 SettingsDialog.propTypes = {
134 onHide: PropTypes.func,
135 show: PropTypes.bool,
136 tournament: PropTypes.shape({
137 accept_applications: PropTypes.bool,
138 discord: PropTypes.string,
139 locked: PropTypes.bool,
143 export default withTranslation()(SettingsDialog);