forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink-to-copilot-cloud.tsx
More file actions
68 lines (58 loc) · 1.92 KB
/
Copy pathlink-to-copilot-cloud.tsx
File metadata and controls
68 lines (58 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use client";
import { useEffect, useState } from "react";
import Link from "next/link";
import posthog from "posthog-js";
import { CloudIcon } from "lucide-react";
export function LinkToCopilotCloud({
className,
subPath,
asButton = true,
children,
}: {
className?: string;
subPath?: string;
asButton?: boolean;
children?: React.ReactNode;
}) {
const [isClient, setIsClient] = useState(false);
useEffect(() => {
setIsClient(true);
}, []);
// Build base URL without PostHog session ID to avoid hydration issues
const baseUrl = new URL(`https://dashboard.operations.copilotkit.ai/sign-in`);
baseUrl.searchParams.set("ref", "docs");
if (subPath) {
baseUrl.pathname += subPath;
}
// Only add PostHog session ID on client side after hydration
const [href, setHref] = useState(baseUrl.toString());
useEffect(() => {
if (isClient) {
const sessionId = posthog.get_session_id();
if (sessionId) {
const url = new URL(baseUrl.toString());
url.searchParams.set("session_id", sessionId);
setHref(url.toString());
}
}
}, [isClient, baseUrl.toString()]);
let cn = "";
if (asButton) {
cn =
"text-indigo-800 dark:text-indigo-300 ring-1 ring-indigo-200 dark:ring-indigo-900 text-sm items-center bg-gradient-to-r from-indigo-200/50 to-purple-200/80 dark:from-indigo-900/40 dark:to-purple-900/50 flex p-3 px-4 no-underline whitespace-nowrap";
cn +=
" transition-all duration-100 hover:ring-2 hover:ring-indigo-400 hover:dark:text-indigo-200 rounded-lg";
} else {
cn =
"_text-primary-600 decoration-from-font underline [text-underline-position:from-font]";
}
if (className) {
cn += ` ${className}`;
}
return (
<Link href={href} target="_blank" className={cn} suppressHydrationWarning>
{asButton ? <CloudIcon className="w-5 h-5 mr-2" /> : null}
{children ? children : "Free Developer Access"}
</Link>
);
}