Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ChatGptUsageLimitNotice.tsx

69 lines2.7 KB

1import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2import {
3 CHATGPT_USAGE_LIMIT_CODE,
4 CHATGPT_USAGE_URL,
5 CHATGPT_WORKSPACE_ADMIN_REQUEST,
6 CHATGPT_WORKSPACE_USAGE_LIMIT_CODE,
7} from "@t3tools/shared/usageLimits";
8import * as Clipboard from "expo-clipboard";
9import { useState } from "react";
10import { Linking, View } from "react-native";
11import { ProviderIcon } from "../../components/ProviderIcon";
12import { AppText as Text } from "../../components/ui/AppText";
13import { Button } from "../../components/ui/Button";
14​
15export function ChatGptUsageLimitNotice({ thread }: { thread: EnvironmentThreadShell }) {
16 const [status, setStatus] = useState<"copied" | "copy-failed" | "open-failed" | null>(null);
17 const code = thread.runtime?.lastErrorCode;
18 const workspaceLimit = code === CHATGPT_WORKSPACE_USAGE_LIMIT_CODE;
19 if (thread.runtime?.status !== "failed" || (!workspaceLimit && code !== CHATGPT_USAGE_LIMIT_CODE))
20 return null;
21 return (
22 <View
23 accessibilityRole="alert"
24 className="mx-3 mb-2 gap-2 rounded-xl border border-border-subtle bg-screen p-3"
25 >
26 <View className="flex-row items-center gap-2">
27 <ProviderIcon provider="codex" size={16} />
28 <Text className="text-sm font-t3-medium text-foreground">ChatGPT usage limit reached</Text>
29 </View>
30 <Text className="text-xs text-foreground-muted">
31 {workspaceLimit
32 ? status === "copied"
33 ? "Request copied. Send it to your workspace admin."
34 : "You've reached your workspace's limit for using your ChatGPT plan in other apps. Copy a request to ask your workspace admin for increased usage limits."
35 : "Review your usage settings in ChatGPT."}
36 </Text>
37 {workspaceLimit ? (
38 <Button
39 label="Copy request for admin"
40 tone="primary"
41 onPress={() =>
42 void Clipboard.setStringAsync(CHATGPT_WORKSPACE_ADMIN_REQUEST).then(
43 () => setStatus("copied"),
44 () => setStatus("copy-failed"),
45 )
46 }
47 />
48 ) : (
49 <Button
50 label="Manage usage"
51 tone="primary"
52 onPress={() =>
53 void Linking.openURL(CHATGPT_USAGE_URL).then(
54 () => setStatus(null),
55 () => setStatus("open-failed"),
56 )
57 }
58 />
59 )}
60 {status === "copy-failed" || status === "open-failed" ? (
61 <Text accessibilityRole="alert" className="text-xs text-destructive">
62 {status === "copy-failed"
63 ? "Could not copy the request. Try again."
64 : "Could not open ChatGPT. Go to chatgpt.com → Settings → Usage."}
65 </Text>
66 ) : null}
67 </View>
68 );