Key billing data on the selected tenant#2003
Open
GregorShear wants to merge 1 commit into
Open
Conversation
Billing invoices are now fetched through a tenant-keyed SWR hook (useBillingInvoices) instead of an imperative fetch into the Billing store. Because the SWR key derives from the selected tenant and the rolling six-month window, switching orgs re-fetches automatically and never shows the previous tenant's data — so the store no longer needs to be manually reset when the tenant changes. Removes the useTenantChangeReset hook, the unmount reset in AdminBilling, and the StoreWithHydration machinery (invoices, active/hydrated/ networkFailed/hydrationErrorsExist, resetState) from the Billing store, which is now just the invoice selection and paymentMethodExists. The selected invoice resolves to the stored selection or falls back to the newest invoice, so a stale selection from another tenant self-corrects. All invoice/loading/error reads across the billing page, history table, line-items table, usage graphs, and graph-state wrapper now come from the hook. SWR dedupes the shared key to a single request, and revisiting a tenant is served instantly from cache.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Route billing invoice fetching through a single tenant-keyed hook (
useBillingInvoices) instead of an imperative fetch into the Billing store.Why
Switching tenants required manually resetting the billing store (
useTenantChangeReset) so the previous tenant's data wasn't left on screen. Keying the fetch on the selected tenant makes that reset unnecessary — the data refetches and supersedes on its own, matching howuseMonthlyUsage/AlertSubscriptionsalready work.Changes
useBillingInvoiceshook: fetches the selected tenant's invoices for a rolling six-month window and returns{ invoices, selectedInvoice, isLoading, networkFailed, errorExists }.selectedInvoicefalls back to the newest invoice when the stored selection isn't in the current tenant's data, so an org switch self-corrects.Billingstore to just the invoice selection andpaymentMethodExists; dropinvoices, theStoreWithHydrationflags, andresetState.useTenantChangeResetand the unmount reset inAdminBilling.Still PostgREST under the hood — transport is unchanged here; the GraphQL migration follows in the stacked PR. Behavior-preserving, no consumer API changes.
Stacked on
greg/move-avatar.