website refactor

This commit is contained in:
2026-01-19 12:35:16 +01:00
parent a8731e6937
commit 15290400b3
122 changed files with 902 additions and 255 deletions

View File

@@ -5,14 +5,14 @@ import { ApiError } from '@/lib/api/base/ApiError';
import { CreateLeagueInputDTO } from '@/lib/types/generated/CreateLeagueInputDTO';
import { CreateLeagueOutputDTO } from '@/lib/types/generated/CreateLeagueOutputDTO';
interface CreateLeagueInput {
export interface CreateLeagueInput {
name: string;
description: string;
maxDrivers: number;
scoringPresetId: string;
}
interface CreateLeagueResult {
export interface CreateLeagueResult {
success: boolean;
leagueId: string;
error?: string;

View File

@@ -22,9 +22,13 @@ export function useLeagueDetail({ leagueId, queryOptions }: UseLeagueDetailOptio
return useQuery<LeagueWithCapacityAndScoringDTO, ApiError>({
queryKey: ['league-detail', leagueId],
queryFn: async () => {
const result = await leagueService.getAllLeagues() as AllLeaguesWithCapacityAndScoringDTO;
const result = await leagueService.getAllLeagues();
if (result.isErr()) {
throw result.getError();
}
const data = result.unwrap();
// Filter for the specific league
const leagues = Array.isArray(result?.leagues) ? result.leagues : [];
const leagues = Array.isArray(data?.leagues) ? data.leagues : [];
const league = leagues.find(l => l.id === leagueId);
if (!league) {
throw new ApiError('League not found', 'NOT_FOUND', {
@@ -46,8 +50,11 @@ export function useLeagueMemberships({ leagueId, queryOptions }: UseLeagueMember
queryKey: ['league-memberships', leagueId],
queryFn: async () => {
const result = await leagueService.getLeagueMemberships(leagueId);
if (result.isErr()) {
throw result.getError();
}
// The DTO already has the correct structure with members property
return result;
return result.unwrap();
},
...queryOptions,
});

View File

@@ -9,7 +9,7 @@ export function useLeagueSponsorshipsPageData(leagueId: string, currentDriverId:
return usePageDataMultiple({
league: {
queryKey: ['leagueDetail', leagueId, currentDriverId],
queryFn: () => leagueService.getLeagueDetail(leagueId),
queryFn: () => leagueService.getLeagueDetailData(leagueId),
},
membership: {
queryKey: ['leagueMembership', leagueId, currentDriverId],

View File

@@ -17,25 +17,24 @@ export function useLeagueWalletPageData(leagueId: string) {
// Transform DTO to ViewModel at client boundary
const transactions = dto.transactions.map(t => new WalletTransactionViewModel({
id: t.id,
type: t.type,
type: t.type as any,
description: t.description,
amount: t.amount,
fee: t.fee,
netAmount: t.netAmount,
date: new globalThis.Date(t.date),
fee: 0,
netAmount: t.amount,
date: new globalThis.Date(t.createdAt),
status: t.status,
reference: t.reference,
}));
return new LeagueWalletViewModel({
balance: dto.balance,
currency: dto.currency,
totalRevenue: dto.totalRevenue,
totalFees: dto.totalFees,
totalWithdrawals: dto.totalWithdrawals,
pendingPayouts: dto.pendingPayouts,
totalRevenue: dto.balance, // Fallback
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
transactions,
canWithdraw: dto.canWithdraw,
withdrawalBlockReason: dto.withdrawalBlockReason,
canWithdraw: true,
withdrawalBlockReason: undefined,
});
},
enabled: !!leagueId,