From 2890687f7383453d0d752d88faf06008340829a8 Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Sat, 17 Apr 2021 12:29:01 +0200 Subject: [PATCH] bugfix: handle time 0 --- .../common/components/eventTimes/EventTimes.jsx | 15 ++++++++++----- client/src/common/dateConfig.js | 3 +-- server/data/eventsDefinition.js | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/client/src/common/components/eventTimes/EventTimes.jsx b/client/src/common/components/eventTimes/EventTimes.jsx index 4e2060627..74658bb7c 100644 --- a/client/src/common/components/eventTimes/EventTimes.jsx +++ b/client/src/common/components/eventTimes/EventTimes.jsx @@ -1,5 +1,6 @@ import EditableTimer from '../../input/EditableTimer'; import DelayValue from '../../input/DelayValue'; +import { showErrorToast } from '../../helpers/toastManager'; export default function EventTimes(props) { const { updateValues, delay, timeStart, timeEnd } = props; @@ -9,15 +10,19 @@ export default function EventTimes(props) { // if one of the fields is not set, all good if (v == null || timeStart == null || timeEnd == null) return true; + if (v === 0 || timeStart === 0 || timeEnd === 0) return true; - if (entry === 'timeStart') return v < timeEnd; - else if (entry === 'timeEnd') return v > timeStart; + let validate = { value: false, catch: 'undefined error' }; + if (entry === 'timeStart') + validate = { value: v < timeEnd, catch: 'Start time later than end time' }; + else if (entry === 'timeEnd') + validate = { value: v > timeStart, catch: 'End time earlier than start time' }; - // shouldnt come to this - return false; + if (validate.value === false) + showErrorToast('Time Input Invalid', validate.catch); + return validate.value; }; - return ( <> diff --git a/client/src/common/dateConfig.js b/client/src/common/dateConfig.js index cf6222d6c..4978f47b3 100644 --- a/client/src/common/dateConfig.js +++ b/client/src/common/dateConfig.js @@ -1,4 +1,3 @@ - export const timeFormat = 'HH:mm'; export const timeFormatSeconds = 'HH:mm:ss'; @@ -16,7 +15,7 @@ export const stringFromMillis = ( const seconds = showWith0(Math.floor((ms / 1000) % 60)); return showSeconds ? `${parseInt(hours) ? `${hours}${delim}` : ''}${minutes}${delim}${seconds}` - : `${parseInt(hours) ? `${hours}${delim}` : ''}${minutes}`; + : `${parseInt(hours) ? `${hours}` : '00'}${delim}${minutes}`; }; // millis to seconds diff --git a/server/data/eventsDefinition.js b/server/data/eventsDefinition.js index 8e873f133..72303c695 100644 --- a/server/data/eventsDefinition.js +++ b/server/data/eventsDefinition.js @@ -3,9 +3,10 @@ const event = { title: '', subtitle: '', presenter: '', - timeStart: null, - timeEnd: null, + timeStart: 0, + timeEnd: 0, clockStarted: null, + isPublic: false, type: 'event', };