feat(dashboard,types,js-sdk,ui): Add missing Price List features (#7856)
**What** - Adds missing features to Price List domain - Adds `StackedFocusModal` and `StackedDrawer` components that should replace SplitView across the project. - Add Footer to FocusModal - Adds missing js-sdk functions and types **Note** The DatePickers in the PriceLists forms do not work as intended atm. The component is broken, and needs to be fixed. I am working on a fix, but choose to move that work into a separate branch, to prevent this PR from getting bigger then it already is. Will update once the fixes have been merged.
This commit is contained in:
committed by
GitHub
parent
9f3998393b
commit
c1740218e9
@@ -1,3 +1,4 @@
|
||||
import { HttpTypes, PaginatedResponse } from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
UseMutationOptions,
|
||||
@@ -12,7 +13,6 @@ import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { CreateCustomerGroupSchema } from "../../routes/customer-groups/customer-group-create/components/create-customer-group-form"
|
||||
import { EditCustomerGroupSchema } from "../../routes/customer-groups/customer-group-edit/components/edit-customer-group-form"
|
||||
import { customersQueryKeys } from "./customers"
|
||||
import { HttpTypes, PaginatedResponse } from "@medusajs/types"
|
||||
|
||||
const CUSTOMER_GROUPS_QUERY_KEY = "customer_groups" as const
|
||||
export const customerGroupsQueryKeys = queryKeysFactory(
|
||||
@@ -45,9 +45,9 @@ export const useCustomerGroups = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
PaginatedResponse<HttpTypes.AdminCustomerGroup[]>,
|
||||
PaginatedResponse<{ customer_groups: HttpTypes.AdminCustomerGroup[] }>,
|
||||
Error,
|
||||
PaginatedResponse<HttpTypes.AdminCustomerGroup[]>,
|
||||
PaginatedResponse<{ customer_groups: HttpTypes.AdminCustomerGroup[] }>,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
|
||||
@@ -7,20 +7,10 @@ import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
} from "@tanstack/react-query"
|
||||
import { client, sdk } from "../../lib/client"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import {
|
||||
AddPriceListPricesReq,
|
||||
CreatePriceListReq,
|
||||
DeletePriceListPricesReq,
|
||||
UpdatePriceListReq,
|
||||
} from "../../types/api-payloads"
|
||||
import {
|
||||
PriceListDeleteRes,
|
||||
PriceListListRes,
|
||||
PriceListRes,
|
||||
} from "../../types/api-responses"
|
||||
import { customerGroupsQueryKeys } from "./customer-groups"
|
||||
import { productsQueryKeys } from "./products"
|
||||
|
||||
const PRICE_LISTS_QUERY_KEY = "price-lists" as const
|
||||
@@ -28,14 +18,19 @@ export const priceListsQueryKeys = queryKeysFactory(PRICE_LISTS_QUERY_KEY)
|
||||
|
||||
export const usePriceList = (
|
||||
id: string,
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminPriceListListParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<PriceListRes, Error, PriceListRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminPriceListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminPriceListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.priceLists.retrieve(id, query),
|
||||
queryFn: () => sdk.admin.priceList.retrieve(id, query),
|
||||
queryKey: priceListsQueryKeys.detail(id),
|
||||
...options,
|
||||
})
|
||||
@@ -44,14 +39,19 @@ export const usePriceList = (
|
||||
}
|
||||
|
||||
export const usePriceLists = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminPriceListListParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<PriceListListRes, Error, PriceListListRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminPriceListListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminPriceListListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.priceLists.list(query),
|
||||
queryFn: () => sdk.admin.priceList.list(query),
|
||||
queryKey: priceListsQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
@@ -60,13 +60,20 @@ export const usePriceLists = (
|
||||
}
|
||||
|
||||
export const useCreatePriceList = (
|
||||
options?: UseMutationOptions<PriceListRes, Error, CreatePriceListReq>
|
||||
query?: HttpTypes.AdminPriceListParams,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPriceListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreatePriceList
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.priceLists.create(payload),
|
||||
mutationFn: (payload) => sdk.admin.priceList.create(payload, query),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.list() })
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: customerGroupsQueryKeys.all })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -75,16 +82,23 @@ export const useCreatePriceList = (
|
||||
|
||||
export const useUpdatePriceList = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<PriceListRes, Error, UpdatePriceListReq>
|
||||
query?: HttpTypes.AdminPriceListParams,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPriceListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminUpdatePriceList
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.priceLists.update(id, payload),
|
||||
mutationFn: (payload) => sdk.admin.priceList.update(id, payload, query),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.list() })
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: priceListsQueryKeys.detail(id),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: customerGroupsQueryKeys.all })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -93,10 +107,14 @@ export const useUpdatePriceList = (
|
||||
|
||||
export const useDeletePriceList = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<PriceListDeleteRes, Error, void>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPriceListDeleteResponse,
|
||||
FetchError,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.priceLists.delete(id),
|
||||
mutationFn: () => sdk.admin.priceList.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.list() })
|
||||
|
||||
@@ -106,17 +124,22 @@ export const useDeletePriceList = (
|
||||
})
|
||||
}
|
||||
|
||||
export const usePriceListAddPrices = (
|
||||
export const useBatchPriceListPrices = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<PriceListRes, Error, AddPriceListPricesReq>
|
||||
query?: HttpTypes.AdminPriceListParams,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPriceListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminBatchPriceListPrice
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.priceLists.addPrices(id, payload),
|
||||
mutationFn: (payload) =>
|
||||
sdk.admin.priceList.batchPrices(id, payload, query),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: priceListsQueryKeys.detail(id),
|
||||
})
|
||||
queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
@@ -125,24 +148,6 @@ export const usePriceListAddPrices = (
|
||||
})
|
||||
}
|
||||
|
||||
export const usePriceListRemovePrices = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<PriceListRes, Error, DeletePriceListPricesReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.priceLists.removePrices(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: priceListsQueryKeys.detail(id),
|
||||
})
|
||||
queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.lists() })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const usePriceListLinkProducts = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
|
||||
@@ -6,23 +6,46 @@ import {
|
||||
useQuery,
|
||||
} from "@tanstack/react-query"
|
||||
|
||||
import { client } from "../../lib/client"
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { UpdateStoreReq } from "../../types/api-payloads"
|
||||
import { StoreRes } from "../../types/api-responses"
|
||||
|
||||
const STORE_QUERY_KEY = "store" as const
|
||||
export const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY)
|
||||
|
||||
/**
|
||||
* Workaround to keep the V1 version of retrieving the store.
|
||||
*/
|
||||
async function retrieveActiveStore(
|
||||
query?: HttpTypes.AdminStoreParams
|
||||
): Promise<HttpTypes.AdminStoreResponse> {
|
||||
const response = await sdk.admin.store.list(query)
|
||||
|
||||
const activeStore = response.stores?.[0]
|
||||
|
||||
if (!activeStore) {
|
||||
throw new FetchError("No active store found", "Not Found", 404)
|
||||
}
|
||||
|
||||
return { store: activeStore }
|
||||
}
|
||||
|
||||
export const useStore = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<StoreRes, Error, StoreRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminStoreResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminStoreResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.stores.retrieve(),
|
||||
queryFn: () => retrieveActiveStore(query),
|
||||
queryKey: storeQueryKeys.details(),
|
||||
...options,
|
||||
})
|
||||
@@ -35,10 +58,14 @@ export const useStore = (
|
||||
|
||||
export const useUpdateStore = (
|
||||
id: string,
|
||||
options?: MutationOptions<StoreRes, Error, UpdateStoreReq>
|
||||
options?: MutationOptions<
|
||||
HttpTypes.AdminStoreResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminUpdateStore
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.stores.update(id, payload),
|
||||
mutationFn: (payload) => sdk.admin.store.update(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: storeQueryKeys.details() })
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
|
||||
Reference in New Issue
Block a user