move static data
This commit is contained in:
@@ -22,9 +22,10 @@ import {
|
||||
Users,
|
||||
} from 'lucide-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { FormEvent, useCallback, useEffect, useState } from 'react';
|
||||
import { FormEvent, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { LeagueWizardCommandModel } from '@/lib/command-models/leagues/LeagueWizardCommandModel';
|
||||
|
||||
import { useCreateLeagueWizard } from '@/hooks/useLeagueWizardService';
|
||||
import { useLeagueScoringPresets } from '@/hooks/useLeagueScoringPresets';
|
||||
import { LeagueBasicsSection } from './LeagueBasicsSection';
|
||||
@@ -494,78 +495,29 @@ export default function CreateLeagueWizard({ stepName, onStepChange }: CreateLea
|
||||
}
|
||||
};
|
||||
|
||||
// Handler for scoring preset selection - delegates to application-level config helper
|
||||
// Handler for scoring preset selection (timings default from API)
|
||||
const handleScoringPresetChange = (patternId: string) => {
|
||||
setForm((prev) => {
|
||||
// Convert to LeagueWizardFormData for the command model
|
||||
const formData: any = {
|
||||
leagueId: prev.leagueId || '',
|
||||
basics: {
|
||||
name: prev.basics?.name || '',
|
||||
description: prev.basics?.description || '',
|
||||
visibility: (prev.basics?.visibility as 'public' | 'private' | 'unlisted') || 'public',
|
||||
gameId: prev.basics?.gameId || 'iracing',
|
||||
},
|
||||
structure: {
|
||||
mode: (prev.structure?.mode as 'solo' | 'fixedTeams') || 'solo',
|
||||
maxDrivers: prev.structure?.maxDrivers || 24,
|
||||
maxTeams: prev.structure?.maxTeams || 0,
|
||||
driversPerTeam: prev.structure?.driversPerTeam || 0,
|
||||
},
|
||||
championships: {
|
||||
enableDriverChampionship: prev.championships?.enableDriverChampionship ?? true,
|
||||
enableTeamChampionship: prev.championships?.enableTeamChampionship ?? false,
|
||||
enableNationsChampionship: prev.championships?.enableNationsChampionship ?? false,
|
||||
enableTrophyChampionship: prev.championships?.enableTrophyChampionship ?? false,
|
||||
},
|
||||
scoring: {
|
||||
patternId: prev.scoring?.patternId,
|
||||
customScoringEnabled: prev.scoring?.customScoringEnabled ?? false,
|
||||
},
|
||||
dropPolicy: {
|
||||
strategy: (prev.dropPolicy?.strategy as 'none' | 'bestNResults' | 'dropWorstN') || 'bestNResults',
|
||||
n: prev.dropPolicy?.n || 6,
|
||||
},
|
||||
timings: {
|
||||
practiceMinutes: prev.timings?.practiceMinutes || 0,
|
||||
qualifyingMinutes: prev.timings?.qualifyingMinutes || 0,
|
||||
sprintRaceMinutes: prev.timings?.sprintRaceMinutes || 0,
|
||||
mainRaceMinutes: prev.timings?.mainRaceMinutes || 0,
|
||||
sessionCount: prev.timings?.sessionCount || 0,
|
||||
roundsPlanned: prev.timings?.roundsPlanned || 0,
|
||||
raceDayOfWeek: prev.timings?.raceDayOfWeek || 0,
|
||||
raceTimeUtc: prev.timings?.raceTimeUtc || '',
|
||||
weekdays: (prev.timings?.weekdays as Weekday[]) || [],
|
||||
recurrenceStrategy: prev.timings?.recurrenceStrategy || '',
|
||||
timezoneId: prev.timings?.timezoneId || '',
|
||||
seasonStartDate: prev.timings?.seasonStartDate || '',
|
||||
},
|
||||
stewarding: {
|
||||
decisionMode: (prev.stewarding?.decisionMode as 'owner_only' | 'admin_vote' | 'steward_panel') || 'admin_only',
|
||||
requiredVotes: prev.stewarding?.requiredVotes || 2,
|
||||
requireDefense: prev.stewarding?.requireDefense ?? false,
|
||||
defenseTimeLimit: prev.stewarding?.defenseTimeLimit || 48,
|
||||
voteTimeLimit: prev.stewarding?.voteTimeLimit || 72,
|
||||
protestDeadlineHours: prev.stewarding?.protestDeadlineHours || 48,
|
||||
stewardingClosesHours: prev.stewarding?.stewardingClosesHours || 168,
|
||||
notifyAccusedOnProtest: prev.stewarding?.notifyAccusedOnProtest ?? true,
|
||||
notifyOnVoteRequired: prev.stewarding?.notifyOnVoteRequired ?? true,
|
||||
},
|
||||
};
|
||||
const selectedPreset = presets.find((p) => p.id === patternId);
|
||||
|
||||
const updated = LeagueWizardCommandModel.applyScoringPresetToConfig(formData, patternId);
|
||||
|
||||
// Convert back to LeagueWizardFormModel
|
||||
return {
|
||||
basics: updated.basics,
|
||||
structure: updated.structure,
|
||||
championships: updated.championships,
|
||||
scoring: updated.scoring,
|
||||
dropPolicy: updated.dropPolicy,
|
||||
timings: updated.timings,
|
||||
stewarding: updated.stewarding,
|
||||
seasonName: prev.seasonName,
|
||||
} as LeagueWizardFormModel;
|
||||
...prev,
|
||||
scoring: {
|
||||
...prev.scoring,
|
||||
patternId,
|
||||
customScoringEnabled: false,
|
||||
},
|
||||
timings: selectedPreset
|
||||
? {
|
||||
...prev.timings,
|
||||
practiceMinutes: prev.timings?.practiceMinutes ?? selectedPreset.defaultTimings.practiceMinutes,
|
||||
qualifyingMinutes: prev.timings?.qualifyingMinutes ?? selectedPreset.defaultTimings.qualifyingMinutes,
|
||||
sprintRaceMinutes: prev.timings?.sprintRaceMinutes ?? selectedPreset.defaultTimings.sprintRaceMinutes,
|
||||
mainRaceMinutes: prev.timings?.mainRaceMinutes ?? selectedPreset.defaultTimings.mainRaceMinutes,
|
||||
sessionCount: selectedPreset.defaultTimings.sessionCount,
|
||||
}
|
||||
: prev.timings,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user