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
64 lines (54 loc) · 1.63 KB
/
Copy pathlink-to-copilot-cloud.tsx
File metadata and controls
64 lines (54 loc) · 1.63 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
"use client";
import { useEffect, useState } from "react";
import Link from "next/link";
import { useAuth } from "@clerk/nextjs";
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);
const { userId } = useAuth();
useEffect(() => {
setIsClient(true);
}, []);
if (!isClient) {
return null;
}
const url = new URL(`https://go.copilotkit.ai/copilot-cloud-button-docs`);
url.searchParams.set("ref", "docs");
const sessionId = posthog.get_session_id();
if (sessionId) {
url.searchParams.set("session_id", sessionId);
}
if (subPath) {
url.pathname += subPath;
}
let cn = `${className}`;
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";
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]";
}
return (
<Link
href={url.toString()}
target="_blank"
className={cn}
>
{asButton ? <CloudIcon className="w-5 h-5 mr-2" /> : null}
{
children ? children : userId ? "Go to Copilot Platform" : "Sign up for Copilot Platform"
}
</Link>
);
}