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 Tournament from '../../helpers/Tournament';
13 import i18n from '../../i18n';
15 const open = async tournament => {
17 await axios.post(`/api/tournaments/${tournament.id}/open`);
18 toastr.success(i18n.t('tournaments.openSuccess'));
20 toastr.error(i18n.t('tournaments.openError'));
24 const close = async tournament => {
26 await axios.post(`/api/tournaments/${tournament.id}/close`);
27 toastr.success(i18n.t('tournaments.closeSuccess'));
29 toastr.error(i18n.t('tournaments.closeError'));
33 const lock = async tournament => {
35 await axios.post(`/api/tournaments/${tournament.id}/lock`);
36 toastr.success(i18n.t('tournaments.lockSuccess'));
38 toastr.error(i18n.t('tournaments.lockError'));
42 const unlock = async tournament => {
44 await axios.post(`/api/tournaments/${tournament.id}/unlock`);
45 toastr.success(i18n.t('tournaments.unlockSuccess'));
47 toastr.error(i18n.t('tournaments.unlockError'));
51 const setDiscord = async (tournament, guild_id) => {
53 await axios.post(`/api/tournaments/${tournament.id}/discord`, { guild_id });
54 toastr.success(i18n.t('tournaments.discordSuccess'));
56 toastr.error(i18n.t('tournaments.discordError'));
60 const inviteUrl = 'https://discordapp.com/oauth2/authorize?client_id=951113702839549982&scope=bot';
62 const SettingsDialog = ({
68 className="settings-dialog"
71 size={tournament.discord ? 'lg' : 'md'}
73 <Modal.Header closeButton>
75 {i18n.t('tournaments.settings')}
80 <Col sm={tournament.discord ? 6 : 12}>
81 {Tournament.hasSignup(tournament) ?
82 <div className="d-flex align-items-center justify-content-between mb-3">
83 <span>{i18n.t('tournaments.open')}</span>
85 onChange={({ target: { value } }) => value
86 ? open(tournament) : close(tournament)}
87 value={tournament.accept_applications}
91 <div className="d-flex align-items-center justify-content-between mb-3">
92 <span>{i18n.t('tournaments.locked')}</span>
94 onChange={({ target: { value } }) => value
95 ? lock(tournament) : unlock(tournament)}
96 value={tournament.locked}
99 <div className="d-flex align-items-center justify-content-between">
101 <p>{i18n.t('tournaments.discord')}</p>
102 {!tournament.discord ?
111 {i18n.t('tournaments.inviteBot')}
117 onChange={({ target: { value } }) => setDiscord(tournament, value)}
118 value={tournament.discord}
122 {tournament.discord ?
124 <DiscordForm tournament={tournament} />
130 <Button onClick={onHide} variant="secondary">
131 {i18n.t('button.close')}
136 SettingsDialog.propTypes = {
137 onHide: PropTypes.func,
138 show: PropTypes.bool,
139 tournament: PropTypes.shape({
140 accept_applications: PropTypes.bool,
141 discord: PropTypes.string,
142 locked: PropTypes.bool,
146 export default withTranslation()(SettingsDialog);