reload vault store after fdw create/delete

This commit is contained in:
Alaister Young committed 2022-12-12 16:54:36 +01:00
1 parent e2e96cb0a6
commit 62c4d2f9bd
2 files changed
+12 -2

No files matched your search

+6 -1
View File
@@ -2,6 +2,7 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react
import { AvailableColumn, Wrapper } from 'components/interfaces/Database/Wrappers/Wrappers.types'
import { executeSql } from 'data/sql/execute-sql-query'
import { sqlKeys } from 'data/sql/keys'
import { useStore } from 'hooks'
export type FDWCreateVariables = {
projectRef?: string
@@ -150,12 +151,16 @@ export const useFDWCreateMutation = ({
...options
}: Omit<UseMutationOptions<FDWCreateData, unknown, FDWCreateVariables>, 'mutationFn'> = {}) => {
const queryClient = useQueryClient()
const { vault } = useStore()
return useMutation<FDWCreateData, unknown, FDWCreateVariables>((vars) => createFDW(vars), {
async onSuccess(data, variables, context) {
const { projectRef } = variables
await queryClient.invalidateQueries(sqlKeys.query(projectRef, ['fdws']))
await Promise.all([
queryClient.invalidateQueries(sqlKeys.query(projectRef, ['fdws'])),
vault.load(),
])
await onSuccess?.(data, variables, context)
},
+6 -1
View File
@@ -2,6 +2,7 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react
import { Wrapper } from 'components/interfaces/Database/Wrappers/Wrappers.types'
import { executeSql } from 'data/sql/execute-sql-query'
import { sqlKeys } from 'data/sql/keys'
import { useStore } from 'hooks'
export type FDWDeleteVariables = {
projectRef?: string
@@ -56,12 +57,16 @@ export const useFDWDeleteMutation = ({
...options
}: Omit<UseMutationOptions<FDWDeleteData, unknown, FDWDeleteVariables>, 'mutationFn'> = {}) => {
const queryClient = useQueryClient()
const { vault } = useStore()
return useMutation<FDWDeleteData, unknown, FDWDeleteVariables>((vars) => deleteFDW(vars), {
async onSuccess(data, variables, context) {
const { projectRef } = variables
await queryClient.invalidateQueries(sqlKeys.query(projectRef, ['fdws']))
await Promise.all([
queryClient.invalidateQueries(sqlKeys.query(projectRef, ['fdws'])),
vault.load(),
])
await onSuccess?.(data, variables, context)
},