import { withFormik } from 'formik';
import PropTypes from 'prop-types';
import React from 'react';
-import { Button, Col, Form, Row } from 'react-bootstrap';
+import { Button, Form } from 'react-bootstrap';
import { withTranslation } from 'react-i18next';
import toastr from 'toastr';
+import DiscordChannelSelect from '../common/DiscordChannelSelect';
import laravelErrorsToFormik from '../../helpers/laravelErrorsToFormik';
import i18n from '../../i18n';
import yup from '../../schema/yup';
handleChange,
handleSubmit,
touched,
+ tournament,
values,
}) =>
<Form noValidate onSubmit={handleSubmit}>
<fieldset>
<legend>{i18n.t('tournaments.discordSettings')}</legend>
+ <Form.Group controlId="tournament.discord_round_category">
+ <Form.Label>
+ {i18n.t('tournaments.discordRoundCategory')}
+ </Form.Label>
+ <DiscordChannelSelect
+ guild={tournament.discord}
+ isInvalid={!!(touched.round_category && errors.round_category)}
+ name="round_category"
+ onBlur={handleBlur}
+ onChange={handleChange}
+ types={[4]}
+ value={values.round_category || ''}
+ />
+ </Form.Group>
<Form.Group controlId="tournament.discord_round_template">
<Form.Label>
{i18n.t('tournaments.discordRoundTemplate')}
DiscordForm.propTypes = {
errors: PropTypes.shape({
+ round_category: PropTypes.string,
round_template: PropTypes.string,
}),
handleBlur: PropTypes.func,
handleChange: PropTypes.func,
handleSubmit: PropTypes.func,
touched: PropTypes.shape({
+ round_category: PropTypes.bool,
round_template: PropTypes.bool,
}),
+ tournament: PropTypes.shape({
+ discord: PropTypes.string,
+ }),
values: PropTypes.shape({
+ round_category: PropTypes.string,
round_template: PropTypes.string,
}),
};
displayName: 'DiscordForm',
enableReinitialize: true,
handleSubmit: async (values, actions) => {
- const { round_template } = values;
+ const { round_category, round_template } = values;
const { setErrors } = actions;
const { tournament } = actions.props;
try {
await axios.post(`/api/tournaments/${tournament.id}/discord-settings`, {
+ round_category,
round_template,
});
toastr.success(i18n.t('tournaments.discordSettingsSuccess'));
}
},
mapPropsToValues: ({ tournament }) => ({
+ round_category: tournament.discord_round_category || '',
round_template: tournament.discord_round_template || '',
}),
validationSchema: yup.object().shape({
+ round_category: yup.string(),
round_template: yup.string(),
}),
})(withTranslation()(DiscordForm));