Skip to content

Commit 5b655f6

Browse files
authored
feat(dashboard,medusa,types): improve order timeline UI (#14935)
* Update type * Use query for line items queryKeys * Fix line item versionj validator * Make next and previous rendering more generic to reuse for other change detail tooltips * Improve activity items with user who performed the action + items details for item edits * Fix condition * Add shipped by reference * Update type * Allow customer actor to be resolved * Add created by to active claims * Invert By order so it is the last element * Include return created by * Changeset
1 parent 5dbda9c commit 5b655f6

File tree

8 files changed

+347
-78
lines changed

8 files changed

+347
-78
lines changed

.changeset/easy-birds-teach.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@medusajs/dashboard": patch
3+
"@medusajs/types": patch
4+
"@medusajs/medusa": patch
5+
---
6+
7+
feat(dashboard,medusa,types): improve order timeline UI

packages/admin/dashboard/src/components/common/user-link/user-link.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Avatar, Text } from "@medusajs/ui"
22
import { Link } from "react-router-dom"
33
import { useUser } from "../../../hooks/api/users"
4+
import { useCustomer } from "../../../hooks/api/customers"
45

56
type UserLinkProps = {
67
id: string
@@ -24,7 +25,7 @@ export const UserLink = ({
2425
return (
2526
<Link
2627
to={link}
27-
className="flex items-center gap-x-2 w-fit transition-fg hover:text-ui-fg-subtle outline-none focus-visible:shadow-borders-focus rounded-md"
28+
className="transition-fg hover:text-ui-fg-subtle focus-visible:shadow-borders-focus flex w-fit items-center gap-x-2 rounded-md outline-none"
2829
>
2930
<Avatar size="2xsmall" fallback={fallback.toUpperCase()} />
3031
<Text size="small" leading="compact" weight="regular">
@@ -35,11 +36,20 @@ export const UserLink = ({
3536
}
3637

3738
export const By = ({ id }: { id: string }) => {
38-
const { user } = useUser(id) // todo: extend to support customers
39+
const isUser = id.startsWith("user_")
40+
const isCustomer = id.startsWith("cus_")
41+
if (!isUser && !isCustomer) {
42+
return null
43+
}
44+
45+
const { user } = useUser(id, undefined, { enabled: isUser }) // todo: extend to support customers
46+
const { customer } = useCustomer(id, undefined, { enabled: isCustomer })
47+
48+
const actor = isUser ? user : customer
3949

40-
if (!user) {
50+
if (!actor) {
4151
return null
4252
}
4353

44-
return <UserLink {...user} />
54+
return <UserLink {...actor} />
4555
}

packages/admin/dashboard/src/hooks/api/orders.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const ORDERS_QUERY_KEY = "orders" as const
1717
const _orderKeys = queryKeysFactory(ORDERS_QUERY_KEY) as TQueryKey<"orders"> & {
1818
preview: (orderId: string) => any
1919
changes: (orderId: string) => any
20-
lineItems: (orderId: string) => any
20+
lineItems: (orderId: string, query?: any) => any
2121
shippingOptions: (orderId: string) => any
2222
}
2323

@@ -29,8 +29,10 @@ _orderKeys.changes = function (id: string) {
2929
return [this.detail(id), "changes"]
3030
}
3131

32-
_orderKeys.lineItems = function (id: string) {
33-
return [this.detail(id), "lineItems"]
32+
_orderKeys.lineItems = function (id: string, query?: any) {
33+
return [this.detail(id), query ? { query } : undefined, "lineItems"].filter(
34+
(k) => !!k
35+
)
3436
}
3537

3638
_orderKeys.shippingOptions = function (id: string) {
@@ -189,7 +191,7 @@ export const useOrderLineItems = (
189191
) => {
190192
const { data, ...rest } = useQuery({
191193
queryFn: async () => sdk.admin.order.listLineItems(id, query),
192-
queryKey: ordersQueryKeys.lineItems(id),
194+
queryKey: ordersQueryKeys.lineItems(id, query),
193195
...options,
194196
})
195197

packages/admin/dashboard/src/routes/orders/order-detail/components/order-activity-section/change-details-tooltip.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { ReactNode, useState } from "react"
33
import { useTranslation } from "react-i18next"
44

55
type ChangeDetailsTooltipProps = {
6-
previous: ReactNode
7-
next: ReactNode
6+
previous?: ReactNode
7+
next?: ReactNode
88
title: string
99
}
1010

@@ -14,6 +14,7 @@ function ChangeDetailsTooltip(props: ChangeDetailsTooltipProps) {
1414
const previous = props.previous
1515
const next = props.next
1616
const title = props.title
17+
const showComparison = !!previous && !!next
1718

1819
const handleMouseEnter = () => {
1920
setOpen(true)
@@ -48,21 +49,25 @@ function ChangeDetailsTooltip(props: ChangeDetailsTooltipProps) {
4849
<div className="flex flex-col">
4950
{!!previous && (
5051
<div className="p-3">
51-
<div className="txt-compact-small-plus mb-1">
52-
{t("labels.from")}
53-
</div>
52+
{showComparison && (
53+
<div className="txt-compact-small-plus mb-1">
54+
{t("labels.from")}
55+
</div>
56+
)}
5457

55-
<p className="txt-compact-small text-ui-fg-subtle">{previous}</p>
58+
{previous}
5659
</div>
5760
)}
5861

5962
{!!next && (
6063
<div className="border-t-2 border-dotted p-3">
61-
<div className="txt-compact-small-plus mb-1">
62-
{t("labels.to")}
63-
</div>
64+
{showComparison && (
65+
<div className="txt-compact-small-plus mb-1">
66+
{t("labels.to")}
67+
</div>
68+
)}
6469

65-
<p className="txt-compact-small text-ui-fg-subtle">{next}</p>
70+
{next}
6671
</div>
6772
)}
6873
</div>

0 commit comments

Comments
 (0)