Skip to content

fix: invalidate invoice queries after marking as paid#569

Merged
adambarito merged 1 commit intomainfrom
claude/issue-533-20260129-2107
Mar 23, 2026
Merged

fix: invalidate invoice queries after marking as paid#569
adambarito merged 1 commit intomainfrom
claude/issue-533-20260129-2107

Conversation

@adambarito
Copy link
Contributor

Fixes #533

Description

This PR fixes the issue where marking an invoice as paid doesn't update its status on the invoice page or the all-invoices page without requiring a page refresh.

Changes

  • Add byWorkspace query invalidation to markPaid mutation
  • Add byWorkspace query invalidation to send mutation
  • Add stats query invalidation to all invoice mutations
  • Also update delete mutation to invalidate stats

This ensures the invoice list and stats update immediately without requiring a page refresh.

Generated with Claude Code

- Add byWorkspace query invalidation to markPaid mutation
- Add byWorkspace query invalidation to send mutation
- Add stats query invalidation to all invoice mutations
- Also update delete mutation to invalidate stats

This ensures the invoice list and stats update immediately without requiring a page refresh

Fixes #533

Co-authored-by: adambarito <adambarito@users.noreply.github.com>
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 20, 2026

Greptile Summary

This PR fixes a stale-UI bug where marking an invoice as paid (or sending it) would not update the invoice list or stats counters without a full page refresh. It does so by adding byWorkspace and stats query invalidations alongside the already-present byId invalidation in the send and markPaid mutation onSettled callbacks, and by adding a new onSettled to the delete mutation for the same purpose.

Key changes:

  • send mutation: now invalidates byId, byWorkspace, and stats in parallel via Promise.all
  • markPaid mutation: now invalidates byId, byWorkspace, and stats in parallel via Promise.all
  • delete mutation: gains a new onSettled that invalidates byWorkspace and stats

Minor gap: The duplicate mutation (unchanged in this PR) still does not invalidate byWorkspace or stats. A duplicated invoice won't appear in the list until a manual refresh. Given the stated intent of this PR, it is worth addressing in the same change.

Confidence Score: 4/5

  • Safe to merge — the changes are correct and directly fix the reported issue with no risk of regressions.
  • The invalidation pattern (queryKey() called without arguments for prefix-based matching) is consistent with the pre-existing byId invalidation that was already in place and working. Promise.all parallelises the invalidations cleanly. The only gap is that the duplicate mutation is not updated, leaving a similar stale-list bug for that action, but that is pre-existing and not introduced by this PR.
  • No files require special attention — the single changed file is straightforward.

Important Files Changed

Filename Overview
apps/app/src/app/[handle]/invoices/_components/invoice-detail.tsx Adds byWorkspace and stats query invalidation to send and markPaid mutations via Promise.all, and introduces a new onSettled for the delete mutation invalidating the same queries. The duplicate mutation still lacks byWorkspace invalidation (pre-existing gap).

Sequence Diagram

sequenceDiagram
    participant U as User
    participant IC as InvoiceDetail
    participant tRPC as tRPC Server
    participant QC as QueryClient Cache

    U->>IC: Click "Mark as Paid" / "Send Invoice"
    IC->>tRPC: mutate(markPaid / send)
    tRPC-->>IC: onSuccess → show toast
    IC->>QC: onSettled: Promise.all([invalidate byId, byWorkspace, stats])
    QC-->>IC: refetch byId (invoice detail updates)
    QC-->>IC: refetch byWorkspace (invoice list updates)
    QC-->>IC: refetch stats (dashboard counters update)

    U->>IC: Click "Delete"
    IC->>tRPC: mutate(delete)
    tRPC-->>IC: onSuccess → toast + router.push(invoice list)
    IC->>QC: onSettled: Promise.all([invalidate byWorkspace, stats])
    QC-->>IC: refetch byWorkspace (deleted item removed from list)
    QC-->>IC: refetch stats (counters updated)
Loading

Comments Outside Diff (1)

  1. apps/app/src/app/[handle]/invoices/_components/invoice-detail.tsx, line 114-124 (link)

    P2 duplicate mutation missing byWorkspace invalidation

    The duplicateInvoice mutation navigates to the new invoice's detail page on success, but never invalidates byWorkspace or stats. If a user duplicates an invoice and then navigates to the invoice list, the duplicated entry will not appear until a manual page refresh.

    This is a pre-existing gap, but since the stated intent of this PR is to ensure every mutation that changes the invoice list also invalidates byWorkspace and stats, it would be consistent to address duplicate here too. Adding an onSettled block mirroring the pattern used by send and markPaid would close the gap.

Last reviewed commit: "fix: invalidate invo..."

@github-actions
Copy link

apps

📱 app 🚀 preview 🔍 inspect
📱 app preview inspect
📻 app-fm preview inspect
🧾 app-invoice preview inspect
🌱 bio preview inspect
🛒 cart preview inspect
📻 fm preview inspect
🧾 invoice preview inspect
🔗 link preview inspect
📧 manage-email preview inspect
🌆 nyc preview inspect
📄 page preview inspect
📰 press preview inspect
⭐ vip preview inspect
🌐 www preview inspect

db

💾 db 🔍 inspect
🐘 neon inspect

@adambarito adambarito added this pull request to the merge queue Mar 23, 2026
Merged via the queue into main with commit 0d66eca Mar 23, 2026
102 checks passed
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.

marking an invoice as paid doesn't update its status on the invoice page or on the all-invoices (/invoices) page

1 participant