feat(dashboard,types,js-sdk,ui): Tax Regions UI (#7935)
This commit is contained in:
committed by
GitHub
parent
75e7047243
commit
046a34bdfc
@@ -1,3 +1,4 @@
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes, PaginatedResponse } from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
@@ -25,7 +26,7 @@ export const useCustomerGroup = (
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||
Error,
|
||||
FetchError,
|
||||
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||
QueryKey
|
||||
>,
|
||||
@@ -46,7 +47,7 @@ export const useCustomerGroups = (
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
PaginatedResponse<{ customer_groups: HttpTypes.AdminCustomerGroup[] }>,
|
||||
Error,
|
||||
FetchError,
|
||||
PaginatedResponse<{ customer_groups: HttpTypes.AdminCustomerGroup[] }>,
|
||||
QueryKey
|
||||
>,
|
||||
@@ -65,7 +66,7 @@ export const useCustomerGroups = (
|
||||
export const useCreateCustomerGroup = (
|
||||
options?: UseMutationOptions<
|
||||
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||
Error,
|
||||
FetchError,
|
||||
z.infer<typeof CreateCustomerGroupSchema>
|
||||
>
|
||||
) => {
|
||||
@@ -85,7 +86,7 @@ export const useUpdateCustomerGroup = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||
Error,
|
||||
FetchError,
|
||||
z.infer<typeof EditCustomerGroupSchema>
|
||||
>
|
||||
) => {
|
||||
@@ -109,7 +110,7 @@ export const useDeleteCustomerGroup = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
{ id: string; object: "customer-group"; deleted: boolean },
|
||||
Error,
|
||||
FetchError,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
@@ -133,7 +134,7 @@ export const useAddCustomersToGroup = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||
Error,
|
||||
FetchError,
|
||||
{ customer_ids: string[] }
|
||||
>
|
||||
) => {
|
||||
@@ -160,7 +161,7 @@ export const useRemoveCustomersFromGroup = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||
Error,
|
||||
FetchError,
|
||||
{ customer_ids: string[] }
|
||||
>
|
||||
) => {
|
||||
|
||||
31
packages/admin-next/dashboard/src/hooks/api/index.ts
Normal file
31
packages/admin-next/dashboard/src/hooks/api/index.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export * from "./api-keys"
|
||||
export * from "./auth"
|
||||
export * from "./campaigns"
|
||||
export * from "./categories"
|
||||
export * from "./collections"
|
||||
export * from "./currencies"
|
||||
export * from "./customer-groups"
|
||||
export * from "./customers"
|
||||
export * from "./fulfillment"
|
||||
export * from "./fulfillment-providers"
|
||||
export * from "./fulfillment-sets"
|
||||
export * from "./inventory"
|
||||
export * from "./invites"
|
||||
export * from "./orders"
|
||||
export * from "./payments"
|
||||
export * from "./price-lists"
|
||||
export * from "./product-types"
|
||||
export * from "./products"
|
||||
export * from "./promotions"
|
||||
export * from "./regions"
|
||||
export * from "./reservations"
|
||||
export * from "./sales-channels"
|
||||
export * from "./shipping-options"
|
||||
export * from "./shipping-profiles"
|
||||
export * from "./stock-locations"
|
||||
export * from "./store"
|
||||
export * from "./tags"
|
||||
export * from "./tax-rates"
|
||||
export * from "./tax-regions"
|
||||
export * from "./users"
|
||||
export * from "./workflow-executions"
|
||||
@@ -1,7 +1,8 @@
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { QueryKey, UseQueryOptions, useQuery } from "@tanstack/react-query"
|
||||
import { client } from "../../lib/client"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { TagsListRes, TagRes } from "../../types/api-responses"
|
||||
|
||||
const TAGS_QUERY_KEY = "tags" as const
|
||||
export const tagsQueryKeys = queryKeysFactory(TAGS_QUERY_KEY)
|
||||
@@ -9,13 +10,18 @@ export const tagsQueryKeys = queryKeysFactory(TAGS_QUERY_KEY)
|
||||
export const useTag = (
|
||||
id: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<TagRes, Error, TagRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminProductTagResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminProductTagResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryKey: tagsQueryKeys.detail(id),
|
||||
queryFn: async () => client.tags.retrieve(id),
|
||||
queryFn: async () => sdk.admin.productTag.retrieve(id),
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -23,15 +29,20 @@ export const useTag = (
|
||||
}
|
||||
|
||||
export const useTags = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminProductTagListParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<TagsListRes, Error, TagsListRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminProductTagListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminProductTagListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryKey: tagsQueryKeys.list(query),
|
||||
queryFn: async () => client.tags.list(query),
|
||||
queryFn: async () => sdk.admin.productTag.list(query),
|
||||
...options,
|
||||
})
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { taxRegionsQueryKeys } from "./tax-regions"
|
||||
|
||||
const TAX_RATES_QUERY_KEY = "tax_rates" as const
|
||||
export const taxRatesQueryKeys = queryKeysFactory(TAX_RATES_QUERY_KEY)
|
||||
@@ -19,7 +21,7 @@ export const useTaxRate = (
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminTaxRateResponse,
|
||||
Error,
|
||||
FetchError,
|
||||
HttpTypes.AdminTaxRateResponse,
|
||||
QueryKey
|
||||
>,
|
||||
@@ -72,6 +74,8 @@ export const useUpdateTaxRate = (
|
||||
queryKey: taxRatesQueryKeys.detail(id),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.details() })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -81,7 +85,7 @@ export const useUpdateTaxRate = (
|
||||
export const useCreateTaxRate = (
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminTaxRateResponse,
|
||||
Error,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreateTaxRate
|
||||
>
|
||||
) => {
|
||||
@@ -89,6 +93,9 @@ export const useCreateTaxRate = (
|
||||
mutationFn: (payload) => sdk.admin.taxRate.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() })
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.details() })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -111,6 +118,8 @@ export const useDeleteTaxRate = (
|
||||
queryKey: taxRatesQueryKeys.detail(id),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.details() })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
@@ -15,11 +16,11 @@ export const taxRegionsQueryKeys = queryKeysFactory(TAX_REGIONS_QUERY_KEY)
|
||||
|
||||
export const useTaxRegion = (
|
||||
id: string,
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminTaxRegionParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminTaxRegionResponse,
|
||||
Error,
|
||||
FetchError,
|
||||
HttpTypes.AdminTaxRegionResponse,
|
||||
QueryKey
|
||||
>,
|
||||
@@ -36,11 +37,11 @@ export const useTaxRegion = (
|
||||
}
|
||||
|
||||
export const useTaxRegions = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminTaxRegionListParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminTaxRegionListResponse,
|
||||
Error,
|
||||
FetchError,
|
||||
HttpTypes.AdminTaxRegionListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
@@ -59,7 +60,7 @@ export const useTaxRegions = (
|
||||
export const useCreateTaxRegion = (
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminTaxRegionResponse,
|
||||
Error,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreateTaxRegion
|
||||
>
|
||||
) => {
|
||||
@@ -77,7 +78,7 @@ export const useDeleteTaxRegion = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminTaxRegionDeleteResponse,
|
||||
Error,
|
||||
FetchError,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
@@ -89,6 +90,9 @@ export const useDeleteTaxRegion = (
|
||||
queryKey: taxRegionsQueryKeys.detail(id),
|
||||
})
|
||||
|
||||
// Invalidate all detail queries, as the deleted tax region may have been a sublevel region
|
||||
queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.details() })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
|
||||
Reference in New Issue
Block a user