@terreno/admin-frontend 0.7.2 → 0.8.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.
Files changed (54) hide show
  1. package/dist/AdminFieldRenderer.d.ts +2 -0
  2. package/dist/AdminFieldRenderer.js +96 -3
  3. package/dist/AdminFieldRenderer.js.map +1 -1
  4. package/dist/AdminModelForm.d.ts +11 -0
  5. package/dist/AdminModelForm.js +95 -24
  6. package/dist/AdminModelForm.js.map +1 -1
  7. package/dist/AdminModelList.d.ts +4 -0
  8. package/dist/AdminModelList.js +10 -4
  9. package/dist/AdminModelList.js.map +1 -1
  10. package/dist/AdminModelTable.js +33 -33
  11. package/dist/AdminModelTable.js.map +1 -1
  12. package/dist/AdminNestedArrayField.d.ts +26 -0
  13. package/dist/AdminNestedArrayField.js +118 -0
  14. package/dist/AdminNestedArrayField.js.map +1 -0
  15. package/dist/CheckboxListEditor.d.ts +15 -0
  16. package/dist/CheckboxListEditor.js +21 -0
  17. package/dist/CheckboxListEditor.js.map +1 -0
  18. package/dist/ConsentFormEditor.d.ts +12 -0
  19. package/dist/ConsentFormEditor.js +299 -0
  20. package/dist/ConsentFormEditor.js.map +1 -0
  21. package/dist/ConsentFormList.d.ts +9 -0
  22. package/dist/ConsentFormList.js +70 -0
  23. package/dist/ConsentFormList.js.map +1 -0
  24. package/dist/ConsentResponseViewer.d.ts +8 -0
  25. package/dist/ConsentResponseViewer.js +61 -0
  26. package/dist/ConsentResponseViewer.js.map +1 -0
  27. package/dist/LocaleContentEditor.d.ts +10 -0
  28. package/dist/LocaleContentEditor.js +48 -0
  29. package/dist/LocaleContentEditor.js.map +1 -0
  30. package/dist/generateConsentPdf.d.ts +26 -0
  31. package/dist/generateConsentPdf.js +210 -0
  32. package/dist/generateConsentPdf.js.map +1 -0
  33. package/dist/index.d.ts +7 -1
  34. package/dist/index.js +6 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/types.d.ts +4 -0
  37. package/dist/types.js.map +1 -1
  38. package/dist/useAdminApi.js +2 -1
  39. package/dist/useAdminApi.js.map +1 -1
  40. package/package.json +3 -2
  41. package/src/AdminFieldRenderer.tsx +190 -2
  42. package/src/AdminModelForm.tsx +134 -40
  43. package/src/AdminModelList.tsx +35 -19
  44. package/src/AdminModelTable.tsx +40 -36
  45. package/src/AdminNestedArrayField.tsx +228 -0
  46. package/src/CheckboxListEditor.tsx +107 -0
  47. package/src/ConsentFormEditor.tsx +677 -0
  48. package/src/ConsentFormList.tsx +164 -0
  49. package/src/ConsentResponseViewer.tsx +228 -0
  50. package/src/LocaleContentEditor.tsx +151 -0
  51. package/src/generateConsentPdf.ts +264 -0
  52. package/src/index.tsx +7 -0
  53. package/src/types.ts +4 -0
  54. package/src/useAdminApi.ts +2 -1
@@ -0,0 +1,677 @@
1
+ import {
2
+ BooleanField,
3
+ Box,
4
+ Button,
5
+ Heading,
6
+ MarkdownEditor,
7
+ Modal,
8
+ NumberField,
9
+ Page,
10
+ SegmentedControl,
11
+ SelectField,
12
+ Spinner,
13
+ Text,
14
+ TextField,
15
+ useToast,
16
+ } from "@terreno/ui";
17
+ import React, {useCallback, useEffect, useMemo, useState} from "react";
18
+ import {useAdminApi} from "./useAdminApi";
19
+
20
+ interface CheckboxConfig {
21
+ label: string;
22
+ required: boolean;
23
+ confirmationPrompt?: string;
24
+ }
25
+
26
+ interface ConsentFormEditorProps {
27
+ baseUrl: string;
28
+ api: any;
29
+ id?: string;
30
+ supportedLocales?: string[];
31
+ hasAiSupport?: boolean;
32
+ onSave?: (form: any) => void;
33
+ onCancel?: () => void;
34
+ }
35
+
36
+ const CONSENT_FORM_ROUTE = "/consent-forms";
37
+
38
+ const TYPE_OPTIONS = [
39
+ {label: "Agreement", value: "agreement"},
40
+ {label: "Privacy", value: "privacy"},
41
+ {label: "HIPAA", value: "hipaa"},
42
+ {label: "Research", value: "research"},
43
+ {label: "Terms", value: "terms"},
44
+ {label: "Custom", value: "custom"},
45
+ ];
46
+
47
+ const slugify = (text: string): string => {
48
+ return text
49
+ .toLowerCase()
50
+ .trim()
51
+ .replace(/[^a-z0-9]+/g, "-")
52
+ .replace(/^-+|-+$/g, "");
53
+ };
54
+
55
+ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
56
+ baseUrl,
57
+ api,
58
+ id,
59
+ supportedLocales = ["en"],
60
+ hasAiSupport = false,
61
+ onSave,
62
+ onCancel,
63
+ }) => {
64
+ const isEditMode = Boolean(id);
65
+ const toast = useToast();
66
+
67
+ // Basic fields
68
+ const [title, setTitle] = useState("");
69
+ const [slug, setSlug] = useState("");
70
+ const [slugManuallySet, setSlugManuallySet] = useState(false);
71
+ const [type, setType] = useState("agreement");
72
+ const [order, setOrder] = useState("0");
73
+ const [required, setRequired] = useState(false);
74
+ const [active, setActive] = useState(true);
75
+
76
+ // Form behavior
77
+ const [captureSignature, setCaptureSignature] = useState(false);
78
+ const [requireScrollToBottom, setRequireScrollToBottom] = useState(false);
79
+
80
+ // Locale config
81
+ const [defaultLocale, setDefaultLocale] = useState(supportedLocales[0] ?? "en");
82
+
83
+ // Button config
84
+ const [agreeButtonText, setAgreeButtonText] = useState("I Agree");
85
+ const [allowDecline, setAllowDecline] = useState(false);
86
+ const [declineButtonText, setDeclineButtonText] = useState("Decline");
87
+
88
+ // Content per locale
89
+ const [localeContent, setLocaleContent] = useState<Record<string, string>>(() => {
90
+ const initial: Record<string, string> = {};
91
+ for (const locale of supportedLocales) {
92
+ initial[locale] = "";
93
+ }
94
+ return initial;
95
+ });
96
+ const [activeLocaleIndex, setActiveLocaleIndex] = useState(0);
97
+
98
+ // Checkboxes
99
+ const [checkboxes, setCheckboxes] = useState<CheckboxConfig[]>([]);
100
+
101
+ // AI state
102
+ const [isGenerateModalVisible, setIsGenerateModalVisible] = useState(false);
103
+ const [generateDescription, setGenerateDescription] = useState("");
104
+ const [generateType, setGenerateType] = useState(type);
105
+
106
+ const routePath = `${baseUrl}${CONSENT_FORM_ROUTE}`;
107
+ // publish/generate/translate are registered directly under /consent-forms, not the admin base path
108
+ const consentApiPath = CONSENT_FORM_ROUTE;
109
+
110
+ const {useReadQuery, useCreateMutation, useUpdateMutation} = useAdminApi(
111
+ api,
112
+ routePath,
113
+ "ConsentForm"
114
+ );
115
+
116
+ const enhancedApi = useMemo(
117
+ () =>
118
+ api.injectEndpoints({
119
+ endpoints: (build: any) => ({
120
+ generateConsentContent: build.mutation({
121
+ query: (body: {type: string; description: string; locale: string}) => ({
122
+ body,
123
+ method: "POST",
124
+ url: `${consentApiPath}/generate`,
125
+ }),
126
+ }),
127
+ publishConsentForm: build.mutation({
128
+ query: (formId: string) => ({
129
+ method: "POST",
130
+ url: `${consentApiPath}/${formId}/publish`,
131
+ }),
132
+ }),
133
+ translateConsentContent: build.mutation({
134
+ query: (body: {content: string; fromLocale: string; toLocale: string}) => ({
135
+ body,
136
+ method: "POST",
137
+ url: `${consentApiPath}/translate`,
138
+ }),
139
+ }),
140
+ }),
141
+ overrideExisting: true,
142
+ }),
143
+ [api, consentApiPath]
144
+ );
145
+
146
+ const [publishConsentForm, {isLoading: isPublishing}] = (
147
+ enhancedApi as any
148
+ ).usePublishConsentFormMutation();
149
+
150
+ const [generateContent, {isLoading: isGenerating}] = (
151
+ enhancedApi as any
152
+ ).useGenerateConsentContentMutation();
153
+
154
+ const [translateContent, {isLoading: isTranslating}] = (
155
+ enhancedApi as any
156
+ ).useTranslateConsentContentMutation();
157
+
158
+ const {data: formData, isLoading: isFormLoading} = useReadQuery(id ?? "", {
159
+ skip: !isEditMode || !id,
160
+ });
161
+
162
+ const [createForm, {isLoading: isCreating}] = useCreateMutation();
163
+ const [updateForm, {isLoading: isUpdating}] = useUpdateMutation();
164
+
165
+ // Populate form state when editing an existing form
166
+ useEffect(() => {
167
+ if (!formData) {
168
+ return;
169
+ }
170
+ setTitle(formData.title ?? "");
171
+ setSlug(formData.slug ?? "");
172
+ setSlugManuallySet(true);
173
+ setType(formData.type ?? "agreement");
174
+ setGenerateType(formData.type ?? "agreement");
175
+ setOrder(String(formData.order ?? 0));
176
+ setRequired(formData.required ?? false);
177
+ setActive(formData.active ?? true);
178
+ setCaptureSignature(formData.captureSignature ?? false);
179
+ setRequireScrollToBottom(formData.requireScrollToBottom ?? false);
180
+ setDefaultLocale(formData.defaultLocale ?? supportedLocales[0] ?? "en");
181
+ setAgreeButtonText(formData.agreeButtonText ?? "I Agree");
182
+ setAllowDecline(formData.allowDecline ?? false);
183
+ setDeclineButtonText(formData.declineButtonText ?? "Decline");
184
+
185
+ if (formData.content && typeof formData.content === "object") {
186
+ const newLocaleContent: Record<string, string> = {};
187
+ for (const locale of supportedLocales) {
188
+ newLocaleContent[locale] = formData.content[locale] ?? "";
189
+ }
190
+ setLocaleContent(newLocaleContent);
191
+ }
192
+
193
+ if (Array.isArray(formData.checkboxes)) {
194
+ setCheckboxes(formData.checkboxes);
195
+ }
196
+ }, [formData, supportedLocales]);
197
+
198
+ // Auto-generate slug from title unless manually set
199
+ const handleTitleChange = useCallback(
200
+ (newTitle: string) => {
201
+ setTitle(newTitle);
202
+ if (!slugManuallySet) {
203
+ setSlug(slugify(newTitle));
204
+ }
205
+ },
206
+ [slugManuallySet]
207
+ );
208
+
209
+ const handleSlugChange = useCallback((newSlug: string) => {
210
+ setSlug(newSlug);
211
+ setSlugManuallySet(true);
212
+ }, []);
213
+
214
+ const handleLocaleContentChange = useCallback((locale: string, content: string) => {
215
+ setLocaleContent((prev) => ({...prev, [locale]: content}));
216
+ }, []);
217
+
218
+ const handleAddCheckbox = useCallback(() => {
219
+ setCheckboxes((prev) => [...prev, {confirmationPrompt: "", label: "", required: false}]);
220
+ }, []);
221
+
222
+ const handleRemoveCheckbox = useCallback((index: number) => {
223
+ setCheckboxes((prev) => prev.filter((_, i) => i !== index));
224
+ }, []);
225
+
226
+ const handleCheckboxChange = useCallback(
227
+ (index: number, field: keyof CheckboxConfig, value: any) => {
228
+ setCheckboxes((prev) => {
229
+ const updated = [...prev];
230
+ updated[index] = {...updated[index], [field]: value};
231
+ return updated;
232
+ });
233
+ },
234
+ []
235
+ );
236
+
237
+ const buildPayload = useCallback(() => {
238
+ return {
239
+ active,
240
+ agreeButtonText,
241
+ allowDecline,
242
+ captureSignature,
243
+ checkboxes: checkboxes.map((cb) => ({
244
+ confirmationPrompt: cb.confirmationPrompt || undefined,
245
+ label: cb.label,
246
+ required: cb.required,
247
+ })),
248
+ content: localeContent,
249
+ declineButtonText: allowDecline ? declineButtonText : undefined,
250
+ defaultLocale,
251
+ order: parseInt(order, 10) || 0,
252
+ required,
253
+ requireScrollToBottom,
254
+ slug,
255
+ title,
256
+ type,
257
+ };
258
+ }, [
259
+ active,
260
+ agreeButtonText,
261
+ allowDecline,
262
+ captureSignature,
263
+ checkboxes,
264
+ defaultLocale,
265
+ localeContent,
266
+ declineButtonText,
267
+ order,
268
+ required,
269
+ requireScrollToBottom,
270
+ slug,
271
+ title,
272
+ type,
273
+ ]);
274
+
275
+ const handleSave = useCallback(async () => {
276
+ if (!title.trim()) {
277
+ toast.error("Title is required");
278
+ return;
279
+ }
280
+ if (!slug.trim()) {
281
+ toast.error("Slug is required");
282
+ return;
283
+ }
284
+
285
+ const payload = buildPayload();
286
+
287
+ try {
288
+ let result: any;
289
+ if (isEditMode && id) {
290
+ result = await updateForm({body: payload, id}).unwrap();
291
+ } else {
292
+ result = await createForm(payload).unwrap();
293
+ }
294
+ console.info("Consent form saved", {id: result?._id ?? id});
295
+ onSave?.(result);
296
+ } catch (err) {
297
+ toast.catch(err, `Failed to ${isEditMode ? "update" : "create"} consent form`);
298
+ }
299
+ }, [buildPayload, createForm, id, isEditMode, onSave, slug, title, toast, updateForm]);
300
+
301
+ const handlePublish = useCallback(async () => {
302
+ if (!id) {
303
+ return;
304
+ }
305
+ try {
306
+ await publishConsentForm(id).unwrap();
307
+ console.info("Consent form published", {id});
308
+ toast.success("New version published");
309
+ } catch (err) {
310
+ toast.catch(err, "Failed to publish consent form");
311
+ }
312
+ }, [id, publishConsentForm, toast]);
313
+
314
+ const handleOpenGenerateModal = useCallback(() => {
315
+ setGenerateType(type);
316
+ setGenerateDescription("");
317
+ setIsGenerateModalVisible(true);
318
+ }, [type]);
319
+
320
+ const handleGenerate = useCallback(async () => {
321
+ const activeLocale = supportedLocales[activeLocaleIndex] ?? "en";
322
+ try {
323
+ const result = await generateContent({
324
+ description: generateDescription,
325
+ locale: activeLocale,
326
+ type: generateType,
327
+ }).unwrap();
328
+ const generatedText = result?.data?.content ?? "";
329
+ handleLocaleContentChange(activeLocale, generatedText);
330
+ setIsGenerateModalVisible(false);
331
+ toast.success("Content generated successfully");
332
+ } catch (err) {
333
+ toast.catch(err, "Failed to generate content");
334
+ }
335
+ }, [
336
+ activeLocaleIndex,
337
+ generateContent,
338
+ generateDescription,
339
+ generateType,
340
+ handleLocaleContentChange,
341
+ supportedLocales,
342
+ toast,
343
+ ]);
344
+
345
+ const handleTranslate = useCallback(
346
+ async (targetLocale: string) => {
347
+ const sourceContent = localeContent[defaultLocale] ?? "";
348
+
349
+ if (!sourceContent.trim()) {
350
+ toast.error(`No content in ${defaultLocale} to translate from`);
351
+ return;
352
+ }
353
+
354
+ try {
355
+ const result = await translateContent({
356
+ content: sourceContent,
357
+ fromLocale: defaultLocale,
358
+ toLocale: targetLocale,
359
+ }).unwrap();
360
+ const translatedText = result?.data?.content ?? "";
361
+ handleLocaleContentChange(targetLocale, translatedText);
362
+ toast.success(`Content translated to ${targetLocale}`);
363
+ } catch (err) {
364
+ toast.catch(err, `Failed to translate content to ${targetLocale}`);
365
+ }
366
+ },
367
+ [defaultLocale, handleLocaleContentChange, localeContent, toast, translateContent]
368
+ );
369
+
370
+ if (isEditMode && isFormLoading) {
371
+ return (
372
+ <Page maxWidth="100%">
373
+ <Box alignItems="center" justifyContent="center" padding={6}>
374
+ <Spinner />
375
+ </Box>
376
+ </Page>
377
+ );
378
+ }
379
+
380
+ const isSaving = isCreating || isUpdating;
381
+ const activeLocale = supportedLocales[activeLocaleIndex] ?? "en";
382
+ const isNonDefaultLocale = activeLocale !== defaultLocale;
383
+
384
+ const contentLocales = useMemo(
385
+ () => Object.keys(localeContent).filter((k) => localeContent[k] !== undefined),
386
+ [localeContent]
387
+ );
388
+ const hasLocales = contentLocales.length > 0;
389
+ const defaultLocaleOptions = useMemo(
390
+ () =>
391
+ contentLocales.map((locale) => ({
392
+ label: locale.toUpperCase(),
393
+ value: locale,
394
+ })),
395
+ [contentLocales]
396
+ );
397
+
398
+ return (
399
+ <Page
400
+ footer={
401
+ <Box direction="row" gap={2} justifyContent="between" padding={2}>
402
+ <Box>
403
+ {onCancel && (
404
+ <Button
405
+ onClick={onCancel}
406
+ testID="consent-form-cancel-button"
407
+ text="Cancel"
408
+ variant="secondary"
409
+ />
410
+ )}
411
+ </Box>
412
+ <Button
413
+ loading={isSaving}
414
+ onClick={handleSave}
415
+ testID="consent-form-save-button"
416
+ text={isEditMode ? "Save" : "Create"}
417
+ variant="primary"
418
+ />
419
+ </Box>
420
+ }
421
+ maxWidth="100%"
422
+ scroll
423
+ >
424
+ <Box gap={4} padding={4}>
425
+ {isEditMode && (
426
+ <Box alignItems="center" direction="row" justifyContent="between">
427
+ <Heading size="md">{title || "Edit Consent Form"}</Heading>
428
+ <Box direction="row" gap={2}>
429
+ {hasAiSupport && (
430
+ <Button
431
+ iconName="wand-magic-sparkles"
432
+ loading={isGenerating}
433
+ onClick={handleOpenGenerateModal}
434
+ testID="consent-form-generate-button"
435
+ text="Generate with AI"
436
+ variant="secondary"
437
+ />
438
+ )}
439
+ <Button
440
+ loading={isPublishing}
441
+ onClick={handlePublish}
442
+ testID="consent-form-publish-button"
443
+ text="Publish New Version"
444
+ variant="primary"
445
+ />
446
+ </Box>
447
+ </Box>
448
+ )}
449
+
450
+ {/* Basic Fields */}
451
+ <Box gap={3}>
452
+ <Heading size="sm">Basic Information</Heading>
453
+ <TextField
454
+ onChange={handleTitleChange}
455
+ placeholder="Form title"
456
+ testID="consent-form-title-input"
457
+ title="Title"
458
+ value={title}
459
+ />
460
+ <TextField
461
+ onChange={handleSlugChange}
462
+ placeholder="form-slug"
463
+ testID="consent-form-slug-input"
464
+ title="Slug"
465
+ value={slug}
466
+ />
467
+ <SelectField
468
+ onChange={setType}
469
+ options={TYPE_OPTIONS}
470
+ requireValue
471
+ title="Type"
472
+ value={type}
473
+ />
474
+ <NumberField
475
+ onChange={setOrder}
476
+ testID="consent-form-order-input"
477
+ title="Order"
478
+ type="number"
479
+ value={order}
480
+ />
481
+ <SelectField
482
+ disabled={!hasLocales}
483
+ helperText={
484
+ hasLocales
485
+ ? undefined
486
+ : "Add at least one locale with content before setting a default locale."
487
+ }
488
+ onChange={setDefaultLocale}
489
+ options={defaultLocaleOptions}
490
+ title="Default Locale"
491
+ value={defaultLocale}
492
+ />
493
+ <BooleanField onChange={setRequired} title="Required" value={required} variant="title" />
494
+ <BooleanField onChange={setActive} title="Active" value={active} variant="title" />
495
+ </Box>
496
+
497
+ {/* Form Behavior */}
498
+ <Box gap={3}>
499
+ <Heading size="sm">Form Behavior</Heading>
500
+ <BooleanField
501
+ onChange={setCaptureSignature}
502
+ title="Capture Signature"
503
+ value={captureSignature}
504
+ variant="title"
505
+ />
506
+ <BooleanField
507
+ onChange={setRequireScrollToBottom}
508
+ title="Require Scroll to Bottom"
509
+ value={requireScrollToBottom}
510
+ variant="title"
511
+ />
512
+ </Box>
513
+
514
+ {/* Button Config */}
515
+ <Box gap={3}>
516
+ <Heading size="sm">Button Configuration</Heading>
517
+ <TextField
518
+ onChange={setAgreeButtonText}
519
+ placeholder="I Agree"
520
+ testID="consent-form-agree-button-text-input"
521
+ title="Agree Button Text"
522
+ value={agreeButtonText}
523
+ />
524
+ <BooleanField
525
+ onChange={setAllowDecline}
526
+ title="Allow Decline"
527
+ value={allowDecline}
528
+ variant="title"
529
+ />
530
+ {allowDecline && (
531
+ <TextField
532
+ onChange={setDeclineButtonText}
533
+ placeholder="Decline"
534
+ testID="consent-form-decline-button-text-input"
535
+ title="Decline Button Text"
536
+ value={declineButtonText}
537
+ />
538
+ )}
539
+ </Box>
540
+
541
+ {/* Content per Locale */}
542
+ <Box gap={3}>
543
+ <Box alignItems="center" direction="row" justifyContent="between">
544
+ <Heading size="sm">Content</Heading>
545
+ {hasAiSupport && !isEditMode && (
546
+ <Button
547
+ iconName="wand-magic-sparkles"
548
+ loading={isGenerating}
549
+ onClick={handleOpenGenerateModal}
550
+ testID="consent-form-generate-button"
551
+ text="Generate with AI"
552
+ variant="secondary"
553
+ />
554
+ )}
555
+ </Box>
556
+ {supportedLocales.length > 1 && (
557
+ <SegmentedControl
558
+ items={supportedLocales}
559
+ onChange={setActiveLocaleIndex}
560
+ selectedIndex={activeLocaleIndex}
561
+ />
562
+ )}
563
+ {hasAiSupport && isNonDefaultLocale && (
564
+ <Box>
565
+ <Button
566
+ loading={isTranslating}
567
+ onClick={() => handleTranslate(activeLocale)}
568
+ testID={`consent-form-translate-${activeLocale}-button`}
569
+ text={`Translate from ${defaultLocale}`}
570
+ variant="secondary"
571
+ />
572
+ </Box>
573
+ )}
574
+ <MarkdownEditor
575
+ onChange={(content) => handleLocaleContentChange(activeLocale, content)}
576
+ placeholder={`Enter content for locale: ${activeLocale}`}
577
+ testID={`consent-form-content-${activeLocale}`}
578
+ title={supportedLocales.length > 1 ? `Content (${activeLocale})` : "Content"}
579
+ value={localeContent[activeLocale] ?? ""}
580
+ />
581
+ </Box>
582
+
583
+ {/* Checkbox Builder */}
584
+ <Box gap={3}>
585
+ <Box alignItems="center" direction="row" justifyContent="between">
586
+ <Heading size="sm">Checkboxes</Heading>
587
+ <Button
588
+ iconName="plus"
589
+ onClick={handleAddCheckbox}
590
+ testID="consent-form-add-checkbox-button"
591
+ text="Add Checkbox"
592
+ variant="secondary"
593
+ />
594
+ </Box>
595
+ {checkboxes.length === 0 && <Text color="secondaryDark">No checkboxes configured.</Text>}
596
+ {checkboxes.map((checkbox, index) => (
597
+ <Box
598
+ border="default"
599
+ gap={3}
600
+ key={index}
601
+ padding={3}
602
+ rounding="md"
603
+ testID={`consent-form-checkbox-${index}`}
604
+ >
605
+ <Box alignItems="center" direction="row" justifyContent="between">
606
+ <Heading size="sm">Checkbox {index + 1}</Heading>
607
+ <Button
608
+ iconName="trash"
609
+ onClick={() => handleRemoveCheckbox(index)}
610
+ testID={`consent-form-checkbox-${index}-remove-button`}
611
+ text="Remove"
612
+ variant="destructive"
613
+ />
614
+ </Box>
615
+ <TextField
616
+ onChange={(value) => handleCheckboxChange(index, "label", value)}
617
+ placeholder="Checkbox label"
618
+ testID={`consent-form-checkbox-${index}-label-input`}
619
+ title="Label"
620
+ value={checkbox.label}
621
+ />
622
+ <BooleanField
623
+ onChange={(value) => handleCheckboxChange(index, "required", value)}
624
+ title="Required"
625
+ value={checkbox.required}
626
+ variant="title"
627
+ />
628
+ <TextField
629
+ onChange={(value) => handleCheckboxChange(index, "confirmationPrompt", value)}
630
+ placeholder="Optional confirmation prompt"
631
+ testID={`consent-form-checkbox-${index}-prompt-input`}
632
+ title="Confirmation Prompt (optional)"
633
+ value={checkbox.confirmationPrompt ?? ""}
634
+ />
635
+ </Box>
636
+ ))}
637
+ </Box>
638
+ </Box>
639
+
640
+ {/* AI Generate Modal */}
641
+ {hasAiSupport && (
642
+ <Modal
643
+ onDismiss={() => setIsGenerateModalVisible(false)}
644
+ primaryButtonOnClick={handleGenerate}
645
+ primaryButtonText={isGenerating ? "Generating..." : "Generate"}
646
+ secondaryButtonOnClick={() => setIsGenerateModalVisible(false)}
647
+ secondaryButtonText="Cancel"
648
+ size="md"
649
+ title="Generate Content with AI"
650
+ visible={isGenerateModalVisible}
651
+ >
652
+ <Box gap={3}>
653
+ <SelectField
654
+ onChange={setGenerateType}
655
+ options={TYPE_OPTIONS}
656
+ requireValue
657
+ title="Form Type"
658
+ value={generateType}
659
+ />
660
+ <Text color="secondaryDark" size="sm">
661
+ Locale: {activeLocale}
662
+ </Text>
663
+ <TextField
664
+ multiline
665
+ onChange={setGenerateDescription}
666
+ placeholder="Describe the consent form you need..."
667
+ rows={4}
668
+ testID="consent-form-generate-description-input"
669
+ title="Description"
670
+ value={generateDescription}
671
+ />
672
+ </Box>
673
+ </Modal>
674
+ )}
675
+ </Page>
676
+ );
677
+ };