Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add endpoints and queries for company doc signing #151

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'