Source

apis/User.js

import { useMutation, useQuery } from "@tanstack/react-query";
import Axios from "../utils/ApiConfiguration";
/**
 * Custom hook to fetch user data.
 *
 * This hook sends a GET request to retrieve user data from the server.
 *
 * @returns {Object} The query result object.
 *
 * @example
 * // Usage of useGetUser hook
 * const { data, isLoading, isError, error } = useGetUser();
 */
export const useGetUser = () =>
  useQuery({
    queryKey: ["user"],
    queryFn: () => Axios.get("auth/user/"),
    refetchOnWindowFocus: false,
  });
/**
 * Custom hook to fetch user roles.
 *
 * This hook sends a GET request to retrieve user roles from the server.
 *
 * @returns {Object} The query result object.
 *
 * @example
 * // Usage of useGetUserRoles hook
 * const { data, isLoading, isError, error } = useGetUserRoles();
 */
export const useGetUserRoles = () =>
  useQuery({
    queryKey: ["user_roles"],
    queryFn: () => Axios.get(`auth/userroles/`),
    refetchOnWindowFocus: false,
  });