diff --git a/apps/platform/trpc/routers/orgRouter/iCanHaz/iCanHazRouter.ts b/apps/platform/trpc/routers/orgRouter/iCanHaz/iCanHazRouter.ts index c6320c3e..46e02464 100644 --- a/apps/platform/trpc/routers/orgRouter/iCanHaz/iCanHazRouter.ts +++ b/apps/platform/trpc/routers/orgRouter/iCanHaz/iCanHazRouter.ts @@ -2,6 +2,13 @@ import { router, orgProcedure, createCallerFactory } from '~platform/trpc/trpc'; import { billingTrpcClient } from '~platform/utils/tRPCServerClients'; export const iCanHazRouter = router({ + billing: orgProcedure.query(async ({ ctx }) => { + const { selfHosted } = ctx; + if (selfHosted) { + return false; + } + return await billingTrpcClient.iCanHaz.billing.query(); + }), domain: orgProcedure.query(async ({ ctx }) => { const { org, selfHosted } = ctx; if (selfHosted) { diff --git a/apps/platform/trpc/routers/orgRouter/setup/billingRouter.ts b/apps/platform/trpc/routers/orgRouter/setup/billingRouter.ts index c84ebc34..f6464afd 100644 --- a/apps/platform/trpc/routers/orgRouter/setup/billingRouter.ts +++ b/apps/platform/trpc/routers/orgRouter/setup/billingRouter.ts @@ -126,7 +126,7 @@ export const billingRouter = router({ plan: true } }); - const orgPlan = orgBillingResponse?.plan ?? 'free'; + const orgPlan = orgBillingResponse?.plan; return { isPro: orgPlan === 'pro' }; diff --git a/apps/web/src/app/[orgShortcode]/settings/_components/settings-sidebar.tsx b/apps/web/src/app/[orgShortcode]/settings/_components/settings-sidebar.tsx index 153453ce..ed055e0d 100644 --- a/apps/web/src/app/[orgShortcode]/settings/_components/settings-sidebar.tsx +++ b/apps/web/src/app/[orgShortcode]/settings/_components/settings-sidebar.tsx @@ -27,6 +27,9 @@ type NavLinks = { export default function SettingsSidebarContent() { const orgShortcode = useOrgShortcode(); + const { data: hasBilling } = platform.org.iCanHaz.billing.useQuery({ + orgShortcode + }); const { data: isAdmin } = platform.org.users.members.isOrgMemberAdmin.useQuery({ @@ -56,11 +59,15 @@ export default function SettingsSidebarContent() { to: `/${orgShortcode}/settings/org`, icon: }, - { - label: 'Billing', - to: `/${orgShortcode}/settings/org/setup/billing`, - icon: - } + ...(hasBilling + ? [ + { + label: 'Billing', + to: `/${orgShortcode}/settings/org/setup/billing`, + icon: + } + ] + : []) ]; const orgUserLinks: NavLinks[] = [ diff --git a/apps/web/src/app/[orgShortcode]/settings/org/setup/billing/page.tsx b/apps/web/src/app/[orgShortcode]/settings/org/setup/billing/page.tsx index 20ba5460..fb45acc3 100644 --- a/apps/web/src/app/[orgShortcode]/settings/org/setup/billing/page.tsx +++ b/apps/web/src/app/[orgShortcode]/settings/org/setup/billing/page.tsx @@ -1,16 +1,24 @@ 'use client'; +import { useOrgShortcode, useOrgScopedRouter } from '@/src/hooks/use-params'; import { Skeleton } from '@/src/components/shadcn-ui/skeleton'; import { PageTitle } from '../../../_components/page-title'; import { Button } from '@/src/components/shadcn-ui/button'; import { PricingTable } from './_components/plans-table'; -import { useOrgShortcode } from '@/src/hooks/use-params'; -import { useEffect, useState } from 'react'; +import { useState, useEffect } from 'react'; import CalEmbed from '@calcom/embed-react'; import { platform } from '@/src/lib/trpc'; export default function Page() { const orgShortcode = useOrgShortcode(); + const { scopedRedirect } = useOrgScopedRouter(); + + const { data: hasBilling } = platform.org.iCanHaz.billing.useQuery({ + orgShortcode + }); + + if (hasBilling === false) scopedRedirect(`/settings`); + const { data, isLoading } = platform.org.setup.billing.getOrgBillingOverview.useQuery({ orgShortcode diff --git a/apps/web/src/app/[orgShortcode]/settings/user/addresses/page.tsx b/apps/web/src/app/[orgShortcode]/settings/user/addresses/page.tsx index 1e3c374d..210ef29a 100644 --- a/apps/web/src/app/[orgShortcode]/settings/user/addresses/page.tsx +++ b/apps/web/src/app/[orgShortcode]/settings/user/addresses/page.tsx @@ -16,9 +16,19 @@ export default function Page() { null ); - const { data: proStatus } = platform.org.setup.billing.isPro.useQuery({ + const { data: hasBilling } = platform.org.iCanHaz.billing.useQuery({ orgShortcode }); + + const { data: proStatus } = platform.org.setup.billing.isPro.useQuery( + { + orgShortcode + }, + { + enabled: hasBilling === true + } + ); + const { data: orgMember } = platform.account.profile.getOrgMemberProfile.useQuery({ orgShortcode @@ -85,7 +95,16 @@ export default function Page() { {orgMember?.account?.username}@{domain} diff --git a/ee/apps/billing/trpc/routers/iCanHazRouter.ts b/ee/apps/billing/trpc/routers/iCanHazRouter.ts index fe4d3ab9..c669a10b 100644 --- a/ee/apps/billing/trpc/routers/iCanHazRouter.ts +++ b/ee/apps/billing/trpc/routers/iCanHazRouter.ts @@ -6,6 +6,7 @@ import { TRPCError } from '@trpc/server'; import { z } from 'zod'; export const iCanHazRouter = router({ + billing: protectedProcedure.query(() => true), domain: protectedProcedure .input(z.object({ orgId: z.number() })) .query(async ({ ctx, input }) => {