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

ConnectOnboardingRouteScreen.tsx

125 lines4.9 KB

1import { useGT } from "gt-react-native";
2import { AppBar } from "../../components/ui/AppBar";
3import { Button } from "../../components/ui/Button";
4import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
5​
6import { useAuth } from "@clerk/expo";
7import { useNavigation } from "@react-navigation/native";
8import { useState } from "react";
9import { View } from "react-native";
10import { RefreshControl } from "../../components/ui/RefreshControl";
11import { useSafeAreaInsets } from "react-native-safe-area-context";
12​
13import { reportAtomCommandResult, settlePromise } from "@t3tools/client-runtime/state/runtime";
14import { AppText as Text } from "../../components/ui/AppText";
15import { useRemoteConnections } from "../../state/use-remote-environment-registry";
16import { CloudEnvironmentRows } from "../connection/CloudEnvironmentRows";
17import { splitEnvironmentSections } from "../connection/environmentSections";
18import { useConnectionController } from "../connection/useConnectionController";
19import {
20 ConnectionTracesSwitch,
21 connectionTracesAvailable,
22} from "../observability/ConnectionTracesSwitch";
23import { optOutOfConnectOnboarding } from "./connectOnboardingOptOut";
24import { hasCloudPublicConfig } from "./publicConfig";
25​
26// Only reachable with cloud config: onboarding is requested after a T3 Connect
27// sign-in, and appLinking drops the deep link otherwise.
28export function ConnectOnboardingRouteScreen() {
29 return hasCloudPublicConfig() ? <ConfiguredConnectOnboardingRouteScreen /> : null;
31​
32function ConfiguredConnectOnboardingRouteScreen() {
33 const gt = useGT();
34 const navigation = useNavigation();
35 const insets = useSafeAreaInsets();
36 const { isSignedIn, userId } = useAuth({ treatPendingAsSignedOut: false });
37 const { connectedEnvironments, onSetEnvironmentEnabled, onRemoveEnvironmentPress } =
38 useRemoteConnections();
39 const { refreshRelayEnvironments } = useConnectionController();
40 const { connectedCloudEnvironments } = splitEnvironmentSections({
41 connectedEnvironments,
42 cloudEnvironments: null,
43 });
44​
45 const [isRefreshing, setIsRefreshing] = useState(false);
46 const handleRefresh = () => {
47 setIsRefreshing(true);
48 void refreshRelayEnvironments().finally(() => setIsRefreshing(false));
49 };
50​
51 const handleClose = () => {
52 navigation.goBack();
53 };
54​
55 // Persist before dismissing so quick sign-out/sign-in cannot outrun the write.
56 const handleDontShowAgain = () => {
57 void (async () => {
58 if (userId) {
59 const result = await settlePromise(() => optOutOfConnectOnboarding(userId));
60 reportAtomCommandResult(result, { label: "connect onboarding opt-out" });
61 }
62 navigation.goBack();
63 })();
64 };
65​
66 return (
67 <View collapsable={false} className="flex-1 bg-sheet">
68 <AppBar
69 title={gt("Set up {product}", { product: "T3 Connect" })}
70 onClose={handleClose}
71 refresh={{
72 accessibilityLabel: gt("Refresh environments"),
73 disabled: isRefreshing,
74 onPress: handleRefresh,
75 }}
76 />
77 <ScrollView
78 nestedScrollEnabled
79 alwaysBounceVertical
80 contentInsetAdjustmentBehavior="automatic"
81 showsVerticalScrollIndicator={false}
82 className="flex-1"
83 contentContainerStyle={{
84 gap: 16,
85 paddingHorizontal: 20,
86 paddingTop: 16,
87 paddingBottom: Math.max(insets.bottom, 18) + 18,
88 }}
89 refreshControl={<RefreshControl refreshing={isRefreshing} onRefresh={handleRefresh} />}
90 >
91 {isSignedIn ? (
92 <CloudEnvironmentRows
93 connectedCloudEnvironments={connectedCloudEnvironments}
94 onSetEnvironmentEnabled={onSetEnvironmentEnabled}
95 onRemoveEnvironment={onRemoveEnvironmentPress}
96 showHeader={false}
97 />
98 ) : (
99 <View collapsable={false} className="rounded-[24px] bg-grouped-card p-5">
100 <Text className="text-sm leading-normal text-foreground-muted">
101 {gt("Sign in to your T3 account to set up {product}.", { product: "T3 Connect" })}
102 </Text>
103 </View>
104 )}
105​
106 {isSignedIn && connectionTracesAvailable ? (
107 <View collapsable={false} className="gap-2">
108 <View collapsable={false} className="overflow-hidden rounded-[24px] bg-grouped-card">
109 <ConnectionTracesSwitch />
110 </View>
111 <Text className="px-2 text-sm leading-normal text-foreground-muted">
112 {gt(
113 "Helps the T3 Code team fix connection problems. Traces hold timings, error types, an ID for this app session, and the app version, never your threads, prompts, or code. You can change this in Settings > About T3 Code > Diagnostics.",
114 )}
115 </Text>
116 </View>
117 ) : null}
118​
119 {userId ? (
120 <Button label={gt("Don't show this again")} tone="text" onPress={handleDontShowAgain} />
121 ) : null}
122 </ScrollView>
123 </View>
124 );