]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/rounds/EditForm.js
basic seed code input
[alttp.git] / resources / js / components / rounds / EditForm.js
index 57ee95a5a6e1298c97d9891617beab9e121ac376..3d0d0b368ad0749008b4153327a5f85c37cc37ed 100644 (file)
@@ -6,6 +6,7 @@ import { Button, Col, Form, Modal, Row } from 'react-bootstrap';
 import { withTranslation } from 'react-i18next';
 import toastr from 'toastr';
 
+import SeedCodeInput from './SeedCodeInput';
 import laravelErrorsToFormik from '../../helpers/laravelErrorsToFormik';
 import i18n from '../../i18n';
 import yup from '../../schema/yup';
@@ -57,6 +58,25 @@ const EditForm = ({
                                : null}
                        </Form.Group>
                </Row>
+               <Row>
+                       <Form.Group as={Col}>
+                               <Form.Label>{i18n.t('rounds.code')}</Form.Label>
+                               <Form.Control
+                                       as={SeedCodeInput}
+                                       game={values.game || 'mixed'}
+                                       isInvalid={!!(touched.code && errors.code)}
+                                       name="code"
+                                       onBlur={handleBlur}
+                                       onChange={handleChange}
+                                       value={values.code || []}
+                               />
+                               {touched.code && errors.code ?
+                                       <Form.Control.Feedback type="invalid">
+                                               {i18n.t(errors.code)}
+                                       </Form.Control.Feedback>
+                               : null}
+                       </Form.Group>
+               </Row>
        </Modal.Body>
        <Modal.Footer>
                {onCancel ?
@@ -72,6 +92,7 @@ const EditForm = ({
 
 EditForm.propTypes = {
        errors: PropTypes.shape({
+               code: PropTypes.arrayOf(PropTypes.string),
                seed: PropTypes.string,
                title: PropTypes.string,
        }),
@@ -80,10 +101,13 @@ EditForm.propTypes = {
        handleSubmit: PropTypes.func,
        onCancel: PropTypes.func,
        touched: PropTypes.shape({
+               code: PropTypes.arrayOf(PropTypes.bool),
                seed: PropTypes.bool,
                title: PropTypes.bool,
        }),
        values: PropTypes.shape({
+               code: PropTypes.arrayOf(PropTypes.string),
+               game: PropTypes.string,
                seed: PropTypes.string,
                title: PropTypes.string,
        }),
@@ -110,11 +134,14 @@ export default withFormik({
                }
        },
        mapPropsToValues: ({ round }) => ({
+               code: round.code || [],
+               game: round.game || 'mixed',
                round_id: round.id,
                seed: round.seed || '',
                title: round.title || '',
        }),
        validationSchema: yup.object().shape({
+               code: yup.array().of(yup.string()),
                seed: yup.string().url(),
                title: yup.string(),
        }),