working dashboard again
This commit is contained in:
parent
af49dea1d6
commit
ec7f07d788
@ -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 = () => {
|
||||
>
|
||||
<option value="">Select a resource...</option>
|
||||
{resources.map(resource => (
|
||||
<option key={resource.id} value={resource.id}>
|
||||
<option key={resource.resourceId} value={resource.resourceId}>
|
||||
{resource.name} ({resource.capacity ? `Capacity: ${resource.capacity}` : 'No capacity limit'})
|
||||
</option>
|
||||
))}
|
||||
|
||||
@ -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}
|
||||
</h4>
|
||||
<div style={{ color: '#666', fontSize: '0.875rem' }}>
|
||||
{reservation.resource.name}
|
||||
{reservation.resourceName}
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
@ -250,8 +258,7 @@ const UserDashboard: React.FC = () => {
|
||||
{reservation.title}
|
||||
</h4>
|
||||
<div style={{ color: '#666', fontSize: '0.875rem' }}>
|
||||
{reservation.resource.name}
|
||||
{reservation.resource.location && ` • ${reservation.resource.location}`}
|
||||
{reservation.resourceName}
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
@ -280,7 +287,7 @@ const UserDashboard: React.FC = () => {
|
||||
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<div style={{ color: '#888', fontSize: '0.75rem' }}>
|
||||
Booked on {format(new Date(reservation.createdAt), 'MMM d, yyyy')}
|
||||
Booked on {reservation.startDate ? format(new Date(reservation.startDate), 'MMM d, yyyy') : 'Unknown date'}
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: '0.5rem' }}>
|
||||
|
||||
@ -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<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
@ -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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user