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:
5
.changeset/stale-adults-tease.md
Normal file
5
.changeset/stale-adults-tease.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/admin-ui": patch
|
||||
---
|
||||
|
||||
fix(admin): Fix fulfilment creation
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user