The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Refactor send support ticket to RQ and update SupportForm to use it
Joshen Lim4d29ba037c1f
diff --git a/studio/components/interfaces/Support/SupportForm.tsx b/studio/components/interfaces/Support/SupportForm.tsxindex f77f92b2efc..bf2bddef769 100644--- a/studio/components/interfaces/Support/SupportForm.tsx+++ b/studio/components/interfaces/Support/SupportForm.tsx@@ -1,3 +1,4 @@+import { useParams } from 'common'import { CLIENT_LIBRARIES } from 'common/constants'import { observer } from 'mobx-react-lite'import Link from 'next/link'@@ -16,17 +17,17 @@ import {Listbox,} from 'ui'-import { useParams } from 'common'import Divider from 'components/ui/Divider'import InformationBox from 'components/ui/InformationBox'import MultiSelect from 'components/ui/MultiSelect'import ShimmeringLoader from 'components/ui/ShimmeringLoader'+import { useSendSupportTicketMutation } from 'data/feedback/support-ticket-send'import { useOrganizationsQuery } from 'data/organizations/organizations-query'import { useProjectsQuery } from 'data/projects/projects-query'import { useProjectSubscriptionV2Query } from 'data/subscriptions/project-subscription-v2-query'import { useFlag, useStore } from 'hooks'import useLatest from 'hooks/misc/useLatest'-import { get, isResponseOk, post } from 'lib/common/fetch'+import { get } from 'lib/common/fetch'import { API_URL } from 'lib/constants'import { detectBrowser } from 'lib/helpers'import { useProfile } from 'lib/profile'@@ -48,6 +49,7 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {const uploadButtonRef = useRef()const enableFreeSupport = useFlag('enableFreeSupport')+ const [isSubmitting, setIsSubmitting] = useState(false)const [uploadedFiles, setUploadedFiles] = useState<File[]>([])const [uploadedDataUrls, setUploadedDataUrls] = useState<string[]>([])const [selectedServices, setSelectedServices] = useState<string[]>([])@@ -68,6 +70,21 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {isSuccess: isSuccessProjects,} = useProjectsQuery()+ const { mutate: submitSupportTicket } = useSendSupportTicketMutation({+ onSuccess: (res, variables) => {+ ui.setNotification({ category: 'success', message: 'Support request sent. Thank you!' })+ setSentCategory(variables.category)+ },+ onError: (error) => {+ ui.setNotification({+ error,+ category: 'error',+ message: `Failed to submit support ticket: ${error.message}`,+ })+ setIsSubmitting(false)+ },+ })+const projectDefaults: Partial<Project>[] = [{ ref: 'no-project', name: 'No specific project' }]const projects = [...(allProjects ?? []), ...projectDefaults]@@ -160,8 +177,8 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {return errors}- const onSubmit = async (values: any, { setSubmitting }: any) => {- setSubmitting(true)+ const onSubmit = async (values: any) => {+ setIsSubmitting(true)const attachments =uploadedFiles.length > 0 ? await uploadAttachments(values.projectRef, uploadedFiles) : []const selectedLibrary = CLIENT_LIBRARIES.find((library) => library.language === values.library)@@ -183,6 +200,8 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {if (values.projectRef !== 'no-project') {const URL = `${API_URL}/auth/${values.projectRef}/config`+ // [Joshen] Will refactor another time once+ // https://github.com/supabase/supabase/pull/16227 goes inconst authConfig = await get(URL)if (!authConfig.error) {payload.siteUrl = authConfig.SITE_URL@@ -190,22 +209,12 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {}}- const response = await post<void>(`${API_URL}/feedback/send`, payload)- if (!isResponseOk(response)) {- ui.setNotification({- category: 'error',- message: `Failed to submit support ticket: ${response.error.message}`,- })- setSubmitting(false)- } else {- ui.setNotification({ category: 'success', message: 'Support request sent. Thank you!' })- setSentCategory(values.category)- }+ submitSupportTicket(payload)}return (<Form id="support-form" initialValues={initialValues} validate={onValidate} onSubmit={onSubmit}>- {({ isSubmitting, resetForm, values }: any) => {+ {({ resetForm, values }: any) => {const selectedCategory = CATEGORY_OPTIONS.find((category) => category.value === values.category)diff --git a/studio/data/feedback/support-ticket-send.ts b/studio/data/feedback/support-ticket-send.tsnew file mode 100644index 00000000000..ce9118afded--- /dev/null+++ b/studio/data/feedback/support-ticket-send.ts@@ -0,0 +1,81 @@+import { useMutation, UseMutationOptions } from '@tanstack/react-query'+import { toast } from 'react-hot-toast'++import { post } from 'data/fetchers'+import { ResponseError } from 'types'++export type sendSupportTicketVariables = {+ subject: string+ message: string+ category: string+ severity: string+ projectRef?: string+ organizationSlug?: string+ library?: string+ affectedServices?: string+ browserInformation?: string+ allowSupportAccess: boolean+}++export async function sendSupportTicket({+ subject,+ message,+ category,+ severity,+ projectRef,+ organizationSlug,+ library,+ affectedServices,+ browserInformation,+ allowSupportAccess,+}: sendSupportTicketVariables) {+ const { data, error } = await post('/platform/feedback/send', {+ body: {+ subject,+ message,+ category,+ severity,+ projectRef,+ organizationSlug,+ library,+ verified: true,+ tags: ['dashboard-support-form'],+ siteUrl: '',+ additionalRedirectUrls: '',+ affectedServices,+ browserInformation,+ allowSupportAccess,+ },+ })++ if (error) throw error+ return data+}++type sendSupportTicketData = Awaited<ReturnType<typeof sendSupportTicket>>++export const useSendSupportTicketMutation = ({+ onSuccess,+ onError,+ ...options+}: Omit<+ UseMutationOptions<sendSupportTicketData, ResponseError, sendSupportTicketVariables>,+ 'mutationFn'+> = {}) => {+ return useMutation<sendSupportTicketData, ResponseError, sendSupportTicketVariables>(+ (vars) => sendSupportTicket(vars),+ {+ async onSuccess(data, variables, context) {+ await onSuccess?.(data, variables, context)+ },+ async onError(data, variables, context) {+ if (onError === undefined) {+ toast.error(`Failed to submit support ticket: ${data.message}`)+ } else {+ onError(data, variables, context)+ }+ },+ ...options,+ }+ )+}