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,
</Modal.Footer>
</Form>;
-ReportForm.propTypes = {
+SeedForm.propTypes = {
errors: PropTypes.shape({
seed: PropTypes.string,
}),
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 }) => ({
validationSchema: yup.object().shape({
seed: yup.string().required().url(),
}),
-})(withTranslation()(ReportForm));
+})(withTranslation()(SeedForm));