diff --git a/web/src/components/BaseQuestionnaireResponseForm/components/quantity.tsx b/web/src/components/BaseQuestionnaireResponseForm/components/quantity.tsx new file mode 100644 index 00000000..4e6443aa --- /dev/null +++ b/web/src/components/BaseQuestionnaireResponseForm/components/quantity.tsx @@ -0,0 +1,65 @@ +import React from 'react'; +import { QuestionItemProps, useQuestionnaireResponseFormContext } from 'sdc-qrf/src'; + +import { QuestionField } from './field'; +import { QuestionLabel } from './label'; + +export function QuestionQuantity({ parentPath, questionItem }: QuestionItemProps) { + const qrfContext = useQuestionnaireResponseFormContext(); + const { linkId, readOnly, hidden, unitOption } = questionItem; + const fieldPath = [...parentPath, linkId, 0, 'value', 'decimal']; + const fieldName = fieldPath.join('.'); + + const [selectedUnit, setSelectedUnit] = React.useState(unitOption?.[0]); + + return ( + + {({ input, meta }) => ( + <> + +
+ { + input.onChange({ + value: e.target.value, + unit: selectedUnit?.display, + system: selectedUnit?.system, + code: selectedUnit?.code, + }); + }} + /> + +
+ {meta.touched && meta.error && {meta.error}} + + )} +
+ ); +} diff --git a/web/src/components/BaseQuestionnaireResponseForm/index.tsx b/web/src/components/BaseQuestionnaireResponseForm/index.tsx index 9d14909b..c014c420 100644 --- a/web/src/components/BaseQuestionnaireResponseForm/index.tsx +++ b/web/src/components/BaseQuestionnaireResponseForm/index.tsx @@ -23,6 +23,7 @@ import { Row, } from './components'; import { QuestionInteger } from './components/integer'; +import { QuestionQuantity } from './components/quantity'; import { QuestionReference } from './components/reference'; import s from './QuestionnaireResponseForm.module.scss'; @@ -76,6 +77,7 @@ export function BaseQuestionnaireResponseForm({ formData, onSubmit, readOnly, on decimal: QuestionDecimal, reference: QuestionReference, integer: QuestionInteger, + quantity: QuestionQuantity, }} readOnly={readOnly} >