Open History to see the last commit
1import { providerClients } from "@t3tools/client-runtime/provider-clients";
2import type { EnvironmentId, UsageLimitsReport } from "@t3tools/contracts";
3import { Pressable, ScrollView, View } from "react-native";
4
5import { SymbolView } from "../../components/ui/AppSymbol";
6import { AppText as Text } from "../../components/ui/AppText";
7import { AccountLimits, ResetCredits } from "../usage/UsageLimitsSection";
8
9export function ComposerUsageLimits({
10 report,
11 environmentId,
12 maxHeight,
13 onClose,
14}: {
15 readonly report: UsageLimitsReport;
16 readonly environmentId: EnvironmentId;
17 readonly maxHeight: number;
18 readonly onClose: () => void;
19}) {
20 const now = Date.parse(report.createdAt);
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 bounces={false} showsVerticalScrollIndicator={false} style={{ maxHeight }}>
35 {report.accounts.map((account, index) => {
36 const resetCreditInput =
37 account.resetCreditInput ??
38 (account.instanceId ? { instanceId: account.instanceId } : undefined);
39 const driverLabel = providerClients.get(account.driver)?.label ?? account.driver;
40 return (
41 <AccountLimits
42 key={account.id}
43 dense
44 first={index === 0}
45 driver={account.driver}
46 accentColor={account.accentColor}
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}