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