mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 12:55:06 +03:00
## 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 -->
76 lines
2.5 KiB
TypeScript
76 lines
2.5 KiB
TypeScript
import { TextConfirmModal } from 'components/ui/TextConfirmModalWrapper'
|
|
import { useDatabaseTriggerDeleteMutation } from 'data/database-triggers/database-trigger-delete-mutation'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import { parseAsString, useQueryState } from 'nuqs'
|
|
import { useEffect } from 'react'
|
|
import { toast } from 'sonner'
|
|
|
|
import { useDatabaseHooksQuery } from '@/data/database-triggers/database-triggers-query'
|
|
|
|
export const DeleteHookModal = () => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const { data: hooks = [], isSuccess } = useDatabaseHooksQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const [selectedHookIdToDelete, setSelectedHookIdToDelete] = useQueryState(
|
|
'delete',
|
|
parseAsString.withDefault('')
|
|
)
|
|
const selectedHook = hooks.find((hook) => hook.id.toString() === selectedHookIdToDelete)
|
|
const { name, schema } = selectedHook ?? {}
|
|
|
|
const {
|
|
mutate: deleteDatabaseTrigger,
|
|
isPending: isDeleting,
|
|
isSuccess: isSuccessDelete,
|
|
} = useDatabaseTriggerDeleteMutation({
|
|
onSuccess: () => {
|
|
toast.success(`Successfully deleted ${name}`)
|
|
setSelectedHookIdToDelete(null)
|
|
},
|
|
})
|
|
|
|
async function handleDelete() {
|
|
if (!project) return console.error('Project ref is required')
|
|
if (!selectedHook) return toast.error('Unable to find selected hook')
|
|
|
|
deleteDatabaseTrigger({
|
|
trigger: selectedHook,
|
|
projectRef: project.ref,
|
|
connectionString: project.connectionString,
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (isSuccess && !!selectedHookIdToDelete && !selectedHook && !isSuccessDelete) {
|
|
toast('Webhook not found')
|
|
setSelectedHookIdToDelete(null)
|
|
}
|
|
}, [isSuccess, isSuccessDelete, selectedHook, selectedHookIdToDelete, setSelectedHookIdToDelete])
|
|
|
|
return (
|
|
<TextConfirmModal
|
|
variant="destructive"
|
|
visible={!!selectedHook}
|
|
size="small"
|
|
onCancel={() => setSelectedHookIdToDelete(null)}
|
|
onConfirm={handleDelete}
|
|
title="Delete database webhook"
|
|
loading={isDeleting}
|
|
confirmLabel={`Delete ${name}`}
|
|
confirmPlaceholder="Type in name of webhook"
|
|
confirmString={name || ''}
|
|
text={
|
|
<>
|
|
This will delete the webhook <span className="text-bold text-foreground">{name}</span>{' '}
|
|
from the schema <span className="text-bold text-foreground">{schema}</span>
|
|
</>
|
|
}
|
|
alert={{ title: 'You cannot recover this webhook once deleted.' }}
|
|
/>
|
|
)
|
|
}
|