Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | import {
InfiniteData,
useInfiniteQuery,
useQuery,
} from "@tanstack/react-query";
import {
modUserDetailsKey,
modUserKey,
newUsersListKey,
} from "features/queryKeys";
import { userStaleTime } from "features/userQueries/constants";
import { RpcError } from "grpc-web";
import { ListUserIdsRes, UserDetails } from "proto/admin_pb";
import { User } from "proto/api_pb";
import { service } from "service";
export const useNewUsers = () => {
const query = useInfiniteQuery<
ListUserIdsRes.AsObject,
RpcError,
InfiniteData<ListUserIdsRes.AsObject>,
[typeof newUsersListKey],
string
>({
queryKey: [newUsersListKey],
queryFn: ({ pageParam }) =>
service.admin.listUserIds({
startTime: new Date(1970, 0, 0, 0, 0, 1),
endTime: new Date(2050, 0, 0),
pageSize: 50,
pageToken: pageParam,
}),
initialPageParam: "0",
getNextPageParam: (lastPage) => lastPage.nextPageToken || undefined,
refetchInterval: 60_000,
});
const userIds = query.data?.pages.flatMap((page) => page.userIdsList);
return { ...query, userIds };
};
export default function useUserWithDetails(user: string) {
const query = useQuery<User.AsObject, RpcError>({
queryFn: () => service.admin.getUser(user),
queryKey: [modUserKey(user)],
staleTime: userStaleTime,
});
const detailsQuery = useQuery<UserDetails.AsObject, RpcError>({
queryFn: () => service.admin.getUserDetails(user),
queryKey: [modUserDetailsKey(user)],
staleTime: userStaleTime,
});
const errors = [];
Iif (query.error?.message) {
errors.push(query.error?.message || "");
}
Iif (detailsQuery.error?.message) {
errors.push(detailsQuery.error?.message || "");
}
const error = errors.join("\n");
const isLoading = query.isLoading || detailsQuery.isLoading;
const isFetching = query.isFetching || detailsQuery.isFetching;
const isError = query.isError || detailsQuery.isError;
return {
user: query.data,
userDetails: detailsQuery.data,
error,
isError,
isFetching,
isLoading,
};
}
|