X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Fresults%2FReportForm.js;h=942869da7123c36b160ef76368c3877f2032bbee;hb=a4260a00251cef4ad806c9d5c44d4c444d6ab831;hp=e7d1d9dec2566eb6afca44578138e0d7179a7128;hpb=812a270c7a410461e931394496512d36b34ef7b5;p=alttp.git diff --git a/resources/js/components/results/ReportForm.js b/resources/js/components/results/ReportForm.js index e7d1d9d..942869d 100644 --- a/resources/js/components/results/ReportForm.js +++ b/resources/js/components/results/ReportForm.js @@ -7,10 +7,10 @@ import { withTranslation } from 'react-i18next'; import toastr from 'toastr'; import LargeCheck from '../common/LargeCheck'; -import i18n from '../../i18n'; import laravelErrorsToFormik from '../../helpers/laravelErrorsToFormik'; import { findResult } from '../../helpers/Participant'; import { formatTime, parseTime } from '../../helpers/Result'; +import i18n from '../../i18n'; import yup from '../../schema/yup'; const ReportForm = ({ @@ -19,47 +19,63 @@ const ReportForm = ({ handleChange, handleSubmit, onCancel, + round, touched, values, }) =>
+ {!round.locked ? + + + {i18n.t('results.reportTime')} + + {touched.time && errors.time ? + + {i18n.t(errors.time)} + + : + + {parseTime(values.time) ? + i18n.t( + 'results.reportPreview', + { time: formatTime({ time: parseTime(values.time) })}, + ) + : null} + + } + + + {i18n.t('results.forfeit')} + + + + : null} - - {i18n.t('results.reportTime')} + + {i18n.t('results.comment')} - {touched.time && errors.time ? - - {i18n.t(errors.time)} - - : - - {parseTime(values.time) ? - i18n.t( - 'results.reportPreview', - { time: formatTime({ time: parseTime(values.time) })}, - ) - : null} - - } - - - {i18n.t('results.forfeit')} - @@ -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, @@ -114,7 +137,7 @@ export default withFormik({ onCancel(); } } catch (e) { - toastr.success(i18n.t('results.reportError')); + toastr.error(i18n.t('results.reportError')); if (e.response && e.response.data && e.response.data.errors) { setErrors(laravelErrorsToFormik(e.response.data.errors)); } @@ -122,8 +145,8 @@ export default withFormik({ }, mapPropsToValues: ({ participant, round }) => { const result = findResult(participant, round); - console.log(result); return { + comment: result && result.comment ? result.comment : '', forfeit: result ? !!result.forfeit : false, participant_id: participant.id, round_id: round.id, @@ -131,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,