page wrapper
This commit is contained in:
@@ -1,100 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_STEWARDING_SERVICE_TOKEN, LEAGUE_MEMBERSHIP_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { LeagueRoleUtility } from '@/lib/utilities/LeagueRoleUtility';
|
||||
import { useCurrentDriver } from '@/hooks/driver/useCurrentDriver';
|
||||
|
||||
/**
|
||||
* Hook for league stewarding data with admin check
|
||||
*/
|
||||
export function useLeagueStewarding(leagueId: string) {
|
||||
const leagueStewardingService = useInject(LEAGUE_STEWARDING_SERVICE_TOKEN);
|
||||
const leagueMembershipService = useInject(LEAGUE_MEMBERSHIP_SERVICE_TOKEN);
|
||||
const { data: currentDriver } = useCurrentDriver();
|
||||
const currentDriverId = currentDriver?.id;
|
||||
|
||||
// Check admin status
|
||||
const adminQuery = useQuery({
|
||||
queryKey: ['leagueMembership', leagueId, currentDriverId],
|
||||
queryFn: async () => {
|
||||
if (!currentDriverId) return false;
|
||||
const membership = await leagueMembershipService.getMembership(leagueId, currentDriverId);
|
||||
return membership ? LeagueRoleUtility.isLeagueAdminOrHigherRole(membership.role) : false;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
gcTime: 10 * 60 * 1000, // 10 minutes
|
||||
enabled: !!leagueId && !!currentDriverId,
|
||||
});
|
||||
|
||||
// Load stewarding data (only if admin)
|
||||
const stewardingQuery = useQuery({
|
||||
queryKey: ['leagueStewarding', leagueId],
|
||||
queryFn: async () => {
|
||||
return await leagueStewardingService.getLeagueStewardingData(leagueId);
|
||||
},
|
||||
staleTime: 2 * 60 * 1000, // 2 minutes
|
||||
gcTime: 5 * 60 * 1000, // 5 minutes
|
||||
enabled: !!leagueId && adminQuery.data === true,
|
||||
});
|
||||
|
||||
return {
|
||||
isAdmin: adminQuery.data,
|
||||
adminLoading: adminQuery.isLoading,
|
||||
adminError: adminQuery.error,
|
||||
|
||||
stewardingData: stewardingQuery.data,
|
||||
stewardingLoading: stewardingQuery.isLoading,
|
||||
stewardingError: stewardingQuery.error,
|
||||
|
||||
refetchStewarding: stewardingQuery.refetch,
|
||||
refetchAdmin: adminQuery.refetch,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for league stewarding mutations
|
||||
*/
|
||||
export function useLeagueStewardingMutations(leagueId: string) {
|
||||
const leagueStewardingService = useInject(LEAGUE_STEWARDING_SERVICE_TOKEN);
|
||||
const { data: currentDriver } = useCurrentDriver();
|
||||
const currentDriverId = currentDriver?.id;
|
||||
|
||||
const reviewProtest = async (input: { protestId: string; decision: string; decisionNotes: string }) => {
|
||||
if (!currentDriverId) throw new Error('No current driver');
|
||||
return await leagueStewardingService.reviewProtest({
|
||||
protestId: input.protestId,
|
||||
stewardId: currentDriverId,
|
||||
decision: input.decision,
|
||||
decisionNotes: input.decisionNotes,
|
||||
});
|
||||
};
|
||||
|
||||
const applyPenalty = async (input: {
|
||||
raceId: string;
|
||||
driverId: string;
|
||||
type: string;
|
||||
value: number;
|
||||
reason: string;
|
||||
protestId: string;
|
||||
notes: string;
|
||||
}) => {
|
||||
if (!currentDriverId) throw new Error('No current driver');
|
||||
return await leagueStewardingService.applyPenalty({
|
||||
raceId: input.raceId,
|
||||
driverId: input.driverId,
|
||||
stewardId: currentDriverId,
|
||||
type: input.type,
|
||||
value: input.value,
|
||||
reason: input.reason,
|
||||
protestId: input.protestId,
|
||||
notes: input.notes,
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
reviewProtest,
|
||||
applyPenalty,
|
||||
};
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { RACE_RESULTS_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
/**
|
||||
* Hook for race results data
|
||||
*/
|
||||
export function useRaceResults(raceId: string, currentUserId?: string) {
|
||||
const raceResultsService = useInject(RACE_RESULTS_SERVICE_TOKEN);
|
||||
|
||||
const raceQuery = useQuery({
|
||||
queryKey: ['raceResults', raceId, currentUserId],
|
||||
queryFn: async () => {
|
||||
return await raceResultsService.getResultsDetail(raceId, currentUserId);
|
||||
},
|
||||
staleTime: 2 * 60 * 1000, // 2 minutes
|
||||
gcTime: 5 * 60 * 1000, // 5 minutes
|
||||
enabled: !!raceId,
|
||||
});
|
||||
|
||||
const sofQuery = useQuery({
|
||||
queryKey: ['raceSof', raceId],
|
||||
queryFn: async () => {
|
||||
return await raceResultsService.getWithSOF(raceId);
|
||||
},
|
||||
staleTime: 2 * 60 * 1000, // 2 minutes
|
||||
gcTime: 5 * 60 * 1000, // 5 minutes
|
||||
enabled: !!raceId,
|
||||
});
|
||||
|
||||
return {
|
||||
raceData: raceQuery.data,
|
||||
isLoading: raceQuery.isLoading || sofQuery.isLoading,
|
||||
error: raceQuery.error || sofQuery.error,
|
||||
retry: raceQuery.refetch,
|
||||
sofData: sofQuery.data,
|
||||
};
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { RACE_STEWARDING_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
/**
|
||||
* Hook for race stewarding data
|
||||
*/
|
||||
export function useRaceStewarding(raceId: string, driverId: string) {
|
||||
const raceStewardingService = useInject(RACE_STEWARDING_SERVICE_TOKEN);
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: ['raceStewarding', raceId, driverId],
|
||||
queryFn: async () => {
|
||||
return await raceStewardingService.getRaceStewardingData(raceId, driverId);
|
||||
},
|
||||
staleTime: 2 * 60 * 1000, // 2 minutes
|
||||
gcTime: 5 * 60 * 1000, // 5 minutes
|
||||
enabled: !!raceId && !!driverId,
|
||||
});
|
||||
|
||||
return {
|
||||
data: query.data,
|
||||
isLoading: query.isLoading,
|
||||
error: query.error,
|
||||
retry: query.refetch,
|
||||
};
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
/**
|
||||
* Hook for team leaderboard data
|
||||
*/
|
||||
export function useTeamLeaderboard() {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: ['allTeams'],
|
||||
queryFn: async () => {
|
||||
return await teamService.getAllTeams();
|
||||
},
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
gcTime: 10 * 60 * 1000, // 10 minutes
|
||||
});
|
||||
|
||||
return {
|
||||
data: query.data,
|
||||
isLoading: query.isLoading,
|
||||
error: query.error,
|
||||
retry: query.refetch,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user