diff --git a/apps/web/app/(dashboard)/home/(user)/billing/page.tsx b/apps/web/app/(dashboard)/home/(user)/billing/page.tsx index d12f2a1c0..d7de63492 100644 --- a/apps/web/app/(dashboard)/home/(user)/billing/page.tsx +++ b/apps/web/app/(dashboard)/home/(user)/billing/page.tsx @@ -18,8 +18,6 @@ import { withI18n } from '~/lib/i18n/with-i18n'; import { PersonalAccountCheckoutForm } from './_components/personal-account-checkout-form'; -type Subscription = Database['public']['Tables']['subscriptions']['Row']; - export const generateMetadata = async () => { const i18n = await createI18nServerInstance(); const title = i18n.t('account:billingTab'); @@ -78,7 +76,7 @@ async function loadData(client: SupabaseClient) { const subscription = client .from('subscriptions') - .select('*') + .select('*, items: subscription_items !inner (*)') .eq('account_id', user.id) .maybeSingle() .then(({ data }) => data); diff --git a/apps/web/app/(dashboard)/home/[account]/billing/_components/team-account-checkout-form.tsx b/apps/web/app/(dashboard)/home/[account]/billing/_components/team-account-checkout-form.tsx index afea8dcb6..100cc8e98 100644 --- a/apps/web/app/(dashboard)/home/[account]/billing/_components/team-account-checkout-form.tsx +++ b/apps/web/app/(dashboard)/home/[account]/billing/_components/team-account-checkout-form.tsx @@ -38,11 +38,11 @@ export function TeamAccountCheckoutForm(params: { accountId: string }) { - + - + diff --git a/apps/web/app/(dashboard)/home/[account]/billing/page.tsx b/apps/web/app/(dashboard)/home/[account]/billing/page.tsx index d3b727641..13be1ea7a 100644 --- a/apps/web/app/(dashboard)/home/[account]/billing/page.tsx +++ b/apps/web/app/(dashboard)/home/[account]/billing/page.tsx @@ -35,6 +35,7 @@ async function TeamAccountBillingPage({ params }: Params) { const workspace = await loadTeamWorkspace(params.account); const accountId = workspace.account.id; const [subscription, customerId] = await loadAccountData(accountId); + const canManageBilling = workspace.account.permissions.includes('billing.manage'); @@ -46,7 +47,7 @@ async function TeamAccountBillingPage({ params }: Params) { /> -
+
@@ -100,7 +101,7 @@ async function loadAccountData(accountId: string) { const subscription = client .from('subscriptions') - .select('*') + .select('*, items: subscription_items !inner (*)') .eq('account_id', accountId) .maybeSingle() .then(({ data }) => data); diff --git a/packages/billing-gateway/src/components/current-plan-card.tsx b/packages/billing-gateway/src/components/current-plan-card.tsx index 2e2739512..04be4d283 100644 --- a/packages/billing-gateway/src/components/current-plan-card.tsx +++ b/packages/billing-gateway/src/components/current-plan-card.tsx @@ -27,14 +27,33 @@ import { Trans } from '@kit/ui/trans'; import { CurrentPlanAlert } from './current-plan-alert'; import { CurrentPlanBadge } from './current-plan-badge'; +type Subscription = Database['public']['Tables']['subscriptions']['Row']; +type LineItem = Database['public']['Tables']['subscription_items']['Row']; + +interface Props { + subscription: Subscription & { + items: LineItem[]; + }; + + config: BillingConfig; +} + export function CurrentPlanCard({ subscription, config, -}: React.PropsWithChildren<{ - subscription: Database['public']['Tables']['subscriptions']['Row']; - config: BillingConfig; -}>) { - const { plan, product } = getProductPlanPair(config, subscription); +}: React.PropsWithChildren) { + // line items have the same product id + const lineItem = subscription.items[0] as LineItem; + + const product = config.products.find( + (product) => product.id === lineItem.product_id, + ); + + if (!product) { + throw new Error( + 'Product not found. Make sure the product exists in the billing config.', + ); + } return ( @@ -58,6 +77,7 @@ export function CurrentPlanCard({ /> {product.name} +
diff --git a/packages/billing-gateway/src/components/plan-picker.tsx b/packages/billing-gateway/src/components/plan-picker.tsx index ffd94aea0..8d1b4a250 100644 --- a/packages/billing-gateway/src/components/plan-picker.tsx +++ b/packages/billing-gateway/src/components/plan-picker.tsx @@ -96,7 +96,11 @@ export function PlanPicker( return (
-
+