import NodeEditContainer from '@/components/admin/nodes/NodeEditContainer'; import React, { useEffect, useState } from 'react'; import { useLocation } from 'react-router'; import tw from 'twin.macro'; import { Route, Switch, useRouteMatch } from 'react-router-dom'; import { action, Action, Actions, createContextStore, useStoreActions } from 'easy-peasy'; import { Node } from '@/api/admin/nodes/getNodes'; import getNode from '@/api/admin/nodes/getNode'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import Spinner from '@/components/elements/Spinner'; import FlashMessageRender from '@/components/FlashMessageRender'; import { ApplicationStore } from '@/state'; import { SubNavigation, SubNavigationLink } from '@/components/admin/SubNavigation'; import NodeAboutContainer from '@/components/admin/nodes/NodeAboutContainer'; import NodeConfigurationContainer from '@/components/admin/nodes/NodeConfigurationContainer'; import NodeAllocationContainer from '@/components/admin/nodes/NodeAllocationContainer'; import NodeServers from '@/components/admin/nodes/NodeServers'; interface ctx { node: Node | undefined; setNode: Action; } export const Context = createContextStore({ node: undefined, setNode: action((state, payload) => { state.node = payload; }), }); const NodeRouter = () => { const location = useLocation(); const match = useRouteMatch<{ id?: string }>(); const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); const [ loading, setLoading ] = useState(true); const node = Context.useStoreState(state => state.node); const setNode = Context.useStoreActions(actions => actions.setNode); useEffect(() => { clearFlashes('node'); getNode(Number(match.params?.id), [ 'database_host', 'location' ]) .then(node => setNode(node)) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'node', error }); }) .then(() => setLoading(false)); }, []); if (loading || node === undefined) { return (
); } return (

{node.name}

{node.uuid}

); }; export default () => { return ( ); };