Skip to content

Commit

Permalink
Refactor : Added toggle rendering type to the interactive builder as …
Browse files Browse the repository at this point in the history
…well as options for the toggle
  • Loading branch information
Kinotijoan committed Sep 10, 2024
1 parent cd3a8ed commit d3f9bfd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/components/interactive-builder/add-question.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ const AddQuestionModal: React.FC<AddQuestionModalProps> = ({
programWorkflow?.uuid,
);
const [programWorkflows, setProgramWorkflows] = useState<Array<ProgramWorkflow>>([]);
const [toggleLabelTrue, setToggleLabelTrue] = useState('');
const [toggleLabelFalse, setToggleLabelFalse] = useState('');

const renderTypeOptions = {
control: ['text'],
Expand Down Expand Up @@ -244,6 +246,12 @@ const AddQuestionModal: React.FC<AddQuestionModalProps> = ({
programUuid: selectedProgram.uuid,
workflowUuid: programWorkflow.uuid,
}),
...(renderingType === 'toggle' && {
toggleOptions: {
labelTrue: toggleLabelTrue,
labelFalse: toggleLabelFalse,
},
}),
},
validators: [],
};
Expand Down Expand Up @@ -495,6 +503,29 @@ const AddQuestionModal: React.FC<AddQuestionModalProps> = ({
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setRows(event.target.value)}
required
/>
) : renderingType === 'toggle' ? (
<div>
<TextInput
id="lableTrue"
labelText={t('Label true', 'Label true')}
value={t(toggleLabelTrue || '')}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
setToggleLabelTrue(event.target.value)
}
placeholder={t('On')}
required
/>
<TextInput
id="lableFalse"
labelText={t('Label false', 'Lable false')}
value={t(toggleLabelFalse || '')}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
setToggleLabelFalse(event.target.value)
}
placeholder={t('Off')}
required
/>
</div>
) : null}

{renderingType !== 'ui-select-extended' && (
Expand Down
1 change: 1 addition & 0 deletions src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const configSchema = {
'text',
'textarea',
'ui-select-extended',
'toggle',
],
},
showSchemaSaveWarning: {
Expand Down

0 comments on commit d3f9bfd

Please sign in to comment.