Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
reload list after adding new form
Browse files Browse the repository at this point in the history
  • Loading branch information
wodka committed Jan 3, 2022
1 parent 92bc295 commit 831e0d7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- fixes for hide contrib setting
- fix problem with node-prune on production build
- translation for prev / continue during form submission
- reload form list after adding new one (https://github.com/ohmyform/ohmyform/issues/139)

### Security

Expand Down
2 changes: 1 addition & 1 deletion graphql/fragment/form.pager.fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface FormPagerFragment {
}

export const FORM_PAGER_FRAGMENT = gql`
fragment Form on Form {
fragment PagerForm on Form {
id
created
lastModified
Expand Down
2 changes: 1 addition & 1 deletion graphql/fragment/form.public.fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export interface FormPublicFragment {
}

export const FORM_PUBLIC_FRAGMENT = gql`
fragment Form on Form {
fragment PublicForm on Form {
id
title
language
Expand Down
19 changes: 17 additions & 2 deletions graphql/mutation/form.create.mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,20 @@ const MUTATION = gql`
`

export const useFormCreateMutation = (
data?: MutationHookOptions<Data, Variables>
): MutationTuple<Data, Variables> => useMutation<Data, Variables>(MUTATION, data)
options: MutationHookOptions<Data, Variables> = {}
): MutationTuple<Data, Variables> => {
const oldUpdate = options.update

options.update = (cache, result, options) => {
cache.evict({
fieldName: 'listForms',
})
cache.gc()

if (oldUpdate) {
oldUpdate(cache, result, options)
}
}

return useMutation<Data, Variables>(MUTATION, options)
}
2 changes: 1 addition & 1 deletion graphql/query/form.pager.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const QUERY = gql`
query listForms($start: Int, $limit: Int) {
pager: listForms(start: $start, limit: $limit) {
entries {
...Form
...PagerForm
}
total
limit
Expand Down
2 changes: 1 addition & 1 deletion graphql/query/form.public.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Variables {
const QUERY = gql`
query getFormById($id: ID!) {
form: getFormById(id: $id) {
...Form
...PublicForm
}
}
Expand Down
2 changes: 1 addition & 1 deletion graphql/query/submission.pager.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface Variables {
const QUERY = gql`
query listSubmissions($form: ID!, $start: Int, $limit: Int) {
form: getFormById(id: $form) {
...Form
...PagerForm
}
pager: listSubmissions(form: $form, start: $start, limit: $limit) {
Expand Down

0 comments on commit 831e0d7

Please sign in to comment.