@terreno/ui 57.19.2 → 57.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ai/guidelines/core.md +1 -1
- package/CHANGELOG.md +393 -0
- package/dist/Accordion.d.ts.map +1 -1
- package/dist/Accordion.js +3 -3
- package/dist/Accordion.js.map +1 -1
- package/dist/Avatar.d.ts.map +1 -1
- package/dist/Avatar.js +3 -1
- package/dist/Avatar.js.map +1 -1
- package/dist/Box.d.ts.map +1 -1
- package/dist/Box.js +38 -2
- package/dist/Box.js.map +1 -1
- package/dist/Card.js +2 -2
- package/dist/Card.js.map +1 -1
- package/dist/Common.d.ts +120 -7
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.d.ts +1 -1
- package/dist/ConsentFormScreen.d.ts.map +1 -1
- package/dist/ConsentFormScreen.js +13 -4
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/DateTimeField.d.ts.map +1 -1
- package/dist/DateTimeField.js +5 -3
- package/dist/DateTimeField.js.map +1 -1
- package/dist/Field.d.ts.map +1 -1
- package/dist/Field.js +2 -0
- package/dist/Field.js.map +1 -1
- package/dist/FormContainer.d.ts +68 -0
- package/dist/FormContainer.d.ts.map +1 -0
- package/dist/FormContainer.js +79 -0
- package/dist/FormContainer.js.map +1 -0
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +2 -1
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +1 -1
- package/dist/Heading.d.ts.map +1 -1
- package/dist/Heading.js +5 -2
- package/dist/Heading.js.map +1 -1
- package/dist/Icon.d.ts +4 -0
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Icon.js +43 -2
- package/dist/Icon.js.map +1 -1
- package/dist/LabeledCheckBox.d.ts +22 -0
- package/dist/LabeledCheckBox.d.ts.map +1 -0
- package/dist/LabeledCheckBox.js +30 -0
- package/dist/LabeledCheckBox.js.map +1 -0
- package/dist/ListDetailLayout.d.ts +36 -0
- package/dist/ListDetailLayout.d.ts.map +1 -0
- package/dist/ListDetailLayout.js +153 -0
- package/dist/ListDetailLayout.js.map +1 -0
- package/dist/MarkdownEditor.d.ts.map +1 -1
- package/dist/MarkdownEditor.js +2 -1
- package/dist/MarkdownEditor.js.map +1 -1
- package/dist/MediaQuery.d.ts +1 -1
- package/dist/MediaQuery.d.ts.map +1 -1
- package/dist/MediaQuery.js +1 -1
- package/dist/MediaQuery.js.map +1 -1
- package/dist/OtpField.d.ts +60 -0
- package/dist/OtpField.d.ts.map +1 -0
- package/dist/OtpField.js +154 -0
- package/dist/OtpField.js.map +1 -0
- package/dist/ProvisionalConsentSigner.d.ts +21 -0
- package/dist/ProvisionalConsentSigner.d.ts.map +1 -0
- package/dist/ProvisionalConsentSigner.js +199 -0
- package/dist/ProvisionalConsentSigner.js.map +1 -0
- package/dist/ResponsiveBreakpoint.d.ts +5 -0
- package/dist/ResponsiveBreakpoint.d.ts.map +1 -1
- package/dist/ResponsiveBreakpoint.js +7 -0
- package/dist/ResponsiveBreakpoint.js.map +1 -1
- package/dist/SocialLoginButton.d.ts +10 -0
- package/dist/SocialLoginButton.d.ts.map +1 -1
- package/dist/SocialLoginButton.js +26 -8
- package/dist/SocialLoginButton.js.map +1 -1
- package/dist/SplitPage.d.ts +11 -0
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +11 -5
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts.map +1 -1
- package/dist/SplitPage.native.js +3 -1
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/SyncStatusBanner.d.ts +7 -1
- package/dist/SyncStatusBanner.d.ts.map +1 -1
- package/dist/SyncStatusBanner.js +20 -4
- package/dist/SyncStatusBanner.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +44 -10
- package/dist/TextField.js.map +1 -1
- package/dist/fieldElements/FieldError.d.ts.map +1 -1
- package/dist/fieldElements/FieldError.js +1 -1
- package/dist/fieldElements/FieldError.js.map +1 -1
- package/dist/index.d.ts +19 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +3 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +2 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/login/LastUsedBadge.d.ts +14 -0
- package/dist/login/LastUsedBadge.d.ts.map +1 -0
- package/dist/login/LastUsedBadge.js +23 -0
- package/dist/login/LastUsedBadge.js.map +1 -0
- package/dist/login/LoginAccountCard.d.ts +38 -0
- package/dist/login/LoginAccountCard.d.ts.map +1 -0
- package/dist/login/LoginAccountCard.js +72 -0
- package/dist/login/LoginAccountCard.js.map +1 -0
- package/dist/login/LoginAccountList.d.ts +33 -0
- package/dist/login/LoginAccountList.d.ts.map +1 -0
- package/dist/login/LoginAccountList.js +30 -0
- package/dist/login/LoginAccountList.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +4 -4
- package/dist/login/LoginScreen.d.ts.map +1 -1
- package/dist/login/LoginScreen.js +294 -13
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/OutlinePill.d.ts +28 -0
- package/dist/login/OutlinePill.d.ts.map +1 -0
- package/dist/login/OutlinePill.js +48 -0
- package/dist/login/OutlinePill.js.map +1 -0
- package/dist/login/TwoFactorChallengeScreen.d.ts +26 -0
- package/dist/login/TwoFactorChallengeScreen.d.ts.map +1 -0
- package/dist/login/TwoFactorChallengeScreen.js +139 -0
- package/dist/login/TwoFactorChallengeScreen.js.map +1 -0
- package/dist/login/loginMethods.d.ts +27 -0
- package/dist/login/loginMethods.d.ts.map +1 -0
- package/dist/login/loginMethods.js +37 -0
- package/dist/login/loginMethods.js.map +1 -0
- package/dist/login/loginTypes.d.ts +202 -5
- package/dist/login/loginTypes.d.ts.map +1 -1
- package/dist/pdfHtmlTemplate.d.ts +17 -0
- package/dist/pdfHtmlTemplate.d.ts.map +1 -1
- package/dist/pdfHtmlTemplate.js +78 -0
- package/dist/pdfHtmlTemplate.js.map +1 -1
- package/dist/security/AccountSecurityScreen.d.ts +10 -0
- package/dist/security/AccountSecurityScreen.d.ts.map +1 -0
- package/dist/security/AccountSecurityScreen.js +50 -0
- package/dist/security/AccountSecurityScreen.js.map +1 -0
- package/dist/security/LinkedAccountsCard.d.ts +32 -0
- package/dist/security/LinkedAccountsCard.d.ts.map +1 -0
- package/dist/security/LinkedAccountsCard.js +145 -0
- package/dist/security/LinkedAccountsCard.js.map +1 -0
- package/dist/security/PasskeysCard.d.ts +39 -0
- package/dist/security/PasskeysCard.d.ts.map +1 -0
- package/dist/security/PasskeysCard.js +168 -0
- package/dist/security/PasskeysCard.js.map +1 -0
- package/dist/security/PasswordCard.d.ts +32 -0
- package/dist/security/PasswordCard.d.ts.map +1 -0
- package/dist/security/PasswordCard.js +198 -0
- package/dist/security/PasswordCard.js.map +1 -0
- package/dist/security/SessionsCard.d.ts +39 -0
- package/dist/security/SessionsCard.d.ts.map +1 -0
- package/dist/security/SessionsCard.js +168 -0
- package/dist/security/SessionsCard.js.map +1 -0
- package/dist/security/TwoFactorSettingsCard.d.ts +55 -0
- package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -0
- package/dist/security/TwoFactorSettingsCard.js +458 -0
- package/dist/security/TwoFactorSettingsCard.js.map +1 -0
- package/dist/security/securityMethods.d.ts +40 -0
- package/dist/security/securityMethods.d.ts.map +1 -0
- package/dist/security/securityMethods.js +66 -0
- package/dist/security/securityMethods.js.map +1 -0
- package/dist/security/securityTypes.d.ts +467 -0
- package/dist/security/securityTypes.d.ts.map +1 -0
- package/dist/security/securityTypes.js +2 -0
- package/dist/security/securityTypes.js.map +1 -0
- package/dist/security/userAgent.d.ts +26 -0
- package/dist/security/userAgent.d.ts.map +1 -0
- package/dist/security/userAgent.js +80 -0
- package/dist/security/userAgent.js.map +1 -0
- package/dist/signUp/OAuthButtons.d.ts +28 -5
- package/dist/signUp/OAuthButtons.d.ts.map +1 -1
- package/dist/signUp/OAuthButtons.js +44 -5
- package/dist/signUp/OAuthButtons.js.map +1 -1
- package/dist/signUp/SignUpScreen.d.ts.map +1 -1
- package/dist/signUp/SignUpScreen.js +50 -5
- package/dist/signUp/SignUpScreen.js.map +1 -1
- package/dist/signUp/signUpTypes.d.ts +21 -1
- package/dist/signUp/signUpTypes.d.ts.map +1 -1
- package/dist/useConsentForms.d.ts +9 -0
- package/dist/useConsentForms.d.ts.map +1 -1
- package/dist/useConsentForms.js +18 -0
- package/dist/useConsentForms.js.map +1 -1
- package/dist/useProvisionalConsent.d.ts +124 -0
- package/dist/useProvisionalConsent.d.ts.map +1 -0
- package/dist/useProvisionalConsent.js +79 -0
- package/dist/useProvisionalConsent.js.map +1 -0
- package/package.json +3 -2
- package/src/Accordion.test.tsx +5 -0
- package/src/Accordion.tsx +3 -8
- package/src/AreaChart.test.tsx +15 -0
- package/src/Avatar.test.tsx +8 -0
- package/src/Avatar.tsx +2 -0
- package/src/BarChart.test.tsx +15 -0
- package/src/Box.test.tsx +61 -1
- package/src/Box.tsx +44 -2
- package/src/Card.tsx +2 -2
- package/src/Common.ts +134 -7
- package/src/ConsentFormScreen.test.tsx +84 -0
- package/src/ConsentFormScreen.tsx +28 -4
- package/src/DateTimeField.tsx +5 -3
- package/src/DonutChart.test.tsx +15 -0
- package/src/Field.tsx +2 -0
- package/src/FilePickerButton.test.tsx +35 -0
- package/src/FormContainer.test.tsx +242 -0
- package/src/FormContainer.tsx +177 -0
- package/src/GPTChat.test.tsx +16 -0
- package/src/GPTChat.tsx +8 -2
- package/src/Heading.test.tsx +14 -0
- package/src/Heading.tsx +6 -1
- package/src/Icon.test.tsx +52 -1
- package/src/Icon.tsx +92 -3
- package/src/IconButton.test.tsx +85 -0
- package/src/LabeledCheckBox.test.tsx +45 -0
- package/src/LabeledCheckBox.tsx +89 -0
- package/src/ListDetailLayout.tsx +247 -0
- package/src/MarkdownEditor.tsx +2 -1
- package/src/MediaQuery.ts +1 -0
- package/src/OtpField.test.tsx +280 -0
- package/src/OtpField.tsx +307 -0
- package/src/ProvisionalConsentSigner.test.tsx +625 -0
- package/src/ProvisionalConsentSigner.tsx +423 -0
- package/src/ResponsiveBreakpoint.test.tsx +7 -0
- package/src/ResponsiveBreakpoint.tsx +14 -0
- package/src/RootImportRegression.test.tsx +3 -0
- package/src/SocialLoginButton.test.tsx +14 -0
- package/src/SocialLoginButton.tsx +51 -7
- package/src/SplitPage.native.tsx +3 -1
- package/src/SplitPage.tsx +11 -5
- package/src/SyncStatusBanner.test.tsx +61 -4
- package/src/SyncStatusBanner.tsx +29 -3
- package/src/TextField.test.tsx +150 -0
- package/src/TextField.tsx +66 -8
- package/src/__snapshots__/AddressField.test.tsx.snap +12 -0
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +15 -0
- package/src/__snapshots__/Avatar.test.tsx.snap +1 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +3 -0
- package/src/__snapshots__/EmailField.test.tsx.snap +6 -0
- package/src/__snapshots__/Field.test.tsx.snap +37 -0
- package/src/__snapshots__/HeightField.test.tsx.snap +2 -0
- package/src/__snapshots__/MobileAddressAutoComplete.test.tsx.snap +3 -0
- package/src/__snapshots__/NumberField.test.tsx.snap +3 -0
- package/src/__snapshots__/PhoneNumberField.test.tsx.snap +12 -0
- package/src/__snapshots__/Slider.test.tsx.snap +1 -0
- package/src/__snapshots__/SocialLoginButton.test.tsx.snap +43 -22
- package/src/__snapshots__/TapToEdit.test.tsx.snap +3 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +17 -1
- package/src/__snapshots__/TextField.test.tsx.snap +19 -2
- package/src/__snapshots__/TypedSignatureField.test.tsx.snap +3 -0
- package/src/__snapshots__/UnifiedAddressAutoComplete.test.tsx.snap +18 -0
- package/src/__snapshots__/WebAddressAutocomplete.test.tsx.snap +12 -0
- package/src/bunSetup.ts +13 -1
- package/src/fieldElements/FieldError.tsx +1 -0
- package/src/fieldElements/__snapshots__/FieldError.test.tsx.snap +2 -0
- package/src/index.tsx +42 -1
- package/src/isolated/ListDetailLayout.isolated.tsx +634 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +7 -0
- package/src/login/LastUsedBadge.tsx +40 -0
- package/src/login/LoginAccountCard.tsx +205 -0
- package/src/login/LoginAccountList.tsx +115 -0
- package/src/login/LoginScreen.test.tsx +837 -1
- package/src/login/LoginScreen.tsx +674 -91
- package/src/login/OutlinePill.tsx +110 -0
- package/src/login/TwoFactorChallengeScreen.test.tsx +376 -0
- package/src/login/TwoFactorChallengeScreen.tsx +307 -0
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +1454 -334
- package/src/login/loginMethods.test.ts +53 -0
- package/src/login/loginMethods.ts +60 -0
- package/src/login/loginTypes.ts +208 -5
- package/src/pdfHtmlTemplate.test.ts +243 -4
- package/src/pdfHtmlTemplate.ts +93 -0
- package/src/security/AccountSecurityScreen.test.tsx +262 -0
- package/src/security/AccountSecurityScreen.tsx +156 -0
- package/src/security/LinkedAccountsCard.test.tsx +371 -0
- package/src/security/LinkedAccountsCard.tsx +297 -0
- package/src/security/PasskeysCard.test.tsx +378 -0
- package/src/security/PasskeysCard.tsx +371 -0
- package/src/security/PasswordCard.test.tsx +445 -0
- package/src/security/PasswordCard.tsx +342 -0
- package/src/security/SessionsCard.test.tsx +349 -0
- package/src/security/SessionsCard.tsx +362 -0
- package/src/security/TwoFactorSettingsCard.test.tsx +700 -0
- package/src/security/TwoFactorSettingsCard.tsx +872 -0
- package/src/security/securityMethods.test.ts +101 -0
- package/src/security/securityMethods.ts +104 -0
- package/src/security/securityTypes.ts +480 -0
- package/src/security/userAgent.test.ts +119 -0
- package/src/security/userAgent.ts +102 -0
- package/src/signUp/OAuthButtons.test.tsx +27 -0
- package/src/signUp/OAuthButtons.tsx +153 -19
- package/src/signUp/SignUpScreen.test.tsx +170 -1
- package/src/signUp/SignUpScreen.tsx +87 -25
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -11
- package/src/signUp/signUpTypes.ts +23 -1
- package/src/useConsentForms.test.ts +37 -1
- package/src/useConsentForms.ts +25 -0
- package/src/useProvisionalConsent.test.ts +256 -0
- package/src/useProvisionalConsent.ts +218 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import {type FC, useCallback, useState} from "react";
|
|
2
|
+
import {View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import {Badge} from "../Badge";
|
|
5
|
+
import {Box} from "../Box";
|
|
6
|
+
import {Button} from "../Button";
|
|
7
|
+
import {Card} from "../Card";
|
|
8
|
+
import {Heading} from "../Heading";
|
|
9
|
+
import {Icon} from "../Icon";
|
|
10
|
+
import {Modal} from "../Modal";
|
|
11
|
+
import {Text} from "../Text";
|
|
12
|
+
import {TextField} from "../TextField";
|
|
13
|
+
import {formatSecurityDate, getRejectionMessage} from "./securityMethods";
|
|
14
|
+
import type {AccountPasskey, PasskeysCardProps} from "./securityTypes";
|
|
15
|
+
|
|
16
|
+
/** Pending key for the Add button; rows use `rename:{id}` and `remove:{id}`. */
|
|
17
|
+
const ADD_KEY = "__add__";
|
|
18
|
+
|
|
19
|
+
/** The dialog the card has open: naming a new passkey, renaming one, or confirming removal. */
|
|
20
|
+
type PasskeyDialog =
|
|
21
|
+
| {kind: "add"}
|
|
22
|
+
| {kind: "rename"; passkey: AccountPasskey}
|
|
23
|
+
| {kind: "remove"; passkey: AccountPasskey};
|
|
24
|
+
|
|
25
|
+
/** The passkey's name, else its authenticator's name, else "Unnamed passkey". */
|
|
26
|
+
const getPasskeyLabel = (passkey: AccountPasskey): string => {
|
|
27
|
+
return passkey.name?.trim() || passkey.authenticatorName?.trim() || "Unnamed passkey";
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** "Added Mar 3, 2026 · Last used Mar 10, 2026", or "Passkey" when neither date is known. */
|
|
31
|
+
const describePasskey = (passkey: AccountPasskey): string => {
|
|
32
|
+
const createdDate = formatSecurityDate(passkey.createdAt);
|
|
33
|
+
const lastUsedDate = formatSecurityDate(passkey.lastUsedAt);
|
|
34
|
+
const parts = [
|
|
35
|
+
createdDate ? `Added ${createdDate}` : undefined,
|
|
36
|
+
lastUsedDate ? `Last used ${lastUsedDate}` : undefined,
|
|
37
|
+
].filter((part): part is string => Boolean(part));
|
|
38
|
+
return parts.length > 0 ? parts.join(" · ") : "Passkey";
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Lists the user's passkeys with their created and last-used dates and a "Synced" badge for
|
|
43
|
+
* backed-up ones, and lets the user add, rename, and remove them. Add asks for an optional name,
|
|
44
|
+
* Rename edits the name in a dialog, and Remove asks for confirmation. When the device can't
|
|
45
|
+
* create passkeys (`supported={false}`) Add is hidden and the card says why. Presentational: it
|
|
46
|
+
* reports actions through `onAdd`, `onRename`, and `onRemove` and never calls an auth client.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* // The Better Auth client resolves {data, error} rather than throwing; throw so the card
|
|
51
|
+
* // shows the error.
|
|
52
|
+
* <PasskeysCard
|
|
53
|
+
* passkeys={passkeys} // authClient.passkey.listUserPasskeys() data
|
|
54
|
+
* supported={typeof window !== "undefined" && "PublicKeyCredential" in window}
|
|
55
|
+
* onAdd={async (name) => {
|
|
56
|
+
* const {error} = await authClient.passkey.addPasskey({name});
|
|
57
|
+
* if (error) {
|
|
58
|
+
* throw new Error(error.message ?? "Couldn't add a passkey.");
|
|
59
|
+
* }
|
|
60
|
+
* }}
|
|
61
|
+
* onRename={async (id, name) => {
|
|
62
|
+
* const {error} = await authClient.passkey.updatePasskey({id, name});
|
|
63
|
+
* if (error) {
|
|
64
|
+
* throw new Error(error.message ?? "Couldn't rename that passkey.");
|
|
65
|
+
* }
|
|
66
|
+
* }}
|
|
67
|
+
* onRemove={async (passkey) => {
|
|
68
|
+
* const {error} = await authClient.passkey.deletePasskey({id: passkey.id});
|
|
69
|
+
* if (error) {
|
|
70
|
+
* throw new Error(error.message ?? "Couldn't remove that passkey.");
|
|
71
|
+
* }
|
|
72
|
+
* }}
|
|
73
|
+
* />
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export const PasskeysCard: FC<PasskeysCardProps> = ({
|
|
77
|
+
passkeys,
|
|
78
|
+
onAdd,
|
|
79
|
+
onRename,
|
|
80
|
+
onRemove,
|
|
81
|
+
supported = true,
|
|
82
|
+
error,
|
|
83
|
+
disabled = false,
|
|
84
|
+
title = "Passkeys",
|
|
85
|
+
description = "Sign in with your fingerprint, face, or screen lock instead of a password.",
|
|
86
|
+
testID = "passkeys-card",
|
|
87
|
+
}) => {
|
|
88
|
+
const [pendingKey, setPendingKey] = useState<string | undefined>(undefined);
|
|
89
|
+
const [dialog, setDialog] = useState<PasskeyDialog | undefined>(undefined);
|
|
90
|
+
const [nameDraft, setNameDraft] = useState("");
|
|
91
|
+
const [actionError, setActionError] = useState<string | undefined>(undefined);
|
|
92
|
+
|
|
93
|
+
const isBusy = disabled || pendingKey !== undefined;
|
|
94
|
+
const shownError = error ?? actionError;
|
|
95
|
+
const trimmedDraft = nameDraft.trim();
|
|
96
|
+
const isRenameUnchanged =
|
|
97
|
+
dialog?.kind === "rename" && trimmedDraft === (dialog.passkey.name?.trim() ?? "");
|
|
98
|
+
|
|
99
|
+
const runAction = useCallback(
|
|
100
|
+
async ({
|
|
101
|
+
key,
|
|
102
|
+
action,
|
|
103
|
+
fallback,
|
|
104
|
+
}: {
|
|
105
|
+
key: string;
|
|
106
|
+
action: () => void | Promise<void>;
|
|
107
|
+
fallback: string;
|
|
108
|
+
}): Promise<void> => {
|
|
109
|
+
setActionError(undefined);
|
|
110
|
+
setPendingKey(key);
|
|
111
|
+
try {
|
|
112
|
+
await action();
|
|
113
|
+
} catch (rejection: unknown) {
|
|
114
|
+
console.warn("PasskeysCard: action rejected", rejection);
|
|
115
|
+
setActionError(getRejectionMessage({error: rejection, fallback}));
|
|
116
|
+
} finally {
|
|
117
|
+
setPendingKey(undefined);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
[]
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const handleDismissDialog = useCallback((): void => {
|
|
124
|
+
setDialog(undefined);
|
|
125
|
+
}, []);
|
|
126
|
+
|
|
127
|
+
const handleOpenAdd = useCallback((): void => {
|
|
128
|
+
setNameDraft("");
|
|
129
|
+
setDialog({kind: "add"});
|
|
130
|
+
}, []);
|
|
131
|
+
|
|
132
|
+
const handleOpenRename = useCallback((passkey: AccountPasskey): void => {
|
|
133
|
+
setNameDraft(passkey.name ?? "");
|
|
134
|
+
setDialog({kind: "rename", passkey});
|
|
135
|
+
}, []);
|
|
136
|
+
|
|
137
|
+
const handleOpenRemove = useCallback((passkey: AccountPasskey): void => {
|
|
138
|
+
setDialog({kind: "remove", passkey});
|
|
139
|
+
}, []);
|
|
140
|
+
|
|
141
|
+
const handleConfirmAdd = useCallback(async (): Promise<void> => {
|
|
142
|
+
setDialog(undefined);
|
|
143
|
+
if (!onAdd) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const name = trimmedDraft || undefined;
|
|
147
|
+
await runAction({
|
|
148
|
+
action: () => onAdd(name),
|
|
149
|
+
fallback: "Couldn't add a passkey. Try again.",
|
|
150
|
+
key: ADD_KEY,
|
|
151
|
+
});
|
|
152
|
+
}, [onAdd, runAction, trimmedDraft]);
|
|
153
|
+
|
|
154
|
+
const handleConfirmRename = useCallback(async (): Promise<void> => {
|
|
155
|
+
if (dialog?.kind !== "rename" || !trimmedDraft || isRenameUnchanged) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const {passkey} = dialog;
|
|
159
|
+
setDialog(undefined);
|
|
160
|
+
if (!onRename) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
await runAction({
|
|
164
|
+
action: () => onRename(passkey.id, trimmedDraft),
|
|
165
|
+
fallback: `Couldn't rename ${getPasskeyLabel(passkey)}. Try again.`,
|
|
166
|
+
key: `rename:${passkey.id}`,
|
|
167
|
+
});
|
|
168
|
+
}, [dialog, isRenameUnchanged, onRename, runAction, trimmedDraft]);
|
|
169
|
+
|
|
170
|
+
const handleConfirmRemove = useCallback(async (): Promise<void> => {
|
|
171
|
+
if (dialog?.kind !== "remove") {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const {passkey} = dialog;
|
|
175
|
+
setDialog(undefined);
|
|
176
|
+
if (!onRemove) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
await runAction({
|
|
180
|
+
action: () => onRemove(passkey),
|
|
181
|
+
fallback: `Couldn't remove ${getPasskeyLabel(passkey)}. Try again.`,
|
|
182
|
+
key: `remove:${passkey.id}`,
|
|
183
|
+
});
|
|
184
|
+
}, [dialog, onRemove, runAction]);
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<Card testID={testID}>
|
|
188
|
+
<Box gap={4}>
|
|
189
|
+
<Box gap={1}>
|
|
190
|
+
<Heading level={2} size="md" testID={`${testID}-title`}>
|
|
191
|
+
{title}
|
|
192
|
+
</Heading>
|
|
193
|
+
<Text color="secondaryLight">{description}</Text>
|
|
194
|
+
</Box>
|
|
195
|
+
|
|
196
|
+
{passkeys.length === 0 && (
|
|
197
|
+
<Text color="secondaryLight" testID={`${testID}-empty`}>
|
|
198
|
+
You haven't added a passkey yet.
|
|
199
|
+
</Text>
|
|
200
|
+
)}
|
|
201
|
+
|
|
202
|
+
{passkeys.map((passkey) => {
|
|
203
|
+
const {id} = passkey;
|
|
204
|
+
const label = getPasskeyLabel(passkey);
|
|
205
|
+
return (
|
|
206
|
+
<Box
|
|
207
|
+
alignItems="center"
|
|
208
|
+
direction="row"
|
|
209
|
+
gap={3}
|
|
210
|
+
key={id}
|
|
211
|
+
testID={`${testID}-row-${id}`}
|
|
212
|
+
>
|
|
213
|
+
<Box alignItems="center" width={24}>
|
|
214
|
+
<Icon iconName="key" size="lg" />
|
|
215
|
+
</Box>
|
|
216
|
+
<Box flex="grow" gap={1}>
|
|
217
|
+
<Box alignItems="center" direction="row" gap={2} wrap>
|
|
218
|
+
<Text bold testID={`${testID}-name-${id}`}>
|
|
219
|
+
{label}
|
|
220
|
+
</Text>
|
|
221
|
+
{Boolean(passkey.backedUp) && (
|
|
222
|
+
<Badge
|
|
223
|
+
iconName="cloud"
|
|
224
|
+
secondary
|
|
225
|
+
status="info"
|
|
226
|
+
testID={`${testID}-synced-${id}`}
|
|
227
|
+
value="Synced"
|
|
228
|
+
/>
|
|
229
|
+
)}
|
|
230
|
+
</Box>
|
|
231
|
+
<Text color="secondaryLight" size="sm" testID={`${testID}-status-${id}`}>
|
|
232
|
+
{describePasskey(passkey)}
|
|
233
|
+
</Text>
|
|
234
|
+
</Box>
|
|
235
|
+
{Boolean(onRename) && (
|
|
236
|
+
<Button
|
|
237
|
+
accessibilityLabel={`Rename passkey ${label}`}
|
|
238
|
+
disabled={isBusy}
|
|
239
|
+
loading={pendingKey === `rename:${id}`}
|
|
240
|
+
onClick={() => handleOpenRename(passkey)}
|
|
241
|
+
size="sm"
|
|
242
|
+
testID={`${testID}-rename-${id}`}
|
|
243
|
+
text="Rename"
|
|
244
|
+
variant="muted"
|
|
245
|
+
/>
|
|
246
|
+
)}
|
|
247
|
+
{Boolean(onRemove) && (
|
|
248
|
+
<Button
|
|
249
|
+
accessibilityLabel={`Remove passkey ${label}`}
|
|
250
|
+
disabled={isBusy}
|
|
251
|
+
loading={pendingKey === `remove:${id}`}
|
|
252
|
+
onClick={() => handleOpenRemove(passkey)}
|
|
253
|
+
size="sm"
|
|
254
|
+
testID={`${testID}-remove-${id}`}
|
|
255
|
+
text="Remove"
|
|
256
|
+
variant="outline"
|
|
257
|
+
/>
|
|
258
|
+
)}
|
|
259
|
+
</Box>
|
|
260
|
+
);
|
|
261
|
+
})}
|
|
262
|
+
|
|
263
|
+
{!supported && (
|
|
264
|
+
<Text color="secondaryLight" testID={`${testID}-unsupported`}>
|
|
265
|
+
This device or browser can't create passkeys. You can add one from another device, and
|
|
266
|
+
manage the ones you have here.
|
|
267
|
+
</Text>
|
|
268
|
+
)}
|
|
269
|
+
|
|
270
|
+
{Boolean(shownError) && (
|
|
271
|
+
<View role="alert" testID={`${testID}-error`}>
|
|
272
|
+
<Text color="error">{shownError}</Text>
|
|
273
|
+
</View>
|
|
274
|
+
)}
|
|
275
|
+
|
|
276
|
+
{supported && Boolean(onAdd) && (
|
|
277
|
+
<Box alignItems="start">
|
|
278
|
+
<Button
|
|
279
|
+
disabled={isBusy}
|
|
280
|
+
iconName="plus"
|
|
281
|
+
loading={pendingKey === ADD_KEY}
|
|
282
|
+
onClick={handleOpenAdd}
|
|
283
|
+
testID={`${testID}-add`}
|
|
284
|
+
text="Add a passkey"
|
|
285
|
+
variant="secondary"
|
|
286
|
+
/>
|
|
287
|
+
</Box>
|
|
288
|
+
)}
|
|
289
|
+
</Box>
|
|
290
|
+
|
|
291
|
+
{dialog?.kind === "add" && (
|
|
292
|
+
<Modal
|
|
293
|
+
onDismiss={handleDismissDialog}
|
|
294
|
+
primaryButtonOnClick={handleConfirmAdd}
|
|
295
|
+
primaryButtonText="Continue"
|
|
296
|
+
secondaryButtonOnClick={handleDismissDialog}
|
|
297
|
+
secondaryButtonText="Cancel"
|
|
298
|
+
testIDs={{
|
|
299
|
+
dismiss: `${testID}-add-dialog-dismiss`,
|
|
300
|
+
primaryButton: `${testID}-add-dialog-submit`,
|
|
301
|
+
root: `${testID}-add-dialog`,
|
|
302
|
+
secondaryButton: `${testID}-add-dialog-cancel`,
|
|
303
|
+
title: `${testID}-add-dialog-title`,
|
|
304
|
+
}}
|
|
305
|
+
text="Your device will ask you to confirm with your fingerprint, face, or screen lock."
|
|
306
|
+
title="Add a passkey"
|
|
307
|
+
visible
|
|
308
|
+
>
|
|
309
|
+
<TextField
|
|
310
|
+
accessibilityLabel="Passkey name"
|
|
311
|
+
helperText="Optional. For example, “Work laptop”."
|
|
312
|
+
onChange={setNameDraft}
|
|
313
|
+
onEnter={handleConfirmAdd}
|
|
314
|
+
testID={`${testID}-add-dialog-name`}
|
|
315
|
+
title="Name"
|
|
316
|
+
value={nameDraft}
|
|
317
|
+
/>
|
|
318
|
+
</Modal>
|
|
319
|
+
)}
|
|
320
|
+
|
|
321
|
+
{dialog?.kind === "rename" && (
|
|
322
|
+
<Modal
|
|
323
|
+
onDismiss={handleDismissDialog}
|
|
324
|
+
primaryButtonDisabled={!trimmedDraft || isRenameUnchanged}
|
|
325
|
+
primaryButtonOnClick={handleConfirmRename}
|
|
326
|
+
primaryButtonText="Save"
|
|
327
|
+
secondaryButtonOnClick={handleDismissDialog}
|
|
328
|
+
secondaryButtonText="Cancel"
|
|
329
|
+
testIDs={{
|
|
330
|
+
dismiss: `${testID}-rename-dialog-dismiss`,
|
|
331
|
+
primaryButton: `${testID}-rename-dialog-submit`,
|
|
332
|
+
root: `${testID}-rename-dialog`,
|
|
333
|
+
secondaryButton: `${testID}-rename-dialog-cancel`,
|
|
334
|
+
title: `${testID}-rename-dialog-title`,
|
|
335
|
+
}}
|
|
336
|
+
title={`Rename ${getPasskeyLabel(dialog.passkey)}`}
|
|
337
|
+
visible
|
|
338
|
+
>
|
|
339
|
+
<TextField
|
|
340
|
+
accessibilityLabel="Passkey name"
|
|
341
|
+
onChange={setNameDraft}
|
|
342
|
+
onEnter={handleConfirmRename}
|
|
343
|
+
testID={`${testID}-rename-dialog-name`}
|
|
344
|
+
title="Name"
|
|
345
|
+
value={nameDraft}
|
|
346
|
+
/>
|
|
347
|
+
</Modal>
|
|
348
|
+
)}
|
|
349
|
+
|
|
350
|
+
{dialog?.kind === "remove" && (
|
|
351
|
+
<Modal
|
|
352
|
+
onDismiss={handleDismissDialog}
|
|
353
|
+
primaryButtonOnClick={handleConfirmRemove}
|
|
354
|
+
primaryButtonText="Remove"
|
|
355
|
+
secondaryButtonOnClick={handleDismissDialog}
|
|
356
|
+
secondaryButtonText="Cancel"
|
|
357
|
+
testIDs={{
|
|
358
|
+
dismiss: `${testID}-confirm-dismiss`,
|
|
359
|
+
primaryButton: `${testID}-confirm-submit`,
|
|
360
|
+
root: `${testID}-confirm`,
|
|
361
|
+
secondaryButton: `${testID}-confirm-cancel`,
|
|
362
|
+
title: `${testID}-confirm-title`,
|
|
363
|
+
}}
|
|
364
|
+
text="You won't be able to sign in with this passkey anymore. Also remove it from your device or password manager."
|
|
365
|
+
title={`Remove ${getPasskeyLabel(dialog.passkey)}?`}
|
|
366
|
+
visible
|
|
367
|
+
/>
|
|
368
|
+
)}
|
|
369
|
+
</Card>
|
|
370
|
+
);
|
|
371
|
+
};
|