/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { flowsCreate } from "../funcs/flowsCreate.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 { PostV1CompanyFlowsRequest, PostV1CompanyFlowsResponse, } from "../models/operations/postv1companyflows.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type FlowsCreateMutationVariables = { request: PostV1CompanyFlowsRequest; options?: RequestOptions; }; export type FlowsCreateMutationData = PostV1CompanyFlowsResponse; export type FlowsCreateMutationError = | NotFoundErrorObject | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create a flow * * @remarks * Generate a link to access a pre-built workflow in Gusto white-label UI. For security, all generated flows will expire within 1 hour of inactivity or 24 hours from creation time, whichever comes first. * * You can see a list of all possible flow types in our [Flow Types](https://docs.gusto.com/embedded-payroll/docs/flow-types) guide. * * You can also mix and match flow_types in the same category to create custom flows suitable for your needs. * * For instance, to create a custom onboarding flow that only includes `add_addresses`, `add_employees`, and `sign_all_forms` steps, simply stitch those flow_types together into a comma delimited string: * * ```json * { * "flow_type": "add_addresses,add_employees,sign_all_forms" * } * ``` * * Please be mindful of data dependencies in each step to achieve the best user experience. * * For more information and in-depth guides review the [Getting Started](https://docs.gusto.com/embedded-payroll/docs/flows-getting-started) guide for flows. * * scope: `flows:write` */ export function useFlowsCreateMutation( options?: MutationHookOptions< FlowsCreateMutationData, FlowsCreateMutationError, FlowsCreateMutationVariables >, ): UseMutationResult< FlowsCreateMutationData, FlowsCreateMutationError, FlowsCreateMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildFlowsCreateMutation(client, options), ...options, }); } export function mutationKeyFlowsCreate(): MutationKey { return ["@gusto/embedded-api", "Flows", "create"]; } export function buildFlowsCreateMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: FlowsCreateMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyFlowsCreate(), mutationFn: function flowsCreateMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(flowsCreate( client$, request, mergedOptions, )); }, }; }