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