Skip to content

Commit 779ec98

Browse files
committed
feat(clients): let users check secrets before saving
1 parent fa31b66 commit 779ec98

2 files changed

Lines changed: 67 additions & 37 deletions

File tree

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/
2020
import { serverEnvironment } from "../../state/server";
2121
import { useAtomCommand } from "../../state/use-atom-command";
2222
import { Button } from "../../components/ui/Button";
23+
import { IconButton } from "../../components/ui/IconButton";
2324

2425
const LOCK_SYMBOL: AppSymbolName = { ios: "lock", android: "lock" };
2526
const PRIVATE_SYMBOL: AppSymbolName = { ios: "checkmark.shield", android: "lock" };
@@ -70,6 +71,7 @@ function PendingSecretRequestForm(props: {
7071
reportDefect: false,
7172
});
7273
const [secret, setSecret] = useState("");
74+
const [revealed, setRevealed] = useState(false);
7375
const [submitting, setSubmitting] = useState(false);
7476
const [error, setError] = useState<string | null>(null);
7577
// Submit then a tap can both run before a re-render; this guard is synchronous.
@@ -89,6 +91,7 @@ function PendingSecretRequestForm(props: {
8991
});
9092
if (result._tag === "Success") {
9193
setSecret("");
94+
setRevealed(false);
9295
return;
9396
}
9497
if (!isAtomCommandInterrupted(result)) {
@@ -106,22 +109,33 @@ function PendingSecretRequestForm(props: {
106109
</Text>
107110
) : null}
108111
</View>
109-
<TextInput
110-
accessibilityLabel={item.label}
111-
placeholder={item.placeholder ?? SECRET_REQUEST_DEFAULT_PLACEHOLDER}
112-
value={secret}
113-
onChangeText={setSecret}
114-
editable={!submitting}
115-
secureTextEntry
116-
autoCorrect={false}
117-
autoCapitalize="none"
118-
autoComplete="off"
119-
textContentType="none"
120-
importantForAutofill="no"
121-
spellCheck={false}
122-
returnKeyType="done"
123-
onSubmitEditing={() => void send({ type: "save", secret })}
124-
/>
112+
<View className="flex-row items-center gap-2">
113+
<View className="min-w-0 flex-1">
114+
<TextInput
115+
accessibilityLabel={item.label}
116+
placeholder={item.placeholder ?? SECRET_REQUEST_DEFAULT_PLACEHOLDER}
117+
value={secret}
118+
onChangeText={setSecret}
119+
editable={!submitting}
120+
secureTextEntry={!revealed}
121+
autoCorrect={false}
122+
autoCapitalize="none"
123+
autoComplete="off"
124+
textContentType="none"
125+
importantForAutofill="no"
126+
spellCheck={false}
127+
returnKeyType="done"
128+
onSubmitEditing={() => void send({ type: "save", secret })}
129+
/>
130+
</View>
131+
<IconButton
132+
accessibilityLabel={revealed ? "Hide secret" : "Show secret"}
133+
icon={revealed ? "eye.slash" : "eye"}
134+
selected={revealed}
135+
disabled={submitting}
136+
onPress={() => setRevealed((current) => !current)}
137+
/>
138+
</View>
125139
{error !== null ? (
126140
<Text
127141
accessibilityRole="alert"

‎apps/web/src/components/chat/SecretRequestCard.tsx‎

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import {
1212
squashAtomCommandFailure,
1313
} from "@t3tools/client-runtime/state/runtime";
1414
import type { EnvironmentId, OrchestrationV2ProjectedTurnItem } from "@t3tools/contracts";
15-
import { CheckIcon, LockIcon, MinusIcon, ShieldCheckIcon } from "lucide-react";
15+
import { CheckIcon, EyeIcon, EyeOffIcon, LockIcon, MinusIcon, ShieldCheckIcon } from "lucide-react";
1616
import { useId, useRef, useState, type FormEvent } from "react";
1717

1818
import { serverEnvironment } from "../../state/server";
1919
import { useAtomCommand } from "../../state/use-atom-command";
2020
import { Button } from "../ui/button";
21-
import { Input } from "../ui/input";
21+
import { InputGroup, InputGroupAddon, InputGroupInput } from "../ui/input-group";
2222
import { WorkLogRow } from "./WorkLog";
2323

2424
export function SecretRequestCard(props: {
@@ -65,6 +65,7 @@ function PendingSecretRequestForm(props: {
6565
reportDefect: false,
6666
});
6767
const [secret, setSecret] = useState("");
68+
const [revealed, setRevealed] = useState(false);
6869
const [submitting, setSubmitting] = useState(false);
6970
const [error, setError] = useState<string | null>(null);
7071
// Enter and click can both submit before a render.
@@ -84,6 +85,7 @@ function PendingSecretRequestForm(props: {
8485
});
8586
if (result._tag === "Success") {
8687
setSecret("");
88+
setRevealed(false);
8789
return;
8890
}
8991
if (!isAtomCommandInterrupted(result)) {
@@ -122,25 +124,39 @@ function PendingSecretRequestForm(props: {
122124
</div>
123125
<div className="flex min-w-0 items-center gap-2">
124126
<div className="min-w-0 flex-1">
125-
<Input
126-
id={inputId}
127-
// Password fields prompt to save credentials; this secret is not a login.
128-
type="text"
129-
className="[-webkit-text-security:disc]"
130-
autoComplete="off"
131-
autoCorrect="off"
132-
autoCapitalize="off"
133-
spellCheck={false}
134-
data-1p-ignore
135-
data-lpignore="true"
136-
data-bwignore
137-
placeholder={item.placeholder ?? SECRET_REQUEST_DEFAULT_PLACEHOLDER}
138-
value={secret}
139-
disabled={submitting}
140-
aria-invalid={error !== null || undefined}
141-
aria-describedby={error !== null ? `${privacyId} ${errorId}` : privacyId}
142-
onChange={(event) => setSecret(event.currentTarget.value)}
143-
/>
127+
<InputGroup>
128+
<InputGroupInput
129+
id={inputId}
130+
type={revealed ? "text" : "password"}
131+
autoComplete="off"
132+
autoCorrect="off"
133+
autoCapitalize="off"
134+
spellCheck={false}
135+
data-1p-ignore
136+
data-lpignore="true"
137+
data-bwignore
138+
placeholder={item.placeholder ?? SECRET_REQUEST_DEFAULT_PLACEHOLDER}
139+
value={secret}
140+
disabled={submitting}
141+
aria-invalid={error !== null || undefined}
142+
aria-describedby={error !== null ? `${privacyId} ${errorId}` : privacyId}
143+
onChange={(event) => setSecret(event.currentTarget.value)}
144+
/>
145+
<InputGroupAddon align="inline-end">
146+
<Button
147+
type="button"
148+
size="icon-xs"
149+
variant="ghost-muted"
150+
aria-label={revealed ? "Hide secret" : "Show secret"}
151+
aria-controls={inputId}
152+
aria-pressed={revealed}
153+
disabled={submitting}
154+
onClick={() => setRevealed((current) => !current)}
155+
>
156+
{revealed ? <EyeOffIcon /> : <EyeIcon />}
157+
</Button>
158+
</InputGroupAddon>
159+
</InputGroup>
144160
</div>
145161
<Button type="submit" disabled={submitting || secret.trim().length === 0}>
146162
Save securely

0 commit comments

Comments
 (0)