fix: sync endHour state when effectiveStartHour shifts past it
When existing bookings block the initial startHour, effectiveStartHour snaps to the first available slot. Added useLayoutEffect to update endHour state immediately so start and end times are never equal. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
import { useState, useRef, useEffect, useLayoutEffect } from 'react'
|
||||
import { X, Clock, CalendarDays, User, Phone, AlertCircle, Banknote, CreditCard, Building2, Link2 } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { api } from '../../lib/api'
|
||||
@@ -124,6 +124,13 @@ export function RentalBookingModal({
|
||||
|
||||
const availableEndHours = hourOptions(effectiveStartHour + 1, getMaxEndHour(effectiveStartHour))
|
||||
|
||||
// Sync endHour state when effectiveStartHour shifts past it (e.g. first available start is beyond initial endHour)
|
||||
useLayoutEffect(() => {
|
||||
if (!isFullDay && endHour <= effectiveStartHour) {
|
||||
setEndHour(effectiveStartHour + 1)
|
||||
}
|
||||
}, [effectiveStartHour])
|
||||
|
||||
const hours = isFullDay
|
||||
? obj.closeHour - obj.openHour
|
||||
: Math.max(0, endHour - effectiveStartHour)
|
||||
|
||||
Reference in New Issue
Block a user