The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Include exit survey for project deletion when deleting a paid project
Joshen Limb6fab995511d
diff --git a/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsxindex 2dffe5af320..a4de90d7d37 100644--- a/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx+++ b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx@@ -139,7 +139,7 @@ const ExitSurvey: FC<Props> = ({ freeTier, subscription, onSelectBack }) => {}}- // Submit feedback to Freshdesk+ // Submit exit survey to Hubspotconst feedbackRes = await post(`${API_URL}/feedback/send`, {projectRef,subject: 'Subscription cancellation - Exit survey',diff --git a/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx b/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsxindex edfff4083d4..6bd489a0fd2 100644--- a/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx+++ b/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx@@ -1,13 +1,15 @@-import { FC, useState } from 'react'+import { FC, useEffect, useState } from 'react'import { useRouter } from 'next/router'-import { Button } from 'ui'+import { Button, Input } from 'ui'import * as Tooltip from '@radix-ui/react-tooltip'+import { PermissionAction } from '@supabase/shared-types/out/constants'import { useStore, checkPermissions, useFlag } from 'hooks'-import { API_URL } from 'lib/constants'-import { delete_ } from 'lib/common/fetch'+import { API_URL, PRICING_TIER_PRODUCT_IDS } from 'lib/constants'+import { delete_, post } from 'lib/common/fetch'import TextConfirmModal from 'components/ui/Modals/TextConfirmModal'-import { PermissionAction } from '@supabase/shared-types/out/constants'+import { CANCELLATION_REASONS } from 'components/interfaces/Billing/Billing.constants'+import { generateFeedbackMessage } from 'components/interfaces/Billing/ExitSurvey/ExitSurvey.utils'interface Props {type?: 'danger' | 'default'@@ -19,10 +21,23 @@ const DeleteProjectButton: FC<Props> = ({ type = 'danger' }) => {const enablePermissions = useFlag('enablePermissions')const project = ui.selectedProject+ const projectRef = project?.ref+ const projectTier = project?.subscription_tier+const isOwner = ui.selectedOrganization?.is_owner+ const isFree = projectTier === PRICING_TIER_PRODUCT_IDS.FREEconst [isOpen, setIsOpen] = useState(false)const [loading, setLoading] = useState(false)+ const [selectedReasons, setSelectedReasons] = useState<string[]>([])+ const [cancellationMessage, setCancellationMessage] = useState<string>('')++ useEffect(() => {+ if (isOpen) {+ setSelectedReasons([])+ setCancellationMessage('')+ }+ }, [isOpen])const canDeleteProject = enablePermissions? checkPermissions(PermissionAction.UPDATE, 'projects')@@ -33,12 +48,29 @@ const DeleteProjectButton: FC<Props> = ({ type = 'danger' }) => {setIsOpen(!isOpen)}+ const onSelectCancellationReason = (reason: string) => {+ const existingSelection = selectedReasons.find((x) => x === reason)+ const updatedSelection =+ existingSelection === undefined+ ? selectedReasons.concat([reason])+ : selectedReasons.filter((x) => x !== reason)+ setSelectedReasons(updatedSelection)+ }+async function handleDeleteProject() {if (project === undefined) return+ if (!isFree && selectedReasons.length === 0) {+ return ui.setNotification({+ category: 'error',+ duration: 4000,+ message: 'Please select at least one reason for deleting your project',+ })+ }+setLoading(true)try {- const response = await delete_(`${API_URL}/projects/${project.ref}`)+ const response = await delete_(`${API_URL}/projects/${projectRef}`)if (response.error) throw response.errorapp.onProjectDeleted(response)ui.setNotification({ category: 'success', message: `Successfully deleted ${project.name}` })@@ -50,6 +82,16 @@ const DeleteProjectButton: FC<Props> = ({ type = 'danger' }) => {message: `Failed to delete project ${project.name}: ${error.message}`,})}++ // Submit exit survey to Hubspot+ const feedbackRes = await post(`${API_URL}/feedback/send`, {+ projectRef,+ subject: 'Subscription cancellation - Exit survey',+ tags: ['dashboard-exitsurvey'],+ category: 'Billing',+ message: generateFeedbackMessage(selectedReasons, cancellationMessage),+ })+ if (feedbackRes.error) throw feedbackRes.error}return (@@ -79,15 +121,76 @@ const DeleteProjectButton: FC<Props> = ({ type = 'danger' }) => {<TextConfirmModalvisible={isOpen}loading={loading}+ size={isFree ? 'small' : 'xlarge'}title={`Confirm deletion of ${project?.name}`}+ alert={+ isFree+ ? 'This action cannot be undone.'+ : `This will permanently delete the ${project?.name} project and all of its data, and cannot be undone`+ }+ text={+ isFree+ ? `This will permanently delete the ${project?.name} project and all of its data.`+ : undefined+ }confirmPlaceholder="Type the project name in here"- alert="This action cannot be undone."- text={`This will permanently delete the ${project?.name} project and all of its data.`}confirmString={project?.name || ''}confirmLabel="I understand, delete this project"onConfirm={handleDeleteProject}onCancel={toggle}- />+ >+ {/*+ [Joshen] This is basically ExitSurvey.tsx, ideally we have one shared component but the one+ in ExitSurvey has a Form wrapped around it already. Will probably need some effort to refactor+ but leaving that for the future.+ */}+ <div className="space-y-1">+ <h4 className="text-base">We're sad that you're leaving.</h4>+ <p className="text-sm text-scale-1100">+ We always strive to improve Supabase as much as we can. Please let us know the reasons+ you are deleting your project so that we can improve in the future.+ </p>+ </div>+ <div className="space-y-4 pt-4">+ <div className="flex flex-wrap gap-2" data-toggle="buttons">+ {CANCELLATION_REASONS.map((option) => {+ const active = selectedReasons.find((x) => x === option)+ return (+ <label+ key={option}+ className={[+ 'flex cursor-pointer items-center space-x-2 rounded-md py-1',+ 'pl-2 pr-3 text-center text-sm shadow-sm transition-all duration-100',+ `${+ active+ ? ` bg-scale-1200 text-scale-100 opacity-100 hover:bg-opacity-75`+ : ` bg-scale-700 text-scale-1200 opacity-25 hover:opacity-50`+ }`,+ ].join(' ')}+ >+ <input+ type="checkbox"+ name="options"+ value={option}+ className="hidden"+ onClick={(event: any) => onSelectCancellationReason(event.target.value)}+ />+ <div>{option}</div>+ </label>+ )+ })}+ </div>+ <div className="text-area-text-sm">+ <Input.TextArea+ name="message"+ label="Anything else that we can improve on?"+ rows={3}+ value={cancellationMessage}+ onChange={(event) => setCancellationMessage(event.target.value)}+ />+ </div>+ </div>+ </TextConfirmModal></>)}diff --git a/studio/components/ui/Modals/TextConfirmModal.tsx b/studio/components/ui/Modals/TextConfirmModal.tsxindex 78d413c865b..5394761ff22 100644--- a/studio/components/ui/Modals/TextConfirmModal.tsx+++ b/studio/components/ui/Modals/TextConfirmModal.tsx@@ -5,17 +5,20 @@ interface Props {loading: booleanvisible: booleantitle: string+ size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'confirmLabel: stringconfirmPlaceholder: stringconfirmString: string- alert: string- text: string | ReactNode+ alert?: string+ text?: string | ReactNode+ children?: ReactNodeonConfirm: () => voidonCancel: () => void}const TextConfirmModal: FC<Props> = ({title,+ size = 'small',onConfirm,visible,onCancel,@@ -25,6 +28,7 @@ const TextConfirmModal: FC<Props> = ({confirmString,alert,text,+ children,}) => {// [Joshen] Have to keep the loading prop here as this component itself doesn't// directly trigger any potential async job that follows onConfirm. It only triggers@@ -42,7 +46,7 @@ const TextConfirmModal: FC<Props> = ({}return (- <Modal hideFooter closable size="small" visible={visible} header={title} onCancel={onCancel}>+ <Modal hideFooter closable size={size} visible={visible} header={title} onCancel={onCancel}><FormvalidateOnBlurinitialValues={{ confirmValue: '' }}@@ -52,14 +56,22 @@ const TextConfirmModal: FC<Props> = ({{() => (<div className="w-full py-4"><div className="space-y-4">+ {children !== undefined && (+ <>+ <Modal.Content>{children}</Modal.Content>+ <Modal.Separator />+ </>+ )}{alert && (<Modal.Content><Alert variant="warning" withIcon title={alert} /></Modal.Content>)}- <Modal.Content>- <p className="mb-2 block text-sm">{text}</p>- </Modal.Content>+ {text !== undefined && (+ <Modal.Content>+ <p className="mb-2 block text-sm">{text}</p>+ </Modal.Content>+ )}<Modal.Separator /><Modal.Content><Input