Files
supabase/apps/studio/data/auth/validate-spam-mutation.ts
T
Joshen LimandPaul Cioanca a4243f438f Add restrictions for orioledb technical preview (#30410)
* Add restrictions for orioledb technical preview

* Add callouts to pgvector and postgis if orioledb

* Restrict restore to new project for orioledb

* Scaffold client side validation for preventing org upgrade if org has oriole db present

* Hook up proper logic for oriole

* Fix

* Remove console log

* Fix type

* Disable version selector if only one version is available

* chore: oriole badges

* UI updates based on requests

* Update copy

* Fix

* Dont open assistant if opt is selected

* Fix

* Fix

* Update badge

* Add feature flag for orioleDB

* Feature flag oriole check in plan update

---------

Co-authored-by: Paul Cioanca <paul.cioanca@supabase.io>
2024-11-30 17:36:15 +08:00

52 lines
1.5 KiB
TypeScript

import { useMutation, UseMutationOptions } from '@tanstack/react-query'
import { toast } from 'sonner'
import type { components } from 'data/api'
import { handleError, post } from 'data/fetchers'
import type { ResponseError } from 'types'
export type ValidateSpamVariables = {
projectRef: string
template: components['schemas']['ValidateSpamBodyDto']
}
export type ValidateSpamResponse = components['schemas']['ValidateSpamResponse']
export async function validateSpam({ projectRef, template }: ValidateSpamVariables) {
const { data, error } = await post('/platform/auth/{ref}/validate/spam', {
// @ts-expect-error API doesnt have the param check cause it's not being used in the controller
params: { path: { ref: projectRef } },
body: template,
})
if (error) handleError(error)
return data
}
type ValidateSpamData = Awaited<ReturnType<typeof validateSpam>>
export const useValidateSpamMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseMutationOptions<ValidateSpamData, ResponseError, ValidateSpamVariables>,
'mutationFn'
> = {}) => {
return useMutation<ValidateSpamData, ResponseError, ValidateSpamVariables>(
(vars) => validateSpam(vars),
{
async onSuccess(data, variables, context) {
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
toast.error(`Failed to validate template: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
}
)
}