This commit is contained in:
2025-12-04 23:31:55 +01:00
parent 9fa21a488a
commit fb509607c1
96 changed files with 5839 additions and 1609 deletions

View File

@@ -4,7 +4,8 @@ import { useState } from 'react';
import { useRouter } from 'next/navigation';
import Button from '@/components/ui/Button';
import Input from '@/components/ui/Input';
import { createTeam, getCurrentDriverId } from '@/lib/racingLegacyFacade';
import { getCreateTeamUseCase } from '@/lib/di-container';
import { useEffectiveDriverId } from '@/lib/currentDriver';
interface CreateTeamFormProps {
onCancel?: () => void;
@@ -20,6 +21,7 @@ export default function CreateTeamForm({ onCancel, onSuccess }: CreateTeamFormPr
});
const [errors, setErrors] = useState<Record<string, string>>({});
const [submitting, setSubmitting] = useState(false);
const currentDriverId = useEffectiveDriverId();
const validateForm = () => {
const newErrors: Record<string, string> = {};
@@ -56,18 +58,21 @@ export default function CreateTeamForm({ onCancel, onSuccess }: CreateTeamFormPr
setSubmitting(true);
try {
getCurrentDriverId(); // ensure identity initialized
const team = createTeam({
const useCase = getCreateTeamUseCase();
const result = await useCase.execute({
name: formData.name,
tag: formData.tag.toUpperCase(),
description: formData.description,
ownerId: currentDriverId,
leagues: [],
});
const teamId = result.team.id;
if (onSuccess) {
onSuccess(team.id);
onSuccess(teamId);
} else {
router.push(`/teams/${team.id}`);
router.push(`/teams/${teamId}`);
}
} catch (error) {
alert(error instanceof Error ? error.message : 'Failed to create team');