diff --git a/builder-frontend/README.md b/builder-frontend/README.md index 7ad9a04c..64c0f3bc 100644 --- a/builder-frontend/README.md +++ b/builder-frontend/README.md @@ -104,3 +104,22 @@ The component renders sanitized Markdown without template evaluation. Web links accept HTTP(S) URLs and open in a new tab. Pending or failed evaluations hide old instructions until fresh decisions arrive. Forms containing the component use its progress heading; existing forms without it keep the legacy completion message. + +## Unanswered questions in Next steps + +For an undecided benefit, Next steps lists the form's question labels for missing +inputs used by that benefit's undecided checks. Shared inputs are deduplicated; +inputs used only by decided checks are omitted. Fields sharing a label add their +group's label, and items of a repeated section with more than one item are +numbered, such as "Age (Household member #2)". Questions a form condition +currently hides are left out, since no one can answer them. Zero, No, and explicit None +answers remain answered. The list uses the same normalized data sent to the +eligibility service, including unknown CRM prefill preserved as null. + +Published screeners, Preview, and the print summary share these labels. Pending +or failed evaluations suppress old prompts along with old instructions, and +prompts disappear when the benefit is decided. Labels are kept separately from +answers in the results snapshot; answers and technical input paths are never +printed by this feature. If an input has no static form label, Next steps keeps +its general need-more-information message rather than inventing a question. +The CRM `nextSteps` extension continues to contain decided benefits only. diff --git a/builder-frontend/src/components/screener/FormRenderer.tsx b/builder-frontend/src/components/screener/FormRenderer.tsx index c77f83cc..9b82e890 100644 --- a/builder-frontend/src/components/screener/FormRenderer.tsx +++ b/builder-frontend/src/components/screener/FormRenderer.tsx @@ -91,6 +91,8 @@ function FormRenderer({ additionalModules: [CustomFormFieldsModule, screeningResultsModule], }); connectScreeningResults(form, { + schema: () => schema, + evaluatedAnswers: formData, results, screenerName, pending, diff --git a/builder-frontend/src/components/screenerEditor/formJsExtensions/nextSteps/NextSteps.test.ts b/builder-frontend/src/components/screenerEditor/formJsExtensions/nextSteps/NextSteps.test.ts index fd0d5632..beb56805 100644 --- a/builder-frontend/src/components/screenerEditor/formJsExtensions/nextSteps/NextSteps.test.ts +++ b/builder-frontend/src/components/screenerEditor/formJsExtensions/nextSteps/NextSteps.test.ts @@ -96,6 +96,34 @@ it("shows decided benefits immediately, preserves answers/schema, and lists unde expect((form as any)._getState().data).toEqual({}); }); +it("lists missing questions for undecided benefits and hides stale questions while pending", async () => { + const { container, service } = await mount(); + const current = result(); + service.update(current, false, false, { + food: ["Your date of birth", "Annual income"], + }); + await vi.waitFor(() => + expect(container.textContent).toContain("Find answers to these questions"), + ); + expect(container.textContent).toContain("Your date of birth"); + service.update(current, true, false, { food: ["Your date of birth"] }); + await vi.waitFor(() => + expect(container.textContent).not.toContain("Your date of birth"), + ); + service.update( + { ...current, food: { ...current.food, result: "TRUE" } }, + false, + false, + {}, + ); + await vi.waitFor(() => + expect(container.textContent).toContain("Screening complete"), + ); + expect(container.textContent).not.toContain( + "Find answers to these questions", + ); +}); + it("uses failed check aliases with name fallback and the analyst's note", async () => { const { container, service } = await mount(); const results = result("FALSE"); diff --git a/builder-frontend/src/components/screenerEditor/formJsExtensions/nextSteps/NextSteps.ts b/builder-frontend/src/components/screenerEditor/formJsExtensions/nextSteps/NextSteps.ts index 71860c8f..866512da 100644 --- a/builder-frontend/src/components/screenerEditor/formJsExtensions/nextSteps/NextSteps.ts +++ b/builder-frontend/src/components/screenerEditor/formJsExtensions/nextSteps/NextSteps.ts @@ -7,6 +7,7 @@ import { Text, } from "@bpmn-io/form-js-viewer"; import type { BenefitResult } from "@/types"; +import type { UnansweredQuestions } from "@/utils/unansweredQuestions"; import { useScreeningResults } from "../screeningResults/useScreeningResults"; import { NEXT_STEPS_TYPE, @@ -106,7 +107,8 @@ export function NextSteps({ field }: { field: NextStepsField }) { () => getService("screeningResults", false)?.showNextSteps(field.id), [getService, field.id], ); - const { results, pending, failed, mode } = useScreeningResults(); + const { results, pending, failed, mode, unansweredQuestions } = + useScreeningResults(); const benefits = Object.entries(results ?? {}); const complete = benefits.length > 0 && benefits.every(([, benefit]) => isDecided(benefit)); @@ -124,6 +126,7 @@ export function NextSteps({ field }: { field: NextStepsField }) { pending=${pending} failed=${failed} mode=${mode} + unansweredQuestions=${unansweredQuestions} /> `; } @@ -136,6 +139,7 @@ export function NextStepsBody({ failed, mode, forPrint = false, + unansweredQuestions, }: { field: NextStepsField; benefits: [string, BenefitResult][]; @@ -144,6 +148,7 @@ export function NextStepsBody({ failed: boolean; mode: "live" | "editor"; forPrint?: boolean; + unansweredQuestions?: UnansweredQuestions; }) { if (failed) return html`
Still needs more information.
+ ${!!unansweredQuestions?.[id]?.length && + html` +Find answers to these questions to continue:
+