mirror of
https://github.com/supabase/supabase.git
synced 2026-05-25 13:13:51 +08:00
* 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>
61 lines
1.8 KiB
TypeScript
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
|