website refactor
This commit is contained in:
@@ -10,7 +10,13 @@ export function useForgotPassword(
|
||||
const authService = useInject(AUTH_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<{ message: string; magicLink?: string }, ApiError, ForgotPasswordDTO>({
|
||||
mutationFn: (params) => authService.forgotPassword(params),
|
||||
mutationFn: async (params) => {
|
||||
const result = await authService.forgotPassword(params);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -11,7 +11,13 @@ export function useLogin(
|
||||
const authService = useInject(AUTH_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<SessionViewModel, ApiError, LoginParamsDTO>({
|
||||
mutationFn: (params) => authService.login(params),
|
||||
mutationFn: async (params) => {
|
||||
const result = await authService.login(params);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -10,7 +10,13 @@ export function useResetPassword(
|
||||
const authService = useInject(AUTH_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<{ message: string }, ApiError, ResetPasswordDTO>({
|
||||
mutationFn: (params) => authService.resetPassword(params),
|
||||
mutationFn: async (params) => {
|
||||
const result = await authService.resetPassword(params);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -11,7 +11,13 @@ export function useSignup(
|
||||
const authService = useInject(AUTH_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<SessionViewModel, ApiError, SignupParamsDTO>({
|
||||
mutationFn: (params) => authService.signup(params),
|
||||
mutationFn: async (params) => {
|
||||
const result = await authService.signup(params);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -17,7 +17,10 @@ export function useDriverProfilePageData(driverId: string) {
|
||||
queryFn: async () => {
|
||||
if (!driverId) return [];
|
||||
|
||||
const allTeams = await teamService.getAllTeams();
|
||||
const allTeamsResult = await teamService.getAllTeams();
|
||||
if (allTeamsResult.isErr()) return [];
|
||||
const allTeams = allTeamsResult.unwrap();
|
||||
|
||||
let teamMemberships: Array<{
|
||||
team: { id: string; name: string };
|
||||
role: string;
|
||||
@@ -25,7 +28,10 @@ export function useDriverProfilePageData(driverId: string) {
|
||||
}> = [];
|
||||
|
||||
for (const team of allTeams) {
|
||||
const teamMembers = await teamService.getTeamMembers(team.id, driverId, '');
|
||||
const teamMembersResult = await teamService.getTeamMembers(team.id, driverId, '');
|
||||
if (teamMembersResult.isErr()) continue;
|
||||
const teamMembers = teamMembersResult.unwrap();
|
||||
|
||||
const membership = teamMembers?.find(member => member.driverId === driverId);
|
||||
if (membership) {
|
||||
teamMemberships.push({
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user