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
+5
View 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("inventoryService") &&
isFeatureEnabled("stockLocationService") isFeatureEnabled("stockLocationService")
const [quantities, setQuantities] = useState<Record<string, number>>( const [quantities, setQuantities] = useState<Record<string, number>>(
"object" in orderToFulfill "items" in orderToFulfill
? (orderToFulfill as Order).items.reduce((acc, next) => { ? (orderToFulfill as Order).items.reduce((acc, next) => {
return { return {
...acc, ...acc,
@@ -57,6 +57,7 @@ const CreateFulfillmentModal: React.FC<CreateFulfillmentModalProps> = ({
}, {}) }, {})
: {} : {}
) )
console.log({ orderToFulfill })
const [noNotis, setNoNotis] = useState(false) const [noNotis, setNoNotis] = useState(false)
const [errors, setErrors] = useState({}) const [errors, setErrors] = useState({})
const [locationSelectValue, setLocationSelectValue] = useState<{ const [locationSelectValue, setLocationSelectValue] = useState<{
@@ -67,17 +68,8 @@ const CreateFulfillmentModal: React.FC<CreateFulfillmentModalProps> = ({
{ key: "", value: "" }, { 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( const { stock_locations, refetch } = useAdminStockLocations(
filterableFields, {},
{ {
enabled: isLocationFulfillmentEnabled, enabled: isLocationFulfillmentEnabled,
} }
@@ -106,15 +106,23 @@ const FulfillmentLine = ({
(locationId && (locationId &&
(!availableQuantity || quantities[item.id] < availableQuantity)) (!availableQuantity || quantities[item.id] < availableQuantity))
console.log({
validQuantity,
locationId,
availableQuantity,
quantities,
itemId: item.id,
})
React.useEffect(() => { React.useEffect(() => {
setErrors((errors) => { setErrors((errors) => {
if (validQuantity) { if (validQuantity) {
delete errors[item.id] delete errors[item.id]
return { errors } return errors
} }
errors[item.id] = "Quantity is not valid" errors[item.id] = "Quantity is not valid"
return { errors } return errors
}) })
}, [validQuantity, setErrors, item.id]) }, [validQuantity, setErrors, item.id])