mirror of
https://github.com/IT4Change/ohmyform-ui.git
synced 2025-12-13 09:45:50 +00:00
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { QueryHookOptions, QueryResult, useQuery } from '@apollo/client'
|
|
import { gql } from '@apollo/client/core'
|
|
import { useImperativeQuery } from '../../components/use.imerative.query'
|
|
import { FORM_PAGER_FRAGMENT, FormPagerFragment } from '../fragment/form.pager.fragment'
|
|
import { SUBMISSION_FRAGMENT, SubmissionFragment } from '../fragment/submission.fragment'
|
|
|
|
interface Data {
|
|
pager: {
|
|
entries: SubmissionFragment[]
|
|
|
|
total: number
|
|
limit: number
|
|
start: number
|
|
}
|
|
|
|
form: FormPagerFragment
|
|
}
|
|
|
|
interface Variables {
|
|
form: string
|
|
start?: number
|
|
limit?: number
|
|
}
|
|
|
|
const QUERY = gql`
|
|
query listSubmissions($form: ID!, $start: Int, $limit: Int) {
|
|
form: getFormById(id: $form) {
|
|
...Form
|
|
}
|
|
|
|
pager: listSubmissions(form: $form, start: $start, limit: $limit) {
|
|
entries {
|
|
...Submission
|
|
}
|
|
total
|
|
limit
|
|
start
|
|
}
|
|
}
|
|
|
|
${SUBMISSION_FRAGMENT}
|
|
${FORM_PAGER_FRAGMENT}
|
|
`
|
|
|
|
export const useSubmissionPagerQuery = (
|
|
options?: QueryHookOptions<Data, Variables>
|
|
): QueryResult<Data, Variables> => useQuery<Data, Variables>(QUERY, options)
|
|
|
|
export const useSubmissionPagerImperativeQuery = () => useImperativeQuery<Data, Variables>(QUERY)
|