Files
supabase/apps/studio/data/telemetry/send-reset-mutation.ts
T
Joshen Lim cdb07346bc Update PH consent banner (#29891)
* Update PH consent banner

* Fix
2024-10-15 16:32:37 +08:00

33 lines
967 B
TypeScript

import { useMutation, UseMutationOptions } from '@tanstack/react-query'
import { handleError, post } from 'data/fetchers'
import type { ResponseError } from 'types'
export async function sendReset() {
const { data, error } = await post(`/platform/telemetry/reset`, {})
if (error) handleError(error)
return data
}
type SendResetData = Awaited<ReturnType<typeof sendReset>>
export const useSendResetMutation = ({
onSuccess,
onError,
...options
}: Omit<UseMutationOptions<SendResetData, ResponseError>, 'mutationFn'> = {}) => {
return useMutation<SendResetData, ResponseError>(() => sendReset(), {
async onSuccess(data, variables, context) {
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
console.error(`Failed to send Telemetry reset: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
})
}