From 21529da79970882dc32ac898c66c56be12c9e005 Mon Sep 17 00:00:00 2001 From: Matti Nannt Date: Thu, 13 Jul 2023 20:28:48 +0200 Subject: [PATCH] Fix billing page not showing current plan (#550) * update packages, fix error getting current subscription plan * fix billing page not showing current plan * add revalidation constant --- apps/web/app/environments/[environmentId]/people/page.tsx | 3 ++- .../[environmentId]/settings/billing/PricingTable.tsx | 6 +++--- .../[environmentId]/surveys/[surveyId]/(analysis)/data.ts | 3 ++- .../surveys/[surveyId]/(analysis)/responses/page.tsx | 4 +++- .../surveys/[surveyId]/(analysis)/summary/page.tsx | 3 ++- .../pages/api/v1/environments/[environmentId]/team/index.ts | 1 + packages/lib/constants.ts | 1 + 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/web/app/environments/[environmentId]/people/page.tsx b/apps/web/app/environments/[environmentId]/people/page.tsx index fd7f29bafb..90bf403267 100644 --- a/apps/web/app/environments/[environmentId]/people/page.tsx +++ b/apps/web/app/environments/[environmentId]/people/page.tsx @@ -1,7 +1,8 @@ -export const revalidate = 0; +export const revalidate = REVALIDATION_INTERVAL; import EmptySpaceFiller from "@/components/shared/EmptySpaceFiller"; import { truncateMiddle } from "@/lib/utils"; +import { REVALIDATION_INTERVAL } from "@formbricks/lib/constants"; import { getPeople } from "@formbricks/lib/services/person"; import { TPerson } from "@formbricks/types/v1/people"; import { PersonAvatar } from "@formbricks/ui"; diff --git a/apps/web/app/environments/[environmentId]/settings/billing/PricingTable.tsx b/apps/web/app/environments/[environmentId]/settings/billing/PricingTable.tsx index 9c0edf77ee..47a7029f29 100644 --- a/apps/web/app/environments/[environmentId]/settings/billing/PricingTable.tsx +++ b/apps/web/app/environments/[environmentId]/settings/billing/PricingTable.tsx @@ -73,9 +73,9 @@ export default function PricingTable({ environmentId, session }: PricingTablePro
-

Free

+

Free

{team.plan === "free" && } -

+

Always free. Giving back to the community.

    @@ -109,7 +109,7 @@ export default function PricingTable({ environmentId, session }: PricingTablePro
    -

    Pro

    +

    Pro

    {team.plan === "pro" && }

    All features included. Unlimited usage. diff --git a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/data.ts b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/data.ts index 1c0b6e624e..ed4e688d9b 100644 --- a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/data.ts +++ b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/data.ts @@ -10,9 +10,10 @@ export const getAnalysisData = async (surveyId: string, environmentId: string) = getSurveyResponses(surveyId), ]); if (!survey) throw new Error(`Survey not found: ${surveyId}`); + if (!team) throw new Error(`Team not found for environment: ${environmentId}`); if (survey.environmentId !== environmentId) throw new Error(`Survey not found: ${surveyId}`); const limitReached = - IS_FORMBRICKS_CLOUD && team?.plan === "free" && allResponses.length >= RESPONSES_LIMIT_FREE; + IS_FORMBRICKS_CLOUD && team.plan === "free" && allResponses.length >= RESPONSES_LIMIT_FREE; const responses = limitReached ? allResponses.slice(0, RESPONSES_LIMIT_FREE) : allResponses; const responsesCount = allResponses.length; diff --git a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/page.tsx b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/page.tsx index 652a12f6cd..63e7d25128 100644 --- a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/page.tsx +++ b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/page.tsx @@ -1,9 +1,11 @@ -export const revalidate = 0; +export const revalidate = REVALIDATION_INTERVAL; + import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions"; import ResponsePage from "@/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/ResponsePage"; import { getAnalysisData } from "@/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/data"; import { getServerSession } from "next-auth"; import ResponsesLimitReachedBanner from "../ResponsesLimitReachedBanner"; +import { REVALIDATION_INTERVAL } from "@formbricks/lib/constants"; export default async function Page({ params }) { const session = await getServerSession(authOptions); diff --git a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/page.tsx b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/page.tsx index ebddfe830c..8815358fe7 100644 --- a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/page.tsx +++ b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/page.tsx @@ -1,10 +1,11 @@ -export const revalidate = 0; +export const revalidate = REVALIDATION_INTERVAL; import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions"; import { getAnalysisData } from "@/app/environments/[environmentId]/surveys/[surveyId]/(analysis)/data"; import { getServerSession } from "next-auth"; import ResponsesLimitReachedBanner from "../ResponsesLimitReachedBanner"; import SummaryPage from "./SummaryPage"; +import { REVALIDATION_INTERVAL } from "@formbricks/lib/constants"; export default async function Page({ params }) { const session = await getServerSession(authOptions); diff --git a/apps/web/pages/api/v1/environments/[environmentId]/team/index.ts b/apps/web/pages/api/v1/environments/[environmentId]/team/index.ts index b81f0b65a4..3af4f870b7 100644 --- a/apps/web/pages/api/v1/environments/[environmentId]/team/index.ts +++ b/apps/web/pages/api/v1/environments/[environmentId]/team/index.ts @@ -38,6 +38,7 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse) id: true, name: true, stripeCustomerId: true, + plan: true, }, }); diff --git a/packages/lib/constants.ts b/packages/lib/constants.ts index 9b2efee6a7..56e8994df7 100644 --- a/packages/lib/constants.ts +++ b/packages/lib/constants.ts @@ -1,5 +1,6 @@ export const RESPONSES_LIMIT_FREE = 100; export const IS_FORMBRICKS_CLOUD = process.env.NEXT_PUBLIC_IS_FORMBRICKS_CLOUD === "1"; +export const REVALIDATION_INTERVAL = process.env.NODE_ENV === "production" ? 30 : 0; // 30 seconds in production, 10 seconds in development // URLs const VERCEL_URL = process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : "";