Skip to content

Commit

Permalink
fix: settings billing issues for selfhosted (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
McPizza0 authored Aug 31, 2024
1 parent 63048b2 commit 04d31f6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
7 changes: 7 additions & 0 deletions apps/platform/trpc/routers/orgRouter/iCanHaz/iCanHazRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const billingRouter = router({
plan: true
}
});
const orgPlan = orgBillingResponse?.plan ?? 'free';
const orgPlan = orgBillingResponse?.plan;
return {
isPro: orgPlan === 'pro'
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -56,11 +59,15 @@ export default function SettingsSidebarContent() {
to: `/${orgShortcode}/settings/org`,
icon: <Buildings />
},
{
label: 'Billing',
to: `/${orgShortcode}/settings/org/setup/billing`,
icon: <CreditCard />
}
...(hasBilling
? [
{
label: 'Billing',
to: `/${orgShortcode}/settings/org/setup/billing`,
icon: <CreditCard />
}
]
: [])
];

const orgUserLinks: NavLinks[] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 21 additions & 2 deletions apps/web/src/app/[orgShortcode]/settings/user/addresses/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,7 +95,16 @@ export default function Page() {
{orgMember?.account?.username}@{domain}
</span>
<Button
disabled={!proStatus?.isPro || !personalAddresses.hasUninBonus}>
onClick={() =>
setClaimAddressValue(
`${orgMember?.account?.username}@${domain}`
)
}
disabled={
hasBilling === true
? !proStatus?.isPro && !personalAddresses.hasUninBonus
: false
}>
Claim
</Button>
</div>
Expand Down
1 change: 1 addition & 0 deletions ee/apps/billing/trpc/routers/iCanHazRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 04d31f6

Please sign in to comment.