Files
supabase/apps/studio/data/api-authorization/api-authorization-decline-mutation.ts
Danny White 840127cd69 let inline error callers own mutation failures (#48640)
## What kind of change does this PR introduce?

Code clean-up following #48470, #48471, #48472, #48473, and #48474.

## What is the current behavior?

Mutation hooks provide fallback error toasts, so callers that already
render errors inline must suppress those toasts with empty `onError`
handlers.

## What is the new behavior?

The affected callers own their error presentation. Inline interstitial
errors remain unchanged, API authorisation retains its state-reset
handlers, and Project Claim retains its combined caller-owned toast.

## To test

There is no useful before-and-after visual check for this PR: the
rendered error states should be identical on `master` and this branch.
The change only removes the default-toast and no-op-handler pair
underneath the UI.

The existing [Organisation
Invite](https://github.com/supabase/supabase/pull/48470), [API
authorisation, AWS
Marketplace](https://github.com/supabase/supabase/pull/48471), and
[Stripe Projects](https://github.com/supabase/supabase/pull/48472)
failure tests cover the inline errors and confirm that no duplicate
toast appears.
2026-08-06 16:06:38 +07:00

45 lines
1.4 KiB
TypeScript

import { useMutation } from '@tanstack/react-query'
import { del, handleError } from '@/data/fetchers'
import type { ResponseError, UseCustomMutationOptions } from '@/types'
export type ApiAuthorizationDeclineVariables = {
id: string
slug: string
}
export type ApiAuthorizationDeclineResponse = {
id: string
}
export async function declineApiAuthorization({ id, slug }: ApiAuthorizationDeclineVariables) {
if (!id) throw new Error('Authorization ID is required')
const { data, error } = await del('/platform/organizations/{slug}/oauth/authorizations/{id}', {
// @ts-ignore [Joshen] Endpoint doesnt need slug in the path params, but the endpoint path requires slug
// it's a little weird, will need API to decide if they wanna shift this route outside of the {slug} endpoint
params: { path: { slug, id } },
})
if (error) handleError(error)
return data as ApiAuthorizationDeclineResponse
}
type ApiAuthorizationDeclineData = Awaited<ReturnType<typeof declineApiAuthorization>>
export const useApiAuthorizationDeclineMutation = (
options: Omit<
UseCustomMutationOptions<
ApiAuthorizationDeclineData,
ResponseError,
ApiAuthorizationDeclineVariables
>,
'mutationFn'
> = {}
) => {
return useMutation<ApiAuthorizationDeclineData, ResponseError, ApiAuthorizationDeclineVariables>({
mutationFn: (vars) => declineApiAuthorization(vars),
...options,
})
}