website refactor
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user