import * as Tooltip from '@radix-ui/react-tooltip' import { useRef, useState } from 'react' import { Button, Form, IconHelpCircle, Input, SidePanel, Toggle } from 'ui' import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms' import { useStore } from 'hooks' import { ROLE_PERMISSIONS } from './Roles.constants' interface CreateRolePanelProps { visible: boolean onClose: () => void } const CreateRolePanel = ({ visible, onClose }: CreateRolePanelProps) => { const formId = 'create-new-role' const submitRef: any = useRef() const { ui, meta } = useStore() const [isSubmitting, setIsSubmitting] = useState(false) const initialValues = { name: '', is_superuser: false, can_login: false, can_create_role: false, can_create_db: false, is_replication_role: false, can_bypass_rls: false, } const validate = (values: any) => { const errors: any = {} if (values.name.length === 0) errors.name = 'Please provide a name for your role' return errors } const onSubmit = async (values: any) => { setIsSubmitting(true) const res = await meta.roles.create(values) setIsSubmitting(false) if (res.error) { return ui.setNotification({ category: 'error', message: `Failed to create role: ${res.error.message}`, }) } else { ui.setNotification({ category: 'success', message: `Successfully created new role: ${res.name}`, }) onClose() } } return ( } >
{({ isSubmitting, handleReset, values, initialValues }: any) => { return (
Role Configuration } > Role Privileges } >
{Object.keys(ROLE_PERMISSIONS).map((permission) => (
This privilege cannot be granted via the dashboard
) } /> ))}
) }}
) } export default CreateRolePanel