Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/hooks/api/inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,18 @@ export const useBatchInventoryItemLocationLevels = (
>
) => {
return useMutation({
mutationFn: (payload) =>
sdk.admin.inventoryItem.batchInventoryItemLocationLevels(
mutationFn: (payload) => {
// force: true is required for admin batch endpoint to delete levels with stocked items
const payloadWithForce: HttpTypes.AdminBatchInventoryItemLocationLevels = {
...payload,
force: payload?.delete?.length ? true : payload.force,
}

return sdk.admin.inventoryItem.batchInventoryItemLocationLevels(
Comment on lines 229 to 230
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. How about force: !!payload?.delete?.length || payload.force
  2. IMO we don't need to use separate const, we could just
    return sdk.admin.inventoryItem.batchInventoryItemLocationLevels( inventoryItemId, {...payload, force: ....} )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, refactored

inventoryItemId,
payload
),
payloadWithForce
)
},
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: inventoryItemsQueryKeys.lists(),
Expand Down Expand Up @@ -258,8 +265,15 @@ export const useBatchInventoryItemsLocationLevels = (
>
) => {
return useMutation({
mutationFn: (payload) =>
sdk.admin.inventoryItem.batchInventoryItemsLocationLevels(payload),
mutationFn: (payload) => {
// force: true is required for admin batch endpoint to delete levels with stocked items
const payloadWithForce: HttpTypes.AdminBatchInventoryItemsLocationLevels = {
...payload,
force: payload?.delete?.length ? true : payload.force,
}

return sdk.admin.inventoryItem.batchInventoryItemsLocationLevels(payloadWithForce)
},
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: inventoryItemsQueryKeys.all,
Expand Down