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

ComposerUsageLimits.tsx

96 lines3.3 KB

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 accentColor={account.accentColor}
48 label={driverLabel}
49 instanceLabel={
50 account.instanceId
51 ? account.displayName?.trim() ||
52 (String(account.instanceId) !== String(account.driver)
53 ? account.instanceId
54 : driverLabel)
55 : account.label
56 }
57 detail={account.plan}
58 limits={account.limits}
59 now={now}
60 trailing={index === 0 ? close : undefined}
61 footer={
62 resetCreditInput && account.limits.resetCredits ? (
63 <ResetCredits
64 dense
65 environmentId={environmentId}
66 input={resetCreditInput}
67 credits={account.limits.resetCredits}
68 now={now}
69 />
70 ) : undefined
71 }
72 />
73 );
74 })}
75 {report.accounts.length === 0 ? (
76 <View className="flex-row items-center gap-3 px-4 pt-3">
77 <Text className="min-w-0 flex-1 text-base text-foreground">Usage limits</Text>
78 {close}
79 </View>
80 ) : null}
81 {report.notices.map((notice) => (
82 <Text
83 key={notice}
84 className={
85 report.accounts.length === 0
86 ? "px-4 py-3 text-xs text-foreground-muted"
87 : "border-t border-border-subtle px-4 py-3 text-xs text-foreground-muted"
88 }
89 >
90 {notice}
91 </Text>
92 ))}
93 </ScrollView>
94 </View>
95 );