-
Notifications
You must be signed in to change notification settings - Fork 896
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,6 +1,10 @@ | ||
import { QueryClient } from "@tanstack/react-query"; | ||
import * as API from "api/api"; | ||
import { CreateGroupRequest } from "api/typesGenerated"; | ||
import { | ||
CreateGroupRequest, | ||
Group, | ||
PatchGroupRequest, | ||
} from "api/typesGenerated"; | ||
|
||
export const groups = (organizationId: string) => { | ||
return { | ||
|
@@ -9,6 +13,13 @@ export const groups = (organizationId: string) => { | |
}; | ||
}; | ||
|
||
export const group = (groupId: string) => { | ||
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. I can't remember if anyone discussed this, but is there a naming convention that we're going to follow for these React Query utility functions? I guess my concern here is that 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. Hm...... this is a good one, I don't have an answer for that. What do you think @Parkreiner @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. Maybe something like 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. eh, I think the fact that they're coming from the queries module is clear enough. I like the short names that focus end result we've been using. |
||
return { | ||
queryKey: ["group", groupId], | ||
queryFn: () => API.getGroup(groupId), | ||
}; | ||
}; | ||
|
||
export const createGroup = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: ({ | ||
|
@@ -21,3 +32,19 @@ export const createGroup = (queryClient: QueryClient) => { | |
}, | ||
}; | ||
}; | ||
|
||
export const patchGroup = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: ({ | ||
groupId, | ||
...request | ||
}: PatchGroupRequest & { groupId: string }) => | ||
API.patchGroup(groupId, request), | ||
onSuccess: async (updatedGroup: Group) => { | ||
await Promise.all([ | ||
queryClient.invalidateQueries(["groups"]), | ||
queryClient.invalidateQueries(["group", updatedGroup.id]), | ||
]); | ||
}, | ||
}; | ||
}; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is what I've been doing to. it's fine. 🤷♀️