mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 04:45:08 +03:00
## What kind of change does this PR introduce? - ~Feat~ Chore - Resolves DEPR-33 ## What is the current behavior? The dialog used to delete an organization uses a ”type this org’s name in before you can press this button” interaction but: - A) Enables the button the whole time - B) We already have this componentized in TextConfirmModal ## What is the new behavior? - Refactored this dialog to use `TextConfirmModal` instead - Updated design docs to make this prop clearer | Before | After | | --- | --- | | <img width="1024" height="759" alt="Supabase" src="https://github.com/user-attachments/assets/85c965f6-29d4-4696-8c0c-a54ddcbe6167" /> | <img width="1024" height="759" alt="Supabase" src="https://github.com/user-attachments/assets/0a96ca65-15c3-4b1b-bb10-620526c059b8" /> | <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated Text Confirm Dialog documentation with clarifications: the confirm action remains disabled until input exactly matches the required string, and leading/trailing whitespace is trimmed from the input. * **Refactor** * Streamlined the organization deletion confirmation workflow for improved user experience. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
92 lines
3.0 KiB
TypeScript
92 lines
3.0 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useRouter } from 'next/router'
|
|
import { useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
|
|
import { LOCAL_STORAGE_KEYS } from 'common'
|
|
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
|
|
import { useOrganizationDeleteMutation } from 'data/organizations/organization-delete-mutation'
|
|
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
|
|
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
|
|
import { TextConfirmModal } from 'components/ui/TextConfirmModalWrapper'
|
|
|
|
export const DeleteOrganizationButton = () => {
|
|
const router = useRouter()
|
|
const { data: selectedOrganization } = useSelectedOrganizationQuery()
|
|
const { slug: orgSlug, name: orgName } = selectedOrganization ?? {}
|
|
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
|
|
const [_, setLastVisitedOrganization] = useLocalStorageQuery(
|
|
LOCAL_STORAGE_KEYS.LAST_VISITED_ORGANIZATION,
|
|
''
|
|
)
|
|
|
|
const { can: canDeleteOrganization } = useAsyncCheckPermissions(
|
|
PermissionAction.UPDATE,
|
|
'organizations'
|
|
)
|
|
|
|
const { mutate: deleteOrganization, isPending: isDeleting } = useOrganizationDeleteMutation({
|
|
onSuccess: () => {
|
|
toast.success(`Successfully deleted ${orgName}`)
|
|
setLastVisitedOrganization('')
|
|
router.push('/organizations')
|
|
},
|
|
})
|
|
|
|
const onConfirmDelete = () => {
|
|
if (!canDeleteOrganization) {
|
|
toast.error('You do not have permission to delete this organization')
|
|
return
|
|
}
|
|
if (!orgSlug) {
|
|
console.error('Org slug is required')
|
|
return
|
|
}
|
|
deleteOrganization({ slug: orgSlug })
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="mt-2">
|
|
<ButtonTooltip
|
|
type="danger"
|
|
disabled={!canDeleteOrganization || !orgSlug}
|
|
loading={!orgSlug}
|
|
onClick={() => setIsOpen(true)}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: !canDeleteOrganization
|
|
? 'You need additional permissions to delete this organization'
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
Delete organization
|
|
</ButtonTooltip>
|
|
</div>
|
|
<TextConfirmModal
|
|
visible={isOpen}
|
|
size="small"
|
|
variant="destructive"
|
|
title="Delete organization"
|
|
loading={isDeleting}
|
|
confirmString={orgSlug ?? ''}
|
|
confirmPlaceholder="Enter the string above"
|
|
confirmLabel="I understand, delete this organization"
|
|
onConfirm={onConfirmDelete}
|
|
onCancel={() => setIsOpen(false)}
|
|
>
|
|
<p className="text-sm text-foreground-lighter">
|
|
This action <span className="text-foreground">cannot</span> be undone. This will
|
|
permanently delete the <span className="text-foreground">{orgName}</span> organization and
|
|
remove all of its projects.
|
|
</p>
|
|
</TextConfirmModal>
|
|
</>
|
|
)
|
|
}
|