Files
gridpilot.gg/apps/website/hooks/team/useUpdateTeam.ts
2026-01-24 12:47:49 +01:00

21 lines
950 B
TypeScript

import { useInject } from '@/lib/di/hooks/useInject';
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
import { ApiError } from '@/lib/gateways/api/base/ApiError';
import type { UpdateTeamInputDTO } from '@/lib/types/generated/UpdateTeamInputDTO';
import type { UpdateTeamOutputDTO } from '@/lib/types/generated/UpdateTeamOutputDTO';
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
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: async ({ teamId, input }) => {
const result = await teamService.updateTeam(teamId, input);
if (result.isErr()) {
throw result.getError();
}
return result.unwrap();
},
...options,
});
}