Skip to content

Commit b45045d

Browse files
committed
fix posthog fetching
1 parent 7179f98 commit b45045d

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

ui/src/lib/env.server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export type Env = {
1111
STATESMAN_BACKEND_URL: string
1212
WORKOS_REDIRECT_URI: string
1313
ORCHESTRATOR_GITHUB_APP_URL: string
14+
POSTHOG_KEY?: string
15+
POSTHOG_HOST?: string
1416
}
1517

1618
export const getPublicServerConfig = createServerFn({ method: 'GET' })
@@ -21,5 +23,7 @@ export const getPublicServerConfig = createServerFn({ method: 'GET' })
2123
STATESMAN_BACKEND_URL: process.env.STATESMAN_BACKEND_URL ?? '',
2224
WORKOS_REDIRECT_URI: process.env.WORKOS_REDIRECT_URI ?? '',
2325
ORCHESTRATOR_GITHUB_APP_URL: process.env.ORCHESTRATOR_GITHUB_APP_URL ?? '',
26+
POSTHOG_KEY: process.env.POSTHOG_KEY || process.env.NEXT_PUBLIC_POSTHOG_KEY || process.env.VITE_PUBLIC_POSTHOG_KEY || '',
27+
POSTHOG_HOST: process.env.POSTHOG_HOST || process.env.NEXT_PUBLIC_POSTHOG_HOST || process.env.VITE_PUBLIC_POSTHOG_HOST || 'https://app.posthog.com',
2428
} as Env
2529
})

ui/src/routes/__root.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,30 @@ export const Route = createRootRoute({
4545
],
4646
}),
4747
loader: async ({ context }) => {
48-
const { user } = context;
48+
const { user, publicServerConfig } = context as any;
4949
// Only fetch sign-in URL if user is not authenticated
5050
const url = !user ? await getSignInUrl() : null;
5151
return {
5252
user,
5353
url,
54-
};
54+
publicServerConfig,
55+
} as any;
5556
},
5657
component: DashboardRootComponent,
5758
notFoundComponent: () => <div>Not Found</div>,
5859
});
5960

6061
function DashboardRootComponent() {
62+
const data = (Route as any).useLoaderData?.() || {};
6163
return (
62-
<DashboardRootDocument>
64+
<DashboardRootDocument publicServerConfig={data.publicServerConfig}>
6365
<Outlet />
6466
<TanStackRouterDevtools position="bottom-right" />
6567
</DashboardRootDocument>
6668
);
6769
}
6870

69-
function DashboardRootDocument({ children }: Readonly<{ children: ReactNode }>) {
71+
function DashboardRootDocument({ children, publicServerConfig }: Readonly<{ children: ReactNode, publicServerConfig?: any }>) {
7072
return (
7173
<html>
7274
<head>
@@ -84,14 +86,14 @@ function DashboardRootDocument({ children }: Readonly<{ children: ReactNode }>)
8486
<link rel="apple-touch-icon" href="/favicon.png" />
8587
</head>
8688
<body>
87-
{import.meta.env.VITE_PUBLIC_POSTHOG_KEY ? (
89+
{publicServerConfig?.POSTHOG_KEY ? (
8890
<PostHogProvider
89-
apiKey={import.meta.env.VITE_PUBLIC_POSTHOG_KEY}
91+
apiKey={publicServerConfig.POSTHOG_KEY}
9092
options={{
91-
api_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
93+
api_host: publicServerConfig.POSTHOG_HOST,
9294
defaults: '2025-05-24',
9395
capture_exceptions: true,
94-
debug: import.meta.env.MODE === 'development',
96+
debug: false,
9597
}}
9698
>
9799
{children}

ui/src/routes/_authenticated/_dashboard/dashboard/units.index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ function formatBytes(bytes: number) {
5353
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
5454
}
5555

56-
function formatDate(date: Date) {
57-
return date.toLocaleDateString('en-US', {
56+
function formatDate(value: any) {
57+
if (!value) return '—'
58+
const d = value instanceof Date ? value : new Date(value)
59+
if (isNaN(d.getTime())) return '—'
60+
return d.toLocaleString('en-US', {
5861
year: 'numeric',
5962
month: 'short',
6063
day: 'numeric',
@@ -124,7 +127,7 @@ function RouteComponent() {
124127
...tempUnit,
125128
locked: false,
126129
size: 0,
127-
updatedAt: new Date(),
130+
updated: new Date(),
128131
isOptimistic: true
129132
}, ...prev])
130133
}
@@ -206,7 +209,7 @@ function RouteComponent() {
206209
{unit.isOptimistic && <span className="ml-2 text-xs text-muted-foreground">(Creating...)</span>}
207210
</TableCell>
208211
<TableCell>{formatBytes(unit.size)}</TableCell>
209-
<TableCell>{formatDate(unit.updatedAt || new Date())}</TableCell>
212+
<TableCell>{formatDate(unit.updated)}</TableCell>
210213
<TableCell className="text-right">
211214
{!unit.isOptimistic && (
212215
<Button variant="ghost" asChild className="justify-end">

ui/src/vite-env.d.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
11
/// <reference types="vite/client" />
2-
3-
interface ImportMetaEnv {
4-
readonly VITE_PUBLIC_POSTHOG_KEY?: string
5-
readonly VITE_PUBLIC_POSTHOG_HOST?: string
6-
readonly MODE?: string
7-
}
8-
9-
interface ImportMeta {
10-
readonly env: ImportMetaEnv
11-
}
12-
13-

0 commit comments

Comments
 (0)