Skip to content

Commit

Permalink
feat: add useAddUser hook for adding a user via API
Browse files Browse the repository at this point in the history
  • Loading branch information
anovazzi1 committed Jul 16, 2024
1 parent c86b884 commit b7ef9c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/frontend/src/controllers/API/queries/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-get-user";
28 changes: 28 additions & 0 deletions src/frontend/src/controllers/API/queries/auth/use-add-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Users, useMutationFunctionType } from "@/types/api";
import { UserInputType } from "@/types/components";
import { UseMutationResult } from "@tanstack/react-query";
import { api } from "../../api";
import { getURL } from "../../helpers/constants";
import { UseRequestProcessor } from "../../services/request-processor";

export const useAddUser: useMutationFunctionType<UserInputType> = (
options?,
) => {
const { mutate } = UseRequestProcessor();

const addUserFunction = async (user: UserInputType): Promise<Array<Users>> => {
const res = await api.post(`${getURL("USERS")}`, user);
return res.data;
}

const mutation: UseMutationResult<Array<Users>, any, UserInputType> = mutate(
["useAddUser"],
async (payload: UserInputType) => {
const res = await addUserFunction(payload);
return res;
},
options,
);

return mutation;
};

0 comments on commit b7ef9c7

Please sign in to comment.