mirror of
https://github.com/supabase/supabase.git
synced 2026-06-13 01:39:53 +08:00
## Problem We still use the deprecated `Modal` for: - Deleting a wrapper - Updating a vault secret - Sending a queue message ## Solution - use `Dialog` instead <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Replaced several modal dialogs with updated dialog/alert patterns for sending messages and confirming deletions, improving visual consistency and content structure. * **Bug Fixes** * Prevent duplicate/accidental actions by disabling buttons and showing loading states during pending operations; confirmation dialogs now display relevant item details and close on success. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46380?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
103 lines
3.3 KiB
TypeScript
103 lines
3.3 KiB
TypeScript
import { useParams } from 'common'
|
|
import { parseAsString, useQueryState } from 'nuqs'
|
|
import { useEffect, useMemo } from 'react'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from 'ui'
|
|
|
|
import { INTEGRATIONS } from '../Landing/Integrations.constants'
|
|
import { getWrapperMetaForWrapper, wrapperMetaComparator } from './Wrappers.utils'
|
|
import { useFDWDeleteMutation } from '@/data/fdw/fdw-delete-mutation'
|
|
import { useFDWsQuery } from '@/data/fdw/fdws-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
export const DeleteWrapperModal = () => {
|
|
const { id, ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const integration = INTEGRATIONS.find((i) => i.id === id)
|
|
|
|
const { data, isSuccess } = useFDWsQuery({
|
|
projectRef: ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const wrappers = useMemo(
|
|
() =>
|
|
integration && integration.type === 'wrapper' && data
|
|
? data.filter((wrapper) => wrapperMetaComparator(integration.meta, wrapper))
|
|
: [],
|
|
[data, integration]
|
|
)
|
|
|
|
const [selectedWrapperIdToDelete, setSelectedWrapperToDelete] = useQueryState(
|
|
'delete',
|
|
parseAsString
|
|
)
|
|
const selectedWrapper = wrappers.find((x) => x.id.toString() === selectedWrapperIdToDelete)
|
|
|
|
const { mutateAsync: deleteFDW, isSuccess: isSuccessDelete } = useFDWDeleteMutation({
|
|
onSuccess: () => {
|
|
toast.success(`Successfully disabled ${selectedWrapper?.name} foreign data wrapper`)
|
|
setSelectedWrapperToDelete(null)
|
|
},
|
|
})
|
|
const wrapperMeta = getWrapperMetaForWrapper(selectedWrapper)
|
|
|
|
const onConfirmDelete = async () => {
|
|
if (!project?.ref) return console.error('Project ref is required')
|
|
if (!selectedWrapper) return console.error('Wrapper is required')
|
|
if (!wrapperMeta) return console.error('Wrapper meta is required')
|
|
|
|
await deleteFDW({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
wrapper: selectedWrapper,
|
|
wrapperMeta: wrapperMeta,
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (isSuccess && !!selectedWrapperIdToDelete && !selectedWrapper && !isSuccessDelete) {
|
|
toast('Wrapper not found')
|
|
setSelectedWrapperToDelete(null)
|
|
}
|
|
}, [
|
|
isSuccess,
|
|
isSuccessDelete,
|
|
selectedWrapper,
|
|
selectedWrapperIdToDelete,
|
|
setSelectedWrapperToDelete,
|
|
])
|
|
|
|
return (
|
|
<AlertDialog
|
|
open={selectedWrapper !== undefined}
|
|
onOpenChange={() => setSelectedWrapperToDelete(null)}
|
|
>
|
|
<AlertDialogContent size="medium">
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{`Confirm to disable ${selectedWrapper?.name}`}</AlertDialogTitle>
|
|
<AlertDialogDescription>
|
|
Are you sure you want to disable {selectedWrapper?.name}? This will also remove all
|
|
tables created with this wrapper.
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction variant="danger" onClick={onConfirmDelete}>
|
|
Confirm
|
|
</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
)
|
|
}
|