1 import axios from 'axios';
2 import { withFormik } from 'formik';
3 import PropTypes from 'prop-types';
4 import React from 'react';
5 import { Button, Col, Form, Modal, Row } from 'react-bootstrap';
6 import { withTranslation } from 'react-i18next';
7 import toastr from 'toastr';
9 import laravelErrorsToFormik from '../../helpers/laravelErrorsToFormik';
10 import i18n from '../../i18n';
11 import yup from '../../schema/yup';
22 <Form noValidate onSubmit={handleSubmit}>
25 <Form.Group as={Col} controlId="round.seed">
26 <Form.Label>{i18n.t('rounds.seed')}</Form.Label>
28 isInvalid={!!(touched.seed && errors.seed)}
31 onChange={handleChange}
32 placeholder="https://alttprpatch.synack.live/patcher.html?patch=https://sahasrahbot.s3.amazonaws.com/patch/DR_XXXXXXXXXXX.bps"
34 value={values.seed || ''}
36 {touched.seed && errors.seed ?
37 <Form.Control.Feedback type="invalid">
39 </Form.Control.Feedback>
46 <Button onClick={onCancel} variant="secondary">
47 {i18n.t('button.cancel')}
50 <Button type="submit" variant="primary">
51 {i18n.t('button.save')}
56 SeedForm.propTypes = {
57 errors: PropTypes.shape({
58 seed: PropTypes.string,
60 handleBlur: PropTypes.func,
61 handleChange: PropTypes.func,
62 handleSubmit: PropTypes.func,
63 onCancel: PropTypes.func,
64 touched: PropTypes.shape({
67 values: PropTypes.shape({
68 seed: PropTypes.string,
72 export default withFormik({
73 displayName: 'SeedForm',
74 enableReinitialize: true,
75 handleSubmit: async (values, actions) => {
76 const { round_id, seed } = values;
77 const { setErrors } = actions;
78 const { onCancel } = actions.props;
80 await axios.post(`/api/rounds/${round_id}/setSeed`, {
83 toastr.success(i18n.t('rounds.setSeedSuccess'));
88 toastr.error(i18n.t('rounds.setSeedError'));
89 if (e.response && e.response.data && e.response.data.errors) {
90 setErrors(laravelErrorsToFormik(e.response.data.errors));
94 mapPropsToValues: ({ round }) => ({
96 seed: round.seed || '',
98 validationSchema: yup.object().shape({
99 seed: yup.string().required().url(),
101 })(withTranslation()(SeedForm));