website refactor
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
export { useCurrentSession } from './useCurrentSession';
|
||||
export { useLogin } from './useLogin';
|
||||
export { useLogout } from './useLogout';
|
||||
export { useSignup } from './useSignup';
|
||||
export { useForgotPassword } from './useForgotPassword';
|
||||
export { useResetPassword } from './useResetPassword';
|
||||
@@ -1,21 +0,0 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { SESSION_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
||||
|
||||
export function useCurrentSession(
|
||||
options?: Omit<UseQueryOptions<SessionViewModel | null, ApiError>, 'queryKey' | 'queryFn'> & { initialData?: SessionViewModel | null }
|
||||
) {
|
||||
const sessionService = useInject(SESSION_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['currentSession'],
|
||||
queryFn: () => sessionService.getSession(),
|
||||
initialData: options?.initialData,
|
||||
...options,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { AUTH_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import type { ForgotPasswordDTO } from '@/lib/types/generated/ForgotPasswordDTO';
|
||||
|
||||
export function useForgotPassword(
|
||||
options?: Omit<UseMutationOptions<{ message: string; magicLink?: string }, ApiError, ForgotPasswordDTO>, 'mutationFn'>
|
||||
) {
|
||||
const authService = useInject(AUTH_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<{ message: string; magicLink?: string }, ApiError, ForgotPasswordDTO>({
|
||||
mutationFn: (params) => authService.forgotPassword(params),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { AUTH_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
||||
import type { LoginParamsDTO } from '@/lib/types/generated/LoginParamsDTO';
|
||||
|
||||
export function useLogin(
|
||||
options?: Omit<UseMutationOptions<SessionViewModel, ApiError, LoginParamsDTO>, 'mutationFn'>
|
||||
) {
|
||||
const authService = useInject(AUTH_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<SessionViewModel, ApiError, LoginParamsDTO>({
|
||||
mutationFn: (params) => authService.login(params),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { AUTH_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
|
||||
export function useLogout(
|
||||
options?: Omit<UseMutationOptions<void, ApiError, void>, 'mutationFn'>
|
||||
) {
|
||||
const authService = useInject(AUTH_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<void, ApiError, void>({
|
||||
mutationFn: () => authService.logout(),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { AUTH_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import type { ResetPasswordDTO } from '@/lib/types/generated/ResetPasswordDTO';
|
||||
|
||||
export function useResetPassword(
|
||||
options?: Omit<UseMutationOptions<{ message: string }, ApiError, ResetPasswordDTO>, 'mutationFn'>
|
||||
) {
|
||||
const authService = useInject(AUTH_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<{ message: string }, ApiError, ResetPasswordDTO>({
|
||||
mutationFn: (params) => authService.resetPassword(params),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { AUTH_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
||||
import type { SignupParamsDTO } from '@/lib/types/generated/SignupParamsDTO';
|
||||
|
||||
export function useSignup(
|
||||
options?: Omit<UseMutationOptions<SessionViewModel, ApiError, SignupParamsDTO>, 'mutationFn'>
|
||||
) {
|
||||
const authService = useInject(AUTH_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<SessionViewModel, ApiError, SignupParamsDTO>({
|
||||
mutationFn: (params) => authService.signup(params),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
export { useCurrentDriver } from './useCurrentDriver';
|
||||
export { useDriverLeaderboard } from '@/lib/hooks/useDriverLeaderboard';
|
||||
export { useDriverProfile } from './useDriverProfile';
|
||||
export { useUpdateDriverProfile } from './useUpdateDriverProfile';
|
||||
export { useCreateDriver } from './useCreateDriver';
|
||||
export { useFindDriverById } from './useFindDriverById';
|
||||
@@ -1,17 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { DRIVER_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import type { CompleteOnboardingInputDTO } from '@/lib/types/generated/CompleteOnboardingInputDTO';
|
||||
import { CompleteOnboardingViewModel } from '@/lib/view-models/CompleteOnboardingViewModel';
|
||||
|
||||
export function useCreateDriver(
|
||||
options?: Omit<UseMutationOptions<CompleteOnboardingViewModel, ApiError, CompleteOnboardingInputDTO>, 'mutationFn'>
|
||||
) {
|
||||
const driverService = useInject(DRIVER_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<CompleteOnboardingViewModel, ApiError, CompleteOnboardingInputDTO>({
|
||||
mutationFn: (input) => driverService.completeDriverOnboarding(input),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { DRIVER_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
|
||||
type DriverData = any; // Replace with actual type
|
||||
|
||||
export function useCurrentDriver(
|
||||
options?: Omit<UseQueryOptions<DriverData, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const driverService = useInject(DRIVER_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['currentDriver'],
|
||||
queryFn: () => driverService.getCurrentDriver(),
|
||||
...options,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { DRIVER_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import { DriverProfileViewModel } from '@/lib/view-models/DriverProfileViewModel';
|
||||
|
||||
export function useDriverProfile(
|
||||
driverId: string,
|
||||
options?: Omit<UseQueryOptions<DriverProfileViewModel, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const driverService = useInject(DRIVER_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['driverProfile', driverId],
|
||||
queryFn: () => driverService.getDriverProfile(driverId),
|
||||
enabled: !!driverId,
|
||||
...options,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import { usePageDataMultiple } from '@/lib/page/usePageData';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { DRIVER_SERVICE_TOKEN, TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
export function useDriverProfilePageData(driverId: string) {
|
||||
const driverService = useInject(DRIVER_SERVICE_TOKEN);
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
return usePageDataMultiple({
|
||||
driverProfile: {
|
||||
queryKey: ['driverProfile', driverId],
|
||||
queryFn: () => driverService.getDriverProfile(driverId),
|
||||
enabled: !!driverId,
|
||||
},
|
||||
teamMemberships: {
|
||||
queryKey: ['teamMemberships', driverId],
|
||||
queryFn: async () => {
|
||||
if (!driverId) return [];
|
||||
|
||||
const allTeams = await teamService.getAllTeams();
|
||||
let teamMemberships: Array<{
|
||||
team: { id: string; name: string };
|
||||
role: string;
|
||||
joinedAt: Date;
|
||||
}> = [];
|
||||
|
||||
for (const team of allTeams) {
|
||||
const teamMembers = await teamService.getTeamMembers(team.id, driverId, '');
|
||||
const membership = teamMembers?.find(member => member.driverId === driverId);
|
||||
if (membership) {
|
||||
teamMemberships.push({
|
||||
team: {
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
},
|
||||
role: membership.role,
|
||||
joinedAt: new Date(membership.joinedAt),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return teamMemberships;
|
||||
},
|
||||
enabled: !!driverId,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { DRIVER_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import type { GetDriverOutputDTO } from '@/lib/types/generated/GetDriverOutputDTO';
|
||||
|
||||
export function useFindDriverById(
|
||||
driverId: string,
|
||||
options?: Omit<UseQueryOptions<GetDriverOutputDTO | null, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const driverService = useInject(DRIVER_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['driver', driverId],
|
||||
queryFn: () => driverService.findById(driverId),
|
||||
enabled: !!driverId,
|
||||
...options,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { DRIVER_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import { DriverProfileViewModel } from '@/lib/view-models/DriverProfileViewModel';
|
||||
|
||||
export function useUpdateDriverProfile(
|
||||
options?: Omit<UseMutationOptions<DriverProfileViewModel, ApiError, { bio?: string; country?: string }>, 'mutationFn'>
|
||||
) {
|
||||
const driverService = useInject(DRIVER_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<DriverProfileViewModel, ApiError, { bio?: string; country?: string }>({
|
||||
mutationFn: (updates) => driverService.updateProfile(updates),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useAllLeagues() {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['allLeagues'],
|
||||
queryFn: () => leagueService.getAllLeagues(),
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
export function useCreateLeague() {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const createLeagueMutation = useMutation({
|
||||
mutationFn: (input: any) => leagueService.createLeague(input),
|
||||
onSuccess: () => {
|
||||
// Invalidate relevant queries to refresh data
|
||||
queryClient.invalidateQueries({ queryKey: ['allLeagues'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['leagueMemberships'] });
|
||||
},
|
||||
});
|
||||
|
||||
return createLeagueMutation;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_MEMBERSHIP_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { LeagueRoleUtility } from '@/lib/utilities/LeagueRoleUtility';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useLeagueAdminStatus(leagueId: string, currentDriverId: string) {
|
||||
const leagueMembershipService = useInject(LEAGUE_MEMBERSHIP_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueMembership', leagueId, currentDriverId],
|
||||
queryFn: async () => {
|
||||
await leagueMembershipService.fetchLeagueMemberships(leagueId);
|
||||
const membership = leagueMembershipService.getMembership(leagueId, currentDriverId);
|
||||
return membership ? LeagueRoleUtility.isLeagueAdminOrHigherRole(membership.role) : false;
|
||||
},
|
||||
enabled: !!leagueId && !!currentDriverId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useLeagueDetail(leagueId: string, currentDriverId: string) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueDetail', leagueId, currentDriverId],
|
||||
queryFn: () => leagueService.getLeagueDetail(leagueId, currentDriverId),
|
||||
enabled: !!leagueId && !!currentDriverId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_MEMBERSHIP_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
export function useLeagueMembershipMutation() {
|
||||
const leagueMembershipService = useInject(LEAGUE_MEMBERSHIP_SERVICE_TOKEN);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const joinLeagueMutation = useMutation({
|
||||
mutationFn: ({ leagueId, driverId }: { leagueId: string; driverId: string }) =>
|
||||
leagueMembershipService.joinLeague(leagueId, driverId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['leagueMemberships'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['allLeagues'] });
|
||||
},
|
||||
});
|
||||
|
||||
const leaveLeagueMutation = useMutation({
|
||||
mutationFn: ({ leagueId, driverId }: { leagueId: string; driverId: string }) =>
|
||||
leagueMembershipService.leaveLeague(leagueId, driverId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['leagueMemberships'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['allLeagues'] });
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
joinLeague: joinLeagueMutation,
|
||||
leaveLeague: leaveLeagueMutation,
|
||||
};
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useLeagueMemberships(leagueId: string, currentUserId: string) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueMemberships', leagueId, currentUserId],
|
||||
queryFn: () => leagueService.getLeagueMemberships(leagueId, currentUserId),
|
||||
enabled: !!leagueId && !!currentUserId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { RACE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useLeagueRaces(leagueId: string) {
|
||||
const raceService = useInject(RACE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueRaces', leagueId],
|
||||
queryFn: () => raceService.findByLeagueId(leagueId),
|
||||
enabled: !!leagueId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import type { LeagueAdminRosterJoinRequestViewModel } from '@/lib/view-models/LeagueAdminRosterJoinRequestViewModel';
|
||||
import type { LeagueAdminRosterMemberViewModel } from '@/lib/view-models/LeagueAdminRosterMemberViewModel';
|
||||
import type { MembershipRole } from '@/lib/types/MembershipRole';
|
||||
|
||||
export function useLeagueRosterJoinRequests(
|
||||
leagueId: string,
|
||||
options?: Omit<UseQueryOptions<LeagueAdminRosterJoinRequestViewModel[], ApiError>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueRosterJoinRequests', leagueId],
|
||||
queryFn: () => leagueService.getAdminRosterJoinRequests(leagueId),
|
||||
...options,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
|
||||
export function useLeagueRosterMembers(
|
||||
leagueId: string,
|
||||
options?: Omit<UseQueryOptions<LeagueAdminRosterMemberViewModel[], ApiError>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueRosterMembers', leagueId],
|
||||
queryFn: () => leagueService.getAdminRosterMembers(leagueId),
|
||||
...options,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
|
||||
export function useApproveJoinRequest(
|
||||
options?: Omit<UseMutationOptions<{ success: boolean }, ApiError, { leagueId: string; joinRequestId: string }>, 'mutationFn'>
|
||||
) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<{ success: boolean }, ApiError, { leagueId: string; joinRequestId: string }>({
|
||||
mutationFn: ({ leagueId, joinRequestId }) => leagueService.approveJoinRequest(leagueId, joinRequestId),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export function useRejectJoinRequest(
|
||||
options?: Omit<UseMutationOptions<{ success: boolean }, ApiError, { leagueId: string; joinRequestId: string }>, 'mutationFn'>
|
||||
) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<{ success: boolean }, ApiError, { leagueId: string; joinRequestId: string }>({
|
||||
mutationFn: ({ leagueId, joinRequestId }) => leagueService.rejectJoinRequest(leagueId, joinRequestId),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateMemberRole(
|
||||
options?: Omit<UseMutationOptions<{ success: boolean }, ApiError, { leagueId: string; driverId: string; role: MembershipRole }>, 'mutationFn'>
|
||||
) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<{ success: boolean }, ApiError, { leagueId: string; driverId: string; role: MembershipRole }>({
|
||||
mutationFn: ({ leagueId, driverId, role }) => leagueService.updateMemberRole(leagueId, driverId, role),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export function useRemoveMember(
|
||||
options?: Omit<UseMutationOptions<{ success: boolean }, ApiError, { leagueId: string; driverId: string }>, 'mutationFn'>
|
||||
) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<{ success: boolean }, ApiError, { leagueId: string; driverId: string }>({
|
||||
mutationFn: ({ leagueId, driverId }) => leagueService.removeMember(leagueId, driverId),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useLeagueSchedule(leagueId: string) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueSchedule', leagueId],
|
||||
queryFn: () => leagueService.getLeagueSchedule(leagueId),
|
||||
enabled: !!leagueId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import { usePageData } from '@/lib/page/usePageData';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN, LEAGUE_MEMBERSHIP_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { LeagueRoleUtility } from '@/lib/utilities/LeagueRoleUtility';
|
||||
|
||||
export function useLeagueAdminStatus(leagueId: string, currentDriverId: string) {
|
||||
const leagueMembershipService = useInject(LEAGUE_MEMBERSHIP_SERVICE_TOKEN);
|
||||
|
||||
return usePageData({
|
||||
queryKey: ['admin-check', leagueId, currentDriverId],
|
||||
queryFn: async () => {
|
||||
await leagueMembershipService.fetchLeagueMemberships(leagueId);
|
||||
const membership = leagueMembershipService.getMembership(leagueId, currentDriverId);
|
||||
return membership ? LeagueRoleUtility.isLeagueAdminOrHigherRole(membership.role) : false;
|
||||
},
|
||||
enabled: !!leagueId && !!currentDriverId,
|
||||
});
|
||||
}
|
||||
|
||||
export function useLeagueSeasons(leagueId: string, isAdmin: boolean) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
return usePageData({
|
||||
queryKey: ['leagueSeasons', leagueId],
|
||||
queryFn: () => leagueService.getLeagueSeasonSummaries(leagueId),
|
||||
enabled: !!leagueId && !!isAdmin,
|
||||
});
|
||||
}
|
||||
|
||||
export function useLeagueAdminSchedule(leagueId: string, selectedSeasonId: string, isAdmin: boolean) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
return usePageData({
|
||||
queryKey: ['adminSchedule', leagueId, selectedSeasonId],
|
||||
queryFn: () => leagueService.getAdminSchedule(leagueId, selectedSeasonId),
|
||||
enabled: !!leagueId && !!selectedSeasonId && !!isAdmin,
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useLeagueSeasons(leagueId: string) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueSeasons', leagueId],
|
||||
queryFn: () => leagueService.getLeagueSeasons(leagueId),
|
||||
enabled: !!leagueId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SETTINGS_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import type { LeagueSettingsViewModel } from '@/lib/view-models/LeagueSettingsViewModel';
|
||||
|
||||
export function useLeagueSettings(
|
||||
leagueId: string,
|
||||
options?: Omit<UseQueryOptions<LeagueSettingsViewModel | null, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const leagueSettingsService = useInject(LEAGUE_SETTINGS_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueSettings', leagueId],
|
||||
queryFn: () => leagueSettingsService.getLeagueSettings(leagueId),
|
||||
enabled: !!leagueId,
|
||||
...options,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { usePageDataMultiple } from '@/lib/page/usePageData';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN, LEAGUE_MEMBERSHIP_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
export function useLeagueSponsorshipsPageData(leagueId: string, currentDriverId: string) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
const leagueMembershipService = useInject(LEAGUE_MEMBERSHIP_SERVICE_TOKEN);
|
||||
|
||||
return usePageDataMultiple({
|
||||
league: {
|
||||
queryKey: ['leagueDetail', leagueId, currentDriverId],
|
||||
queryFn: () => leagueService.getLeagueDetail(leagueId, currentDriverId),
|
||||
},
|
||||
membership: {
|
||||
queryKey: ['leagueMembership', leagueId, currentDriverId],
|
||||
queryFn: () => leagueMembershipService.fetchLeagueMemberships(leagueId).then(() => {
|
||||
return leagueMembershipService.getMembership(leagueId, currentDriverId);
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_STEWARDING_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useLeagueStewardingData(leagueId: string) {
|
||||
const leagueStewardingService = useInject(LEAGUE_STEWARDING_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueStewardingData', leagueId],
|
||||
queryFn: () => leagueStewardingService.getLeagueStewardingData(leagueId),
|
||||
enabled: !!leagueId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
import { usePageMutation } from '@/lib/page/usePageData';
|
||||
|
||||
export function useLeagueStewardingMutations(onRefetch: () => void) {
|
||||
const acceptProtestMutation = usePageMutation(
|
||||
async (variables: { protestId: string; penaltyType: string; penaltyValue: number; stewardNotes: string; raceId: string; accusedDriverId: string; reason: string }) => {
|
||||
// TODO: Implement protest review and penalty application
|
||||
// await leagueStewardingService.reviewProtest({
|
||||
// protestId: variables.protestId,
|
||||
// stewardId: currentDriverId,
|
||||
// decision: 'uphold',
|
||||
// decisionNotes: variables.stewardNotes,
|
||||
// });
|
||||
|
||||
// await leagueStewardingService.applyPenalty({
|
||||
// raceId: variables.raceId,
|
||||
// driverId: variables.accusedDriverId,
|
||||
// stewardId: currentDriverId,
|
||||
// type: variables.penaltyType,
|
||||
// value: variables.penaltyValue,
|
||||
// reason: variables.reason,
|
||||
// protestId: variables.protestId,
|
||||
// notes: variables.stewardNotes,
|
||||
// });
|
||||
},
|
||||
{
|
||||
onSuccess: () => onRefetch(),
|
||||
}
|
||||
);
|
||||
|
||||
const rejectProtestMutation = usePageMutation(
|
||||
async (variables: { protestId: string; stewardNotes: string }) => {
|
||||
// TODO: Implement protest rejection
|
||||
// await leagueStewardingService.reviewProtest({
|
||||
// protestId: variables.protestId,
|
||||
// stewardId: currentDriverId,
|
||||
// decision: 'dismiss',
|
||||
// decisionNotes: variables.stewardNotes,
|
||||
// });
|
||||
},
|
||||
{
|
||||
onSuccess: () => onRefetch(),
|
||||
}
|
||||
);
|
||||
|
||||
return { acceptProtestMutation, rejectProtestMutation };
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import { usePageData, usePageMutation } from '@/lib/page/usePageData';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_WALLET_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
export function useLeagueWalletPageData(leagueId: string) {
|
||||
const leagueWalletService = useInject(LEAGUE_WALLET_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = usePageData({
|
||||
queryKey: ['leagueWallet', leagueId],
|
||||
queryFn: () => leagueWalletService.getWalletForLeague(leagueId),
|
||||
enabled: !!leagueId,
|
||||
});
|
||||
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
export function useLeagueWalletWithdrawal(leagueId: string, data: any, refetch: () => void) {
|
||||
const leagueWalletService = useInject(LEAGUE_WALLET_SERVICE_TOKEN);
|
||||
|
||||
const withdrawMutation = usePageMutation(
|
||||
async ({ amount }: { amount: number }) => {
|
||||
if (!data) throw new Error('Wallet data not available');
|
||||
|
||||
const result = await leagueWalletService.withdraw(
|
||||
leagueId,
|
||||
amount,
|
||||
data.currency,
|
||||
'season-2', // Current active season
|
||||
'bank-account-***1234'
|
||||
);
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error(result.message || 'Withdrawal failed');
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
// Refetch wallet data after successful withdrawal
|
||||
refetch();
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return withdrawMutation;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { PENALTY_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
export function usePenaltyMutation() {
|
||||
const penaltyService = useInject(PENALTY_SERVICE_TOKEN);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const applyPenaltyMutation = useMutation({
|
||||
mutationFn: (command: any) => penaltyService.applyPenalty(command),
|
||||
onSuccess: () => {
|
||||
// Invalidate relevant queries to refresh data
|
||||
queryClient.invalidateQueries({ queryKey: ['leagueStewardingData'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['penalties'] });
|
||||
},
|
||||
});
|
||||
|
||||
return applyPenaltyMutation;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_STEWARDING_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useProtestDetail(leagueId: string, protestId: string, enabled: boolean = true) {
|
||||
const leagueStewardingService = useInject(LEAGUE_STEWARDING_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['protestDetail', leagueId, protestId],
|
||||
queryFn: () => leagueStewardingService.getProtestDetailViewModel(leagueId, protestId),
|
||||
enabled: enabled && !!leagueId && !!protestId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { SPONSORSHIP_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useSponsorshipRequests(entityType: string, entityId: string) {
|
||||
const sponsorshipService = useInject(SPONSORSHIP_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorshipRequests', entityType, entityId],
|
||||
queryFn: () => sponsorshipService.getPendingSponsorshipRequests({
|
||||
entityType,
|
||||
entityId,
|
||||
}),
|
||||
enabled: !!entityType && !!entityId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export { useCompleteOnboarding } from './useCompleteOnboarding';
|
||||
export { useGenerateAvatars } from './useGenerateAvatars';
|
||||
export { useValidateFacePhoto } from './useValidateFacePhoto';
|
||||
@@ -1,17 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { ONBOARDING_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import { CompleteOnboardingViewModel } from '@/lib/view-models/CompleteOnboardingViewModel';
|
||||
import type { CompleteOnboardingInputDTO } from '@/lib/types/generated/CompleteOnboardingInputDTO';
|
||||
|
||||
export function useCompleteOnboarding(
|
||||
options?: Omit<UseMutationOptions<CompleteOnboardingViewModel, ApiError, CompleteOnboardingInputDTO>, 'mutationFn'>
|
||||
) {
|
||||
const onboardingService = useInject(ONBOARDING_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<CompleteOnboardingViewModel, ApiError, CompleteOnboardingInputDTO>({
|
||||
mutationFn: (input) => onboardingService.completeOnboarding(input),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { ONBOARDING_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import { AvatarGenerationViewModel } from '@/lib/view-models/AvatarGenerationViewModel';
|
||||
|
||||
interface GenerateAvatarsParams {
|
||||
userId: string;
|
||||
facePhotoData: string;
|
||||
suitColor: string;
|
||||
}
|
||||
|
||||
export function useGenerateAvatars(
|
||||
options?: Omit<UseMutationOptions<AvatarGenerationViewModel, ApiError, GenerateAvatarsParams>, 'mutationFn'>
|
||||
) {
|
||||
const onboardingService = useInject(ONBOARDING_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<AvatarGenerationViewModel, ApiError, GenerateAvatarsParams>({
|
||||
mutationFn: (params) => onboardingService.generateAvatars(params.userId, params.facePhotoData, params.suitColor),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { ONBOARDING_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
|
||||
export function useValidateFacePhoto(
|
||||
options?: Omit<UseMutationOptions<{ isValid: boolean; errorMessage?: string }, ApiError, string>, 'mutationFn'>
|
||||
) {
|
||||
const onboardingService = useInject(ONBOARDING_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<{ isValid: boolean; errorMessage?: string }, ApiError, string>({
|
||||
mutationFn: (photoData) => onboardingService.validateFacePhoto(photoData),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { usePageData } from '@/lib/page/usePageData';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { RACE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
export function useAllRacesPageData() {
|
||||
const raceService = useInject(RACE_SERVICE_TOKEN);
|
||||
|
||||
return usePageData({
|
||||
queryKey: ['races', 'all'],
|
||||
queryFn: () => raceService.getAllRacesPageData(),
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { RACE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import type { FileProtestCommandDTO } from '@/lib/types/generated/FileProtestCommandDTO';
|
||||
|
||||
export function useFileProtest(
|
||||
options?: Omit<UseMutationOptions<void, ApiError, FileProtestCommandDTO>, 'mutationFn'>
|
||||
) {
|
||||
const raceService = useInject(RACE_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<void, ApiError, FileProtestCommandDTO>({
|
||||
mutationFn: (command) => raceService.fileProtest(command),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { usePageDataMultiple } from '@/lib/page/usePageData';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { RACE_RESULTS_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
|
||||
export function useRaceResultsPageData(raceId: string, currentDriverId: string) {
|
||||
const raceResultsService = useInject(RACE_RESULTS_SERVICE_TOKEN);
|
||||
|
||||
return usePageDataMultiple({
|
||||
results: {
|
||||
queryKey: ['raceResultsDetail', raceId, currentDriverId],
|
||||
queryFn: () => raceResultsService.getResultsDetail(raceId, currentDriverId),
|
||||
enabled: !!raceId,
|
||||
},
|
||||
sof: {
|
||||
queryKey: ['raceWithSOF', raceId],
|
||||
queryFn: () => raceResultsService.getWithSOF(raceId),
|
||||
enabled: !!raceId,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { RACE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
|
||||
interface RegisterForRaceParams {
|
||||
raceId: string;
|
||||
leagueId: string;
|
||||
driverId: string;
|
||||
}
|
||||
|
||||
export function useRegisterForRace(
|
||||
options?: Omit<UseMutationOptions<void, ApiError, RegisterForRaceParams>, 'mutationFn'>
|
||||
) {
|
||||
const raceService = useInject(RACE_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<void, ApiError, RegisterForRaceParams>({
|
||||
mutationFn: (params) => raceService.registerForRace(params.raceId, params.leagueId, params.driverId),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { RACE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
|
||||
interface WithdrawFromRaceParams {
|
||||
raceId: string;
|
||||
driverId: string;
|
||||
}
|
||||
|
||||
export function useWithdrawFromRace(
|
||||
options?: Omit<UseMutationOptions<void, ApiError, WithdrawFromRaceParams>, 'mutationFn'>
|
||||
) {
|
||||
const raceService = useInject(RACE_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<void, ApiError, WithdrawFromRaceParams>({
|
||||
mutationFn: (params) => raceService.withdrawFromRace(params.raceId, params.driverId),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export { useAvailableLeagues } from './useAvailableLeagues';
|
||||
export { useSponsorDashboard } from './useSponsorDashboard';
|
||||
export { useSponsorSponsorships } from './useSponsorSponsorships';
|
||||
export { useSponsorBilling } from './useSponsorBilling';
|
||||
export { useSponsorLeagueDetail } from './useSponsorLeagueDetail';
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { SPONSOR_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useAvailableLeagues() {
|
||||
const sponsorService = useInject(SPONSOR_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['availableLeagues'],
|
||||
queryFn: () => sponsorService.getAvailableLeagues(),
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { SPONSOR_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useSponsorBilling(sponsorId: string) {
|
||||
const sponsorService = useInject(SPONSOR_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorBilling', sponsorId],
|
||||
queryFn: () => sponsorService.getBilling(sponsorId),
|
||||
enabled: !!sponsorId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { SPONSOR_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useSponsorDashboard(sponsorId: string) {
|
||||
const sponsorService = useInject(SPONSOR_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorDashboard', sponsorId],
|
||||
queryFn: () => sponsorService.getSponsorDashboard(sponsorId),
|
||||
enabled: !!sponsorId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { SPONSOR_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useSponsorLeagueDetail(leagueId: string) {
|
||||
const sponsorService = useInject(SPONSOR_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorLeagueDetail', leagueId],
|
||||
queryFn: () => sponsorService.getLeagueDetail(leagueId),
|
||||
enabled: !!leagueId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { SPONSOR_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useSponsorSponsorships(sponsorId: string) {
|
||||
const sponsorService = useInject(SPONSOR_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorSponsorships', sponsorId],
|
||||
queryFn: () => sponsorService.getSponsorSponsorships(sponsorId),
|
||||
enabled: !!sponsorId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
import { usePageData, usePageMutation } from '@/lib/page/usePageData';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import {
|
||||
SPONSORSHIP_SERVICE_TOKEN,
|
||||
DRIVER_SERVICE_TOKEN,
|
||||
LEAGUE_SERVICE_TOKEN,
|
||||
TEAM_SERVICE_TOKEN,
|
||||
LEAGUE_MEMBERSHIP_SERVICE_TOKEN
|
||||
} from '@/lib/di/tokens';
|
||||
import { LeagueRoleUtility } from '@/lib/utilities/LeagueRoleUtility';
|
||||
|
||||
export function useSponsorshipRequestsPageData(currentDriverId: string | null | undefined) {
|
||||
const sponsorshipService = useInject(SPONSORSHIP_SERVICE_TOKEN);
|
||||
const driverService = useInject(DRIVER_SERVICE_TOKEN);
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
const leagueMembershipService = useInject(LEAGUE_MEMBERSHIP_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = usePageData({
|
||||
queryKey: ['sponsorshipRequests', 'all', currentDriverId || ''],
|
||||
queryFn: async () => {
|
||||
if (!currentDriverId) return [];
|
||||
|
||||
const allSections: any[] = [];
|
||||
|
||||
// 1. Driver's own sponsorship requests
|
||||
const driverRequests = await sponsorshipService.getPendingSponsorshipRequests({
|
||||
entityType: 'driver',
|
||||
entityId: currentDriverId,
|
||||
});
|
||||
|
||||
if (driverRequests.length > 0) {
|
||||
const driverProfile = await driverService.getDriverProfile(currentDriverId);
|
||||
allSections.push({
|
||||
entityType: 'driver',
|
||||
entityId: currentDriverId,
|
||||
entityName: driverProfile?.currentDriver?.name ?? 'Your Profile',
|
||||
requests: driverRequests,
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Leagues where the user is admin/owner
|
||||
const allLeagues = await leagueService.getAllLeagues();
|
||||
for (const league of allLeagues) {
|
||||
const membership = await leagueMembershipService.getMembership(league.id, currentDriverId);
|
||||
if (membership && LeagueRoleUtility.isLeagueAdminOrHigherRole(membership.role)) {
|
||||
try {
|
||||
const leagueRequests = await sponsorshipService.getPendingSponsorshipRequests({
|
||||
entityType: 'season',
|
||||
entityId: league.id,
|
||||
});
|
||||
|
||||
if (leagueRequests.length > 0) {
|
||||
allSections.push({
|
||||
entityType: 'season',
|
||||
entityId: league.id,
|
||||
entityName: league.name,
|
||||
requests: leagueRequests,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
// Silently skip if no requests found
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Teams where the user is owner/manager
|
||||
const allTeams = await teamService.getAllTeams();
|
||||
for (const team of allTeams) {
|
||||
const membership = await teamService.getMembership(team.id, currentDriverId);
|
||||
if (membership && (membership.role === 'owner' || membership.role === 'manager')) {
|
||||
const teamRequests = await sponsorshipService.getPendingSponsorshipRequests({
|
||||
entityType: 'team',
|
||||
entityId: team.id,
|
||||
});
|
||||
|
||||
if (teamRequests.length > 0) {
|
||||
allSections.push({
|
||||
entityType: 'team',
|
||||
entityId: team.id,
|
||||
entityName: team.name,
|
||||
requests: teamRequests,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allSections;
|
||||
},
|
||||
enabled: !!currentDriverId,
|
||||
});
|
||||
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
export function useSponsorshipRequestMutations(currentDriverId: string | null | undefined, refetch: () => void) {
|
||||
const sponsorshipService = useInject(SPONSORSHIP_SERVICE_TOKEN);
|
||||
|
||||
const acceptMutation = usePageMutation(
|
||||
async ({ requestId }: { requestId: string }) => {
|
||||
if (!currentDriverId) throw new Error('No driver ID');
|
||||
await sponsorshipService.acceptSponsorshipRequest(requestId, currentDriverId);
|
||||
},
|
||||
{
|
||||
onSuccess: () => refetch(),
|
||||
}
|
||||
);
|
||||
|
||||
const rejectMutation = usePageMutation(
|
||||
async ({ requestId, reason }: { requestId: string; reason?: string }) => {
|
||||
if (!currentDriverId) throw new Error('No driver ID');
|
||||
await sponsorshipService.rejectSponsorshipRequest(requestId, currentDriverId, reason);
|
||||
},
|
||||
{
|
||||
onSuccess: () => refetch(),
|
||||
}
|
||||
);
|
||||
|
||||
return { acceptMutation, rejectMutation };
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
export { useAllTeams } from './useAllTeams';
|
||||
export { useTeamDetails } from './useTeamDetails';
|
||||
export { useTeamMembers } from './useTeamMembers';
|
||||
export { useTeamJoinRequests } from './useTeamJoinRequests';
|
||||
export { useCreateTeam } from './useCreateTeam';
|
||||
export { useUpdateTeam } from './useUpdateTeam';
|
||||
export { useTeamMembership } from './useTeamMembership';
|
||||
export { useApproveJoinRequest } from './useApproveJoinRequest';
|
||||
export { useRejectJoinRequest } from './useRejectJoinRequest';
|
||||
export { useTeamStandings } from './useTeamStandings';
|
||||
export { useJoinTeam } from './useJoinTeam';
|
||||
export { useLeaveTeam } from './useLeaveTeam';
|
||||
export { useTeamRoster } from './useTeamRoster';
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useAllTeams() {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['allTeams'],
|
||||
queryFn: () => teamService.getAllTeams(),
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_JOIN_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
|
||||
export function useApproveJoinRequest(options?: Omit<UseMutationOptions<void, ApiError, void>, 'mutationFn'>) {
|
||||
const teamJoinService = useInject(TEAM_JOIN_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<void, ApiError, void>({
|
||||
mutationFn: () => teamJoinService.approveJoinRequest(),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import type { CreateTeamInputDTO } from '@/lib/types/generated/CreateTeamInputDTO';
|
||||
import type { CreateTeamOutputDTO } from '@/lib/types/generated/CreateTeamOutputDTO';
|
||||
|
||||
export function useCreateTeam(options?: UseMutationOptions<CreateTeamOutputDTO, ApiError, CreateTeamInputDTO>) {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<CreateTeamOutputDTO, ApiError, CreateTeamInputDTO>({
|
||||
mutationFn: (input) => teamService.createTeam(input),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
|
||||
interface JoinTeamParams {
|
||||
teamId: string;
|
||||
driverId: string;
|
||||
requiresApproval?: boolean;
|
||||
}
|
||||
|
||||
export function useJoinTeam(options?: Omit<UseMutationOptions<void, ApiError, JoinTeamParams>, 'mutationFn'>) {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<void, ApiError, JoinTeamParams>({
|
||||
mutationFn: async (params) => {
|
||||
// Note: Team join functionality would need to be added to teamService
|
||||
// For now, we'll use a placeholder
|
||||
console.log('Joining team:', params);
|
||||
if (params.requiresApproval) {
|
||||
alert('Join request sent! Wait for team approval.');
|
||||
} else {
|
||||
alert('Successfully joined team!');
|
||||
}
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
|
||||
interface LeaveTeamParams {
|
||||
teamId: string;
|
||||
driverId: string;
|
||||
}
|
||||
|
||||
export function useLeaveTeam(options?: Omit<UseMutationOptions<void, ApiError, LeaveTeamParams>, 'mutationFn'>) {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<void, ApiError, LeaveTeamParams>({
|
||||
mutationFn: async (params) => {
|
||||
// Note: Leave team functionality would need to be added to teamService
|
||||
// For now, we'll use a placeholder
|
||||
console.log('Leaving team:', params);
|
||||
alert('Successfully left team');
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_JOIN_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
|
||||
export function useRejectJoinRequest(options?: Omit<UseMutationOptions<void, ApiError, void>, 'mutationFn'>) {
|
||||
const teamJoinService = useInject(TEAM_JOIN_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<void, ApiError, void>({
|
||||
mutationFn: () => teamJoinService.rejectJoinRequest(),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useTeamDetails(teamId: string, currentUserId: string) {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['teamDetails', teamId, currentUserId],
|
||||
queryFn: () => teamService.getTeamDetails(teamId, currentUserId),
|
||||
enabled: !!teamId && !!currentUserId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_JOIN_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useTeamJoinRequests(teamId: string, currentUserId: string, isOwner: boolean) {
|
||||
const teamJoinService = useInject(TEAM_JOIN_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['teamJoinRequests', teamId, currentUserId, isOwner],
|
||||
queryFn: () => teamJoinService.getJoinRequests(teamId, currentUserId, isOwner),
|
||||
enabled: !!teamId && !!currentUserId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useTeamMembers(teamId: string, currentUserId: string, teamOwnerId: string) {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['teamMembers', teamId, currentUserId, teamOwnerId],
|
||||
queryFn: () => teamService.getTeamMembers(teamId, currentUserId, teamOwnerId),
|
||||
enabled: !!teamId && !!currentUserId && !!teamOwnerId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import type { GetTeamMembershipOutputDTO } from '@/lib/types/generated/GetTeamMembershipOutputDTO';
|
||||
|
||||
export function useTeamMembership(teamId: string, driverId: string) {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['teamMembership', teamId, driverId],
|
||||
queryFn: () => teamService.getMembership(teamId, driverId),
|
||||
enabled: !!teamId && !!driverId,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN, DRIVER_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import type { TeamMemberViewModel } from '@/lib/view-models/TeamMemberViewModel';
|
||||
|
||||
interface TeamRosterMember {
|
||||
driver: any;
|
||||
role: string;
|
||||
joinedAt: string;
|
||||
rating: number | null;
|
||||
overallRank: number | null;
|
||||
}
|
||||
|
||||
export function useTeamRoster(memberships: TeamMemberViewModel[]) {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
const driverService = useInject(DRIVER_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['teamRoster', memberships],
|
||||
queryFn: async () => {
|
||||
// Get driver details for each membership
|
||||
const membersWithDetails = await Promise.all(
|
||||
memberships.map(async (m) => {
|
||||
const driver = await driverService.findById(m.driverId);
|
||||
return {
|
||||
driver: driver || { id: m.driverId, name: 'Unknown Driver', country: 'Unknown', position: 'N/A', races: '0', impressions: '0', team: 'None' },
|
||||
role: m.role,
|
||||
joinedAt: m.joinedAt,
|
||||
rating: null, // DriverDTO doesn't include rating
|
||||
overallRank: null, // DriverDTO doesn't include overallRank
|
||||
};
|
||||
})
|
||||
);
|
||||
return membersWithDetails;
|
||||
},
|
||||
enabled: memberships.length > 0,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function useTeamStandings(teamId: string, leagues: string[]) {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['teamStandings', teamId, leagues],
|
||||
queryFn: async () => {
|
||||
// For demo purposes, create mock standings
|
||||
return leagues.map(leagueId => ({
|
||||
leagueId,
|
||||
leagueName: `League ${leagueId}`,
|
||||
position: Math.floor(Math.random() * 10) + 1,
|
||||
points: Math.floor(Math.random() * 100),
|
||||
wins: Math.floor(Math.random() * 5),
|
||||
racesCompleted: Math.floor(Math.random() * 10),
|
||||
}));
|
||||
},
|
||||
enabled: leagues.length > 0,
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import type { UpdateTeamInputDTO } from '@/lib/types/generated/UpdateTeamInputDTO';
|
||||
import type { UpdateTeamOutputDTO } from '@/lib/types/generated/UpdateTeamOutputDTO';
|
||||
|
||||
export function useUpdateTeam(options?: UseMutationOptions<UpdateTeamOutputDTO, ApiError, { teamId: string; input: UpdateTeamInputDTO }>) {
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<UpdateTeamOutputDTO, ApiError, { teamId: string; input: UpdateTeamInputDTO }>({
|
||||
mutationFn: ({ teamId, input }) => teamService.updateTeam(teamId, input),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { POLICY_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import { ApiError } from '@/lib/api/base/ApiError';
|
||||
import { PolicySnapshotDto } from '@/lib/api/policy/PolicyApiClient';
|
||||
|
||||
export function useCapability(
|
||||
capabilityKey: string,
|
||||
options?: Omit<UseQueryOptions<PolicySnapshotDto, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
const policyService = useInject(POLICY_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['policySnapshot', capabilityKey],
|
||||
queryFn: () => policyService.getSnapshot(),
|
||||
staleTime: 60_000,
|
||||
gcTime: 5 * 60_000,
|
||||
...options,
|
||||
});
|
||||
|
||||
const enhancedResult = enhanceQueryResult(queryResult);
|
||||
|
||||
// Add helper to get capability state
|
||||
const capabilityState = enhancedResult.data
|
||||
? policyService.getCapabilityState(enhancedResult.data, capabilityKey)
|
||||
: null;
|
||||
|
||||
return {
|
||||
...enhancedResult,
|
||||
capabilityState,
|
||||
isCapabilityEnabled: capabilityState === 'enabled',
|
||||
isCapabilityComingSoon: capabilityState === 'coming_soon',
|
||||
};
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { useCurrentDriver } from './driver/useCurrentDriver';
|
||||
|
||||
/**
|
||||
* Hook to get the current driver ID from the user's session.
|
||||
* Returns the driver ID string or undefined if not available.
|
||||
*/
|
||||
export function useEffectiveDriverId(): string | undefined {
|
||||
const { data: currentDriver } = useCurrentDriver();
|
||||
return currentDriver?.id;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
import type { LeagueScoringPresetDTO } from '@/lib/types/generated/LeagueScoringPresetDTO';
|
||||
|
||||
export function useLeagueScoringPresets() {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['leagueScoringPresets'],
|
||||
queryFn: async () => {
|
||||
const result = await leagueService.getScoringPresets();
|
||||
return result as LeagueScoringPresetDTO[];
|
||||
},
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { CreateLeagueInputDTO } from '@/lib/types/generated/CreateLeagueInputDTO';
|
||||
import { CreateLeagueOutputDTO } from '@/lib/types/generated/CreateLeagueOutputDTO';
|
||||
|
||||
export interface LeagueWizardFormModel {
|
||||
leagueId?: string;
|
||||
basics?: {
|
||||
name?: string;
|
||||
description?: string;
|
||||
visibility?: string;
|
||||
gameId?: string;
|
||||
};
|
||||
structure?: {
|
||||
mode?: string;
|
||||
maxDrivers?: number;
|
||||
maxTeams?: number;
|
||||
driversPerTeam?: number;
|
||||
multiClassEnabled?: boolean;
|
||||
};
|
||||
championships?: {
|
||||
enableDriverChampionship?: boolean;
|
||||
enableTeamChampionship?: boolean;
|
||||
enableNationsChampionship?: boolean;
|
||||
enableTrophyChampionship?: boolean;
|
||||
};
|
||||
scoring?: {
|
||||
patternId?: string;
|
||||
customScoringEnabled?: boolean;
|
||||
};
|
||||
dropPolicy?: {
|
||||
strategy?: string;
|
||||
n?: number;
|
||||
};
|
||||
timings?: {
|
||||
practiceMinutes?: number;
|
||||
qualifyingMinutes?: number;
|
||||
sprintRaceMinutes?: number;
|
||||
mainRaceMinutes?: number;
|
||||
sessionCount?: number;
|
||||
roundsPlanned?: number;
|
||||
raceDayOfWeek?: number;
|
||||
raceTimeUtc?: string;
|
||||
weekdays?: string[];
|
||||
recurrenceStrategy?: string;
|
||||
timezoneId?: string;
|
||||
seasonStartDate?: string;
|
||||
};
|
||||
stewarding?: {
|
||||
decisionMode?: string;
|
||||
requiredVotes?: number;
|
||||
requireDefense?: boolean;
|
||||
defenseTimeLimit?: number;
|
||||
voteTimeLimit?: number;
|
||||
protestDeadlineHours?: number;
|
||||
stewardingClosesHours?: number;
|
||||
notifyAccusedOnProtest?: boolean;
|
||||
notifyOnVoteRequired?: boolean;
|
||||
};
|
||||
seasonName?: string;
|
||||
}
|
||||
|
||||
export function useCreateLeagueWizard() {
|
||||
const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (params: { form: LeagueWizardFormModel; ownerId: string }): Promise<CreateLeagueOutputDTO> => {
|
||||
// Convert form to CreateLeagueInputDTO
|
||||
const input: CreateLeagueInputDTO = {
|
||||
name: params.form.basics?.name?.trim() ?? '',
|
||||
description: params.form.basics?.description?.trim() ?? '',
|
||||
visibility: (params.form.basics?.visibility as 'public' | 'private') ?? 'public',
|
||||
ownerId: params.ownerId,
|
||||
};
|
||||
|
||||
// Use the league service to create the league
|
||||
const result = await leagueService.createLeague(input);
|
||||
|
||||
return result;
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { PENALTY_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
||||
|
||||
export function usePenaltyTypesReference() {
|
||||
const penaltyService = useInject(PENALTY_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['penaltyTypesReference'],
|
||||
queryFn: () => penaltyService.getPenaltyTypesReference(),
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState, RefObject } from 'react';
|
||||
|
||||
/**
|
||||
* Calculate scroll progress (0-1) based on element's position in viewport
|
||||
* @param ref - Reference to the element to track
|
||||
* @param offset - Offset from viewport edges (0-1, default 0.1)
|
||||
* @returns progress value between 0 and 1
|
||||
*/
|
||||
export function useScrollProgress(ref: RefObject<HTMLElement | null>, offset: number = 0.1): number {
|
||||
const [progress, setProgress] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) return;
|
||||
|
||||
let rafId: number;
|
||||
|
||||
const calculateProgress = () => {
|
||||
if (!ref.current) return;
|
||||
|
||||
const rect = ref.current.getBoundingClientRect();
|
||||
const viewportHeight = window.innerHeight;
|
||||
const scrollY = window.scrollY;
|
||||
const documentHeight = document.documentElement.scrollHeight;
|
||||
|
||||
// Element enters viewport from bottom
|
||||
const enterPoint = viewportHeight * (1 - offset);
|
||||
// Element reaches top of viewport
|
||||
const exitPoint = viewportHeight * offset;
|
||||
|
||||
// Calculate progress: 0 when entering, 1 at 30% viewport (accelerated)
|
||||
const elementCenter = rect.top + rect.height / 2;
|
||||
const totalDistance = enterPoint - exitPoint;
|
||||
const currentDistance = enterPoint - elementCenter;
|
||||
|
||||
// Accelerate progress to reach 1.0 at 30% viewport height
|
||||
// Scale factor: 1.67 makes progress reach 1.0 at ~30% instead of 50%
|
||||
const rawProgress = (currentDistance / totalDistance) * 1.67;
|
||||
let clampedProgress = Math.max(0, Math.min(1, rawProgress));
|
||||
|
||||
// At bottom of page - ensure elements near bottom can reach 100%
|
||||
// Only apply if we're at the very bottom AND this element is below the fold
|
||||
if (scrollY + viewportHeight >= documentHeight - 50 && rect.top < viewportHeight) {
|
||||
clampedProgress = Math.max(clampedProgress, 1);
|
||||
}
|
||||
|
||||
setProgress(clampedProgress);
|
||||
};
|
||||
|
||||
const handleScroll = () => {
|
||||
if (rafId) {
|
||||
cancelAnimationFrame(rafId);
|
||||
}
|
||||
rafId = requestAnimationFrame(calculateProgress);
|
||||
};
|
||||
|
||||
// Initial calculation
|
||||
calculateProgress();
|
||||
|
||||
window.addEventListener('scroll', handleScroll, { passive: true });
|
||||
window.addEventListener('resize', handleScroll, { passive: true });
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('scroll', handleScroll);
|
||||
window.removeEventListener('resize', handleScroll);
|
||||
if (rafId) {
|
||||
cancelAnimationFrame(rafId);
|
||||
}
|
||||
};
|
||||
}, [ref, offset]);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate parallax offset based on scroll position
|
||||
* @param ref - Reference to the element to track
|
||||
* @param speed - Parallax speed multiplier (default 0.5)
|
||||
* @returns offset in pixels
|
||||
*/
|
||||
export function useParallax(ref: RefObject<HTMLElement | null>, speed: number = 0.5): number {
|
||||
const [offset, setOffset] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) return;
|
||||
|
||||
let rafId: number;
|
||||
|
||||
const calculateOffset = () => {
|
||||
if (!ref.current) return;
|
||||
|
||||
const rect = ref.current.getBoundingClientRect();
|
||||
const viewportHeight = window.innerHeight;
|
||||
|
||||
// Calculate offset based on element position relative to viewport
|
||||
const scrolled = viewportHeight - rect.top;
|
||||
const parallaxOffset = scrolled * speed;
|
||||
|
||||
setOffset(parallaxOffset);
|
||||
};
|
||||
|
||||
const handleScroll = () => {
|
||||
if (rafId) {
|
||||
cancelAnimationFrame(rafId);
|
||||
}
|
||||
rafId = requestAnimationFrame(calculateOffset);
|
||||
};
|
||||
|
||||
calculateOffset();
|
||||
|
||||
window.addEventListener('scroll', handleScroll, { passive: true });
|
||||
window.addEventListener('resize', handleScroll, { passive: true });
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('scroll', handleScroll);
|
||||
window.removeEventListener('resize', handleScroll);
|
||||
if (rafId) {
|
||||
cancelAnimationFrame(rafId);
|
||||
}
|
||||
};
|
||||
}, [ref, speed]);
|
||||
|
||||
return offset;
|
||||
}
|
||||
Reference in New Issue
Block a user