]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/tournament/DiscordForm.js
svg dungeon tracker
[alttp.git] / resources / js / components / tournament / DiscordForm.js
index f9eba93e516615f08437c302b3ea5070bb801a8b..d896504c60bab62d6c0617d68ccc8e34fcdf1c51 100644 (file)
@@ -2,10 +2,11 @@ import axios from 'axios';
 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';
@@ -16,11 +17,26 @@ const DiscordForm = ({
        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')}
@@ -42,15 +58,21 @@ const DiscordForm = ({
 
 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,
        }),
 };
@@ -59,11 +81,12 @@ export default withFormik({
        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'));
@@ -75,9 +98,11 @@ export default withFormik({
                }
        },
        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));