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}`,
|
endDateTime: `${formData.date}T${formData.endTime}`,
|
||||||
title: formData.title.trim(),
|
title: formData.title.trim(),
|
||||||
description: formData.description.trim() || '',
|
description: formData.description.trim() || '',
|
||||||
userId: apiClient.getUserId() || undefined,
|
allowParticipation: false,
|
||||||
allowParticipation: true,
|
|
||||||
termsAccepted: true
|
termsAccepted: true
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -153,7 +152,7 @@ const CreateReservation: React.FC = () => {
|
|||||||
>
|
>
|
||||||
<option value="">Select a resource...</option>
|
<option value="">Select a resource...</option>
|
||||||
{resources.map(resource => (
|
{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'})
|
{resource.name} ({resource.capacity ? `Capacity: ${resource.capacity}` : 'No capacity limit'})
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -31,20 +31,28 @@ const UserDashboard: React.FC = () => {
|
|||||||
const confirmedReservations = reservations.filter(r => r.status === 'confirmed');
|
const confirmedReservations = reservations.filter(r => r.status === 'confirmed');
|
||||||
|
|
||||||
// Group upcoming reservations
|
// Group upcoming reservations
|
||||||
const upcomingReservations = reservations.filter(r =>
|
const upcomingReservations = reservations.filter(r => {
|
||||||
r.status !== 'cancelled' && new Date(r.endTime) > new Date()
|
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 =>
|
const todayReservations = reservations.filter(r => {
|
||||||
r.status !== 'cancelled' && (
|
if (r.status === 'cancelled') return false;
|
||||||
isToday(new Date(r.startTime)) ||
|
const startTime = r.startTime instanceof Date ? r.startTime : new Date(r.startTime);
|
||||||
isToday(new Date(r.endTime))
|
const endTime = r.endTime instanceof Date ? r.endTime : new Date(r.endTime);
|
||||||
)
|
return isToday(startTime) || isToday(endTime);
|
||||||
);
|
});
|
||||||
|
|
||||||
const getReservationLabel = (reservation: Reservation): string => {
|
const getReservationLabel = (reservation: Reservation): string => {
|
||||||
const startDate = new Date(reservation.startTime);
|
// Handle both string and Date formats for startTime/endTime
|
||||||
const endDate = new Date(reservation.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)) {
|
if (isToday(startDate)) {
|
||||||
return `Today, ${format(startDate, 'h:mm a')} - ${format(endDate, 'h:mm a')}`;
|
return `Today, ${format(startDate, 'h:mm a')} - ${format(endDate, 'h:mm a')}`;
|
||||||
@ -152,7 +160,7 @@ const UserDashboard: React.FC = () => {
|
|||||||
{reservation.title}
|
{reservation.title}
|
||||||
</h4>
|
</h4>
|
||||||
<div style={{ color: '#666', fontSize: '0.875rem' }}>
|
<div style={{ color: '#666', fontSize: '0.875rem' }}>
|
||||||
{reservation.resource.name}
|
{reservation.resourceName}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span
|
<span
|
||||||
@ -250,8 +258,7 @@ const UserDashboard: React.FC = () => {
|
|||||||
{reservation.title}
|
{reservation.title}
|
||||||
</h4>
|
</h4>
|
||||||
<div style={{ color: '#666', fontSize: '0.875rem' }}>
|
<div style={{ color: '#666', fontSize: '0.875rem' }}>
|
||||||
{reservation.resource.name}
|
{reservation.resourceName}
|
||||||
{reservation.resource.location && ` • ${reservation.resource.location}`}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span
|
<span
|
||||||
@ -280,7 +287,7 @@ const UserDashboard: React.FC = () => {
|
|||||||
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||||
<div style={{ color: '#888', fontSize: '0.75rem' }}>
|
<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>
|
||||||
|
|
||||||
<div style={{ display: 'flex', gap: '0.5rem' }}>
|
<div style={{ display: 'flex', gap: '0.5rem' }}>
|
||||||
|
|||||||
@ -169,13 +169,10 @@ export class SimpleLibreBookingClient {
|
|||||||
endDateTime: data.endDateTime,
|
endDateTime: data.endDateTime,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.description || '',
|
description: data.description || '',
|
||||||
userId: this.getUserId() || undefined,
|
allowParticipation: false,
|
||||||
allowParticipation: true,
|
|
||||||
termsAccepted: true
|
termsAccepted: true
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Creating reservation with data:', requestData);
|
|
||||||
|
|
||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
export interface Resource {
|
export interface Resource {
|
||||||
id: string;
|
id: string;
|
||||||
|
resourceId: string;
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
location?: string;
|
location?: string;
|
||||||
@ -10,16 +11,26 @@ export interface Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Reservation {
|
export interface Reservation {
|
||||||
id: string;
|
id?: string;
|
||||||
|
referenceNumber?: string;
|
||||||
resourceId: string;
|
resourceId: string;
|
||||||
resource: Resource;
|
resourceName: string;
|
||||||
|
resource?: Resource;
|
||||||
userId: string;
|
userId: string;
|
||||||
startTime: Date;
|
firstName?: string;
|
||||||
endTime: Date;
|
lastName?: string;
|
||||||
|
startTime: Date | string;
|
||||||
|
endTime: Date | string;
|
||||||
|
startDate: string;
|
||||||
|
endDate: string;
|
||||||
title: string;
|
title: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
status: 'pending' | 'confirmed' | 'cancelled';
|
status: 'pending' | 'confirmed' | 'cancelled';
|
||||||
createdAt: Date;
|
requiresApproval?: boolean;
|
||||||
|
isRecurring?: boolean;
|
||||||
|
duration?: string;
|
||||||
|
participants?: any[];
|
||||||
|
createdAt?: Date | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
@ -31,11 +42,10 @@ export interface User {
|
|||||||
|
|
||||||
export interface CreateReservationRequest {
|
export interface CreateReservationRequest {
|
||||||
resourceId: string;
|
resourceId: string;
|
||||||
startDateTime: string; // Match field name from LibreBooking API
|
startDateTime: string;
|
||||||
endDateTime: string; // Match field name from LibreBooking API
|
endDateTime: string;
|
||||||
title: string;
|
title: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
userId?: string; // Allow null initially
|
allowParticipation: boolean;
|
||||||
allowParticipation?: boolean;
|
termsAccepted: boolean;
|
||||||
termsAccepted?: boolean;
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user