import DatabaseSelect from '@/components/admin/nodes/DatabaseSelect'; import React from 'react'; import AdminBox from '@/components/admin/AdminBox'; import tw from 'twin.macro'; import { object, string } from 'yup'; 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'; import LocationSelect from '@/components/admin/nodes/LocationSelect'; interface Values { public: boolean; name: string; description: string; locationId: number; databaseHostId: number | null; fqdn: string; listenPortHTTP: number; publicPortHTTP: number; listenPortSFTP: number; publicPortSFTP: number; scheme: string; } 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 = ({ name, description, locationId, databaseHostId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP }: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('node'); console.log(`Location ID: ${locationId}`); console.log(`Database Host ID: ${databaseHostId || 'null'}`); updateNode(node.id, { name, description, locationId, databaseHostId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP }) .then(() => setNode({ ...node, name, description, locationId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP })) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'node', error }); }) .then(() => setSubmitting(false)); }; return ( { ({ isSubmitting, isValid }) => (
) }
); };