Skip to content

Commit

Permalink
fix: reload on mutation complete
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexZorkin committed Dec 11, 2021
1 parent 81c66bb commit 9324c18
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/pages/admin/attachments.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DefaultLayout from "components/Layout/DefaultLayout";
import { withRelay, RelayProps } from "relay-nextjs";
import { graphql, usePreloadedQuery } from "react-relay/hooks";
import { useMutation } from "react-relay";
import { useMutation, loadQuery, useRelayEnvironment } from "react-relay";
import FilePicker from "@button-inc/bcgov-theme/FilePicker";

import { createAttachmentMutation } from "mutations/attachment/createAttachment";
Expand All @@ -28,7 +28,14 @@ const AttachmentsQuery = graphql`

function Attachments({ preloadedQuery }: RelayProps<{}, attachmentsQuery>) {
const { query } = usePreloadedQuery(AttachmentsQuery, preloadedQuery);
const [commit] = useMutation(createAttachmentMutation);
const [commit] = useMutation(createAttachmentMutation)
const environment = useRelayEnvironment();

const refetch = () => {
loadQuery(environment, AttachmentsQuery, {})
};


return (
<DefaultLayout session={query.session}>
<h2>Attachments List</h2>
Expand All @@ -51,7 +58,9 @@ function Attachments({ preloadedQuery }: RelayProps<{}, attachmentsQuery>) {
},
},
onCompleted(data) {
console.log(data);
//refetch()
// How to re-run query direct?
window.location.reload()
},
});
}}
Expand Down

0 comments on commit 9324c18

Please sign in to comment.