From ec7f07d788902f45cc21e9e39cf366d14cbe7030 Mon Sep 17 00:00:00 2001 From: Joshua Schmucker Date: Tue, 3 Feb 2026 13:17:48 +0100 Subject: [PATCH] working dashboard again --- src/pages/CreateReservation.tsx | 5 ++--- src/pages/UserDashboard.tsx | 37 +++++++++++++++++++------------- src/services/librebooking-api.ts | 5 +---- src/types/index.ts | 30 +++++++++++++++++--------- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/pages/CreateReservation.tsx b/src/pages/CreateReservation.tsx index 6de9cc0..0f825ab 100644 --- a/src/pages/CreateReservation.tsx +++ b/src/pages/CreateReservation.tsx @@ -70,8 +70,7 @@ const CreateReservation: React.FC = () => { endDateTime: `${formData.date}T${formData.endTime}`, title: formData.title.trim(), description: formData.description.trim() || '', - userId: apiClient.getUserId() || undefined, - allowParticipation: true, + allowParticipation: false, termsAccepted: true }; @@ -153,7 +152,7 @@ const CreateReservation: React.FC = () => { > {resources.map(resource => ( - ))} diff --git a/src/pages/UserDashboard.tsx b/src/pages/UserDashboard.tsx index e22380a..6fbe050 100644 --- a/src/pages/UserDashboard.tsx +++ b/src/pages/UserDashboard.tsx @@ -31,20 +31,28 @@ const UserDashboard: React.FC = () => { const confirmedReservations = reservations.filter(r => r.status === 'confirmed'); // Group upcoming reservations - const upcomingReservations = reservations.filter(r => - r.status !== 'cancelled' && new Date(r.endTime) > new Date() - ); + const upcomingReservations = reservations.filter(r => { + if (r.status === 'cancelled') return false; + const endTime = r.endTime instanceof Date ? r.endTime : new Date(r.endTime); + return endTime > new Date(); + }); - const todayReservations = reservations.filter(r => - r.status !== 'cancelled' && ( - isToday(new Date(r.startTime)) || - isToday(new Date(r.endTime)) - ) - ); + const todayReservations = reservations.filter(r => { + if (r.status === 'cancelled') return false; + const startTime = r.startTime instanceof Date ? r.startTime : new Date(r.startTime); + const endTime = r.endTime instanceof Date ? r.endTime : new Date(r.endTime); + return isToday(startTime) || isToday(endTime); + }); const getReservationLabel = (reservation: Reservation): string => { - const startDate = new Date(reservation.startTime); - const endDate = new Date(reservation.endTime); + // Handle both string and Date formats for startTime/endTime + const startDate = reservation.startTime instanceof Date ? reservation.startTime : new Date(reservation.startTime); + const endDate = reservation.endTime instanceof Date ? reservation.endTime : new Date(reservation.endTime); + + // Validate dates before formatting + if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) { + return 'Invalid date'; + } if (isToday(startDate)) { return `Today, ${format(startDate, 'h:mm a')} - ${format(endDate, 'h:mm a')}`; @@ -152,7 +160,7 @@ const UserDashboard: React.FC = () => { {reservation.title}
- {reservation.resource.name} + {reservation.resourceName}
{ {reservation.title}
- {reservation.resource.name} - {reservation.resource.location && ` • ${reservation.resource.location}`} + {reservation.resourceName}
{
- Booked on {format(new Date(reservation.createdAt), 'MMM d, yyyy')} + Booked on {reservation.startDate ? format(new Date(reservation.startDate), 'MMM d, yyyy') : 'Unknown date'}
diff --git a/src/services/librebooking-api.ts b/src/services/librebooking-api.ts index 65b54ae..1815586 100644 --- a/src/services/librebooking-api.ts +++ b/src/services/librebooking-api.ts @@ -169,13 +169,10 @@ export class SimpleLibreBookingClient { endDateTime: data.endDateTime, title: data.title, description: data.description || '', - userId: this.getUserId() || undefined, - allowParticipation: true, + allowParticipation: false, termsAccepted: true }; - console.log('Creating reservation with data:', requestData); - const headers: Record = { 'Content-Type': 'application/json', }; diff --git a/src/types/index.ts b/src/types/index.ts index b97f035..315d1b5 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,5 +1,6 @@ export interface Resource { id: string; + resourceId: string; name: string; description?: string; location?: string; @@ -10,16 +11,26 @@ export interface Resource { } export interface Reservation { - id: string; + id?: string; + referenceNumber?: string; resourceId: string; - resource: Resource; + resourceName: string; + resource?: Resource; userId: string; - startTime: Date; - endTime: Date; + firstName?: string; + lastName?: string; + startTime: Date | string; + endTime: Date | string; + startDate: string; + endDate: string; title: string; description?: string; status: 'pending' | 'confirmed' | 'cancelled'; - createdAt: Date; + requiresApproval?: boolean; + isRecurring?: boolean; + duration?: string; + participants?: any[]; + createdAt?: Date | string; } export interface User { @@ -31,11 +42,10 @@ export interface User { export interface CreateReservationRequest { resourceId: string; - startDateTime: string; // Match field name from LibreBooking API - endDateTime: string; // Match field name from LibreBooking API + startDateTime: string; + endDateTime: string; title: string; description?: string; - userId?: string; // Allow null initially - allowParticipation?: boolean; - termsAccepted?: boolean; + allowParticipation: boolean; + termsAccepted: boolean; } \ No newline at end of file