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 settings = async (tournament, params) => {
62 await axios.post(`/api/tournaments/${tournament.id}/settings`, params);
63 toastr.success(i18n.t('tournaments.settingsSuccess'));
65 toastr.error(i18n.t('tournaments.settingsError'));
69 const inviteUrl = 'https://discordapp.com/oauth2/authorize?client_id=951113702839549982&scope=bot';
71 const SettingsDialog = ({
77 className="settings-dialog"
80 size={tournament.discord ? 'lg' : 'md'}
82 <Modal.Header closeButton>
84 {i18n.t('tournaments.settings')}
89 <Col sm={tournament.discord ? 6 : 12}>
90 {Tournament.hasSignup(tournament) ?
91 <div className="d-flex align-items-center justify-content-between mb-3">
92 <span>{i18n.t('tournaments.open')}</span>
94 onChange={({ target: { value } }) => value
95 ? open(tournament) : close(tournament)}
96 value={tournament.accept_applications}
100 <div className="d-flex align-items-center justify-content-between mb-3">
101 <span>{i18n.t('tournaments.locked')}</span>
103 onChange={({ target: { value } }) => value
104 ? lock(tournament) : unlock(tournament)}
105 value={tournament.locked}
108 <div className="d-flex align-items-center justify-content-between mb-3">
109 <span>{i18n.t('tournaments.showNumbers')}</span>
111 onChange={({ target: { value } }) =>
112 settings(tournament, { show_numbers: value })}
113 value={tournament.show_numbers}
116 <div className="d-flex align-items-center justify-content-between">
118 <p>{i18n.t('tournaments.discord')}</p>
119 {!tournament.discord ?
128 {i18n.t('tournaments.inviteBot')}
134 onChange={({ target: { value } }) => setDiscord(tournament, value)}
135 value={tournament.discord}
139 {tournament.discord ?
141 <DiscordForm tournament={tournament} />
147 <Button onClick={onHide} variant="secondary">
148 {i18n.t('button.close')}
153 SettingsDialog.propTypes = {
154 onHide: PropTypes.func,
155 show: PropTypes.bool,
156 tournament: PropTypes.shape({
157 accept_applications: PropTypes.bool,
158 discord: PropTypes.string,
159 locked: PropTypes.bool,
160 show_numbers: PropTypes.bool,
164 export default withTranslation()(SettingsDialog);