diff --git a/site/src/pages/GroupsPage/GroupsPage.tsx b/site/src/pages/GroupsPage/GroupsPage.tsx index 3319fe74e2126..f51e2d788c321 100644 --- a/site/src/pages/GroupsPage/GroupsPage.tsx +++ b/site/src/pages/GroupsPage/GroupsPage.tsx @@ -10,14 +10,15 @@ import GroupsPageView from "./GroupsPageView" export const GroupsPage: FC = () => { const organizationId = useOrganizationId() + const { createGroup: canCreateGroup } = usePermissions() + const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility() const [state] = useMachine(groupsMachine, { context: { organizationId, + shouldFetchGroups: isTemplateRBACEnabled, }, }) const { groups } = state.context - const { createGroup: canCreateGroup } = usePermissions() - const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility() return ( <> diff --git a/site/src/xServices/groups/groupsXService.ts b/site/src/xServices/groups/groupsXService.ts index 451bd85fc534f..ff17e94dc5bdc 100644 --- a/site/src/xServices/groups/groupsXService.ts +++ b/site/src/xServices/groups/groupsXService.ts @@ -11,6 +11,7 @@ export const groupsMachine = createMachine( schema: { context: {} as { organizationId: string + shouldFetchGroups: boolean groups?: Group[] }, services: {} as { @@ -23,6 +24,7 @@ export const groupsMachine = createMachine( initial: "loading", states: { loading: { + always: [{ target: "idle", cond: "cantFetchGroups" }], invoke: { src: "loadGroups", onDone: { @@ -39,6 +41,9 @@ export const groupsMachine = createMachine( }, }, { + guards: { + cantFetchGroups: ({ shouldFetchGroups }) => !shouldFetchGroups, + }, services: { loadGroups: ({ organizationId }) => getGroups(organizationId), },