fix(admin): Fix fulfilment creation (#3434)

* Remove error object nesting that stopped fulfilment creation

* Create stale-adults-tease.md

* Fix quantities object creation check

* Add some debug logs
This commit is contained in:
Rares Stefan
2023-03-10 14:41:03 +01:00
committed by GitHub
parent 54dcc1871c
commit f43f03badb
3 changed files with 18 additions and 13 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/admin-ui": patch
---
fix(admin): Fix fulfilment creation

View File

@@ -48,7 +48,7 @@ const CreateFulfillmentModal: React.FC<CreateFulfillmentModalProps> = ({
isFeatureEnabled("inventoryService") &&
isFeatureEnabled("stockLocationService")
const [quantities, setQuantities] = useState<Record<string, number>>(
"object" in orderToFulfill
"items" in orderToFulfill
? (orderToFulfill as Order).items.reduce((acc, next) => {
return {
...acc,
@@ -57,6 +57,7 @@ const CreateFulfillmentModal: React.FC<CreateFulfillmentModalProps> = ({
}, {})
: {}
)
console.log({ orderToFulfill })
const [noNotis, setNoNotis] = useState(false)
const [errors, setErrors] = useState({})
const [locationSelectValue, setLocationSelectValue] = useState<{
@@ -67,17 +68,8 @@ const CreateFulfillmentModal: React.FC<CreateFulfillmentModalProps> = ({
{ key: "", value: "" },
])
const salesChannelId =
"object" in orderToFulfill
? (orderToFulfill as Order).sales_channel_id
: (orderToFulfill as ClaimOrder | Swap)?.order?.sales_channel_id
const filterableFields: { sales_channel_id?: string } = {}
if (salesChannelId) {
filterableFields.sales_channel_id = salesChannelId
}
const { stock_locations, refetch } = useAdminStockLocations(
filterableFields,
{},
{
enabled: isLocationFulfillmentEnabled,
}

View File

@@ -106,15 +106,23 @@ const FulfillmentLine = ({
(locationId &&
(!availableQuantity || quantities[item.id] < availableQuantity))
console.log({
validQuantity,
locationId,
availableQuantity,
quantities,
itemId: item.id,
})
React.useEffect(() => {
setErrors((errors) => {
if (validQuantity) {
delete errors[item.id]
return { errors }
return errors
}
errors[item.id] = "Quantity is not valid"
return { errors }
return errors
})
}, [validQuantity, setErrors, item.id])