import updateNode from '@/api/admin/nodes/updateNode'; import NodeDeleteButton from '@/components/admin/nodes/NodeDeleteButton'; import NodeLimitContainer from '@/components/admin/nodes/NodeLimitContainer'; import NodeListenContainer from '@/components/admin/nodes/NodeListenContainer'; import { Context } from '@/components/admin/nodes/NodeRouter'; import NodeSettingsContainer from '@/components/admin/nodes/NodeSettingsContainer'; import Button from '@/components/elements/Button'; import { ApplicationStore } from '@/state'; import { Actions, useStoreActions } from 'easy-peasy'; import { Form, Formik, FormikHelpers } from 'formik'; import React from 'react'; import { useHistory } from 'react-router-dom'; import tw from 'twin.macro'; import { number, object, string } from 'yup'; interface Values { name: string; locationId: number; databaseHostId: number | null; fqdn: string; scheme: string; behindProxy: boolean; public: boolean; daemonBase: string; // This value cannot be updated once a node has been created. memory: number; memoryOverallocate: number; disk: number; diskOverallocate: number; listenPortHTTP: number; publicPortHTTP: number; listenPortSFTP: number; publicPortSFTP: number; } export default () => { const history = useHistory(); const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); const node = Context.useStoreState(state => state.node); const setNode = Context.useStoreActions(actions => actions.setNode); if (node === undefined) { return ( <> ); } const submit = (values: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('node'); updateNode(node.id, values) .then(() => setNode({ ...node, ...values })) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'node', error }); }) .then(() => setSubmitting(false)); }; return ( { ({ isSubmitting, isValid }) => (
history.push('/admin/nodes')} />
) }
); };