import EggInstallContainer from '@/components/admin/nests/eggs/EggInstallContainer'; import EggVariablesContainer from '@/components/admin/nests/eggs/EggVariablesContainer'; 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 getEgg, { Egg } from '@/api/admin/eggs/getEgg'; 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 EggSettingsContainer from '@/components/admin/nests/eggs/EggSettingsContainer'; interface ctx { egg: Egg | undefined; setEgg: Action; } export const Context = createContextStore({ egg: undefined, setEgg: action((state, payload) => { state.egg = payload; }), }); const EggRouter = () => { const location = useLocation(); const match = useRouteMatch<{ id?: string }>(); const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); const [ loading, setLoading ] = useState(true); const egg = Context.useStoreState(state => state.egg); const setEgg = Context.useStoreActions(actions => actions.setEgg); useEffect(() => { clearFlashes('egg'); getEgg(Number(match.params?.id), [ 'variables' ]) .then(egg => setEgg(egg)) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'egg', error }); }) .then(() => setLoading(false)); }, []); if (loading || egg === undefined) { return (
); } return (

{egg.name}

{egg.uuid}

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