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 [ghostPos, setGhostPos] = useState<{ x: number; y: number } | null>(null)
|
||||||
const movingBookingRef = useRef<Booking | null>(null)
|
const movingBookingRef = useRef<Booking | null>(null)
|
||||||
const moveTargetRoomIdRef = useRef<string | null>(null) // всегда актуален, без stale closure
|
const moveTargetRoomIdRef = useRef<string | null>(null) // всегда актуален, без stale closure
|
||||||
|
const bookingsRef = useRef<Booking[]>(bookings)
|
||||||
const didDragRef = useRef(false)
|
const didDragRef = useRef(false)
|
||||||
movingBookingRef.current = movingBooking
|
movingBookingRef.current = movingBooking
|
||||||
|
bookingsRef.current = bookings
|
||||||
|
|
||||||
// Compact mode (default from Settings → Appearance)
|
// Compact mode (default from Settings → Appearance)
|
||||||
const [compact, setCompact] = useState(
|
const [compact, setCompact] = useState(
|
||||||
@@ -510,8 +512,17 @@ export function BookingCalendar({ rooms, bookings, slug, onBookingCreate, onBook
|
|||||||
// Читаем из ref — всегда актуальное значение, не stale closure
|
// Читаем из ref — всегда актуальное значение, не stale closure
|
||||||
const targetRoomId = moveTargetRoomIdRef.current
|
const targetRoomId = moveTargetRoomIdRef.current
|
||||||
if (targetRoomId && targetRoomId !== booking.roomId) {
|
if (targetRoomId && targetRoomId !== booking.roomId) {
|
||||||
didDragRef.current = true
|
// Проверяем конфликт в целевом номере
|
||||||
onBookingUpdate(booking.id, { roomId: targetRoomId })
|
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)
|
setMovingBooking(null)
|
||||||
setMoveTargetRoomId(null)
|
setMoveTargetRoomId(null)
|
||||||
|
|||||||
Reference in New Issue
Block a user