fix(dashboard): fix customer details page crashing when their order is refunded (#14413)

1. Fix the customer details page crashing when a customer's order is fully refunded. The error was originating from the payment collections of the order not being retrieved, since they're being used to calculate the refunded total.
2. Other: fix country not showing as well due to incorrectly trying to retrieving and access the shipping address's country

Closes #14409
This commit is contained in:
Shahed Nasser
2025-12-29 11:38:21 +02:00
committed by GitHub
parent 89a0adc612
commit 4ac7b72d10
4 changed files with 16 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---
fix(dashboard): fix customer details page crashing when their order is refunded

View File

@@ -3,10 +3,14 @@ import ReactCountryFlag from "react-country-flag"
import { PlaceholderCell } from "../../common/placeholder-cell" import { PlaceholderCell } from "../../common/placeholder-cell"
import { HttpTypes } from "@medusajs/types" import { HttpTypes } from "@medusajs/types"
type Country = Omit<HttpTypes.AdminRegionCountry, "id"> & {
id?: string
}
export const CountryCell = ({ export const CountryCell = ({
country, country,
}: { }: {
country?: HttpTypes.AdminRegionCountry | null country?: Country | null
}) => { }) => {
if (!country) { if (!country) {
return <PlaceholderCell /> return <PlaceholderCell />

View File

@@ -9,6 +9,7 @@ import {
DateCell, DateCell,
DateHeader, DateHeader,
} from "../../../components/table/table-cells/common/date-cell" } from "../../../components/table/table-cells/common/date-cell"
import { countries } from "../../../lib/data/countries"
import { CountryCell } from "../../../components/table/table-cells/order/country-cell" import { CountryCell } from "../../../components/table/table-cells/order/country-cell"
import { import {
CustomerCell, CustomerCell,
@@ -101,10 +102,10 @@ export const useOrderTableColumns = (props: UseOrderTableColumnsProps) => {
const isFullyRefunded = row.original.payment_status === "refunded" const isFullyRefunded = row.original.payment_status === "refunded"
const total = !isFullyRefunded const total = !isFullyRefunded
? getValue() ? getValue()
: row.original.payment_collections.reduce( : row.original.payment_collections?.reduce(
(acc, payCol) => acc + (payCol.refunded_amount ?? 0), (acc, payCol) => acc + (payCol.refunded_amount ?? 0),
0 0
) ) || 0
const currencyCode = row.original.currency_code const currencyCode = row.original.currency_code
return ( return (
@@ -121,7 +122,8 @@ export const useOrderTableColumns = (props: UseOrderTableColumnsProps) => {
columnHelper.display({ columnHelper.display({
id: "actions", id: "actions",
cell: ({ row }) => { cell: ({ row }) => {
const country = row.original.shipping_address?.country const countryCode = row.original.shipping_address?.country_code
const country = countries.find((c) => c.iso_2 === countryCode)
return <CountryCell country={country} /> return <CountryCell country={country} />
}, },

View File

@@ -19,7 +19,7 @@ type CustomerGeneralSectionProps = {
const PREFIX = "cusord" const PREFIX = "cusord"
const PAGE_SIZE = 10 const PAGE_SIZE = 10
const DEFAULT_RELATIONS = "*customer,*items,*sales_channel" const DEFAULT_RELATIONS = "*customer,*items,*sales_channel,payment_collections.refunded_amount,+shipping_address.country_code"
const DEFAULT_FIELDS = const DEFAULT_FIELDS =
"id,status,display_id,created_at,email,fulfillment_status,payment_status,total,currency_code" "id,status,display_id,created_at,email,fulfillment_status,payment_status,total,currency_code"