Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboard,types): split damaged activity from received #8859

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/admin-next/dashboard/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,12 @@
"inboundShippingHint": "Choose which method you want to use.",
"returnableQuantityLabel": "Returnable quantity",
"refundableAmountLabel": "Refundable amount",
"returnRequestedInfo": "{{requestedItemsCount}}x item return requested",
"returnReceivedInfo": "{{requestedItemsCount}}x item return received",
"returnRequestedInfo": "{{requestedItemsCount}}x items return requested",
"returnReceivedInfo": "{{requestedItemsCount}}x items return received",
"itemReceived": "Items received",
"returnRequested": "Return requested",
"damagedItemReceived": "Damaged items received",
"damagedItemsReturned": "{{quantity}}x Damaged items returned",
Copy link
Contributor

@fPolic fPolic Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion/nit: can "Damaged" be lower first letter on L:932, it looks a bit off next to the return received line

"activeChangeError": "There is an active order change in progress on this order. Please finish or discard the change first.",
"cancel": {
"title": "Cancel Return",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function ActivityItems(props: ActivityItemsProps) {
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
autoFocus={false}
className="focus-visible:outline-none"
>
<Text size="small" leading="compact" weight="plus">
{title}
Expand All @@ -53,7 +54,7 @@ function ActivityItems(props: ActivityItemsProps) {
<Popover.Content
align="center"
side="top"
className="bg-ui-bg-component p-0 max-w-[200px]"
className="bg-ui-bg-component p-0 max-w-[200px] focus-visible:outline-none"
>
<div className="flex flex-col">
{!!itemsToSend?.length && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
import { getTotalCaptured } from "../../../../../lib/payment"
import { getReturnableQuantity } from "../../../../../lib/rma"
import { CopyPaymentLink } from "../copy-payment-link/copy-payment-link"
import ReturnInfoPopover from "./return-info-popover"

type OrderSummarySectionProps = {
order: AdminOrder
Expand Down Expand Up @@ -565,26 +566,17 @@ const CostBreakdown = ({ order }: { order: AdminOrder }) => {
)
}

const ReturnBreakdown = ({
const ReturnBreakdownWithDamages = ({
orderReturn,
itemId,
}: {
orderReturn: AdminReturn
itemId: string
}) => {
const { t } = useTranslation()
const { getRelativeDate } = useDate()

if (
!["requested", "received", "partially_received"].includes(
orderReturn.status || ""
)
) {
return null
}

const isRequested = orderReturn.status === "requested"
const item = orderReturn?.items?.find((ri) => ri.item_id === itemId)
const damagedQuantity = item?.damaged_quantity || 0

return (
item && (
Expand All @@ -594,16 +586,10 @@ const ReturnBreakdown = ({
>
<div className="flex items-center gap-2">
<ArrowDownRightMini className="text-ui-fg-muted" />
<Text>
{t(
`orders.returns.${
isRequested ? "returnRequestedInfo" : "returnReceivedInfo"
}`,
{
requestedItemsCount:
item?.[isRequested ? "quantity" : "received_quantity"],
}
)}
<Text size="small">
{t(`orders.returns.damagedItemsReturned`, {
quantity: damagedQuantity,
})}
</Text>

{item?.note && (
Expand All @@ -623,18 +609,108 @@ const ReturnBreakdown = ({
)}
</div>

{orderReturn && (
<Text size="small" leading="compact" className="text-ui-fg-muted">
{getRelativeDate(
isRequested ? orderReturn.created_at : orderReturn.received_at
)}
</Text>
)}
<Text size="small" leading="compact" className="text-ui-fg-muted">
{t(`orders.returns.damagedItemReceived`)}

<span className="ml-2">
<ReturnInfoPopover orderReturn={orderReturn} />
</span>
</Text>
</div>
)
)
}

const ReturnBreakdown = ({
orderReturn,
itemId,
}: {
orderReturn: AdminReturn
itemId: string
}) => {
const { t } = useTranslation()
const { getRelativeDate } = useDate()

if (
!["requested", "received", "partially_received"].includes(
orderReturn.status || ""
)
) {
return null
}

const isRequested = orderReturn.status === "requested"
const item = orderReturn?.items?.find((ri) => ri.item_id === itemId)
const damagedQuantity = item?.damaged_quantity || 0

return (
item && (
<>
{damagedQuantity > 0 && (
<ReturnBreakdownWithDamages
orderReturn={orderReturn}
itemId={itemId}
/>
)}
<div
key={item.id}
className="txt-compact-small-plus text-ui-fg-subtle bg-ui-bg-subtle flex flex-row justify-between gap-y-2 border-t-2 border-dotted px-6 py-4"
>
<div className="flex items-center gap-2">
<ArrowDownRightMini className="text-ui-fg-muted" />
<Text size="small">
{t(
`orders.returns.${
isRequested ? "returnRequestedInfo" : "returnReceivedInfo"
}`,
{
requestedItemsCount:
item?.[isRequested ? "quantity" : "received_quantity"],
}
)}
</Text>

{item?.note && (
<Tooltip content={item.note}>
<DocumentText className="text-ui-tag-neutral-icon ml-1 inline" />
</Tooltip>
)}

{item?.reason && (
<Badge
size="2xsmall"
className="cursor-default select-none capitalize"
rounded="full"
>
{item?.reason?.label}
</Badge>
)}
</div>

{orderReturn && isRequested && (
<Text size="small" leading="compact" className="text-ui-fg-muted">
{getRelativeDate(orderReturn.created_at)}
<span className="ml-2">
<ReturnInfoPopover orderReturn={orderReturn} />
</span>
</Text>
)}

{orderReturn && !isRequested && (
<Text size="small" leading="compact" className="text-ui-fg-muted">
{t(`orders.returns.itemReceived`)}

<span className="ml-2">
<ReturnInfoPopover orderReturn={orderReturn} />
</span>
</Text>
)}
</div>
</>
)
)
}

const ClaimBreakdown = ({
claim,
itemId,
Expand All @@ -657,7 +733,7 @@ const ClaimBreakdown = ({
<div className="flex items-center gap-2">
<ArrowDownRightMini className="text-ui-fg-muted" />

<Text>
<Text size="small">
{t(`orders.claims.outboundItemAdded`, {
itemsCount: items.reduce(
(acc, item) => (acc = acc + item.quantity),
Expand Down Expand Up @@ -696,7 +772,7 @@ const ExchangeBreakdown = ({
>
<div className="flex items-center gap-2">
<ArrowDownRightMini className="text-ui-fg-muted" />
<Text>
<Text size="small">
{t(`orders.exchanges.outboundItemAdded`, {
itemsCount: items.reduce(
(acc, item) => (acc = acc + item.quantity),
Expand All @@ -720,19 +796,39 @@ const Total = ({ order }: { order: AdminOrder }) => {
return (
<div className=" flex flex-col gap-y-2 px-6 py-4">
<div className="text-ui-fg-base flex items-center justify-between">
<Text className="text-ui-fg-subtle" size="small" leading="compact">
<Text
weight="plus"
className="text-ui-fg-subtle"
size="small"
leading="compact"
>
{t("fields.total")}
</Text>
<Text className="text-ui-fg-subtle" size="small" leading="compact">
<Text
weight="plus"
className="text-ui-fg-subtle"
size="small"
leading="compact"
>
{getStylizedAmount(order.total, order.currency_code)}
</Text>
</div>

<div className="text-ui-fg-base flex items-center justify-between">
<Text className="text-ui-fg-subtle" size="small" leading="compact">
<Text
weight="plus"
className="text-ui-fg-subtle"
size="small"
leading="compact"
>
{t("fields.paidTotal")}
</Text>
<Text className="text-ui-fg-subtle" size="small" leading="compact">
<Text
weight="plus"
className="text-ui-fg-subtle"
size="small"
leading="compact"
>
{getStylizedAmount(
getTotalCaptured(order.payment_collections || []),
order.currency_code
Expand All @@ -745,13 +841,15 @@ const Total = ({ order }: { order: AdminOrder }) => {
className="text-ui-fg-subtle text-semibold"
size="small"
leading="compact"
weight="plus"
>
{t("orders.returns.outstandingAmount")}
</Text>
<Text
className="text-ui-fg-subtle text-bold"
size="small"
leading="compact"
weight="plus"
>
{getStylizedAmount(
order.summary.pending_difference || 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { InformationCircleSolid } from "@medusajs/icons"
import { AdminReturn } from "@medusajs/types"
import { Badge, Popover, Text } from "@medusajs/ui"
import { useState } from "react"
import { useTranslation } from "react-i18next"
import { formatDate } from "../../../../../components/common/date"

type ReturnInfoPopoverProps = {
orderReturn: AdminReturn
}

function ReturnInfoPopover({ orderReturn }: ReturnInfoPopoverProps) {
const { t } = useTranslation()
const [open, setOpen] = useState(false)

const handleMouseEnter = () => {
setOpen(true)
}

const handleMouseLeave = () => {
setOpen(false)
}

if (typeof orderReturn !== "object") {
return
}

return (
<Popover open={open}>
<Popover.Trigger
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
autoFocus={false}
className="focus-visible:outline-none align-sub"
>
<InformationCircleSolid />
</Popover.Trigger>

<Popover.Content
align="center"
side="top"
className="bg-ui-bg-component focus-visible:outline-none p-2"
>
<div className="flex flex-col">
<Badge size="2xsmall" className="mb-2" rounded="full">
#{orderReturn.id.replace("return_", "")}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: can we keep the same number of characters consistent across the page so users can easily identifies the same return

</Badge>

<Text size="xsmall">
<span className="text-ui-fg-subtle">
{t(`orders.returns.returnRequested`)}
</span>
{" · "}
{formatDate(orderReturn.requested_at)}
</Text>

<Text size="xsmall">
<span className="text-ui-fg-subtle">
{t(`orders.returns.itemReceived`)}
</span>
{" · "}
{formatDate(orderReturn.received_at)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: add fallback to "-" if for some reason this is null

</Text>
</div>
</Popover.Content>
</Popover>
)
}

export default ReturnInfoPopover
1 change: 1 addition & 0 deletions packages/core/types/src/http/return/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface BaseReturnItem {
id: string
quantity: number
received_quantity: number
damaged_quantity: number
reason_id?: string
note?: string
item_id: string
Expand Down
Loading