Files
supabase/apps/studio/data/telemetry/send-reset-mutation.ts
T
Ivan VasilovandJoshen Lim f29003e0e7 fix: Use protocol property when building API url (#30332)
* Fix the types for API settings to include protocol.

* Use the protocol property in all usages of endpoints.

* Update

* Lint

* Revert changes to retrieving protocol

* Remove console.logs

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-11-06 22:22:24 +01:00

36 lines
1.0 KiB
TypeScript

import { useMutation, UseMutationOptions } from '@tanstack/react-query'
import { handleError, post } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
import type { ResponseError } from 'types'
export async function sendReset() {
if (!IS_PLATFORM) return undefined
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,
})
}