vchikalkin a3f98c1e91 finally: fix calculate error
(caused by empty cookies in bonus validation user request)
2023-03-24 20:21:10 +03:00

35 lines
962 B
TypeScript

import { getUser } from '@/api/user/query';
import { STALE_TIME } from '@/constants/request';
import type { Process, ProcessContext } from '@/process/types';
import { useStore } from '@/stores/hooks';
import { trpcPureClient } from '@/trpc/client';
import { useApolloClient } from '@apollo/client';
import { useQuery, useQueryClient } from '@tanstack/react-query';
export function useProcess({ reactions }: Process) {
const context = useProcessContext();
Object.keys(reactions).forEach((name) => {
const injector = reactions[name];
injector(context);
});
}
export function useProcessContext(): ProcessContext {
const store = useStore();
const apolloClient = useApolloClient();
const queryClient = useQueryClient();
const { data: user } = useQuery(['user'], ({ signal }) => getUser({ signal }), {
staleTime: STALE_TIME,
});
return {
apolloClient,
queryClient,
store,
trpcClient: trpcPureClient,
user,
};
}