gitpay icon indicating copy to clipboard operation
gitpay copied to clipboard

[Feature] [Refactor] Better handling of Status update for payments

Open alexanmtz opened this issue 8 months ago • 5 comments

🚀 Feature Title

Refactor task update api and actions to handle payments

❓ What problem does this solve?

We need to change how we handle payment updates for tasks, initially on the backend. Then, we need to update the related action that requests the API to return the updated task without executing extra actions.

Currently, we dispatch many actions after a task is updated (fetch task and sync task) to display the task after an update. We need to refactor this logic so that on the API, the task update handles everything and returns the updated task and the updated value of the bounty when the payment succeeds.

We have BE and FE tests for the taskUpdate on the API and taskActions.

💡 Proposed Solution

Make the API return an updated task with the new order created when calling the API https://github.com/worknenjoy/gitpay/blob/master/modules/tasks/taskUpdate.js#L123

Change the action that handles the update https://github.com/worknenjoy/gitpay/blob/master/frontend/src/actions/taskActions.js#L336

You need to check if there is a new order on the request (as the commented code), and display a notification for this case,.

Remove the sync and fetch calls from this action, call the sync on the BE, and refactor the update action to return the task and update the state with the updated data.

** You will need Stripe development keys to test payments on the UI, you can request ([email protected]) or count with our tests **

Tests for these components can be found on Task Actions: https://github.com/worknenjoy/gitpay/blob/master/frontend/tests/actions/taskActions.test.js Task Update: https://github.com/worknenjoy/gitpay/blob/master/test/task.test.js#L161 _ Most of the Task Updates and actions are skiped and it should be fixed _

🔁 Alternatives Considered

You can keep the Sync actions if is not possible to handle all in the back end, and only have the task update updating the response data so we update the status with the current task updated and call sync to get the bounty values and updates on the UI.

🎨 Does this feature affect the UI?

Yes

🛠️ Technical Notes (if any)

React, Redux, Express

💰 Is there a bounty for this issue?

No

💵 Bounty Amount (if any)

No bounty for this issue

📜 Bounty Details (if applicable)

There's no Bounty for this issue.

This issue is part of the Only Dust Hackathon: https://onlydust.notion.site/May-28th-Open-Source-Hackathon-1f244b682a80801890e5fda15b779746

alexanmtz avatar May 27 '25 10:05 alexanmtz

Here’s a summary of what’s needed to refactor the task update API and related frontend actions for better payment handling, based on the current implementation and your requirements:

Current Implementation

  • Backend (API):
    The task update API (modules/tasks/taskUpdate.js) currently processes various task parameters (like deadline, offer, members, assigned status) and handles payments via Stripe using functions such as createSourceAndCharge and createCustomer. After a successful charge, it updates the order in the database with orderUpdateAfterStripe. However, the API typically returns only the task data and does not explicitly return the updated bounty value or the new order when a payment is processed see source.

  • Frontend (Redux Action):
    The updateTask action (frontend/src/actions/taskActions.js) dispatches several actions after a task update, including syncTask and fetchTask, which is inefficient. It checks for a new order (task?.Orders?.source_id) to display a payment notification, but still fetches and syncs the task state redundantly see source.

What Needs Refactoring

  • Backend:

    • Update the task update API to always return the updated task object, including the new order and updated bounty value, when a payment is processed.
    • Ensure that after payment, the backend handles all necessary state updates so the frontend does not need to re-fetch or sync the task.
  • Frontend:

    • Refactor the updateTask action to rely on the updated task returned by the API.
    • Remove redundant calls to syncTask and fetchTask after a successful update.
    • Update the Redux state directly with the returned task data.
    • Continue to display notifications based on the presence of a new order in the response (task?.Orders?.source_id).
    • Maintain error handling for Stripe errors and other API issues.

Tests

  • Backend and Frontend Tests:
    • There are existing tests for task updates and actions, but many are currently skipped (e.g., updating task value and status in test/task.test.js). These should be fixed and updated to cover the new logic see source.
    • Ensure tests verify that the updated task and bounty value are returned and that the frontend state updates correctly without extra fetches.

References

If you need to test payments in the UI, you’ll need Stripe development keys as mentioned in your notes.

Let me know if you need a more detailed breakdown of the code changes or help with specific parts of the refactor!

To reply, just mention my name @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar May 27 '25 10:05 dosubot[bot]

Hi! I’d love to work on this issue.

Plan: I’ll refactor the backend (taskUpdate.js) to return the updated task and bounty after payment succeeds, handling sync logic there. On the frontend, I’ll update taskActions.js to use this new response, remove redundant fetch/sync calls, and show a notification if a new order is detected. I’ll also fix and enhance the related tests.

Why me: I have strong experience with Node.js, React, Redux, and Stripe. I’ve handled similar fullstack flows and enjoy improving performance and maintainability through refactoring. my EAT is 48hrs

HyzeahAchungha avatar May 28 '25 21:05 HyzeahAchungha

Hi, I’m Joe, a backend/frontend developer experienced with React, Redux, and Express. I’d like to refactor the task update API and related actions to handle payments more efficiently.

Tasks:

Modify the API to return the updated task and new order info after payment succeeds.

Refactor the frontend action to update state with returned data without extra fetch or sync calls.

Implement notification display when a new order is created.

Ensure backend handles sync logic to reduce redundant frontend calls.

Update and fix existing tests for task updates and actions.

Use Stripe dev keys for testing payment flows.

Checks:

Confirm updated task and bounty info are returned correctly from API.

Ensure UI updates properly without multiple dispatches.

Notifications work for new orders.

Tests pass and cover payment-related updates.

ETA: 8 hours Telegram: @chiefDevOvrlrd

chiefDevOvrlrd avatar May 29 '25 03:05 chiefDevOvrlrd

Hi, I'm a MERN developer with strong grip of APIs. I will love to work on this task as it'll be an avenue for me to master my skills with Stripe. With a few questions, I will get a better understanding of the task then I will go ahead and work on it then update the test files and test what I have worked on.

Dagdon avatar Jun 02 '25 09:06 Dagdon

Could someone please take a look on this?

alexanmtz avatar Jul 24 '25 10:07 alexanmtz