Skip to content

fix(pos): sync receipt settings on tenant switch - #1313

Merged
khaira777 merged 5 commits into
mainfrom
fm/ship-c7755f35-receipt-settings-tenant-sync
Oct 23, 2026
Merged

khaira777 merged 5 commits into
mainfrom
fm/ship-c7755f35-receipt-settings-tenant-sync

Conversation

@khaira777

@khaira777 khaira777 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1297

Summary

  • Track hydratedTenantId in useReceiptSettingsSync so switching currentTenant within the 60-second FOCUS_SYNC_THROTTLE_MS window immediately forces a re-sync of GET /api/settings/business.
  • Guard hydrateReceiptSettings against stale in-flight responses when currentTenant?.id changes before the request resolves, and avoid throttling or suppressing a subsequent sync for the newly active tenant.
  • Throw PrintCancelledOnTenantChangeError when currentTenant switches mid-print in usePrinterStore and ignore it in callers so canceled prints neither report success/post print history nor show error toasts.
  • Add regression tests in tests/receipt-settings-hydration.test.ts covering immediate sync on tenant switch within the throttle window, stale in-flight response rejection, and mid-print tenant switch cancellation.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment @coderabbitai help to get the list of available commands.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@khaira777 khaira777 changed the title fix(frontend): re-sync receipt settings immediately on tenant switch fix(pos): sync receipt settings on tenant switch Oct 22, 2026
@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5 Tier: apex

[Medium impact] The changes affect tenant receipt settings and printing within the POS workflow.

Not ready to merge: canceled prints can be recorded as successful, and a pending print can still read another tenant's settings after A → B → A.

Findings

  1. P1 Canceled prints report success ▶

Summary

This PR refreshes receipt settings when the active tenant changes and rejects responses from older requests.

  • Receipt settings refresh for the active tenant, even within the focus throttle window.
  • Receipt print jobs stop when the active tenant changes.

Static review only; tests and builds were not run.

Diagram

sequenceDiagram
    participant Orders as Orders page
    participant Print as usePrinterStore
    participant Sync as Receipt settings sync
    participant Auth as useAuthStore
    participant API
    participant Settings as usePosSettingsStore

    Orders->>Print: printBill for A
    Print->>Sync: ensureReceiptSettingsLoaded(A)
    Note over Sync: A settings request is pending
    Auth->>Sync: Active tenant changes to B
    Sync->>Sync: Invalidate A request and hydration
    Sync->>API: Fetch B settings
    API-->>Sync: B settings
    Sync->>Settings: Apply B settings
    API-->>Sync: Delayed A response
    Sync->>Sync: Ignore old A response
    Sync-->>Print: false
    Print-->>Orders: Empty warnings array
    Orders->>API: Record print as successful
Loading

Reviews (2) · Last reviewed commit: "fix(pos): guard receipt sync and print t..." · Reviewed by Greptile

@khaira777
khaira777 force-pushed the fm/ship-c7755f35-receipt-settings-tenant-sync branch from 1c076b9 to 037618f Compare October 22, 2026 21:41
@khaira777 khaira777 changed the title fix(pos): sync receipt settings on tenant switch fix(frontend): resync receipt settings immediately on tenant switch Oct 22, 2026
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@khaira777 khaira777 changed the title fix(frontend): resync receipt settings immediately on tenant switch fix(pos): sync receipt settings on tenant switch Oct 22, 2026
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

Comment thread frontend/src/hooks/usePrinter.ts Resolved
@khaira777
khaira777 force-pushed the fm/ship-c7755f35-receipt-settings-tenant-sync branch from 037618f to d383308 Compare October 22, 2026 22:49
@khaira777 khaira777 changed the title fix(pos): sync receipt settings on tenant switch fix(frontend): sync receipt settings on tenant switch and abort stale tenant prints Oct 22, 2026
@khaira777 khaira777 changed the title fix(frontend): sync receipt settings on tenant switch and abort stale tenant prints fix(pos): sync receipt settings on tenant switch Oct 22, 2026
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@khaira777
khaira777 merged commit 892d58f into main Oct 23, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/ship-c7755f35-receipt-settings-tenant-sync branch October 23, 2026 01:52
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.

fix(frontend): re-sync receipt settings immediately on tenant switch

1 participant