Files
supabase/apps/studio/components/interfaces/Integrations/Wrappers/DeleteWrapperModal.tsx
T
Joshen Lim e48c909b31 Chore/deprecate use query state with select part 04 (#42747)
## Context

Related to FE-2461

More refactoring to clean up usage of `useQueryStateWithSelect`, in the
following pages
- Auth OAuth Apps
- Cron Jobs
- Vaults Secrets Management
- Database Hooks
- Wrappers

## To test

In each of those pages, verify that
- [ ] Clicking the "new" cta updates the URL params, and refreshing
should re-open the sheet
- [ ] Editing an existing item should update URL params, and refreshing
should re-open the sheet with the right item
- Verify that if the URL param has the wrong id, page should not open
the sheet, show a toast, and reset the URL param
- [ ] Deleting an existing item should update URL params, and refreshing
should re-open the sheet with the right item
- Verify that if the URL param has the wrong id, page should not open
the sheet, show a toast, and reset the URL param

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Added "item not found" toasts and clearer feedback after
create/update/delete actions; prevent opening create flows when server
features are disabled.

* **Style**
* Standardized button labels, sizes and modal/dialog spacing; refined
table column widths and inline code formatting for readability.

* **Refactor**
* Simplified UI state flows across OAuth Apps, Hooks/Webhooks, Cron
Jobs, Vault Secrets, and Wrappers to use consistent URL-driven
interactions and centralized modals.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-13 16:18:28 +08:00

95 lines
2.9 KiB
TypeScript

import { useParams } from 'common'
import { useFDWDeleteMutation } from 'data/fdw/fdw-delete-mutation'
import { useFDWsQuery } from 'data/fdw/fdws-query'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { parseAsString, useQueryState } from 'nuqs'
import { useEffect, useMemo } from 'react'
import { toast } from 'sonner'
import { Modal } from 'ui'
import { INTEGRATIONS } from '../Landing/Integrations.constants'
import { getWrapperMetaForWrapper, wrapperMetaComparator } from './Wrappers.utils'
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 {
mutate: deleteFDW,
isPending: isDeleting,
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')
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 (
<Modal
size="medium"
variant="danger"
alignFooter="right"
loading={isDeleting}
visible={selectedWrapper !== undefined}
onCancel={() => setSelectedWrapperToDelete(null)}
onConfirm={() => onConfirmDelete()}
header={`Confirm to disable ${selectedWrapper?.name}`}
>
<Modal.Content>
<p className="text-sm">
Are you sure you want to disable {selectedWrapper?.name}? This will also remove all tables
created with this wrapper.
</p>
</Modal.Content>
</Modal>
)
}