mirror of
https://github.com/supabase/supabase.git
synced 2026-09-08 10:59:38 +08:00
## 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.
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { useMutation } from '@tanstack/react-query'
|
|
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
export type ApiAuthorizationApproveVariables = {
|
|
id: string
|
|
slug: string
|
|
}
|
|
|
|
export type ApiAuthorizationApproveResponse = {
|
|
url: string
|
|
}
|
|
|
|
export async function approveApiAuthorization({ id, slug }: ApiAuthorizationApproveVariables) {
|
|
if (!id) throw new Error('Authorization ID is required')
|
|
if (!slug) throw new Error('Organization slug is required')
|
|
|
|
const { data, error } = await post('/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 }, query: { skip_browser_redirect: true } },
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data as unknown as ApiAuthorizationApproveResponse
|
|
}
|
|
|
|
type ApiAuthorizationApproveData = Awaited<ReturnType<typeof approveApiAuthorization>>
|
|
|
|
export const useApiAuthorizationApproveMutation = (
|
|
options: Omit<
|
|
UseCustomMutationOptions<
|
|
ApiAuthorizationApproveData,
|
|
ResponseError,
|
|
ApiAuthorizationApproveVariables
|
|
>,
|
|
'mutationFn'
|
|
> = {}
|
|
) => {
|
|
return useMutation<ApiAuthorizationApproveData, ResponseError, ApiAuthorizationApproveVariables>({
|
|
mutationFn: (vars) => approveApiAuthorization(vars),
|
|
...options,
|
|
})
|
|
}
|