PromucFlow_constructor/app/client/src/utils/hooks/useWorkspace.tsx
Ankita Kinger 38d321242f
chore: Splitting files to support groups on members page in EE (#18085)
* splitted files to support groups on members page in EE

* updated an import

* minor change
2022-11-03 22:09:51 +05:30

26 lines
891 B
TypeScript

import { fetchWorkspace } from "@appsmith/actions/workspaceActions";
import { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import { getCurrentUser } from "selectors/usersSelectors";
import { getCurrentAppWorkspace } from "@appsmith/selectors/workspaceSelectors";
import { ANONYMOUS_USERNAME } from "constants/userConstants";
const useWorkspace = (workspaceId: string) => {
const dispatch = useDispatch();
const workspace = useSelector(getCurrentAppWorkspace);
const currentUser = useSelector(getCurrentUser);
useEffect(() => {
if (!currentUser || currentUser.username === ANONYMOUS_USERNAME) return;
if ((!workspace || !workspace.userPermissions) && workspaceId) {
dispatch(fetchWorkspace(workspaceId, true));
}
}, [workspaceId, currentUser && currentUser.username]);
return workspace;
};
export default useWorkspace;