Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Feat: Add account deletion button to Preferences (#22486)

Monica Khoury9cc616351262
diff --git a/apps/studio/components/interfaces/Account/Preferences/AccountDeletion.tsx b/apps/studio/components/interfaces/Account/Preferences/AccountDeletion.tsx
new file mode 100644
index 00000000000..87dae7bfd9e
--- /dev/null
+++ b/apps/studio/components/interfaces/Account/Preferences/AccountDeletion.tsx
@@ -0,0 +1,30 @@
+import Panel from 'components/ui/Panel'
+import { useProfile } from 'lib/profile'
+import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_ } from 'ui'
+import { CriticalIcon } from 'ui-patterns/Icons/StatusIcons'
+import { DeleteAccountButton } from './DeleteAccountButton'
+
+export const AccountDeletion = () => {
+ const { profile } = useProfile()
+
+ return (
+ <>
+ <Panel className="[&>div:first-child]:uppercase" title="Danger Zone">
+ <Panel.Content>
+ <Alert_Shadcn_ variant="destructive">
+ <CriticalIcon />
+ <AlertTitle_Shadcn_>Request for account deletion</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Deleting your account is permanent and cannot be undone. Your data will be deleted
+ within 30 days, except we may retain some metadata and logs for longer where required
+ or permitted by law.
+ </AlertDescription_Shadcn_>
+ <AlertDescription_Shadcn_ className="mt-3">
+ <DeleteAccountButton />
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ </Panel.Content>
+ </Panel>
+ </>
+ )
+}
diff --git a/apps/studio/components/interfaces/Account/Preferences/DeleteAccountButton.tsx b/apps/studio/components/interfaces/Account/Preferences/DeleteAccountButton.tsx
new file mode 100644
index 00000000000..7fef3f9478f
--- /dev/null
+++ b/apps/studio/components/interfaces/Account/Preferences/DeleteAccountButton.tsx
@@ -0,0 +1,171 @@
+import { zodResolver } from '@hookform/resolvers/zod'
+import { useEffect, useState } from 'react'
+import { useForm } from 'react-hook-form'
+import toast from 'react-hot-toast'
+import * as z from 'zod'
+
+import { useSendSupportTicketMutation } from 'data/feedback/support-ticket-send'
+import { useOrganizationsQuery } from 'data/organizations/organizations-query'
+import { useProfile } from 'lib/profile'
+import {
+ Button,
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogSection,
+ DialogSectionSeparator,
+ DialogTitle,
+ DialogTrigger,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ FormItem_Shadcn_,
+ FormLabel_Shadcn_,
+ Form_Shadcn_,
+ Input_Shadcn_,
+} from 'ui'
+
+export const DeleteAccountButton = () => {
+ const { profile } = useProfile()
+ const [isOpen, setIsOpen] = useState(false)
+ const { data: organizations, isSuccess } = useOrganizationsQuery()
+ const numberOfOwnership = (organizations ?? []).filter((org) => org.is_owner).length
+
+ const accountEmail = profile?.primary_email
+ const FormSchema = z.object({ account: z.string() })
+ const form = useForm<z.infer<typeof FormSchema>>({
+ mode: 'onBlur',
+ reValidateMode: 'onBlur',
+ resolver: zodResolver(FormSchema),
+ defaultValues: { account: '' },
+ })
+ const { account } = form.watch()
+
+ const { mutate: submitSupportTicket, isLoading } = useSendSupportTicketMutation({
+ onSuccess: () => {
+ setIsOpen(false)
+ toast.success(
+ 'Successfully submitted account deletion request - we will reach out to you via email once the request is completed!',
+ { duration: 8000 }
+ )
+ },
+ onError: (error) => {
+ toast.error(`Failed to submit account deletion request: ${error}`)
+ },
+ })
+
+ const onConfirmDelete = async () => {
+ if (!accountEmail) return console.error('Account information is required')
+
+ const payload = {
+ subject: 'Account Deletion Request',
+ message: 'I want to delete my account.',
+ category: 'Account deletion',
+ severity: 'Medium',
+ allowSupportAccess: false,
+ }
+
+ submitSupportTicket(payload)
+ }
+
+ useEffect(() => {
+ if (isOpen && form !== undefined) form.reset({ account: '' })
+ }, [form, isOpen])
+
+ return (
+ <Dialog open={isOpen} onOpenChange={setIsOpen}>
+ <DialogTrigger asChild>
+ <Button type="danger" loading={!accountEmail}>
+ Request to delete account
+ </Button>
+ </DialogTrigger>
+ <DialogContent className="!w-[500px]">
+ <DialogHeader className="pb-0">
+ {(organizations ?? []).length > 0 ? (
+ <>
+ <DialogTitle>Leave all organizations before requesting account deletion</DialogTitle>
+ <DialogDescription>
+ This will allow us to process your account deletion request faster
+ </DialogDescription>
+ </>
+ ) : (
+ <>
+ <DialogTitle>Are you sure you want to delete your account?</DialogTitle>
+ <DialogDescription>
+ Deleting your account is permanent and{' '}
+ <span className="text-foreground">cannot</span> be undone
+ </DialogDescription>
+ </>
+ )}
+ </DialogHeader>
+
+ {isSuccess && (
+ <>
+ {organizations.length > 0 ? (
+ <DialogSection className="!pt-0">
+ <span className="text-sm text-foreground flex flex-col gap-y-2">
+ Before submitting an account deletion request, please ensure that your account is
+ not part of any organization. This can be done by leaving leaving or deleting the
+ organizations that you are a part of.
+ </span>
+ <Button
+ block
+ type="primary"
+ size="medium"
+ className="mt-6"
+ onClick={() => setIsOpen(false)}
+ >
+ Understood
+ </Button>
+ </DialogSection>
+ ) : (
+ <Form_Shadcn_ {...form}>
+ <form
+ id="account-deletion-request"
+ className="flex flex-col gap-y-4"
+ onSubmit={form.handleSubmit(() => onConfirmDelete())}
+ >
+ <FormField_Shadcn_
+ name="account"
+ control={form.control}
+ render={({ field }) => (
+ <FormItem_Shadcn_ className="px-7">
+ <FormLabel_Shadcn_>
+ Please type{' '}
+ <span className="font-bold">{profile?.primary_email ?? ''}</span> to
+ confirm
+ </FormLabel_Shadcn_>
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ autoFocus
+ {...field}
+ autoComplete="off"
+ disabled={isLoading}
+ placeholder="Enter the account above"
+ />
+ </FormControl_Shadcn_>
+ </FormItem_Shadcn_>
+ )}
+ />
+ <DialogSectionSeparator />
+ <div className="px-7 pb-4">
+ <Button
+ block
+ size="small"
+ type="danger"
+ htmlType="submit"
+ loading={isLoading}
+ disabled={account !== accountEmail || isLoading}
+ >
+ Submit request for account deletion
+ </Button>
+ </div>
+ </form>
+ </Form_Shadcn_>
+ )}
+ </>
+ )}
+ </DialogContent>
+ </Dialog>
+ )
+}
diff --git a/apps/studio/components/ui/Panel.tsx b/apps/studio/components/ui/Panel.tsx
index 84f9a7b1a89..76965332a19 100644
--- a/apps/studio/components/ui/Panel.tsx
+++ b/apps/studio/components/ui/Panel.tsx
@@ -25,8 +25,13 @@ function Panel(props: PropsWithChildren<PanelProps>) {
)}
>
{props.title && (
- <div className={cn('bg-surface-100 border-b border-muted', props.titleClasses)}>
- <div className="flex items-center px-6 py-4">{props.title}</div>
+ <div
+ className={cn(
+ 'bg-surface-100 border-b border-muted flex items-center px-6 py-4',
+ props.titleClasses
+ )}
+ >
+ {props.title}
</div>
)}
{props.children}
diff --git a/apps/studio/pages/account/me.tsx b/apps/studio/pages/account/me.tsx
index d301d240215..8d1ddc8feb7 100644
--- a/apps/studio/pages/account/me.tsx
+++ b/apps/studio/pages/account/me.tsx
@@ -4,6 +4,7 @@ import {
ThemeSettings,
ThemeSettingsOld,
} from 'components/interfaces/Account/Preferences'
+import { AccountDeletion } from 'components/interfaces/Account/Preferences/AccountDeletion'
import { ProfileInformation } from 'components/interfaces/Account/Preferences/ProfileInformation'
import { AccountLayout } from 'components/layouts'
import AlertError from 'components/ui/AlertError'
@@ -74,6 +75,10 @@ const ProfileCard = () => {
<section>
<AnalyticsSettings />
</section>
+
+ <section>
+ <AccountDeletion />
+ </section>
</article>
)
}