Skip to content

Commit 315d227

Browse files
shivamhwpclaude
andcommitted
fix(mobile): fold the ChatGPT limit notice into the one usage-limit card
The separate ChatGPT card with its full-width blue button is gone. The usage-limit card now carries the ChatGPT identity, the guideline copy and a compact Manage usage / Copy request for admin action, matching web's compact banner. It also covers older servers that report sharing limits as provider errors. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 283d19f commit 315d227

4 files changed

Lines changed: 110 additions & 122 deletions

File tree

‎apps/mobile/src/features/threads/ChatGptUsageLimitNotice.tsx‎

Lines changed: 0 additions & 69 deletions
This file was deleted.

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { parseThreadKey, threadKey } from "@t3tools/client-runtime/state/entitie
1414
import { createThreadVisitTracker } from "@t3tools/client-runtime/state/thread-visits";
1515
import { useChildThreadInputs, useThreadReportedModelSelection } from "../../state/entities";
1616
import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";
17-
import { ChatGptUsageLimitNotice } from "./ChatGptUsageLimitNotice";
1817
import { useFocusEffect, useNavigation } from "@react-navigation/native";
1918
import {
2019
effectiveSnoozed,
@@ -1618,10 +1617,6 @@ function ThreadDetailBody(
16181617
thread={props.selectedThread}
16191618
environmentId={props.environmentId}
16201619
/>
1621-
<ChatGptUsageLimitNotice
1622-
key={`chatgpt-limit:${props.selectedThread.latestRun?.runId}`}
1623-
thread={props.selectedThread}
1624-
/>
16251620
<ChildThreadApprovals
16261621
threadRef={props.selectedThreadDetailRef}
16271622
maxHeight={pendingUserInputMaxHeight}

‎apps/mobile/src/features/threads/UsageLimitRecoveryCard.test.tsx‎

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ import { describe, expect, it, vi } from "vite-plus/test";
1212
type ButtonProps = { label: string; disabled?: boolean; onPress: () => void };
1313

1414
vi.mock("react-native", () => ({
15+
Linking: { openURL: vi.fn() },
1516
View: ({ children }: { children: ReactNode }) => <div>{children}</div>,
1617
}));
18+
vi.mock("expo-clipboard", () => ({ setStringAsync: vi.fn() }));
19+
vi.mock("../../components/ProviderIcon", () => ({ ProviderIcon: () => null }));
1720
vi.mock("../../components/ui/AppText", () => ({
1821
AppText: ({ children }: { children: ReactNode }) => <span>{children}</span>,
1922
}));
@@ -31,40 +34,45 @@ import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";
3134

3235
const DAY_MS = 24 * 60 * 60 * 1000;
3336

34-
function failedThread(resetAt: string | null, lastErrorCode?: string): EnvironmentThreadShell {
37+
function failedThread(
38+
resetAt: string | null,
39+
lastErrorCode?: string,
40+
lastErrorClass = "usage_limit",
41+
): EnvironmentThreadShell {
3542
return {
3643
id: "thread-1",
3744
updatedAt: new Date(0).toISOString(),
3845
snoozedUntil: null,
3946
latestRun: { runId: "run-1", completedAt: new Date(0).toISOString() },
4047
limitRecovery: null,
41-
runtime: {
42-
status: "failed",
43-
lastErrorClass: "usage_limit",
44-
lastErrorCode,
45-
usageLimitResetAt: resetAt,
46-
},
48+
runtime: { status: "failed", lastErrorClass, lastErrorCode, usageLimitResetAt: resetAt },
4749
} as unknown as EnvironmentThreadShell;
4850
}
4951

5052
describe("UsageLimitRecoveryCard", () => {
51-
it.each([CHATGPT_USAGE_LIMIT_CODE, CHATGPT_WORKSPACE_USAGE_LIMIT_CODE])(
52-
"leaves the %s limit to the ChatGPT notice",
53-
(code) => {
54-
const container = document.createElement("div");
55-
const root = createRoot(container);
56-
using _root = { [Symbol.dispose]: () => act(() => root.unmount()) };
57-
act(() =>
58-
root.render(
59-
<UsageLimitRecoveryCard
60-
thread={failedThread(null, code)}
61-
environmentId={"env-1" as EnvironmentId}
62-
/>,
63-
),
64-
);
65-
expect(container.textContent).toBe("");
66-
},
67-
);
53+
// Servers before #25341 report sharing limits as provider errors.
54+
it.each([
55+
[CHATGPT_USAGE_LIMIT_CODE, "usage_limit", "Manage usage"],
56+
[CHATGPT_WORKSPACE_USAGE_LIMIT_CODE, "usage_limit", "Copy request for admin"],
57+
[CHATGPT_USAGE_LIMIT_CODE, "provider_error", "Manage usage"],
58+
])("shows one ChatGPT notice for %s (%s)", (code, errorClass, action) => {
59+
const container = document.createElement("div");
60+
const root = createRoot(container);
61+
using _root = { [Symbol.dispose]: () => act(() => root.unmount()) };
62+
act(() =>
63+
root.render(
64+
<UsageLimitRecoveryCard
65+
thread={failedThread(null, code, errorClass)}
66+
environmentId={"env-1" as EnvironmentId}
67+
/>,
68+
),
69+
);
70+
expect(container.textContent).toContain("ChatGPT usage limit reached");
71+
expect(container.textContent).not.toContain("did not report a reset time");
72+
expect([...container.querySelectorAll("button")].map((button) => button.textContent)).toEqual([
73+
action,
74+
]);
75+
});
6876

6977
it("keeps reset controls for a ChatGPT limit stored with a reset time", () => {
7078
const container = document.createElement("div");

‎apps/mobile/src/features/threads/UsageLimitRecoveryCard.tsx‎

Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell
55
import type { EnvironmentId } from "@t3tools/contracts";
66
import {
77
CHATGPT_USAGE_LIMIT_CODE,
8+
CHATGPT_USAGE_URL,
9+
CHATGPT_WORKSPACE_ADMIN_REQUEST,
810
CHATGPT_WORKSPACE_USAGE_LIMIT_CODE,
911
} from "@t3tools/shared/usageLimits";
1012
import * as DateTime from "effect/DateTime";
13+
import * as Clipboard from "expo-clipboard";
1114
import { useState } from "react";
12-
import { View } from "react-native";
15+
import { Linking, View } from "react-native";
16+
import { ProviderIcon } from "../../components/ProviderIcon";
1317
import { AppText as Text } from "../../components/ui/AppText";
1418
import { useDeadlinePassed } from "../../lib/clock";
1519
import { threadEnvironment } from "../../state/threads";
@@ -34,16 +38,20 @@ export function UsageLimitRecoveryCard({
3438
const recovery = thread.limitRecovery;
3539
const scheduled =
3640
recovery?.runId === runId && recovery?.resetAt === resetAt && recovery?.autoResume;
41+
const [copied, setCopied] = useState(false);
3742
const code = thread.runtime?.lastErrorCode;
43+
const workspaceLimit = code === CHATGPT_WORKSPACE_USAGE_LIMIT_CODE;
44+
const chatGptLimit = workspaceLimit || code === CHATGPT_USAGE_LIMIT_CODE;
3845
if (
3946
thread.runtime?.status !== "failed" ||
40-
thread.runtime.lastErrorClass !== "usage_limit" ||
41-
!runId ||
42-
// Without a reset there is nothing to schedule, and ChatGptUsageLimitNotice covers it.
43-
(resetAt === null &&
44-
(code === CHATGPT_USAGE_LIMIT_CODE || code === CHATGPT_WORKSPACE_USAGE_LIMIT_CODE))
47+
// Servers before #25341 report sharing limits as provider errors.
48+
(thread.runtime.lastErrorClass !== "usage_limit" && !chatGptLimit) ||
49+
!runId
4550
)
4651
return null;
52+
const resetText = resetAt
53+
? `Usage limit resets ${DateTime.toDateUtc(DateTime.makeUnsafe(resetAt)).toLocaleString()}.`
54+
: null;
4755
const snoozed =
4856
recovery?.snooze === true &&
4957
recovery.runId === runId &&
@@ -78,25 +86,71 @@ export function UsageLimitRecoveryCard({
7886
}
7987
return (
8088
<View className="mx-3 mb-2 gap-2 rounded-xl border border-warning-foreground/25 bg-screen p-3">
81-
<Text className="text-sm text-warning-foreground">
82-
{resetAt
83-
? `Usage limit resets ${DateTime.toDateUtc(DateTime.makeUnsafe(resetAt)).toLocaleString()}.`
84-
: "The provider did not report a reset time. Retry manually when your limit is available."}
85-
</Text>
86-
{canSchedule ? (
89+
{chatGptLimit ? (
90+
// OpenAI's partner guidelines specify this ChatGPT notice and its action.
91+
<>
92+
<View className="flex-row items-center gap-2">
93+
<ProviderIcon provider="codex" size={16} />
94+
<Text className="text-sm font-t3-medium text-warning-foreground">
95+
ChatGPT usage limit reached
96+
</Text>
97+
</View>
98+
<Text className="text-sm text-warning-foreground">
99+
{workspaceLimit
100+
? copied
101+
? "Request copied. Send it to your workspace admin."
102+
: "You've reached your workspace's limit for using your ChatGPT plan in other apps. Copy a request to ask your workspace admin for increased usage limits."
103+
: (resetText ?? "Review your usage settings in ChatGPT.")}
104+
</Text>
105+
</>
106+
) : (
107+
<Text className="text-sm text-warning-foreground">
108+
{resetText ??
109+
"The provider did not report a reset time. Retry manually when your limit is available."}
110+
</Text>
111+
)}
112+
{canSchedule || chatGptLimit ? (
87113
<View className="flex-row flex-wrap gap-2">
88-
<Button
89-
label={scheduled ? "Cancel auto-resume" : "Resume at reset"}
90-
tone="secondary"
91-
disabled={pending}
92-
onPress={() => void toggle("resume")}
93-
/>
94-
<Button
95-
label={snoozed ? "Wake now" : "Snooze until reset"}
96-
tone="secondary"
97-
disabled={pending || (!snoozed && resetPassed)}
98-
onPress={() => void toggle("snooze")}
99-
/>
114+
{canSchedule ? (
115+
<>
116+
<Button
117+
label={scheduled ? "Cancel auto-resume" : "Resume at reset"}
118+
tone="secondary"
119+
disabled={pending}
120+
onPress={() => void toggle("resume")}
121+
/>
122+
<Button
123+
label={snoozed ? "Wake now" : "Snooze until reset"}
124+
tone="secondary"
125+
disabled={pending || (!snoozed && resetPassed)}
126+
onPress={() => void toggle("snooze")}
127+
/>
128+
</>
129+
) : null}
130+
{workspaceLimit ? (
131+
<Button
132+
label="Copy request for admin"
133+
tone="secondary"
134+
size="compact"
135+
onPress={() =>
136+
void Clipboard.setStringAsync(CHATGPT_WORKSPACE_ADMIN_REQUEST).then(
137+
() => setCopied(true),
138+
() => setError("Could not copy the request. Try again."),
139+
)
140+
}
141+
/>
142+
) : chatGptLimit ? (
143+
<Button
144+
label="Manage usage"
145+
tone="secondary"
146+
size="compact"
147+
onPress={() =>
148+
void Linking.openURL(CHATGPT_USAGE_URL).catch(() =>
149+
setError("Could not open ChatGPT. Go to chatgpt.com → Settings → Usage."),
150+
)
151+
}
152+
/>
153+
) : null}
100154
</View>
101155
) : null}
102156
{error ? (

0 commit comments

Comments
 (0)