X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Frounds%2FSeedForm.js;h=3cff560e93760b0898c784475c254b1fa7d2d236;hb=b5a50d74cf042fa7fc874d8184dc37ae20bb74dd;hp=e21da2e4c364ffa6fb1ed41286f87fbc1696e12a;hpb=a907ef7c6676fef11f42933b2d79bdd496b20122;p=alttp.git diff --git a/resources/js/components/rounds/SeedForm.js b/resources/js/components/rounds/SeedForm.js index e21da2e..3cff560 100644 --- a/resources/js/components/rounds/SeedForm.js +++ b/resources/js/components/rounds/SeedForm.js @@ -4,11 +4,13 @@ import PropTypes from 'prop-types'; import React from 'react'; import { Button, Col, Form, Modal, 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 ReportForm = ({ +const SeedForm = ({ errors, handleBlur, handleChange, @@ -51,7 +53,7 @@ const ReportForm = ({ ; -ReportForm.propTypes = { +SeedForm.propTypes = { errors: PropTypes.shape({ seed: PropTypes.string, }), @@ -72,12 +74,21 @@ export default withFormik({ enableReinitialize: true, handleSubmit: async (values, actions) => { const { round_id, seed } = values; + const { setErrors } = actions; const { onCancel } = actions.props; - await axios.post(`/api/rounds/${round_id}/setSeed`, { - seed, - }); - if (onCancel) { - onCancel(); + try { + await axios.post(`/api/rounds/${round_id}/setSeed`, { + seed, + }); + toastr.success(i18n.t('rounds.setSeedSuccess')); + if (onCancel) { + onCancel(); + } + } catch (e) { + toastr.error(i18n.t('rounds.setSeedError')); + if (e.response && e.response.data && e.response.data.errors) { + setErrors(laravelErrorsToFormik(e.response.data.errors)); + } } }, mapPropsToValues: ({ round }) => ({ @@ -87,4 +98,4 @@ export default withFormik({ validationSchema: yup.object().shape({ seed: yup.string().required().url(), }), -})(withTranslation()(ReportForm)); +})(withTranslation()(SeedForm));