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