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

@@ -12,7 +12,7 @@ import type {
ProfileOverviewAchievementViewModel,
ProfileOverviewSocialHandleViewModel,
ProfileOverviewViewModel
} from '@core/racing/application/presenters/IProfileOverviewPresenter';
} from '@/lib/view-models/ProfileOverviewViewModel';
import {
Activity,
Award,

View File

@@ -9,7 +9,7 @@ import { useCallback, useEffect, useState } from 'react';
import { useEffectiveDriverId } from '@/hooks/useEffectiveDriverId';
import { isLeagueAdminOrHigherRole } from '@/lib/leagueRoles';
import { PendingSponsorshipRequestsPresenter } from '@/lib/presenters/PendingSponsorshipRequestsPresenter';
import { useServices } from '@/lib/services/ServiceProvider';
import { AlertTriangle, Building, ChevronRight, Handshake, Trophy, User, Users } from 'lucide-react';
import Link from 'next/link';
@@ -31,27 +31,22 @@ export default function SponsorshipRequestsPage() {
const loadAllRequests = useCallback(async () => {
setLoading(true);
setError(null);
try {
const { sponsorshipService } = useServices();
const driverRepo = getDriverRepository();
const leagueRepo = getLeagueRepository();
const teamRepo = getTeamRepository();
const leagueMembershipRepo = getLeagueMembershipRepository();
const teamMembershipRepo = getTeamMembershipRepository();
const useCase = getGetPendingSponsorshipRequestsUseCase();
const allSections: EntitySection[] = [];
// 1. Driver's own sponsorship requests
const driverPresenter = new PendingSponsorshipRequestsPresenter();
await useCase.execute(
{
entityType: 'driver',
entityId: currentDriverId,
},
driverPresenter,
);
const driverResult = driverPresenter.getViewModel();
const driverResult = await sponsorshipService.getPendingSponsorshipRequests({
entityType: 'driver',
entityId: currentDriverId,
});
if (driverResult && driverResult.requests.length > 0) {
const driver = await driverRepo.findById(currentDriverId);
@@ -71,15 +66,10 @@ export default function SponsorshipRequestsPage() {
// Load sponsorship requests for this league's active season
try {
// For simplicity, we'll query by season entityType - in production you'd get the active season ID
const leaguePresenter = new PendingSponsorshipRequestsPresenter();
await useCase.execute(
{
entityType: 'season',
entityId: league.id, // Using league ID as a proxy for now
},
leaguePresenter,
);
const leagueResult = leaguePresenter.getViewModel();
const leagueResult = await sponsorshipService.getPendingSponsorshipRequests({
entityType: 'season',
entityId: league.id, // Using league ID as a proxy for now
});
if (leagueResult && leagueResult.requests.length > 0) {
allSections.push({
@@ -100,15 +90,10 @@ export default function SponsorshipRequestsPage() {
for (const team of allTeams) {
const membership = await teamMembershipRepo.getMembership(team.id, currentDriverId);
if (membership && (membership.role === 'owner' || membership.role === 'manager')) {
const teamPresenter = new PendingSponsorshipRequestsPresenter();
await useCase.execute(
{
entityType: 'team',
entityId: team.id,
},
teamPresenter,
);
const teamResult = teamPresenter.getViewModel();
const teamResult = await sponsorshipService.getPendingSponsorshipRequests({
entityType: 'team',
entityId: team.id,
});
if (teamResult && teamResult.requests.length > 0) {
allSections.push({