Files
supabase/apps/studio/data/organizations/keys.ts
Ignacio Dobronich e6ca2766ff feat: show tax preview for credit top-ups (#45005)
## Summary

- Add tax preview to the credit top-up flow by integrating the new `POST
/organizations/{slug}/billing/credits/preview` endpoint
- Show a price breakdown (credit amount, tax line item, total) in the
top-up dialog before the user confirms payment
- Handle all three `tax_status` states: show tax when `calculated`, hide
the line when `not_applicable`, show an inline warning when `failed`


## Behavior

- Preview fires as soon as a valid amount (300–2000) is entered; address
and tax ID are optional and refine the estimate
- Amount and address changes are debounced at 1s to avoid excessive API
calls

## Test plan

- [ ]  Open credit top-up dialog - verify preview appears with default
$300 amount
- [ ]  Change amount within 300–2000 - verify preview updates after
debounce
- [ ]  Enter amount outside range (e.g. 100 or 3000) - verify preview
hides and validation error shows
- [ ]  Add a new payment method with a billing address in a taxed region
- verify tax line item appears
- [ ]  Add a new payment method with no tax jurisdiction - verify no tax
line, just total
- [ ]  Complete a top-up - verify the charge goes through and dialog
closes


<img width="571" height="551" alt="image"
src="https://github.com/user-attachments/assets/d3357752-f913-4a4a-b84a-f78e2f457c7b"
/>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Credit top-up preview with charge breakdown (credit, tax or tax note,
total).
* Onboarding survey endpoint and ISO 27001 certificate availability for
organizations.

* **Updates**
* Improved top-up UX: debounced address/tax inputs, enforced min/max
amount validation, preview-driven form state, and submit disabled while
preview is loading/stale.
  * API docs wording changed to “temporary access configuration.”
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-23 12:16:57 -03:00

40 lines
2.3 KiB
TypeScript

export const organizationKeys = {
list: () => ['organizations'] as const,
detail: (slug?: string) => ['organizations', slug] as const,
members: (slug?: string) => ['organizations', slug, 'members'] as const,
mfa: (slug?: string) => ['organizations', slug, 'mfa'] as const,
paymentMethods: (slug: string | undefined) => ['organizations', slug, 'payment-methods'] as const,
entitlements: (slug: string | undefined) => ['entitlements', slug] as const,
roles: (slug: string | undefined) => ['organizations', slug, 'roles'] as const,
freeProjectLimitCheck: (slug: string | undefined) =>
['organizations', slug, 'free-project-limit-check'] as const,
customerProfile: (slug: string | undefined) =>
['organizations', slug, 'customer-profile'] as const,
auditLogs: (
slug: string | undefined,
{ date_start, date_end }: { date_start: string | undefined; date_end: string | undefined }
) => ['organizations', slug, 'audit-logs', { date_start, date_end }] as const,
subscriptionPreview: (
slug: string | undefined,
tier: string | undefined,
params?: { address?: Record<string, unknown>; taxId?: Record<string, unknown> }
) => ['organizations', slug, 'subscription', 'preview', tier, params] as const,
taxId: (slug: string | undefined) => ['organizations', slug, 'tax-ids'] as const,
tokenValidation: (slug: string | undefined, token: string | undefined) =>
['organizations', slug, 'validate-token', token] as const,
projectClaim: (slug: string, token: string) =>
['organizations', slug, 'project-claim', token] as const,
availableRegions: (slug: string | undefined, cloudProvider: string, size?: string) =>
['organizations', slug, 'available-regions', cloudProvider, size] as const,
creationPreview: (
tier: string | undefined,
params?: { address?: Record<string, unknown>; taxId?: Record<string, unknown> }
) => ['organizations', 'creation-preview', tier, params] as const,
previewCreditCode: (slug: string | undefined, code: string) =>
['organizations', slug, 'preview-credit-code', code] as const,
creditTopUpPreview: (
slug: string | undefined,
params?: { amount?: number; address?: Record<string, unknown>; taxId?: Record<string, unknown> }
) => ['organizations', slug, 'credits', 'preview', params] as const,
}