1
1
import { Metadata } from "next" ;
2
2
import { clsx } from "clsx" ;
3
3
import type Stripe from "stripe" ;
4
+ import type { CurrentPhase , LookupOrgResponse , PaymentMethodsResponse , Usage } from "tier" ;
4
5
6
+ import { PricingTableData } from "@/types" ;
5
7
import { TIER_AICOPY_FEATURE_ID } from "@/config/tierConstants" ;
6
8
import { pullCurrentPlan } from "@/lib/services/currentPlan" ;
7
9
import { pullPricingTableData } from "@/lib/services/pricingTableData" ;
@@ -22,29 +24,26 @@ export const metadata: Metadata = {
22
24
} ;
23
25
24
26
export default async function BillingPage ( ) {
25
- const pricing = await pullPricingTableData ( ) ;
26
-
27
27
const user = await getCurrentUser ( ) ;
28
28
29
- // Fetch the feature consumption and limit of the AI copy feature for the plan currently subscribed
30
- const featureLimits = await tier . lookupLimit ( `org:${ user ?. id } ` , TIER_AICOPY_FEATURE_ID ) ;
29
+ let [ pricing , featureLimits , phase , org , paymentMethodResponse ] = await Promise . all ( [
30
+ pullPricingTableData ( ) ,
31
+ // Fetch the feature consumption and limit of the AI copy feature for the plan currently subscribed
32
+ tier . lookupLimit ( `org:${ user ?. id } ` , TIER_AICOPY_FEATURE_ID ) ,
33
+ // Fetch the phase data of the current subscription
34
+ tier . lookupPhase ( `org:${ user ?. id } ` ) ,
35
+ // Fetch organization/user details
36
+ tier . lookupOrg ( `org:${ user ?. id } ` ) ,
37
+ // Fetch the saved payment methods
38
+ tier . lookupPaymentMethods ( `org:${ user ?. id } ` ) ,
39
+ ] ) ;
31
40
32
41
const usageLimit = featureLimits . limit ;
33
42
const used = featureLimits . used ;
34
43
35
- // Fetch the phase data of the current subscription
36
- const phase = await tier . lookupPhase ( `org:${ user ?. id } ` ) ;
37
- console . log ( phase . current ?. end ) ;
38
-
39
44
// Fetch the current plan from the pricing table data
40
45
const currentPlan = await pullCurrentPlan ( phase , pricing ) ;
41
46
42
- // Fetch organization/user details
43
- const org = await tier . lookupOrg ( `org:${ user ?. id } ` ) ;
44
-
45
- // Fetch the saved payment methods
46
- const paymentMethodResponse = await tier . lookupPaymentMethods ( `org:${ user ?. id } ` ) ;
47
-
48
47
const paymentMethod = paymentMethodResponse . methods [ 0 ] as unknown as Stripe . PaymentMethod ;
49
48
50
49
return (
0 commit comments