1
- import { useMachine } from "@xstate/react" ;
2
1
import { useFeatureVisibility } from "hooks/useFeatureVisibility" ;
3
2
import { useOrganizationId } from "hooks/useOrganizationId" ;
4
3
import { usePermissions } from "hooks/usePermissions" ;
5
- import { FC } from "react" ;
4
+ import { FC , useEffect } from "react" ;
6
5
import { Helmet } from "react-helmet-async" ;
7
6
import { pageTitle } from "utils/page" ;
8
- import { groupsMachine } from "xServices/groups/groupsXService" ;
9
7
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" ;
10
12
11
13
export const GroupsPage : FC = ( ) => {
12
14
const organizationId = useOrganizationId ( ) ;
13
15
const { createGroup : canCreateGroup } = usePermissions ( ) ;
14
16
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 ] ) ;
22
26
23
27
return (
24
28
< >
@@ -27,7 +31,7 @@ export const GroupsPage: FC = () => {
27
31
</ Helmet >
28
32
29
33
< GroupsPageView
30
- groups = { groups }
34
+ groups = { groupsQuery . data }
31
35
canCreateGroup = { canCreateGroup }
32
36
isTemplateRBACEnabled = { isTemplateRBACEnabled }
33
37
/>
0 commit comments