Skip to content

Commit

Permalink
feat: add endpoints and queries for company doc signing
Browse files Browse the repository at this point in the history
  • Loading branch information
serikjensen committed Feb 14, 2025
1 parent 78799c9 commit ac24f9a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ class GustoClient {
.then(handleResponse)
}

// Employee forms
async getAllEmployeeForms(employee_id: string) {
return this.client
.GET('/v1/employees/{employee_id}/forms', {
Expand Down Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions src/api/queries/companyForms.ts
Original file line number Diff line number Diff line change
@@ -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<Parameters<typeof useMutation>[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<typeof client.signCompanyForm>[1]
}) => client.signCompanyForm(form_id, body),
...opts,
onSettled,
})
}
1 change: 1 addition & 0 deletions src/api/queries/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './company'
export * from './employee'
export * from './payroll'
export * from './companyForms'

0 comments on commit ac24f9a

Please sign in to comment.