fixed calendar view from reservations
This commit is contained in:
parent
ca573c36e8
commit
6d99ca594a
@ -20,13 +20,17 @@ const ResourceCalendar: React.FC = () => {
|
||||
const loadData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
console.log('Loading calendar for resource ID:', id);
|
||||
const [resourceData, reservationsData] = await Promise.all([
|
||||
api.getResource(id),
|
||||
api.getReservations(id)
|
||||
]);
|
||||
console.log('Resource data:', resourceData);
|
||||
console.log('Reservations data:', reservationsData);
|
||||
setResource(resourceData);
|
||||
setReservations(reservationsData);
|
||||
} catch (err) {
|
||||
console.log('Error loading calendar:', err);
|
||||
setError(err instanceof Error ? err.message : 'Failed to load data');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@ -39,6 +43,8 @@ const ResourceCalendar: React.FC = () => {
|
||||
const weekStart = startOfWeek(currentWeek, { weekStartsOn: 1 });
|
||||
const weekDays = Array.from({ length: 7 }, (_, i) => addDays(weekStart, i));
|
||||
|
||||
|
||||
|
||||
// Generate time slots from 8 AM to 8 PM
|
||||
const timeSlots = Array.from({ length: 13 }, (_, i) => {
|
||||
const hour = i + 8; // Start at 8 AM
|
||||
@ -50,13 +56,14 @@ const ResourceCalendar: React.FC = () => {
|
||||
const slotEnd = addHours(slotStart, 1);
|
||||
|
||||
return reservations.find(reservation => {
|
||||
const reservationStart = new Date(reservation.startTime);
|
||||
const reservationEnd = new Date(reservation.endTime);
|
||||
const reservationStart = new Date(reservation.startDate);
|
||||
const reservationEnd = new Date(reservation.endDate);
|
||||
|
||||
// Check if reservation occupies this time slot
|
||||
return (
|
||||
(reservationStart < slotEnd && reservationEnd > slotStart) ||
|
||||
(isSameDay(reservationStart, date) &&
|
||||
reservationStart.getHours() === slotStart.getHours())
|
||||
reservationStart.getHours() === timeSlot.getHours())
|
||||
);
|
||||
}) || null;
|
||||
};
|
||||
@ -228,7 +235,7 @@ const ResourceCalendar: React.FC = () => {
|
||||
}}>
|
||||
<div style={{ fontWeight: 'bold' }}>{reservation.title}</div>
|
||||
<div style={{ fontSize: '0.625rem', opacity: 0.8 }}>
|
||||
{format(new Date(reservation.startTime), 'h:mm')} - {format(new Date(reservation.endTime), 'h:mm')}
|
||||
{format(new Date(reservation.startDate), 'h:mm')} - {format(new Date(reservation.endDate), 'h:mm')}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@ -47,8 +47,16 @@ const UserDashboard: React.FC = () => {
|
||||
});
|
||||
|
||||
// Debug: Check what status field exists
|
||||
console.log('Sample reservation:', reservations[0]);
|
||||
console.log('Available fields:', reservations[0] ? Object.keys(reservations[0]) : 'No reservations');
|
||||
// Debug: Check the first reservation structure
|
||||
if (reservations.length > 0) {
|
||||
const firstReservation = reservations[0];
|
||||
console.log('=== RESERVATION DEBUG ===');
|
||||
console.log('Sample reservation:', firstReservation);
|
||||
console.log('Available fields:', Object.keys(firstReservation));
|
||||
console.log('Resource ID field:', firstReservation.resourceId);
|
||||
console.log('Resource ID type:', typeof firstReservation.resourceId);
|
||||
console.log('========================');
|
||||
}
|
||||
|
||||
// Stats should always use all reservations (not filtered)
|
||||
const upcomingReservations = reservations.filter(r => {
|
||||
|
||||
@ -107,7 +107,7 @@ export class SimpleLibreBookingClient {
|
||||
|
||||
const data = await response.json();
|
||||
console.log('Resource response:', data);
|
||||
return data.resource || null;
|
||||
return data || null;
|
||||
}
|
||||
|
||||
async getReservations(resourceId?: string): Promise<Reservation[]> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user