Open History to see the last commit
1import type { EnvironmentId } from "@t3tools/contracts";
2import { CHATGPT_USAGE_URL } from "@t3tools/shared/usageLimits";
3import { collectExternalUsageLinks } from "@t3tools/shared/usageLimitsCopy";
4import { T, useMessages, Var } from "gt-react-native";
5import { use } from "react";
6import { Pressable, View } from "react-native";
7import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
8import { AppText as Text } from "../../components/ui/AppText";
9import { ProviderIcon } from "../../components/ProviderIcon";
10import { environmentPresentations } from "../../state/presentation";
11import { NativeWorkspaceTabActivityContext } from "../../native/v5-workspace-context";
12import { useAtomValueWhileVisible } from "../home/home-route-visibility";
13
14export function ChatGptUsageSummary({
15 selectedEnvironmentIds,
16}: {
17 selectedEnvironmentIds: ReadonlySet<EnvironmentId> | null;
18}) {
19 const presentations = useAtomValueWhileVisible(
20 environmentPresentations.presentationsWithProvidersAtom,
21 use(NativeWorkspaceTabActivityContext)?.active ?? true,
22 );
23 const m = useMessages();
24 const selected =
25 selectedEnvironmentIds === null
26 ? presentations
27 : new Map([...presentations].filter(([id]) => selectedEnvironmentIds.has(id)));
28 const usage = collectExternalUsageLinks(selected, m).find(
29 (link) => link.url === CHATGPT_USAGE_URL,
30 );
31 if (!usage) return null;
32 return (
33 <View className="gap-1">
34 <View className="flex-row items-center justify-between gap-3">
35 <View className="flex-row items-center gap-2">
36 <ProviderIcon provider="codex" size={16} />
37 <Text className="text-sm text-foreground">
38 <T>ChatGPT shared usage</T>
39 </Text>
40 </View>
41 <Pressable
42 accessibilityRole="link"
43 className="min-h-11 justify-center"
44 onPress={() => void tryOpenExternalUrl(usage.url)}
45 >
46 <Text className="text-sm font-t3-medium text-primary">
47 <T>Manage usage</T>
48 </Text>
49 </Pressable>
50 </View>
51 <Text className="text-xs text-foreground-muted">
52 <T>
53 <Var>{usage.accounts.join(", ")}</Var>. Open ChatGPT with the account you connected.
54 </T>
55 </Text>
56 </View>
57 );
58}