mirror of
https://github.com/supabase/supabase.git
synced 2026-10-16 22:59:11 +03:00
* init * Update inner-side-menu.mdx * chore: update SQL sidebar to use ui pattern components * mor * Update * Update index.tsx * init: merge table editor and sql editor and schema visualization together * more * move to valtio * fix issue with Command+B shortcut * now shows in treeviews if item is opened in tab * Update ProjectLayout.tsx * fix sidebar * fix schema selector for non explorer version * show schema name in tabs * added schema names to tabs * tabs have been updated to support preview tabs * fix URL issue * add empty state stuff * Update SQLEditorNav.tsx * preview tab works now * more tabs stuff. 'new' tab also added * new tab concept * updates * fix type errors * remove unused files * update test * move back button, fix width issues on sidebar * update sidebar logic * Update ProjectLayout.tsx * lots of updates. layouts now streamlined. localstorage for tabs in use * moar * bunch of new tab logic * fix empty tab issue * Update tabs.ts * layouts switched * new pages now have fixed layouts * fix tabs * fix code bg * add tabs support for multiple project refs * intialization issue * update ID handling * fixed isOpened state for SQL snippets * remove old assistant because its bugging up panels * preview style works in sql editor * fix border * removes preview tab if there is one * fix background of loading skeleton * lots of issues with types/icons/redirect * new tab cards * snippets in empty state now work * moar stuff * tabs now in feature flags * Update tabs.ts * Update tabs.ts * moar * add feature previews * remove code not needed * Update next-env.d.ts * Delete FeaturePreviewModal.tsx * fix typescript errors. remove more explorer stuff * remove explorer files * fixed issues with templates and quickstarts tab * fixed active state when tabs are not opted in * logic error * fix open/highlight issue when opted out of tabs * templates/quickstarts now displayed with new cards * Update recent-items.tsx * Update new-tab.tsx * add icon back in * add old empty state back in * recent items updated to respect project ref * localstorage cleanup on deletion * moar * overflow tabs now working * correct tab names used for new sql templates/quickstarts * ongoing queries fix * cleanup * update images * Update RouteValidationWrapper.tsx * Update AppLayout.tsx * Update NavigationBar.tsx * add headers back into side panels * improve writing * tabs now drag and drop a billion times better * Update tabs.tsx * Update tabs.tsx * init issues on stores, which caused a race condition. * fix hydration error * fix new tab issue in sql * Update ProjectLayout.tsx * Update pnpm-lock.yaml * Update new-tab.tsx * move EditorMenuListSkeleton * Fix type issues * fixes: DESIGN-87 fixes: DESIGN-87 * refactor sort/filter components * Update rules-set-button-text.tsx * remove discussions for now * small styling fixes * Update FeaturePreviewModal.tsx * Update FeaturePreviewModal.tsx * Update RouteValidationWrapper.tsx * revert * revert * revert * revert * revert * more revert * Update collapse-button.tsx * Update SQLEditorTreeViewItem.tsx * revert * Update SchemaGraph.tsx * Delete new-upcoming.tsx * revert * Update ProjectLayout.tsx * fix home link * Update table-editor.spec.ts * test update * Update table-editor.spec.ts * Fix the playwright tests. * layout fixes * layout fix * revert sort/filter * Update LastSignInWrapper.tsx * revert * revert * remove * update file names * revert * revert * revert * Fix TreeView console error props * Add guards in SQL Editor to ensure that feature preview tabs changes do not affect existing UI when flag is off * Fix missing DefaultLayout in SQL editor templates + fix New tab * Remove console log * Remove DatabaseSelector for SQL editor on local * Fix SQL editor shared favorites for local * Fix test * Ensure NewTab doesn't show up if flag is not toggled for SQL editor * Decouple UI state changes from content-query and entity-types-infinite-query * Fix tab closing unnecessary rerouting * Beef up feature previews * Fix create new table from table editor new tab * Fix tabs getting incorrectly reset when going between table and SQL editors * Fix last visited SQL snippet for both tabs and not tabs * Fix last visited table for table editor tabs * Clear dashboard history when closing last tab * Fix loading dashboard history * Add comment to refactor stores * Ensure we only save up to 8 items for recent items for each type * Remove unneccesary logic in tabs * Smol style fix for DeleteAccountButton * Smol fix * Fix inability to close New tab --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Alaister Young <a@alaisteryoung.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
203 lines
6.6 KiB
TypeScript
203 lines
6.6 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { SupportCategories } from '@supabase/shared-types/out/constants'
|
|
import { LOCAL_STORAGE_KEYS } from 'lib/constants'
|
|
import { useEffect, useState } from 'react'
|
|
import { useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
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,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
FormControl_Shadcn_,
|
|
FormField_Shadcn_,
|
|
FormItem_Shadcn_,
|
|
FormLabel_Shadcn_,
|
|
Form_Shadcn_,
|
|
Input_Shadcn_,
|
|
Separator,
|
|
} from 'ui'
|
|
|
|
const setDeletionRequestFlag = () => {
|
|
const expiryDate = new Date()
|
|
expiryDate.setDate(expiryDate.getDate() + 30)
|
|
localStorage.setItem(LOCAL_STORAGE_KEYS.ACCOUNT_DELETION_REQUEST, expiryDate.toString())
|
|
}
|
|
|
|
const hasActiveDeletionRequest = () => {
|
|
const expiryDateStr = localStorage.getItem(LOCAL_STORAGE_KEYS.ACCOUNT_DELETION_REQUEST)
|
|
if (!expiryDateStr) return false
|
|
|
|
const expiryDate = new Date(expiryDateStr)
|
|
const now = new Date()
|
|
|
|
if (now > expiryDate) {
|
|
localStorage.removeItem(LOCAL_STORAGE_KEYS.ACCOUNT_DELETION_REQUEST)
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
export const DeleteAccountButton = () => {
|
|
const { profile } = useProfile()
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
const { data: organizations, isSuccess } = useOrganizationsQuery()
|
|
|
|
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)
|
|
setDeletionRequestFlag()
|
|
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')
|
|
|
|
if (hasActiveDeletionRequest()) {
|
|
return toast.error('You have already submitted a deletion request within the last 30 days.')
|
|
}
|
|
|
|
const payload = {
|
|
subject: 'Account Deletion Request',
|
|
message: 'I want to delete my account.',
|
|
category: SupportCategories.ACCOUNT_DELETION,
|
|
severity: 'Low',
|
|
allowSupportAccess: false,
|
|
verified: true,
|
|
projectRef: 'no-project',
|
|
}
|
|
|
|
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>
|
|
{(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>
|
|
|
|
<Separator />
|
|
|
|
{isSuccess && (
|
|
<>
|
|
{organizations.length > 0 ? (
|
|
<>
|
|
<DialogSection>
|
|
<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 or deleting the
|
|
organizations that you are a part of.
|
|
</span>
|
|
</DialogSection>
|
|
<DialogFooter>
|
|
<Button block type="primary" size="medium" onClick={() => setIsOpen(false)}>
|
|
Understood
|
|
</Button>
|
|
</DialogFooter>
|
|
</>
|
|
) : (
|
|
<Form_Shadcn_ {...form}>
|
|
<form
|
|
id="account-deletion-request"
|
|
onSubmit={form.handleSubmit(() => onConfirmDelete())}
|
|
>
|
|
<DialogSection>
|
|
<FormField_Shadcn_
|
|
name="account"
|
|
control={form.control}
|
|
render={({ field }) => (
|
|
<FormItem_Shadcn_>
|
|
<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_>
|
|
)}
|
|
/>
|
|
</DialogSection>
|
|
|
|
<DialogFooter>
|
|
<Button
|
|
block
|
|
size="small"
|
|
type="danger"
|
|
htmlType="submit"
|
|
loading={isLoading}
|
|
disabled={account !== accountEmail || isLoading}
|
|
>
|
|
Submit request for account deletion
|
|
</Button>
|
|
</DialogFooter>
|
|
</form>
|
|
</Form_Shadcn_>
|
|
)}
|
|
</>
|
|
)}
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|