Files
supabase/apps/studio/components/interfaces/Integrations/Wrappers/DeleteWrapperModal.tsx
Gildas Garcia 9155357d82 chore: migrate Integrations Modal to Dialog (#46380)
## 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 -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](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 -->
2026-05-27 14:06:52 +02:00

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>
)
}