feat: Add tax regions table (#6983)

This commit is contained in:
Oli Juhl
2024-04-07 15:02:48 +02:00
committed by GitHub
parent 44bcde92c8
commit 31b07aea3d
69 changed files with 381 additions and 2923 deletions

View File

@@ -0,0 +1,53 @@
import { QueryKey, UseQueryOptions, useQuery } from "@tanstack/react-query"
import { client } from "../../lib/client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import {
AdminTaxRegionResponse,
AdminTaxRegionListResponse,
} from "@medusajs/types"
const TAX_REGIONS_QUERY_KEY = "tax_regions" as const
const taxRegionsQueryKeys = queryKeysFactory(TAX_REGIONS_QUERY_KEY)
export const useTaxRegion = (
id: string,
query?: Record<string, any>,
options?: Omit<
UseQueryOptions<
AdminTaxRegionResponse,
Error,
AdminTaxRegionResponse,
QueryKey
>,
"queryFn" | "queryKey"
>
) => {
const { data, ...rest } = useQuery({
queryKey: taxRegionsQueryKeys.detail(id),
queryFn: async () => client.taxes.retrieveTaxRegion(id, query),
...options,
})
return { ...data, ...rest }
}
export const useTaxRegions = (
query?: Record<string, any>,
options?: Omit<
UseQueryOptions<
AdminTaxRegionListResponse,
Error,
AdminTaxRegionListResponse,
QueryKey
>,
"queryFn" | "queryKey"
>
) => {
const { data, ...rest } = useQuery({
queryFn: () => client.taxes.listTaxRegions(query),
queryKey: taxRegionsQueryKeys.list(query),
...options,
})
return { ...data, ...rest }
}