import { useHistory } from 'react-router-dom'; import useEnvironmentForm from '../hooks/useEnvironmentForm'; import useUiConfig from '../../../hooks/api/getters/useUiConfig/useUiConfig'; import useToast from '../../../hooks/useToast'; import useEnvironmentApi from '../../../hooks/api/actions/useEnvironmentApi/useEnvironmentApi'; import EnvironmentForm from '../EnvironmentForm/EnvironmentForm'; import FormTemplate from '../../common/FormTemplate/FormTemplate'; import useEnvironments from '../../../hooks/api/getters/useEnvironments/useEnvironments'; import { Alert } from '@material-ui/lab'; import { Button } from '@material-ui/core'; import ConditionallyRender from '../../common/ConditionallyRender'; import PageContent from '../../common/PageContent'; import HeaderTitle from '../../common/HeaderTitle'; import PermissionButton from '../../common/PermissionButton/PermissionButton'; import { ADMIN } from '../../providers/AccessProvider/permissions'; import useProjectRolePermissions from '../../../hooks/api/getters/useProjectRolePermissions/useProjectRolePermissions'; const CreateEnvironment = () => { const { setToastApiError, setToastData } = useToast(); const { uiConfig } = useUiConfig(); const history = useHistory(); const { environments } = useEnvironments(); const canCreateMoreEnvs = environments.length < 7; const { createEnvironment, loading } = useEnvironmentApi(); const { refetch } = useProjectRolePermissions(); const { name, setName, type, setType, getEnvPayload, validateEnvironmentName, clearErrors, errors, } = useEnvironmentForm(); const handleSubmit = async (e: Event) => { e.preventDefault(); clearErrors(); const validName = await validateEnvironmentName(); if (validName) { const payload = getEnvPayload(); try { await createEnvironment(payload); refetch(); setToastData({ title: 'Environment created', type: 'success', confetti: true, }); history.push('/environments'); } catch (e: any) { setToastApiError(e.toString()); } } }; const formatApiCode = () => { return `curl --location --request POST '${ uiConfig.unleashUrl }/api/admin/environments' \\ --header 'Authorization: INSERT_API_KEY' \\ --header 'Content-Type: application/json' \\ --data-raw '${JSON.stringify(getEnvPayload(), undefined, 2)}'`; }; const handleCancel = () => { history.goBack(); }; return ( Create environment } elseShow={ <> } >

Currently Unleash does not support more than 7 environments. If you need more please reach out.


} /> ); }; export default CreateEnvironment;