website refactor
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInject } from '@/lib/di/hooks/useInject';
|
||||
import { SPONSORSHIP_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { SPONSOR_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 sponsorshipService = useInject(SPONSOR_SERVICE_TOKEN);
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorshipRequests', entityType, entityId],
|
||||
queryFn: () => sponsorshipService.getPendingSponsorshipRequests({
|
||||
entityType,
|
||||
entityId,
|
||||
}),
|
||||
queryFn: async () => {
|
||||
const result = await sponsorshipService.getPendingSponsorshipRequests({
|
||||
entityType,
|
||||
entityId,
|
||||
});
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
enabled: !!entityType && !!entityId,
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,13 @@ export function useAvailableLeagues() {
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['availableLeagues'],
|
||||
queryFn: () => sponsorService.getAvailableLeagues(),
|
||||
queryFn: async () => {
|
||||
const result = await sponsorService.getAvailableLeagues();
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
|
||||
@@ -8,7 +8,13 @@ export function useSponsorBilling(sponsorId: string) {
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorBilling', sponsorId],
|
||||
queryFn: () => sponsorService.getBilling(sponsorId),
|
||||
queryFn: async () => {
|
||||
const result = await sponsorService.getBilling(sponsorId);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
enabled: !!sponsorId,
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,13 @@ export function useSponsorDashboard(sponsorId: string) {
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorDashboard', sponsorId],
|
||||
queryFn: () => sponsorService.getSponsorDashboard(sponsorId),
|
||||
queryFn: async () => {
|
||||
const result = await sponsorService.getSponsorDashboard(sponsorId);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
enabled: !!sponsorId,
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,13 @@ export function useSponsorLeagueDetail(leagueId: string) {
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorLeagueDetail', leagueId],
|
||||
queryFn: () => sponsorService.getLeagueDetail(leagueId),
|
||||
queryFn: async () => {
|
||||
const result = await sponsorService.getLeagueDetail(leagueId);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
enabled: !!leagueId,
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,13 @@ export function useSponsorSponsorships(sponsorId: string) {
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['sponsorSponsorships', sponsorId],
|
||||
queryFn: () => sponsorService.getSponsorSponsorships(sponsorId),
|
||||
queryFn: async () => {
|
||||
const result = await sponsorService.getSponsorSponsorships(sponsorId);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
enabled: !!sponsorId,
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,13 @@ export function useAllTeams() {
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['allTeams'],
|
||||
queryFn: () => teamService.getAllTeams(),
|
||||
queryFn: async () => {
|
||||
const result = await teamService.getAllTeams();
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
});
|
||||
|
||||
return enhanceQueryResult(queryResult);
|
||||
|
||||
@@ -9,7 +9,13 @@ export function useCreateTeam(options?: UseMutationOptions<CreateTeamOutputDTO,
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<CreateTeamOutputDTO, ApiError, CreateTeamInputDTO>({
|
||||
mutationFn: (input) => teamService.createTeam(input),
|
||||
mutationFn: async (input) => {
|
||||
const result = await teamService.createTeam(input);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -8,7 +8,13 @@ export function useTeamDetails(teamId: string, currentUserId: string) {
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['teamDetails', teamId, currentUserId],
|
||||
queryFn: () => teamService.getTeamDetails(teamId, currentUserId),
|
||||
queryFn: async () => {
|
||||
const result = await teamService.getTeamDetails(teamId, currentUserId);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
enabled: !!teamId && !!currentUserId,
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,13 @@ export function useTeamMembers(teamId: string, currentUserId: string, teamOwnerI
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['teamMembers', teamId, currentUserId, teamOwnerId],
|
||||
queryFn: () => teamService.getTeamMembers(teamId, currentUserId, teamOwnerId),
|
||||
queryFn: async () => {
|
||||
const result = await teamService.getTeamMembers(teamId, currentUserId, teamOwnerId);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
enabled: !!teamId && !!currentUserId && !!teamOwnerId,
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,13 @@ export function useTeamMembership(teamId: string, driverId: string) {
|
||||
|
||||
const queryResult = useQuery({
|
||||
queryKey: ['teamMembership', teamId, driverId],
|
||||
queryFn: () => teamService.getMembership(teamId, driverId),
|
||||
queryFn: async () => {
|
||||
const result = await teamService.getMembership(teamId, driverId);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
enabled: !!teamId && !!driverId,
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,13 @@ export function useUpdateTeam(options?: UseMutationOptions<UpdateTeamOutputDTO,
|
||||
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
||||
|
||||
return useMutation<UpdateTeamOutputDTO, ApiError, { teamId: string; input: UpdateTeamInputDTO }>({
|
||||
mutationFn: ({ teamId, input }) => teamService.updateTeam(teamId, input),
|
||||
mutationFn: async ({ teamId, input }) => {
|
||||
const result = await teamService.updateTeam(teamId, input);
|
||||
if (result.isErr()) {
|
||||
throw result.getError();
|
||||
}
|
||||
return result.unwrap();
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
30
apps/website/lib/hooks/useDriverSearch.ts
Normal file
30
apps/website/lib/hooks/useDriverSearch.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
import type { DriverLeaderboardItemViewModel } from '@/lib/view-models/DriverLeaderboardItemViewModel';
|
||||
|
||||
/**
|
||||
* useDriverSearch
|
||||
*
|
||||
* Client-side hook for UX-only search filtering.
|
||||
* This is view-only transformation, not business logic.
|
||||
*/
|
||||
export function useDriverSearch(drivers: DriverLeaderboardItemViewModel[]) {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
|
||||
const filteredDrivers = useMemo(() => {
|
||||
if (!searchQuery) return drivers;
|
||||
|
||||
const query = searchQuery.toLowerCase();
|
||||
return drivers.filter(driver => {
|
||||
return (
|
||||
driver.name.toLowerCase().includes(query) ||
|
||||
driver.nationality.toLowerCase().includes(query)
|
||||
);
|
||||
});
|
||||
}, [drivers, searchQuery]);
|
||||
|
||||
return {
|
||||
searchQuery,
|
||||
setSearchQuery,
|
||||
filteredDrivers,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user