Allow use of useCurrentUser/useCurrentTeam hooks in unauthenticated components

This commit is contained in:
Tom Moor
2023-10-28 11:31:42 -04:00
parent 56f9755cd9
commit 964d2b6bb3
17 changed files with 109 additions and 71 deletions

View File

@@ -17,6 +17,7 @@ import Modal from "~/components/Modal";
import PaginatedList from "~/components/PaginatedList";
import Text from "~/components/Text";
import useBoolean from "~/hooks/useBoolean";
import useCurrentTeam from "~/hooks/useCurrentTeam";
import useStores from "~/hooks/useStores";
type Props = {
@@ -29,11 +30,11 @@ function AddGroupsToCollection(props: Props) {
const [newGroupModalOpen, handleNewGroupModalOpen, handleNewGroupModalClose] =
useBoolean(false);
const [query, setQuery] = React.useState("");
const { auth, collectionGroupMemberships, groups, policies } = useStores();
const { fetchPage: fetchGroups } = groups;
const team = useCurrentTeam();
const { collectionGroupMemberships, groups, policies } = useStores();
const { t } = useTranslation();
const { fetchPage: fetchGroups } = groups;
const can = policies.abilities(team.id);
const debouncedFetch = React.useMemo(
() => debounce((query) => fetchGroups({ query }), 250),
@@ -65,13 +66,6 @@ function AddGroupsToCollection(props: Props) {
}
};
const { user, team } = auth;
if (!user || !team) {
return null;
}
const can = policies.abilities(team.id);
return (
<Flex column>
{can.createGroup ? (