Skip to content

fix invalidation when creating / editing a todo#148

Merged
yesyash merged 1 commit intodevelopfrom
yash/invalidation
Jul 19, 2025
Merged

fix invalidation when creating / editing a todo#148
yesyash merged 1 commit intodevelopfrom
yash/invalidation

Conversation

@yesyash
Copy link
Contributor

@yesyash yesyash commented Jul 19, 2025

Date: 19 July 2025

Developer Name: Yash Raj


Issue Ticket Number

  • N/A

Description

  • fix tanstack query cache invalidation when creating / updating a todo.

Description by Korbit AI

What change is being made?

Fix task invalidation when creating or editing a todo by returning the updated task object and adding additional query invalidations based on the assignee's user type.

Why are these changes being made?

The previous implementation did not return the updated task object after patching, which limited the ability to handle responses correctly. Adding query invalidations when a task's assignee is a team allows for updated task data to reflect dynamically across different contexts or views tied to team members, ensuring that the user interface remains consistent and accurate when tasks are updated or reassigned.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

@coderabbitai
Copy link

coderabbitai bot commented Jul 19, 2025

Summary by CodeRabbit

  • Improvements
    • Enhanced task update and creation workflows with more precise cache updates, resulting in improved data consistency, especially when tasks are assigned to team members.
    • Broadened cache refresh logic after task reassignment to ensure up-to-date task lists.
    • Removed unnecessary debugging code for a cleaner user experience.

Walkthrough

The updateTask API method was changed to return the updated task data. Components handling task creation, editing, and reassignment now perform more granular cache invalidation based on the assignee's user type and ID, ensuring cache consistency. Debug code was removed from the reassignment component.

Changes

File(s) Change Summary
api/tasks/tasks.api.ts updateTask now returns the updated task data (TTask) instead of void; method signature updated accordingly.
components/edit-task-button.tsx Added conditional cache invalidation for tasks by assignee ID and user type in update mutation's onSuccess.
components/reassign-user.tsx Added broader cache invalidation for tasks; removed a debugger statement from reassign handler.
modules/dashboard/components/create-todo-button.tsx Added conditional cache invalidation by assignee ID and user type in create mutation's onSuccess handler.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant TasksApi
    participant Cache

    UI->>TasksApi: updateTask({id, ...task})
    TasksApi-->>UI: Returns updated TTask

    UI->>Cache: Invalidate general tasks query
    alt Assignee is TEAM
        UI->>Cache: Invalidate tasks query by assignee ID
    end
    UI->>UI: Show success toast, close form
Loading

Possibly related PRs

  • #136: Also modifies the updateTask method, specifically updating the API endpoint URL.
  • #131: Refactors mutation handling and cache invalidation in edit-task-button.tsx, directly affecting update task mutation logic.
  • #130: Changes the TTask type and updates related UI components, relating to task assignment handling.

Suggested reviewers

  • Achintya-Chatterjee

Poem

A patch for tasks, both old and new,
Returns fresh data, cache in view!
No more stale lists, no more fuss,
The bunny hops—no debugger for us!
With teams and users, all in sync,
This code’s as crisp as a carrot drink. 🥕

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

api/tasks/tasks.api.ts

Oops! Something went wrong! :(

ESLint: 9.30.1

ESLint couldn't find the plugin "eslint-plugin-react-hooks".

(The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react-hooks@latest --save-dev

The plugin "eslint-plugin-react-hooks" was referenced from the config file in " » eslint-config-next/core-web-vitals » /node_modules/.pnpm/eslint-config-next@15.3.5_eslint-plugin-import-x@4.16.1_@typescript-eslint+utils@8.36.0_79fa352f41e97200dfc66b7389b5a599/node_modules/eslint-config-next/index.js".

If you still can't figure out the problem, please see https://eslint.org/docs/latest/use/troubleshooting.

components/reassign-user.tsx

Oops! Something went wrong! :(

ESLint: 9.30.1

ESLint couldn't find the plugin "eslint-plugin-react-hooks".

(The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react-hooks@latest --save-dev

The plugin "eslint-plugin-react-hooks" was referenced from the config file in " » eslint-config-next/core-web-vitals » /node_modules/.pnpm/eslint-config-next@15.3.5_eslint-plugin-import-x@4.16.1_@typescript-eslint+utils@8.36.0_79fa352f41e97200dfc66b7389b5a599/node_modules/eslint-config-next/index.js".

If you still can't figure out the problem, please see https://eslint.org/docs/latest/use/troubleshooting.

components/edit-task-button.tsx

Oops! Something went wrong! :(

ESLint: 9.30.1

ESLint couldn't find the plugin "eslint-plugin-react-hooks".

(The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react-hooks@latest --save-dev

The plugin "eslint-plugin-react-hooks" was referenced from the config file in " » eslint-config-next/core-web-vitals » /node_modules/.pnpm/eslint-config-next@15.3.5_eslint-plugin-import-x@4.16.1_@typescript-eslint+utils@8.36.0_79fa352f41e97200dfc66b7389b5a599/node_modules/eslint-config-next/index.js".

If you still can't figure out the problem, please see https://eslint.org/docs/latest/use/troubleshooting.

  • 1 others

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 442ca82 and 5781613.

📒 Files selected for processing (4)
  • api/tasks/tasks.api.ts (1 hunks)
  • components/edit-task-button.tsx (2 hunks)
  • components/reassign-user.tsx (1 hunks)
  • modules/dashboard/components/create-todo-button.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: Hariom01010
PR: Real-Dev-Squad/todo-frontend#51
File: __mocks__/types.ts:33-34
Timestamp: 2025-07-09T08:59:13.002Z
Learning: In the todo-frontend project, the PATCH task API endpoint payload uses `dueAt` and `startedAt` field names, but these update the `dueDate` and `startDate` fields respectively in the Task object. This is intentional according to the API contract design.
components/edit-task-button.tsx (1)
Learnt from: Hariom01010
PR: Real-Dev-Squad/todo-frontend#51
File: __mocks__/types.ts:33-34
Timestamp: 2025-07-09T08:59:13.002Z
Learning: In the todo-frontend project, the PATCH task API endpoint payload uses `dueAt` and `startedAt` field names, but these update the `dueDate` and `startDate` fields respectively in the Task object. This is intentional according to the API contract design.
api/tasks/tasks.api.ts (1)
Learnt from: Hariom01010
PR: Real-Dev-Squad/todo-frontend#51
File: __mocks__/types.ts:33-34
Timestamp: 2025-07-09T08:59:13.002Z
Learning: In the todo-frontend project, the PATCH task API endpoint payload uses `dueAt` and `startedAt` field names, but these update the `dueDate` and `startDate` fields respectively in the Task object. This is intentional according to the API contract design.
modules/dashboard/components/create-todo-button.tsx (1)
Learnt from: Hariom01010
PR: Real-Dev-Squad/todo-frontend#51
File: __mocks__/types.ts:33-34
Timestamp: 2025-07-09T08:59:13.002Z
Learning: In the todo-frontend project, the PATCH task API endpoint payload uses `dueAt` and `startedAt` field names, but these update the `dueDate` and `startDate` fields respectively in the Task object. This is intentional according to the API contract design.
🧬 Code Graph Analysis (3)
components/reassign-user.tsx (1)
api/tasks/tasks.api.ts (1)
  • TasksApi (16-69)
api/tasks/tasks.api.ts (2)
api/tasks/tasks.types.ts (2)
  • UpdateTaskDto (59-72)
  • TTask (11-22)
lib/api-client.ts (1)
  • apiClient (6-10)
modules/dashboard/components/create-todo-button.tsx (1)
api/tasks/tasks.api.ts (1)
  • TasksApi (16-69)
🔇 Additional comments (6)
api/tasks/tasks.api.ts (1)

35-37: LGTM! API method now returns updated task data for better cache management.

The change from Promise<void> to Promise<TTask> enables downstream components to access the updated task information, allowing for more granular cache invalidation based on the assignee's details.

modules/dashboard/components/create-todo-button.tsx (2)

1-1: Good addition of required import for user type checking.

The USER_TYPE_ENUM import is correctly added to support the conditional cache invalidation logic.


16-23: Excellent implementation of granular cache invalidation.

The conditional cache invalidation logic correctly targets team-specific caches when the assignee is a team member. This ensures both the general task list and team-filtered views stay synchronized after task creation.

components/reassign-user.tsx (1)

44-44: Good addition of general cache invalidation for comprehensive coverage.

Adding invalidation of the general tasks cache (without teamId) ensures that all task views are updated after reassignment, providing comprehensive cache consistency.

components/edit-task-button.tsx (2)

1-1: Consistent import addition for user type checking.

The USER_TYPE_ENUM import correctly supports the conditional cache invalidation logic, maintaining consistency with other components.


25-32: Excellent consistency in cache invalidation strategy.

The conditional cache invalidation logic matches the pattern implemented in create-todo-button.tsx, ensuring uniform cache management across create and edit operations. This leverages the updated task data returned by the API to make informed invalidation decisions.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Performance Inefficient Query Invalidation Pattern ▹ view
Design Violation of Single Responsibility in mutation callback ▹ view
Files scanned
File Path Reviewed
api/tasks/tasks.api.ts
modules/dashboard/components/create-todo-button.tsx
components/edit-task-button.tsx
components/reassign-user.tsx

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

@yesyash yesyash merged commit 126b5f2 into develop Jul 19, 2025
4 checks passed
@yesyash yesyash deleted the yash/invalidation branch July 19, 2025 02:22
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.

1 participant