@@ -9,7 +9,11 @@ import type {
99const GROUPS_QUERY_KEY = [ "groups" ] ;
1010type GroupSortOrder = "asc" | "desc" ;
1111
12- const getGroupQueryKey = ( groupName :string ) => [ "group" , groupName ] ;
12+ const getGroupQueryKey = ( organizationId :string , groupName :string ) => [
13+ organizationId ,
14+ "group" ,
15+ groupName ,
16+ ] ;
1317
1418export const groups = ( organizationId :string ) => {
1519return {
@@ -18,10 +22,10 @@ export const groups = (organizationId: string) => {
1822} satisfies UseQueryOptions < Group [ ] > ;
1923} ;
2024
21- export const group = ( groupName :string ) => {
25+ export const group = ( organizationId : string , groupName :string ) => {
2226return {
23- queryKey :getGroupQueryKey ( groupName ) ,
24- queryFn :( ) => API . getGroup ( groupName ) ,
27+ queryKey :getGroupQueryKey ( organizationId , groupName ) ,
28+ queryFn :( ) => API . getGroup ( organizationId , groupName ) ,
2529} ;
2630} ;
2731
@@ -69,7 +73,7 @@ export function groupsForUser(organizationId: string, userId: string) {
6973
7074export const groupPermissions = ( groupId :string ) => {
7175return {
72- queryKey :[ ... getGroupQueryKey ( groupId ) , "permissions" ] ,
76+ queryKey :[ "group" , groupId , "permissions" ] ,
7377queryFn :( ) =>
7478API . checkAuthorization ( {
7579checks :{
@@ -85,12 +89,12 @@ export const groupPermissions = (groupId: string) => {
8589} ;
8690} ;
8791
88- export const createGroup = ( queryClient :QueryClient ) => {
92+ export const createGroup = (
93+ queryClient :QueryClient ,
94+ organizationId :string ,
95+ ) => {
8996return {
90- mutationFn :( {
91- organizationId,
92- ...request
93- } :CreateGroupRequest & { organizationId :string } ) =>
97+ mutationFn :( request :CreateGroupRequest ) =>
9498API . createGroup ( organizationId , request ) ,
9599onSuccess :async ( ) => {
96100await queryClient . invalidateQueries ( GROUPS_QUERY_KEY ) ;
@@ -106,15 +110,15 @@ export const patchGroup = (queryClient: QueryClient) => {
106110} :PatchGroupRequest & { groupId :string } ) =>
107111API . patchGroup ( groupId , request ) ,
108112onSuccess :async ( updatedGroup :Group ) =>
109- invalidateGroup ( queryClient , updatedGroup . id ) ,
113+ invalidateGroup ( queryClient , "default" , updatedGroup . id ) ,
110114} ;
111115} ;
112116
113117export const deleteGroup = ( queryClient :QueryClient ) => {
114118return {
115119mutationFn :API . deleteGroup ,
116120onSuccess :async ( _ :void , groupId :string ) =>
117- invalidateGroup ( queryClient , groupId ) ,
121+ invalidateGroup ( queryClient , "default" , groupId ) ,
118122} ;
119123} ;
120124
@@ -123,7 +127,7 @@ export const addMember = (queryClient: QueryClient) => {
123127mutationFn :( { groupId, userId} :{ groupId :string ; userId :string } ) =>
124128API . addMember ( groupId , userId ) ,
125129onSuccess :async ( updatedGroup :Group ) =>
126- invalidateGroup ( queryClient , updatedGroup . id ) ,
130+ invalidateGroup ( queryClient , "default" , updatedGroup . id ) ,
127131} ;
128132} ;
129133
@@ -132,14 +136,18 @@ export const removeMember = (queryClient: QueryClient) => {
132136mutationFn :( { groupId, userId} :{ groupId :string ; userId :string } ) =>
133137API . removeMember ( groupId , userId ) ,
134138onSuccess :async ( updatedGroup :Group ) =>
135- invalidateGroup ( queryClient , updatedGroup . id ) ,
139+ invalidateGroup ( queryClient , "default" , updatedGroup . id ) ,
136140} ;
137141} ;
138142
139- export const invalidateGroup = ( queryClient :QueryClient , groupId :string ) =>
143+ export const invalidateGroup = (
144+ queryClient :QueryClient ,
145+ organizationId :string ,
146+ groupId :string ,
147+ ) =>
140148Promise . all ( [
141149queryClient . invalidateQueries ( GROUPS_QUERY_KEY ) ,
142- queryClient . invalidateQueries ( getGroupQueryKey ( groupId ) ) ,
150+ queryClient . invalidateQueries ( getGroupQueryKey ( organizationId , groupId ) ) ,
143151] ) ;
144152
145153export function sortGroupsByName (