Update billing page data handling and version bump to 2.12.0 (#300)

* Update billing page data handling and version bump to 2.12.0

- Refactored billing page components to streamline data loading for subscriptions and orders.
- Introduced `getProductPlan` function to encapsulate product plan resolution logic.
- Updated `package.json` version from 2.11.0 to 2.12.0.
This commit is contained in:
Giancarlo Buomprisco
2025-07-16 16:11:55 +07:00
committed by GitHub
parent abcf1ae3d7
commit da8a3a903d
6 changed files with 116 additions and 125 deletions

View File

@@ -2,26 +2,9 @@ import 'server-only';
import { cache } from 'react';
import { z } from 'zod';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { createTeamAccountsApi } from '@kit/team-accounts/api';
/**
* The variable BILLING_MODE represents the billing mode for a service. It can
* have either the value 'subscription' or 'one-time'. If not provided, the default
* value is 'subscription'. The value can be overridden by the environment variable
* BILLING_MODE.
*
* If the value is 'subscription', we fetch the subscription data for the user.
* If the value is 'one-time', we fetch the orders data for the user.
* if none of these suits your needs, please override the below function.
*/
const BILLING_MODE = z
.enum(['subscription', 'one-time'])
.default('subscription')
.parse(process.env.BILLING_MODE);
/**
* @name loadTeamAccountBillingPage
* @description Load the team account billing page data for the given account.
@@ -32,12 +15,9 @@ function teamAccountBillingPageLoader(accountId: string) {
const client = getSupabaseServerClient();
const api = createTeamAccountsApi(client);
const data =
BILLING_MODE === 'subscription'
? api.getSubscription(accountId)
: api.getOrder(accountId);
const subscription = api.getSubscription(accountId);
const order = api.getOrder(accountId);
const customerId = api.getCustomerId(accountId);
return Promise.all([data, customerId]);
return Promise.all([subscription, order, customerId]);
}