/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { paySchedulesCreate } from "../funcs/paySchedulesCreate.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 { PostV1CompaniesCompanyIdPaySchedulesRequest, PostV1CompaniesCompanyIdPaySchedulesResponse, } from "../models/operations/postv1companiescompanyidpayschedules.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type PaySchedulesCreateMutationVariables = { request: PostV1CompaniesCompanyIdPaySchedulesRequest; options?: RequestOptions; }; export type PaySchedulesCreateMutationData = PostV1CompaniesCompanyIdPaySchedulesResponse; export type PaySchedulesCreateMutationError = | NotFoundErrorObject | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create a new pay schedule * * @remarks * If a company does not have any pay schedules, this endpoint will create a single pay schedule and assign it to all employees. This is a common use case during company onboarding. * * If a company has an existing active pay schedule and want to support multiple pay schedules, this endpoint will create a pay schedule that is not assigned to any employee. * * Be sure to **[check state laws](https://www.dol.gov/agencies/whd/state/payday)** to know what schedule is right for your customers. * * > If an onboarded company misses their first pay date, Gusto will automatically adjust the pay schedule to the next available pay date. * * ### Webhooks * - `pay_schedule.created`: Fires when a pay schedule is successfully created. * * ### Related guides * - [Create a pay schedule](doc:create-a-pay-schedule) * - [Pay Schedules](doc:pay-schedule-info) * - [Manage Pay Schedules via API](doc:manage-pay-schedules-api) * * scope: `pay_schedules:write` */ export function usePaySchedulesCreateMutation( options?: MutationHookOptions< PaySchedulesCreateMutationData, PaySchedulesCreateMutationError, PaySchedulesCreateMutationVariables >, ): UseMutationResult< PaySchedulesCreateMutationData, PaySchedulesCreateMutationError, PaySchedulesCreateMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildPaySchedulesCreateMutation(client, options), ...options, }); } export function mutationKeyPaySchedulesCreate(): MutationKey { return ["@gusto/embedded-api", "paySchedules", "create"]; } export function buildPaySchedulesCreateMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: PaySchedulesCreateMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyPaySchedulesCreate(), mutationFn: function paySchedulesCreateMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(paySchedulesCreate( client$, request, mergedOptions, )); }, }; }