mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 07:29:08 +00:00
easier timer validation
This commit is contained in:
@@ -1,25 +1,24 @@
|
|||||||
import EditableTimer from '../../input/EditableTimer';
|
import EditableTimer from '../../input/EditableTimer';
|
||||||
import DelayValue from '../../input/DelayValue';
|
import DelayValue from '../../input/DelayValue';
|
||||||
import { showErrorToast } from '../../helpers/toastManager';
|
import { showWarningToast } from '../../helpers/toastManager';
|
||||||
|
|
||||||
export default function EventTimes(props) {
|
export default function EventTimes(props) {
|
||||||
const { updateValues, delay, timeStart, timeEnd } = props;
|
const { updateValues, delay, timeStart, timeEnd } = props;
|
||||||
|
|
||||||
// TODO: how to handle midnight rollover
|
|
||||||
const handleValidate = (entry, v) => {
|
const handleValidate = (entry, v) => {
|
||||||
// if one of the fields is not set, all good
|
// we dont inforce validation here
|
||||||
|
|
||||||
if (v == null || timeStart == null || timeEnd == null) return true;
|
if (v == null || timeStart == null || timeEnd == null) return true;
|
||||||
if (v === 0 || timeStart === 0 || timeEnd === 0) return true;
|
if (timeStart === 0) return true;
|
||||||
|
|
||||||
let validate = { value: false, catch: 'undefined error' };
|
let validate = { value: true, catch: '' };
|
||||||
if (entry === 'timeStart')
|
if (entry === 'timeStart' && v > timeEnd)
|
||||||
validate = { value: v < timeEnd, catch: 'Start time later than end time' };
|
validate.catch = 'Start time later than end time';
|
||||||
else if (entry === 'timeEnd')
|
else if (entry === 'timeEnd' && v < timeStart)
|
||||||
validate = { value: v > timeStart, catch: 'End time earlier than start time' };
|
validate.catch = 'End time earlier than start time';
|
||||||
|
|
||||||
if (validate.value === false)
|
if (validate.catch !== '')
|
||||||
showErrorToast('Time Input Invalid', validate.catch);
|
showWarningToast('Time Input Warning', validate.catch);
|
||||||
return validate.value;
|
return validate.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,3 +14,15 @@ export const showErrorToast = (title, description) => {
|
|||||||
isClosable: true,
|
isClosable: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// warning toast
|
||||||
|
export const showWarningToast = (title, description) => {
|
||||||
|
toast({
|
||||||
|
title: title,
|
||||||
|
description: description,
|
||||||
|
position: 'top-left',
|
||||||
|
variant: 'subtle',
|
||||||
|
status: 'warning',
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user