fix(dashboard): order edit - display item quantity change correctly (#10078)
**What** - use a diff form change action details to display edit history
This commit is contained in:
1 parent
7aa990795c
commit
39e81d8d21
1 file changed
+10
-29
+10
-29
@@ -376,9 +376,7 @@ const useActivityItems = (order: AdminOrder): Activity[] => {
|
|||||||
: edit.status === "canceled"
|
: edit.status === "canceled"
|
||||||
? edit.canceled_at
|
? edit.canceled_at
|
||||||
: edit.created_at,
|
: edit.created_at,
|
||||||
children: isConfirmed ? (
|
children: isConfirmed ? <OrderEditBody edit={edit} /> : null,
|
||||||
<OrderEditBody edit={edit} itemsMap={itemsMap} />
|
|
||||||
) : null,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -839,18 +837,12 @@ const ExchangeBody = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const OrderEditBody = ({
|
const OrderEditBody = ({ edit }: { edit: AdminOrderChange }) => {
|
||||||
edit,
|
|
||||||
itemsMap,
|
|
||||||
}: {
|
|
||||||
edit: AdminOrderChange
|
|
||||||
itemsMap: Map<string, AdminOrderLineItem>
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const [itemsAdded, itemsRemoved] = useMemo(
|
const [itemsAdded, itemsRemoved] = useMemo(
|
||||||
() => countItemsChange(edit.actions, itemsMap),
|
() => countItemsChange(edit.actions),
|
||||||
[edit, itemsMap]
|
[edit]
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -873,10 +865,7 @@ const OrderEditBody = ({
|
|||||||
/**
|
/**
|
||||||
* Returns count of added and removed item quantity
|
* Returns count of added and removed item quantity
|
||||||
*/
|
*/
|
||||||
function countItemsChange(
|
function countItemsChange(actions: AdminOrderChange["actions"]) {
|
||||||
actions: AdminOrderChange["actions"],
|
|
||||||
itemsMap: Map<string, AdminOrderLineItem>
|
|
||||||
) {
|
|
||||||
let added = 0
|
let added = 0
|
||||||
let removed = 0
|
let removed = 0
|
||||||
|
|
||||||
@@ -885,20 +874,12 @@ function countItemsChange(
|
|||||||
added += action.details!.quantity as number
|
added += action.details!.quantity as number
|
||||||
}
|
}
|
||||||
if (action.action === "ITEM_UPDATE") {
|
if (action.action === "ITEM_UPDATE") {
|
||||||
const newQuantity = action.details!.quantity as number
|
const quantityDiff = action.details!.quantity_diff as number
|
||||||
const originalQuantity: number | undefined = itemsMap.get(
|
|
||||||
action.details!.reference_id as string
|
|
||||||
)?.quantity
|
|
||||||
|
|
||||||
if (typeof originalQuantity === "number") {
|
if (quantityDiff > 0) {
|
||||||
const diff = Math.abs(newQuantity - originalQuantity)
|
added += quantityDiff
|
||||||
|
} else {
|
||||||
if (newQuantity > originalQuantity) {
|
removed += Math.abs(quantityDiff)
|
||||||
added += diff
|
|
||||||
}
|
|
||||||
if (newQuantity < originalQuantity) {
|
|
||||||
removed += diff
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user