* splitted files to support groups on members page in EE * updated an import * minor change
26 lines
891 B
TypeScript
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;
|