import { FC } from 'react' import { Button, Input, Form, Modal, Listbox, IconPlus, IconDatabase } from '@supabase/ui' import { PostgresExtension, PostgresSchema } from '@supabase/postgres-meta' import { useStore } from 'hooks' interface Props { visible: boolean extension: PostgresExtension onCancel: () => void } const EnableExtensionModal: FC = ({ visible, extension, onCancel }) => { const { ui, meta } = useStore() const schemas = meta.schemas.list() const validate = (values: any) => { const errors: any = {} if (values.schema === 'custom' && !values.name) errors.name = 'Required field' return errors } const onSubmit = async (values: any, { setSubmitting }: any) => { setSubmitting(true) if (values.schema === 'custom') { const { error } = await meta.query(`create schema if not exists ${values.name}`) if (error) { return ui.setNotification({ error, category: 'error', message: `Failed to create schema: ${error.message}`, }) } } const { error } = await meta.extensions.create({ name: extension.name, schema: values.schema === 'custom' ? values.name : values.schema, version: extension.default_version, cascade: true, }) if (error) { ui.setNotification({ error, category: 'error', message: `Failed to toggle ${extension.name.toUpperCase()}: ${error.message}`, }) } else { ui.setNotification({ category: 'success', message: `${extension.name.toUpperCase()} is on.`, }) } setSubmitting(false) onCancel() } return (
Confirm to enable
{extension.name} } >
{({ isSubmitting, values }: any) => { return (
} > Create a new schema "{extension.name}" {/* @ts-ignore */} {schemas.map((schema: PostgresSchema) => { return ( } > {schema.name} ) })} {values.schema === 'custom' && ( )}
) }}
) } export default EnableExtensionModal