import { faNetworkWired } from '@fortawesome/free-solid-svg-icons'; import type { FormikHelpers } from 'formik'; import { Form, Formik, useFormikContext } from 'formik'; import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import tw from 'twin.macro'; import { object } from 'yup'; import type { Egg } from '@/api/admin/egg'; import type { CreateServerRequest } from '@/api/admin/servers/createServer'; import createServer from '@/api/admin/servers/createServer'; import type { Allocation, Node } from '@/api/admin/node'; import { getAllocations } from '@/api/admin/node'; 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 AdminContentBlock from '@/components/admin/AdminContentBlock'; 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 navigate = useNavigate(); const { clearFlashes, clearAndAddHttpError } = useFlash(); const submit = (r: CreateServerRequest, { setSubmitting }: FormikHelpers) => { clearFlashes('server:create'); createServer(r) .then(s => navigate(`/admin/servers/${s.id}`)) .catch(error => clearAndAddHttpError({ key: 'server:create', error })) .then(() => setSubmitting(false)); }; return (

New Server

Add a new server to the panel.

); };