diff --git a/src/ui/hooks/useBooking.test.ts b/src/ui/hooks/useBooking.test.ts index 87af58e..22eae6e 100644 --- a/src/ui/hooks/useBooking.test.ts +++ b/src/ui/hooks/useBooking.test.ts @@ -88,6 +88,33 @@ describe('useBooking', () => { expect(result.current.missingFields).toContain('project') }) + it('snaps a non-quarter start to the nearest quarter and keeps the duration', () => { + // A concept block at 16:11–16:41 has times no silently falls + * back to its first entry — which is why concept blocks showed up as 07:00–07:00. + * Snap the start to the nearest quarter and carry the original duration (also + * quarter-rounded, min 15m) so both dropdowns land on a real option and the + * booked range still reflects the block. With no start, fall back to 09:00–09:30. + */ +function snapInitialTimes(start?: string, end?: string): { startTime: string; endTime: string } { + if (!start) return { startTime: '09:00', endTime: '09:30' } + const startMin = timeToMinutes(start) + const snappedStart = Math.round(startMin / QUARTER_MIN) * QUARTER_MIN + const rawDuration = end ? timeToMinutes(end) - startMin : 30 + const duration = Math.max(QUARTER_MIN, Math.round(rawDuration / QUARTER_MIN) * QUARTER_MIN) + return { + startTime: minutesToTime(snappedStart), + endTime: minutesToTime(snappedStart + duration), + } +} + function sortProjects(projects: SimplicateProject[], starredIds: ReadonlySet): { sorted: SimplicateProject[]; lastStarredId: string | undefined } { const starred = projects .filter(p => starredIds.has(p.id)) @@ -31,8 +64,9 @@ export function useBooking(initial: Partial = {}) { const [serviceId, setServiceId] = useState(initial.projectServiceId ?? '') const [hourTypeId, setHourTypeId] = useState(initial.hourTypeId ?? '') const [note, setNote] = useState(initial.note ?? '') - const [startTime, setStartTime] = useState(initial.startTime ?? '09:00') - const [endTime, setEndTime] = useState(initial.endTime ?? '09:30') + const snapped = snapInitialTimes(initial.startTime, initial.endTime) + const [startTime, setStartTime] = useState(snapped.startTime) + const [endTime, setEndTime] = useState(snapped.endTime) const [date, setDate] = useState(initial.startDate ?? new Date().toISOString().split('T')[0]!) const [services, setServices] = useState<{ id: string; name: string; hourTypeIds: string[] }[]>([]) const [status, setStatus] = useState('idle')