-
-
Notifications
You must be signed in to change notification settings - Fork 4k
fix(dashboard): handle undefined payment_collections in order table calculations #14523
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
base: develop
Are you sure you want to change the base?
fix(dashboard): handle undefined payment_collections in order table calculations #14523
Conversation
|
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 detectedLatest commit: c1e1f0f The changes in this PR will be included in the next version bump. This PR includes changesets to release 76 packages
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 |
|
@bqst is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
| : Array.isArray(row.original.payment_collections) | ||
| ? row.original.payment_collections.reduce( | ||
| (acc, payCol) => acc + (payCol.refunded_amount ?? 0), | ||
| 0 | ||
| ) | ||
| : 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| : 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 |
adrien2p
left a comment
There was a problem hiding this 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
.changeset/few-yaks-flash.md
Outdated
| "@medusajs/dashboard": patch | ||
| --- | ||
|
|
||
| Fix customer orders payment_collections undefined error |
There was a problem hiding this comment.
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
494e81f to
c1e1f0f
Compare
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_collectionswas 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_collectionsfield, which is required to calculate refunded amounts for orders withpayment_status === "refunded".How — How have these changes been implemented?
customer-order-section.tsx): Changedpayment_collections.refunded_amountto*payment_collectionsin theDEFAULT_RELATIONSconstant to properly fetch payment collections from the API.use-order-table-columns.tsx): Replaced optional chaining with explicitArray.isArray()check before callingreduce()onpayment_collectionsto 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?
payment_status === "refunded"refunded_amountfrom payment collections)Examples
The fix ensures that when calculating totals for refunded orders, the code correctly accesses payment collections:
Checklist
Please ensure the following before requesting a review:
yarn changesetand follow the promptsAdditional Context
Error details:
use-order-table-columns.tsxline 105Files changed:
packages/admin/dashboard/src/routes/customers/customer-detail/components/customer-order-section/customer-order-section.tsxpackages/admin/dashboard/src/hooks/table/columns/use-order-table-columns.tsxRelated 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.