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';
8 import i18n from '../../i18n';
9 import { formatTime, parseTime } from '../../helpers/Result';
10 import yup from '../../schema/yup';
21 <Form noValidate onSubmit={handleSubmit}>
24 <Form.Group as={Col} controlId="report.time">
25 <Form.Label>{i18n.t('results.reportTime')}</Form.Label>
27 isInvalid={!!(touched.time && errors.time)}
30 onChange={handleChange}
33 value={values.time || ''}
35 {touched.time && errors.time ?
36 <Form.Control.Feedback type="invalid">
38 </Form.Control.Feedback>
41 {parseTime(values.time) ?
43 'results.reportPreview',
44 { time: formatTime({ time: parseTime(values.time) })},
54 <Button onClick={onCancel} variant="secondary">
55 {i18n.t('button.cancel')}
58 <Button type="submit" variant="primary">
59 {i18n.t('button.save')}
64 ReportForm.propTypes = {
65 errors: PropTypes.shape({
66 time: PropTypes.string,
68 handleBlur: PropTypes.func,
69 handleChange: PropTypes.func,
70 handleSubmit: PropTypes.func,
71 onCancel: PropTypes.func,
72 touched: PropTypes.shape({
75 values: PropTypes.shape({
76 time: PropTypes.string,
80 export default withFormik({
81 displayName: 'ReportForm',
82 enableReinitialize: true,
83 handleSubmit: async (values, actions) => {
84 const { participant_id, round_id, time } = values;
85 const { onCancel } = actions.props;
86 await axios.post('/api/results', {
89 time: parseTime(time),
95 mapPropsToValues: ({ participant, round }) => ({
96 participant_id: participant.id,
100 validationSchema: yup.object().shape({
101 time: yup.string().required().time(),
103 })(withTranslation()(ReportForm));