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:
5
.changeset/social-donuts-pay.md
Normal file
5
.changeset/social-donuts-pay.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/dashboard": patch
|
||||
---
|
||||
|
||||
fix(dashboard): use order version 1 for the initial node of activity timeline
|
||||
5
.changeset/tiny-bottles-turn.md
Normal file
5
.changeset/tiny-bottles-turn.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
fix(medusa): preprocess `version` as number in AdminGetOrdersOrderParams validator
|
||||
@@ -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,
|
||||
|
||||
@@ -9,7 +9,15 @@ import {
|
||||
|
||||
export const AdminGetOrdersOrderParams = createSelectParams().merge(
|
||||
z.object({
|
||||
version: z.number().optional(),
|
||||
version: z.preprocess(
|
||||
(val) => {
|
||||
if (val && typeof val === "string") {
|
||||
return parseInt(val)
|
||||
}
|
||||
return val
|
||||
},
|
||||
z.number().optional()
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user