|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { QueryClient } from "@tanstack/react-query" |
|
3
|
import { promotionsQueryKeys } from "../../../hooks/api/promotions" |
|
4
|
import { sdk } from "../../../lib/client" |
|
5
|
import { queryClient } from "../../../lib/query-client" |
|
6
|
|
|
7
|
const params = { |
|
8
|
limit: 20, |
|
9
|
offset: 0, |
|
10
|
} |
|
11
|
|
|
12
|
const promotionsListQuery = () => ({ |
|
13
|
queryKey: promotionsQueryKeys.list(params), |
|
14
|
queryFn: async () => sdk.admin.promotion.list(params), |
|
15
|
}) |
|
16
|
|
|
17
|
export const promotionsLoader = (client: QueryClient) => { |
|
18
|
return async () => { |
|
19
|
const query = promotionsListQuery() |
|
20
|
|
|
21
|
return ( |
|
22
|
queryClient.getQueryData<HttpTypes.AdminPromotionListResponse>( |
|
23
|
query.queryKey |
|
24
|
) ?? (await client.fetchQuery(query)) |
|
25
|
) |
|
26
|
} |
|
27
|
} |