import { TimeField, TimeStrategy } from 'ontime-types'; import { dayInMs } from 'ontime-utils'; import { memo } from 'react'; import { IoAlertCircleOutline, IoLink, IoLockClosed, IoLockOpenOutline, IoUnlink } from 'react-icons/io5'; import IconButton from '../../../common/components/buttons/IconButton'; import * as Editor from '../../../common/components/editor-utils/EditorUtils'; import TimeInput from '../../../common/components/input/time-input/TimeInput'; import Tooltip from '../../../common/components/tooltip/Tooltip'; import { useEntryActionsContext } from '../../../common/context/EntryActionsContext'; import TimeInputGroup from './TimeInputGroup'; import style from './TimeInputFlow.module.scss'; interface TimeInputFlowProps { eventId: string; timeStart: number; timeEnd: number; duration: number; timeStrategy: TimeStrategy; linkStart: boolean; delay: number; showLabels?: boolean; showWarnings?: boolean; } export default memo(TimeInputFlow); function TimeInputFlow({ eventId, timeStart, timeEnd, duration, timeStrategy, linkStart, delay, showLabels, showWarnings = true, }: TimeInputFlowProps) { const { updateEntry, updateTimer } = useEntryActionsContext(); // In sync with EventEditorTimes const handleSubmit = (field: TimeField, value: string) => { updateTimer(eventId, field, value); }; const handleChangeStrategy = (timeStrategy: TimeStrategy) => { updateEntry({ id: eventId, timeStrategy }); }; const handleLink = (doLink: boolean) => { updateEntry({ id: eventId, linkStart: doLink }); }; const warnings = []; if (timeStart + duration > dayInMs) { warnings.push('Over midnight'); } const hasDelay = delay !== 0; const isLockedEnd = timeStrategy === TimeStrategy.LockEnd; const isLockedDuration = timeStrategy === TimeStrategy.LockDuration; return ( <>
{showLabels && Start time} Start handleLink(!linkStart)} render={} > {linkStart ? : }
{showLabels && End time} End } onClick={() => handleChangeStrategy(TimeStrategy.LockEnd)} data-testid='lock__end' > {isLockedEnd ? : }
{showLabels && Duration} Duration } onClick={() => handleChangeStrategy(TimeStrategy.LockDuration)} data-testid='lock__duration' > {isLockedDuration ? : }
{showWarnings && (warnings.length > 0 ? ( } > ) : (