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'.
master
Guillermo Pages 1 week ago
parent fbf4bdd55b
commit 447b2125a8

@ -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<CompetitionType, Record<string, unknown>> = {
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 {

Loading…
Cancel
Save