/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { payrollsCalculate } from "../funcs/payrollsCalculate.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 { PutV1CompaniesCompanyIdPayrollsPayrollIdCalculateRequest, PutV1CompaniesCompanyIdPayrollsPayrollIdCalculateResponse, } from "../models/operations/putv1companiescompanyidpayrollspayrollidcalculate.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type PayrollsCalculateMutationVariables = { request: PutV1CompaniesCompanyIdPayrollsPayrollIdCalculateRequest; options?: RequestOptions; }; export type PayrollsCalculateMutationData = PutV1CompaniesCompanyIdPayrollsPayrollIdCalculateResponse; export type PayrollsCalculateMutationError = | NotFoundErrorObject | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Calculate a payroll * * @remarks * Performs calculations for taxes, benefits, and deductions for an unprocessed payroll. The calculated payroll details provide a preview of the actual values that will be used when the payroll is run. * * This calculation is asynchronous and a successful request responds with a 202 HTTP status. To view the details of the calculated payroll, use the GET /v1/companies/{company_id}/payrolls/{payroll_id} endpoint with *include=taxes,benefits,deductions* params. * * If the company is blocked from running payroll due to issues like incomplete setup, missing information or other compliance issues, the response will be 422 Unprocessable Entity with a categorization of the blockers as described in the error responses. * * scope: `payrolls:run` */ export function usePayrollsCalculateMutation( options?: MutationHookOptions< PayrollsCalculateMutationData, PayrollsCalculateMutationError, PayrollsCalculateMutationVariables >, ): UseMutationResult< PayrollsCalculateMutationData, PayrollsCalculateMutationError, PayrollsCalculateMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildPayrollsCalculateMutation(client, options), ...options, }); } export function mutationKeyPayrollsCalculate(): MutationKey { return ["@gusto/embedded-api", "Payrolls", "calculate"]; } export function buildPayrollsCalculateMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: PayrollsCalculateMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyPayrollsCalculate(), mutationFn: function payrollsCalculateMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(payrollsCalculate( client$, request, mergedOptions, )); }, }; }