From 8e5eadb1f4f737b321f87e101e67f01f84064acd Mon Sep 17 00:00:00 2001 From: Jerric Lyns John Date: Thu, 10 Aug 2023 15:38:21 +0530 Subject: [PATCH 1/2] fix: reverting to old version number for free plan --- src/config/tierConstants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/tierConstants.ts b/src/config/tierConstants.ts index 876ff57..27c38ba 100644 --- a/src/config/tierConstants.ts +++ b/src/config/tierConstants.ts @@ -3,7 +3,7 @@ import type { FeatureName, PlanName } from "tier"; import { TierPlanConstant } from "@/types"; // Plans -export const TIER_FREE_PLAN_ID = "plan:free@1"; +export const TIER_FREE_PLAN_ID = "plan:free@0"; export const TIER_STARTUP_PLAN_ID = "plan:startup@0"; export const TIER_BUSINESS_PLAN_ID = "plan:business@0"; From b8e078b9da01c3a2ed066b91d747bd3dca31cea4 Mon Sep 17 00:00:00 2001 From: Jerric Lyns John Date: Fri, 11 Aug 2023 02:40:07 +0530 Subject: [PATCH 2/2] perf: comverted sequention awaits into Promise.all() to make all the calls concurrent --- src/app/(app)/billing/page.tsx | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/app/(app)/billing/page.tsx b/src/app/(app)/billing/page.tsx index c05f856..ca8b531 100644 --- a/src/app/(app)/billing/page.tsx +++ b/src/app/(app)/billing/page.tsx @@ -1,7 +1,9 @@ import { Metadata } from "next"; import { clsx } from "clsx"; import type Stripe from "stripe"; +import type { CurrentPhase, LookupOrgResponse, PaymentMethodsResponse, Usage } from "tier"; +import { PricingTableData } from "@/types"; import { TIER_AICOPY_FEATURE_ID } from "@/config/tierConstants"; import { pullCurrentPlan } from "@/lib/services/currentPlan"; import { pullPricingTableData } from "@/lib/services/pricingTableData"; @@ -22,29 +24,26 @@ export const metadata: Metadata = { }; export default async function BillingPage() { - const pricing = await pullPricingTableData(); - const user = await getCurrentUser(); - // Fetch the feature consumption and limit of the AI copy feature for the plan currently subscribed - const featureLimits = await tier.lookupLimit(`org:${user?.id}`, TIER_AICOPY_FEATURE_ID); + let [pricing, featureLimits, phase, org, paymentMethodResponse] = await Promise.all([ + pullPricingTableData(), + // Fetch the feature consumption and limit of the AI copy feature for the plan currently subscribed + tier.lookupLimit(`org:${user?.id}`, TIER_AICOPY_FEATURE_ID), + // Fetch the phase data of the current subscription + tier.lookupPhase(`org:${user?.id}`), + // Fetch organization/user details + tier.lookupOrg(`org:${user?.id}`), + // Fetch the saved payment methods + tier.lookupPaymentMethods(`org:${user?.id}`), + ]); const usageLimit = featureLimits.limit; const used = featureLimits.used; - // Fetch the phase data of the current subscription - const phase = await tier.lookupPhase(`org:${user?.id}`); - console.log(phase.current?.end); - // Fetch the current plan from the pricing table data const currentPlan = await pullCurrentPlan(phase, pricing); - // Fetch organization/user details - const org = await tier.lookupOrg(`org:${user?.id}`); - - // Fetch the saved payment methods - const paymentMethodResponse = await tier.lookupPaymentMethods(`org:${user?.id}`); - const paymentMethod = paymentMethodResponse.methods[0] as unknown as Stripe.PaymentMethod; return (