diff --git a/apps/client/src/common/components/input/time-input/TimeInput.tsx b/apps/client/src/common/components/input/time-input/TimeInput.tsx index d584b8f02..84f1575b0 100644 --- a/apps/client/src/common/components/input/time-input/TimeInput.tsx +++ b/apps/client/src/common/components/input/time-input/TimeInput.tsx @@ -17,9 +17,8 @@ interface TimeInputProps { time?: number; delay?: number; placeholder: string; - validationHandler: (entry: TimeEntryField, val: number) => boolean; previousEnd?: number; - warning?: string; + tooltip?: string; } function ButtonInitial(name: TimeEntryField) { @@ -29,25 +28,15 @@ function ButtonInitial(name: TimeEntryField) { return ''; } -function ButtonTooltip(name: TimeEntryField, warning?: string) { - if (name === 'timeStart') return `Start${warning ? `: ${warning}` : ''}`; - if (name === 'timeEnd') return `End${warning ? `: ${warning}` : ''}`; - if (name === 'durationOverride') return `Duration${warning ? `: ${warning}` : ''}`; +function ButtonTooltip(name: TimeEntryField, tooltip?: string) { + if (name === 'timeStart') return `Start${tooltip ? `: ${tooltip}` : ''}`; + if (name === 'timeEnd') return `End${tooltip ? `: ${tooltip}` : ''}`; + if (name === 'durationOverride') return `Duration${tooltip ? `: ${tooltip}` : ''}`; return ''; } export default function TimeInput(props: TimeInputProps) { - const { - id, - name, - submitHandler, - time = 0, - delay = 0, - placeholder, - validationHandler, - previousEnd = 0, - warning, - } = props; + const { id, name, submitHandler, time = 0, delay = 0, placeholder, previousEnd = 0 } = props; const { emitError } = useEmitLog(); const inputRef = useRef(null); const [value, setValue] = useState(''); @@ -103,15 +92,12 @@ export default function TimeInput(props: TimeInputProps) { // check if time is different from before if (newValMillis === time) return false; - // validate with parent - if (!validationHandler(name, newValMillis)) return false; - // update entry submitHandler(name, newValMillis); return true; }, - [name, previousEnd, submitHandler, time, validationHandler], + [name, previousEnd, submitHandler, time], ); /** @@ -171,11 +157,11 @@ export default function TimeInput(props: TimeInputProps) { const isDelayed = delay !== 0; const inputClasses = cx([style.timeInput, isDelayed ? style.delayed : null]); - const buttonClasses = cx([style.inputButton, isDelayed ? style.delayed : null, warning ? style.warn : null]); + const buttonClasses = cx([style.inputButton, isDelayed ? style.delayed : null]); const TooltipLabel = useMemo(() => { - return ButtonTooltip(name, warning); - }, [name, warning]); + return ButtonTooltip(name, ''); + }, [name]); const ButtonText = useMemo(() => { return ButtonInitial(name); diff --git a/apps/client/src/common/utils/timesManager.ts b/apps/client/src/common/utils/timesManager.ts index 4c17af915..6cb51b5ee 100644 --- a/apps/client/src/common/utils/timesManager.ts +++ b/apps/client/src/common/utils/timesManager.ts @@ -1,44 +1 @@ export type TimeEntryField = 'timeStart' | 'timeEnd' | 'durationOverride'; - -/** - * @description Checks which field the value relates to - */ -export const handleTimeEntry = ( - field: TimeEntryField, - val: number, - timeStart: number, - timeEnd: number, -): { start: number; end: number; durationOverride: boolean } => { - let start = timeStart; - let end = timeEnd; - let durationOverride = false; - - if (field === 'timeStart') { - start = val; - } else if (field === 'timeEnd') { - end = val; - } else { - durationOverride = field === 'durationOverride'; - } - return { start, end, durationOverride }; -}; - -/** - * @description Validates time entry - */ -export const validateEntry = ( - field: TimeEntryField, - value: number, - timeStart: number, - timeEnd: number, -): { value: boolean; warnings: { start?: string; end?: string; duration?: string } } => { - const validate = { value: true, warnings: { start: '', end: '', duration: '' } }; - - const { start, end } = handleTimeEntry(field, value, timeStart, timeEnd); - - if (end < start) { - validate.warnings.start = 'Start time later than end time'; - } - - return validate; -}; diff --git a/apps/client/src/features/event-editor/composite/EventEditorTimes.tsx b/apps/client/src/features/event-editor/composite/EventEditorTimes.tsx index b3e634f00..fdb612e94 100644 --- a/apps/client/src/features/event-editor/composite/EventEditorTimes.tsx +++ b/apps/client/src/features/event-editor/composite/EventEditorTimes.tsx @@ -1,4 +1,4 @@ -import { memo, useState } from 'react'; +import { memo } from 'react'; import { Select, Switch } from '@chakra-ui/react'; import { EndAction, OntimeEvent, TimerType } from 'ontime-types'; import { calculateDuration, millisToString } from 'ontime-utils'; @@ -7,7 +7,6 @@ import TimeInput from '../../../common/components/input/time-input/TimeInput'; import { useEventAction } from '../../../common/hooks/useEventAction'; import { millisToDelayString } from '../../../common/utils/dateConfig'; import { cx } from '../../../common/utils/styleUtils'; -import { TimeEntryField, validateEntry } from '../../../common/utils/timesManager'; import style from '../EventEditor.module.scss'; @@ -29,13 +28,6 @@ const EventEditorTimes = (props: EventEditorTimesProps) => { const { eventId, timeStart, timeEnd, duration, delay, isPublic, endAction, timerType } = props; const { updateEvent } = useEventAction(); - const [warning, setWarnings] = useState({ start: '', end: '', duration: '' }); - - const timerValidationHandler = (entry: TimeEntryField, val: number) => { - const valid = validateEntry(entry, val, timeStart, timeEnd); - setWarnings((prev) => ({ ...prev, ...valid.warnings })); - return valid.value; - }; const handleSubmit = (field: TimeActions, value: number | string | boolean) => { const newEventData: Partial = { id: eventId }; @@ -87,11 +79,9 @@ const EventEditorTimes = (props: EventEditorTimesProps) => { id='timeStart' name='timeStart' submitHandler={handleSubmit} - validationHandler={timerValidationHandler} time={timeStart} delay={delay} placeholder='Start' - warning={warning.start} />