Skip to content

Commit

Permalink
update hook examples
Browse files Browse the repository at this point in the history
  • Loading branch information
choden-dev committed Mar 12, 2024
1 parent 60a5f03 commit 7582461
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
7 changes: 0 additions & 7 deletions client/src/services/Queries.ts

This file was deleted.

8 changes: 8 additions & 0 deletions client/src/services/User/UserMutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useMutation } from "@tanstack/react-query"
import UserService, { EditUsersBody } from "./UserService"

export function useEditUserMutation(users: EditUsersBody) {
return useMutation({
mutationFn: () => UserService.editUsers(users)
})
}
9 changes: 9 additions & 0 deletions client/src/services/User/UserQueries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useQuery } from "@tanstack/react-query"
import UserService from "./UserService"

export function useUsersQuery() {
return useQuery({
queryKey: ["allUsers"],
queryFn: () => UserService.getUsers()
})
}
24 changes: 24 additions & 0 deletions client/src/services/User/UserService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { components } from "models/__generated__/schema"
import fetchClient from "../OpenApiFetchClient"

type UserAdditionalInfo = components["schemas"]["UserAdditionalInfo"]
export type EditUsersBody = {
uid: string
updatedInformation: UserAdditionalInfo
}[]

const UserService = {
getUsers: async function () {
const { data } = await fetchClient.GET("/users", {})
return data
},
editUsers: async function (users: EditUsersBody) {
await fetchClient.PATCH("/users/bulk-edit", {
body: {
users
}
})
}
} as const

export default UserService
10 changes: 0 additions & 10 deletions client/src/services/UserService.ts

This file was deleted.

0 comments on commit 7582461

Please sign in to comment.