import React, { useEffect, useState } from 'react'; import tw from 'twin.macro'; import { 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'; interface ctx { node: Node | undefined; setNode: Action; } export const Context = createContextStore({ node: undefined, setNode: action((state, payload) => { state.node = payload; }), }); const NodeEditContainer = () => { 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)) .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 ( ); };