diff --git a/apps/web/app/(admin)/live/page.tsx b/apps/web/app/(admin)/live/page.tsx index 807ae02..5511a1d 100644 --- a/apps/web/app/(admin)/live/page.tsx +++ b/apps/web/app/(admin)/live/page.tsx @@ -135,7 +135,7 @@ export default function LiveCourtsPage() { const response = await fetch(url); if (!response.ok) throw new Error("Failed to load court data"); const data = await response.json(); - setCourts(data.courts ?? data.data ?? []); + setCourts(Array.isArray(data) ? data : data.courts ?? data.data ?? []); setLastUpdated(new Date()); } catch (err) { console.error("Live courts fetch error:", err); diff --git a/apps/web/app/api/live/route.ts b/apps/web/app/api/live/route.ts index 1588158..90f17cc 100644 --- a/apps/web/app/api/live/route.ts +++ b/apps/web/app/api/live/route.ts @@ -63,26 +63,46 @@ export async function GET(request: NextRequest) { orderBy: { displayOrder: 'asc' }, }); - // Compute status for each court + // Compute status for each court and transform to frontend shape const courtsWithStatus = courts.map((court) => { - let status: 'available' | 'active' | 'open-play' | 'booked'; + let status: 'available' | 'active' | 'open_play' | 'booked'; if (court.sessions.length > 0) { - // Court has active sessions - if (court.isOpenPlay) { - status = 'open-play'; - } else { - status = 'active'; - } + status = court.isOpenPlay ? 'open_play' : 'active'; + } else if (court.isOpenPlay) { + status = 'open_play'; } else if (court.bookings.length > 0) { status = 'booked'; } else { status = 'available'; } + // Transform sessions to players array for frontend + const players = court.sessions.map((session) => ({ + id: session.client?.id || session.id, + firstName: session.client?.firstName, + lastName: session.client?.lastName, + walkInName: session.walkInName, + checkedInAt: session.startTime.toISOString(), + sessionId: session.id, + })); + + // Get upcoming booking info + const upcomingBooking = court.bookings.length > 0 ? { + startTime: court.bookings[0].startTime.toISOString(), + clientName: court.bookings[0].client + ? `${court.bookings[0].client.firstName} ${court.bookings[0].client.lastName}` + : 'Walk-in', + } : undefined; + return { - ...court, + id: court.id, + name: court.name, + type: court.type, + isOpenPlay: court.isOpenPlay, status, + players, + upcomingBooking, }; });