Skip to content

Commit

Permalink
fix: change the way of initializing analytics server on web (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyevskii authored Oct 1, 2024
1 parent 28eb6ce commit 8713a83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions template/apps/web/src/pages/_app/PageConfig/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, Fragment, ReactElement } from 'react';
import React, { FC, Fragment, ReactElement, useEffect } from 'react';
import { useRouter } from 'next/router';

import { accountApi } from 'resources/account';
Expand Down Expand Up @@ -30,15 +30,15 @@ interface PageConfigProps {

const PageConfig: FC<PageConfigProps> = ({ children }) => {
const { route, push } = useRouter();
const { data: account, isLoading: isAccountLoading } = accountApi.useGet({
onSettled: () => {
if (!config.MIXPANEL_API_KEY) return;

analyticsService.init();
const { data: account, isLoading: isAccountLoading, isSuccess, isError } = accountApi.useGet();

analyticsService.setUser(account);
},
});
useEffect(() => {
if ((!isSuccess && !isError) || !config.MIXPANEL_API_KEY) return;

analyticsService.init();
analyticsService.setUser(account);
}, [isSuccess, isError]);

if (isAccountLoading) return null;

Expand Down
4 changes: 2 additions & 2 deletions template/apps/web/src/resources/account/account.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation, useQuery } from '@tanstack/react-query';
import { useMutation, useQuery, UseQueryOptions } from '@tanstack/react-query';

import { apiService } from 'services';

Expand Down Expand Up @@ -56,7 +56,7 @@ export const useResendEmail = <T = ResendEmailParams>() =>
mutationFn: (data: T) => apiService.post('/account/resend-email', data),
});

export const useGet = (options = {}) =>
export const useGet = (options: Partial<UseQueryOptions<User>> = {}) =>
useQuery<User>({
queryKey: ['account'],
queryFn: () => apiService.get('/account'),
Expand Down

0 comments on commit 8713a83

Please sign in to comment.