Files
supabase/apps/studio/components/interfaces/Database/Hooks/DeleteHookModal.tsx
Joshen Lim 540049992d Replace ui setnotification with toast part 2 (#21872)
* Replace ui setnotification with toast part 2

* Prettier lint
2024-03-08 18:28:21 +08:00

67 lines
1.9 KiB
TypeScript

import type { PostgresTrigger } from '@supabase/postgres-meta'
import toast from 'react-hot-toast'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
import { useDatabaseTriggerDeleteMutation } from 'data/database-triggers/database-trigger-delete-mutation'
interface DeleteHookModalProps {
visible: boolean
selectedHook?: PostgresTrigger
onClose: () => void
}
const DeleteHookModal = ({ selectedHook, visible, onClose }: DeleteHookModalProps) => {
const { id, name, schema } = selectedHook ?? {}
const { project } = useProjectContext()
const { mutate: deleteDatabaseTrigger, isLoading: isDeleting } = useDatabaseTriggerDeleteMutation(
{
onSuccess: () => {
toast.success(`Successfully deleted ${name}`)
onClose()
},
}
)
async function handleDelete() {
if (!project) {
return console.error('Project ref is required')
}
if (!id) {
return toast.error('Unable find selected hook')
}
deleteDatabaseTrigger({
id,
projectRef: project.ref,
connectionString: project.connectionString,
})
}
return (
<TextConfirmModal
variant={'warning'}
visible={visible}
size="medium"
onCancel={() => onClose()}
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> rom the schema
<span className="text-bold text-foreground">{schema}</span>
</>
}
alert={{ title: 'You cannot recover this webhook once deleted.' }}
/>
)
}
export default DeleteHookModal