Skip to content

Commit

Permalink
Fix VehicleScheduler for empty bookings
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Jan 23, 2025
1 parent 45afab7 commit 8b29abd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/src/components/VehicleScheduler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const VehicleScheduler = (
}, [filterFromProps])

const fetchBookings = useCallback(async (query: RemoteQuery): Promise<ProcessedEvent[]> => {
const emptyEvents: ProcessedEvent[] = [
{
event_id: '1',
title: 'Dummy Event',
start: new Date(1970, 0, 1),
end: new Date(1970, 0, 2),
}
]
const payload: bookcarsTypes.GetBookingsPayload = {
suppliers,
statuses,
Expand All @@ -55,9 +63,10 @@ const VehicleScheduler = (
const _data = data && data.length > 0 ? data[0] : { pageInfo: { totalRecord: 0 }, resultData: [] }
if (!_data) {
helper.error()
return []
return emptyEvents
}
const bookings = _data.resultData

const events = bookings.map((booking): ProcessedEvent => ({
event_id: booking._id as string,
title: `${(booking.car as bookcarsTypes.Car).name} / ${(booking.supplier as bookcarsTypes.User).fullName} / ${helper.getBookingStatus(booking.status)}`,
Expand All @@ -67,6 +76,10 @@ const VehicleScheduler = (
textColor: helper.getBookingStatusTextColor(booking.status),
}))
setInit(false)

if (events.length === 0) {
return emptyEvents
}
return events
}, [filter, statuses, suppliers, user])

Expand Down

0 comments on commit 8b29abd

Please sign in to comment.