|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { useQueryParams } from "../../use-query-params" |
|
3
|
|
|
4
|
type UseCustomerTableQueryProps = { |
|
5
|
prefix?: string |
|
6
|
pageSize?: number |
|
7
|
} |
|
8
|
|
|
9
|
export const useCustomerTableQuery = ({ |
|
10
|
prefix, |
|
11
|
pageSize = 20, |
|
12
|
}: UseCustomerTableQueryProps) => { |
|
13
|
const queryObject = useQueryParams( |
|
14
|
[ |
|
15
|
"offset", |
|
16
|
"q", |
|
17
|
"has_account", |
|
18
|
"groups", |
|
19
|
"order", |
|
20
|
"created_at", |
|
21
|
"updated_at", |
|
22
|
], |
|
23
|
prefix |
|
24
|
) |
|
25
|
|
|
26
|
const { offset, groups, created_at, updated_at, has_account, q, order } = |
|
27
|
queryObject |
|
28
|
|
|
29
|
const searchParams: HttpTypes.AdminCustomerFilters = { |
|
30
|
limit: pageSize, |
|
31
|
offset: offset ? Number(offset) : 0, |
|
32
|
groups: groups?.split(","), |
|
33
|
has_account: has_account ? has_account === "true" : undefined, |
|
34
|
order, |
|
35
|
created_at: created_at ? JSON.parse(created_at) : undefined, |
|
36
|
updated_at: updated_at ? JSON.parse(updated_at) : undefined, |
|
37
|
q, |
|
38
|
} |
|
39
|
|
|
40
|
return { |
|
41
|
searchParams, |
|
42
|
raw: queryObject, |
|
43
|
} |
|
44
|
} |