Skip to content

Commit acfe028

Browse files
committed
Add getPostHogUrl util for region-aware URLs
1 parent a2ebca0 commit acfe028

5 files changed

Lines changed: 22 additions & 22 deletions

File tree

apps/code/src/renderer/features/billing/stores/seatStore.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useAuthStore } from "@features/auth/stores/authStore";
2-
import { getCloudUrlFromRegion } from "@shared/constants/oauth";
2+
import { getPostHogUrl } from "@shared/utils/urls";
33
import type { SeatData } from "@shared/types/seat";
44
import { PLAN_FREE, PLAN_PRO } from "@shared/types/seat";
55
import { electronStorage } from "@utils/electronStorage";
@@ -52,9 +52,7 @@ function parseFetcherError(
5252
}
5353

5454
function getBillingUrl(): string {
55-
const region = useAuthStore.getState().cloudRegion;
56-
const base = region ? getCloudUrlFromRegion(region) : "http://localhost:8010";
57-
return `${base}/organization/billing`;
55+
return getPostHogUrl("/organization/billing");
5856
}
5957

6058
function handleSeatError(

apps/code/src/renderer/features/settings/components/sections/GeneralSettings.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
Text,
2020
} from "@radix-ui/themes";
2121
import { useTRPC } from "@renderer/trpc";
22-
import { getCloudUrlFromRegion } from "@shared/constants/oauth";
22+
import { getPostHogUrl } from "@shared/utils/urls";
2323
import { ANALYTICS_EVENTS } from "@shared/types/analytics";
2424
import type { ThemePreference } from "@stores/themeStore";
2525
import { useThemeStore } from "@stores/themeStore";
@@ -34,7 +34,6 @@ export function GeneralSettings() {
3434
const isAuthenticated = useAuthStateValue(
3535
(state) => state.status === "authenticated",
3636
);
37-
const cloudRegion = useAuthStateValue((state) => state.cloudRegion);
3837

3938
// Appearance state
4039
const theme = useThemeStore((state) => state.theme);
@@ -214,13 +213,11 @@ export function GeneralSettings() {
214213
[hedgehogMode, setHedgehogMode],
215214
);
216215

217-
const accountUrl = cloudRegion
218-
? `${getCloudUrlFromRegion(cloudRegion)}/settings/user`
219-
: null;
216+
const accountUrl = getPostHogUrl("/settings/user");
220217

221218
return (
222219
<Flex direction="column">
223-
{isAuthenticated && accountUrl && (
220+
{isAuthenticated && (
224221
<SettingRow
225222
label="Manage Account"
226223
description="Manage your account and billing on PostHog"
@@ -505,13 +502,11 @@ export function GeneralSettings() {
505502
}
506503

507504
function HedgehogDescription() {
508-
const cloudRegion = useAuthStateValue((state) => state.cloudRegion);
509505
const projectId = useAuthStateValue((state) => state.projectId);
510506

511-
const customizeUrl =
512-
cloudRegion && projectId
513-
? `${getCloudUrlFromRegion(cloudRegion)}/project/${projectId}/settings/user-customization`
514-
: null;
507+
const customizeUrl = projectId
508+
? getPostHogUrl(`/project/${projectId}/settings/user-customization`)
509+
: null;
515510

516511
return (
517512
<Flex direction="column" gap="1">

apps/code/src/renderer/features/settings/components/sections/PlanUsageSettings.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useAuthStore } from "@features/auth/stores/authStore";
21
import { useSeatStore } from "@features/billing/stores/seatStore";
32
import { useSeat } from "@hooks/useSeat";
43
import {
@@ -14,7 +13,7 @@ import {
1413
Spinner,
1514
Text,
1615
} from "@radix-ui/themes";
17-
import { getCloudUrlFromRegion } from "@shared/constants/oauth";
16+
import { getPostHogUrl } from "@shared/utils/urls";
1817

1918
export function PlanUsageSettings() {
2019
const {
@@ -272,11 +271,8 @@ export function PlanUsageSettings() {
272271
size="1"
273272
variant="outline"
274273
onClick={() => {
275-
const region = useAuthStore.getState().cloudRegion;
276-
const base = region
277-
? getCloudUrlFromRegion(region)
278-
: "http://localhost:8010";
279-
window.open(`${base}/organization/billing`, "_blank");
274+
const url = getPostHogUrl("/organization/billing");
275+
window.open(url, "_blank");
280276
}}
281277
>
282278
Open

apps/code/src/shared/constants/oauth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function getCloudUrlFromRegion(region: CloudRegion): string {
6464
}
6565
}
6666

67+
6768
export function getOauthClientIdFromRegion(region: CloudRegion): string {
6869
switch (region) {
6970
case "us":

apps/code/src/shared/utils/urls.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { useAuthStore } from "@features/auth/stores/authStore";
2+
import { getCloudUrlFromRegion } from "@shared/constants/oauth";
3+
4+
export function getPostHogUrl(path: string): string {
5+
const region = useAuthStore.getState().cloudRegion;
6+
const base = region
7+
? getCloudUrlFromRegion(region)
8+
: "http://localhost:8010";
9+
return `${base}${path.startsWith("/") ? path : `/${path}`}`;
10+
}

0 commit comments

Comments
 (0)