@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 145 lines 4.84 KB
Raw
1 import { T3CHAT_PLAN_TUNNEL_LIMITS, type RelayT3ChatLink } from "@t3tools/contracts/relay";
2 import { MessageSquareIcon } from "lucide-react";
3 import { T, useGT, Var } from "gt-react";
4 import type { ReactNode } from "react";
5
6 import { useManagedTunnelUsage } from "../../cloud/managedRelayState";
7 import { T3CHAT_SUBSCRIPTION_URL, TunnelUsageMeter } from "../cloud/TunnelUsage";
8 import { Button } from "../ui/button";
9 import {
10 ClerkUserProfilePage,
11 ClerkUserProfileRefreshButton,
12 ClerkUserProfileRow,
13 } from "./ClerkUserProfilePage";
14 import { useT3ChatLink } from "./useT3ChatLink";
15
16 function planLabel(link: RelayT3ChatLink): ReactNode {
17 switch (link.plan) {
18 case "premier":
19 return (
20 <T>
21 Premier · up to <Var>{T3CHAT_PLAN_TUNNEL_LIMITS.premier}</Var> tunnels
22 </T>
23 );
24 case "pro":
25 return (
26 <T>
27 Pro · up to <Var>{T3CHAT_PLAN_TUNNEL_LIMITS.pro}</Var> tunnels.{" "}
28 <a
29 className="underline"
30 href={T3CHAT_SUBSCRIPTION_URL}
31 target="_blank"
32 rel="noopener noreferrer"
33 >
34 Upgrade on T3 Chat
35 </a>{" "}
36 to Premier for <Var>{T3CHAT_PLAN_TUNNEL_LIMITS.premier}</Var>.
37 </T>
38 );
39 case "free":
40 return (
41 <T>
42 <a
43 className="underline"
44 href={T3CHAT_SUBSCRIPTION_URL}
45 target="_blank"
46 rel="noopener noreferrer"
47 >
48 Upgrade on T3 Chat
49 </a>{" "}
50 for more tunnels
51 </T>
52 );
53 }
54 }
55
56 /** Links a T3 Chat account so paid subscribers get more tunnels. */
57 export function T3ChatUserProfilePage() {
58 const { linkState, pending, linkUrl, link: handleLink, unlink: handleUnlink } = useT3ChatLink();
59 const usage = useManagedTunnelUsage();
60 const gt = useGT();
61
62 const data = linkState.data;
63 const link = data?.link ?? null;
64
65 return (
66 <ClerkUserProfilePage
67 title="T3 Chat"
68 description={gt(
69 "Link a paid T3 Chat account for more T3 Connect tunnels: up to {pro} with Pro, {premier} with Premier.",
70 { pro: T3CHAT_PLAN_TUNNEL_LIMITS.pro, premier: T3CHAT_PLAN_TUNNEL_LIMITS.premier },
71 )}
72 action={
73 <ClerkUserProfileRefreshButton
74 disabled={pending !== null}
75 isPending={linkState.isPending}
76 onClick={usage.refresh}
77 />
78 }
79 >
80 {linkState.error ? (
81 <div className="border-t py-3 text-xs" role="alert">
82 <p className="font-medium text-destructive-foreground">
83 <T>Could not load T3 Chat link</T>
84 </p>
85 <p className="mt-0.5 text-muted-foreground">{linkState.error}</p>
86 </div>
87 ) : data === null ? null : !data.available ? (
88 <p className="border-t py-4 text-xs text-muted-foreground">
89 <T>This T3 Connect server does not support T3 Chat linking.</T>
90 </p>
91 ) : (
92 <ul className="border-t">
93 <ClerkUserProfileRow icon={<MessageSquareIcon className="size-4" />}>
94 <div className="flex items-start gap-4">
95 <div className="min-w-0 flex-1">
96 <h3 className="truncate text-sm leading-4.5 font-medium text-foreground">
97 {link ? link.email : gt("Not linked")}
98 </h3>
99 <p className="mt-1 text-xs leading-4.5 text-muted-foreground">
100 {link ? (
101 planLabel(link)
102 ) : linkUrl ? (
103 <T>
104 Confirm on{" "}
105 <a
106 className="underline"
107 href={linkUrl}
108 target="_blank"
109 rel="noopener noreferrer"
110 >
111 t3.chat
112 </a>
113 , then select Refresh.
114 </T>
115 ) : (
116 gt("You confirm the link on t3.chat.")
117 )}
118 </p>
119 </div>
120 {link ? (
121 <Button
122 size="sm"
123 variant="destructive-outline"
124 disabled={pending !== null}
125 onClick={() => void handleUnlink()}
126 >
127 {pending === "unlink" ? gt("Unlinking…") : gt("Unlink")}
128 </Button>
129 ) : (
130 <Button size="sm" disabled={pending !== null} onClick={() => void handleLink()}>
131 {pending === "link" ? gt("Opening…") : gt("Link T3 Chat")}
132 </Button>
133 )}
134 </div>
135 </ClerkUserProfileRow>
136 {usage.used !== null && usage.limit !== null ? (
137 <li className="border-t py-4">
138 <TunnelUsageMeter used={usage.used} limit={usage.limit} />
139 </li>
140 ) : null}
141 </ul>
142 )}
143 </ClerkUserProfilePage>
144 );
145 }