import React from 'react'; import AdminBox from '@/components/admin/AdminBox'; import tw from 'twin.macro'; import { number, object } from 'yup'; 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'; import updateNode from '@/api/admin/nodes/updateNode'; interface Values { memory: number; memoryOverallocate: number; disk: number; diskOverallocate: number; } export default () => { 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 = ({ memory, memoryOverallocate, disk, diskOverallocate }: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('node'); updateNode(node.id, { memory, memoryOverallocate, disk, diskOverallocate }) .then(() => setNode({ ...node, memory, memoryOverallocate, disk, diskOverallocate })) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'node', error }); }) .then(() => setSubmitting(false)); }; return ( { ({ isSubmitting, isValid }) => (
) }
); };