Files
supabase/apps/studio/data/sso/sso-config-create-mutation.ts
Ivan Vasilov 26e89b36c3 chore: Regenerate API types and fix all issues (#49646)
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 -->
2026-08-27 17:07:58 +02:00

56 lines
1.7 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, post } from '@/data/fetchers'
import type { ResponseError, UseCustomMutationOptions } from '@/types'
type CreateSSOProviderBody =
operations['SSOProvidersController_createSSOProvider']['requestBody']['content']['application/json']
export type SSOConfigCreateVariables = {
slug: string
config: CreateSSOProviderBody
}
export async function createSSOConfig({ slug, config }: SSOConfigCreateVariables) {
const { data, error } = await post('/platform/organizations/{slug}/sso', {
params: { path: { slug } },
body: config,
})
if (error) handleError(error)
return data
}
type SSOConfigCreateData = Awaited<ReturnType<typeof createSSOConfig>>
export const useSSOConfigCreateMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseCustomMutationOptions<SSOConfigCreateData, ResponseError, SSOConfigCreateVariables>,
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
return useMutation<SSOConfigCreateData, ResponseError, SSOConfigCreateVariables>({
mutationFn: (vars) => createSSOConfig(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) {
toast.error(`Failed to create SSO configuration: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
})
}