]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/rounds/SeedForm.js
tracker items as svg
[alttp.git] / resources / js / components / rounds / SeedForm.js
index e21da2e4c364ffa6fb1ed41286f87fbc1696e12a..3cff560e93760b0898c784475c254b1fa7d2d236 100644 (file)
@@ -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 = ({
        </Modal.Footer>
 </Form>;
 
-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));