Skip to content

Conversation

@bqst
Copy link
Contributor

@bqst bqst commented Jan 12, 2026

Summary

What — What changes are introduced in this PR?

This PR fixes an error that occurs when viewing customer detail pages with refunded orders. The error "Cannot read properties of undefined (reading 'reduce')" was thrown because payment_collections was not included in the API query, but the frontend code expected it to be present when calculating totals for refunded orders.

Why — Why are these changes relevant or necessary?

When a customer has one or more refunded orders, the customer detail page crashes with a React error. This prevents admins from viewing customer information and order history. The root cause is that the API query for customer orders was missing the payment_collections field, which is required to calculate refunded amounts for orders with payment_status === "refunded".

How — How have these changes been implemented?

  1. Fixed API query (customer-order-section.tsx): Changed payment_collections.refunded_amount to *payment_collections in the DEFAULT_RELATIONS constant to properly fetch payment collections from the API.
  2. Improved error handling (use-order-table-columns.tsx): Replaced optional chaining with explicit Array.isArray() check before calling reduce() on payment_collections to ensure robust handling when the field is missing or not an array.

Testing — How have these changes been tested, or how can the reviewer test the feature?

  1. Navigate to a customer detail page in the admin dashboard
  2. Ensure the customer has at least one order with payment_status === "refunded"
  3. Verify that:
    • The page loads without errors
    • The orders table displays correctly
    • Refunded orders show the correct total (sum of refunded_amount from payment collections)
    • Refunded order totals are displayed with strikethrough styling

Examples

The fix ensures that when calculating totals for refunded orders, the code correctly accesses payment collections:

// Before (causing error):
const DEFAULT_RELATIONS = "*customer,*items,*sales_channel,payment_collections.refunded_amount,+shipping_address.country_code"

// After (fixed):
const DEFAULT_RELATIONS = "*customer,*items,*sales_channel,*payment_collections,+shipping_address.country_code"

// Before (fragile):
const total = !isFullyRefunded
  ? getValue()
  : row.original.payment_collections?.reduce(
      (acc, payCol) => acc + (payCol.refunded_amount ?? 0),
      0
    ) || 0

// After (robust):
const total = !isFullyRefunded
  ? getValue()
  : Array.isArray(row.original.payment_collections)
    ? row.original.payment_collections.reduce(
        (acc, payCol) => acc + (payCol.refunded_amount ?? 0),
        0
      )
    : 0

Checklist

Please ensure the following before requesting a review:

  • I have added a changeset for this PR
    • Every non-breaking change should be marked as a patch
    • To add a changeset, run yarn changeset and follow the prompts
  • The changes are covered by relevant tests
  • I have verified the code works as intended locally
  • I have linked the related issue(s) if applicable

Additional Context

Error details:

  • Error: TypeError: Cannot read properties of undefined (reading 'reduce')
  • Location: use-order-table-columns.tsx line 105
  • Trigger: Viewing customer detail page with refunded orders
  • Network request: /admin/orders?customer_id=...&fields=... was missing payment_collections

Files changed:

  • packages/admin/dashboard/src/routes/customers/customer-detail/components/customer-order-section/customer-order-section.tsx
  • packages/admin/dashboard/src/hooks/table/columns/use-order-table-columns.tsx

Related API endpoint:
The fix ensures the API query includes *payment_collections which matches the pattern used in order-detail/constants.ts where payment collections are properly included.

@bqst bqst requested a review from a team as a code owner January 12, 2026 14:11
@cursor
Copy link

cursor bot commented Jan 12, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on January 17.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@changeset-bot
Copy link

changeset-bot bot commented Jan 12, 2026

🦋 Changeset detected

Latest commit: c1e1f0f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 76 packages
Name Type
@medusajs/dashboard Patch
@medusajs/admin-bundler Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/medusa-oas-cli Patch
integration-tests-http Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/draft-order Patch
@medusajs/oas-github-ci Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/telemetry Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jan 12, 2026

@bqst is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

Comment on lines 105 to 110
: Array.isArray(row.original.payment_collections)
? row.original.payment_collections.reduce(
(acc, payCol) => acc + (payCol.refunded_amount ?? 0),
0
)
: 0
Copy link
Member

@adrien2p adrien2p Jan 13, 2026

Choose a reason for hiding this comment

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

nit:

Suggested change
: Array.isArray(row.original.payment_collections)
? row.original.payment_collections.reduce(
(acc, payCol) => acc + (payCol.refunded_amount ?? 0),
0
)
: 0
: row.original.payment_collections?.reduce(
(acc, payCol) => acc + (payCol.refunded_amount ?? 0),
0
) ?? 0

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

LGTM, I ll wait on @olivermrbl approval

"@medusajs/dashboard": patch
---

Fix customer orders payment_collections undefined error
Copy link
Contributor

@NicolasGorga NicolasGorga Jan 13, 2026

Choose a reason for hiding this comment

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

nit:

"@medusajs/dashboard": patch

fix(dashboard): handle undefined payment_collections in order table calculations

@bqst bqst force-pushed the fix/admin-customer-orders-payment-collections branch from 494e81f to c1e1f0f Compare January 13, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants