mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { useMutation } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
export type SendDowngradeFeedbackVariables = {
|
|
projectRef?: string
|
|
orgSlug?: string
|
|
reasons: string
|
|
message: string
|
|
exitAction: 'downgrade' | 'delete'
|
|
}
|
|
|
|
export async function sendDowngradeFeedback({
|
|
projectRef,
|
|
orgSlug,
|
|
reasons,
|
|
message,
|
|
exitAction,
|
|
}: SendDowngradeFeedbackVariables) {
|
|
const { data, error } = await post('/platform/feedback/downgrade', {
|
|
body: {
|
|
...(projectRef !== undefined && { projectRef }),
|
|
...(orgSlug !== undefined && { orgSlug }),
|
|
reasons,
|
|
additionalFeedback: message,
|
|
exitAction,
|
|
},
|
|
})
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type SendDowngradeFeedbackData = Awaited<ReturnType<typeof sendDowngradeFeedback>>
|
|
|
|
export const useSendDowngradeFeedbackMutation = ({
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<
|
|
SendDowngradeFeedbackData,
|
|
ResponseError,
|
|
SendDowngradeFeedbackVariables
|
|
>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
return useMutation<SendDowngradeFeedbackData, ResponseError, SendDowngradeFeedbackVariables>({
|
|
mutationFn: (vars) => sendDowngradeFeedback(vars),
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to submit exit survey: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|