fix(dashboard): use order version 1 for the initial node of activity timeline (#13997)

* Add preprocess to version param to validate as number

* Add changeset

* Use the first version of the order as the starting node of activity to show correct total

* Add changeset

* Fetch first order version only if it's not the current version

* Remove conditionally rendered hook, use enable config
This commit is contained in:
Nicolas Gorga
2025-11-12 11:11:47 -03:00
committed by GitHub
parent efed4d7346
commit 4bbf0d2367
4 changed files with 38 additions and 10 deletions

View File

@@ -18,6 +18,7 @@ import { By } from "../../../../../components/common/user-link"
import {
useCancelOrderTransfer,
useCustomer,
useOrder,
useOrderChanges,
useOrderLineItems,
} from "../../../../../hooks/api"
@@ -123,6 +124,11 @@ type Activity = {
const useActivityItems = (order: AdminOrder): Activity[] => {
const { t } = useTranslation()
const { order: initialOrder = order } = useOrder(order.id, {
version: 1,
fields: "created_at,total,currency_code",
}, { enabled: order.version !== 1})
const { order_changes: orderChanges = [] } = useOrderChanges(order.id, {
change_type: [
"edit",
@@ -520,19 +526,23 @@ const useActivityItems = (order: AdminOrder): Activity[] => {
return new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()
})
const createdAt = {
title: t("orders.activity.events.placed.title"),
timestamp: order.created_at,
children: (
<Text size="small" className="text-ui-fg-subtle">
{getStylizedAmount(order.total, order.currency_code)}
</Text>
),
if (initialOrder.created_at) {
const createdAt = {
title: t("orders.activity.events.placed.title"),
timestamp: initialOrder.created_at,
children: (
<Text size="small" className="text-ui-fg-subtle">
{getStylizedAmount(initialOrder.total, initialOrder.currency_code)}
</Text>
),
}
sortedActivities.push(createdAt)
}
return [...sortedActivities, createdAt]
return [...sortedActivities]
}, [
order,
initialOrder,
payments,
returns,
exchanges,