# Updated behaviour for extended_dose_duration question in Survey:

- Choosing Less than 6 months keeps that answer and opens the same-style .survey-dialog with the eligibility note + Confirm
  Message:  As per the study eligibility criteria, physicians must have at least 6 months of prescribing experience with both packs. Kindly review and confirm your response.
- Confirm closes the dialog; the answer stays selected
- Other options do not show the popup
This commit is contained in:
Amey Bhagwat 2026-11-26 12:10:26 +05:30
parent 51f99134c3
commit 20cd54723c
2 changed files with 96 additions and 0 deletions

View File

@ -476,6 +476,12 @@ function QuestionField({
return null; return null;
} }
/** Soft eligibility note when Extended-Dose Pack duration is under 6 months. */
const EXTENDED_DOSE_DURATION_ID = 'extended_dose_duration';
const LESS_THAN_SIX_MONTHS_ID = 'less_than_6_months';
const ELIGIBILITY_NOTE =
'As per the study eligibility criteria, physicians must have at least 6 months of prescribing experience with both packs. Kindly review and confirm your response.';
export default function SurveyPage() { export default function SurveyPage() {
const { token } = useParams(); const { token } = useParams();
const [screen, setScreen] = useState('loading'); const [screen, setScreen] = useState('loading');
@ -486,6 +492,7 @@ export default function SurveyPage() {
const [error, setError] = useState(''); const [error, setError] = useState('');
const [stepErrors, setStepErrors] = useState([]); const [stepErrors, setStepErrors] = useState([]);
const [confirming, setConfirming] = useState(false); const [confirming, setConfirming] = useState(false);
const [eligibilityConfirming, setEligibilityConfirming] = useState(false);
const [busy, setBusy] = useState(false); const [busy, setBusy] = useState(false);
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
/** @type {[{ message: string, tone: 'success' | 'error' } | null, Function]} */ /** @type {[{ message: string, tone: 'success' | 'error' } | null, Function]} */
@ -608,6 +615,19 @@ export default function SurveyPage() {
dirtyRef.current = true; dirtyRef.current = true;
setStepErrors((current) => current.filter((item) => item.id !== id)); setStepErrors((current) => current.filter((item) => item.id !== id));
setAnswers((current) => ({ ...current, [id]: value })); setAnswers((current) => ({ ...current, [id]: value }));
if (
id === EXTENDED_DOSE_DURATION_ID &&
value &&
typeof value === 'object' &&
value.choice === LESS_THAN_SIX_MONTHS_ID
) {
setEligibilityConfirming(true);
}
}
function closeEligibilityConfirm() {
setEligibilityConfirming(false);
} }
async function saveProgress() { async function saveProgress() {
@ -873,6 +893,23 @@ export default function SurveyPage() {
</div> </div>
</div> </div>
) : null} ) : null}
{eligibilityConfirming ? (
<div className="survey-dialog">
<div role="dialog" aria-modal="true" aria-labelledby="eligibility-title">
<h2 id="eligibility-title">Please confirm</h2>
<p>{ELIGIBILITY_NOTE}</p>
<div className="survey-actions">
<button
type="button"
onMouseDown={(event) => event.preventDefault()}
onClick={closeEligibilityConfirm}
>
Confirm
</button>
</div>
</div>
</div>
) : null}
</main> </main>
); );
} }

View File

@ -232,4 +232,63 @@ describe('survey steps', () => {
fireEvent.change(select, { target: { value: 'kerala' } }); fireEvent.change(select, { target: { value: 'kerala' } });
expect(select).toHaveValue('kerala'); expect(select).toHaveValue('kerala');
}); });
it('shows an eligibility note when Extended-Dose Pack duration is under 6 months', async () => {
const withDuration = {
...survey,
definition: {
sections: [
{
id: 'prescribing',
title: 'Prescribing',
questions: [
{
id: 'extended_dose_duration',
type: 'single_choice',
label:
'For how long have you been prescribing the Extended-Dose Pack to your patients with asthma and/or COPD?',
required: true,
options: [
{ id: 'less_than_6_months', label: 'Less than 6 months' },
{ id: 'six_months_to_one_year', label: '6 months to less than 1 year' },
{ id: 'more_than_one_year', label: 'More than 1 year' },
],
},
],
},
],
},
};
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValue({ ok: true, json: async () => withDuration }),
);
renderSurvey();
const underSix = await screen.findByRole('radio', { name: 'Less than 6 months' });
expect(underSix).not.toBeChecked();
fireEvent.click(underSix);
expect(underSix).toBeChecked();
expect(
await screen.findByText(
/physicians must have at least 6 months of prescribing experience with both packs/i,
),
).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'Confirm' }));
expect(
screen.queryByText(
/physicians must have at least 6 months of prescribing experience with both packs/i,
),
).not.toBeInTheDocument();
expect(underSix).toBeChecked();
fireEvent.click(screen.getByRole('radio', { name: 'More than 1 year' }));
expect(
screen.queryByText(
/physicians must have at least 6 months of prescribing experience with both packs/i,
),
).not.toBeInTheDocument();
});
}); });