From 7833e87aab11a015a72372cb7805d550e61241b5 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Fri, 10 Jul 2026 21:16:59 +0100 Subject: [PATCH] fix: add split-lunch detection with formatted time range warnings --- frontend/src/lib/lunchProtection.ts | 35 ++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/lunchProtection.ts b/frontend/src/lib/lunchProtection.ts index 701b183..ccc3cf9 100644 --- a/frontend/src/lib/lunchProtection.ts +++ b/frontend/src/lib/lunchProtection.ts @@ -212,6 +212,21 @@ export function getLunchProtectionForSlots( if (isAdmin) { if (gapWith < 30) { + const gapWasBelow30 = gapsWith.length > 1; + if (gapWasBelow30) { + const gapsWithout = findAllLunchGaps(windowStart, windowEnd, existingBookings); + const gapWithout = gapsWithout[0] ?? 0; + if (gapWithout >= 30 && gapWith < gapWithout) { + const firstGap = gapsWith[0] ?? 0; + const secondGap = gapsWith[1] ?? 0; + results.set(slotStartStr, { + isBlocked: false, + showWarning: true, + warningMessage: `This booking (${slotStartStr}–${slotEndStr}) would split your suggested lunch break into ${firstGap} and ${secondGap} minute blocks.` + }); + continue; + } + } results.set(slotStartStr, { isBlocked: true, showWarning: false, @@ -221,11 +236,21 @@ export function getLunchProtectionForSlots( const gapsWithout = findAllLunchGaps(windowStart, windowEnd, existingBookings); const gapWithout = gapsWithout[0] ?? 0; if (gapWith < gapWithout) { - results.set(slotStartStr, { - isBlocked: false, - showWarning: true, - warningMessage: `This booking would reduce lunch break to ${gapWith} minutes.` - }); + if (gapsWith.length > 1) { + const firstGap = gapsWith[0] ?? 0; + const secondGap = gapsWith[1] ?? 0; + results.set(slotStartStr, { + isBlocked: false, + showWarning: true, + warningMessage: `This booking (${slotStartStr}–${slotEndStr}) would split your suggested lunch break into ${firstGap} and ${secondGap} minute blocks.` + }); + } else { + results.set(slotStartStr, { + isBlocked: false, + showWarning: true, + warningMessage: `This booking would reduce lunch break to ${gapWith} minutes.` + }); + } } } } else {