feat: use availability rate overrides in calendar tooltip and booking modal
- Load rate_overrides in CalendarPage, pass as priceOverrides to BookingCalendar - Tooltip shows override price for the hovered date (falls back to baseRate) - BookingModal sums per-night prices from overrides for the stay period - Room baseRate now only used as initial default for availability grid Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,8 @@ const HOURS = Array.from({ length: 24 }, (_, i) => i)
|
||||
interface BookingModalProps {
|
||||
open: boolean
|
||||
draft: DraftBooking
|
||||
/** categoryId → date (YYYY-MM-DD) → price; used to price bookings by availability rates */
|
||||
priceOverrides?: Record<string, Record<string, number>>
|
||||
rooms: Room[]
|
||||
bookings?: Booking[]
|
||||
onClose: () => void
|
||||
@@ -94,7 +96,7 @@ function getRoomCategories(rooms: Room[], bookings: Booking[], checkIn: string,
|
||||
})
|
||||
}
|
||||
|
||||
export function BookingModal({ open, draft, rooms, bookings = [], onClose, onSave, existing, rentalObjects, rentalBookings = [], onRentalSave, slug }: BookingModalProps) {
|
||||
export function BookingModal({ open, draft, rooms, bookings = [], onClose, onSave, existing, rentalObjects, rentalBookings = [], onRentalSave, slug, priceOverrides }: BookingModalProps) {
|
||||
const { statuses } = useModules()
|
||||
const { user } = useAuth()
|
||||
const tvEnabled = statuses['tv-welcome'] === 'active'
|
||||
@@ -329,9 +331,22 @@ export function BookingModal({ open, draft, rooms, bookings = [], onClose, onSav
|
||||
: 0
|
||||
|
||||
const hourlyHours = Math.max(0, endHour - startHour)
|
||||
// Calculate room cost: sum per-night prices from availability overrides, fall back to baseRate
|
||||
const roomNightlyTotal = (() => {
|
||||
if (!room || !form.checkIn || !form.checkOut || nights <= 0) return 0
|
||||
const catId = room.categoryId
|
||||
const catOverrides = catId ? priceOverrides?.[catId] : undefined
|
||||
if (!catOverrides) return (room.baseRate ?? 0) * nights
|
||||
let sum = 0
|
||||
for (let i = 0; i < nights; i++) {
|
||||
const d = format(addDays(new Date(form.checkIn), i), 'yyyy-MM-dd')
|
||||
sum += catOverrides[d] ?? room.baseRate ?? 0
|
||||
}
|
||||
return sum
|
||||
})()
|
||||
const roomBaseTotal = isHourly && room?.allowHourly
|
||||
? (room.hourlyRate ?? 0) * hourlyHours
|
||||
: (room?.baseRate ?? 0) * nights
|
||||
: roomNightlyTotal
|
||||
const discountAmount = selectedDiscount
|
||||
? selectedDiscount.valueType === 'percent'
|
||||
? Math.round(roomBaseTotal * Math.min(100, selectedDiscount.value) / 100)
|
||||
|
||||
Reference in New Issue
Block a user