import ServerManageContainer from '@/components/admin/servers/ServerManageContainer'; import ServerStartupContainer from '@/components/admin/servers/ServerStartupContainer'; 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 { Server } from '@/api/admin/servers/getServers'; import getServer from '@/api/admin/servers/getServer'; 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 ServerSettingsContainer from '@/components/admin/servers/ServerSettingsContainer'; export const ServerIncludes = [ 'allocations', 'user', 'variables' ]; interface ctx { server: Server | undefined; setServer: Action; } export const Context = createContextStore({ server: undefined, setServer: action((state, payload) => { state.server = payload; }), }); const ServerRouter = () => { const location = useLocation(); const match = useRouteMatch<{ id?: string }>(); const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); const [ loading, setLoading ] = useState(true); const server = Context.useStoreState(state => state.server); const setServer = Context.useStoreActions(actions => actions.setServer); useEffect(() => { clearFlashes('server'); getServer(Number(match.params?.id), ServerIncludes) .then(server => setServer(server)) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'server', error }); }) .then(() => setLoading(false)); }, []); if (loading || server === undefined) { return (
); } return (

{server.name}

{server.uuid}

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