|
1
|
import { FetchError } from "@medusajs/js-sdk"; |
|
2
|
import { HttpTypes } from "@medusajs/types"; |
|
3
|
import { QueryKey, UseQueryOptions, useQuery } from "@tanstack/react-query"; |
|
4
|
import { queryKeysFactory } from "../../lib/query-key"; |
|
5
|
import { sdk } from "../../lib/sdk"; |
|
6
|
|
|
7
|
const PRICE_PREFERENCES_QUERY_KEY = "price-preferences" as const; |
|
8
|
export const pricePreferencesQueryKeys = queryKeysFactory( |
|
9
|
PRICE_PREFERENCES_QUERY_KEY |
|
10
|
); |
|
11
|
|
|
12
|
export const usePricePreferences = ( |
|
13
|
query?: HttpTypes.AdminPricePreferenceListParams, |
|
14
|
options?: Omit< |
|
15
|
UseQueryOptions< |
|
16
|
HttpTypes.AdminPricePreferenceListResponse, |
|
17
|
FetchError, |
|
18
|
HttpTypes.AdminPricePreferenceListResponse, |
|
19
|
QueryKey |
|
20
|
>, |
|
21
|
"queryKey" | "queryFn" |
|
22
|
> |
|
23
|
) => { |
|
24
|
const { data, ...rest } = useQuery({ |
|
25
|
queryFn: () => sdk.admin.pricePreference.list(query), |
|
26
|
queryKey: pricePreferencesQueryKeys.list(query), |
|
27
|
...options, |
|
28
|
}); |
|
29
|
|
|
30
|
return { ...data, ...rest }; |
|
31
|
}; |