Files
supabase/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx
Joshen Lim cab0585533 Fe 1799/consolidate to useselectedprojectquery and (#37684)
* Replace all usage of useProjectContext with useSelectedProjectQuery

* Replace all usage of useSelectedProject with useSelectedProjectQuery

* Replace all usage of useProjectByRef with useProjectByRefQuery

* Replace all usage of useSelectedOrganization with useSelectedOrganizationQuery

* Deprecate useSelectedProject, useSelectedOrganization, and useProjectByRef hooks

* Deprecate ProjecContext
2025-08-06 10:53:10 +07:00

62 lines
1.9 KiB
TypeScript

import { toast } from 'sonner'
import { useDatabaseFunctionDeleteMutation } from 'data/database-functions/database-functions-delete-mutation'
import { DatabaseFunction } from 'data/database-functions/database-functions-query'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
interface DeleteFunctionProps {
func?: DatabaseFunction
visible: boolean
setVisible: (value: boolean) => void
}
const DeleteFunction = ({ func, visible, setVisible }: DeleteFunctionProps) => {
const { data: project } = useSelectedProjectQuery()
const { name, schema } = func ?? {}
const { mutate: deleteDatabaseFunction, isLoading } = useDatabaseFunctionDeleteMutation({
onSuccess: () => {
toast.success(`Successfully removed function ${name}`)
setVisible(false)
},
})
async function handleDelete() {
if (!func) return console.error('Function is required')
if (!project) return console.error('Project is required')
deleteDatabaseFunction({
func,
projectRef: project.ref,
connectionString: project.connectionString,
})
}
return (
<>
<TextConfirmModal
variant={'warning'}
visible={visible}
onCancel={() => setVisible(!visible)}
onConfirm={handleDelete}
title="Delete this function"
loading={isLoading}
confirmLabel={`Delete function ${name}`}
confirmPlaceholder="Type in name of function"
confirmString={name ?? 'Unknown'}
text={
<>
<span>This will delete the function</span>{' '}
<span className="text-bold text-foreground">{name}</span> <span>from the schema</span>{' '}
<span className="text-bold text-foreground">{schema}</span>
</>
}
alert={{ title: 'You cannot recover this function once deleted.' }}
/>
</>
)
}
export default DeleteFunction