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

ComposerUsageLimits.tsx

98 lines3.3 KB

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