Files
supabase/apps/studio/data/telemetry/send-groups-reset-mutation.ts
Joshen Lim 9b3d87207f Chore/add new telemetry triggers for ph (#29769)
* Init new telemetry mutations and add telemetry reset for logging out

* Add sendPageLeave on unloadBefore event in PageTelemetry

* Add sendGroupsIdentify and sendGroupsReset in PageTelemetry

* Ensure new telemetry triggers only if feature flag is enabled

* Update call to sendGroupsReset

* some fixes and ensure that telemetry opt in is true before firing telemetry events

* Ensure that telemetry events get triggered when landing on project or org
2024-10-09 17:52:43 +08:00

45 lines
1.3 KiB
TypeScript

import { useMutation, UseMutationOptions } from '@tanstack/react-query'
import { components } from 'api-types'
import { handleError, post } from 'data/fetchers'
import type { ResponseError } from 'types'
export type SendGroupsResetVariables = components['schemas']['TelemetryGroupsResetBody']
export async function sendGroupsReset(body: SendGroupsResetVariables) {
const { data, error } = await post(`/platform/telemetry/groups/reset`, {
body,
credentials: 'include',
})
if (error) handleError(error)
return data
}
type SendGroupsResetData = Awaited<ReturnType<typeof sendGroupsReset>>
export const useSendGroupsResetMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseMutationOptions<SendGroupsResetData, ResponseError, SendGroupsResetVariables>,
'mutationFn'
> = {}) => {
return useMutation<SendGroupsResetData, ResponseError, SendGroupsResetVariables>(
(vars) => sendGroupsReset(vars),
{
async onSuccess(data, variables, context) {
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
console.error(`Failed to send Telemetry groups reset: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
}
)
}