/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { i9VerificationUpdate } from "../funcs/i9VerificationUpdate.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 { PutV1EmployeesEmployeeIdI9AuthorizationRequest, PutV1EmployeesEmployeeIdI9AuthorizationResponse, } from "../models/operations/putv1employeesemployeeidi9authorization.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type I9VerificationUpdateMutationVariables = { request: PutV1EmployeesEmployeeIdI9AuthorizationRequest; options?: RequestOptions; }; export type I9VerificationUpdateMutationData = PutV1EmployeesEmployeeIdI9AuthorizationResponse; export type I9VerificationUpdateMutationError = | NotFoundErrorObject | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create or update an employee's I-9 authorization * * @remarks * An employee's I-9 authorization stores information about an employee's authorization status, as well as signatures and other information required to complete the Form I-9 for employment eligibility verification. * * If the version is supplied and the employee I-9 authorization exists, this endpoint acts as an update. Otherwise, it will create an employee I-9 authorization. * * Validations on this endpoint are conditional: * * `document_type` may be required, depending on `authorization_status`. * * Valid formats for `document_number` vary, depending on `document_type`. * * `country` is only allowed with `document_type: 'foreign_passport'`. * * `expiration_date` is only allowed with `authorization_status: 'alien'`. * * > ℹ️ Unneeded information is automatically removed during updates. * > * > If an update causes some formerly-required fields to be unneeded, the now-unneeded data will be removed automatically. * > * > **Example:** Updating `authorization_status` from `alien` to `citizen` will cause any data in `document_type`, `document_number`, `country`, and `expiration_date` to be removed, since these fields are unused for `authorization_status:'citizen'`. * * Detailed instructions for completing Form I-9 can be found at https://www.uscis.gov/sites/default/files/document/forms/i-9instr.pdf * * ### Related guides * - [I-9 employment verification](doc:i-9-employment-verification) * * scope: `i9_authorizations:write` */ export function useI9VerificationUpdateMutation( options?: MutationHookOptions< I9VerificationUpdateMutationData, I9VerificationUpdateMutationError, I9VerificationUpdateMutationVariables >, ): UseMutationResult< I9VerificationUpdateMutationData, I9VerificationUpdateMutationError, I9VerificationUpdateMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildI9VerificationUpdateMutation(client, options), ...options, }); } export function mutationKeyI9VerificationUpdate(): MutationKey { return ["@gusto/embedded-api", "i9Verification", "update"]; } export function buildI9VerificationUpdateMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: I9VerificationUpdateMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyI9VerificationUpdate(), mutationFn: function i9VerificationUpdateMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(i9VerificationUpdate( client$, request, mergedOptions, )); }, }; }