+import axios from 'axios';
+import { withFormik } from 'formik';
+import PropTypes from 'prop-types';
+import React from 'react';
+import { Button, Col, Form, Modal, Row } from 'react-bootstrap';
+import { withTranslation } from 'react-i18next';
+
+import i18n from '../../i18n';
+import yup from '../../schema/yup';
+
+const ReportForm = ({
+ errors,
+ handleBlur,
+ handleChange,
+ handleSubmit,
+ onCancel,
+ touched,
+ values,
+}) =>
+<Form noValidate onSubmit={handleSubmit}>
+ <Modal.Body>
+ <Row>
+ <Form.Group as={Col} controlId="round.seed">
+ <Form.Label>{i18n.t('rounds.seed')}</Form.Label>
+ <Form.Control
+ isInvalid={!!(touched.seed && errors.seed)}
+ name="seed"
+ onBlur={handleBlur}
+ onChange={handleChange}
+ placeholder="https://alttprpatch.synack.live/patcher.html?patch=https://sahasrahbot.s3.amazonaws.com/patch/DR_XXXXXXXXXXX.bps"
+ type="text"
+ value={values.seed || ''}
+ />
+ {touched.seed && errors.seed ?
+ <Form.Control.Feedback type="invalid">
+ {i18n.t(errors.seed)}
+ </Form.Control.Feedback>
+ : null}
+ </Form.Group>
+ </Row>
+ </Modal.Body>
+ <Modal.Footer>
+ {onCancel ?
+ <Button onClick={onCancel} variant="secondary">
+ {i18n.t('button.cancel')}
+ </Button>
+ : null}
+ <Button type="submit" variant="primary">
+ {i18n.t('button.save')}
+ </Button>
+ </Modal.Footer>
+</Form>;
+
+ReportForm.propTypes = {
+ errors: PropTypes.shape({
+ seed: PropTypes.string,
+ }),
+ handleBlur: PropTypes.func,
+ handleChange: PropTypes.func,
+ handleSubmit: PropTypes.func,
+ onCancel: PropTypes.func,
+ touched: PropTypes.shape({
+ seed: PropTypes.bool,
+ }),
+ values: PropTypes.shape({
+ seed: PropTypes.string,
+ }),
+};
+
+export default withFormik({
+ displayName: 'SeedForm',
+ enableReinitialize: true,
+ handleSubmit: async (values, actions) => {
+ const { round_id, seed } = values;
+ const { onCancel } = actions.props;
+ await axios.post(`/api/rounds/${round_id}/setSeed`, {
+ seed,
+ });
+ if (onCancel) {
+ onCancel();
+ }
+ },
+ mapPropsToValues: ({ round }) => ({
+ round_id: round.id,
+ seed: round.seed || '',
+ }),
+ validationSchema: yup.object().shape({
+ seed: yup.string().required().url(),
+ }),
+})(withTranslation()(ReportForm));