/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { earningTypesCreate } from "../funcs/earningTypesCreate.js"; import { combineSignals } from "../lib/primitives.js"; import { RequestOptions } from "../lib/sdks.js"; import { GustoEmbeddedError } from "../models/errors/gustoembeddederror.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import { NotFoundErrorObject } from "../models/errors/notfounderrorobject.js"; import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { UnprocessableEntityError } from "../models/errors/unprocessableentityerror.js"; import { PostV1CompaniesCompanyIdEarningTypesRequest, PostV1CompaniesCompanyIdEarningTypesResponse, } from "../models/operations/postv1companiescompanyidearningtypes.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type EarningTypesCreateMutationVariables = { request: PostV1CompaniesCompanyIdEarningTypesRequest; options?: RequestOptions; }; export type EarningTypesCreateMutationData = PostV1CompaniesCompanyIdEarningTypesResponse; export type EarningTypesCreateMutationError = | NotFoundErrorObject | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create a custom earning type * * @remarks * Create a custom earning type. * * If an inactive earning type exists with the same name, this will reactivate it instead of creating a new one. * * scope: `payrolls:write` */ export function useEarningTypesCreateMutation( options?: MutationHookOptions< EarningTypesCreateMutationData, EarningTypesCreateMutationError, EarningTypesCreateMutationVariables >, ): UseMutationResult< EarningTypesCreateMutationData, EarningTypesCreateMutationError, EarningTypesCreateMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildEarningTypesCreateMutation(client, options), ...options, }); } export function mutationKeyEarningTypesCreate(): MutationKey { return ["@gusto/embedded-api", "earningTypes", "create"]; } export function buildEarningTypesCreateMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: EarningTypesCreateMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyEarningTypesCreate(), mutationFn: function earningTypesCreateMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(earningTypesCreate( client$, request, mergedOptions, )); }, }; }