mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import { usageKeys } from '@/data/usage/keys'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
export type TempDisableReadOnlyModeVariables = {
|
|
projectRef: string
|
|
}
|
|
|
|
export async function tempDisableReadOnlyMode({ projectRef }: TempDisableReadOnlyModeVariables) {
|
|
const { data, error } = await post('/v1/projects/{ref}/readonly/temporary-disable', {
|
|
params: { path: { ref: projectRef } },
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type DisableReadOnlyModeData = Awaited<ReturnType<typeof tempDisableReadOnlyMode>>
|
|
|
|
export const useDisableReadOnlyModeMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<
|
|
DisableReadOnlyModeData,
|
|
ResponseError,
|
|
TempDisableReadOnlyModeVariables
|
|
>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
return useMutation<DisableReadOnlyModeData, ResponseError, TempDisableReadOnlyModeVariables>({
|
|
mutationFn: (vars) => tempDisableReadOnlyMode(vars),
|
|
async onSuccess(data, variables, context) {
|
|
setTimeout(
|
|
() => queryClient.invalidateQueries({ queryKey: usageKeys.resourceWarnings() }),
|
|
2000
|
|
)
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to disable read only mode: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|