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