@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
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type {FC} from "react";
|
|
2
|
-
import {useCallback, useState} from "react";
|
|
2
|
+
import {useCallback, useRef, useState} from "react";
|
|
3
|
+
import type {TextInput} from "react-native";
|
|
3
4
|
|
|
4
5
|
import {Box} from "../Box";
|
|
5
6
|
import {Button} from "../Button";
|
|
7
|
+
import type {TextFieldProps} from "../Common";
|
|
8
|
+
import {FormContainer, type FormContainerHandle} from "../FormContainer";
|
|
6
9
|
import {Heading} from "../Heading";
|
|
7
10
|
import {Page} from "../Page";
|
|
8
11
|
import {Text} from "../Text";
|
|
@@ -10,7 +13,22 @@ import {TextField} from "../TextField";
|
|
|
10
13
|
import {OAuthButtons} from "./OAuthButtons";
|
|
11
14
|
import {PasswordRequirements} from "./PasswordRequirements";
|
|
12
15
|
import {Swiper} from "./Swiper";
|
|
13
|
-
import type {SignUpScreenProps} from "./signUpTypes";
|
|
16
|
+
import type {SignUpFieldConfig, SignUpScreenProps} from "./signUpTypes";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The autofill hint for a field: its own hint, else "username" for the email field (password
|
|
20
|
+
* managers save it with the new password) and "new-password" for password fields (browsers and
|
|
21
|
+
* iOS then offer a strong password).
|
|
22
|
+
*/
|
|
23
|
+
const getFieldAutoComplete = (field: SignUpFieldConfig): TextFieldProps["autoComplete"] => {
|
|
24
|
+
if (field.autoComplete) {
|
|
25
|
+
return field.autoComplete;
|
|
26
|
+
}
|
|
27
|
+
if (field.type === "email" || field.name === "email") {
|
|
28
|
+
return "username";
|
|
29
|
+
}
|
|
30
|
+
return field.type === "password" ? "new-password" : undefined;
|
|
31
|
+
};
|
|
14
32
|
|
|
15
33
|
/**
|
|
16
34
|
* A configurable sign-up screen component with support for custom fields,
|
|
@@ -61,10 +79,6 @@ export const SignUpScreen: FC<SignUpScreenProps> = ({
|
|
|
61
79
|
setFormValues((prev) => ({...prev, [fieldName]: value}));
|
|
62
80
|
}, []);
|
|
63
81
|
|
|
64
|
-
const handleSubmit = useCallback(async () => {
|
|
65
|
-
await onSubmit(formValues);
|
|
66
|
-
}, [formValues, onSubmit]);
|
|
67
|
-
|
|
68
82
|
const passwordField = fields.find((f) => f.type === "password");
|
|
69
83
|
const passwordValue = passwordField ? (formValues[passwordField.name] ?? "") : "";
|
|
70
84
|
|
|
@@ -79,6 +93,36 @@ export const SignUpScreen: FC<SignUpScreenProps> = ({
|
|
|
79
93
|
|
|
80
94
|
const isSubmitDisabled = loading || !requiredFieldsFilled || !allRequirementsMet;
|
|
81
95
|
|
|
96
|
+
const formRef = useRef<FormContainerHandle>(null);
|
|
97
|
+
const inputRefs = useRef<Record<string, TextInput | null>>({});
|
|
98
|
+
// Blocks a second submission (Enter plus a press, or a double Enter) before `loading` lands.
|
|
99
|
+
const isSubmittingRef = useRef(false);
|
|
100
|
+
|
|
101
|
+
// Every submission (Enter, the Sign Up button, or the browser) arrives here through the form.
|
|
102
|
+
const handleSubmit = useCallback(async (): Promise<void> => {
|
|
103
|
+
if (isSubmitDisabled || isSubmittingRef.current) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
isSubmittingRef.current = true;
|
|
107
|
+
try {
|
|
108
|
+
await onSubmit(formValues);
|
|
109
|
+
} finally {
|
|
110
|
+
isSubmittingRef.current = false;
|
|
111
|
+
}
|
|
112
|
+
}, [formValues, isSubmitDisabled, onSubmit]);
|
|
113
|
+
|
|
114
|
+
// On web this goes through the <form>, so password managers see a real submit.
|
|
115
|
+
const requestSubmit = useCallback(async (): Promise<void> => {
|
|
116
|
+
if (isSubmitDisabled) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
await formRef.current?.requestSubmit();
|
|
120
|
+
}, [isSubmitDisabled]);
|
|
121
|
+
|
|
122
|
+
const focusField = useCallback((fieldName: string): void => {
|
|
123
|
+
inputRefs.current[fieldName]?.focus();
|
|
124
|
+
}, []);
|
|
125
|
+
|
|
82
126
|
return (
|
|
83
127
|
<Page navigation={undefined}>
|
|
84
128
|
<Box
|
|
@@ -103,23 +147,41 @@ export const SignUpScreen: FC<SignUpScreenProps> = ({
|
|
|
103
147
|
<Heading testID={`${testID}-title`}>{title}</Heading>
|
|
104
148
|
</Box>
|
|
105
149
|
|
|
106
|
-
<
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
150
|
+
<FormContainer
|
|
151
|
+
accessibilityLabel={title}
|
|
152
|
+
gap={4}
|
|
153
|
+
onSubmit={handleSubmit}
|
|
154
|
+
ref={formRef}
|
|
155
|
+
testID={`${testID}-form`}
|
|
156
|
+
width="100%"
|
|
157
|
+
>
|
|
158
|
+
{fields.map((field, index) => {
|
|
159
|
+
// Enter moves to the next field; in the last field it submits.
|
|
160
|
+
const nextField = fields[index + 1];
|
|
161
|
+
return (
|
|
162
|
+
<TextField
|
|
163
|
+
accessibilityLabel={field.label}
|
|
164
|
+
autoComplete={getFieldAutoComplete(field)}
|
|
165
|
+
blurOnSubmit={!nextField}
|
|
166
|
+
disabled={loading}
|
|
167
|
+
id={`${testID}-${field.name}-input`}
|
|
168
|
+
inputRef={(ref) => {
|
|
169
|
+
inputRefs.current[field.name] = ref;
|
|
170
|
+
}}
|
|
171
|
+
key={field.name}
|
|
172
|
+
onChange={(value: string) => handleFieldChange(field.name, value)}
|
|
173
|
+
onEnter={nextField ? () => focusField(nextField.name) : requestSubmit}
|
|
174
|
+
placeholder={field.placeholder ?? field.label}
|
|
175
|
+
returnKeyType={nextField ? "next" : "go"}
|
|
176
|
+
testID={`${testID}-${field.name}-input`}
|
|
177
|
+
title={field.label}
|
|
178
|
+
type={
|
|
179
|
+
field.type === "email" ? "email" : field.type === "password" ? "password" : "text"
|
|
180
|
+
}
|
|
181
|
+
value={formValues[field.name]}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
})}
|
|
123
185
|
|
|
124
186
|
{Boolean(passwordRequirements && passwordRequirements.length > 0 && passwordField) && (
|
|
125
187
|
<PasswordRequirements
|
|
@@ -140,7 +202,7 @@ export const SignUpScreen: FC<SignUpScreenProps> = ({
|
|
|
140
202
|
disabled={isSubmitDisabled}
|
|
141
203
|
fullWidth
|
|
142
204
|
loading={loading}
|
|
143
|
-
onClick={
|
|
205
|
+
onClick={requestSubmit}
|
|
144
206
|
testID={`${testID}-submit-button`}
|
|
145
207
|
text="Sign Up"
|
|
146
208
|
/>
|
|
@@ -166,7 +228,7 @@ export const SignUpScreen: FC<SignUpScreenProps> = ({
|
|
|
166
228
|
testID={`${testID}-oauth`}
|
|
167
229
|
/>
|
|
168
230
|
)}
|
|
169
|
-
</
|
|
231
|
+
</FormContainer>
|
|
170
232
|
</Box>
|
|
171
233
|
</Page>
|
|
172
234
|
);
|
|
@@ -82,11 +82,13 @@ exports[`SignUpScreen renders correctly with all props 1`] = `
|
|
|
82
82
|
"accessibilityState": {
|
|
83
83
|
"disabled": true,
|
|
84
84
|
},
|
|
85
|
-
"aria-
|
|
85
|
+
"aria-describedby": undefined,
|
|
86
|
+
"aria-invalid": false,
|
|
87
|
+
"aria-label": "Name",
|
|
86
88
|
"autoCapitalize": "sentences",
|
|
87
89
|
"autoCorrect": true,
|
|
88
|
-
"blurOnSubmit":
|
|
89
|
-
"enterKeyHint":
|
|
90
|
+
"blurOnSubmit": false,
|
|
91
|
+
"enterKeyHint": "next",
|
|
90
92
|
"keyboardType": "default",
|
|
91
93
|
"multiline": undefined,
|
|
92
94
|
"nativeID": "signup-screen-name-input",
|
|
@@ -108,6 +110,7 @@ exports[`SignUpScreen renders correctly with all props 1`] = `
|
|
|
108
110
|
"fontSize": 16,
|
|
109
111
|
"gap": 10,
|
|
110
112
|
"height": 24,
|
|
113
|
+
"letterSpacing": undefined,
|
|
111
114
|
"paddingVertical": 0,
|
|
112
115
|
"width": "100%",
|
|
113
116
|
},
|
|
@@ -188,11 +191,14 @@ exports[`SignUpScreen renders correctly with all props 1`] = `
|
|
|
188
191
|
"accessibilityState": {
|
|
189
192
|
"disabled": true,
|
|
190
193
|
},
|
|
191
|
-
"aria-
|
|
194
|
+
"aria-describedby": undefined,
|
|
195
|
+
"aria-invalid": false,
|
|
196
|
+
"aria-label": "Email",
|
|
192
197
|
"autoCapitalize": "none",
|
|
198
|
+
"autoComplete": "username",
|
|
193
199
|
"autoCorrect": false,
|
|
194
|
-
"blurOnSubmit":
|
|
195
|
-
"enterKeyHint":
|
|
200
|
+
"blurOnSubmit": false,
|
|
201
|
+
"enterKeyHint": "next",
|
|
196
202
|
"keyboardType": "email-address",
|
|
197
203
|
"multiline": undefined,
|
|
198
204
|
"nativeID": "signup-screen-email-input",
|
|
@@ -214,11 +220,12 @@ exports[`SignUpScreen renders correctly with all props 1`] = `
|
|
|
214
220
|
"fontSize": 16,
|
|
215
221
|
"gap": 10,
|
|
216
222
|
"height": 24,
|
|
223
|
+
"letterSpacing": undefined,
|
|
217
224
|
"paddingVertical": 0,
|
|
218
225
|
"width": "100%",
|
|
219
226
|
},
|
|
220
227
|
"testID": "signup-screen-email-input",
|
|
221
|
-
"textContentType": "
|
|
228
|
+
"textContentType": "username",
|
|
222
229
|
"underlineColorAndroid": "transparent",
|
|
223
230
|
"value": "",
|
|
224
231
|
},
|
|
@@ -294,11 +301,14 @@ exports[`SignUpScreen renders correctly with all props 1`] = `
|
|
|
294
301
|
"accessibilityState": {
|
|
295
302
|
"disabled": true,
|
|
296
303
|
},
|
|
297
|
-
"aria-
|
|
304
|
+
"aria-describedby": undefined,
|
|
305
|
+
"aria-invalid": false,
|
|
306
|
+
"aria-label": "Password",
|
|
298
307
|
"autoCapitalize": "none",
|
|
308
|
+
"autoComplete": "new-password",
|
|
299
309
|
"autoCorrect": false,
|
|
300
310
|
"blurOnSubmit": true,
|
|
301
|
-
"enterKeyHint":
|
|
311
|
+
"enterKeyHint": "go",
|
|
302
312
|
"keyboardType": "default",
|
|
303
313
|
"multiline": undefined,
|
|
304
314
|
"nativeID": "signup-screen-password-input",
|
|
@@ -320,11 +330,12 @@ exports[`SignUpScreen renders correctly with all props 1`] = `
|
|
|
320
330
|
"fontSize": 16,
|
|
321
331
|
"gap": 10,
|
|
322
332
|
"height": 24,
|
|
333
|
+
"letterSpacing": undefined,
|
|
323
334
|
"paddingVertical": 0,
|
|
324
335
|
"width": "100%",
|
|
325
336
|
},
|
|
326
337
|
"testID": "signup-screen-password-input",
|
|
327
|
-
"textContentType": "
|
|
338
|
+
"textContentType": "newPassword",
|
|
328
339
|
"underlineColorAndroid": "transparent",
|
|
329
340
|
"value": "",
|
|
330
341
|
},
|
|
@@ -838,7 +849,7 @@ exports[`SignUpScreen renders correctly with all props 1`] = `
|
|
|
838
849
|
"gap": 16,
|
|
839
850
|
"width": "100%",
|
|
840
851
|
},
|
|
841
|
-
"testID":
|
|
852
|
+
"testID": "signup-screen-form",
|
|
842
853
|
},
|
|
843
854
|
"type": "View",
|
|
844
855
|
},
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type {ReactNode} from "react";
|
|
2
2
|
|
|
3
|
+
import type {IconName} from "../Common";
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Supported OAuth providers for social login buttons.
|
|
5
7
|
*/
|
|
@@ -19,6 +21,26 @@ export interface OAuthProviderConfig {
|
|
|
19
21
|
disabled?: boolean;
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for a sign-in provider without a branded `SocialLoginButton`, such as a Better
|
|
26
|
+
* Auth generic OAuth/OIDC provider (`mock-oidc`, a company SSO). It renders as an outline
|
|
27
|
+
* `Button` reading "Continue with {label}".
|
|
28
|
+
*/
|
|
29
|
+
export interface GenericOAuthProviderConfig {
|
|
30
|
+
/** Provider id, matching the id passed to `signIn.social` and to `lastUsedMethod`. */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Display name. The button reads "Continue with {label}". */
|
|
33
|
+
label: string;
|
|
34
|
+
/** Callback triggered when the provider button is pressed. */
|
|
35
|
+
onPress: () => Promise<void>;
|
|
36
|
+
/** Whether the button is in a loading state. */
|
|
37
|
+
loading?: boolean;
|
|
38
|
+
/** Whether the button is disabled. */
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
/** Optional FontAwesome icon shown before the label. */
|
|
41
|
+
iconName?: IconName;
|
|
42
|
+
}
|
|
43
|
+
|
|
22
44
|
/**
|
|
23
45
|
* Configuration for a sign-up form field.
|
|
24
46
|
*/
|
|
@@ -34,7 +56,7 @@ export interface SignUpFieldConfig {
|
|
|
34
56
|
/** Whether the field is required. */
|
|
35
57
|
required?: boolean;
|
|
36
58
|
/** Auto-complete hint for the field. */
|
|
37
|
-
autoComplete?: "current-password" | "on" | "off" | "username";
|
|
59
|
+
autoComplete?: "current-password" | "email" | "new-password" | "on" | "off" | "username";
|
|
38
60
|
}
|
|
39
61
|
|
|
40
62
|
/**
|
|
@@ -2,7 +2,12 @@ import {describe, expect, it, mock} from "bun:test";
|
|
|
2
2
|
import {renderHook} from "@testing-library/react-native";
|
|
3
3
|
|
|
4
4
|
import type {ConsentFormPublic} from "./useConsentForms";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
applyConsentVariables,
|
|
7
|
+
detectLocale,
|
|
8
|
+
resolveConsentLocale,
|
|
9
|
+
useConsentForms,
|
|
10
|
+
} from "./useConsentForms";
|
|
6
11
|
|
|
7
12
|
type ConsentFormsApi = Parameters<typeof useConsentForms>[0];
|
|
8
13
|
|
|
@@ -26,6 +31,37 @@ mock.module("expo-localization", () => ({
|
|
|
26
31
|
getLocales: () => [{languageTag: "es-ES"}],
|
|
27
32
|
}));
|
|
28
33
|
|
|
34
|
+
describe("resolveConsentLocale", () => {
|
|
35
|
+
const form = {
|
|
36
|
+
content: {en: "Hi", "pt-BR": "Oi"},
|
|
37
|
+
defaultLocale: "en",
|
|
38
|
+
} as unknown as ConsentFormPublic;
|
|
39
|
+
|
|
40
|
+
it("uses the exact locale when the form has it", () => {
|
|
41
|
+
expect(resolveConsentLocale(form, "pt-BR")).toBe("pt-BR");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("falls back to the language when the exact locale is missing", () => {
|
|
45
|
+
expect(resolveConsentLocale(form, "en-GB")).toBe("en");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("falls back to the form default otherwise", () => {
|
|
49
|
+
expect(resolveConsentLocale(form, "fr-FR")).toBe("en");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("applyConsentVariables", () => {
|
|
54
|
+
it("replaces known placeholders and keeps unknown ones", () => {
|
|
55
|
+
expect(applyConsentVariables("Hi {{name}}, {{missing}}", {name: "Ada"})).toBe(
|
|
56
|
+
"Hi Ada, {{missing}}"
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("returns content unchanged without variables", () => {
|
|
61
|
+
expect(applyConsentVariables("Hi {{name}}")).toBe("Hi {{name}}");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
29
65
|
describe("detectLocale", () => {
|
|
30
66
|
it("returns locale from expo-localization in native test env", () => {
|
|
31
67
|
const g = globalThis as unknown as GlobalThisWithNavigator;
|
package/src/useConsentForms.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface ConsentFormPublic {
|
|
|
15
15
|
allowDecline: boolean;
|
|
16
16
|
declineButtonText: string;
|
|
17
17
|
required: boolean;
|
|
18
|
+
/** Set when staff signed this form provisionally for the user; the user still signs it. */
|
|
19
|
+
provisionalSignature?: {signedAt: string; signedByName: string};
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
import {getLocales} from "expo-localization";
|
|
@@ -56,6 +58,29 @@ interface ConsentFormsApi {
|
|
|
56
58
|
enhanceEndpoints: (options: {addTagTypes: string[]}) => ConsentFormsApiWithTags;
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
/** Replace `{{name}}` placeholders in consent content; unknown placeholders stay as written. */
|
|
62
|
+
export const applyConsentVariables = (
|
|
63
|
+
content: string,
|
|
64
|
+
variables?: Record<string, string>
|
|
65
|
+
): string => {
|
|
66
|
+
if (!variables) {
|
|
67
|
+
return content;
|
|
68
|
+
}
|
|
69
|
+
return content.replace(/\{\{(\w+)\}\}/g, (match, key) => variables[key] ?? match);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** The content locale to show: the exact locale, then its language, then the form default. */
|
|
73
|
+
export const resolveConsentLocale = (form: ConsentFormPublic, locale: string): string => {
|
|
74
|
+
if (form.content[locale] !== undefined) {
|
|
75
|
+
return locale;
|
|
76
|
+
}
|
|
77
|
+
const language = locale.split("-")[0];
|
|
78
|
+
if (form.content[language] !== undefined) {
|
|
79
|
+
return language;
|
|
80
|
+
}
|
|
81
|
+
return form.defaultLocale;
|
|
82
|
+
};
|
|
83
|
+
|
|
59
84
|
export const detectLocale = (): string => {
|
|
60
85
|
// Web
|
|
61
86
|
if (typeof navigator !== "undefined" && navigator.language) {
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {act, renderHook} from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type ProvisionalConsentApi,
|
|
6
|
+
type ProvisionalConsentStatusRow,
|
|
7
|
+
provisionalSignerName,
|
|
8
|
+
useProvisionalConsent,
|
|
9
|
+
} from "./useProvisionalConsent";
|
|
10
|
+
|
|
11
|
+
interface CapturedQuery {
|
|
12
|
+
providesTags: string[];
|
|
13
|
+
query: (userId: string) => string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface CapturedMutation {
|
|
17
|
+
invalidatesTags: string[];
|
|
18
|
+
query: (args: Record<string, unknown>) => {body: unknown; method: string; url: string};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const row: ProvisionalConsentStatusRow = {
|
|
22
|
+
form: {
|
|
23
|
+
active: true,
|
|
24
|
+
agreeButtonText: "I agree",
|
|
25
|
+
allowDecline: true,
|
|
26
|
+
captureSignature: false,
|
|
27
|
+
checkboxes: [],
|
|
28
|
+
content: {en: "# Telehealth"},
|
|
29
|
+
declineButtonText: "Decline",
|
|
30
|
+
defaultLocale: "en",
|
|
31
|
+
id: "form-1",
|
|
32
|
+
order: 1,
|
|
33
|
+
required: true,
|
|
34
|
+
requireScrollToBottom: false,
|
|
35
|
+
slug: "telehealth",
|
|
36
|
+
title: "Telehealth",
|
|
37
|
+
type: "agreement",
|
|
38
|
+
version: 1,
|
|
39
|
+
},
|
|
40
|
+
isConsented: false,
|
|
41
|
+
status: "pending",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const buildApi = (
|
|
45
|
+
state: {data?: unknown; error?: unknown; isLoading?: boolean} = {},
|
|
46
|
+
signResult: () => Promise<unknown> = () => Promise.resolve({}),
|
|
47
|
+
voidResult: () => Promise<unknown> = () => Promise.resolve({})
|
|
48
|
+
): {
|
|
49
|
+
voidedArgs: unknown[];
|
|
50
|
+
api: ProvisionalConsentApi;
|
|
51
|
+
captured: CapturedQuery[];
|
|
52
|
+
capturedMutations: CapturedMutation[];
|
|
53
|
+
addTagTypes: string[][];
|
|
54
|
+
queriedUserIds: string[];
|
|
55
|
+
signedBodies: unknown[];
|
|
56
|
+
} => {
|
|
57
|
+
const captured: CapturedQuery[] = [];
|
|
58
|
+
const capturedMutations: CapturedMutation[] = [];
|
|
59
|
+
const addTagTypes: string[][] = [];
|
|
60
|
+
const queriedUserIds: string[] = [];
|
|
61
|
+
const signedBodies: unknown[] = [];
|
|
62
|
+
const voidedArgs: unknown[] = [];
|
|
63
|
+
const api = {
|
|
64
|
+
enhanceEndpoints: mock((options: {addTagTypes: string[]}) => {
|
|
65
|
+
addTagTypes.push(options.addTagTypes);
|
|
66
|
+
return {
|
|
67
|
+
injectEndpoints: mock(
|
|
68
|
+
(options: {
|
|
69
|
+
endpoints: (build: {
|
|
70
|
+
mutation: (def: CapturedMutation) => unknown;
|
|
71
|
+
query: (def: CapturedQuery) => unknown;
|
|
72
|
+
}) => unknown;
|
|
73
|
+
}) => {
|
|
74
|
+
options.endpoints({
|
|
75
|
+
mutation: (def: CapturedMutation) => {
|
|
76
|
+
capturedMutations.push(def);
|
|
77
|
+
return def;
|
|
78
|
+
},
|
|
79
|
+
query: (def: CapturedQuery) => {
|
|
80
|
+
captured.push(def);
|
|
81
|
+
return def;
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
useGetConsentStatusQuery: (userId: string) => {
|
|
86
|
+
queriedUserIds.push(userId);
|
|
87
|
+
return {
|
|
88
|
+
data: state.data,
|
|
89
|
+
error: state.error,
|
|
90
|
+
isLoading: state.isLoading ?? false,
|
|
91
|
+
refetch: () => {},
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
useSignConsentProvisionallyMutation: () => [
|
|
95
|
+
(body: unknown) => {
|
|
96
|
+
signedBodies.push(body);
|
|
97
|
+
return {unwrap: signResult};
|
|
98
|
+
},
|
|
99
|
+
{isLoading: false},
|
|
100
|
+
],
|
|
101
|
+
useVoidProvisionalConsentMutation: () => [
|
|
102
|
+
(args: unknown) => {
|
|
103
|
+
voidedArgs.push(args);
|
|
104
|
+
return {unwrap: voidResult};
|
|
105
|
+
},
|
|
106
|
+
{isLoading: false},
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
),
|
|
111
|
+
};
|
|
112
|
+
}),
|
|
113
|
+
} as unknown as ProvisionalConsentApi;
|
|
114
|
+
return {addTagTypes, api, captured, capturedMutations, queriedUserIds, signedBodies, voidedArgs};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
describe("useProvisionalConsent", () => {
|
|
118
|
+
it("queries the status endpoint for the user under the base URL", () => {
|
|
119
|
+
const {api, captured, addTagTypes, queriedUserIds} = buildApi({data: {data: [row]}});
|
|
120
|
+
|
|
121
|
+
const {result} = renderHook(() =>
|
|
122
|
+
useProvisionalConsent({api, baseUrl: "/api", userId: "user 1"})
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
expect(captured).toHaveLength(1);
|
|
126
|
+
expect(captured[0].query("user 1")).toBe("/api/consent-responses/status?userId=user%201");
|
|
127
|
+
expect(captured[0].providesTags).toEqual(["ConsentStatus"]);
|
|
128
|
+
expect(addTagTypes[0]).toEqual(["ConsentStatus", "PendingConsents"]);
|
|
129
|
+
expect(queriedUserIds).toContain("user 1");
|
|
130
|
+
expect(result.current.statuses).toEqual([row]);
|
|
131
|
+
expect(result.current.isLoading).toBe(false);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("injects the endpoint once per api and base URL", () => {
|
|
135
|
+
const {api, captured} = buildApi({data: {data: []}});
|
|
136
|
+
|
|
137
|
+
renderHook(() => useProvisionalConsent({api, userId: "a"}));
|
|
138
|
+
renderHook(() => useProvisionalConsent({api, userId: "b"}));
|
|
139
|
+
renderHook(() => useProvisionalConsent({api, baseUrl: "/v2", userId: "a"}));
|
|
140
|
+
|
|
141
|
+
expect(captured).toHaveLength(2);
|
|
142
|
+
expect(captured[0].query("a")).toBe("/consent-responses/status?userId=a");
|
|
143
|
+
expect(captured[1].query("a")).toBe("/v2/consent-responses/status?userId=a");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("defines the provisional sign mutation and invalidates statuses and pending consents", () => {
|
|
147
|
+
const {api, capturedMutations} = buildApi({data: []});
|
|
148
|
+
renderHook(() => useProvisionalConsent({api, baseUrl: "/api", userId: "a"}));
|
|
149
|
+
|
|
150
|
+
expect(capturedMutations).toHaveLength(2);
|
|
151
|
+
expect(capturedMutations[0].invalidatesTags).toEqual(["ConsentStatus", "PendingConsents"]);
|
|
152
|
+
const body = {consentFormId: "form-1", note: "Phone", userId: "a"};
|
|
153
|
+
expect(capturedMutations[0].query(body)).toEqual({
|
|
154
|
+
body,
|
|
155
|
+
method: "POST",
|
|
156
|
+
url: "/api/consent-responses/provisional",
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("signs for the hook's user and unwraps the response envelope", async () => {
|
|
161
|
+
const response = {_id: "response-1", agreedAt: "2026-10-20T15:30:00.000Z"};
|
|
162
|
+
const {api, signedBodies} = buildApi({data: []}, () => Promise.resolve({data: response}));
|
|
163
|
+
const {result} = renderHook(() => useProvisionalConsent({api, userId: "member-1"}));
|
|
164
|
+
|
|
165
|
+
let signed: unknown;
|
|
166
|
+
await act(async () => {
|
|
167
|
+
signed = await result.current.sign({consentFormId: "form-1", locale: "en", note: "Phone"});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(signedBodies).toEqual([
|
|
171
|
+
{consentFormId: "form-1", locale: "en", note: "Phone", userId: "member-1"},
|
|
172
|
+
]);
|
|
173
|
+
expect(signed).toEqual(response);
|
|
174
|
+
expect(result.current.isSigning).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("returns an already-unwrapped sign response as is", async () => {
|
|
178
|
+
const response = {_id: "response-2", agreedAt: "2026-10-20T15:30:00.000Z"};
|
|
179
|
+
const {api} = buildApi({data: []}, () => Promise.resolve(response));
|
|
180
|
+
const {result} = renderHook(() => useProvisionalConsent({api, userId: "member-1"}));
|
|
181
|
+
|
|
182
|
+
let signed: unknown;
|
|
183
|
+
await act(async () => {
|
|
184
|
+
signed = await result.current.sign({consentFormId: "form-1", note: "Phone"});
|
|
185
|
+
});
|
|
186
|
+
expect(signed).toEqual(response);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("rejects with the server error when signing fails", async () => {
|
|
190
|
+
const error = {data: {title: "Consent form is not active"}, status: 400};
|
|
191
|
+
const {api} = buildApi({data: []}, () => Promise.reject(error));
|
|
192
|
+
const {result} = renderHook(() => useProvisionalConsent({api, userId: "member-1"}));
|
|
193
|
+
|
|
194
|
+
await expect(result.current.sign({consentFormId: "form-1", note: "Phone"})).rejects.toBe(error);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("defines the void mutation for a response id", () => {
|
|
198
|
+
const {api, capturedMutations} = buildApi({data: []});
|
|
199
|
+
renderHook(() => useProvisionalConsent({api, baseUrl: "/api", userId: "a"}));
|
|
200
|
+
|
|
201
|
+
expect(capturedMutations[1].invalidatesTags).toEqual(["ConsentStatus", "PendingConsents"]);
|
|
202
|
+
expect(capturedMutations[1].query({reason: "Wrong member", responseId: "resp 1"})).toEqual({
|
|
203
|
+
body: {reason: "Wrong member"},
|
|
204
|
+
method: "POST",
|
|
205
|
+
url: "/api/consent-responses/resp%201/void",
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("voids a signature and unwraps the response", async () => {
|
|
210
|
+
const response = {_id: "response-1", voidedAt: "2026-10-21T09:00:00.000Z"};
|
|
211
|
+
const {api, voidedArgs} = buildApi({data: []}, undefined, () =>
|
|
212
|
+
Promise.resolve({data: response})
|
|
213
|
+
);
|
|
214
|
+
const {result} = renderHook(() => useProvisionalConsent({api, userId: "member-1"}));
|
|
215
|
+
|
|
216
|
+
let voided: unknown;
|
|
217
|
+
await act(async () => {
|
|
218
|
+
voided = await result.current.voidSignature({reason: "Wrong member", responseId: "r1"});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(voidedArgs).toEqual([{reason: "Wrong member", responseId: "r1"}]);
|
|
222
|
+
expect(voided).toEqual(response);
|
|
223
|
+
expect(result.current.isVoiding).toBe(false);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("accepts an unwrapped array response", () => {
|
|
227
|
+
const {api} = buildApi({data: [row]});
|
|
228
|
+
const {result} = renderHook(() => useProvisionalConsent({api, userId: "a"}));
|
|
229
|
+
expect(result.current.statuses).toEqual([row]);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("returns no statuses while loading and passes the error through", () => {
|
|
233
|
+
const error = {status: 405};
|
|
234
|
+
const {api} = buildApi({error, isLoading: true});
|
|
235
|
+
const {result} = renderHook(() => useProvisionalConsent({api, userId: "a"}));
|
|
236
|
+
expect(result.current.statuses).toEqual([]);
|
|
237
|
+
expect(result.current.isLoading).toBe(true);
|
|
238
|
+
expect(result.current.error).toBe(error);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe("provisionalSignerName", () => {
|
|
243
|
+
it("prefers the signer's name, then their email", () => {
|
|
244
|
+
expect(provisionalSignerName({email: "dana@example.com", name: "Dana Rivera"})).toBe(
|
|
245
|
+
"Dana Rivera"
|
|
246
|
+
);
|
|
247
|
+
expect(provisionalSignerName({email: "dana@example.com"})).toBe("dana@example.com");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("falls back to Staff when the signer is unknown or not populated", () => {
|
|
251
|
+
expect(provisionalSignerName({})).toBe("Staff");
|
|
252
|
+
expect(provisionalSignerName(null)).toBe("Staff");
|
|
253
|
+
expect(provisionalSignerName(undefined)).toBe("Staff");
|
|
254
|
+
expect(provisionalSignerName("64b7f0c2a1b2c3d4e5f60718")).toBe("Staff");
|
|
255
|
+
});
|
|
256
|
+
});
|