|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { useQueryParams } from "../../use-query-params" |
|
3
|
|
|
4
|
type UseOrderTableQueryProps = { |
|
5
|
prefix?: string |
|
6
|
pageSize?: number |
|
7
|
} |
|
8
|
|
|
9
|
export const useOrderTableQuery = ({ |
|
10
|
prefix, |
|
11
|
pageSize = 20, |
|
12
|
}: UseOrderTableQueryProps) => { |
|
13
|
const queryObject = useQueryParams( |
|
14
|
[ |
|
15
|
"offset", |
|
16
|
"q", |
|
17
|
"created_at", |
|
18
|
"updated_at", |
|
19
|
"region_id", |
|
20
|
"sales_channel_id", |
|
21
|
// "payment_status", |
|
22
|
// "fulfillment_status", |
|
23
|
"order", |
|
24
|
"total", |
|
25
|
], |
|
26
|
prefix |
|
27
|
) |
|
28
|
|
|
29
|
const { |
|
30
|
offset, |
|
31
|
sales_channel_id, |
|
32
|
created_at, |
|
33
|
updated_at, |
|
34
|
// fulfillment_status, |
|
35
|
// payment_status, |
|
36
|
region_id, |
|
37
|
q, |
|
38
|
order, |
|
39
|
// total, |
|
40
|
} = queryObject |
|
41
|
|
|
42
|
const searchParams: HttpTypes.AdminOrderFilters = { |
|
43
|
limit: pageSize, |
|
44
|
offset: offset ? Number(offset) : 0, |
|
45
|
sales_channel_id: sales_channel_id?.split(","), |
|
46
|
// fulfillment_status: fulfillment_status?.split(","), |
|
47
|
// payment_status: payment_status?.split(","), |
|
48
|
created_at: created_at ? JSON.parse(created_at) : undefined, |
|
49
|
updated_at: updated_at ? JSON.parse(updated_at) : undefined, |
|
50
|
region_id: region_id?.split(","), |
|
51
|
order: order ? order : "-created_at", |
|
52
|
q, |
|
53
|
// total: total ? JSON.parse(total) : undefined, |
|
54
|
} |
|
55
|
|
|
56
|
return { |
|
57
|
searchParams, |
|
58
|
raw: queryObject, |
|
59
|
} |
|
60
|
} |