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

@@ -16,7 +16,7 @@ export class ApiError extends Error {
function getToken(): string | null {
try {
const s = sessionStorage.getItem('hotelsync-session')
const s = localStorage.getItem('hotelsync-session')
return s ? (JSON.parse(s) as { token: string }).token : null
} catch {
return null
@@ -25,11 +25,11 @@ function getToken(): string | null {
function saveToken(token: string) {
try {
const s = sessionStorage.getItem('hotelsync-session')
const s = localStorage.getItem('hotelsync-session')
if (!s) return
const parsed = JSON.parse(s) as Record<string, unknown>
parsed.token = token
sessionStorage.setItem('hotelsync-session', JSON.stringify(parsed))
localStorage.setItem('hotelsync-session', JSON.stringify(parsed))
} catch {
// ignore
}
@@ -86,7 +86,7 @@ async function req<T>(
saveToken(access_token)
res = await doFetch(access_token)
} else {
sessionStorage.removeItem('hotelsync-session')
localStorage.removeItem('hotelsync-session')
window.location.href = '/login'
throw new ApiError(401, 'Session expired')
}