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

main
tsx 99 lines 3.38 KB
Raw
1 import { providerClients } from "@t3tools/client-runtime/provider-clients";
2 import type { EnvironmentId, UsageLimitsReport } from "@t3tools/contracts";
3 import { T, useGT } from "gt-react-native";
4 import { Pressable, ScrollView, View } from "react-native";
5
6 import { SymbolView } from "../../components/ui/AppSymbol";
7 import { AppText as Text } from "../../components/ui/AppText";
8 import { AccountLimits, ResetCredits } from "../usage/UsageLimitsSection";
9
10 export function ComposerUsageLimits({
11 report,
12 environmentId,
13 maxHeight,
14 onClose,
15 }: {
16 readonly report: UsageLimitsReport;
17 readonly environmentId: EnvironmentId;
18 readonly maxHeight: number;
19 readonly onClose: () => void;
20 }) {
21 const gt = useGT();
22 const now = Date.parse(report.createdAt);
23 const close = (
24 <Pressable
25 accessibilityLabel={gt("Dismiss usage limits")}
26 accessibilityRole="button"
27 hitSlop={12}
28 onPress={onClose}
29 className="-me-1 p-1 active:opacity-60"
30 >
31 <SymbolView name="xmark" size={14} tintColorClassName="accent-icon-muted" type="monochrome" />
32 </Pressable>
33 );
34 return (
35 <View className="overflow-hidden rounded-[20px] border-continuous bg-card">
36 <ScrollView bounces={false} showsVerticalScrollIndicator={false} style={{ maxHeight }}>
37 {report.accounts.map((account, index) => {
38 const resetCreditInput =
39 account.resetCreditInput ??
40 (account.instanceId ? { instanceId: account.instanceId } : undefined);
41 const driverLabel = providerClients.get(account.driver)?.label ?? account.driver;
42 return (
43 <AccountLimits
44 key={account.id}
45 dense
46 first={index === 0}
47 driver={account.driver}
48 accentColor={account.accentColor}
49 label={driverLabel}
50 instanceLabel={
51 account.instanceId
52 ? account.displayName?.trim() ||
53 (String(account.instanceId) !== String(account.driver)
54 ? account.instanceId
55 : driverLabel)
56 : account.label
57 }
58 detail={account.plan}
59 limits={account.limits}
60 now={now}
61 trailing={index === 0 ? close : undefined}
62 footer={
63 resetCreditInput && account.limits.resetCredits ? (
64 <ResetCredits
65 dense
66 environmentId={environmentId}
67 input={resetCreditInput}
68 credits={account.limits.resetCredits}
69 now={now}
70 />
71 ) : undefined
72 }
73 />
74 );
75 })}
76 {report.accounts.length === 0 ? (
77 <View className="flex-row items-center gap-3 px-4 pt-3">
78 <Text className="min-w-0 flex-1 text-base text-foreground">
79 <T>Usage limits</T>
80 </Text>
81 {close}
82 </View>
83 ) : null}
84 {report.notices.map((notice) => (
85 <Text
86 key={notice}
87 className={
88 report.accounts.length === 0
89 ? "px-4 py-3 text-xs text-foreground-muted"
90 : "border-t border-border-subtle px-4 py-3 text-xs text-foreground-muted"
91 }
92 >
93 {notice}
94 </Text>
95 ))}
96 </ScrollView>
97 </View>
98 );
99 }