import { Egg } from '@/api/admin/egg'; import AdminBox from '@/components/admin/AdminBox'; import NodeSelect from '@/components/admin/servers/NodeSelect'; import { ServerImageContainer, ServerServiceContainer, ServerVariableContainer } from '@/components/admin/servers/ServerStartupContainer'; import BaseSettingsBox from '@/components/admin/servers/settings/BaseSettingsBox'; import FeatureLimitsBox from '@/components/admin/servers/settings/FeatureLimitsBox'; import ServerResourceBox from '@/components/admin/servers/settings/ServerResourceBox'; import Button from '@/components/elements/Button'; import Field from '@/components/elements/Field'; import FormikSwitch from '@/components/elements/FormikSwitch'; import Label from '@/components/elements/Label'; import Select from '@/components/elements/Select'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import FlashMessageRender from '@/components/FlashMessageRender'; import useFlash from '@/plugins/useFlash'; import { faNetworkWired } from '@fortawesome/free-solid-svg-icons'; import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; import React, { useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; import tw from 'twin.macro'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import { object } from 'yup'; import createServer, { CreateServerRequest } from '@/api/admin/servers/createServer'; import { Allocation, Node, getAllocations } from '@/api/admin/node'; function InternalForm () { const { isSubmitting, isValid, setFieldValue, values: { environment } } = useFormikContext(); const [ egg, setEgg ] = useState(null); const [ node, setNode ] = useState(null); const [ allocations, setAllocations ] = useState(null); useEffect(() => { if (egg === null) { return; } setFieldValue('eggId', egg.id); setFieldValue('startup', ''); setFieldValue('image', egg.dockerImages.length > 0 ? egg.dockerImages[0] : ''); }, [ egg ]); useEffect(() => { if (node === null) { return; } // server_id: 0 filters out assigned allocations getAllocations(node.id, { filters: { server_id: '0' } }) .then(setAllocations); }, [ node ]); return (
{/*
*/} {/* /!* TODO: Multi-select *!/*/} {/* */} {/* */} {/*
*/}
{/* This ensures that no variables are rendered unless the environment has a value for the variable. */} {egg?.relationships.variables?.filter(v => Object.keys(environment).find(e => e === v.environmentVariable) !== undefined).map((v, i) => ( ))}
); } export default () => { const history = useHistory(); const { clearFlashes, clearAndAddHttpError } = useFlash(); const submit = (r: CreateServerRequest, { setSubmitting }: FormikHelpers) => { console.log(r); clearFlashes('server:create'); createServer(r) .then(s => history.push(`/admin/servers/${s.id}`)) .catch(error => clearAndAddHttpError({ key: 'server:create', error })) .then(() => setSubmitting(false)); }; return (

New Server

Add a new server to the panel.

); };