Skip to content

Commit 07a4bd4

Browse files
committed
Remove groups service
1 parent d0d64bb commit 07a4bd4

File tree

3 files changed

+23
-71
lines changed

3 files changed

+23
-71
lines changed

site/src/api/queries/groups.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as API from "api/api";
2+
3+
export const groups = (organizationId: string) => {
4+
return {
5+
queryKey: ["groups"],
6+
queryFn: () => API.getGroups(organizationId),
7+
};
8+
};

site/src/pages/GroupsPage/GroupsPage.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
import { useMachine } from "@xstate/react";
21
import { useFeatureVisibility } from "hooks/useFeatureVisibility";
32
import { useOrganizationId } from "hooks/useOrganizationId";
43
import { usePermissions } from "hooks/usePermissions";
5-
import { FC } from "react";
4+
import { FC, useEffect } from "react";
65
import { Helmet } from "react-helmet-async";
76
import { pageTitle } from "utils/page";
8-
import { groupsMachine } from "xServices/groups/groupsXService";
97
import GroupsPageView from "./GroupsPageView";
8+
import { useQuery } from "@tanstack/react-query";
9+
import { groups } from "api/queries/groups";
10+
import { displayError } from "components/GlobalSnackbar/utils";
11+
import { getErrorMessage } from "api/errors";
1012

1113
export const GroupsPage: FC = () => {
1214
const organizationId = useOrganizationId();
1315
const { createGroup: canCreateGroup } = usePermissions();
1416
const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility();
15-
const [state] = useMachine(groupsMachine, {
16-
context: {
17-
organizationId,
18-
shouldFetchGroups: isTemplateRBACEnabled,
19-
},
20-
});
21-
const { groups } = state.context;
17+
const groupsQuery = useQuery(groups(organizationId));
18+
19+
useEffect(() => {
20+
if (groupsQuery.error) {
21+
displayError(
22+
getErrorMessage(groupsQuery.error, "Error on loading groups."),
23+
);
24+
}
25+
}, [groupsQuery.error]);
2226

2327
return (
2428
<>
@@ -27,7 +31,7 @@ export const GroupsPage: FC = () => {
2731
</Helmet>
2832

2933
<GroupsPageView
30-
groups={groups}
34+
groups={groupsQuery.data}
3135
canCreateGroup={canCreateGroup}
3236
isTemplateRBACEnabled={isTemplateRBACEnabled}
3337
/>

site/src/xServices/groups/groupsXService.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)