Files
supabase/apps/studio/data/third-party-auth/integration-delete-mutation.ts
T
Ivan Vasilov 8b657165b5 chore: Migrate to use custom type for ReactQuery queries and mutations (#40073)
* Add custom types for queries, mutations and infinite queries.

* Migrate all queries to use the new type.

* Migrate all infinite queries to useCustomInfiniteQueryOptions.

* Migrate all mutations to use useCustomMutationOptions.

* Add type to all imports in `types` folder.
2025-11-03 13:18:13 +01:00

65 lines
1.8 KiB
TypeScript

import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { del, handleError } from 'data/fetchers'
import type { ResponseError, UseCustomMutationOptions } from 'types'
import { keys } from './keys'
export type DeleteThirdPartyAuthIntegrationVariables = {
projectRef: string
tpaId: string
}
export async function deleteThirdPartyIntegration({
projectRef,
tpaId,
}: DeleteThirdPartyAuthIntegrationVariables) {
const { data, error } = await del('/v1/projects/{ref}/config/auth/third-party-auth/{tpa_id}', {
params: {
path: {
ref: projectRef,
tpa_id: tpaId,
},
},
})
if (error) handleError(error)
return data
}
type DeleteThirdPartyAuthIntegrationData = Awaited<ReturnType<typeof deleteThirdPartyIntegration>>
export const useDeleteThirdPartyAuthIntegrationMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseCustomMutationOptions<
DeleteThirdPartyAuthIntegrationData,
ResponseError,
DeleteThirdPartyAuthIntegrationVariables
>,
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
return useMutation<
DeleteThirdPartyAuthIntegrationData,
ResponseError,
DeleteThirdPartyAuthIntegrationVariables
>({
mutationFn: (vars) => deleteThirdPartyIntegration(vars),
async onSuccess(data, variables, context) {
const { projectRef } = variables
await queryClient.invalidateQueries({ queryKey: keys.integrations(projectRef) })
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
toast.error(`Failed to delete third party auth integration: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
})
}