Skip to content

Commit

Permalink
feat: env fix
Browse files Browse the repository at this point in the history
  • Loading branch information
scopsy committed Dec 8, 2024
1 parent ef86269 commit 039ae24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 9 additions & 2 deletions apps/dashboard/src/api/activity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IEnvironment } from '@novu/shared';
import { get } from './api.client';
import type { Activity } from '@/hooks/use-activities';

Expand All @@ -15,7 +16,11 @@ interface ActivityResponse {
pageSize: number;
}

export function getActivityList(page = 0, filters?: IActivityFilters): Promise<ActivityResponse> {
export function getActivityList(
environment: IEnvironment,
page = 0,
filters?: IActivityFilters
): Promise<ActivityResponse> {
const searchParams = new URLSearchParams();
searchParams.append('page', page.toString());

Expand All @@ -35,7 +40,9 @@ export function getActivityList(page = 0, filters?: IActivityFilters): Promise<A
searchParams.append('transactionId', filters.transactionId);
}

return get<ActivityResponse>(`/notifications?${searchParams.toString()}`);
return get<ActivityResponse>(`/notifications?${searchParams.toString()}`, {
environment,
});
}

export function getActivityStats() {
Expand Down
7 changes: 5 additions & 2 deletions apps/dashboard/src/hooks/use-activities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useQuery } from '@tanstack/react-query';
import { getActivityList, IActivityFilters } from '@/api/activity';
import { useEnvironment } from '../context/environment/hooks';

interface UseActivitiesOptions {
page?: number;
Expand Down Expand Up @@ -83,9 +84,11 @@ interface ActivityResponse {
}

export function useActivities({ page = 0, filters }: UseActivitiesOptions = {}) {
const { currentEnvironment } = useEnvironment();

const { data, isLoading, isFetching } = useQuery<ActivityResponse>({
queryKey: ['activitiesList', page, filters],
queryFn: () => getActivityList(page, filters),
queryKey: ['activitiesList', currentEnvironment?._id, page, filters],
queryFn: () => getActivityList(currentEnvironment!, page, filters),
staleTime: 1000 * 60, // 1 minute
});

Expand Down

0 comments on commit 039ae24

Please sign in to comment.