From 447b2125a82550d7d372dd70ffba7353ff36c96c Mon Sep 17 00:00:00 2001 From: Guillermo Pages Date: Sat, 6 Dec 2025 22:27:55 +0100 Subject: [PATCH] feat: add default stage configs when creating competitions from scratch When creating a competition without a template, the modal now provides sensible default configurations for each competition type: - league: round_robin stage with standard points (3/1/0) - tournament: single_elimination stage - challenge: rating_delta_challenge stage with sum metric (leaderboard) - hybrid: group stage + knockout stage This ensures stages are created automatically instead of leaving competitions with 'No stages configured yet'. --- .../competitions/CreateCompetitionModal.tsx | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/app/[locale]/admin/facilities/[facility_id]/competitions/CreateCompetitionModal.tsx b/src/app/[locale]/admin/facilities/[facility_id]/competitions/CreateCompetitionModal.tsx index fb79af5..7f23490 100644 --- a/src/app/[locale]/admin/facilities/[facility_id]/competitions/CreateCompetitionModal.tsx +++ b/src/app/[locale]/admin/facilities/[facility_id]/competitions/CreateCompetitionModal.tsx @@ -59,6 +59,62 @@ const visibilityOptions: { value: CompetitionVisibility; label: string; descript { value: 'private', label: 'Private', description: 'Invite only' }, ]; +// Default configs for each competition type when creating from scratch +const defaultConfigs: Record> = { + league: { + format: { + stages: [ + { + type: 'round_robin', + name: 'League Stage', + rounds: 1, + points_win: 3, + points_draw: 1, + points_loss: 0, + }, + ], + }, + }, + tournament: { + format: { + stages: [ + { + type: 'single_elimination', + name: 'Main Draw', + third_place_match: false, + }, + ], + }, + }, + challenge: { + format: { + stages: [ + { + type: 'rating_delta_challenge', + name: 'Leaderboard', + metric: 'rating_delta_sum', // Total rating gained + // Alternative metrics: 'rating_delta_avg', 'rating_delta_max', 'matches_played' + }, + ], + }, + }, + hybrid: { + format: { + stages: [ + { + type: 'round_robin', + name: 'Group Stage', + rounds: 1, + }, + { + type: 'single_elimination', + name: 'Knockout Stage', + }, + ], + }, + }, +}; + export default function CreateCompetitionModal({ isOpen, onClose, @@ -144,6 +200,9 @@ export default function CreateCompetitionModal({ return; } + // Use template config if selected, otherwise use default config for the type + const config = selectedTemplate?.config ?? defaultConfigs[formData.type]; + const request: CreateCompetitionRequest = { type: formData.type, sport_id: formData.sport_id, @@ -159,7 +218,7 @@ export default function CreateCompetitionModal({ ? new Date(formData.registration_close_at).toISOString() : undefined, template_id: selectedTemplate?.template_id, - config: selectedTemplate?.config, + config, }; try {