@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 {describe, expect, it, mock, spyOn} from "bun:test";
|
|
2
|
+
import {act, fireEvent, waitFor} from "@testing-library/react-native";
|
|
3
|
+
import {DateTime} from "luxon";
|
|
4
|
+
import {ActivityIndicator} from "react-native";
|
|
5
|
+
|
|
6
|
+
import {renderWithTheme} from "../test-utils";
|
|
7
|
+
import {LinkedAccountsCard} from "./LinkedAccountsCard";
|
|
8
|
+
import type {LinkableProvider, LinkedAccount} from "./securityTypes";
|
|
9
|
+
|
|
10
|
+
const PROVIDERS: LinkableProvider[] = [{id: "google"}, {id: "github"}];
|
|
11
|
+
|
|
12
|
+
const LINKED_AT = "2026-03-03T12:00:00.000Z";
|
|
13
|
+
// Computed with Luxon so the expectation follows the test runner's locale and time zone.
|
|
14
|
+
const LINKED_DATE = DateTime.fromISO(LINKED_AT).toLocaleString(DateTime.DATE_MED);
|
|
15
|
+
|
|
16
|
+
const GOOGLE: LinkedAccount = {
|
|
17
|
+
accountId: "g-1",
|
|
18
|
+
email: "ada@example.com",
|
|
19
|
+
id: "acc-google",
|
|
20
|
+
linkedAt: LINKED_AT,
|
|
21
|
+
providerId: "google",
|
|
22
|
+
};
|
|
23
|
+
const CREDENTIAL: LinkedAccount = {
|
|
24
|
+
accountId: "u-1",
|
|
25
|
+
id: "acc-credential",
|
|
26
|
+
providerId: "credential",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const press = async (element: Parameters<typeof fireEvent.press>[0]): Promise<void> => {
|
|
30
|
+
await act(async () => {
|
|
31
|
+
fireEvent.press(element);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const isDisabled = (element: {props: Record<string, unknown>}): boolean => {
|
|
36
|
+
const state = element.props.accessibilityState as {disabled?: boolean} | undefined;
|
|
37
|
+
return Boolean(state?.disabled);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
describe("LinkedAccountsCard", () => {
|
|
41
|
+
it("lists linked providers with email and linked date, and unlinked ones with Link", () => {
|
|
42
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
43
|
+
<LinkedAccountsCard
|
|
44
|
+
accounts={[GOOGLE, CREDENTIAL]}
|
|
45
|
+
onLink={mock(() => Promise.resolve())}
|
|
46
|
+
onUnlink={mock(() => Promise.resolve())}
|
|
47
|
+
providers={PROVIDERS}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
expect(getByTestId("linked-accounts-card")).toBeTruthy();
|
|
51
|
+
expect(getByTestId("linked-accounts-card-name-google").props.children).toBe("Google");
|
|
52
|
+
const googleStatus = String(getByTestId("linked-accounts-card-status-google").props.children);
|
|
53
|
+
expect(googleStatus).toContain("ada@example.com");
|
|
54
|
+
expect(googleStatus).toContain(`Linked ${LINKED_DATE}`);
|
|
55
|
+
expect(getByTestId("linked-accounts-card-unlink-google")).toBeTruthy();
|
|
56
|
+
expect(queryByTestId("linked-accounts-card-link-google")).toBeNull();
|
|
57
|
+
|
|
58
|
+
expect(getByTestId("linked-accounts-card-status-github").props.children).toBe("Not linked");
|
|
59
|
+
expect(getByTestId("linked-accounts-card-link-github")).toBeTruthy();
|
|
60
|
+
expect(queryByTestId("linked-accounts-card-unlink-github")).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("does not list the password credential as a provider row", () => {
|
|
64
|
+
const {queryByTestId} = renderWithTheme(
|
|
65
|
+
<LinkedAccountsCard accounts={[GOOGLE, CREDENTIAL]} providers={PROVIDERS} />
|
|
66
|
+
);
|
|
67
|
+
expect(queryByTestId("linked-accounts-card-row-credential")).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("lists a linked account whose provider the app no longer offers", () => {
|
|
71
|
+
const {getByTestId} = renderWithTheme(
|
|
72
|
+
<LinkedAccountsCard
|
|
73
|
+
accounts={[CREDENTIAL, {accountId: "m-1", id: "acc-mock", providerId: "mock-oidc"}]}
|
|
74
|
+
providers={PROVIDERS}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
expect(getByTestId("linked-accounts-card-row-mock-oidc")).toBeTruthy();
|
|
78
|
+
expect(getByTestId("linked-accounts-card-name-mock-oidc").props.children).toBe("mock-oidc");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("uses a provider's label for generic providers", () => {
|
|
82
|
+
const {getByTestId} = renderWithTheme(
|
|
83
|
+
<LinkedAccountsCard accounts={[]} providers={[{id: "mock-oidc", label: "Company SSO"}]} />
|
|
84
|
+
);
|
|
85
|
+
expect(getByTestId("linked-accounts-card-name-mock-oidc").props.children).toBe("Company SSO");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("omits the linked date when linkedAt is not a valid date", () => {
|
|
89
|
+
const {getByTestId} = renderWithTheme(
|
|
90
|
+
<LinkedAccountsCard
|
|
91
|
+
accounts={[{...GOOGLE, linkedAt: "not-a-date"}, CREDENTIAL]}
|
|
92
|
+
providers={PROVIDERS}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
const status = String(getByTestId("linked-accounts-card-status-google").props.children);
|
|
96
|
+
expect(status).toBe("ada@example.com");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("formats a Date linkedAt, as the Better Auth client returns it", () => {
|
|
100
|
+
const linkedAt = new Date(LINKED_AT);
|
|
101
|
+
const {getByTestId} = renderWithTheme(
|
|
102
|
+
<LinkedAccountsCard
|
|
103
|
+
accounts={[{id: "acc-gh", linkedAt, providerId: "github"}, CREDENTIAL]}
|
|
104
|
+
providers={PROVIDERS}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
expect(getByTestId("linked-accounts-card-status-github").props.children).toBe(
|
|
108
|
+
`Linked ${DateTime.fromJSDate(linkedAt).toLocaleString(DateTime.DATE_MED)}`
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("gives each linked account of one provider its own unlinkable row", async () => {
|
|
113
|
+
const work: LinkedAccount = {
|
|
114
|
+
email: "ada@work.example",
|
|
115
|
+
id: "acc-google-2",
|
|
116
|
+
providerId: "google",
|
|
117
|
+
};
|
|
118
|
+
const onUnlink = mock((_providerId: string, _account: LinkedAccount) => Promise.resolve());
|
|
119
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
120
|
+
<LinkedAccountsCard
|
|
121
|
+
accounts={[GOOGLE, work, CREDENTIAL]}
|
|
122
|
+
onLink={mock(() => Promise.resolve())}
|
|
123
|
+
onUnlink={onUnlink}
|
|
124
|
+
providers={PROVIDERS}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
expect(getByTestId("linked-accounts-card-unlink-google")).toBeTruthy();
|
|
128
|
+
expect(getByTestId("linked-accounts-card-unlink-google-2")).toBeTruthy();
|
|
129
|
+
expect(queryByTestId("linked-accounts-card-link-google")).toBeNull();
|
|
130
|
+
expect(getByTestId("linked-accounts-card-link-github")).toBeTruthy();
|
|
131
|
+
|
|
132
|
+
await press(getByTestId("linked-accounts-card-unlink-google-2"));
|
|
133
|
+
await waitFor(() => {
|
|
134
|
+
expect(getByTestId("linked-accounts-card-confirm-submit")).toBeTruthy();
|
|
135
|
+
});
|
|
136
|
+
await press(getByTestId("linked-accounts-card-confirm-submit"));
|
|
137
|
+
await waitFor(() => {
|
|
138
|
+
expect(onUnlink).toHaveBeenCalledWith("google", work);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("disables every button with the disabled prop", () => {
|
|
143
|
+
const {getByTestId} = renderWithTheme(
|
|
144
|
+
<LinkedAccountsCard
|
|
145
|
+
accounts={[GOOGLE, CREDENTIAL]}
|
|
146
|
+
disabled
|
|
147
|
+
onLink={mock(() => Promise.resolve())}
|
|
148
|
+
onUnlink={mock(() => Promise.resolve())}
|
|
149
|
+
providers={PROVIDERS}
|
|
150
|
+
/>
|
|
151
|
+
);
|
|
152
|
+
expect(isDisabled(getByTestId("linked-accounts-card-unlink-google"))).toBe(true);
|
|
153
|
+
expect(isDisabled(getByTestId("linked-accounts-card-link-github"))).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("shows a spinner on the unlinking row and disables the others until unlink settles", async () => {
|
|
157
|
+
let resolveUnlink: () => void = () => {};
|
|
158
|
+
const onUnlink = mock(
|
|
159
|
+
(_providerId: string, _account: LinkedAccount) =>
|
|
160
|
+
new Promise<void>((resolve) => {
|
|
161
|
+
resolveUnlink = resolve;
|
|
162
|
+
})
|
|
163
|
+
);
|
|
164
|
+
const {getByTestId} = renderWithTheme(
|
|
165
|
+
<LinkedAccountsCard
|
|
166
|
+
accounts={[GOOGLE, CREDENTIAL]}
|
|
167
|
+
onLink={mock(() => Promise.resolve())}
|
|
168
|
+
onUnlink={onUnlink}
|
|
169
|
+
providers={PROVIDERS}
|
|
170
|
+
/>
|
|
171
|
+
);
|
|
172
|
+
await press(getByTestId("linked-accounts-card-unlink-google"));
|
|
173
|
+
await waitFor(() => {
|
|
174
|
+
expect(getByTestId("linked-accounts-card-confirm-submit")).toBeTruthy();
|
|
175
|
+
});
|
|
176
|
+
await press(getByTestId("linked-accounts-card-confirm-submit"));
|
|
177
|
+
await waitFor(() => {
|
|
178
|
+
expect(onUnlink).toHaveBeenCalled();
|
|
179
|
+
});
|
|
180
|
+
const unlinkButton = getByTestId("linked-accounts-card-unlink-google");
|
|
181
|
+
expect(isDisabled(unlinkButton)).toBe(true);
|
|
182
|
+
expect(unlinkButton.findAllByType(ActivityIndicator).length).toBe(1);
|
|
183
|
+
const linkButton = getByTestId("linked-accounts-card-link-github");
|
|
184
|
+
expect(isDisabled(linkButton)).toBe(true);
|
|
185
|
+
expect(linkButton.findAllByType(ActivityIndicator).length).toBe(0);
|
|
186
|
+
|
|
187
|
+
await act(async () => {
|
|
188
|
+
resolveUnlink();
|
|
189
|
+
});
|
|
190
|
+
await waitFor(() => {
|
|
191
|
+
expect(isDisabled(getByTestId("linked-accounts-card-link-github"))).toBe(false);
|
|
192
|
+
});
|
|
193
|
+
expect(
|
|
194
|
+
getByTestId("linked-accounts-card-unlink-google").findAllByType(ActivityIndicator).length
|
|
195
|
+
).toBe(0);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("calls onLink with the provider id and shows a spinner on that row while pending", async () => {
|
|
199
|
+
let resolveLink: () => void = () => {};
|
|
200
|
+
const onLink = mock(
|
|
201
|
+
(_providerId: string) =>
|
|
202
|
+
new Promise<void>((resolve) => {
|
|
203
|
+
resolveLink = resolve;
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
const {getByTestId} = renderWithTheme(
|
|
207
|
+
<LinkedAccountsCard accounts={[CREDENTIAL]} onLink={onLink} providers={PROVIDERS} />
|
|
208
|
+
);
|
|
209
|
+
await press(getByTestId("linked-accounts-card-link-github"));
|
|
210
|
+
expect(onLink).toHaveBeenCalledWith("github");
|
|
211
|
+
await waitFor(() => {
|
|
212
|
+
expect(isDisabled(getByTestId("linked-accounts-card-link-github"))).toBe(true);
|
|
213
|
+
expect(isDisabled(getByTestId("linked-accounts-card-link-google"))).toBe(true);
|
|
214
|
+
});
|
|
215
|
+
await act(async () => {
|
|
216
|
+
resolveLink();
|
|
217
|
+
});
|
|
218
|
+
await waitFor(() => {
|
|
219
|
+
expect(isDisabled(getByTestId("linked-accounts-card-link-github"))).toBe(false);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("asks for confirmation before unlinking and unlinks on confirm", async () => {
|
|
224
|
+
const onUnlink = mock((_providerId: string, _account: LinkedAccount) => Promise.resolve());
|
|
225
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
226
|
+
<LinkedAccountsCard
|
|
227
|
+
accounts={[GOOGLE, CREDENTIAL]}
|
|
228
|
+
onUnlink={onUnlink}
|
|
229
|
+
providers={PROVIDERS}
|
|
230
|
+
/>
|
|
231
|
+
);
|
|
232
|
+
expect(queryByTestId("linked-accounts-card-confirm")).toBeNull();
|
|
233
|
+
|
|
234
|
+
await press(getByTestId("linked-accounts-card-unlink-google"));
|
|
235
|
+
await waitFor(() => {
|
|
236
|
+
expect(getByTestId("linked-accounts-card-confirm")).toBeTruthy();
|
|
237
|
+
});
|
|
238
|
+
expect(onUnlink).not.toHaveBeenCalled();
|
|
239
|
+
|
|
240
|
+
await press(getByTestId("linked-accounts-card-confirm-submit"));
|
|
241
|
+
await waitFor(() => {
|
|
242
|
+
expect(onUnlink).toHaveBeenCalledWith("google", GOOGLE);
|
|
243
|
+
});
|
|
244
|
+
await waitFor(() => {
|
|
245
|
+
expect(queryByTestId("linked-accounts-card-confirm")).toBeNull();
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("does not unlink when the confirmation is cancelled", async () => {
|
|
250
|
+
const onUnlink = mock((_providerId: string, _account: LinkedAccount) => Promise.resolve());
|
|
251
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
252
|
+
<LinkedAccountsCard
|
|
253
|
+
accounts={[GOOGLE, CREDENTIAL]}
|
|
254
|
+
onUnlink={onUnlink}
|
|
255
|
+
providers={PROVIDERS}
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
await press(getByTestId("linked-accounts-card-unlink-google"));
|
|
259
|
+
await waitFor(() => {
|
|
260
|
+
expect(getByTestId("linked-accounts-card-confirm-cancel")).toBeTruthy();
|
|
261
|
+
});
|
|
262
|
+
await press(getByTestId("linked-accounts-card-confirm-cancel"));
|
|
263
|
+
await waitFor(() => {
|
|
264
|
+
expect(queryByTestId("linked-accounts-card-confirm")).toBeNull();
|
|
265
|
+
});
|
|
266
|
+
expect(onUnlink).not.toHaveBeenCalled();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("disables Unlink with an explanation when it is the only sign-in method", () => {
|
|
270
|
+
const {getByTestId} = renderWithTheme(
|
|
271
|
+
<LinkedAccountsCard
|
|
272
|
+
accounts={[GOOGLE]}
|
|
273
|
+
onUnlink={mock(() => Promise.resolve())}
|
|
274
|
+
providers={PROVIDERS}
|
|
275
|
+
/>
|
|
276
|
+
);
|
|
277
|
+
expect(isDisabled(getByTestId("linked-accounts-card-unlink-google"))).toBe(true);
|
|
278
|
+
expect(getByTestId("linked-accounts-card-last-method-google")).toBeTruthy();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("allows Unlink when the user also has a password", () => {
|
|
282
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
283
|
+
<LinkedAccountsCard
|
|
284
|
+
accounts={[GOOGLE, CREDENTIAL]}
|
|
285
|
+
onUnlink={mock(() => Promise.resolve())}
|
|
286
|
+
providers={PROVIDERS}
|
|
287
|
+
/>
|
|
288
|
+
);
|
|
289
|
+
expect(isDisabled(getByTestId("linked-accounts-card-unlink-google"))).toBe(false);
|
|
290
|
+
expect(queryByTestId("linked-accounts-card-last-method-google")).toBeNull();
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("counts passkeys passed as otherMethodCount as a sign-in method", () => {
|
|
294
|
+
const {getByTestId} = renderWithTheme(
|
|
295
|
+
<LinkedAccountsCard
|
|
296
|
+
accounts={[GOOGLE]}
|
|
297
|
+
onUnlink={mock(() => Promise.resolve())}
|
|
298
|
+
otherMethodCount={1}
|
|
299
|
+
providers={PROVIDERS}
|
|
300
|
+
/>
|
|
301
|
+
);
|
|
302
|
+
expect(isDisabled(getByTestId("linked-accounts-card-unlink-google"))).toBe(false);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("allows unlinking the last method with canUnlinkLast", () => {
|
|
306
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
307
|
+
<LinkedAccountsCard
|
|
308
|
+
accounts={[GOOGLE]}
|
|
309
|
+
canUnlinkLast
|
|
310
|
+
onUnlink={mock(() => Promise.resolve())}
|
|
311
|
+
providers={PROVIDERS}
|
|
312
|
+
/>
|
|
313
|
+
);
|
|
314
|
+
expect(isDisabled(getByTestId("linked-accounts-card-unlink-google"))).toBe(false);
|
|
315
|
+
expect(queryByTestId("linked-accounts-card-last-method-google")).toBeNull();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("shows a rejected unlink's message as an alert", async () => {
|
|
319
|
+
const warn = spyOn(console, "warn").mockImplementation(() => {});
|
|
320
|
+
const onUnlink = mock((_providerId: string, _account: LinkedAccount) =>
|
|
321
|
+
Promise.reject(new Error("You can't unlink your last account"))
|
|
322
|
+
);
|
|
323
|
+
const {getByTestId} = renderWithTheme(
|
|
324
|
+
<LinkedAccountsCard
|
|
325
|
+
accounts={[GOOGLE, CREDENTIAL]}
|
|
326
|
+
onUnlink={onUnlink}
|
|
327
|
+
providers={PROVIDERS}
|
|
328
|
+
/>
|
|
329
|
+
);
|
|
330
|
+
await press(getByTestId("linked-accounts-card-unlink-google"));
|
|
331
|
+
await waitFor(() => {
|
|
332
|
+
expect(getByTestId("linked-accounts-card-confirm-submit")).toBeTruthy();
|
|
333
|
+
});
|
|
334
|
+
await press(getByTestId("linked-accounts-card-confirm-submit"));
|
|
335
|
+
await waitFor(() => {
|
|
336
|
+
expect(getByTestId("linked-accounts-card-error")).toBeTruthy();
|
|
337
|
+
});
|
|
338
|
+
expect(getByTestId("linked-accounts-card-error").props.role).toBe("alert");
|
|
339
|
+
expect(isDisabled(getByTestId("linked-accounts-card-unlink-google"))).toBe(false);
|
|
340
|
+
warn.mockRestore();
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("shows the error prop as an alert", () => {
|
|
344
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
345
|
+
<LinkedAccountsCard accounts={[]} error="Linking failed" providers={PROVIDERS} />
|
|
346
|
+
);
|
|
347
|
+
expect(getByTestId("linked-accounts-card-error").props.role).toBe("alert");
|
|
348
|
+
expect(getByText("Linking failed")).toBeTruthy();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("names the Link and Unlink buttons after their provider", () => {
|
|
352
|
+
const {getByLabelText} = renderWithTheme(
|
|
353
|
+
<LinkedAccountsCard
|
|
354
|
+
accounts={[GOOGLE, CREDENTIAL]}
|
|
355
|
+
onLink={mock(() => Promise.resolve())}
|
|
356
|
+
onUnlink={mock(() => Promise.resolve())}
|
|
357
|
+
providers={PROVIDERS}
|
|
358
|
+
/>
|
|
359
|
+
);
|
|
360
|
+
expect(getByLabelText("Unlink Google (ada@example.com)")).toBeTruthy();
|
|
361
|
+
expect(getByLabelText("Link GitHub")).toBeTruthy();
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("hides the buttons when no callbacks are given", () => {
|
|
365
|
+
const {queryByTestId} = renderWithTheme(
|
|
366
|
+
<LinkedAccountsCard accounts={[GOOGLE, CREDENTIAL]} providers={PROVIDERS} />
|
|
367
|
+
);
|
|
368
|
+
expect(queryByTestId("linked-accounts-card-unlink-google")).toBeNull();
|
|
369
|
+
expect(queryByTestId("linked-accounts-card-link-github")).toBeNull();
|
|
370
|
+
});
|
|
371
|
+
});
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import {type FC, useCallback, useMemo, useState} from "react";
|
|
2
|
+
import {View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import {Box} from "../Box";
|
|
5
|
+
import {Button} from "../Button";
|
|
6
|
+
import {Card} from "../Card";
|
|
7
|
+
import {Heading} from "../Heading";
|
|
8
|
+
import {Icon} from "../Icon";
|
|
9
|
+
import {Modal} from "../Modal";
|
|
10
|
+
import {Text} from "../Text";
|
|
11
|
+
import {
|
|
12
|
+
CREDENTIAL_PROVIDER_ID,
|
|
13
|
+
formatSecurityDate,
|
|
14
|
+
getProviderDisplay,
|
|
15
|
+
getRejectionMessage,
|
|
16
|
+
type ProviderDisplay,
|
|
17
|
+
} from "./securityMethods";
|
|
18
|
+
import type {LinkableProvider, LinkedAccount, LinkedAccountsCardProps} from "./securityTypes";
|
|
19
|
+
|
|
20
|
+
/** One row: a linked account, or an offered provider with no linked account. */
|
|
21
|
+
interface ProviderRow {
|
|
22
|
+
/** React key: the account id, or the provider id for an unlinked row. */
|
|
23
|
+
key: string;
|
|
24
|
+
/** testID suffix: the provider id, plus `-2`, `-3`, ... for a provider's later accounts. */
|
|
25
|
+
testIDSuffix: string;
|
|
26
|
+
providerId: string;
|
|
27
|
+
display: ProviderDisplay;
|
|
28
|
+
account?: LinkedAccount;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Builds one row per linked account (so two Google accounts are each unlinkable), grouped under
|
|
33
|
+
* the offered providers in order, with a Link row for each offered provider that has none.
|
|
34
|
+
* Accounts for providers the app no longer offers follow.
|
|
35
|
+
*/
|
|
36
|
+
const buildRows = ({
|
|
37
|
+
accounts,
|
|
38
|
+
providers,
|
|
39
|
+
}: {
|
|
40
|
+
accounts: LinkedAccount[];
|
|
41
|
+
providers: LinkableProvider[];
|
|
42
|
+
}): ProviderRow[] => {
|
|
43
|
+
const socialAccounts = accounts.filter(
|
|
44
|
+
(account) => account.providerId !== CREDENTIAL_PROVIDER_ID
|
|
45
|
+
);
|
|
46
|
+
const offeredIds = new Set(providers.map((provider) => provider.id));
|
|
47
|
+
const accountRows = (providerId: string, display: ProviderDisplay): ProviderRow[] => {
|
|
48
|
+
return socialAccounts
|
|
49
|
+
.filter((account) => account.providerId === providerId)
|
|
50
|
+
.map((account, index) => ({
|
|
51
|
+
account,
|
|
52
|
+
display,
|
|
53
|
+
key: account.id,
|
|
54
|
+
providerId,
|
|
55
|
+
testIDSuffix: index === 0 ? providerId : `${providerId}-${index + 1}`,
|
|
56
|
+
}));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const rows: ProviderRow[] = [];
|
|
60
|
+
for (const provider of providers) {
|
|
61
|
+
const display = getProviderDisplay({provider, providerId: provider.id});
|
|
62
|
+
const linkedRows = accountRows(provider.id, display);
|
|
63
|
+
if (linkedRows.length > 0) {
|
|
64
|
+
rows.push(...linkedRows);
|
|
65
|
+
} else {
|
|
66
|
+
rows.push({display, key: provider.id, providerId: provider.id, testIDSuffix: provider.id});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const extraProviderIds = [...new Set(socialAccounts.map((account) => account.providerId))].filter(
|
|
70
|
+
(providerId) => !offeredIds.has(providerId)
|
|
71
|
+
);
|
|
72
|
+
for (const providerId of extraProviderIds) {
|
|
73
|
+
rows.push(...accountRows(providerId, getProviderDisplay({providerId})));
|
|
74
|
+
}
|
|
75
|
+
return rows;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** "ada@example.com · Linked Mar 3, 2026", or "Linked" when neither is known. */
|
|
79
|
+
const describeLinkedAccount = (account: LinkedAccount): string => {
|
|
80
|
+
const linkedDate = formatSecurityDate(account.linkedAt);
|
|
81
|
+
const parts = [account.email, linkedDate ? `Linked ${linkedDate}` : undefined].filter(
|
|
82
|
+
(part): part is string => Boolean(part)
|
|
83
|
+
);
|
|
84
|
+
return parts.length > 0 ? parts.join(" · ") : "Linked";
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Lists the sign-in providers an app offers, each linked (with its email and linked date) or not,
|
|
89
|
+
* with Link and Unlink buttons. Unlink asks for confirmation, and is disabled with an explanation
|
|
90
|
+
* when the account is the user's last way to sign in. Presentational: it reports actions through
|
|
91
|
+
* `onLink` and `onUnlink` and never calls an auth client itself.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* <LinkedAccountsCard
|
|
96
|
+
* accounts={accounts} // listAccounts() entries as LinkedAccount ({id, providerId, linkedAt: createdAt})
|
|
97
|
+
* providers={[{id: "google"}, {id: "github"}]}
|
|
98
|
+
* otherMethodCount={passkeys.length}
|
|
99
|
+
* onLink={async (providerId) => {
|
|
100
|
+
* const {error} = await authClient.linkSocial({provider: providerId, callbackURL});
|
|
101
|
+
* if (error) {
|
|
102
|
+
* throw new Error(error.message ?? "Couldn't link that account.");
|
|
103
|
+
* }
|
|
104
|
+
* }}
|
|
105
|
+
* onUnlink={async (_providerId, account) => {
|
|
106
|
+
* // The Better Auth client resolves {data, error} rather than throwing.
|
|
107
|
+
* const {error} = await authClient.unlinkAccount({accountId: account.id});
|
|
108
|
+
* if (error) {
|
|
109
|
+
* throw new Error(error.message ?? "Couldn't unlink that account.");
|
|
110
|
+
* }
|
|
111
|
+
* }}
|
|
112
|
+
* />
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export const LinkedAccountsCard: FC<LinkedAccountsCardProps> = ({
|
|
116
|
+
accounts,
|
|
117
|
+
providers,
|
|
118
|
+
onLink,
|
|
119
|
+
onUnlink,
|
|
120
|
+
otherMethodCount = 0,
|
|
121
|
+
canUnlinkLast = false,
|
|
122
|
+
error,
|
|
123
|
+
disabled = false,
|
|
124
|
+
title = "Linked accounts",
|
|
125
|
+
description = "Sign in with any account linked here.",
|
|
126
|
+
testID = "linked-accounts-card",
|
|
127
|
+
}) => {
|
|
128
|
+
const [pendingRowKey, setPendingRowKey] = useState<string | undefined>(undefined);
|
|
129
|
+
const [confirmRow, setConfirmRow] = useState<ProviderRow | undefined>(undefined);
|
|
130
|
+
const [actionError, setActionError] = useState<string | undefined>(undefined);
|
|
131
|
+
|
|
132
|
+
const rows = useMemo(() => buildRows({accounts, providers}), [accounts, providers]);
|
|
133
|
+
const isLastMethod = accounts.length + otherMethodCount <= 1;
|
|
134
|
+
const isBusy = disabled || pendingRowKey !== undefined;
|
|
135
|
+
const shownError = error ?? actionError;
|
|
136
|
+
|
|
137
|
+
const runAction = useCallback(
|
|
138
|
+
async ({
|
|
139
|
+
rowKey,
|
|
140
|
+
action,
|
|
141
|
+
fallback,
|
|
142
|
+
}: {
|
|
143
|
+
rowKey: string;
|
|
144
|
+
action: () => void | Promise<void>;
|
|
145
|
+
fallback: string;
|
|
146
|
+
}): Promise<void> => {
|
|
147
|
+
setActionError(undefined);
|
|
148
|
+
setPendingRowKey(rowKey);
|
|
149
|
+
try {
|
|
150
|
+
await action();
|
|
151
|
+
} catch (rejection: unknown) {
|
|
152
|
+
console.warn("LinkedAccountsCard: action rejected", rejection);
|
|
153
|
+
setActionError(getRejectionMessage({error: rejection, fallback}));
|
|
154
|
+
} finally {
|
|
155
|
+
setPendingRowKey(undefined);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
[]
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const handleLink = useCallback(
|
|
162
|
+
async (row: ProviderRow): Promise<void> => {
|
|
163
|
+
if (!onLink || isBusy) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
await runAction({
|
|
167
|
+
action: () => onLink(row.providerId),
|
|
168
|
+
fallback: `Couldn't link ${row.display.label}. Try again.`,
|
|
169
|
+
rowKey: row.key,
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
[isBusy, onLink, runAction]
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const handleDismissConfirm = useCallback((): void => {
|
|
176
|
+
setConfirmRow(undefined);
|
|
177
|
+
}, []);
|
|
178
|
+
|
|
179
|
+
const handleConfirmUnlink = useCallback(async (): Promise<void> => {
|
|
180
|
+
const row = confirmRow;
|
|
181
|
+
setConfirmRow(undefined);
|
|
182
|
+
if (!row?.account || !onUnlink) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const account = row.account;
|
|
186
|
+
await runAction({
|
|
187
|
+
action: () => onUnlink(row.providerId, account),
|
|
188
|
+
fallback: `Couldn't unlink ${row.display.label}. Try again.`,
|
|
189
|
+
rowKey: row.key,
|
|
190
|
+
});
|
|
191
|
+
}, [confirmRow, onUnlink, runAction]);
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<Card testID={testID}>
|
|
195
|
+
<Box gap={4}>
|
|
196
|
+
<Box gap={1}>
|
|
197
|
+
<Heading level={2} size="md" testID={`${testID}-title`}>
|
|
198
|
+
{title}
|
|
199
|
+
</Heading>
|
|
200
|
+
<Text color="secondaryLight">{description}</Text>
|
|
201
|
+
</Box>
|
|
202
|
+
|
|
203
|
+
{rows.map((row) => {
|
|
204
|
+
const {account, display, key, testIDSuffix} = row;
|
|
205
|
+
const isPending = pendingRowKey === key;
|
|
206
|
+
const isUnlinkBlocked = Boolean(account) && isLastMethod && !canUnlinkLast;
|
|
207
|
+
return (
|
|
208
|
+
<Box gap={1} key={key} testID={`${testID}-row-${testIDSuffix}`}>
|
|
209
|
+
<Box alignItems="center" direction="row" gap={3}>
|
|
210
|
+
<Box alignItems="center" width={24}>
|
|
211
|
+
<Icon iconName={display.iconName} size="lg" type={display.iconType} />
|
|
212
|
+
</Box>
|
|
213
|
+
<Box flex="grow" gap={1}>
|
|
214
|
+
<Text bold testID={`${testID}-name-${testIDSuffix}`}>
|
|
215
|
+
{display.label}
|
|
216
|
+
</Text>
|
|
217
|
+
<Text
|
|
218
|
+
color="secondaryLight"
|
|
219
|
+
size="sm"
|
|
220
|
+
testID={`${testID}-status-${testIDSuffix}`}
|
|
221
|
+
>
|
|
222
|
+
{account ? describeLinkedAccount(account) : "Not linked"}
|
|
223
|
+
</Text>
|
|
224
|
+
</Box>
|
|
225
|
+
{account && Boolean(onUnlink) && (
|
|
226
|
+
<Button
|
|
227
|
+
accessibilityLabel={
|
|
228
|
+
account.email
|
|
229
|
+
? `Unlink ${display.label} (${account.email})`
|
|
230
|
+
: `Unlink ${display.label}`
|
|
231
|
+
}
|
|
232
|
+
disabled={isBusy || isUnlinkBlocked}
|
|
233
|
+
loading={isPending}
|
|
234
|
+
onClick={() => setConfirmRow(row)}
|
|
235
|
+
size="sm"
|
|
236
|
+
testID={`${testID}-unlink-${testIDSuffix}`}
|
|
237
|
+
text="Unlink"
|
|
238
|
+
variant="outline"
|
|
239
|
+
/>
|
|
240
|
+
)}
|
|
241
|
+
{!account && Boolean(onLink) && (
|
|
242
|
+
<Button
|
|
243
|
+
accessibilityLabel={`Link ${display.label}`}
|
|
244
|
+
disabled={isBusy}
|
|
245
|
+
loading={isPending}
|
|
246
|
+
onClick={() => handleLink(row)}
|
|
247
|
+
size="sm"
|
|
248
|
+
testID={`${testID}-link-${testIDSuffix}`}
|
|
249
|
+
text="Link"
|
|
250
|
+
variant="secondary"
|
|
251
|
+
/>
|
|
252
|
+
)}
|
|
253
|
+
</Box>
|
|
254
|
+
{isUnlinkBlocked && Boolean(onUnlink) && (
|
|
255
|
+
<Text
|
|
256
|
+
color="secondaryLight"
|
|
257
|
+
size="sm"
|
|
258
|
+
testID={`${testID}-last-method-${testIDSuffix}`}
|
|
259
|
+
>
|
|
260
|
+
{`${display.label} is your only way to sign in. Add a password, a passkey, or another account before unlinking it.`}
|
|
261
|
+
</Text>
|
|
262
|
+
)}
|
|
263
|
+
</Box>
|
|
264
|
+
);
|
|
265
|
+
})}
|
|
266
|
+
|
|
267
|
+
{Boolean(shownError) && (
|
|
268
|
+
<View role="alert" testID={`${testID}-error`}>
|
|
269
|
+
<Text color="error">{shownError}</Text>
|
|
270
|
+
</View>
|
|
271
|
+
)}
|
|
272
|
+
</Box>
|
|
273
|
+
|
|
274
|
+
{confirmRow !== undefined && (
|
|
275
|
+
<Modal
|
|
276
|
+
onDismiss={handleDismissConfirm}
|
|
277
|
+
primaryButtonOnClick={handleConfirmUnlink}
|
|
278
|
+
primaryButtonText="Unlink"
|
|
279
|
+
secondaryButtonOnClick={handleDismissConfirm}
|
|
280
|
+
secondaryButtonText="Cancel"
|
|
281
|
+
testIDs={{
|
|
282
|
+
dismiss: `${testID}-confirm-dismiss`,
|
|
283
|
+
primaryButton: `${testID}-confirm-submit`,
|
|
284
|
+
root: `${testID}-confirm`,
|
|
285
|
+
secondaryButton: `${testID}-confirm-cancel`,
|
|
286
|
+
title: `${testID}-confirm-title`,
|
|
287
|
+
}}
|
|
288
|
+
text={`You won't be able to sign in with ${confirmRow.display.label}${
|
|
289
|
+
confirmRow.account?.email ? ` (${confirmRow.account.email})` : ""
|
|
290
|
+
} anymore. You can link it again later.`}
|
|
291
|
+
title={`Unlink ${confirmRow.display.label}?`}
|
|
292
|
+
visible
|
|
293
|
+
/>
|
|
294
|
+
)}
|
|
295
|
+
</Card>
|
|
296
|
+
);
|
|
297
|
+
};
|