import React, { useEffect, useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faUserPlus } from '@fortawesome/free-solid-svg-icons/faUserPlus'; import { ServerContext } from '@/state/server'; import Spinner from '@/components/elements/Spinner'; import { Subuser } from '@/state/server/subusers'; import { CSSTransition } from 'react-transition-group'; import classNames from 'classnames'; import PermissionEditor from '@/components/server/users/PermissionEditor'; import { Actions, useStoreActions, useStoreState } from 'easy-peasy'; import { ApplicationStore } from '@/state'; export default () => { const [ loading, setLoading ] = useState(true); const [ editSubuser, setEditSubuser ] = useState(null); const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const subusers = ServerContext.useStoreState(state => state.subusers.data); const getSubusers = ServerContext.useStoreActions(actions => actions.subusers.getSubusers); const permissions = useStoreState((state: ApplicationStore) => state.permissions.data); const getPermissions = useStoreActions((actions: Actions) => actions.permissions.getPermissions); useEffect(() => { if (!permissions.length) { getPermissions().catch(error => console.error(error)); } }, [ permissions, getPermissions ]); useEffect(() => { getSubusers(uuid) .then(() => setLoading(false)) .catch(error => { console.error(error); }); }, [ uuid, getSubusers ]); useEffect(() => { if (subusers.length > 0) { setLoading(false); } }, [ subusers ]); return (

Subusers

{(loading || !permissions.length) ?
: !subusers.length ?

It looks like you don't have any subusers.

: subusers.map(subuser => (

{subuser.email}

)) }
{editSubuser &&

Edit {editSubuser.email}

}
); };