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 { getUser } from '@/api/admin/users'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import { SubNavigation, SubNavigationLink } from '@/components/admin/SubNavigation'; import UserAboutContainer from '@/components/admin/users/UserAboutContainer'; import UserServers from '@/components/admin/users/UserServers'; import Spinner from '@/components/elements/Spinner'; import FlashMessageRender from '@/components/FlashMessageRender'; import type { ApplicationStore } from '@/state'; import type { 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 params = useParams<'id'>(); 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(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 ( ); };