21 lines
867 B
TypeScript
21 lines
867 B
TypeScript
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: async (input) => {
|
|
const result = await teamService.createTeam(input);
|
|
if (result.isErr()) {
|
|
throw result.getError();
|
|
}
|
|
return result.unwrap();
|
|
},
|
|
...options,
|
|
});
|
|
} |