/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { locationsCreate } from "../funcs/locationsCreate.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 { PostV1CompaniesCompanyIdLocationsRequest, PostV1CompaniesCompanyIdLocationsResponse, } from "../models/operations/postv1companiescompanyidlocations.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type LocationsCreateMutationVariables = { request: PostV1CompaniesCompanyIdLocationsRequest; options?: RequestOptions; }; export type LocationsCreateMutationData = PostV1CompaniesCompanyIdLocationsResponse; export type LocationsCreateMutationError = | NotFoundErrorObject | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create a company location * * @remarks * Create a company location, which represents any address associated with a company: mailing * addresses, filing addresses, or work locations. A single address may serve multiple, or all, purposes. * * Since all company locations are subsets of locations, use the Locations endpoints to * [get](ref:get-v1-locations-location_id) or [update](ref:put-v1-locations-location_id) an individual record. * * scope: `companies:write` */ export function useLocationsCreateMutation( options?: MutationHookOptions< LocationsCreateMutationData, LocationsCreateMutationError, LocationsCreateMutationVariables >, ): UseMutationResult< LocationsCreateMutationData, LocationsCreateMutationError, LocationsCreateMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildLocationsCreateMutation(client, options), ...options, }); } export function mutationKeyLocationsCreate(): MutationKey { return ["@gusto/embedded-api", "Locations", "create"]; } export function buildLocationsCreateMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: LocationsCreateMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyLocationsCreate(), mutationFn: function locationsCreateMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(locationsCreate( client$, request, mergedOptions, )); }, }; }