Skip to content

Commit 04d31f6

Browse files
authored
fix: settings billing issues for selfhosted (#584)
1 parent 63048b2 commit 04d31f6

File tree

6 files changed

+52
-10
lines changed

6 files changed

+52
-10
lines changed

apps/platform/trpc/routers/orgRouter/iCanHaz/iCanHazRouter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { router, orgProcedure, createCallerFactory } from '~platform/trpc/trpc';
22
import { billingTrpcClient } from '~platform/utils/tRPCServerClients';
33

44
export const iCanHazRouter = router({
5+
billing: orgProcedure.query(async ({ ctx }) => {
6+
const { selfHosted } = ctx;
7+
if (selfHosted) {
8+
return false;
9+
}
10+
return await billingTrpcClient.iCanHaz.billing.query();
11+
}),
512
domain: orgProcedure.query(async ({ ctx }) => {
613
const { org, selfHosted } = ctx;
714
if (selfHosted) {

apps/platform/trpc/routers/orgRouter/setup/billingRouter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const billingRouter = router({
126126
plan: true
127127
}
128128
});
129-
const orgPlan = orgBillingResponse?.plan ?? 'free';
129+
const orgPlan = orgBillingResponse?.plan;
130130
return {
131131
isPro: orgPlan === 'pro'
132132
};

apps/web/src/app/[orgShortcode]/settings/_components/settings-sidebar.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ type NavLinks = {
2727

2828
export default function SettingsSidebarContent() {
2929
const orgShortcode = useOrgShortcode();
30+
const { data: hasBilling } = platform.org.iCanHaz.billing.useQuery({
31+
orgShortcode
32+
});
3033

3134
const { data: isAdmin } =
3235
platform.org.users.members.isOrgMemberAdmin.useQuery({
@@ -56,11 +59,15 @@ export default function SettingsSidebarContent() {
5659
to: `/${orgShortcode}/settings/org`,
5760
icon: <Buildings />
5861
},
59-
{
60-
label: 'Billing',
61-
to: `/${orgShortcode}/settings/org/setup/billing`,
62-
icon: <CreditCard />
63-
}
62+
...(hasBilling
63+
? [
64+
{
65+
label: 'Billing',
66+
to: `/${orgShortcode}/settings/org/setup/billing`,
67+
icon: <CreditCard />
68+
}
69+
]
70+
: [])
6471
];
6572

6673
const orgUserLinks: NavLinks[] = [

apps/web/src/app/[orgShortcode]/settings/org/setup/billing/page.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
'use client';
22

3+
import { useOrgShortcode, useOrgScopedRouter } from '@/src/hooks/use-params';
34
import { Skeleton } from '@/src/components/shadcn-ui/skeleton';
45
import { PageTitle } from '../../../_components/page-title';
56
import { Button } from '@/src/components/shadcn-ui/button';
67
import { PricingTable } from './_components/plans-table';
7-
import { useOrgShortcode } from '@/src/hooks/use-params';
8-
import { useEffect, useState } from 'react';
8+
import { useState, useEffect } from 'react';
99
import CalEmbed from '@calcom/embed-react';
1010
import { platform } from '@/src/lib/trpc';
1111

1212
export default function Page() {
1313
const orgShortcode = useOrgShortcode();
14+
const { scopedRedirect } = useOrgScopedRouter();
15+
16+
const { data: hasBilling } = platform.org.iCanHaz.billing.useQuery({
17+
orgShortcode
18+
});
19+
20+
if (hasBilling === false) scopedRedirect(`/settings`);
21+
1422
const { data, isLoading } =
1523
platform.org.setup.billing.getOrgBillingOverview.useQuery({
1624
orgShortcode

apps/web/src/app/[orgShortcode]/settings/user/addresses/page.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,19 @@ export default function Page() {
1616
null
1717
);
1818

19-
const { data: proStatus } = platform.org.setup.billing.isPro.useQuery({
19+
const { data: hasBilling } = platform.org.iCanHaz.billing.useQuery({
2020
orgShortcode
2121
});
22+
23+
const { data: proStatus } = platform.org.setup.billing.isPro.useQuery(
24+
{
25+
orgShortcode
26+
},
27+
{
28+
enabled: hasBilling === true
29+
}
30+
);
31+
2232
const { data: orgMember } =
2333
platform.account.profile.getOrgMemberProfile.useQuery({
2434
orgShortcode
@@ -85,7 +95,16 @@ export default function Page() {
8595
{orgMember?.account?.username}@{domain}
8696
</span>
8797
<Button
88-
disabled={!proStatus?.isPro || !personalAddresses.hasUninBonus}>
98+
onClick={() =>
99+
setClaimAddressValue(
100+
`${orgMember?.account?.username}@${domain}`
101+
)
102+
}
103+
disabled={
104+
hasBilling === true
105+
? !proStatus?.isPro && !personalAddresses.hasUninBonus
106+
: false
107+
}>
89108
Claim
90109
</Button>
91110
</div>

ee/apps/billing/trpc/routers/iCanHazRouter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TRPCError } from '@trpc/server';
66
import { z } from 'zod';
77

88
export const iCanHazRouter = router({
9+
billing: protectedProcedure.query(() => true),
910
domain: protectedProcedure
1011
.input(z.object({ orgId: z.number() }))
1112
.query(async ({ ctx, input }) => {

0 commit comments

Comments
 (0)