X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftournament%2FDiscordForm.js;fp=resources%2Fjs%2Fcomponents%2Ftournament%2FDiscordForm.js;h=f9eba93e516615f08437c302b3ea5070bb801a8b;hb=f446d5bcf3b87bd9443a060e27e9c0601c96fbb9;hp=0000000000000000000000000000000000000000;hpb=d566d913c251fbb05e6bd314cc51f8b5ca49fe57;p=alttp.git diff --git a/resources/js/components/tournament/DiscordForm.js b/resources/js/components/tournament/DiscordForm.js new file mode 100644 index 0000000..f9eba93 --- /dev/null +++ b/resources/js/components/tournament/DiscordForm.js @@ -0,0 +1,83 @@ +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 { withTranslation } from 'react-i18next'; +import toastr from 'toastr'; + +import laravelErrorsToFormik from '../../helpers/laravelErrorsToFormik'; +import i18n from '../../i18n'; +import yup from '../../schema/yup'; + +const DiscordForm = ({ + errors, + handleBlur, + handleChange, + handleSubmit, + touched, + values, +}) => +
+
+ {i18n.t('tournaments.discordSettings')} + + + {i18n.t('tournaments.discordRoundTemplate')} + + + + +
+
; + +DiscordForm.propTypes = { + errors: PropTypes.shape({ + round_template: PropTypes.string, + }), + handleBlur: PropTypes.func, + handleChange: PropTypes.func, + handleSubmit: PropTypes.func, + touched: PropTypes.shape({ + round_template: PropTypes.bool, + }), + values: PropTypes.shape({ + round_template: PropTypes.string, + }), +}; + +export default withFormik({ + displayName: 'DiscordForm', + enableReinitialize: true, + handleSubmit: async (values, actions) => { + const { round_template } = values; + const { setErrors } = actions; + const { tournament } = actions.props; + try { + await axios.post(`/api/tournaments/${tournament.id}/discord-settings`, { + round_template, + }); + toastr.success(i18n.t('tournaments.discordSettingsSuccess')); + } catch (e) { + toastr.error(i18n.t('tournaments.discordSettingsError')); + if (e.response && e.response.data && e.response.data.errors) { + setErrors(laravelErrorsToFormik(e.response.data.errors)); + } + } + }, + mapPropsToValues: ({ tournament }) => ({ + round_template: tournament.discord_round_template || '', + }), + validationSchema: yup.object().shape({ + round_template: yup.string(), + }), +})(withTranslation()(DiscordForm));