-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuse-query-get-workspace-alerts.ts
48 lines (44 loc) · 1.4 KB
/
use-query-get-workspace-alerts.ts
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
import {
V1GetWorkspaceAlertsData,
V1GetWorkspaceAlertsResponse,
} from "@/api/generated";
import { v1GetWorkspaceAlertsOptions } from "@/api/generated/@tanstack/react-query.gen";
import { useActiveWorkspaceName } from "@/features/workspace/hooks/use-active-workspace-name";
import { getQueryCacheConfig } from "@/lib/react-query-utils";
import { useQuery } from "@tanstack/react-query";
export function useQueryGetWorkspaceAlerts<T = V1GetWorkspaceAlertsResponse>({
select,
}: {
select?: (data: V1GetWorkspaceAlertsResponse) => T;
} = {}) {
const {
data: activeWorkspaceName,
isPending: isWorkspacePending,
isFetching: isWorkspaceFetching,
isLoading: isWorkspaceLoading,
isRefetching: isWorkspaceRefetching,
} = useActiveWorkspaceName();
const options: V1GetWorkspaceAlertsData = {
path: {
workspace_name: activeWorkspaceName ?? "default",
},
};
const {
isPending: isAlertsPending,
isFetching: isAlertsFetching,
isLoading: isAlertsLoading,
isRefetching: isAlertsRefetching,
...rest
} = useQuery({
...v1GetWorkspaceAlertsOptions(options),
...getQueryCacheConfig("5s"),
select,
});
return {
...rest,
isPending: isAlertsPending || isWorkspacePending,
isFetching: isAlertsFetching || isWorkspaceFetching,
isLoading: isAlertsLoading || isWorkspaceLoading,
isRefetching: isAlertsRefetching || isWorkspaceRefetching,
};
}