@ -59,6 +59,62 @@ const visibilityOptions: { value: CompetitionVisibility; label: string; descript
{ value : 'private' , label : 'Private' , description : 'Invite only' } ,
{ 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 ( {
export default function CreateCompetitionModal ( {
isOpen ,
isOpen ,
onClose ,
onClose ,
@ -144,6 +200,9 @@ export default function CreateCompetitionModal({
return ;
return ;
}
}
// Use template config if selected, otherwise use default config for the type
const config = selectedTemplate ? . config ? ? defaultConfigs [ formData . type ] ;
const request : CreateCompetitionRequest = {
const request : CreateCompetitionRequest = {
type : formData . type ,
type : formData . type ,
sport_id : formData.sport_id ,
sport_id : formData.sport_id ,
@ -159,7 +218,7 @@ export default function CreateCompetitionModal({
? new Date ( formData . registration_close_at ) . toISOString ( )
? new Date ( formData . registration_close_at ) . toISOString ( )
: undefined ,
: undefined ,
template_id : selectedTemplate?.template_id ,
template_id : selectedTemplate?.template_id ,
config : selectedTemplate?.config ,
config ,
} ;
} ;
try {
try {