diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/billing/layout.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/billing/layout.tsx new file mode 100644 index 0000000000..8d20a6d4cc --- /dev/null +++ b/apps/web/app/(app)/environments/[environmentId]/settings/billing/layout.tsx @@ -0,0 +1,36 @@ +import { Metadata } from "next"; +import { getServerSession } from "next-auth"; +import { notFound } from "next/navigation"; + +import { authOptions } from "@formbricks/lib/authOptions"; +import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants"; +import { getMembershipByUserIdTeamId } from "@formbricks/lib/membership/service"; +import { getAccessFlags } from "@formbricks/lib/membership/utils"; +import { getTeamByEnvironmentId } from "@formbricks/lib/team/service"; +import { ErrorComponent } from "@formbricks/ui/ErrorComponent"; + +export const metadata: Metadata = { + title: "Billing", +}; + +export default async function BillingLayout({ children, params }) { + if (!IS_FORMBRICKS_CLOUD) { + notFound(); + } + + const session = await getServerSession(authOptions); + const team = await getTeamByEnvironmentId(params.environmentId); + + if (!session) { + throw new Error("Unauthorized"); + } + if (!team) { + throw new Error("Team not found"); + } + + const currentUserMembership = await getMembershipByUserIdTeamId(session?.user.id, team.id); + const { isAdmin, isOwner } = getAccessFlags(currentUserMembership?.role); + const isPricingDisabled = !isOwner && !isAdmin; + + return <>{!isPricingDisabled ? <>{children} : }; +} diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/billing/page.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/billing/page.tsx index cc97c5a210..da026b34ca 100644 --- a/apps/web/app/(app)/environments/[environmentId]/settings/billing/page.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/settings/billing/page.tsx @@ -1,37 +1,15 @@ -import { getServerSession } from "next-auth"; -import { notFound } from "next/navigation"; - -import { authOptions } from "@formbricks/lib/authOptions"; -import { - IS_FORMBRICKS_CLOUD, - PRICING_APPSURVEYS_FREE_RESPONSES, - PRICING_USERTARGETING_FREE_MTU, -} from "@formbricks/lib/constants"; -import { getMembershipByUserIdTeamId } from "@formbricks/lib/membership/service"; -import { getAccessFlags } from "@formbricks/lib/membership/utils"; +import { PRICING_APPSURVEYS_FREE_RESPONSES, PRICING_USERTARGETING_FREE_MTU } from "@formbricks/lib/constants"; import { getMonthlyActiveTeamPeopleCount, getMonthlyTeamResponseCount, getTeamByEnvironmentId, } from "@formbricks/lib/team/service"; -import { ErrorComponent } from "@formbricks/ui/ErrorComponent"; import SettingsTitle from "../components/SettingsTitle"; import PricingTable from "./components/PricingTable"; export default async function BillingPage({ params }) { - if (!IS_FORMBRICKS_CLOUD) { - notFound(); - } - - const session = await getServerSession(authOptions); - const team = await getTeamByEnvironmentId(params.environmentId); - - if (!session) { - throw new Error("Unauthorized"); - } - if (!team) { throw new Error("Team not found"); } @@ -40,26 +18,19 @@ export default async function BillingPage({ params }) { getMonthlyActiveTeamPeopleCount(team.id), getMonthlyTeamResponseCount(team.id), ]); - const currentUserMembership = await getMembershipByUserIdTeamId(session?.user.id, team.id); - const { isAdmin, isOwner } = getAccessFlags(currentUserMembership?.role); - const isPricingDisabled = !isOwner && !isAdmin; return ( <>
- {!isPricingDisabled ? ( - - ) : ( - - )} +
); diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/billing/unlimited/page.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/billing/unlimited/page.tsx index 19be704888..d756971357 100644 --- a/apps/web/app/(app)/environments/[environmentId]/settings/billing/unlimited/page.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/settings/billing/unlimited/page.tsx @@ -1,26 +1,12 @@ -import { getServerSession } from "next-auth"; -import { notFound, redirect } from "next/navigation"; +import { redirect } from "next/navigation"; import { StripePriceLookupKeys } from "@formbricks/ee/billing/lib/constants"; -import { authOptions } from "@formbricks/lib/authOptions"; -import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants"; import { getTeamByEnvironmentId } from "@formbricks/lib/team/service"; import { upgradePlanAction } from "../actions"; export default async function UnlimitedPage({ params }) { - if (!IS_FORMBRICKS_CLOUD) { - notFound(); - } - - const session = await getServerSession(authOptions); - const team = await getTeamByEnvironmentId(params.environmentId); - - if (!session) { - throw new Error("Unauthorized"); - } - if (!team) { throw new Error("Team not found"); } diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/billing/unlimited99/page.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/billing/unlimited99/page.tsx index 16d54a5f3f..1d761aca55 100644 --- a/apps/web/app/(app)/environments/[environmentId]/settings/billing/unlimited99/page.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/settings/billing/unlimited99/page.tsx @@ -1,26 +1,12 @@ -import { getServerSession } from "next-auth"; -import { notFound, redirect } from "next/navigation"; +import { redirect } from "next/navigation"; import { StripePriceLookupKeys } from "@formbricks/ee/billing/lib/constants"; -import { authOptions } from "@formbricks/lib/authOptions"; -import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants"; import { getTeamByEnvironmentId } from "@formbricks/lib/team/service"; import { upgradePlanAction } from "../actions"; export default async function UnlimitedPage({ params }) { - if (!IS_FORMBRICKS_CLOUD) { - notFound(); - } - - const session = await getServerSession(authOptions); - const team = await getTeamByEnvironmentId(params.environmentId); - - if (!session) { - throw new Error("Unauthorized"); - } - if (!team) { throw new Error("Team not found"); }