]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/results/ReportForm.js
result comments
[alttp.git] / resources / js / components / results / ReportForm.js
index 28a757a78ed9326a916aa6f3f24a18b3f7fedda6..942869da7123c36b160ef76368c3877f2032bbee 100644 (file)
@@ -19,47 +19,63 @@ const ReportForm = ({
        handleChange,
        handleSubmit,
        onCancel,
+       round,
        touched,
        values,
 }) =>
 <Form noValidate onSubmit={handleSubmit}>
        <Modal.Body>
+               {!round.locked ?
+                       <Row>
+                               <Form.Group as={Col} sm={9} controlId="report.time">
+                                       <Form.Label>{i18n.t('results.reportTime')}</Form.Label>
+                                       <Form.Control
+                                               isInvalid={!!(touched.time && errors.time)}
+                                               name="time"
+                                               onBlur={handleBlur}
+                                               onChange={handleChange}
+                                               placeholder={values.forfeit ? 'DNF' : '1:22:59'}
+                                               type="text"
+                                               value={values.time || ''}
+                                       />
+                                       {touched.time && errors.time ?
+                                               <Form.Control.Feedback type="invalid">
+                                                       {i18n.t(errors.time)}
+                                               </Form.Control.Feedback>
+                                       :
+                                               <Form.Text muted>
+                                                       {parseTime(values.time) ?
+                                                               i18n.t(
+                                                                       'results.reportPreview',
+                                                                       { time: formatTime({ time: parseTime(values.time) })},
+                                                               )
+                                                       : null}
+                                               </Form.Text>
+                                       }
+                               </Form.Group>
+                               <Form.Group as={Col} sm={3} controlId="report.forfeit">
+                                       <Form.Label>{i18n.t('results.forfeit')}</Form.Label>
+                                       <Form.Control
+                                               as={LargeCheck}
+                                               isInvalid={!!(touched.forfeit && errors.forfeit)}
+                                               name="forfeit"
+                                               onBlur={handleBlur}
+                                               onChange={handleChange}
+                                               value={!!values.forfeit}
+                                       />
+                               </Form.Group>
+                       </Row>
+               : null}
                <Row>
-                       <Form.Group as={Col} sm={9} controlId="report.time">
-                               <Form.Label>{i18n.t('results.reportTime')}</Form.Label>
+                       <Form.Group as={Col} sm={12} controlId="report.comment">
+                               <Form.Label>{i18n.t('results.comment')}</Form.Label>
                                <Form.Control
-                                       isInvalid={!!(touched.time && errors.time)}
-                                       name="time"
+                                       as="textarea"
+                                       isInvalid={!!(touched.comment && errors.comment)}
+                                       name="comment"
                                        onBlur={handleBlur}
                                        onChange={handleChange}
-                                       placeholder={values.forfeit ? 'DNF' : '1:22:59'}
-                                       type="text"
-                                       value={values.time || ''}
-                               />
-                               {touched.time && errors.time ?
-                                       <Form.Control.Feedback type="invalid">
-                                               {i18n.t(errors.time)}
-                                       </Form.Control.Feedback>
-                               :
-                                       <Form.Text muted>
-                                               {parseTime(values.time) ?
-                                                       i18n.t(
-                                                               'results.reportPreview',
-                                                               { time: formatTime({ time: parseTime(values.time) })},
-                                                       )
-                                               : null}
-                                       </Form.Text>
-                               }
-                       </Form.Group>
-                       <Form.Group as={Col} sm={3} controlId="report.forfeit">
-                               <Form.Label>{i18n.t('results.forfeit')}</Form.Label>
-                               <Form.Control
-                                       as={LargeCheck}
-                                       isInvalid={!!(touched.forfeit && errors.forfeit)}
-                                       name="forfeit"
-                                       onBlur={handleBlur}
-                                       onChange={handleChange}
-                                       value={!!values.forfeit}
+                                       value={values.comment || ''}
                                />
                        </Form.Group>
                </Row>
@@ -78,6 +94,7 @@ const ReportForm = ({
 
 ReportForm.propTypes = {
        errors: PropTypes.shape({
+               comment: PropTypes.string,
                forfeit: PropTypes.string,
                time: PropTypes.string,
        }),
@@ -85,11 +102,16 @@ ReportForm.propTypes = {
        handleChange: PropTypes.func,
        handleSubmit: PropTypes.func,
        onCancel: PropTypes.func,
+       round: PropTypes.shape({
+               locked: PropTypes.bool,
+       }),
        touched: PropTypes.shape({
+               comment: PropTypes.bool,
                forfeit: PropTypes.bool,
                time: PropTypes.bool,
        }),
        values: PropTypes.shape({
+               comment: PropTypes.string,
                forfeit: PropTypes.bool,
                time: PropTypes.string,
        }),
@@ -99,11 +121,12 @@ export default withFormik({
        displayName: 'ReportForm',
        enableReinitialize: true,
        handleSubmit: async (values, actions) => {
-               const { forfeit, participant_id, round_id, time } = values;
+               const { comment, forfeit, participant_id, round_id, time } = values;
                const { setErrors } = actions;
                const { onCancel } = actions.props;
                try {
                        await axios.post('/api/results', {
+                               comment,
                                forfeit,
                                participant_id,
                                round_id,
@@ -123,6 +146,7 @@ export default withFormik({
        mapPropsToValues: ({ participant, round }) => {
                const result = findResult(participant, round);
                return {
+                       comment: result && result.comment ? result.comment : '',
                        forfeit: result ? !!result.forfeit : false,
                        participant_id: participant.id,
                        round_id: round.id,
@@ -130,6 +154,7 @@ export default withFormik({
                };
        },
        validationSchema: yup.object().shape({
+               comment: yup.string(),
                forfeit: yup.boolean().required(),
                time: yup.string().time().when('forfeit', {
                        is: false,