mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 13:49:09 +03:00
37 lines
947 B
TypeScript
37 lines
947 B
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { deleteContents } from 'data/content/content-delete-mutation'
|
|
import { databaseTestsKeys } from './database-tests-key'
|
|
|
|
type DatabaseTestDeleteVariables = {
|
|
projectRef: string
|
|
id: string
|
|
}
|
|
|
|
export const useDatabaseTestDeleteMutation = ({
|
|
onSuccess,
|
|
}: {
|
|
onSuccess?: () => void
|
|
} = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ projectRef, id }: DatabaseTestDeleteVariables) => {
|
|
await deleteContents({ projectRef, ids: [id] })
|
|
|
|
// Invalidate test list cache
|
|
await queryClient.invalidateQueries(databaseTestsKeys.list(projectRef))
|
|
|
|
return id
|
|
},
|
|
onSuccess: (id) => {
|
|
toast.success(`Test successfully deleted.`)
|
|
onSuccess?.()
|
|
},
|
|
onError: (error: any) => {
|
|
toast.error(`Failed to delete test: ${error.message}`)
|
|
},
|
|
})
|
|
}
|