Fix reservation fetching

This commit is contained in:
Joshua Schmucker 2026-02-05 17:26:22 +01:00
parent ec7f07d788
commit 56204f3324
2 changed files with 22 additions and 6 deletions

View File

@ -241,9 +241,9 @@ const UserDashboard: React.FC = () => {
<div style={{ display: 'grid', gap: '1rem' }}>
{reservations
.sort((a, b) => new Date(b.startTime).getTime() - new Date(a.startTime).getTime())
.map(reservation => (
.map(reservation => (
<div
key={reservation.id}
key={reservation.referenceNumber}
style={{
backgroundColor: 'white',
padding: '1.5rem',

View File

@ -123,9 +123,21 @@ export class SimpleLibreBookingClient {
}
}
const url = resourceId
? `${this.baseUrl}/Services/index.php/Reservations/?resourceId=${resourceId}`
: `${this.baseUrl}/Services/index.php/Reservations/`;
// Use a wide date range to get all reservations
const today = new Date();
const threeMonthsAgo = new Date(today.getTime() - (90 * 24 * 60 * 60 * 1000));
const threeMonthsFromNow = new Date(today.getTime() + (90 * 24 * 60 * 60 * 1000));
const params = new URLSearchParams({
startDateTime: threeMonthsAgo.toISOString().split('.')[0] + 'Z',
endDateTime: threeMonthsFromNow.toISOString().split('.')[0] + 'Z',
});
if (resourceId) {
params.append('resourceId', resourceId);
}
const url = `${this.baseUrl}/Services/index.php/Reservations/?${params.toString()}`;
const headers: Record<string, string> = {
'Content-Type': 'application/json',
@ -145,7 +157,11 @@ export class SimpleLibreBookingClient {
}
const data = await response.json();
console.log('Reservations response:', data);
console.log('API date range:', {
start: data.startDateTime,
end: data.endDateTime
});
console.log('Found reservations:', data.reservations.length);
return data.reservations || [];
}