import type { Action, Actions } from 'easy-peasy'; import { action, createContextStore, useStoreActions } from 'easy-peasy'; import { useEffect, useState } from 'react'; import { Route, Routes, useParams } from 'react-router-dom'; import tw from 'twin.macro'; import type { Node } from '@/api/admin/nodes/getNodes'; import getNode from '@/api/admin/nodes/getNode'; import FlashMessageRender from '@/components/FlashMessageRender'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import NodeEditContainer from '@/components/admin/nodes/NodeEditContainer'; import Spinner from '@/components/elements/Spinner'; 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'; import type { ApplicationStore } from '@/state'; interface ctx { node: Node | undefined; setNode: Action; } export const Context = createContextStore({ node: undefined, setNode: action((state, payload) => { state.node = payload; }), }); const NodeRouter = () => { const params = useParams<'id'>(); 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(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 ( ); };