Skip to content

Commit fa6073e

Browse files
Add T3 Connect onboarding for mobile and web (#3765)
1 parent 4eb1b57 commit fa6073e

26 files changed

Lines changed: 1546 additions & 720 deletions

‎apps/mobile/src/Stack.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { AppText as Text } from "./components/AppText";
1717
import { ArchivedThreadsRouteScreen } from "./features/archive/ArchivedThreadsRouteScreen";
1818
import { useAgentNotificationNavigation } from "./features/agent-awareness/notificationNavigation";
1919
import { ClerkSettingsSheetDetentProvider } from "./features/cloud/ClerkSettingsSheetDetent";
20+
import { ConnectOnboardingRouteScreen } from "./features/cloud/ConnectOnboardingRouteScreen";
21+
import { useConnectOnboardingNavigation } from "./features/cloud/connectOnboardingNavigation";
2022
import { ThreadFilesTreeScreen, ThreadFileScreen } from "./features/files/ThreadFilesRouteScreen";
2123
import { AdaptiveWorkspaceLayout } from "./features/layout/AdaptiveWorkspaceLayout";
2224
import { HardwareKeyboardCommandProvider } from "./features/keyboard/HardwareKeyboardCommandProvider";
@@ -220,6 +222,7 @@ const NewTaskSheetStack = createNativeStackNavigator({
220222
// influence the adaptive workspace layout: opening Settings over Home should
221223
// not flip the sidebar in or change the active thread.
222224
const WORKSPACE_OVERLAY_ROUTES = new Set([
225+
"ConnectOnboarding",
223226
"Connections",
224227
"ConnectionsNew",
225228
"GitBranches",
@@ -251,6 +254,8 @@ function RootStackLayout(props: {
251254
}) {
252255
useAgentNotificationNavigation();
253256
useThreadOutboxDrain();
257+
// Presents the T3 Connect onboarding sheet after an in-session sign-in.
258+
useConnectOnboardingNavigation();
254259
// Full pathname (sheets included) for keyboard-command scoping; the
255260
// workspace layout only reacts to the underlying non-overlay route.
256261
const path = getPathFromState(props.state, navigationPathConfig);
@@ -412,6 +417,20 @@ export const RootStack = createNativeStackNavigator({
412417
sheetGrabberVisible: true,
413418
},
414419
}),
420+
ConnectOnboarding: createNativeStackScreen({
421+
screen: ConnectOnboardingRouteScreen,
422+
linking: "connect-onboarding",
423+
options: {
424+
// Root screenOptions hide headers; formSheets that want the native
425+
// title bar opt back in with the sheet header preset.
426+
...SHEET_SOLID_HEADER_OPTIONS,
427+
title: "Set up T3 Connect",
428+
gestureEnabled: true,
429+
presentation: "formSheet",
430+
sheetAllowedDetents: [0.6, 0.95],
431+
sheetGrabberVisible: true,
432+
},
433+
}),
415434
Connections: createNativeStackScreen({
416435
screen: ConnectionsRouteScreen,
417436
linking: "connections",

‎apps/mobile/src/connection/platform.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const capabilitiesLayer = Layer.succeedContext(
9292
if (session === null) {
9393
return yield* new ConnectionBlockedError({
9494
reason: "authentication",
95-
detail: "Sign in to T3 Cloud to connect this environment.",
95+
detail: "Sign in to T3 Connect to connect this environment.",
9696
});
9797
}
9898
const token = yield* session.readClerkToken().pipe(
@@ -107,7 +107,7 @@ const capabilitiesLayer = Layer.succeedContext(
107107
if (token === null) {
108108
return yield* new ConnectionBlockedError({
109109
reason: "authentication",
110-
detail: "The T3 Cloud session is unavailable.",
110+
detail: "The T3 Connect session is unavailable.",
111111
});
112112
}
113113
return token;

‎apps/mobile/src/features/cloud/CloudAuthProvider.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
setAgentAwarenessRelayTokenProvider,
1919
unregisterAgentAwarenessDeviceForCurrentUser,
2020
} from "../agent-awareness/remoteRegistration";
21+
import { requestConnectOnboarding } from "./connectOnboarding";
2122
import { resolveCloudPublicConfig, resolveRelayClerkTokenOptions } from "./publicConfig";
2223

2324
function resetManagedRelayTokenCache() {
@@ -67,6 +68,14 @@ function CloudAuthBridge(props: { readonly children: ReactNode }) {
6768
const nextAccount = isSignedIn && userId ? userId : null;
6869
observedAccountRef.current = nextAccount;
6970

71+
// Every sign-in that completes during this session (a cold start observes
72+
// undefined → account and must not re-prompt) requests the T3 Connect
73+
// onboarding sheet — sign-out clears the connected environments, so each
74+
// new session starts with no devices to reach.
75+
if (previousObservedAccount === null && nextAccount !== null) {
76+
requestConnectOnboarding(nextAccount);
77+
}
78+
7079
const queueAccountCleanup = (
7180
previous: {
7281
readonly userId: string;

‎apps/mobile/src/features/cloud/CloudWaitlistEnrollment.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function CloudWaitlistEnrollment(props: { readonly onSignIn: () => void }
3939
You are on the waitlist
4040
</Text>
4141
<Text className="text-center font-sans text-base text-foreground-secondary">
42-
We will email you when your T3 Cloud access is ready.
42+
We will email you when your T3 Connect access is ready.
4343
</Text>
4444
<SignInAction onPress={props.onSignIn} />
4545
</View>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { NativeHeaderToolbar } from "../../native/StackHeader";
2+
import { useAuth } from "@clerk/expo";
3+
import { useNavigation } from "@react-navigation/native";
4+
import { useCallback, useState } from "react";
5+
import { Pressable, RefreshControl, ScrollView, View } from "react-native";
6+
import { useSafeAreaInsets } from "react-native-safe-area-context";
7+
8+
import { reportAtomCommandResult, settlePromise } from "@t3tools/client-runtime/state/runtime";
9+
import { AppText as Text } from "../../components/AppText";
10+
import { useRemoteConnections } from "../../state/use-remote-environment-registry";
11+
import { CloudEnvironmentRows } from "../connection/CloudEnvironmentRows";
12+
import { splitEnvironmentSections } from "../connection/environmentSections";
13+
import { useConnectionController } from "../connection/useConnectionController";
14+
import { optOutOfConnectOnboarding } from "./connectOnboardingOptOut";
15+
import { hasCloudPublicConfig } from "./publicConfig";
16+
17+
/**
18+
* Post-sign-in onboarding sheet for T3 Connect. Mobile never publishes
19+
* environments itself — it consumes ones published elsewhere — so this simply
20+
* surfaces the account's T3 Connect environments right after sign-in so every
21+
* device can be connected in one go. It shows on every sign-in: sign-out
22+
* clears the connected environments, so each new session starts from zero.
23+
*/
24+
export function ConnectOnboardingRouteScreen() {
25+
return hasCloudPublicConfig() ? <ConfiguredConnectOnboardingRouteScreen /> : null;
26+
}
27+
28+
function ConfiguredConnectOnboardingRouteScreen() {
29+
const navigation = useNavigation();
30+
const insets = useSafeAreaInsets();
31+
const { isSignedIn, userId } = useAuth({ treatPendingAsSignedOut: false });
32+
const { connectedEnvironments, onReconnectEnvironment } = useRemoteConnections();
33+
const { refreshRelayEnvironments } = useConnectionController();
34+
const { connectedCloudEnvironments } = splitEnvironmentSections({
35+
connectedEnvironments,
36+
cloudEnvironments: null,
37+
});
38+
39+
// Pull-to-refresh tracks its own spinner instead of discovery's refreshing
40+
// flag, so background refreshes (e.g. the sign-in one) don't yank the
41+
// content down.
42+
const [isPullRefreshing, setIsPullRefreshing] = useState(false);
43+
const handlePullRefresh = useCallback(() => {
44+
void (async () => {
45+
setIsPullRefreshing(true);
46+
await refreshRelayEnvironments();
47+
setIsPullRefreshing(false);
48+
})();
49+
}, [refreshRelayEnvironments]);
50+
51+
const handleClose = useCallback(() => {
52+
navigation.goBack();
53+
}, [navigation]);
54+
55+
const handleDontShowAgain = useCallback(() => {
56+
if (userId) {
57+
void (async () => {
58+
const result = await settlePromise(() => optOutOfConnectOnboarding(userId));
59+
reportAtomCommandResult(result, { label: "connect onboarding opt-out" });
60+
})();
61+
}
62+
navigation.goBack();
63+
}, [navigation, userId]);
64+
65+
return (
66+
<View collapsable={false} className="flex-1 bg-sheet">
67+
<NativeHeaderToolbar placement="right">
68+
<NativeHeaderToolbar.Button icon="xmark" onPress={handleClose} separateBackground />
69+
</NativeHeaderToolbar>
70+
<ScrollView
71+
contentInsetAdjustmentBehavior="automatic"
72+
showsVerticalScrollIndicator={false}
73+
style={{ flex: 1 }}
74+
contentInset={{ bottom: Math.max(insets.bottom, 18) + 18 }}
75+
contentContainerStyle={{
76+
gap: 16,
77+
paddingHorizontal: 20,
78+
paddingTop: 16,
79+
}}
80+
refreshControl={
81+
<RefreshControl refreshing={isPullRefreshing} onRefresh={handlePullRefresh} />
82+
}
83+
>
84+
{isSignedIn ? (
85+
<CloudEnvironmentRows
86+
connectedCloudEnvironments={connectedCloudEnvironments}
87+
onReconnectEnvironment={onReconnectEnvironment}
88+
showHeader={false}
89+
/>
90+
) : (
91+
<View collapsable={false} className="rounded-[24px] bg-card p-5">
92+
<Text className="text-sm leading-normal text-foreground-muted">
93+
Sign in to your T3 account to set up T3 Connect.
94+
</Text>
95+
</View>
96+
)}
97+
98+
{userId ? (
99+
<Pressable
100+
accessibilityRole="button"
101+
hitSlop={8}
102+
onPress={handleDontShowAgain}
103+
className="items-center py-1 active:opacity-70"
104+
>
105+
<Text className="text-xs text-foreground-muted">{"Don't show this again"}</Text>
106+
</Pressable>
107+
) : null}
108+
</ScrollView>
109+
</View>
110+
);
111+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Atom } from "effect/unstable/reactivity";
2+
3+
import { appAtomRegistry } from "../../state/atom-registry";
4+
5+
// Signals RootStackLayout (inside the navigation tree) that an in-session
6+
// sign-in just completed. Holds the account id so a sign-out between the
7+
// request and the navigation cannot present the sheet for the wrong account.
8+
export const connectOnboardingRequestAtom = Atom.make<string | null>(null).pipe(
9+
Atom.keepAlive,
10+
Atom.withLabel("mobile:connect-onboarding-request"),
11+
);
12+
13+
/**
14+
* Requests the onboarding sheet for the given account. Sign-out clears the
15+
* connected environments, so onboarding runs on every in-session sign-in —
16+
* each new session starts with no connected devices.
17+
*/
18+
export function requestConnectOnboarding(accountId: string): void {
19+
appAtomRegistry.set(connectOnboardingRequestAtom, accountId);
20+
}
21+
22+
export function clearConnectOnboardingRequest(): void {
23+
appAtomRegistry.set(connectOnboardingRequestAtom, null);
24+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { useAtomValue } from "@effect/atom-react";
2+
import { useNavigation } from "@react-navigation/native";
3+
import { useEffect } from "react";
4+
5+
import { clearConnectOnboardingRequest, connectOnboardingRequestAtom } from "./connectOnboarding";
6+
import { isConnectOnboardingOptedOut } from "./connectOnboardingOptOut";
7+
8+
// Sign-in happens inside the Settings sheet; give its detent/session-state
9+
// transitions a beat to settle before presenting another formSheet on top.
10+
const PRESENT_ONBOARDING_DELAY_MS = 600;
11+
12+
/**
13+
* Consumes the onboarding request inside the navigation tree (RootStackLayout)
14+
* and presents the onboarding formSheet. Lives apart from connectOnboarding.ts
15+
* so non-navigation consumers (CloudAuthProvider) do not pull
16+
* @react-navigation into their module graph.
17+
*/
18+
export function useConnectOnboardingNavigation(): void {
19+
const navigation = useNavigation();
20+
const requestedAccountId = useAtomValue(connectOnboardingRequestAtom);
21+
22+
useEffect(() => {
23+
if (requestedAccountId === null) {
24+
return;
25+
}
26+
let cancelled = false;
27+
const timer = setTimeout(() => {
28+
void (async () => {
29+
// A failed preference read prefers showing the sheet.
30+
const optedOut = await isConnectOnboardingOptedOut(requestedAccountId).catch(() => false);
31+
if (cancelled) {
32+
return;
33+
}
34+
clearConnectOnboardingRequest();
35+
if (!optedOut) {
36+
navigation.navigate("ConnectOnboarding");
37+
}
38+
})();
39+
}, PRESENT_ONBOARDING_DELAY_MS);
40+
return () => {
41+
cancelled = true;
42+
clearTimeout(timer);
43+
};
44+
}, [navigation, requestedAccountId]);
45+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { loadPreferences, savePreferencesPatch } from "../../lib/storage";
2+
3+
// Lives apart from connectOnboarding.ts so CloudAuthProvider (which imports
4+
// the request signal) never pulls lib/storage — expo-secure-store — into its
5+
// module graph; that breaks CloudAuthProvider.test.ts suite loading.
6+
7+
/** Whether the account chose "Don't show this again". */
8+
export async function isConnectOnboardingOptedOut(accountId: string): Promise<boolean> {
9+
const preferences = await loadPreferences();
10+
return preferences.connectOnboardingOptOutAccounts?.includes(accountId) ?? false;
11+
}
12+
13+
/** Persists "Don't show this again" for the account. */
14+
export async function optOutOfConnectOnboarding(accountId: string): Promise<void> {
15+
const preferences = await loadPreferences();
16+
const optedOut = preferences.connectOnboardingOptOutAccounts ?? [];
17+
if (optedOut.includes(accountId)) {
18+
return;
19+
}
20+
await savePreferencesPatch({ connectOnboardingOptOutAccounts: [...optedOut, accountId] });
21+
}

0 commit comments

Comments
 (0)