mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 13:49:09 +03:00
A bunch of small issues have showed up where the API types are breaking the FE repo: - Regenerate the API types. - For the removed Response types, use the return types from the operations instead. - Fix some types which now have a suffix `_Output`. - Add `requires_indirect_tax_declaration` property to Organization instances in mocks. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Updated Studio and shared type references to use generated API definitions consistently. * Improved typing for SSO configuration creation and updates. * Aligned telemetry lint categories with API-provided values. * Marked the legacy API type re-export as deprecated. * **Tests** * Updated test fixtures and response types to reflect current API contracts. * Added indirect tax declaration data to organization test scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import type { operations } from 'api-types'
|
|
import { toast } from 'sonner'
|
|
|
|
import { orgSSOKeys } from './keys'
|
|
import { handleError, put } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
type UpdateSSOProviderBody =
|
|
operations['SSOProvidersController_updateSSOProvider']['requestBody']['content']['application/json']
|
|
|
|
export type SSOConfigUpdateVariables = {
|
|
slug: string
|
|
config: Partial<UpdateSSOProviderBody>
|
|
}
|
|
|
|
export async function updateSSOConfig({ slug, config }: SSOConfigUpdateVariables) {
|
|
const { data, error } = await put('/platform/organizations/{slug}/sso', {
|
|
params: { path: { slug } },
|
|
body: config as UpdateSSOProviderBody,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type SSOConfigUpdateData = Awaited<ReturnType<typeof updateSSOConfig>>
|
|
|
|
export const useSSOConfigUpdateMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<SSOConfigUpdateData, ResponseError, SSOConfigUpdateVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<SSOConfigUpdateData, ResponseError, SSOConfigUpdateVariables>({
|
|
mutationFn: (vars) => updateSSOConfig(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { slug } = variables
|
|
await queryClient.invalidateQueries({ queryKey: orgSSOKeys.orgSSOConfig(slug) })
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
if (data.message === '') {
|
|
toast.error(`Failed to update SSO configuration.`)
|
|
} else {
|
|
toast.error(`${data.message}`)
|
|
}
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|