Skip to content

Commit df3ef35

Browse files
committed
Revert "feat: route frontend billing through control plane"
This reverts commit a081804.
1 parent 39c53a0 commit df3ef35

15 files changed

Lines changed: 186 additions & 461 deletions

File tree

frontend/app/src/components/modals/welcome-modal.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ import { HatchetLogo } from '@/components/v1/ui/hatchet-logo';
99
import { Spinner } from '@/components/v1/ui/loading.tsx';
1010
import { useAnalytics } from '@/hooks/use-analytics';
1111
import { queries } from '@/lib/api';
12-
import { controlPlaneApi } from '@/lib/api/api';
12+
import { cloudApi } from '@/lib/api/api';
1313
import {
1414
SubscriptionPlanCode,
1515
SubscriptionPeriod,
16-
UpdateTenantSubscriptionResponse,
17-
} from '@/lib/api/generated/control-plane/data-contracts';
18-
import { ContentType } from '@/lib/api/generated/control-plane/http-client';
16+
} from '@/lib/api/generated/cloud/data-contracts';
1917
import { appRoutes } from '@/router';
2018
import { useMutation, useQuery } from '@tanstack/react-query';
2119
import { useNavigate } from '@tanstack/react-router';
@@ -33,7 +31,7 @@ export function WelcomeModal({ tenantId, open, onClose }: WelcomeModalProps) {
3331
const navigate = useNavigate();
3432

3533
const welcomePlansQuery = useQuery({
36-
...queries.controlPlane.subscriptionPlans(),
34+
...queries.cloud.subscriptionPlans(),
3735
enabled: open,
3836
});
3937

@@ -43,24 +41,16 @@ export function WelcomeModal({ tenantId, open, onClose }: WelcomeModalProps) {
4341
if (!tenantId) {
4442
throw new Error('No tenant id');
4543
}
46-
const response =
47-
await controlPlaneApi.request<UpdateTenantSubscriptionResponse>({
48-
path: `/api/v1/control-plane/billing/tenants/${tenantId}/subscription`,
49-
method: 'PATCH',
50-
body: {
51-
plan: SubscriptionPlanCode.Developer,
52-
period: SubscriptionPeriod.Monthly,
53-
},
54-
secure: true,
55-
type: ContentType.Json,
56-
format: 'json',
57-
});
44+
const response = await cloudApi.tenantSubscriptionUpdate(tenantId, {
45+
plan: SubscriptionPlanCode.Developer,
46+
period: SubscriptionPeriod.Monthly,
47+
});
5848
return response.data;
5949
},
6050
onSuccess: (data) => {
6151
localStorage.removeItem(WELCOME_KEY);
6252
onClose();
63-
if (data?.checkoutUrl) {
53+
if (data && 'checkoutUrl' in data) {
6454
window.location.href = data.checkoutUrl;
6555
}
6656
},

frontend/app/src/components/v1/cloud/billing/plan-selector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
Coupon,
1313
SubscriptionPlan,
1414
SubscriptionPlanFeatureGroup,
15-
} from '@/lib/api/generated/control-plane/data-contracts';
15+
} from '@/lib/api/generated/cloud/data-contracts';
1616
import { CheckIcon, Cross2Icon } from '@radix-ui/react-icons';
1717
import { useQuery } from '@tanstack/react-query';
1818
import { useCallback, useMemo } from 'react';
@@ -70,7 +70,7 @@ export function PlanSelector({
7070
}: PlanSelectorProps) {
7171
const activeCoupon = coupons?.[0];
7272
const plansQuery = useQuery({
73-
...queries.controlPlane.subscriptionPlans(),
73+
...queries.cloud.subscriptionPlans(),
7474
});
7575

7676
const plans = plansQuery.data?.plans;

frontend/app/src/components/v1/cloud/billing/subscription.tsx

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ import {
2121
} from '@/components/v1/ui/tooltip';
2222
import { useCurrentTenantId, useTenantDetails } from '@/hooks/use-tenant';
2323
import { queries } from '@/lib/api';
24-
import { controlPlaneApi } from '@/lib/api/api';
24+
import { cloudApi } from '@/lib/api/api';
2525
import {
2626
TenantSubscription,
2727
SubscriptionPlan,
2828
SubscriptionPlanCode,
2929
SubscriptionPeriod,
3030
Coupon,
31-
UpdateTenantSubscriptionResponse,
32-
} from '@/lib/api/generated/control-plane/data-contracts';
33-
import { ContentType } from '@/lib/api/generated/control-plane/http-client';
31+
} from '@/lib/api/generated/cloud/data-contracts';
3432
import { useApiError } from '@/lib/hooks';
3533
import queryClient from '@/query-client';
3634
import { useMutation, useQuery } from '@tanstack/react-query';
@@ -68,7 +66,7 @@ export const Subscription: React.FC<SubscriptionProps> = ({
6866
const { handleApiError } = useApiError({});
6967
const [portalLoading, setPortalLoading] = useState(false);
7068
const creditBalanceQuery = useQuery({
71-
...queries.controlPlane.creditBalance(tenantId),
69+
...queries.cloud.creditBalance(tenantId),
7270
});
7371

7472
const creditBalance = useMemo(() => {
@@ -112,12 +110,7 @@ export const Subscription: React.FC<SubscriptionProps> = ({
112110
return;
113111
}
114112
setPortalLoading(true);
115-
const link = await controlPlaneApi.request<{ url?: string }>({
116-
path: `/api/v1/control-plane/billing/tenants/${tenantId}/billing-portal-link`,
117-
method: 'GET',
118-
secure: true,
119-
format: 'json',
120-
});
113+
const link = await cloudApi.billingPortalLinkGet(tenantId);
121114
window.open(link.data.url, '_blank');
122115
} catch (e) {
123116
handleApiError(e as any);
@@ -131,22 +124,14 @@ export const Subscription: React.FC<SubscriptionProps> = ({
131124
mutationFn: async ({ plan_code }: { plan_code: string }) => {
132125
const [plan, period] = plan_code.split('_');
133126
setLoading(plan_code);
134-
const response =
135-
await controlPlaneApi.request<UpdateTenantSubscriptionResponse>({
136-
path: `/api/v1/control-plane/billing/tenants/${tenantId}/subscription`,
137-
method: 'PATCH',
138-
body: {
139-
plan: plan as SubscriptionPlanCode,
140-
period: period as SubscriptionPeriod,
141-
},
142-
secure: true,
143-
type: ContentType.Json,
144-
format: 'json',
145-
});
127+
const response = await cloudApi.tenantSubscriptionUpdate(tenantId, {
128+
plan: plan as SubscriptionPlanCode,
129+
period: period as SubscriptionPeriod,
130+
});
146131
return response.data;
147132
},
148133
onSuccess: async (data) => {
149-
if (data?.checkoutUrl) {
134+
if (data && 'checkoutUrl' in data) {
150135
window.location.href = data.checkoutUrl;
151136
return;
152137
}
@@ -156,7 +141,7 @@ export const Subscription: React.FC<SubscriptionProps> = ({
156141
queryKey: queries.tenantResourcePolicy.get(tenantId).queryKey,
157142
}),
158143
queryClient.invalidateQueries({
159-
queryKey: queries.controlPlane.billing(tenantId).queryKey,
144+
queryKey: queries.cloud.billing(tenantId).queryKey,
160145
}),
161146
]);
162147

frontend/app/src/hooks/use-tenant.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ export function useTenantDetails() {
142142
const { cloud, isCloudEnabled } = useCloud();
143143

144144
const billingState = useQuery({
145-
...queries.controlPlane.billing(tenant?.metadata?.id || ''),
145+
...queries.cloud.billing(tenant?.metadata?.id || ''),
146146
enabled: !!tenant?.metadata?.id && isCloudEnabled && !!cloud?.canBill,
147147
refetchInterval: pollBilling ? 1000 : false,
148148
retry: false,
149149
});
150150

151151
const paymentMethodsQuery = useQuery({
152-
...queries.controlPlane.paymentMethods(tenant?.metadata?.id || ''),
152+
...queries.cloud.paymentMethods(tenant?.metadata?.id || ''),
153153
enabled: !!tenant && !!cloud?.canBill,
154154
retry: false,
155155
});

frontend/app/src/lib/api/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ declare module 'axios' {
1919
// When set, the interceptor skips the localStorage fallback.
2020
xTenantId?: string;
2121
// Forces the exchange token interceptor to run even for non-tenant-scoped
22-
// endpoints (e.g. /api/v1/control-plane/billing/plans).
22+
// endpoints (e.g. /api/v1/billing/plans).
2323
useExchangeToken?: boolean;
2424
}
2525
// InternalAxiosRequestConfig is what the interceptor receives after Axios

frontend/app/src/lib/api/generated/cloud/Api.ts

Lines changed: 142 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)