-
Notifications
You must be signed in to change notification settings - Fork 899
chore(site): refactor groups to use react-query #9701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
07a4bd4
6b93fcc
7466c8b
93c0f37
9bfb06e
d6220a0
ac005c1
23a34d6
0871f2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { QueryClient } from "@tanstack/react-query"; | ||
import * as API from "api/api"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the conversation we had earlier, would this need to be updated to use named imports, or do we just generally do the wildcard import for the API? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good question, I like this way because it avoids conflicts but I don't think we set a preference. What do you think @aslilac ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, this is what I've been doing to. it's fine. 🤷♀️ |
||
import { checkAuthorization } from "api/api"; | ||
import { | ||
CreateGroupRequest, | ||
Group, | ||
|
@@ -20,6 +21,24 @@ export const group = (groupId: string) => { | |
}; | ||
}; | ||
|
||
export const groupPermissions = (groupId: string) => { | ||
return { | ||
queryKey: ["group", groupId, "permissions"], | ||
queryFn: () => | ||
checkAuthorization({ | ||
checks: { | ||
canUpdateGroup: { | ||
object: { | ||
resource_type: "group", | ||
resource_id: groupId, | ||
}, | ||
action: "update", | ||
}, | ||
}, | ||
}), | ||
}; | ||
}; | ||
|
||
export const createGroup = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: ({ | ||
|
@@ -48,3 +67,41 @@ export const patchGroup = (queryClient: QueryClient) => { | |
}, | ||
}; | ||
}; | ||
|
||
export const deleteGroup = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: API.deleteGroup, | ||
onSuccess: async (_: void, groupId: string) => { | ||
await Promise.all([ | ||
queryClient.invalidateQueries(["groups"]), | ||
queryClient.invalidateQueries(["group", groupId]), | ||
]); | ||
}, | ||
}; | ||
}; | ||
|
||
export const addMember = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: ({ groupId, userId }: { groupId: string; userId: string }) => | ||
API.addMember(groupId, userId), | ||
onSuccess: async (updatedGroup: Group) => { | ||
await Promise.all([ | ||
queryClient.invalidateQueries(["groups"]), | ||
queryClient.invalidateQueries(["group", updatedGroup.id]), | ||
]); | ||
}, | ||
}; | ||
}; | ||
|
||
export const removeMember = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: ({ groupId, userId }: { groupId: string; userId: string }) => | ||
API.removeMember(groupId, userId), | ||
onSuccess: async (updatedGroup: Group) => { | ||
await Promise.all([ | ||
queryClient.invalidateQueries(["groups"]), | ||
queryClient.invalidateQueries(["group", updatedGroup.id]), | ||
]); | ||
}, | ||
}; | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.