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:
@@ -23,20 +23,29 @@ export function CalendarPage() {
|
||||
const [rentalObjects, setRentalObjects] = useState<RentalObjectApi[]>([])
|
||||
const [rentalBookings, setRentalBookings] = useState<RentalBookingApi[]>([])
|
||||
const [locks, setLocks] = useState<Map<string, BookingLock>>(new Map())
|
||||
const [priceOverrides, setPriceOverrides] = useState<Record<string, Record<string, number>>>({})
|
||||
|
||||
useEffect(() => {
|
||||
if (!slug) return
|
||||
const fetches: Promise<unknown>[] = [
|
||||
api.rooms.list(slug),
|
||||
api.bookings.list(slug),
|
||||
api.rateOverrides.list(slug).catch(() => []),
|
||||
]
|
||||
if (isRentalActive) {
|
||||
fetches.push(api.rental.listObjects(slug))
|
||||
fetches.push(api.rental.listBookings(slug))
|
||||
}
|
||||
Promise.all(fetches).then(([r, b, ro, rb]) => {
|
||||
Promise.all(fetches).then(([r, b, overrides, ro, rb]) => {
|
||||
setRooms(r as Room[])
|
||||
setBookings(b as Booking[])
|
||||
// Build categoryId → date → price lookup
|
||||
const map: Record<string, Record<string, number>> = {}
|
||||
for (const o of overrides as import('../lib/api').RateOverrideApi[]) {
|
||||
if (!map[o.categoryId]) map[o.categoryId] = {}
|
||||
map[o.categoryId][o.date] = o.price
|
||||
}
|
||||
setPriceOverrides(map)
|
||||
if (isRentalActive) {
|
||||
setRentalObjects(ro as RentalObjectApi[])
|
||||
setRentalBookings(rb as RentalBookingApi[])
|
||||
@@ -192,6 +201,7 @@ export function CalendarPage() {
|
||||
onDraftStart={handleDraftStart}
|
||||
onDraftCancel={handleDraftCancel}
|
||||
wsConnected={connected}
|
||||
priceOverrides={priceOverrides}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user