fixed ui, connected role user, branch user permissions user api

This commit is contained in:
Jelaletdin12
2026-08-23 19:09:06 +05:00
parent d230b12d6a
commit f00d2abcac
20 changed files with 906 additions and 391 deletions

View File

@@ -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";
@@ -37,6 +37,29 @@ export function useOperator(id: number) {
});
}
const STAFF_PAGE_SIZE = 25;
/**
* Paginated staff users (GET /users/staff) for infinite-scroll selects.
* `search` is debounced server-side search; each keystroke resets to page 1.
*/
export function useInfiniteStaff(search = "") {
const debouncedSearch = useDebouncedValue(search);
const effectiveSearch = normalizeSearch(debouncedSearch);
return useInfiniteQuery({
queryKey: [...operatorKeys.all, "infinite", effectiveSearch] as const,
initialPageParam: 1,
queryFn: ({ pageParam, signal }) =>
operatorsApi.getOperators({ page: pageParam, limit: STAFF_PAGE_SIZE, search: effectiveSearch }, signal),
getNextPageParam: (lastPage, allPages) => {
const loaded = allPages.reduce((sum, p) => sum + (p?.users?.length ?? 0), 0);
const count = lastPage?.count ?? 0;
return loaded < count ? allPages.length + 1 : undefined;
},
});
}
// ─── useCreateOperator ────────────────────────────────────────────────────────
export function useCreateOperator() {