import { TextConfirmModal } from 'components/ui/TextConfirmModalWrapper' import type { DatabaseFunction } from 'data/database-functions/database-functions-query' import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject' interface DeleteFunctionProps { func?: DatabaseFunction visible: boolean setVisible: (value: string | null) => void onDelete: (params: { func: DatabaseFunction projectRef: string connectionString?: string | null }) => void isLoading: boolean } export const DeleteFunction = ({ func, visible, setVisible, onDelete, isLoading, }: DeleteFunctionProps) => { const { data: project } = useSelectedProjectQuery() const { name, schema } = func ?? {} async function handleDelete() { if (!func) return console.error('Function is required') if (!project) return console.error('Project is required') onDelete({ func, projectRef: project.ref, connectionString: project.connectionString, }) } return ( setVisible(null)} onConfirm={handleDelete} title="Delete this function" loading={isLoading} confirmLabel={`Delete function ${name}`} confirmPlaceholder="Type in name of function" confirmString={name ?? 'Unknown'} text={ <> This will delete the function{' '} {name} from the schema{' '} {schema} } alert={{ title: 'You cannot recover this function once deleted.' }} /> ) }