refactor page to use services

This commit is contained in:
2025-12-18 17:02:48 +01:00
parent fc386db06a
commit 9814d9682c
27 changed files with 434 additions and 282 deletions

View File

@@ -4,7 +4,7 @@ import Button from '@/components/ui/Button';
import Card from '@/components/ui/Card';
import { useEffectiveDriverId } from '@/hooks/useEffectiveDriverId';
import { isLeagueAdminOrHigherRole } from '@/lib/leagueRoles';
import { ServiceFactory } from '@/lib/services/ServiceFactory';
import { useServices } from '@/lib/services/ServiceProvider';
import { ProtestViewModel } from '@/lib/view-models/ProtestViewModel';
import { ProtestDecisionCommandModel, type PenaltyType } from '@/lib/command-models/protests/ProtestDecisionCommandModel';
import type { DriverSummaryDTO } from '@/lib/types/generated/LeagueAdminProtestsDTO';
@@ -114,6 +114,7 @@ export default function ProtestReviewPage() {
const leagueId = params.id as string;
const protestId = params.protestId as string;
const currentDriverId = useEffectiveDriverId();
const { protestService } = useServices();
const [protest, setProtest] = useState<ProtestViewModel | null>(null);
const [race, setRace] = useState<RaceDTO | null>(null);
@@ -146,9 +147,6 @@ export default function ProtestReviewPage() {
async function loadProtest() {
setLoading(true);
try {
const serviceFactory = new ServiceFactory(process.env.NEXT_PUBLIC_API_URL || '');
const protestService = serviceFactory.createProtestService();
const protestData = await protestService.getProtestById(leagueId, protestId);
if (!protestData) {
throw new Error('Protest not found');
@@ -212,9 +210,6 @@ export default function ProtestReviewPage() {
setSubmitting(true);
try {
const serviceFactory = new ServiceFactory(process.env.NEXT_PUBLIC_API_URL || '');
const protestService = serviceFactory.createProtestService();
if (decision === 'uphold') {
const commandModel = new ProtestDecisionCommandModel({
decision,
@@ -264,9 +259,6 @@ export default function ProtestReviewPage() {
if (!protest) return;
try {
const serviceFactory = new ServiceFactory(process.env.NEXT_PUBLIC_API_URL || '');
const protestService = serviceFactory.createProtestService();
// Request defense
await protestService.requestDefense({
protestId: protest.id,