From ac24f9a3a166333d9b838421d2a434fd641e4a6f Mon Sep 17 00:00:00 2001 From: Steve Jensen Date: Fri, 14 Feb 2025 10:53:13 -0700 Subject: [PATCH] feat: add endpoints and queries for company doc signing --- src/api/client.ts | 27 +++++++++++++++++++++ src/api/queries/companyForms.ts | 43 +++++++++++++++++++++++++++++++++ src/api/queries/index.ts | 1 + 3 files changed, 71 insertions(+) create mode 100644 src/api/queries/companyForms.ts diff --git a/src/api/client.ts b/src/api/client.ts index e88866cf..edc71a24 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -783,6 +783,7 @@ class GustoClient { .then(handleResponse) } + // Employee forms async getAllEmployeeForms(employee_id: string) { return this.client .GET('/v1/employees/{employee_id}/forms', { @@ -826,6 +827,32 @@ class GustoClient { .then(handleResponse) } + // Company forms + async getAllCompanyForms(company_id: string) { + return this.client + .GET('/v1/companies/{company_id}/forms', { + params: { path: { company_id } }, + }) + .then(handleResponse) + } + + async getCompanyFormPdf(form_id: string) { + return this.client + .GET('/v1/forms/{form_id}/pdf', { + params: { path: { form_id } }, + }) + .then(handleResponse) + } + + async signCompanyForm(form_id: string, body: BodyParams<'/v1/forms/{form_id}/sign', 'PUT'>) { + return this.client + .PUT('/v1/forms/{form_id}/sign', { + params: { path: { form_id } }, + body, + }) + .then(handleResponse) + } + // Pay Schedule async getPaySchedule(pay_schedule_id: string, company_id: string) { return this.client diff --git a/src/api/queries/companyForms.ts b/src/api/queries/companyForms.ts new file mode 100644 index 00000000..68e25561 --- /dev/null +++ b/src/api/queries/companyForms.ts @@ -0,0 +1,43 @@ +import { useMutation, useSuspenseQuery } from '@tanstack/react-query' +import { queryClient, useGustoApi } from '@/api/context' + +export function useGetAllCompanyForms(company_id: string) { + const { GustoClient: client } = useGustoApi() + return useSuspenseQuery({ + queryKey: ['companies', company_id, 'forms'], + queryFn: () => client.getAllCompanyForms(company_id), + }) +} + +export function useGetCompanyFormPdf(form_id: string) { + const { GustoClient: client } = useGustoApi() + return useSuspenseQuery({ + queryKey: ['companies', 'forms', form_id, 'pdf'], + queryFn: () => client.getCompanyFormPdf(form_id), + }) +} + +export function useSignCompanyForm( + company_id: string, + opts?: Omit[0], 'mutationFn'>, +) { + const { GustoClient: client } = useGustoApi() + const onSettled = async (data: unknown, error: unknown, variables: unknown, context: unknown) => { + if (opts?.onSettled) opts.onSettled(data, error, variables, context) + await queryClient.invalidateQueries({ + queryKey: ['companies', company_id, 'forms'], + }) + } + + return useMutation({ + mutationFn: ({ + form_id, + body, + }: { + form_id: string + body: Parameters[1] + }) => client.signCompanyForm(form_id, body), + ...opts, + onSettled, + }) +} diff --git a/src/api/queries/index.ts b/src/api/queries/index.ts index 050e37a1..f277a82a 100644 --- a/src/api/queries/index.ts +++ b/src/api/queries/index.ts @@ -1,3 +1,4 @@ export * from './company' export * from './employee' export * from './payroll' +export * from './companyForms'