@terreno/ui 57.21.0 → 58.0.0-beta.2

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.
Files changed (221) hide show
  1. package/.ai/guidelines/core.md +1 -1
  2. package/CHANGELOG.md +89 -0
  3. package/dist/ActionSheet.d.ts +9 -9
  4. package/dist/ActionSheet.d.ts.map +1 -1
  5. package/dist/ActionSheet.js +11 -4
  6. package/dist/ActionSheet.js.map +1 -1
  7. package/dist/AnnouncementNavigator.d.ts +7 -1
  8. package/dist/AnnouncementNavigator.d.ts.map +1 -1
  9. package/dist/AnnouncementNavigator.js +15 -16
  10. package/dist/AnnouncementNavigator.js.map +1 -1
  11. package/dist/Avatar.d.ts.map +1 -1
  12. package/dist/Avatar.js +1 -1
  13. package/dist/Avatar.js.map +1 -1
  14. package/dist/Box.d.ts.map +1 -1
  15. package/dist/Box.js +3 -1
  16. package/dist/Box.js.map +1 -1
  17. package/dist/Common.d.ts +16 -12
  18. package/dist/Common.d.ts.map +1 -1
  19. package/dist/Common.js.map +1 -1
  20. package/dist/ConsentFormScreen.d.ts.map +1 -1
  21. package/dist/ConsentFormScreen.js.map +1 -1
  22. package/dist/ConsentNavigator.d.ts +5 -3
  23. package/dist/ConsentNavigator.d.ts.map +1 -1
  24. package/dist/ConsentNavigator.js +4 -4
  25. package/dist/ConsentNavigator.js.map +1 -1
  26. package/dist/CustomSelectField.js.map +1 -1
  27. package/dist/DataTable.d.ts.map +1 -1
  28. package/dist/DataTable.js +37 -12
  29. package/dist/DataTable.js.map +1 -1
  30. package/dist/DateTimeField.js.map +1 -1
  31. package/dist/DropdownPanel.d.ts +0 -5
  32. package/dist/DropdownPanel.d.ts.map +1 -1
  33. package/dist/DropdownPanel.js +0 -5
  34. package/dist/DropdownPanel.js.map +1 -1
  35. package/dist/FilterAccordion.d.ts.map +1 -1
  36. package/dist/FilterAccordion.js.map +1 -1
  37. package/dist/FilterBoolean.d.ts.map +1 -1
  38. package/dist/FilterBoolean.js.map +1 -1
  39. package/dist/FilterSelectMenu.js +1 -1
  40. package/dist/FilterSelectMenu.js.map +1 -1
  41. package/dist/GPTChat.d.ts.map +1 -1
  42. package/dist/GPTChat.js.map +1 -1
  43. package/dist/Heading.d.ts.map +1 -1
  44. package/dist/Heading.js +6 -12
  45. package/dist/Heading.js.map +1 -1
  46. package/dist/HeightField.d.ts.map +1 -1
  47. package/dist/HeightField.js +1 -1
  48. package/dist/HeightField.js.map +1 -1
  49. package/dist/Hyperlink.d.ts.map +1 -1
  50. package/dist/Hyperlink.js +6 -1
  51. package/dist/Hyperlink.js.map +1 -1
  52. package/dist/Image.d.ts +1 -1
  53. package/dist/MarkdownEditorField.d.ts.map +1 -1
  54. package/dist/MarkdownEditorField.js +1 -1
  55. package/dist/MarkdownEditorField.js.map +1 -1
  56. package/dist/OfflineBanner.d.ts +3 -2
  57. package/dist/OfflineBanner.d.ts.map +1 -1
  58. package/dist/OfflineBanner.js +3 -2
  59. package/dist/OfflineBanner.js.map +1 -1
  60. package/dist/OtpField.d.ts.map +1 -1
  61. package/dist/OtpField.js +6 -3
  62. package/dist/OtpField.js.map +1 -1
  63. package/dist/PickerSelect.d.ts +4 -4
  64. package/dist/PickerSelect.d.ts.map +1 -1
  65. package/dist/PickerSelect.js.map +1 -1
  66. package/dist/ProvisionalConsentSigner.d.ts +3 -2
  67. package/dist/ProvisionalConsentSigner.d.ts.map +1 -1
  68. package/dist/ProvisionalConsentSigner.js +2 -2
  69. package/dist/ProvisionalConsentSigner.js.map +1 -1
  70. package/dist/SidebarNavigation.js +2 -2
  71. package/dist/SidebarNavigation.js.map +1 -1
  72. package/dist/SidebarNavigation.native.js +2 -2
  73. package/dist/SidebarNavigation.native.js.map +1 -1
  74. package/dist/Skeleton.js.map +1 -1
  75. package/dist/Text.d.ts.map +1 -1
  76. package/dist/Text.js +27 -50
  77. package/dist/Text.js.map +1 -1
  78. package/dist/TextField.d.ts.map +1 -1
  79. package/dist/TextField.js.map +1 -1
  80. package/dist/ThumbsUpDownFeedback.d.ts.map +1 -1
  81. package/dist/ThumbsUpDownFeedback.js.map +1 -1
  82. package/dist/ToastNotifications.d.ts.map +1 -1
  83. package/dist/ToastNotifications.js.map +1 -1
  84. package/dist/Tooltip.d.ts.map +1 -1
  85. package/dist/Tooltip.js.map +1 -1
  86. package/dist/Unifier.d.ts +1 -1
  87. package/dist/WebAddressAutocomplete.js.map +1 -1
  88. package/dist/WebDropdownMenu.d.ts +3 -3
  89. package/dist/WebDropdownMenu.d.ts.map +1 -1
  90. package/dist/WebDropdownMenu.js +1 -1
  91. package/dist/WebDropdownMenu.js.map +1 -1
  92. package/dist/announcementPlatform.d.ts +5 -0
  93. package/dist/announcementPlatform.d.ts.map +1 -1
  94. package/dist/announcementPlatform.js +9 -0
  95. package/dist/announcementPlatform.js.map +1 -1
  96. package/dist/asks/AskCard.d.ts +2 -2
  97. package/dist/asks/AskCard.d.ts.map +1 -1
  98. package/dist/dataTableColumnWidths.d.ts +76 -0
  99. package/dist/dataTableColumnWidths.d.ts.map +1 -0
  100. package/dist/dataTableColumnWidths.js +181 -0
  101. package/dist/dataTableColumnWidths.js.map +1 -0
  102. package/dist/index.d.ts +2 -1
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js.map +1 -1
  105. package/dist/login/LoginScreen.js.map +1 -1
  106. package/dist/requestClient.d.ts +71 -0
  107. package/dist/requestClient.d.ts.map +1 -0
  108. package/dist/requestClient.js +139 -0
  109. package/dist/requestClient.js.map +1 -0
  110. package/dist/security/PasswordCard.d.ts.map +1 -1
  111. package/dist/security/PasswordCard.js.map +1 -1
  112. package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -1
  113. package/dist/security/TwoFactorSettingsCard.js +1 -1
  114. package/dist/security/TwoFactorSettingsCard.js.map +1 -1
  115. package/dist/signUp/SignUpScreen.js.map +1 -1
  116. package/dist/table/Table.d.ts.map +1 -1
  117. package/dist/table/Table.js.map +1 -1
  118. package/dist/table/TableTitle.d.ts.map +1 -1
  119. package/dist/table/TableTitle.js +2 -1
  120. package/dist/table/TableTitle.js.map +1 -1
  121. package/dist/textFontSizes.d.ts +12 -0
  122. package/dist/textFontSizes.d.ts.map +1 -0
  123. package/dist/textFontSizes.js +21 -0
  124. package/dist/textFontSizes.js.map +1 -0
  125. package/dist/useAcknowledgeAnnouncement.d.ts +8 -63
  126. package/dist/useAcknowledgeAnnouncement.d.ts.map +1 -1
  127. package/dist/useAcknowledgeAnnouncement.js +31 -80
  128. package/dist/useAcknowledgeAnnouncement.js.map +1 -1
  129. package/dist/useAnnouncements.d.ts +14 -47
  130. package/dist/useAnnouncements.d.ts.map +1 -1
  131. package/dist/useAnnouncements.js +30 -57
  132. package/dist/useAnnouncements.js.map +1 -1
  133. package/dist/useConsentForms.d.ts +6 -38
  134. package/dist/useConsentForms.d.ts.map +1 -1
  135. package/dist/useConsentForms.js +25 -48
  136. package/dist/useConsentForms.js.map +1 -1
  137. package/dist/useProvisionalConsent.d.ts +7 -58
  138. package/dist/useProvisionalConsent.d.ts.map +1 -1
  139. package/dist/useProvisionalConsent.js +57 -67
  140. package/dist/useProvisionalConsent.js.map +1 -1
  141. package/dist/useSubmitConsent.d.ts +9 -39
  142. package/dist/useSubmitConsent.d.ts.map +1 -1
  143. package/dist/useSubmitConsent.js +10 -39
  144. package/dist/useSubmitConsent.js.map +1 -1
  145. package/package.json +38 -38
  146. package/src/ActionSheet.test.tsx +4 -4
  147. package/src/ActionSheet.tsx +18 -5
  148. package/src/AnnouncementNavigator.test.tsx +215 -315
  149. package/src/AnnouncementNavigator.tsx +25 -20
  150. package/src/Avatar.tsx +2 -9
  151. package/src/Box.test.tsx +3 -3
  152. package/src/Box.tsx +4 -2
  153. package/src/Common.ts +19 -15
  154. package/src/ConsentFormScreen.tsx +2 -1
  155. package/src/ConsentNavigator.test.tsx +166 -242
  156. package/src/ConsentNavigator.tsx +9 -13
  157. package/src/CustomSelectField.tsx +3 -3
  158. package/src/DataTable.test.tsx +69 -1
  159. package/src/DataTable.tsx +72 -19
  160. package/src/DateTimeField.tsx +4 -4
  161. package/src/DropdownPanel.tsx +0 -6
  162. package/src/FilterAccordion.tsx +3 -3
  163. package/src/FilterBoolean.tsx +3 -3
  164. package/src/FilterSelectMenu.tsx +1 -1
  165. package/src/GPTChat.tsx +10 -9
  166. package/src/Heading.tsx +7 -14
  167. package/src/HeightField.tsx +9 -2
  168. package/src/Hyperlink.tsx +6 -3
  169. package/src/Link.test.tsx +2 -2
  170. package/src/MarkdownEditorField.tsx +10 -2
  171. package/src/MarkdownView.test.tsx +10 -6
  172. package/src/Modal.test.tsx +3 -1
  173. package/src/ModalSheet.test.tsx +6 -6
  174. package/src/OfflineBanner.tsx +3 -2
  175. package/src/OtpField.test.tsx +44 -0
  176. package/src/OtpField.tsx +8 -4
  177. package/src/PickerSelect.tsx +3 -2
  178. package/src/ProvisionalConsentSigner.test.tsx +140 -113
  179. package/src/ProvisionalConsentSigner.tsx +5 -4
  180. package/src/SidebarNavigation.native.tsx +2 -2
  181. package/src/SidebarNavigation.tsx +2 -2
  182. package/src/Skeleton.tsx +1 -1
  183. package/src/TapToEdit.test.tsx +2 -2
  184. package/src/Text.test.tsx +1 -1
  185. package/src/Text.tsx +25 -51
  186. package/src/TextField.tsx +2 -1
  187. package/src/ThumbsUpDownFeedback.tsx +3 -3
  188. package/src/ToastNotifications.tsx +3 -2
  189. package/src/ToastNotifications.webModal.test.tsx +4 -1
  190. package/src/Tooltip.tsx +2 -1
  191. package/src/UserInactivity.test.tsx +2 -3
  192. package/src/WebAddressAutocomplete.tsx +3 -3
  193. package/src/WebDropdownMenu.tsx +16 -5
  194. package/src/__snapshots__/DataTable.test.tsx.snap +13 -0
  195. package/src/announcementPlatform.ts +10 -0
  196. package/src/asks/AskCard.test.tsx +14 -12
  197. package/src/asks/AskCard.tsx +2 -2
  198. package/src/bunSetup.ts +42 -0
  199. package/src/dataTableColumnWidths.test.ts +266 -0
  200. package/src/dataTableColumnWidths.ts +272 -0
  201. package/src/index.tsx +9 -2
  202. package/src/login/LoginScreen.tsx +2 -2
  203. package/src/requestClient.test.ts +288 -0
  204. package/src/requestClient.ts +228 -0
  205. package/src/security/PasswordCard.tsx +7 -5
  206. package/src/security/TwoFactorSettingsCard.tsx +10 -3
  207. package/src/signUp/SignUpScreen.tsx +2 -2
  208. package/src/table/Table.tsx +1 -2
  209. package/src/table/TableTitle.tsx +2 -1
  210. package/src/test-utils.tsx +76 -0
  211. package/src/textFontSizes.ts +31 -0
  212. package/src/useAcknowledgeAnnouncement.test.ts +101 -193
  213. package/src/useAcknowledgeAnnouncement.ts +69 -147
  214. package/src/useAnnouncements.test.ts +122 -186
  215. package/src/useAnnouncements.ts +49 -105
  216. package/src/useConsentForms.test.ts +59 -112
  217. package/src/useConsentForms.ts +37 -87
  218. package/src/useProvisionalConsent.test.ts +74 -150
  219. package/src/useProvisionalConsent.ts +79 -125
  220. package/src/useSubmitConsent.test.ts +59 -85
  221. package/src/useSubmitConsent.ts +22 -77
@@ -19,8 +19,9 @@ export interface OfflineBannerProps {
19
19
  *
20
20
  * @example
21
21
  * ```typescript
22
- * const {isOnline, queueLength, isSyncing} = useServerStatus();
23
- * <OfflineBanner isOnline={isOnline} queueLength={queueLength} isSyncing={isSyncing} />
22
+ * // useSyncStatus from @terreno/syncdb/react
23
+ * const {isOnline, isSyncing, queuedCount} = useSyncStatus();
24
+ * <OfflineBanner isOnline={isOnline} queueLength={queuedCount} isSyncing={isSyncing} />
24
25
  * ```
25
26
  */
26
27
  export const OfflineBanner: React.FC<OfflineBannerProps> = ({
@@ -30,6 +30,28 @@ const renderWithFocusSpy = (ui: ReactElement): ReturnType<typeof render> & {focu
30
30
  return Object.assign(result, {focused});
31
31
  };
32
32
 
33
+ const renderWithSynchronousFocus = (
34
+ ui: ReactElement
35
+ ): ReturnType<typeof render> & {getFocusedCell: () => number} => {
36
+ let focusedCell = 1;
37
+ const result = render(ui, {
38
+ createNodeMock: (element: ReactElement) => {
39
+ const props = element.props as {onFocus?: () => void; testID?: string};
40
+ const match = /-cell-(\d+)$/.exec(props.testID ?? "");
41
+ return {
42
+ focus: (): void => {
43
+ if (match) {
44
+ focusedCell = Number(match[1]);
45
+ props.onFocus?.();
46
+ }
47
+ },
48
+ };
49
+ },
50
+ wrapper: ThemeProvider,
51
+ });
52
+ return Object.assign(result, {getFocusedCell: (): number => focusedCell});
53
+ };
54
+
33
55
  const cellValues = (getByTestId: (id: string) => {props: {value?: string}}, length = 6): string[] =>
34
56
  Array.from({length}, (_, index) => getByTestId(`otp-cell-${index + 1}`).props.value ?? "");
35
57
 
@@ -249,6 +271,28 @@ describe("OtpField", () => {
249
271
  expect(focused).toEqual([2, 3]);
250
272
  });
251
273
 
274
+ it.each(["uncontrolled", "controlled"])(
275
+ "typing a full code digit by digit works when focus fires synchronously (%s)",
276
+ (mode): void => {
277
+ const onComplete = mock((_code: string) => {});
278
+ const ui =
279
+ mode === "controlled" ? (
280
+ <ControlledOtp onComplete={onComplete} />
281
+ ) : (
282
+ <OtpField onComplete={onComplete} testID="otp" />
283
+ );
284
+ const {getByTestId, getFocusedCell} = renderWithSynchronousFocus(ui);
285
+
286
+ "123456".split("").forEach((digit): void => {
287
+ fireEvent.changeText(getByTestId(`otp-cell-${getFocusedCell()}`), digit);
288
+ });
289
+
290
+ expect(cellValues(getByTestId)).toEqual(["1", "2", "3", "4", "5", "6"]);
291
+ expect(onComplete).toHaveBeenCalledTimes(1);
292
+ expect(onComplete).toHaveBeenCalledWith("123456");
293
+ }
294
+ );
295
+
252
296
  it("pasting a full code moves focus to the last cell", () => {
253
297
  const {getByTestId, focused} = renderWithFocusSpy(<ControlledOtp />);
254
298
  fireEvent.changeText(getByTestId("otp-cell-1"), "123456");
package/src/OtpField.tsx CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  Platform,
5
5
  type StyleProp,
6
6
  TextInput,
7
+ type TextInputInstance,
7
8
  type TextInputKeyPressEvent,
8
9
  type TextInputProps,
9
10
  View,
@@ -156,9 +157,11 @@ export const OtpField: FC<OtpFieldProps> = ({
156
157
  // Roving tab stop: only the cell that takes the next digit is in the tab order, so Tab and
157
158
  // Shift+Tab leave the field instead of landing on a cell that hands focus back.
158
159
  const activeIndex = Math.min(code.length, length - 1);
160
+ const activeIndexRef = useRef(activeIndex);
161
+ activeIndexRef.current = activeIndex;
159
162
 
160
163
  const [focusedIndex, setFocusedIndex] = useState<number | null>(null);
161
- const inputRefs = useRef<(TextInput | null)[]>([]);
164
+ const inputRefs = useRef<(TextInputInstance | null)[]>([]);
162
165
 
163
166
  const focusCell = useCallback((index: number): void => {
164
167
  inputRefs.current[index]?.focus();
@@ -174,6 +177,7 @@ export const OtpField: FC<OtpFieldProps> = ({
174
177
 
175
178
  const commit = useCallback(
176
179
  (next: string): void => {
180
+ activeIndexRef.current = Math.min(next.length, length - 1);
177
181
  if (next === code) {
178
182
  return;
179
183
  }
@@ -215,13 +219,13 @@ export const OtpField: FC<OtpFieldProps> = ({
215
219
  (index: number): void => {
216
220
  // Digits fill left to right: a tap past the active cell lands on that cell instead. Keyboard
217
221
  // focus never needs this, because only the active cell is a tab stop.
218
- if (index > activeIndex) {
219
- focusCell(activeIndex);
222
+ if (index > activeIndexRef.current) {
223
+ focusCell(activeIndexRef.current);
220
224
  return;
221
225
  }
222
226
  setFocusedIndex(index);
223
227
  },
224
- [activeIndex, focusCell]
228
+ [focusCell]
225
229
  );
226
230
 
227
231
  const handleBlur = useCallback((index: number): void => {
@@ -45,6 +45,7 @@ import {
45
45
  StyleSheet,
46
46
  Text,
47
47
  TextInput,
48
+ type TextInputInstance,
48
49
  type TextInputProps,
49
50
  TouchableOpacity,
50
51
  View,
@@ -137,7 +138,7 @@ export interface RNPickerSelectProps {
137
138
  /**
138
139
  * Web only. When true, the dropdown menu renders in a fixed portal on
139
140
  * `document.body` instead of a React Native `Modal`, so it floats above
140
- * ancestor portals / high-zIndex overlays (e.g. the `Filter` panel).
141
+ * ancestor portals / high-zIndex overlays (e.g. a `DropdownPanel`).
141
142
  * @default false
142
143
  */
143
144
  renderMenuInBodyPortal?: boolean;
@@ -171,7 +172,7 @@ export const RNPickerSelect = ({
171
172
  const searchable = !disableSearch;
172
173
  const [showPicker, setShowPicker] = useState<boolean>(false);
173
174
  const [webSearchQuery, setWebSearchQuery] = useState("");
174
- const webSearchInputRef = useRef<TextInput>(null);
175
+ const webSearchInputRef = useRef<TextInputInstance>(null);
175
176
  const [animationType, setAnimationType] = useState<ModalProps["animationType"]>(undefined);
176
177
  const [orientation, setOrientation] = useState<"portrait" | "landscape">("portrait");
177
178
  const [doneDepressed, setDoneDepressed] = useState<boolean>(false);
@@ -1,11 +1,13 @@
1
1
  import {afterEach, describe, expect, it, mock, spyOn} from "bun:test";
2
2
  import {act, fireEvent, waitFor} from "@testing-library/react-native";
3
3
  import {DateTime} from "luxon";
4
+ import type React from "react";
4
5
  import {ProvisionalConsentSigner} from "./ProvisionalConsentSigner";
5
6
  import * as pdfHtmlTemplate from "./pdfHtmlTemplate";
6
- import {renderWithTheme} from "./test-utils";
7
+ import type {TerrenoRequestClient} from "./requestClient";
8
+ import {createFakeRequestClient, renderWithTheme} from "./test-utils";
7
9
  import type {ConsentFormPublic} from "./useConsentForms";
8
- import type {ProvisionalConsentApi, ProvisionalConsentStatusRow} from "./useProvisionalConsent";
10
+ import type {ProvisionalConsentStatusRow} from "./useProvisionalConsent";
9
11
 
10
12
  interface QueryState {
11
13
  data?: unknown;
@@ -65,13 +67,17 @@ const rows: ProvisionalConsentStatusRow[] = [
65
67
  },
66
68
  ];
67
69
 
68
- /** A fake of the consumer's RTK api: the status query returns `initial`, signing runs `signResult`. */
70
+ /**
71
+ * A fake request client: the status route answers `initial` (hangs while `isLoading`, rejects
72
+ * with `error`), signing runs `signResult`, voiding runs `voidResult`. `refetch` is called for
73
+ * every status request after the first.
74
+ */
69
75
  const buildApi = (
70
76
  initial: QueryState,
71
77
  signResult: () => Promise<unknown> = () => Promise.resolve({}),
72
78
  voidResult: () => Promise<unknown> = () => Promise.resolve({})
73
79
  ): {
74
- api: ProvisionalConsentApi;
80
+ client: TerrenoRequestClient;
75
81
  refetch: ReturnType<typeof mock>;
76
82
  signedBodies: unknown[];
77
83
  userIds: string[];
@@ -81,53 +87,58 @@ const buildApi = (
81
87
  const userIds: string[] = [];
82
88
  const signedBodies: unknown[] = [];
83
89
  const voidedArgs: unknown[] = [];
84
- const api = {
85
- enhanceEndpoints: () => ({
86
- injectEndpoints: () => ({
87
- useGetConsentStatusQuery: (userId: string) => {
88
- userIds.push(userId);
89
- return {
90
- data: initial.data,
91
- error: initial.error,
92
- isLoading: initial.isLoading ?? false,
93
- refetch,
94
- };
95
- },
96
- useSignConsentProvisionallyMutation: () => [
97
- (body: unknown) => {
98
- signedBodies.push(body);
99
- return {unwrap: signResult};
100
- },
101
- {isLoading: false},
102
- ],
103
- useVoidProvisionalConsentMutation: () => [
104
- (args: unknown) => {
105
- voidedArgs.push(args);
106
- return {unwrap: voidResult};
107
- },
108
- {isLoading: false},
109
- ],
110
- }),
111
- }),
112
- } as unknown as ProvisionalConsentApi;
113
- return {api, refetch, signedBodies, userIds, voidedArgs};
90
+ const fake = createFakeRequestClient({
91
+ "GET /consent-responses/status": async (args) => {
92
+ if (userIds.length > 0) {
93
+ refetch();
94
+ }
95
+ userIds.push(String(args.params?.userId));
96
+ if (initial.isLoading) {
97
+ return new Promise(() => {});
98
+ }
99
+ if (initial.error) {
100
+ throw initial.error;
101
+ }
102
+ return initial.data;
103
+ },
104
+ "POST /consent-responses/:id/void": async (args, params) => {
105
+ voidedArgs.push({reason: (args.body as {reason: string}).reason, responseId: params.id});
106
+ return voidResult();
107
+ },
108
+ "POST /consent-responses/provisional": async (args) => {
109
+ signedBodies.push(args.body);
110
+ return signResult();
111
+ },
112
+ });
113
+ return {client: fake.client, refetch, signedBodies, userIds, voidedArgs};
114
+ };
115
+
116
+ /** Renders the component and waits for the status request to settle. */
117
+ const renderLoaded = async (
118
+ element: React.ReactElement
119
+ ): Promise<ReturnType<typeof renderWithTheme>> => {
120
+ const result = renderWithTheme(element);
121
+ await act(async () => {
122
+ await new Promise((resolve) => setTimeout(resolve, 0));
123
+ });
124
+ return result;
114
125
  };
115
126
 
116
127
  describe("ProvisionalConsentSigner", () => {
117
- it("shows a spinner while statuses load", () => {
118
- const {api} = buildApi({isLoading: true});
119
- const {getByTestId, queryByTestId} = renderWithTheme(
120
- <ProvisionalConsentSigner api={api} userId="member-1" />
128
+ it("shows a spinner while statuses load", async () => {
129
+ const {client} = buildApi({isLoading: true});
130
+ const {getByTestId, queryByTestId} = await renderLoaded(
131
+ <ProvisionalConsentSigner client={client} userId="member-1" />
121
132
  );
122
133
  expect(getByTestId("provisional-consent-signer")).toBeTruthy();
123
134
  expect(getByTestId("provisional-consent-loading")).toBeTruthy();
124
135
  expect(queryByTestId("provisional-consent-row-form-pending")).toBeNull();
125
136
  });
126
137
 
127
- it("lists each form with its status for the target user", () => {
128
- const {api, userIds} = buildApi({data: {data: rows}});
129
- const {getByTestId, getByText} = renderWithTheme(
130
- <ProvisionalConsentSigner api={api} userId="member-1" />
138
+ it("lists each form with its status for the target user", async () => {
139
+ const {client, userIds} = buildApi({data: {data: rows}});
140
+ const {getByTestId, getByText} = await renderLoaded(
141
+ <ProvisionalConsentSigner client={client} userId="member-1" />
131
142
  );
132
143
 
133
144
  expect(userIds).toContain("member-1");
@@ -142,7 +153,7 @@ describe("ProvisionalConsentSigner", () => {
142
153
  expect(getByTestId("provisional-consent-status-form-provisional")).toBeTruthy();
143
154
  });
144
155
 
145
- it("falls back to the signer's email, then to staff", () => {
156
+ it("falls back to the signer's email, then to staff", async () => {
146
157
  const byEmail: ProvisionalConsentStatusRow = {
147
158
  ...rows[1],
148
159
  provisional: {responseId: "r", signedAt, signedBy: {email: "dana@example.com", id: "s"}},
@@ -152,28 +163,32 @@ describe("ProvisionalConsentSigner", () => {
152
163
  form: makeForm("form-other", "Other"),
153
164
  provisional: {responseId: "r2", signedAt, signedBy: null},
154
165
  };
155
- const {api} = buildApi({data: [byEmail, deletedSigner]});
156
- const {getByText} = renderWithTheme(<ProvisionalConsentSigner api={api} userId="member-1" />);
166
+ const {client} = buildApi({data: [byEmail, deletedSigner]});
167
+ const {getByText} = await renderLoaded(
168
+ <ProvisionalConsentSigner client={client} userId="member-1" />
169
+ );
157
170
  expect(
158
171
  getByText(`Signed provisionally by dana@example.com on ${formatted(signedAt)}`)
159
172
  ).toBeTruthy();
160
173
  expect(getByText(`Signed provisionally by Staff on ${formatted(signedAt)}`)).toBeTruthy();
161
174
  });
162
175
 
163
- it("uses the form _id when the row has no id", () => {
176
+ it("uses the form _id when the row has no id", async () => {
164
177
  const {id: _omitted, ...formWithoutId} = makeForm("ignored", "Mongo id form");
165
178
  const row = {
166
179
  form: {...formWithoutId, _id: "mongo-id"},
167
180
  isConsented: false,
168
181
  status: "pending",
169
182
  } as unknown as ProvisionalConsentStatusRow;
170
- const {api} = buildApi({data: [row]});
171
- const {getByTestId} = renderWithTheme(<ProvisionalConsentSigner api={api} userId="member-1" />);
183
+ const {client} = buildApi({data: [row]});
184
+ const {getByTestId} = await renderLoaded(
185
+ <ProvisionalConsentSigner client={client} userId="member-1" />
186
+ );
172
187
  expect(getByTestId("provisional-consent-row-mongo-id")).toBeTruthy();
173
188
  });
174
189
 
175
- it("leaves the date off when it is missing or invalid", () => {
176
- const {api} = buildApi({
190
+ it("leaves the date off when it is missing or invalid", async () => {
191
+ const {client} = buildApi({
177
192
  data: [
178
193
  {form: makeForm("no-date", "No date"), isConsented: true, status: "signed"},
179
194
  {
@@ -184,21 +199,25 @@ describe("ProvisionalConsentSigner", () => {
184
199
  },
185
200
  ],
186
201
  });
187
- const {getByText} = renderWithTheme(<ProvisionalConsentSigner api={api} userId="member-1" />);
202
+ const {getByText} = await renderLoaded(
203
+ <ProvisionalConsentSigner client={client} userId="member-1" />
204
+ );
188
205
  expect(getByText("Signed by user")).toBeTruthy();
189
206
  expect(getByText("Declined by user")).toBeTruthy();
190
207
  });
191
208
 
192
- it("says so when no forms apply", () => {
193
- const {api} = buildApi({data: {data: []}});
194
- const {getByTestId} = renderWithTheme(<ProvisionalConsentSigner api={api} userId="member-1" />);
209
+ it("says so when no forms apply", async () => {
210
+ const {client} = buildApi({data: {data: []}});
211
+ const {getByTestId} = await renderLoaded(
212
+ <ProvisionalConsentSigner client={client} userId="member-1" />
213
+ );
195
214
  expect(getByTestId("provisional-consent-empty")).toBeTruthy();
196
215
  });
197
216
 
198
217
  it("shows the server error with a Retry button that refetches", async () => {
199
- const {api, refetch} = buildApi({error: {data: {title: "Access denied"}, status: 405}});
200
- const {getByTestId, getByText} = renderWithTheme(
201
- <ProvisionalConsentSigner api={api} userId="member-1" />
218
+ const {client, refetch} = buildApi({error: {data: {title: "Access denied"}, status: 405}});
219
+ const {getByTestId, getByText} = await renderLoaded(
220
+ <ProvisionalConsentSigner client={client} userId="member-1" />
202
221
  );
203
222
  expect(getByTestId("provisional-consent-error")).toBeTruthy();
204
223
  expect(getByText("Access denied")).toBeTruthy();
@@ -211,9 +230,11 @@ describe("ProvisionalConsentSigner", () => {
211
230
  });
212
231
  });
213
232
 
214
- it("shows a generic message when the error has no title", () => {
215
- const {api} = buildApi({error: {status: "FETCH_ERROR"}});
216
- const {getByText} = renderWithTheme(<ProvisionalConsentSigner api={api} userId="member-1" />);
233
+ it("shows a generic message when the error has no title", async () => {
234
+ const {client} = buildApi({error: {status: "FETCH_ERROR"}});
235
+ const {getByText} = await renderLoaded(
236
+ <ProvisionalConsentSigner client={client} userId="member-1" />
237
+ );
217
238
  expect(getByText("Could not load consent forms.")).toBeTruthy();
218
239
  });
219
240
  describe("signing on the user's behalf", () => {
@@ -237,10 +258,10 @@ describe("ProvisionalConsentSigner", () => {
237
258
  form: {...row.form, content: {en: content}},
238
259
  });
239
260
 
240
- it("offers signing only for pending forms", () => {
241
- const {api} = buildApi({data: rows});
242
- const {getByTestId, queryByTestId} = renderWithTheme(
243
- <ProvisionalConsentSigner api={api} userId="member-1" />
261
+ it("offers signing only for pending forms", async () => {
262
+ const {client} = buildApi({data: rows});
263
+ const {getByTestId, queryByTestId} = await renderLoaded(
264
+ <ProvisionalConsentSigner client={client} userId="member-1" />
244
265
  );
245
266
  expect(getByTestId("provisional-consent-open-form-pending")).toBeTruthy();
246
267
  expect(queryByTestId("provisional-consent-open-form-declined")).toBeNull();
@@ -249,9 +270,15 @@ describe("ProvisionalConsentSigner", () => {
249
270
  });
250
271
 
251
272
  it("shows the form content with variables and keeps submit disabled until a note is entered", async () => {
252
- const {api} = buildApi({data: [withContent(rows[0], "Hello {{memberName}}, please agree.")]});
253
- const {getByTestId, getByText} = renderWithTheme(
254
- <ProvisionalConsentSigner api={api} userId="member-1" variables={{memberName: "Sam"}} />
273
+ const {client} = buildApi({
274
+ data: [withContent(rows[0], "Hello {{memberName}}, please agree.")],
275
+ });
276
+ const {getByTestId, getByText} = await renderLoaded(
277
+ <ProvisionalConsentSigner
278
+ client={client}
279
+ userId="member-1"
280
+ variables={{memberName: "Sam"}}
281
+ />
255
282
  );
256
283
 
257
284
  await openForm(getByTestId, "form-pending");
@@ -284,11 +311,11 @@ describe("ProvisionalConsentSigner", () => {
284
311
  userId: "member-1",
285
312
  };
286
313
  const onSigned = mock(() => {});
287
- const {api, signedBodies} = buildApi({data: [rows[0]]}, () =>
314
+ const {client, signedBodies} = buildApi({data: [rows[0]]}, () =>
288
315
  Promise.resolve({data: response})
289
316
  );
290
- const {getByTestId, getByText, queryByTestId} = renderWithTheme(
291
- <ProvisionalConsentSigner api={api} onSigned={onSigned} userId="member-1" />
317
+ const {getByTestId, getByText, queryByTestId} = await renderLoaded(
318
+ <ProvisionalConsentSigner client={client} onSigned={onSigned} userId="member-1" />
292
319
  );
293
320
 
294
321
  await openForm(getByTestId, "form-pending");
@@ -323,9 +350,9 @@ describe("ProvisionalConsentSigner", () => {
323
350
  it("shows a server error inline and calls onError", async () => {
324
351
  const serverError = {data: {title: "Consent form is not active"}, status: 400};
325
352
  const onError = mock(() => {});
326
- const {api} = buildApi({data: [rows[0]]}, () => Promise.reject(serverError));
327
- const {getByTestId, getByText, queryByTestId} = renderWithTheme(
328
- <ProvisionalConsentSigner api={api} onError={onError} userId="member-1" />
353
+ const {client} = buildApi({data: [rows[0]]}, () => Promise.reject(serverError));
354
+ const {getByTestId, getByText, queryByTestId} = await renderLoaded(
355
+ <ProvisionalConsentSigner client={client} onError={onError} userId="member-1" />
329
356
  );
330
357
 
331
358
  await openForm(getByTestId, "form-pending");
@@ -346,9 +373,9 @@ describe("ProvisionalConsentSigner", () => {
346
373
  });
347
374
 
348
375
  it("shows a generic error when the server gives no title", async () => {
349
- const {api} = buildApi({data: [rows[0]]}, () => Promise.reject({status: "FETCH_ERROR"}));
350
- const {getByTestId, getByText} = renderWithTheme(
351
- <ProvisionalConsentSigner api={api} userId="member-1" />
376
+ const {client} = buildApi({data: [rows[0]]}, () => Promise.reject({status: "FETCH_ERROR"}));
377
+ const {getByTestId, getByText} = await renderLoaded(
378
+ <ProvisionalConsentSigner client={client} userId="member-1" />
352
379
  );
353
380
  await openForm(getByTestId, "form-pending");
354
381
  act(() => {
@@ -363,9 +390,9 @@ describe("ProvisionalConsentSigner", () => {
363
390
  });
364
391
 
365
392
  it("returns to the list on cancel without signing", async () => {
366
- const {api, signedBodies} = buildApi({data: [rows[0]]});
367
- const {getByTestId, queryByTestId} = renderWithTheme(
368
- <ProvisionalConsentSigner api={api} userId="member-1" />
393
+ const {client, signedBodies} = buildApi({data: [rows[0]]});
394
+ const {getByTestId, queryByTestId} = await renderLoaded(
395
+ <ProvisionalConsentSigner client={client} userId="member-1" />
369
396
  );
370
397
  await openForm(getByTestId, "form-pending");
371
398
  act(() => {
@@ -379,11 +406,11 @@ describe("ProvisionalConsentSigner", () => {
379
406
  });
380
407
 
381
408
  it("names the signer as staff when the response is not populated", async () => {
382
- const {api} = buildApi({data: [rows[0]]}, () =>
409
+ const {client} = buildApi({data: [rows[0]]}, () =>
383
410
  Promise.resolve({_id: "r", agreedAt: signedAt, provisionalSignedBy: "staff-1"})
384
411
  );
385
- const {getByTestId, getByText} = renderWithTheme(
386
- <ProvisionalConsentSigner api={api} userId="member-1" />
412
+ const {getByTestId, getByText} = await renderLoaded(
413
+ <ProvisionalConsentSigner client={client} userId="member-1" />
387
414
  );
388
415
  await openForm(getByTestId, "form-pending");
389
416
  act(() => {
@@ -425,10 +452,10 @@ describe("ProvisionalConsentSigner", () => {
425
452
  });
426
453
  };
427
454
 
428
- it("offers print on provisional, signed, and declined rows, and void on provisional only", () => {
429
- const {api} = buildApi({data: rows});
430
- const {getByTestId, queryByTestId} = renderWithTheme(
431
- <ProvisionalConsentSigner api={api} userId="member-1" />
455
+ it("offers print on provisional, signed, and declined rows, and void on provisional only", async () => {
456
+ const {client} = buildApi({data: rows});
457
+ const {getByTestId, queryByTestId} = await renderLoaded(
458
+ <ProvisionalConsentSigner client={client} userId="member-1" />
432
459
  );
433
460
  expect(queryByTestId("provisional-consent-print-form-pending")).toBeNull();
434
461
  expect(getByTestId("provisional-consent-print-form-provisional")).toBeTruthy();
@@ -441,9 +468,9 @@ describe("ProvisionalConsentSigner", () => {
441
468
 
442
469
  it("prints a provisional row with the form content and the provisional block with the note", async () => {
443
470
  spyOnPrint();
444
- const {api} = buildApi({data: rows});
445
- const {getByTestId} = renderWithTheme(
446
- <ProvisionalConsentSigner api={api} userId="member-1" />
471
+ const {client} = buildApi({data: rows});
472
+ const {getByTestId} = await renderLoaded(
473
+ <ProvisionalConsentSigner client={client} userId="member-1" />
447
474
  );
448
475
 
449
476
  await press(getByTestId, "provisional-consent-print-form-provisional");
@@ -457,9 +484,9 @@ describe("ProvisionalConsentSigner", () => {
457
484
 
458
485
  it("prints a signed row without a provisional block", async () => {
459
486
  spyOnPrint();
460
- const {api} = buildApi({data: rows});
461
- const {getByTestId} = renderWithTheme(
462
- <ProvisionalConsentSigner api={api} userId="member-1" />
487
+ const {client} = buildApi({data: rows});
488
+ const {getByTestId} = await renderLoaded(
489
+ <ProvisionalConsentSigner client={client} userId="member-1" />
463
490
  );
464
491
 
465
492
  await press(getByTestId, "provisional-consent-print-form-signed");
@@ -472,9 +499,9 @@ describe("ProvisionalConsentSigner", () => {
472
499
 
473
500
  it("keeps working when printing fails", async () => {
474
501
  spyOnPrint(() => Promise.reject(new Error("printer offline")));
475
- const {api} = buildApi({data: rows});
476
- const {getByTestId} = renderWithTheme(
477
- <ProvisionalConsentSigner api={api} userId="member-1" />
502
+ const {client} = buildApi({data: rows});
503
+ const {getByTestId} = await renderLoaded(
504
+ <ProvisionalConsentSigner client={client} userId="member-1" />
478
505
  );
479
506
  await press(getByTestId, "provisional-consent-print-form-declined");
480
507
  expect(printed).toHaveLength(1);
@@ -489,9 +516,9 @@ describe("ProvisionalConsentSigner", () => {
489
516
  provisionalNote: "Guardian agreed by phone",
490
517
  provisionalSignedBy: {_id: "staff-1", name: "Dana Rivera"},
491
518
  };
492
- const {api} = buildApi({data: [rows[0]]}, () => Promise.resolve({data: response}));
493
- const {getByTestId} = renderWithTheme(
494
- <ProvisionalConsentSigner api={api} userId="member-1" />
519
+ const {client} = buildApi({data: [rows[0]]}, () => Promise.resolve({data: response}));
520
+ const {getByTestId} = await renderLoaded(
521
+ <ProvisionalConsentSigner client={client} userId="member-1" />
495
522
  );
496
523
  await press(getByTestId, "provisional-consent-open-form-pending");
497
524
  act(() => {
@@ -515,9 +542,9 @@ describe("ProvisionalConsentSigner", () => {
515
542
  });
516
543
 
517
544
  it("voids with a required reason and refetches", async () => {
518
- const {api, refetch, voidedArgs} = buildApi({data: rows});
519
- const {getByTestId} = renderWithTheme(
520
- <ProvisionalConsentSigner api={api} userId="member-1" />
545
+ const {client, refetch, voidedArgs} = buildApi({data: rows});
546
+ const {getByTestId} = await renderLoaded(
547
+ <ProvisionalConsentSigner client={client} userId="member-1" />
521
548
  );
522
549
 
523
550
  await press(getByTestId, "provisional-consent-void-form-provisional");
@@ -546,9 +573,9 @@ describe("ProvisionalConsentSigner", () => {
546
573
  });
547
574
 
548
575
  it("closes the void dialog on cancel without voiding", async () => {
549
- const {api, refetch, voidedArgs} = buildApi({data: rows});
550
- const {getByTestId, UNSAFE_getByProps} = renderWithTheme(
551
- <ProvisionalConsentSigner api={api} userId="member-1" />
576
+ const {client, refetch, voidedArgs} = buildApi({data: rows});
577
+ const {getByTestId, UNSAFE_getByProps} = await renderLoaded(
578
+ <ProvisionalConsentSigner client={client} userId="member-1" />
552
579
  );
553
580
 
554
581
  await press(getByTestId, "provisional-consent-void-form-provisional");
@@ -565,9 +592,9 @@ describe("ProvisionalConsentSigner", () => {
565
592
  });
566
593
 
567
594
  it("does not void without a reason even if the confirm handler runs", async () => {
568
- const {api, voidedArgs} = buildApi({data: rows});
569
- const {getByTestId, UNSAFE_getByProps} = renderWithTheme(
570
- <ProvisionalConsentSigner api={api} userId="member-1" />
595
+ const {client, voidedArgs} = buildApi({data: rows});
596
+ const {getByTestId, UNSAFE_getByProps} = await renderLoaded(
597
+ <ProvisionalConsentSigner client={client} userId="member-1" />
571
598
  );
572
599
 
573
600
  await press(getByTestId, "provisional-consent-void-form-provisional");
@@ -581,9 +608,9 @@ describe("ProvisionalConsentSigner", () => {
581
608
  });
582
609
 
583
610
  it("does not sign without a note even if the submit handler runs", async () => {
584
- const {api, signedBodies} = buildApi({data: [rows[0]]});
585
- const {getByTestId, UNSAFE_getByProps} = renderWithTheme(
586
- <ProvisionalConsentSigner api={api} userId="member-1" />
611
+ const {client, signedBodies} = buildApi({data: [rows[0]]});
612
+ const {getByTestId, UNSAFE_getByProps} = await renderLoaded(
613
+ <ProvisionalConsentSigner client={client} userId="member-1" />
587
614
  );
588
615
 
589
616
  await press(getByTestId, "provisional-consent-open-form-pending");
@@ -601,9 +628,9 @@ describe("ProvisionalConsentSigner", () => {
601
628
  it("shows a void error in the dialog and calls onError", async () => {
602
629
  const failure = {data: {title: "Provisional signature is already voided"}, status: 400};
603
630
  const onError = mock(() => {});
604
- const {api, refetch} = buildApi({data: rows}, undefined, () => Promise.reject(failure));
605
- const {getByTestId, getByText} = renderWithTheme(
606
- <ProvisionalConsentSigner api={api} onError={onError} userId="member-1" />
631
+ const {client, refetch} = buildApi({data: rows}, undefined, () => Promise.reject(failure));
632
+ const {getByTestId, getByText} = await renderLoaded(
633
+ <ProvisionalConsentSigner client={client} onError={onError} userId="member-1" />
607
634
  );
608
635
 
609
636
  await press(getByTestId, "provisional-consent-void-form-provisional");
@@ -11,6 +11,7 @@ import {Heading} from "./Heading";
11
11
  import {MarkdownView} from "./MarkdownView";
12
12
  import {Modal} from "./Modal";
13
13
  import {buildConsentPdfHtml, printConsentHtml} from "./pdfHtmlTemplate";
14
+ import type {TerrenoRequestClient} from "./requestClient";
14
15
  import {Spinner} from "./Spinner";
15
16
  import {Text} from "./Text";
16
17
  import {TextField} from "./TextField";
@@ -23,9 +24,9 @@ import {
23
24
  } from "./useProvisionalConsent";
24
25
 
25
26
  export interface ProvisionalConsentSignerProps {
26
- /** The consumer's RTK Query api, as passed to `ConsentNavigator`. */
27
- api: unknown;
28
27
  baseUrl?: string;
28
+ /** The app's request client, as passed to `ConsentNavigator`. */
29
+ client: TerrenoRequestClient;
29
30
  /** The user whose consent forms are listed and signed on their behalf. */
30
31
  userId: string;
31
32
  /** Called with the stored response after a provisional signature succeeds. */
@@ -141,8 +142,8 @@ const rowFormId = (row: ProvisionalConsentStatusRow): string => row.form.id ?? r
141
142
  * behalf. Requires `consentResponse:signOnBehalf` (or `user.admin` without RBAC) on the server.
142
143
  */
143
144
  export const ProvisionalConsentSigner: React.FC<ProvisionalConsentSignerProps> = ({
144
- api,
145
145
  baseUrl,
146
+ client,
146
147
  userId,
147
148
  onSigned,
148
149
  onError,
@@ -150,8 +151,8 @@ export const ProvisionalConsentSigner: React.FC<ProvisionalConsentSignerProps> =
150
151
  }) => {
151
152
  const {error, isLoading, isSigning, isVoiding, refetch, sign, statuses, voidSignature} =
152
153
  useProvisionalConsent({
153
- api,
154
154
  baseUrl,
155
+ client,
155
156
  userId,
156
157
  });
157
158
  const [openFormId, setOpenFormId] = useState<string | null>(null);
@@ -469,7 +469,7 @@ const SidebarNavigationBase: FC<SidebarNavigationProps> = ({
469
469
  topItems,
470
470
  bottomItems,
471
471
  onNavigate,
472
- initialRouteName,
472
+ initialRouteName: _initialRouteName,
473
473
  screenOptions,
474
474
  panelStyle,
475
475
  itemStyle,
@@ -478,7 +478,7 @@ const SidebarNavigationBase: FC<SidebarNavigationProps> = ({
478
478
  const [isSheetOpen, setIsSheetOpen] = useState(false);
479
479
 
480
480
  return (
481
- <Navigator initialRouteName={initialRouteName} router={TabRouter} screenOptions={screenOptions}>
481
+ <Navigator router={TabRouter} screenOptions={screenOptions}>
482
482
  <View style={{flex: 1}}>
483
483
  <SidebarHeader onOpen={() => setIsSheetOpen(true)} />
484
484
  <SidebarNavigatorContent