Fix booking creation: localStorage token, conflict detection, paid_amount

- Fix api.ts getToken/saveToken to read from localStorage (matching AuthContext) — was reading sessionStorage causing all API requests to fail auth until refresh
- Fix session cleanup on 401 to use localStorage
- Add isConflict/availableRooms helpers to BookingModal; show amber warning when selected room is occupied with clickable free room suggestions
- Pass bookings prop to BookingModal via BookingCalendar
- Add paid_amount to backend POST /bookings INSERT
- Show alert() when booking creation fails so user sees the error
- Pass paidAmount in CalendarPage handleCreate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-17 19:48:37 +03:00
parent e59bc752b0
commit 684073c4ad
5 changed files with 61 additions and 12 deletions

View File

@@ -58,13 +58,15 @@ export function CalendarPage() {
checkIn: data.checkIn, checkOut: data.checkOut,
adults: data.adults, children: data.children,
status: data.status, source: data.source,
totalAmount: data.totalAmount, notes: data.notes,
totalAmount: data.totalAmount, paidAmount: data.paidAmount, notes: data.notes,
})
setBookings(prev => [...prev, created])
send({ type: 'booking:created', booking: created })
if (data.roomId) send({ type: 'unlock', roomId: data.roomId })
} catch (err) {
console.error('Failed to create booking:', err)
const msg = err instanceof Error ? err.message : 'Ошибка создания бронирования'
alert(msg)
}
}