TypeScript
refactor(mobile): share connection form fields (#12364)
Julius Marminge18dcc43ace0a
diff --git a/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx b/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsxindex b4e32a06f55..cf90cd42a0a 100644--- a/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx+++ b/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx@@ -10,7 +10,7 @@ import { useCallback, useState } from "react";import { Platform, Alert, Pressable, View } from "react-native";import Animated, { FadeIn, FadeOut, LinearTransition } from "react-native-reanimated";-import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";+import { AppText as Text } from "../../components/AppText";import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";import { MaterialButton } from "../../components/MaterialButton";import { MaterialIconButton } from "../../components/MaterialIconButton";@@ -18,6 +18,7 @@ import { ThemedSwitch } from "../../components/ThemedSwitch";import { cn } from "../../lib/cn";import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types";import { serverEnvironment } from "../../state/server";+import { ConnectionFormField } from "./ConnectionFormField";import { ConnectionStatusDot } from "./ConnectionStatusDot";function connectionStatusLabel(environment: ConnectedEnvironmentSummary): string | null {@@ -152,34 +153,24 @@ export function ConnectionEnvironmentRow(props: {</Text>) : (<>- <View className="gap-1.5">- <Text className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">- Label- </Text>- <TextInput- autoCapitalize="words"- autoCorrect={false}- placeholder="My MacBook"- value={label}- onChangeText={setLabel}- className="rounded-[14px] border border-input-border bg-input px-4 py-3 text-base text-foreground"- />- </View>+ <ConnectionFormField+ label="Label"+ autoCapitalize="words"+ autoCorrect={false}+ placeholder="My MacBook"+ value={label}+ onChangeText={setLabel}+ />- <View className="gap-1.5">- <Text className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">- URL- </Text>- <TextInput- autoCapitalize="none"- autoCorrect={false}- keyboardType="url"- placeholder="192.168.1.100:8080"- value={url}- onChangeText={setUrl}- className="rounded-[14px] border border-input-border bg-input px-4 py-3 text-base text-foreground"- />- </View>+ <ConnectionFormField+ label="URL"+ autoCapitalize="none"+ autoCorrect={false}+ keyboardType="url"+ placeholder="192.168.1.100:8080"+ value={url}+ onChangeText={setUrl}+ /></>)}diff --git a/apps/mobile/src/features/connection/ConnectionFormField.tsx b/apps/mobile/src/features/connection/ConnectionFormField.tsxnew file mode 100644index 00000000000..0d5e21148e5--- /dev/null+++ b/apps/mobile/src/features/connection/ConnectionFormField.tsx@@ -0,0 +1,25 @@+import { View } from "react-native";++import { AppText, AppTextInput, type AppTextInputProps } from "../../components/AppText";+import { cn } from "../../lib/cn";++type ConnectionFormFieldProps = Omit<AppTextInputProps, "className"> & {+ readonly label: string;+ readonly className?: string;+};++/** Labeled connection input with a native wrapper retained inside form sheets. */+export function ConnectionFormField({ label, className, ...inputProps }: ConnectionFormFieldProps) {+ return (+ <View collapsable={false} className={cn("gap-1.5", className)}>+ <AppText className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">+ {label}+ </AppText>+ <AppTextInput+ accessibilityLabel={label}+ {...inputProps}+ className="rounded-[14px] px-4 py-3.5"+ />+ </View>+ );+}diff --git a/apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx b/apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsxindex ea4f1cf6971..6c0d60beb5f 100644--- a/apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx+++ b/apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx@@ -13,8 +13,9 @@ import { Alert, Linking, Platform, View } from "react-native";import { useSafeAreaInsets } from "react-native-safe-area-context";import { useUniwindTheme } from "../../lib/useUniwindTheme";import { SettingsScreen } from "../settings/components/SettingsScreen";-import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";+import { AppText as Text } from "../../components/AppText";import { ErrorBanner } from "../../components/ErrorBanner";+import { ConnectionFormField } from "./ConnectionFormField";import { ConnectionSheetButton } from "./ConnectionSheetButton";import { buildPairingUrl, extractPairingUrlFromQrPayload, parsePairingUrl } from "./pairing";import { useRemoteConnections } from "../../state/use-remote-environment-registry";@@ -262,34 +263,24 @@ export function ConnectionsNewRouteScreen({)) : (<View collapsable={false} className="gap-4 rounded-[24px] bg-card p-4">- <View collapsable={false} className="gap-1.5">- <Text className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">- Host- </Text>- <TextInput- autoCapitalize="none"- autoCorrect={false}- keyboardType="url"- placeholder="192.168.1.100:8080"- value={hostInput}- onChangeText={handleHostChange}- className="rounded-[14px] border border-input-border bg-input px-4 py-3.5 text-base text-foreground"- />- </View>+ <ConnectionFormField+ label="Host"+ autoCapitalize="none"+ autoCorrect={false}+ keyboardType="url"+ placeholder="192.168.1.100:8080"+ value={hostInput}+ onChangeText={handleHostChange}+ />- <View collapsable={false} className="gap-1.5">- <Text className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">- Pairing code- </Text>- <TextInput- autoCapitalize="none"- autoCorrect={false}- placeholder="abc-123-xyz"- value={codeInput}- onChangeText={handleCodeChange}- className="rounded-[14px] border border-input-border bg-input px-4 py-3.5 text-base text-foreground"- />- </View>+ <ConnectionFormField+ label="Pairing code"+ autoCapitalize="none"+ autoCorrect={false}+ placeholder="abc-123-xyz"+ value={codeInput}+ onChangeText={handleCodeChange}+ />{pairingConnectionError ? <ErrorBanner message={pairingConnectionError} /> : null}