diff --git a/apps/backend/db_patches/0214_addMultiInstrumentJustification.sql b/apps/backend/db_patches/0214_addMultiInstrumentJustification.sql new file mode 100644 index 0000000000..8c1e58acb4 --- /dev/null +++ b/apps/backend/db_patches/0214_addMultiInstrumentJustification.sql @@ -0,0 +1,16 @@ +DO +$$ +BEGIN + IF register_patch('addMultiInstrumentJustification.sql', 'Zachary Hankin', 'Adds the option to request justification for multiple instrument use from the user', '2026-6-15') THEN + UPDATE questions + SET default_config = jsonb_set( + default_config::jsonb, + '{multiJustificationRequired}', + 'false'::jsonb, + true + ) + WHERE data_type = 'INSTRUMENT_PICKER'; + END IF; +END; +$$ +LANGUAGE plpgsql; diff --git a/apps/backend/src/models/questionTypes/InstrumentPicker.ts b/apps/backend/src/models/questionTypes/InstrumentPicker.ts index f4d5734a89..d73abc6bf7 100644 --- a/apps/backend/src/models/questionTypes/InstrumentPicker.ts +++ b/apps/backend/src/models/questionTypes/InstrumentPicker.ts @@ -40,6 +40,7 @@ export const instrumentPickerDefinition: Question = config.isMultipleSelect = false; config.requestTime = false; config.readPermissions = []; + config.multiJustificationRequired = false; return config; }, diff --git a/apps/backend/src/resolvers/types/FieldConfig.ts b/apps/backend/src/resolvers/types/FieldConfig.ts index dd845a0bbe..de25bd70f8 100644 --- a/apps/backend/src/resolvers/types/FieldConfig.ts +++ b/apps/backend/src/resolvers/types/FieldConfig.ts @@ -207,6 +207,9 @@ export class InstrumentPickerConfig extends ConfigBase { @Field(() => Boolean) requestTime: boolean; + + @Field(() => Boolean) + multiJustificationRequired: boolean; } @ObjectType() diff --git a/apps/frontend/src/components/questionary/questionaryComponents/InstrumentPicker/QuestionInstrumentPickerFormCommon.tsx b/apps/frontend/src/components/questionary/questionaryComponents/InstrumentPicker/QuestionInstrumentPickerFormCommon.tsx index dcafde8c4c..281d7354cd 100644 --- a/apps/frontend/src/components/questionary/questionaryComponents/InstrumentPicker/QuestionInstrumentPickerFormCommon.tsx +++ b/apps/frontend/src/components/questionary/questionaryComponents/InstrumentPicker/QuestionInstrumentPickerFormCommon.tsx @@ -20,6 +20,8 @@ export const QuestionInstrumentPickerFormCommon = ({ const [showIsMultipleSelectCheckbox, setShowIsMultipleSelectCheckbox] = useState(config.variant === 'dropdown'); + const [showJustification, setShowJustification] = useState(false); + return ( <> @@ -54,17 +56,6 @@ export const QuestionInstrumentPickerFormCommon = ({ /> - {showIsMultipleSelectCheckbox && ( - - )} + {showIsMultipleSelectCheckbox && ( + ) => { + setShowJustification(event.target.checked); + }} + /> + )} + {showIsMultipleSelectCheckbox && showJustification && ( + + )} ); diff --git a/apps/frontend/src/components/questionary/questionaryComponents/InstrumentPicker/QuestionaryComponentInstrumentPicker.tsx b/apps/frontend/src/components/questionary/questionaryComponents/InstrumentPicker/QuestionaryComponentInstrumentPicker.tsx index f2f46a2b0a..091f74e8e4 100644 --- a/apps/frontend/src/components/questionary/questionaryComponents/InstrumentPicker/QuestionaryComponentInstrumentPicker.tsx +++ b/apps/frontend/src/components/questionary/questionaryComponents/InstrumentPicker/QuestionaryComponentInstrumentPicker.tsx @@ -271,6 +271,20 @@ export function QuestionaryComponentInstrumentPicker( {config.requestTime && requestTimeForInstrument && ( )} + {config.requestTime && + requestTimeForInstrument && + config.multiJustificationRequired && ( + ) => { + onComplete(e.target.value); + }} + /> + )} {isError && } ); diff --git a/apps/frontend/src/graphql/template/fragment.fieldConfig.graphql b/apps/frontend/src/graphql/template/fragment.fieldConfig.graphql index e0b3ba81be..95c7af02b4 100644 --- a/apps/frontend/src/graphql/template/fragment.fieldConfig.graphql +++ b/apps/frontend/src/graphql/template/fragment.fieldConfig.graphql @@ -213,6 +213,7 @@ fragment fieldConfig on FieldConfig { readPermissions isMultipleSelect requestTime + multiJustificationRequired instruments { id name