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

main
tsx 104 lines 3.16 KB
Raw
1 import { T, useGT } from "gt-react";
2 import { useState } from "react";
3 import type { ProviderAuthMethod } from "@t3tools/contracts";
4 import { RadioGroup, Radio } from "../ui/radio-group";
5 import {
6 Dialog,
7 DialogPopup,
8 DialogHeader,
9 DialogTitle,
10 DialogDescription,
11 DialogFooter,
12 } from "../ui/dialog";
13 import { Button } from "../ui/button";
14 import { ChatGptConnectionButton } from "./ChatGptConnectionButton";
15
16 export function ChatGptAccountPicker({
17 open,
18 methods,
19 onClose,
20 onSelect,
21 onRemove,
22 disabled,
23 canRemove,
24 error,
25 }: {
26 open: boolean;
27 methods: readonly ProviderAuthMethod[];
28 onClose: () => void;
29 onSelect: (methodId: string) => void;
30 onRemove: (methodId: string) => void;
31 disabled: boolean;
32 canRemove: boolean;
33 error: string | null;
34 }) {
35 const gt = useGT();
36 const profiles = methods.filter((method) => method.id.startsWith("chatgpt-profile:"));
37 const [selection, setSelection] = useState<string | null>(null);
38 const selectedMethodId =
39 selection === "chatgpt-change-account"
40 ? selection
41 : (profiles.find((profile) => profile.id === selection)?.id ??
42 profiles[0]?.id ??
43 "chatgpt-change-account");
44 return (
45 <Dialog
46 open={open}
47 onOpenChange={(value) => {
48 if (!value) onClose();
49 }}
50 >
51 <DialogPopup>
52 <DialogHeader>
53 <DialogTitle>
54 <T>Reconnect ChatGPT</T>
55 </DialogTitle>
56 <DialogDescription>
57 <T>On OpenAI, sign in with the account you choose here.</T>
58 </DialogDescription>
59 </DialogHeader>
60 <div className="px-6 pb-6">
61 <RadioGroup
62 aria-label={gt("ChatGPT account to connect")}
63 disabled={disabled}
64 value={selectedMethodId}
65 onValueChange={(value) => setSelection(value)}
66 >
67 {profiles.map((profile) => (
68 <label
69 key={profile.id}
70 className="flex cursor-pointer items-center gap-3 rounded-lg border px-3 py-3 text-sm"
71 >
72 <Radio value={profile.id} />
73 <span className="min-w-0 break-all font-medium">{profile.name}</span>
74 </label>
75 ))}
76 <label className="flex cursor-pointer items-center gap-3 rounded-lg border px-3 py-3 text-sm">
77 <Radio value="chatgpt-change-account" />
78 <span className="font-medium">
79 <T>Use a different account</T>
80 </span>
81 </label>
82 </RadioGroup>
83 </div>
84 {error ? (
85 <p role="alert" className="px-6 pb-3 text-sm text-destructive">
86 {error}
87 </p>
88 ) : null}
89 <DialogFooter>
90 {profiles.find((profile) => profile.id === selectedMethodId)?.canRemove ? (
91 <Button
92 variant="ghost"
93 disabled={disabled || !canRemove}
94 onClick={() => onRemove(selectedMethodId)}
95 >
96 <T>Remove connection</T>
97 </Button>
98 ) : null}
99 <ChatGptConnectionButton disabled={disabled} onClick={() => onSelect(selectedMethodId)} />
100 </DialogFooter>
101 </DialogPopup>
102 </Dialog>
103 );
104 }