fix: Live Courts data structure and status naming
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -135,7 +135,7 @@ export default function LiveCourtsPage() {
|
|||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (!response.ok) throw new Error("Failed to load court data");
|
if (!response.ok) throw new Error("Failed to load court data");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setCourts(data.courts ?? data.data ?? []);
|
setCourts(Array.isArray(data) ? data : data.courts ?? data.data ?? []);
|
||||||
setLastUpdated(new Date());
|
setLastUpdated(new Date());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Live courts fetch error:", err);
|
console.error("Live courts fetch error:", err);
|
||||||
|
|||||||
@@ -63,26 +63,46 @@ export async function GET(request: NextRequest) {
|
|||||||
orderBy: { displayOrder: 'asc' },
|
orderBy: { displayOrder: 'asc' },
|
||||||
});
|
});
|
||||||
|
|
||||||
// Compute status for each court
|
// Compute status for each court and transform to frontend shape
|
||||||
const courtsWithStatus = courts.map((court) => {
|
const courtsWithStatus = courts.map((court) => {
|
||||||
let status: 'available' | 'active' | 'open-play' | 'booked';
|
let status: 'available' | 'active' | 'open_play' | 'booked';
|
||||||
|
|
||||||
if (court.sessions.length > 0) {
|
if (court.sessions.length > 0) {
|
||||||
// Court has active sessions
|
status = court.isOpenPlay ? 'open_play' : 'active';
|
||||||
if (court.isOpenPlay) {
|
} else if (court.isOpenPlay) {
|
||||||
status = 'open-play';
|
status = 'open_play';
|
||||||
} else {
|
|
||||||
status = 'active';
|
|
||||||
}
|
|
||||||
} else if (court.bookings.length > 0) {
|
} else if (court.bookings.length > 0) {
|
||||||
status = 'booked';
|
status = 'booked';
|
||||||
} else {
|
} else {
|
||||||
status = 'available';
|
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 {
|
return {
|
||||||
...court,
|
id: court.id,
|
||||||
|
name: court.name,
|
||||||
|
type: court.type,
|
||||||
|
isOpenPlay: court.isOpenPlay,
|
||||||
status,
|
status,
|
||||||
|
players,
|
||||||
|
upcomingBooking,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user