Fix: block drag-to-move if target room has conflicting booking
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -87,8 +87,10 @@ export function BookingCalendar({ rooms, bookings, slug, onBookingCreate, onBook
|
||||
const [ghostPos, setGhostPos] = useState<{ x: number; y: number } | null>(null)
|
||||
const movingBookingRef = useRef<Booking | null>(null)
|
||||
const moveTargetRoomIdRef = useRef<string | null>(null) // всегда актуален, без stale closure
|
||||
const bookingsRef = useRef<Booking[]>(bookings)
|
||||
const didDragRef = useRef(false)
|
||||
movingBookingRef.current = movingBooking
|
||||
bookingsRef.current = bookings
|
||||
|
||||
// Compact mode (default from Settings → Appearance)
|
||||
const [compact, setCompact] = useState(
|
||||
@@ -510,9 +512,18 @@ export function BookingCalendar({ rooms, bookings, slug, onBookingCreate, onBook
|
||||
// Читаем из ref — всегда актуальное значение, не stale closure
|
||||
const targetRoomId = moveTargetRoomIdRef.current
|
||||
if (targetRoomId && targetRoomId !== booking.roomId) {
|
||||
// Проверяем конфликт в целевом номере
|
||||
const hasConflict = bookingsRef.current.some(b =>
|
||||
b.roomId === targetRoomId &&
|
||||
b.id !== booking.id &&
|
||||
b.status !== 'cancelled' && b.status !== 'no_show' && b.status !== 'checked_out' &&
|
||||
b.checkIn < booking.checkOut && b.checkOut > booking.checkIn,
|
||||
)
|
||||
if (!hasConflict) {
|
||||
didDragRef.current = true
|
||||
onBookingUpdate(booking.id, { roomId: targetRoomId })
|
||||
}
|
||||
}
|
||||
setMovingBooking(null)
|
||||
setMoveTargetRoomId(null)
|
||||
setGhostPos(null)
|
||||
|
||||
Reference in New Issue
Block a user