cleanup
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import React, { useEffect, useState, FormEvent, useCallback } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useAuth } from '@/lib/auth/AuthContext';
|
||||
import {
|
||||
FileText,
|
||||
Users,
|
||||
@@ -23,13 +24,8 @@ import Heading from '@/components/ui/Heading';
|
||||
import LeagueReviewSummary from '@/components/leagues/LeagueReviewSummary';
|
||||
import Input from '@/components/ui/Input';
|
||||
|
||||
import {
|
||||
validateLeagueWizardStep,
|
||||
validateAllLeagueWizardSteps,
|
||||
hasWizardErrors,
|
||||
createLeagueFromConfig,
|
||||
applyScoringPresetToConfig,
|
||||
} from '@/lib/leagueWizardService';
|
||||
import { LeagueWizardCommandModel } from '@/lib/command-models/leagues/LeagueWizardCommandModel';
|
||||
import { LeagueWizardService } from '@/lib/services/leagues/LeagueWizardService';
|
||||
import type { LeagueScoringPresetDTO } from '@core/racing/application/ports/LeagueScoringPresetProvider';
|
||||
import type { LeagueConfigFormModel } from '@core/racing/application';
|
||||
import { LeagueBasicsSection } from './LeagueBasicsSection';
|
||||
@@ -156,7 +152,7 @@ function stepToStepName(step: Step): StepName {
|
||||
}
|
||||
}
|
||||
|
||||
import type { WizardErrors } from '@/lib/leagueWizardService';
|
||||
import { WizardErrors } from '@/lib/types/WizardErrors';
|
||||
|
||||
function getDefaultSeasonStartDate(): string {
|
||||
// Default to next Saturday
|
||||
@@ -241,6 +237,7 @@ function createDefaultForm(): LeagueWizardFormModel {
|
||||
|
||||
export default function CreateLeagueWizard({ stepName, onStepChange }: CreateLeagueWizardProps) {
|
||||
const router = useRouter();
|
||||
const { session } = useAuth();
|
||||
|
||||
const step = stepNameToStep(stepName);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -314,12 +311,12 @@ export default function CreateLeagueWizard({ stepName, onStepChange }: CreateLea
|
||||
}, []);
|
||||
|
||||
const validateStep = (currentStep: Step): boolean => {
|
||||
const stepErrors = validateLeagueWizardStep(form, currentStep);
|
||||
const stepErrors = LeagueWizardCommandModel.validateLeagueWizardStep(form, currentStep);
|
||||
setErrors((prev) => ({
|
||||
...prev,
|
||||
...stepErrors,
|
||||
}));
|
||||
return !hasWizardErrors(stepErrors);
|
||||
return !LeagueWizardCommandModel.hasWizardErrors(stepErrors);
|
||||
};
|
||||
|
||||
const goToNextStep = () => {
|
||||
@@ -348,13 +345,22 @@ export default function CreateLeagueWizard({ stepName, onStepChange }: CreateLea
|
||||
event.preventDefault();
|
||||
if (loading) return;
|
||||
|
||||
const allErrors = validateAllLeagueWizardSteps(form);
|
||||
const ownerId = session?.user.userId;
|
||||
if (!ownerId) {
|
||||
setErrors((prev) => ({
|
||||
...prev,
|
||||
submit: 'You must be logged in to create a league',
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
const allErrors = LeagueWizardCommandModel.validateAllLeagueWizardSteps(form);
|
||||
setErrors((prev) => ({
|
||||
...prev,
|
||||
...allErrors,
|
||||
}));
|
||||
|
||||
if (hasWizardErrors(allErrors)) {
|
||||
if (LeagueWizardCommandModel.hasWizardErrors(allErrors)) {
|
||||
onStepChange('basics');
|
||||
return;
|
||||
}
|
||||
@@ -366,7 +372,7 @@ export default function CreateLeagueWizard({ stepName, onStepChange }: CreateLea
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await createLeagueFromConfig(form);
|
||||
const result = await LeagueWizardService.createLeagueFromConfig(form, ownerId);
|
||||
// Clear the draft on successful creation
|
||||
clearFormStorage();
|
||||
router.push(`/leagues/${result.leagueId}`);
|
||||
@@ -386,7 +392,7 @@ export default function CreateLeagueWizard({ stepName, onStepChange }: CreateLea
|
||||
|
||||
// Handler for scoring preset selection - delegates to application-level config helper
|
||||
const handleScoringPresetChange = (patternId: string) => {
|
||||
setForm((prev) => applyScoringPresetToConfig(prev, patternId));
|
||||
setForm((prev) => LeagueWizardCommandModel.applyScoringPresetToConfig(prev, patternId));
|
||||
};
|
||||
|
||||
const steps = [
|
||||
|
||||
Reference in New Issue
Block a user