2021-09-13 03:22:33 +00:00
|
|
|
import NodeLimitContainer from '@/components/admin/nodes/NodeLimitContainer';
|
|
|
|
import NodeListenContainer from '@/components/admin/nodes/NodeListenContainer';
|
|
|
|
import NodeSettingsContainer from '@/components/admin/nodes/NodeSettingsContainer';
|
|
|
|
import Button from '@/components/elements/Button';
|
|
|
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
|
|
|
import { ApplicationStore } from '@/state';
|
|
|
|
import { Actions, useStoreActions } from 'easy-peasy';
|
|
|
|
import { Form, Formik, FormikHelpers } from 'formik';
|
2021-01-06 22:39:23 +00:00
|
|
|
import React from 'react';
|
2021-09-13 03:22:33 +00:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2021-01-06 22:39:23 +00:00
|
|
|
import tw from 'twin.macro';
|
|
|
|
import AdminContentBlock from '@/components/admin/AdminContentBlock';
|
2021-09-13 03:22:33 +00:00
|
|
|
import { number, object, string } from 'yup';
|
|
|
|
import createNode, { Values } from '@/api/admin/nodes/createNode';
|
|
|
|
|
|
|
|
type Values2 = Omit<Omit<Values, 'behindProxy'>, 'public'> & { behindProxy: string; public: string };
|
|
|
|
|
|
|
|
const initialValues: Values2 = {
|
|
|
|
name: '',
|
|
|
|
locationId: 0,
|
|
|
|
databaseHostId: null,
|
|
|
|
fqdn: '',
|
|
|
|
scheme: 'https',
|
|
|
|
behindProxy: 'false',
|
|
|
|
public: 'true',
|
|
|
|
daemonBase: '/var/lib/pterodactyl/volumes',
|
|
|
|
|
|
|
|
listenPortHTTP: 8080,
|
|
|
|
publicPortHTTP: 8080,
|
|
|
|
listenPortSFTP: 2022,
|
|
|
|
publicPortSFTP: 2022,
|
|
|
|
|
|
|
|
memory: 0,
|
|
|
|
memoryOverallocate: 0,
|
|
|
|
disk: 0,
|
|
|
|
diskOverallocate: 0,
|
|
|
|
};
|
2021-01-06 22:39:23 +00:00
|
|
|
|
|
|
|
export default () => {
|
2021-09-13 03:22:33 +00:00
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
|
|
|
|
|
|
|
const submit = (values2: Values2, { setSubmitting }: FormikHelpers<Values2>) => {
|
|
|
|
clearFlashes('node:create');
|
|
|
|
|
|
|
|
const values: Values = { ...values2, behindProxy: values2.behindProxy === 'true', public: values2.public === 'true' };
|
|
|
|
|
|
|
|
createNode(values)
|
|
|
|
.then(node => history.push(`/admin/nodes/${node.id}`))
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
clearAndAddHttpError({ key: 'node:create', error });
|
|
|
|
})
|
|
|
|
.then(() => setSubmitting(false));
|
|
|
|
};
|
|
|
|
|
2021-01-06 22:39:23 +00:00
|
|
|
return (
|
2021-01-10 18:34:14 +00:00
|
|
|
<AdminContentBlock title={'New Node'}>
|
2021-01-06 22:39:23 +00:00
|
|
|
<div css={tw`w-full flex flex-row items-center mb-8`}>
|
2021-01-10 18:34:14 +00:00
|
|
|
<div css={tw`flex flex-col flex-shrink`} style={{ minWidth: '0' }}>
|
2021-01-06 22:39:23 +00:00
|
|
|
<h2 css={tw`text-2xl text-neutral-50 font-header font-medium`}>Create Node</h2>
|
2021-01-10 18:34:14 +00:00
|
|
|
<p css={tw`text-base text-neutral-400 whitespace-nowrap overflow-ellipsis overflow-hidden`}>Add a new node to the panel.</p>
|
2021-01-06 22:39:23 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-13 03:22:33 +00:00
|
|
|
|
|
|
|
<FlashMessageRender byKey={'node:create'}/>
|
|
|
|
|
|
|
|
<Formik
|
|
|
|
onSubmit={submit}
|
|
|
|
initialValues={initialValues}
|
|
|
|
validationSchema={object().shape({
|
|
|
|
name: string().required().max(191),
|
|
|
|
|
|
|
|
listenPortHTTP: number().required(),
|
|
|
|
publicPortHTTP: number().required(),
|
|
|
|
listenPortSFTP: number().required(),
|
|
|
|
publicPortSFTP: number().required(),
|
|
|
|
|
|
|
|
memory: number().required(),
|
|
|
|
memoryOverallocate: number().required(),
|
|
|
|
disk: number().required(),
|
|
|
|
diskOverallocate: number().required(),
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
({ isSubmitting, isValid }) => (
|
|
|
|
<Form>
|
|
|
|
<div css={tw`flex flex-col lg:flex-row`}>
|
|
|
|
<div css={tw`w-full lg:w-1/2 flex flex-col mr-0 lg:mr-2`}>
|
|
|
|
<NodeSettingsContainer/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={tw`w-full lg:w-1/2 flex flex-col ml-0 lg:ml-2 mt-4 lg:mt-0`}>
|
|
|
|
<div css={tw`flex w-full`}>
|
|
|
|
<NodeListenContainer/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={tw`flex w-full mt-4`}>
|
|
|
|
<NodeLimitContainer/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={tw`rounded shadow-md bg-neutral-700 mt-4 py-2 pr-6`}>
|
|
|
|
<div css={tw`flex flex-row`}>
|
|
|
|
<Button type={'submit'} css={tw`ml-auto`} disabled={isSubmitting || !isValid}>
|
|
|
|
Create
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</Formik>
|
2021-01-06 22:39:23 +00:00
|
|
|
</AdminContentBlock>
|
|
|
|
);
|
|
|
|
};
|