mirror of
https://github.com/supabase/supabase.git
synced 2026-07-06 18:44:22 +08:00
Add a docs feedback widget to allow upvoting and downvoting pages. Votes (completely anonymized, barely more than a counter) go to a database in the main supabase-com project. If the user has accepted telemetry, the votes also go to Logflare with a bit more info. Post-vote, logged-in users can leave a comment, which goes to the `platform/feedback/send` endpoint. There is a warning in the feedback modal that the feedback is not anonymous.
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { type UseMutationOptions, useMutation } from '@tanstack/react-query'
|
|
|
|
import { type ResponseError } from '~/types/fetch'
|
|
import { post } from './fetchWrappers'
|
|
|
|
type SendFeedbackVariables = {
|
|
message: string
|
|
pathname?: string
|
|
}
|
|
|
|
export async function sendFeedback({ message, pathname }: SendFeedbackVariables) {
|
|
const { data, error } = await post('/platform/feedback/send', {
|
|
body: {
|
|
message,
|
|
category: 'Feedback',
|
|
tags: ['docs-feedback'],
|
|
pathname,
|
|
},
|
|
})
|
|
if (error) throw Error(`Couldn't send feedback`, { cause: error })
|
|
return data
|
|
}
|
|
|
|
type SendFeedbackData = Awaited<ReturnType<typeof sendFeedback>>
|
|
|
|
export const useSendFeedbackMutation = (
|
|
options: Omit<
|
|
UseMutationOptions<SendFeedbackData, ResponseError, SendFeedbackVariables>,
|
|
'mutationFn'
|
|
> = {}
|
|
) => {
|
|
return useMutation<SendFeedbackData, ResponseError, SendFeedbackVariables>({
|
|
...options,
|
|
mutationFn: (vars) => sendFeedback(vars),
|
|
onError: (error, vars, ctx) => {
|
|
console.error(error)
|
|
options.onError?.(error, vars, ctx)
|
|
},
|
|
})
|
|
}
|