website cleanup

This commit is contained in:
2025-12-24 13:04:18 +01:00
parent 5e491d9724
commit a7aee42409
69 changed files with 1624 additions and 938 deletions

View File

@@ -4,7 +4,8 @@ import { useState, FormEvent } from 'react';
import { useRouter } from 'next/navigation';
import Input from '../ui/Input';
import Button from '../ui/Button';
import { League } from '@core/racing/domain/entities/League';
import { useServices } from '@/lib/services/ServiceProvider';
import { useAuth } from '@/lib/auth/AuthContext';
interface FormErrors {
name?: string;
@@ -49,6 +50,9 @@ export default function CreateLeagueForm() {
return Object.keys(newErrors).length === 0;
};
const { session } = useAuth();
const { driverService, leagueService } = useServices();
const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
@@ -56,12 +60,16 @@ export default function CreateLeagueForm() {
if (!validateForm()) return;
if (!session?.user.userId) {
setErrors({ submit: 'You must be logged in to create a league' });
return;
}
setLoading(true);
try {
const driverRepo = getDriverRepository();
const drivers = await driverRepo.findAll();
const currentDriver = drivers[0];
// Get current driver
const currentDriver = await driverService.getDriverProfile(session.user.userId);
if (!currentDriver) {
setErrors({ submit: 'No driver profile found. Please create a profile first.' });
@@ -69,22 +77,16 @@ export default function CreateLeagueForm() {
return;
}
const leagueRepo = getLeagueRepository();
const league = League.create({
id: crypto.randomUUID(),
// Create league using the league service
const input = {
name: formData.name.trim(),
description: formData.description.trim(),
ownerId: currentDriver.id,
settings: {
pointsSystem: formData.pointsSystem,
sessionDuration: formData.sessionDuration,
qualifyingFormat: 'open',
},
});
visibility: 'public' as const,
ownerId: session.user.userId,
};
await leagueRepo.create(league);
router.push(`/leagues/${league.id}`);
const result = await leagueService.createLeague(input);
router.push(`/leagues/${result.leagueId}`);
router.refresh();
} catch (error) {
setErrors({