Conversation
📝 WalkthroughWalkthroughThis PR extends sponsor purchase management by introducing API-driven approval/rejection capabilities. New Redux thunks call payment endpoints to approve or reject invoices, the UI dispatches these based on status selection, and a reducer updates the purchase list state accordingly. Includes translations, constants, and comprehensive test coverage. Changes
Sequence DiagramsequenceDiagram
actor User
participant Component as SponsorPurchasesTab
participant Redux as Redux<br/>(Actions/Reducers)
participant API as Payment API
participant Store as Store State
User->>Component: Select new status in dropdown
Component->>Redux: Dispatch approveSponsorPurchase<br/>or rejectSponsorPurchase
Redux->>Redux: Dispatch startLoading()
Redux->>API: PUT/DELETE /payments/{id}/approve<br/>or /cancel with access_token
alt Success
API-->>Redux: 200 OK
Redux->>Store: Dispatch SPONSOR_PURCHASE_STATUS_UPDATED<br/>{ paymentId, status }
Redux->>Redux: Dispatch snackbarSuccessHandler<br/>(translated message)
else Failure
API-->>Redux: Error response
Redux->>Redux: Log console error
end
Redux->>Redux: Dispatch stopLoading()
Redux->>Component: Update with new state
Component->>User: Re-render with updated<br/>purchase status
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/actions/sponsor-purchases-actions.js (1)
139-160: Same pattern asapproveSponsorPurchase— verify action dispatch timing.The
rejectSponsorPurchasethunk follows the same pattern. Ensure thedeleteRequesthelper dispatches the success action only after the API call succeeds.Consider replacing
.catch(console.log)with.catch(console.error)for clearer error logging.🔧 Minor improvement for error logging
.then(() => { dispatch( snackbarSuccessHandler({ title: T.translate("general.success"), html: T.translate("edit_sponsor.purchase_tab.status_updated") }) ); }) - .catch(console.log) // need to catch promise reject + .catch(console.error) // need to catch promise reject .finally(() => { dispatch(stopLoading()); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/actions/sponsor-purchases-actions.js` around lines 139 - 160, The thunk rejectSponsorPurchase currently passes a success action into deleteRequest which may be dispatched prematurely; instead ensure the SPONSOR_PURCHASE_STATUS_UPDATED action is only dispatched after the API call resolves — either by (a) updating deleteRequest to dispatch the provided action only on successful response, or (b) removing the action argument and dispatching createAction(SPONSOR_PURCHASE_STATUS_UPDATED)({ paymentId, status: PURCHASE_STATUS.CANCELLED }) inside the .then() of rejectSponsorPurchase (same pattern as approveSponsorPurchase); also replace .catch(console.log) with .catch(console.error) to improve error logging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/actions/sponsor-purchases-actions.js`:
- Around line 139-160: The thunk rejectSponsorPurchase currently passes a
success action into deleteRequest which may be dispatched prematurely; instead
ensure the SPONSOR_PURCHASE_STATUS_UPDATED action is only dispatched after the
API call resolves — either by (a) updating deleteRequest to dispatch the
provided action only on successful response, or (b) removing the action argument
and dispatching createAction(SPONSOR_PURCHASE_STATUS_UPDATED)({ paymentId,
status: PURCHASE_STATUS.CANCELLED }) inside the .then() of rejectSponsorPurchase
(same pattern as approveSponsorPurchase); also replace .catch(console.log) with
.catch(console.error) to improve error logging.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 53ff5707-d634-4f0a-a24b-9c1d5dbbebb7
📒 Files selected for processing (7)
.env.examplesrc/actions/sponsor-purchases-actions.jssrc/i18n/en.jsonsrc/pages/sponsors/sponsor-purchases-tab/__tests__/sponsor-purchases-list.test.jssrc/pages/sponsors/sponsor-purchases-tab/index.jssrc/reducers/sponsors/sponsor-page-purchase-list-reducer.jssrc/utils/constants.js
https://app.clickup.com/t/86b66n5k8
Summary by CodeRabbit
New Features
Documentation
Tests