1 import axios from 'axios';
2 import { withFormik } from 'formik';
3 import PropTypes from 'prop-types';
4 import React from 'react';
5 import { Button, Col, Form, Row } from 'react-bootstrap';
6 import { withTranslation } from 'react-i18next';
7 import toastr from 'toastr';
9 import laravelErrorsToFormik from '../../helpers/laravelErrorsToFormik';
10 import i18n from '../../i18n';
11 import yup from '../../schema/yup';
13 const DiscordForm = ({
21 <Form noValidate onSubmit={handleSubmit}>
23 <legend>{i18n.t('tournaments.discordSettings')}</legend>
24 <Form.Group controlId="tournament.discord_round_template">
26 {i18n.t('tournaments.discordRoundTemplate')}
29 isInvalid={!!(touched.round_template && errors.round_template)}
32 onChange={handleChange}
34 value={values.round_template || ''}
37 <Button className="mt-3" type="submit" variant="primary">
38 {i18n.t('button.save')}
43 DiscordForm.propTypes = {
44 errors: PropTypes.shape({
45 round_template: PropTypes.string,
47 handleBlur: PropTypes.func,
48 handleChange: PropTypes.func,
49 handleSubmit: PropTypes.func,
50 touched: PropTypes.shape({
51 round_template: PropTypes.bool,
53 values: PropTypes.shape({
54 round_template: PropTypes.string,
58 export default withFormik({
59 displayName: 'DiscordForm',
60 enableReinitialize: true,
61 handleSubmit: async (values, actions) => {
62 const { round_template } = values;
63 const { setErrors } = actions;
64 const { tournament } = actions.props;
66 await axios.post(`/api/tournaments/${tournament.id}/discord-settings`, {
69 toastr.success(i18n.t('tournaments.discordSettingsSuccess'));
71 toastr.error(i18n.t('tournaments.discordSettingsError'));
72 if (e.response && e.response.data && e.response.data.errors) {
73 setErrors(laravelErrorsToFormik(e.response.data.errors));
77 mapPropsToValues: ({ tournament }) => ({
78 round_template: tournament.discord_round_template || '',
80 validationSchema: yup.object().shape({
81 round_template: yup.string(),
83 })(withTranslation()(DiscordForm));