26 lines
629 B
TypeScript
26 lines
629 B
TypeScript
import { keepPreviousData, queryOptions } from "@tanstack/react-query";
|
|
import { api } from "../apiHelper";
|
|
|
|
export function getScanUsers() {
|
|
return queryOptions({
|
|
queryKey: ["getScanUsers"],
|
|
queryFn: () => dataFetch(),
|
|
staleTime: 5000,
|
|
refetchOnWindowFocus: true,
|
|
placeholderData: keepPreviousData,
|
|
});
|
|
}
|
|
|
|
const dataFetch = async () => {
|
|
if (window.location.hostname === "localhost") {
|
|
await new Promise((res) => setTimeout(res, 1500));
|
|
}
|
|
|
|
const { data } = await api.get("/mobile/auth/user");
|
|
if (!data.success) {
|
|
throw new Error(data.message ?? "Failed to load scan users");
|
|
}
|
|
|
|
return data.data ?? [];
|
|
};
|