Skip to content

Commit

Permalink
#70 Migrate resource select to react-hook-forms
Browse files Browse the repository at this point in the history
  • Loading branch information
ialakey committed Jun 21, 2024
1 parent 94aba65 commit 9ec8b42
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions web/src/components/QRFormWrapper/components/reference/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useFieldController } from '@beda.software/fhir-questionnaire/components/QuestionnaireResponseForm';
import {
parseFhirQueryExpression,
QuestionItemProps,
Expand Down Expand Up @@ -40,6 +41,8 @@ export function useAnswerReference<R extends Resource = any, IR extends Resource

const fieldName = fieldPath.join('.');

const { onChange } = useFieldController(fieldPath, questionItem);

// TODO: add support for fhirpath and application/x-fhir-query
const [resourceType, searchParams] = parseFhirQueryExpression(
answerExpression!.expression!,
Expand All @@ -60,14 +63,16 @@ export function useAnswerReference<R extends Resource = any, IR extends Resource
return [];
};

const onChange = (
_value:
const handleChange = (
selectedValue:
| SingleValue<QuestionnaireItemAnswerOption>
| MultiValue<QuestionnaireItemAnswerOption>,
action: ActionMeta<QuestionnaireItemAnswerOption>,
) => {
if (!repeats || action.action !== 'select-option') {
return;
onChange(selectedValue as SingleValue<QuestionnaireItemAnswerOption>);
} else if (repeats || action.action === 'select-option') {
onChange(selectedValue as MultiValue<QuestionnaireItemAnswerOption>);
}
};

Expand Down Expand Up @@ -95,7 +100,7 @@ export function useAnswerReference<R extends Resource = any, IR extends Resource
rootFieldName,
fieldName,
loadOptions,
onChange,
onChange: handleChange,
validate,
searchParams,
resourceType,
Expand Down

0 comments on commit 9ec8b42

Please sign in to comment.