2021-02-16 01:48:10 +00:00
|
|
|
import DatabaseSelect from '@/components/admin/nodes/DatabaseSelect';
|
2021-01-30 20:53:47 +00:00
|
|
|
import React from 'react';
|
|
|
|
import AdminBox from '@/components/admin/AdminBox';
|
|
|
|
import tw from 'twin.macro';
|
2021-01-30 20:55:13 +00:00
|
|
|
import { object, string } from 'yup';
|
2021-01-30 20:53:47 +00:00
|
|
|
import updateNode from '@/api/admin/nodes/updateNode';
|
|
|
|
import Button from '@/components/elements/Button';
|
|
|
|
import Field from '@/components/elements/Field';
|
|
|
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
|
|
|
import { Form, Formik, FormikHelpers } from 'formik';
|
|
|
|
import { Context } from '@/components/admin/nodes/NodeEditContainer';
|
|
|
|
import { ApplicationStore } from '@/state';
|
|
|
|
import { Actions, useStoreActions } from 'easy-peasy';
|
2021-02-11 17:21:49 +00:00
|
|
|
import LocationSelect from '@/components/admin/nodes/LocationSelect';
|
2021-01-30 20:53:47 +00:00
|
|
|
|
|
|
|
interface Values {
|
2021-01-31 22:59:37 +00:00
|
|
|
public: boolean;
|
2021-01-30 20:53:47 +00:00
|
|
|
name: string;
|
|
|
|
description: string;
|
2021-01-31 22:59:37 +00:00
|
|
|
locationId: number;
|
2021-02-16 01:48:10 +00:00
|
|
|
databaseHostId: number | null;
|
2021-01-31 22:59:37 +00:00
|
|
|
fqdn: string;
|
2021-02-11 17:21:49 +00:00
|
|
|
listenPortHTTP: number;
|
|
|
|
publicPortHTTP: number;
|
2021-02-07 23:41:32 +00:00
|
|
|
listenPortSFTP: number;
|
|
|
|
publicPortSFTP: number;
|
2021-02-11 17:32:13 +00:00
|
|
|
scheme: string;
|
2021-01-30 20:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default () => {
|
|
|
|
const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
|
|
|
|
|
|
|
const node = Context.useStoreState(state => state.node);
|
|
|
|
const setNode = Context.useStoreActions(actions => actions.setNode);
|
|
|
|
|
|
|
|
if (node === undefined) {
|
|
|
|
return (
|
|
|
|
<></>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-16 20:03:14 +00:00
|
|
|
const submit = ({ name, description, locationId, databaseHostId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP }: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
2021-02-11 17:21:49 +00:00
|
|
|
clearFlashes('node');
|
2021-01-30 20:53:47 +00:00
|
|
|
|
2021-02-16 20:03:14 +00:00
|
|
|
console.log(`Location ID: ${locationId}`);
|
|
|
|
console.log(`Database Host ID: ${databaseHostId || 'null'}`);
|
|
|
|
|
|
|
|
updateNode(node.id, { name, description, locationId, databaseHostId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP })
|
2021-02-11 17:21:49 +00:00
|
|
|
.then(() => setNode({ ...node, name, description, locationId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP }))
|
2021-01-30 20:53:47 +00:00
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
clearAndAddHttpError({ key: 'node', error });
|
|
|
|
})
|
|
|
|
.then(() => setSubmitting(false));
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Formik
|
|
|
|
onSubmit={submit}
|
|
|
|
initialValues={{
|
2021-01-31 22:59:37 +00:00
|
|
|
public: node.public,
|
2021-01-30 20:53:47 +00:00
|
|
|
name: node.name,
|
|
|
|
description: node.description || '',
|
2021-01-31 22:59:37 +00:00
|
|
|
locationId: node.locationId,
|
2021-02-16 01:48:10 +00:00
|
|
|
databaseHostId: node.databaseHostId,
|
2021-01-31 22:59:37 +00:00
|
|
|
fqdn: node.fqdn,
|
2021-02-11 17:21:49 +00:00
|
|
|
listenPortHTTP: node.listenPortHTTP,
|
|
|
|
publicPortHTTP: node.publicPortHTTP,
|
|
|
|
listenPortSFTP: node.listenPortSFTP,
|
|
|
|
publicPortSFTP: node.publicPortSFTP,
|
2021-02-11 17:32:13 +00:00
|
|
|
scheme: node.scheme,
|
2021-01-30 20:53:47 +00:00
|
|
|
}}
|
|
|
|
validationSchema={object().shape({
|
|
|
|
name: string().required().max(191),
|
|
|
|
description: string().max(255),
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
({ isSubmitting, isValid }) => (
|
|
|
|
<React.Fragment>
|
|
|
|
<AdminBox title={'Settings'} css={tw`relative`}>
|
|
|
|
<SpinnerOverlay visible={isSubmitting}/>
|
|
|
|
|
|
|
|
<Form css={tw`mb-0`}>
|
|
|
|
<div css={tw`mb-6`}>
|
|
|
|
<Field
|
|
|
|
id={'name'}
|
|
|
|
name={'name'}
|
|
|
|
label={'Name'}
|
|
|
|
type={'text'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={tw`mb-6`}>
|
|
|
|
<Field
|
|
|
|
id={'description'}
|
|
|
|
name={'description'}
|
|
|
|
label={'Description'}
|
|
|
|
type={'text'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2021-01-31 22:59:37 +00:00
|
|
|
<div css={tw`mb-6`}>
|
2021-02-16 05:41:19 +00:00
|
|
|
<LocationSelect selected={node?.relations.location || null}/>
|
2021-02-16 01:48:10 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={tw`mb-6`}>
|
2021-02-16 05:41:19 +00:00
|
|
|
<DatabaseSelect selected={node?.relations.databaseHost || null}/>
|
2021-01-31 22:59:37 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={tw`mb-6`}>
|
|
|
|
<Field
|
|
|
|
id={'fqdn'}
|
|
|
|
name={'fqdn'}
|
|
|
|
label={'FQDN'}
|
|
|
|
type={'text'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2021-02-16 20:03:14 +00:00
|
|
|
<div css={tw`mb-6 md:w-full md:flex md:flex-row`}>
|
|
|
|
<div css={tw`mb-6 md:w-full md:flex md:flex-col md:mr-4 md:mb-0`}>
|
2021-02-07 23:41:32 +00:00
|
|
|
<Field
|
2021-02-11 17:21:49 +00:00
|
|
|
id={'listenPortHTTP'}
|
|
|
|
name={'listenPortHTTP'}
|
|
|
|
label={'HTTP Listen Port'}
|
2021-02-07 23:41:32 +00:00
|
|
|
type={'number'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2021-02-16 20:03:14 +00:00
|
|
|
<div css={tw`mb-6 md:w-full md:flex md:flex-col md:ml-4 md:mb-0`}>
|
2021-02-07 23:41:32 +00:00
|
|
|
<Field
|
2021-02-11 17:21:49 +00:00
|
|
|
id={'publicPortHTTP'}
|
|
|
|
name={'publicPortHTTP'}
|
|
|
|
label={'HTTP Public Port'}
|
2021-02-07 23:41:32 +00:00
|
|
|
type={'number'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-02-16 20:03:14 +00:00
|
|
|
<div css={tw`mb-6 md:w-full md:flex md:flex-row`}>
|
|
|
|
<div css={tw`mb-6 md:w-full md:flex md:flex-col md:mr-4 md:mb-0`}>
|
2021-02-07 23:41:32 +00:00
|
|
|
<Field
|
|
|
|
id={'listenPortSFTP'}
|
|
|
|
name={'listenPortSFTP'}
|
|
|
|
label={'SFTP Listen Port'}
|
|
|
|
type={'number'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2021-02-16 20:03:14 +00:00
|
|
|
<div css={tw`mb-6 md:w-full md:flex md:flex-col md:ml-4 md:mb-0`}>
|
2021-02-07 23:41:32 +00:00
|
|
|
<Field
|
|
|
|
id={'publicPortSFTP'}
|
|
|
|
name={'publicPortSFTP'}
|
|
|
|
label={'SFTP Public Port'}
|
|
|
|
type={'number'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-02-16 20:03:14 +00:00
|
|
|
<div css={tw`flex flex-row items-center w-full`}>
|
2021-01-30 20:53:47 +00:00
|
|
|
<div css={tw`flex ml-auto`}>
|
|
|
|
<Button type={'submit'} disabled={isSubmitting || !isValid}>
|
|
|
|
Save
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
</AdminBox>
|
|
|
|
</React.Fragment>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</Formik>
|
|
|
|
);
|
|
|
|
};
|