Files
supabase/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx
Jonathan Summers-Muir 9104cbc359 Chore/add first pattern docs (#21741)
* remove un-needed stuff

* Update preview.js

* Update preview.js

* upgrade sb

* Update preview.js

* chore: main init of the confirmTextModal

* update modals

* dialog positioned fixed

* fix backdrop

* chore: overlay now wrapping DialogContent !!

* more modal updates

* fix props

* update size

* padding fixed

* Update Dialog.stories.tsx

* add padding to more Dialog stuff

* update text

* start using subcomponents in storybook

* make thinner because it's too wiiiiide

* Tiny fix

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-03-05 18:08:28 +08:00

61 lines
1.8 KiB
TypeScript

import toast from 'react-hot-toast'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
import { useDatabaseFunctionDeleteMutation } from 'data/database-functions/database-functions-delete-mutation'
interface DeleteFunctionProps {
func?: any
visible: boolean
setVisible: (value: boolean) => void
}
const DeleteFunction = ({ func, visible, setVisible }: DeleteFunctionProps) => {
const { project } = useProjectContext()
const { id, name, schema } = func ?? {}
const { mutate: deleteDatabaseFunction, isLoading } = useDatabaseFunctionDeleteMutation({
onSuccess: () => {
toast.success(`Successfully removed function ${name}`)
setVisible(false)
},
})
async function handleDelete() {
if (!id) return console.error('Function ID is require')
if (!project) return console.error('Project is required')
deleteDatabaseFunction({
id,
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}
text={
<>
This will delete the function
<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 function once deleted.' }}
/>
</>
)
}
export default DeleteFunction