Skip to content

Commit

Permalink
fix(dashboard): Don't show query errors for subscription/bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
desiprisg committed Jan 22, 2025
1 parent 6670ead commit ac60f6a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
4 changes: 2 additions & 2 deletions apps/dashboard/src/hooks/use-billing-portal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useMutation } from '@tanstack/react-query';
import { get } from '../api/api.client';
import { toast } from 'sonner';
import { useTelemetry } from './use-telemetry';
import { get } from '../api/api.client';
import { TelemetryEvent } from '../utils/telemetry';
import { useTelemetry } from './use-telemetry';

export function useBillingPortal(billingInterval?: 'month' | 'year') {
const track = useTelemetry();
Expand Down
6 changes: 2 additions & 4 deletions apps/dashboard/src/hooks/use-checkout-session.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useMutation } from '@tanstack/react-query';
import { ApiServiceLevelEnum } from '@novu/shared';
import { useMutation } from '@tanstack/react-query';
import { post } from '../api/api.client';
import { toast } from 'sonner';
import { useTelemetry } from './use-telemetry';
import { TelemetryEvent } from '../utils/telemetry';
import { useTelemetry } from './use-telemetry';

interface CheckoutResponse {
data: {
Expand Down Expand Up @@ -37,7 +36,6 @@ export function useCheckoutSession() {
error: error.message,
billingInterval,
});
toast.error(error.message || 'Unexpected error');
},
});

Expand Down
11 changes: 7 additions & 4 deletions apps/dashboard/src/hooks/use-fetch-bridge-health-check.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ConnectionStatus } from '@/utils/types';
import { getBridgeHealthCheck } from '@/api/bridge';
import { QueryKeys } from '@/utils/query-keys';
import { useEnvironment } from '@/context/environment/hooks';
import { useMemo } from 'react';
import { useQuery } from '@tanstack/react-query';
import { QueryKeys } from '@/utils/query-keys';
import { ConnectionStatus } from '@/utils/types';
import type { HealthCheck } from '@novu/framework/internal';
import { useQuery } from '@tanstack/react-query';
import { useMemo } from 'react';

const BRIDGE_STATUS_REFRESH_INTERVAL_IN_MS = 10 * 1000;

Expand All @@ -19,6 +19,9 @@ export const useFetchBridgeHealthCheck = () => {
networkMode: 'always',
refetchOnWindowFocus: true,
refetchInterval: BRIDGE_STATUS_REFRESH_INTERVAL_IN_MS,
meta: {
showError: false,
},
});

const status = useMemo<ConnectionStatus>(() => {
Expand Down
11 changes: 7 additions & 4 deletions apps/dashboard/src/hooks/use-fetch-subscription.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { differenceInDays, isSameDay } from 'date-fns';
import { getSubscription } from '@/api/billing';
import { QueryKeys } from '@/utils/query-keys';
import { useAuth } from '@/context/auth/hooks';
import { useEnvironment } from '@/context/environment/hooks';
import { useMemo } from 'react';
import { useQuery } from '@tanstack/react-query';
import { QueryKeys } from '@/utils/query-keys';
import type { GetSubscriptionDto } from '@novu/shared';
import { useQuery } from '@tanstack/react-query';
import { differenceInDays, isSameDay } from 'date-fns';
import { useMemo } from 'react';

const today = new Date();

Expand All @@ -19,6 +19,9 @@ export const useFetchSubscription = () => {
queryKey: [QueryKeys.billingSubscription, currentOrganization?._id],
queryFn: () => getSubscription({ environment: currentEnvironment! }),
enabled: !!currentOrganization,
meta: {
showError: false,
},
});

const daysLeft = useMemo(() => {
Expand Down
32 changes: 18 additions & 14 deletions apps/dashboard/src/routes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ const queryClient = new QueryClient({
},
},
queryCache: new QueryCache({
onError: (_, query) => {
showToast({
children: () => (
<>
<ToastIcon variant="error" />
<span className="text-sm">{(query.meta?.errorMessage as string | undefined) || 'Issue fetching.'}</span>
</>
),
options: {
position: 'bottom-right',
classNames: {
toast: 'mb-4 right-0',
onError: (error, query) => {
if (query.meta?.showError !== false) {
showToast({
children: () => (
<>
<ToastIcon variant="error" />
<span className="text-sm">
{(query.meta?.errorMessage as string | undefined) || error.message || 'Issue fetching.'}
</span>
</>
),
options: {
position: 'bottom-right',
classNames: {
toast: 'mb-4 right-0',
},
},
},
});
});
}
},
}),
});
Expand Down

0 comments on commit ac60f6a

Please sign in to comment.