Skip to content

Conversation

@aimensahnoun
Copy link
Member

@aimensahnoun aimensahnoun commented Jun 5, 2025

Problem:

The invoice form was re-routing the moment the submit button was hit.

Solution:

  • Remove the instant route navigations
  • Remove the 3 second timeout
  • Add invalidation

Result:

CleanShot.2025-06-05.at.09.49.01.mp4

Summary by CodeRabbit

  • Bug Fixes

    • Removed unnecessary delay after creating an invoice and ensured the invoice list updates immediately for a more responsive user experience.
    • Eliminated automatic redirection to the dashboard after invoice creation in the invoice form, allowing users to remain on the current page.
  • Chores

    • Improved data freshness by updating the invoice list cache after creating a new invoice.

@aimensahnoun aimensahnoun self-assigned this Jun 5, 2025
@aimensahnoun aimensahnoun linked an issue Jun 5, 2025 that may be closed by this pull request
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

Walkthrough

The changes update the invoice creation flow by introducing API cache invalidation and removing artificial navigation delays. The InvoiceCreator component now invalidates the invoice list cache after invoice creation and navigates immediately to the dashboard. The InvoiceForm component removes all routing logic, eliminating any redirection after invoice creation.

Changes

File(s) Change Summary
src/components/invoice-creator.tsx Added API utility usage for cache invalidation after invoice creation and removed navigation delay.
src/components/invoice-form.tsx Removed all use of Next.js useRouter and eliminated redirection after invoice creation.

Suggested reviewers

  • bassgeta
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/components/invoice-creator.tsx (1)

49-53: Excellent implementation of cache invalidation with immediate navigation

The async onSuccess callback properly invalidates the invoice cache before navigation, ensuring the dashboard displays fresh data. This eliminates the previous artificial delay while maintaining data consistency.

Consider adding error handling for the cache invalidation operation:

 onSuccess: async () => {
   toast.success("Invoice created successfully");
-  await utils.invoice.getAll.invalidate();
-  router.push("/dashboard");
+  try {
+    await utils.invoice.getAll.invalidate();
+    router.push("/dashboard");
+  } catch (error) {
+    console.error("Failed to invalidate cache:", error);
+    // Still navigate even if cache invalidation fails
+    router.push("/dashboard");
+  }
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e38532c and 8478da4.

📒 Files selected for processing (2)
  • src/components/invoice-creator.tsx (2 hunks)
  • src/components/invoice-form.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/components/invoice-creator.tsx (1)
src/trpc/react.tsx (1)
  • api (12-12)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Install Dependencies
🔇 Additional comments (2)
src/components/invoice-form.tsx (1)

515-515: LGTM: Clean removal of router dependency

The removal of the router dependency from the submitAfterApproval callback is consistent with the architectural improvement of removing all navigation logic from the form component. This change properly centralizes navigation responsibility in the parent invoice-creator component.

src/components/invoice-creator.tsx (1)

39-39: LGTM: Proper API utils initialization

The addition of api.useUtils() provides access to cache invalidation methods needed for the improved invoice creation flow.

Copy link
Contributor

@bassgeta bassgeta left a comment

Choose a reason for hiding this comment

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

😎 good stuff, the pesky bug has been resolved, LGTM

@aimensahnoun aimensahnoun merged commit b970cae into main Jun 5, 2025
9 checks passed
@aimensahnoun aimensahnoun deleted the 71-easy-invoice---fix-invoice-creation-forwarding-behavior branch June 5, 2025 08:41
Copy link
Member

@MantisClone MantisClone left a comment

Choose a reason for hiding this comment

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

Nice work 💯

@coderabbitai coderabbitai bot mentioned this pull request Aug 27, 2025
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.

Easy Invoice - Fix invoice creation forwarding behavior

4 participants