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 ToggleSwitch from '../common/ToggleSwitch';
9 import i18n from '../../i18n';
11 const open = async tournament => {
13 await axios.post(`/api/tournaments/${tournament.id}/open`);
14 toastr.success(i18n.t('tournaments.openSuccess'));
16 toastr.error(i18n.t('tournaments.openError'));
20 const close = async tournament => {
22 await axios.post(`/api/tournaments/${tournament.id}/close`);
23 toastr.success(i18n.t('tournaments.closeSuccess'));
25 toastr.error(i18n.t('tournaments.closeError'));
29 const lock = async tournament => {
31 await axios.post(`/api/tournaments/${tournament.id}/lock`);
32 toastr.success(i18n.t('tournaments.lockSuccess'));
34 toastr.error(i18n.t('tournaments.lockError'));
38 const unlock = async tournament => {
40 await axios.post(`/api/tournaments/${tournament.id}/unlock`);
41 toastr.success(i18n.t('tournaments.unlockSuccess'));
43 toastr.error(i18n.t('tournaments.unlockError'));
47 const SettingsDialog = ({
52 <Modal className="settings-dialog" onHide={onHide} show={show}>
53 <Modal.Header closeButton>
55 {i18n.t('tournaments.settings')}
59 <div className="d-flex align-items-center justify-content-between mb-3">
60 <span>{i18n.t('tournaments.open')}</span>
62 onChange={({ target: { value } }) => value ? open(tournament) : close(tournament)}
63 value={tournament.accept_applications}
66 <div className="d-flex align-items-center justify-content-between">
67 <span>{i18n.t('tournaments.locked')}</span>
69 onChange={({ target: { value } }) => value ? lock(tournament) : unlock(tournament)}
70 value={tournament.locked}
75 <Button onClick={onHide} variant="secondary">
76 {i18n.t('button.close')}
81 SettingsDialog.propTypes = {
82 onHide: PropTypes.func,
84 tournament: PropTypes.shape({
85 accept_applications: PropTypes.bool,
86 locked: PropTypes.bool,
90 export default withTranslation()(SettingsDialog);