fix(admin-ui): Allow backorder update on variants (#4051)
This commit is contained in:
1 parent
4fb443c0ea
commit
2945769497
7 files changed
+32
-15
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/admin-ui": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(admin-ui): fix allow_backorder updates
|
||||||
+7
-5
@@ -17,7 +17,7 @@ import Modal from "../../molecules/modal"
|
|||||||
import { Option } from "../../../types/shared"
|
import { Option } from "../../../types/shared"
|
||||||
import { countries } from "../../../utils/countries"
|
import { countries } from "../../../utils/countries"
|
||||||
import { queryClient } from "../../../constants/query-client"
|
import { queryClient } from "../../../constants/query-client"
|
||||||
import { removeNullish } from "../../../utils/remove-nullish"
|
import { removeFalsy, removeNullish } from "../../../utils/remove-nullish"
|
||||||
import { useContext } from "react"
|
import { useContext } from "react"
|
||||||
import useEditProductActions from "../../../hooks/use-edit-product-actions"
|
import useEditProductActions from "../../../hooks/use-edit-product-actions"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
@@ -59,7 +59,7 @@ const EditVariantInventoryModal = ({ onClose, product, variant }: Props) => {
|
|||||||
delete data.upc
|
delete data.upc
|
||||||
delete data.allow_backorder
|
delete data.allow_backorder
|
||||||
|
|
||||||
return removeNullish({
|
return removeFalsy({
|
||||||
...updateDimensions,
|
...updateDimensions,
|
||||||
...updateCustoms,
|
...updateCustoms,
|
||||||
...data,
|
...data,
|
||||||
@@ -167,7 +167,8 @@ const EditVariantInventoryModal = ({ onClose, product, variant }: Props) => {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
onUpdateVariant(
|
onUpdateVariant(
|
||||||
variant.id,
|
variant.id,
|
||||||
removeNullish({
|
{
|
||||||
|
...removeNullish({
|
||||||
...dimensions,
|
...dimensions,
|
||||||
...customs,
|
...customs,
|
||||||
...stock,
|
...stock,
|
||||||
@@ -176,6 +177,7 @@ const EditVariantInventoryModal = ({ onClose, product, variant }: Props) => {
|
|||||||
upc,
|
upc,
|
||||||
allow_backorder,
|
allow_backorder,
|
||||||
}),
|
}),
|
||||||
|
},
|
||||||
() => {
|
() => {
|
||||||
refetch()
|
refetch()
|
||||||
if (shouldInvalidateCache) {
|
if (shouldInvalidateCache) {
|
||||||
@@ -287,7 +289,7 @@ export const getEditVariantDefaultValues = (
|
|||||||
upc: variant?.upc || null,
|
upc: variant?.upc || null,
|
||||||
inventory_quantity: null,
|
inventory_quantity: null,
|
||||||
manage_inventory: false,
|
manage_inventory: false,
|
||||||
allow_backorder: false,
|
allow_backorder: variant?.allow_backorder ?? false,
|
||||||
location_levels: null,
|
location_levels: null,
|
||||||
dimensions: {
|
dimensions: {
|
||||||
height: null,
|
height: null,
|
||||||
@@ -325,7 +327,7 @@ export const getEditVariantDefaultValues = (
|
|||||||
upc: variant?.upc || null,
|
upc: variant?.upc || null,
|
||||||
inventory_quantity: inventoryItem.inventory_quantity,
|
inventory_quantity: inventoryItem.inventory_quantity,
|
||||||
manage_inventory: !!inventoryItem,
|
manage_inventory: !!inventoryItem,
|
||||||
allow_backorder: inventoryItem.allow_backorder,
|
allow_backorder: !!variant?.allow_backorder,
|
||||||
location_levels: inventoryItem.location_levels,
|
location_levels: inventoryItem.location_levels,
|
||||||
dimensions: {
|
dimensions: {
|
||||||
height: inventoryItem.height,
|
height: inventoryItem.height,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useAdminCreateDiscount } from "medusa-react"
|
|||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import useNotification from "../../../hooks/use-notification"
|
import useNotification from "../../../hooks/use-notification"
|
||||||
import { getErrorMessage } from "../../../utils/error-messages"
|
import { getErrorMessage } from "../../../utils/error-messages"
|
||||||
import { removeNullish } from "../../../utils/remove-nullish"
|
import { removeFalsy } from "../../../utils/remove-nullish"
|
||||||
|
|
||||||
const useCopyPromotion = () => {
|
const useCopyPromotion = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
@@ -47,7 +47,7 @@ const useCopyPromotion = () => {
|
|||||||
if (promotion.rule.conditions) {
|
if (promotion.rule.conditions) {
|
||||||
copy.rule.conditions = promotion.rule.conditions.map((cond) => ({
|
copy.rule.conditions = promotion.rule.conditions.map((cond) => ({
|
||||||
operator: cond.operator,
|
operator: cond.operator,
|
||||||
...removeNullish({
|
...removeFalsy({
|
||||||
products: cond.products,
|
products: cond.products,
|
||||||
product_types: cond.product_types,
|
product_types: cond.product_types,
|
||||||
product_tags: cond.product_tags,
|
product_tags: cond.product_tags,
|
||||||
|
|||||||
+2
-2
@@ -7,7 +7,7 @@ import TrashIcon from "../../../../components/fundamentals/icons/trash-icon"
|
|||||||
import { getErrorMessage } from "../../../../utils/error-messages"
|
import { getErrorMessage } from "../../../../utils/error-messages"
|
||||||
import moment from "moment"
|
import moment from "moment"
|
||||||
import { parse } from "iso8601-duration"
|
import { parse } from "iso8601-duration"
|
||||||
import { removeNullish } from "../../../../utils/remove-nullish"
|
import { removeFalsy } from "../../../../utils/remove-nullish"
|
||||||
import { useAdminUpdateDiscount } from "medusa-react"
|
import { useAdminUpdateDiscount } from "medusa-react"
|
||||||
import useNotification from "../../../../hooks/use-notification"
|
import useNotification from "../../../../hooks/use-notification"
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ const useDiscountConfigurations = (discount: Discount) => {
|
|||||||
title: "Duration",
|
title: "Duration",
|
||||||
description: (
|
description: (
|
||||||
<CommonDescription
|
<CommonDescription
|
||||||
text={Object.entries(removeNullish(parse(discount.valid_duration)))
|
text={Object.entries(removeFalsy(parse(discount.valid_duration)))
|
||||||
.map(([key, value]) => `${value} ${key}`)
|
.map(([key, value]) => `${value} ${key}`)
|
||||||
.join(", ")}
|
.join(", ")}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import WarningCircleIcon from "../../../../components/fundamentals/icons/warning
|
|||||||
import { displayAmount } from "../../../../utils/prices"
|
import { displayAmount } from "../../../../utils/prices"
|
||||||
import { getAllReturnableItems } from "../utils/create-filtering"
|
import { getAllReturnableItems } from "../utils/create-filtering"
|
||||||
import { getErrorMessage } from "../../../../utils/error-messages"
|
import { getErrorMessage } from "../../../../utils/error-messages"
|
||||||
import { removeNullish } from "../../../../utils/remove-nullish"
|
import { removeFalsy } from "../../../../utils/remove-nullish"
|
||||||
import { useFeatureFlag } from "../../../../providers/feature-flag-provider"
|
import { useFeatureFlag } from "../../../../providers/feature-flag-provider"
|
||||||
import useNotification from "../../../../hooks/use-notification"
|
import useNotification from "../../../../hooks/use-notification"
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ const ReturnMenu: React.FC<ReturnMenuProps> = ({ order, onDismiss }) => {
|
|||||||
...value,
|
...value,
|
||||||
}
|
}
|
||||||
delete toSet.reason
|
delete toSet.reason
|
||||||
const clean = removeNullish(toSet)
|
const clean = removeFalsy(toSet)
|
||||||
return {
|
return {
|
||||||
item_id: key,
|
item_id: key,
|
||||||
...(clean as { quantity: number }),
|
...(clean as { quantity: number }),
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import {
|
|||||||
useAdminUpdateVariant,
|
useAdminUpdateVariant,
|
||||||
} from "medusa-react"
|
} from "medusa-react"
|
||||||
|
|
||||||
import { useNavigate } from "react-router-dom"
|
|
||||||
import { getErrorMessage } from "../utils/error-messages"
|
import { getErrorMessage } from "../utils/error-messages"
|
||||||
import { removeNullish } from "../utils/remove-nullish"
|
import { removeFalsy } from "../utils/remove-nullish"
|
||||||
import useImperativeDialog from "./use-imperative-dialog"
|
import useImperativeDialog from "./use-imperative-dialog"
|
||||||
|
import { useNavigate } from "react-router-dom"
|
||||||
import useNotification from "./use-notification"
|
import useNotification from "./use-notification"
|
||||||
|
|
||||||
const useEditProductActions = (productId: string) => {
|
const useEditProductActions = (productId: string) => {
|
||||||
@@ -74,8 +74,9 @@ const useEditProductActions = (productId: string) => {
|
|||||||
updateVariant.mutate(
|
updateVariant.mutate(
|
||||||
{
|
{
|
||||||
variant_id: id,
|
variant_id: id,
|
||||||
...removeNullish(payload),
|
...removeFalsy(payload),
|
||||||
manage_inventory: payload.manage_inventory,
|
manage_inventory: payload.manage_inventory,
|
||||||
|
allow_backorder: payload.allow_backorder,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -1,2 +1,11 @@
|
|||||||
export const removeNullish = (obj: Record<string, unknown>) =>
|
export const removeFalsy = (obj: Record<string, unknown>) =>
|
||||||
Object.entries(obj).reduce((a, [k, v]) => (v ? ((a[k] = v), a) : a), {})
|
Object.entries(obj).reduce((a, [k, v]) => (v ? ((a[k] = v), a) : a), {})
|
||||||
|
|
||||||
|
// == null is also true for undefined
|
||||||
|
export const removeNullish = (
|
||||||
|
obj: Record<string, unknown>
|
||||||
|
): Record<string, unknown> =>
|
||||||
|
Object.entries(obj).reduce(
|
||||||
|
(a, [k, v]) => (v != null ? ((a[k] = v), a) : a),
|
||||||
|
{}
|
||||||
|
)
|
||||||
Reference in new issue
Block a user