import UserAboutContainer from '@/components/admin/users/UserAboutContainer'; 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 { getUser } from '@/api/admin/users'; 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 UserServers from '@/components/admin/users/UserServers'; import { User } from '@definitions/admin'; interface ctx { user: User | undefined; setUser: Action; } export const Context = createContextStore({ user: undefined, setUser: action((state, payload) => { state.user = payload; }), }); const UserRouter = () => { const location = useLocation(); const match = useRouteMatch<{ id?: string }>(); const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); const [ loading, setLoading ] = useState(true); const user = Context.useStoreState(state => state.user); const setUser = Context.useStoreActions(actions => actions.setUser); useEffect(() => { clearFlashes('user'); getUser(Number(match.params?.id), [ 'role' ]) .then(user => setUser(user)) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'user', error }); }) .then(() => setLoading(false)); }, []); if (loading || user === undefined) { return (
); } return (

{user.email}

{user.uuid}

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