|
1
|
import { QueryKey, UseQueryOptions, useQuery } from "@tanstack/react-query" |
|
2
|
import { sdk } from "../../lib/client" |
|
3
|
import { queryKeysFactory } from "../../lib/query-key-factory" |
|
4
|
import { HttpTypes } from "@medusajs/types" |
|
5
|
import { FetchError } from "@medusajs/js-sdk" |
|
6
|
|
|
7
|
const WORKFLOW_EXECUTIONS_QUERY_KEY = "workflow_executions" as const |
|
8
|
export const workflowExecutionsQueryKeys = queryKeysFactory( |
|
9
|
WORKFLOW_EXECUTIONS_QUERY_KEY |
|
10
|
) |
|
11
|
|
|
12
|
export const useWorkflowExecutions = ( |
|
13
|
query?: HttpTypes.AdminGetWorkflowExecutionsParams, |
|
14
|
options?: Omit< |
|
15
|
UseQueryOptions< |
|
16
|
HttpTypes.AdminGetWorkflowExecutionsParams, |
|
17
|
FetchError, |
|
18
|
HttpTypes.AdminWorkflowExecutionListResponse, |
|
19
|
QueryKey |
|
20
|
>, |
|
21
|
"queryKey" | "queryFn" |
|
22
|
> |
|
23
|
) => { |
|
24
|
const { data, ...rest } = useQuery({ |
|
25
|
queryFn: () => sdk.admin.workflowExecution.list(query), |
|
26
|
queryKey: workflowExecutionsQueryKeys.list(query), |
|
27
|
...options, |
|
28
|
}) |
|
29
|
|
|
30
|
return { ...data, ...rest } |
|
31
|
} |
|
32
|
|
|
33
|
export const useWorkflowExecution = ( |
|
34
|
id: string, |
|
35
|
options?: Omit< |
|
36
|
UseQueryOptions< |
|
37
|
HttpTypes.AdminWorkflowExecutionResponse, |
|
38
|
FetchError, |
|
39
|
HttpTypes.AdminWorkflowExecutionResponse, |
|
40
|
QueryKey |
|
41
|
>, |
|
42
|
"queryKey" | "queryFn" |
|
43
|
> |
|
44
|
) => { |
|
45
|
const { data, ...rest } = useQuery({ |
|
46
|
queryFn: () => sdk.admin.workflowExecution.retrieve(id), |
|
47
|
queryKey: workflowExecutionsQueryKeys.detail(id), |
|
48
|
...options, |
|
49
|
}) |
|
50
|
|
|
51
|
return { ...data, ...rest } |
|
52
|
} |