|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { Container, Heading } from "@medusajs/ui" |
|
3
|
import { keepPreviousData } from "@tanstack/react-query" |
|
4
|
import { useTranslation } from "react-i18next" |
|
5
|
import { useTaxRates } from "../../../../../hooks/api/tax-rates" |
|
6
|
import { useTaxRateTableQuery } from "../../../../../hooks/table/query/use-tax-rate-table-query" |
|
7
|
import { TaxOverrideTable } from "../../../common/components/tax-override-table" |
|
8
|
import { useTaxOverrideTable } from "../../../common/hooks/use-tax-override-table" |
|
9
|
|
|
10
|
type TaxRegionProvinceOverrideSectionProps = { |
|
11
|
taxRegion: HttpTypes.AdminTaxRegion |
|
12
|
} |
|
13
|
|
|
14
|
const PAGE_SIZE = 10 |
|
15
|
const PREFIX = "o" |
|
16
|
|
|
17
|
export const TaxRegionProvinceOverrideSection = ({ |
|
18
|
taxRegion, |
|
19
|
}: TaxRegionProvinceOverrideSectionProps) => { |
|
20
|
const { t } = useTranslation() |
|
21
|
|
|
22
|
const { searchParams, raw } = useTaxRateTableQuery({ |
|
23
|
pageSize: PAGE_SIZE, |
|
24
|
prefix: PREFIX, |
|
25
|
}) |
|
26
|
const { tax_rates, count, isPending, isError, error } = useTaxRates( |
|
27
|
{ |
|
28
|
...searchParams, |
|
29
|
tax_region_id: taxRegion.id, |
|
30
|
is_default: false, |
|
31
|
}, |
|
32
|
{ |
|
33
|
placeholderData: keepPreviousData, |
|
34
|
} |
|
35
|
) |
|
36
|
|
|
37
|
const { table } = useTaxOverrideTable({ |
|
38
|
count, |
|
39
|
data: tax_rates, |
|
40
|
pageSize: PAGE_SIZE, |
|
41
|
prefix: PREFIX, |
|
42
|
}) |
|
43
|
|
|
44
|
if (isError) { |
|
45
|
throw error |
|
46
|
} |
|
47
|
|
|
48
|
return ( |
|
49
|
<Container className="p-0"> |
|
50
|
<TaxOverrideTable |
|
51
|
isPending={isPending} |
|
52
|
table={table} |
|
53
|
count={count} |
|
54
|
action={{ |
|
55
|
label: t("actions.create"), |
|
56
|
to: "overrides/create", |
|
57
|
}} |
|
58
|
queryObject={raw} |
|
59
|
prefix={PREFIX} |
|
60
|
> |
|
61
|
<Heading level="h2">{t("taxRegions.taxOverrides.header")}</Heading> |
|
62
|
</TaxOverrideTable> |
|
63
|
</Container> |
|
64
|
) |
|
65
|
} |