feat(inventory,dashboard,types,core-flows,js-sdk,medusa): Improve inventory UX (#10630)
* feat(dashboard): Add UI for bulk editing inventory stock (#10556) * progress * cleanup types * add changeset * fix 0 values * format schema * add delete event and allow copy/pasting enabled for some fields * add response types * add tests * work on fixing setValue behaviour * cleanup toggle logic * add loading state * format schema * add support for bidirectional actions in DataGrid and update Checkbox and RadioGroup * update lock * lint * fix 404 * address feedback * update cursor on bidirectional select
This commit is contained in:
committed by
GitHub
parent
c5915451b8
commit
bc22b81cdf
@@ -1,3 +1,4 @@
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
@@ -6,11 +7,11 @@ import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
} from "@tanstack/react-query"
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { variantsQueryKeys } from "./products"
|
||||
|
||||
const INVENTORY_ITEMS_QUERY_KEY = "inventory_items" as const
|
||||
export const inventoryItemsQueryKeys = queryKeysFactory(
|
||||
@@ -23,7 +24,7 @@ export const inventoryItemLevelsQueryKeys = queryKeysFactory(
|
||||
)
|
||||
|
||||
export const useInventoryItems = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminInventoryItemParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminInventoryItemListResponse,
|
||||
@@ -136,7 +137,7 @@ export const useDeleteInventoryItemLevel = (
|
||||
inventoryItemId: string,
|
||||
locationId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminInventoryItemDeleteResponse,
|
||||
HttpTypes.AdminInventoryLevelDeleteResponse,
|
||||
FetchError,
|
||||
void
|
||||
>
|
||||
@@ -210,17 +211,20 @@ export const useUpdateInventoryLevel = (
|
||||
})
|
||||
}
|
||||
|
||||
export const useBatchUpdateInventoryLevels = (
|
||||
export const useBatchInventoryItemLocationLevels = (
|
||||
inventoryItemId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminInventoryItemResponse,
|
||||
HttpTypes.AdminBatchInventoryItemLocationLevelsResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminBatchUpdateInventoryLevelLocation
|
||||
HttpTypes.AdminBatchInventoryItemLocationLevels
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: HttpTypes.AdminBatchUpdateInventoryLevelLocation) =>
|
||||
sdk.admin.inventoryItem.batchUpdateLevels(inventoryItemId, payload),
|
||||
mutationFn: (payload) =>
|
||||
sdk.admin.inventoryItem.batchInventoryItemLocationLevels(
|
||||
inventoryItemId,
|
||||
payload
|
||||
),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: inventoryItemsQueryKeys.lists(),
|
||||
@@ -236,3 +240,26 @@ export const useBatchUpdateInventoryLevels = (
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useBatchInventoryItemsLocationLevels = (
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminBatchInventoryItemsLocationLevelsResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminBatchInventoryItemsLocationLevels
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
sdk.admin.inventoryItem.batchInventoryItemsLocationLevels(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: inventoryItemsQueryKeys.all,
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: variantsQueryKeys.lists(),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -110,9 +110,14 @@ export const useProductVariant = (
|
||||
|
||||
export const useProductVariants = (
|
||||
productId: string,
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminProductVariantParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<any, FetchError, any, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminProductVariantListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminProductVariantListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
|
||||
Reference in New Issue
Block a user