Version 1.0 - Stable
This commit is contained in:
@@ -6,9 +6,64 @@ import { Event, EventRegistration } from '@/types/racing';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { TrophyIcon, MapPinIcon, UsersIcon, ClockIcon, CalendarIcon } from '@/components/ui/icons';
|
||||
import EventRegistrationForm from '@/components/events/EventRegistrationForm';
|
||||
import EventResultClient from '@/components/events/EventResultsClient';
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
async function getEventResults(eventId: number) {
|
||||
|
||||
if (eventId == undefined) {
|
||||
return { event: null, standings: [] };
|
||||
}
|
||||
// Get event info
|
||||
const eventSql = `
|
||||
SELECT
|
||||
event_id,
|
||||
event_name,
|
||||
event_track,
|
||||
event_date,
|
||||
event_status
|
||||
FROM events
|
||||
WHERE event_id = $1
|
||||
`;
|
||||
const events = await query(eventSql, [String(eventId)]);
|
||||
const event = events[0];
|
||||
|
||||
// Get team standings with driver details
|
||||
const standingsSql = `
|
||||
SELECT
|
||||
tcs.team_id,
|
||||
t.name as team_name,
|
||||
tcs.total_points,
|
||||
tcs.races_participated,
|
||||
tcs.best_finish,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'driver_guid', u.driver_guid,
|
||||
'driver_name', u.driver_name,
|
||||
'position', er.position,
|
||||
'points_awarded', er.points_awarded,
|
||||
'laps_completed', er.laps_completed,
|
||||
'dnf', er.dnf
|
||||
) ORDER BY er.position ASC
|
||||
) as drivers
|
||||
FROM team_championship_standings tcs
|
||||
JOIN teams t ON tcs.team_id = t.id
|
||||
LEFT JOIN event_results er ON tcs.event_id = er.event_id AND tcs.team_id = er.team_id
|
||||
LEFT JOIN users u ON er.driver_guid = u.driver_guid
|
||||
WHERE tcs.event_id = $1
|
||||
GROUP BY tcs.team_id, t.name, tcs.total_points, tcs.races_participated, tcs.best_finish
|
||||
ORDER BY tcs.total_points DESC, tcs.best_finish ASC
|
||||
`;
|
||||
|
||||
const standings = await query(standingsSql, [eventId]);
|
||||
|
||||
return { event, standings };
|
||||
}
|
||||
|
||||
|
||||
async function getEvent(eventId: number): Promise<Event | null> {
|
||||
const sql = `
|
||||
const sql = `
|
||||
SELECT e.*, COUNT(er.registration_id) as registrations_count
|
||||
FROM events e
|
||||
LEFT JOIN event_registrations er ON e.event_id = er.event_id AND er.status = 'REGISTERED'
|
||||
@@ -49,19 +104,21 @@ function formatDate(date: Date): string {
|
||||
export default async function EventDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ event_id: string }>;
|
||||
params: Promise<{ event_id: number }>;
|
||||
}) {
|
||||
const { event_id } = await params;
|
||||
|
||||
const eventId = parseInt(event_id, 10);
|
||||
|
||||
const event: any = await getEvent(eventId);
|
||||
const event: any = await getEvent(event_id);
|
||||
if (!event) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const registrations = await getEventRegistrations(eventId);
|
||||
const registrations = await getEventRegistrations(event_id);
|
||||
|
||||
// Fetch initial event results/standings
|
||||
|
||||
const { standings } = await getEventResults(event_id);
|
||||
|
||||
|
||||
const isOpen = event.event_status === 'OPEN';
|
||||
const isFull = event.registrations_count >= event.max_participants;
|
||||
const deadlinePassed = event.registration_deadline && new Date(event.registration_deadline) < new Date();
|
||||
@@ -118,6 +175,12 @@ export default async function EventDetailPage({
|
||||
{deadlinePassed && !isFull && 'Registration deadline has passed.'}
|
||||
{event.event_status === 'CLOSED' && !isFull && !deadlinePassed && 'Registration is closed for this event.'}
|
||||
</p>
|
||||
<div className="mt-6">
|
||||
<EventResultClient
|
||||
eventId={event_id}
|
||||
initialStandings={standings}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user