connected with loan order api
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient, useInfiniteQuery } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useDebouncedValue, normalizeSearch } from "@/hooks/useDebouncedSearch";
|
||||
@@ -10,6 +10,7 @@ export const userKeys = {
|
||||
list: (params: UsersListParams) => [...userKeys.lists(), params] as const,
|
||||
details: () => [...userKeys.all, "detail"] as const,
|
||||
detail: (id: number) => [...userKeys.details(), id] as const,
|
||||
infinite: (search: string) => [...userKeys.all, "infinite", search] as const,
|
||||
};
|
||||
|
||||
export function useUsers(params: UsersListParams = {}) {
|
||||
@@ -23,6 +24,23 @@ export function useUsers(params: UsersListParams = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
const USER_PAGE_SIZE = 25;
|
||||
|
||||
export function useInfiniteUsers(search = "") {
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch);
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: userKeys.infinite(effectiveSearch),
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => usersApi.getUsers({ page: pageParam, limit: USER_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + p.users.length, 0);
|
||||
return loaded < lastPage.count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUser(id: number) {
|
||||
return useQuery({
|
||||
queryKey: userKeys.detail(id),
|
||||
|
||||
Reference in New Issue
Block a user