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

main
tsx 92 lines 2.98 KB
Raw
1 import { useAtomValue } from "@effect/atom-react";
2 import { usesChatGptSharing } from "@t3tools/shared/usageLimits";
3 import { T, Var } from "gt-react";
4 import { useState } from "react";
5 import { environmentPresentations } from "../../state/presentation";
6 import { OpenAI } from "../Icons";
7 import { Button } from "../ui/button";
8 import {
9 Dialog,
10 DialogPopup,
11 DialogHeader,
12 DialogTitle,
13 DialogDescription,
14 DialogFooter,
15 } from "../ui/dialog";
16 import { ChatGptUsageButton } from "./ChatGptUsageButton";
17
18 const STORAGE_KEY = "t3:chatgpt-sharing-welcome:v1";
19 function readAcknowledgedProfiles(): string[] {
20 try {
21 const value: unknown = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "[]");
22 return Array.isArray(value)
23 ? value.filter((key): key is string => typeof key === "string")
24 : [];
25 } catch {
26 return [];
27 }
28 }
29
30 export function ChatGptWelcomeCoordinator() {
31 const presentations = useAtomValue(environmentPresentations.presentationsAtom);
32 const providersByEnvironment = useAtomValue(environmentPresentations.providersByEnvironmentAtom);
33 const [acknowledged, setAcknowledged] = useState(readAcknowledgedProfiles);
34 const profiles = [...presentations].flatMap(([environmentId, presentation]) =>
35 presentation.connection.phase !== "connected"
36 ? []
37 : (providersByEnvironment.get(environmentId) ?? [])
38 .filter(usesChatGptSharing)
39 .map((provider) => ({
40 key: JSON.stringify([
41 environmentId,
42 provider.instanceId,
43 provider.auth.profileId ?? provider.auth.email ?? "default",
44 ]),
45 environmentLabel: presentation.entry.target.label,
46 providerName: provider.displayName ?? "Codex",
47 })),
48 );
49 const next = profiles.find((profile) => !acknowledged.includes(profile.key));
50 const dismiss = () => {
51 if (!next) return;
52 const updated = [...acknowledged, next.key];
53 setAcknowledged(updated);
54 try {
55 localStorage.setItem(STORAGE_KEY, JSON.stringify(updated));
56 } catch {}
57 };
58 return (
59 <Dialog
60 open={next !== undefined}
61 onOpenChange={(open) => {
62 if (!open) dismiss();
63 }}
64 >
65 <DialogPopup>
66 <DialogHeader>
67 <OpenAI className="mb-2 size-8" aria-hidden="true" />
68 <DialogTitle>
69 <T>Your ChatGPT plan is connected</T>
70 </DialogTitle>
71 <DialogDescription>
72 <T>
73 Eligible usage in T3 Code uses your ChatGPT plan. Manage your shared usage and any
74 credit settings in ChatGPT.
75 </T>
76 </DialogDescription>
77 <p className="text-xs text-muted-foreground">
78 <T>
79 <Var>{next?.providerName}</Var> on <Var>{next?.environmentLabel}</Var>
80 </T>
81 </p>
82 </DialogHeader>
83 <DialogFooter>
84 <ChatGptUsageButton />
85 <Button onClick={dismiss}>
86 <T>Continue</T>
87 </Button>
88 </DialogFooter>
89 </DialogPopup>
90 </Dialog>
91 );
92 }