@awell-health/ui-library 0.1.140 → 0.1.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -51524,6 +51524,9 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51524
51524
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
51525
51525
  var question = _a.question,control = _a.control,getValues = _a.getValues,labels = _a.labels,_m = _a.inputAutoFocus,inputAutoFocus = _m === void 0 ? false : _m,_o = _a.submitAndMoveToNextQuestion,submitAndMoveToNextQuestion = _o === void 0 ? lodash.exports.noop : _o,_p = _a.onAnswerChange,onAnswerChange = _p === void 0 ? lodash.exports.noop : _p,_q = _a.shouldAutoProgress,shouldAutoProgress = _q === void 0 ? function () {return false;} : _q,onFileUpload = _a.onFileUpload;
51526
51526
  var config = question === null || question === void 0 ? void 0 : question.questionConfig;
51527
+ var notifyAnswerChange = function (value) {
51528
+ onAnswerChange({ questionId: question.id, value: value });
51529
+ };
51527
51530
  var _r = useICDClassificationList(question.id),icdClassificationOptions = _r.options,optionsLoading = _r.loading,onIcdClassificationSearchChange = _r.onIcdClassificationSearchChange;
51528
51531
  var getAcceptedFileTypes = function () {
51529
51532
  var _a, _b, _c, _d;
@@ -51550,7 +51553,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51550
51553
  onChange: function (data) {
51551
51554
  onChange(data);
51552
51555
  if (value !== data) {
51553
- onAnswerChange();
51556
+ notifyAnswerChange(data);
51554
51557
  if (shouldAutoProgress(question)) {
51555
51558
  setTimeout(function () {return submitAndMoveToNextQuestion();}, AUTO_PROGRESS_DELAY);
51556
51559
  }
@@ -51570,14 +51573,14 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51570
51573
  var mapped = selectValueToOptions(selected);
51571
51574
  onChange(mapped);
51572
51575
  if (value !== mapped) {
51573
- onAnswerChange();
51576
+ notifyAnswerChange(mapped);
51574
51577
  }
51575
51578
  }, isMulti: true, options: optionsToSelectItems((_c = question.options) !== null && _c !== void 0 ? _c : []), required: config === null || config === void 0 ? void 0 : config.mandatory, isSearchable: true });
51576
51579
  }
51577
51580
  return jsxRuntime.exports.jsx(MultipleChoiceQuestion, { label: question.title, options: (_d = question.options) !== null && _d !== void 0 ? _d : [], onChange: function (data) {
51578
51581
  onChange(data);
51579
51582
  if (value !== data) {
51580
- onAnswerChange();
51583
+ notifyAnswerChange(data);
51581
51584
  }
51582
51585
  }, questionId: question.id, values: value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory });
51583
51586
  } });
@@ -51589,13 +51592,13 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51589
51592
  return jsxRuntime.exports.jsx(hf, { label: question.title, value: singleValueToSelectItem(value, (_b = question.options) !== null && _b !== void 0 ? _b : []), placeholder: (_c = labels.select) === null || _c === void 0 ? void 0 : _c.search_placeholder, onChange: function (selected) {
51590
51593
  var mapped = selectValueToSingleValue(selected);
51591
51594
  onChange(mapped);
51592
- onAnswerChange();
51595
+ notifyAnswerChange(mapped);
51593
51596
  }, options: optionsToSelectItems((_d = question.options) !== null && _d !== void 0 ? _d : []), required: config === null || config === void 0 ? void 0 : config.mandatory, isSearchable: true });
51594
51597
  }
51595
51598
  return jsxRuntime.exports.jsx(SingleChoiceQuestion, { label: question.title, options: question.options || [], onChange: function (data) {
51596
51599
  onChange(data);
51597
51600
  if (value !== data) {
51598
- onAnswerChange();
51601
+ notifyAnswerChange(data);
51599
51602
  if (shouldAutoProgress(question)) {
51600
51603
  setTimeout(function () {return submitAndMoveToNextQuestion();}, AUTO_PROGRESS_DELAY);
51601
51604
  }
@@ -51607,7 +51610,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51607
51610
  var _b = _a.field,onChange = _b.onChange,value = _b.value;
51608
51611
  return jsxRuntime.exports.jsx(LongTextField, { autoFocus: inputAutoFocus, onChange: function (e) {
51609
51612
  onChange(e.target.value);
51610
- onAnswerChange();
51613
+ notifyAnswerChange(e.target.value);
51611
51614
  }, label: question.title, id: question.id, value: value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory });
51612
51615
  } });
51613
51616
  case exports.UserQuestionType.Number:
@@ -51615,7 +51618,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51615
51618
  var _b = _a.field,onChange = _b.onChange,value = _b.value;
51616
51619
  return jsxRuntime.exports.jsx(InputField, { autoFocus: inputAutoFocus, type: "number", onChange: function (e) {
51617
51620
  onChange(e.target.value);
51618
- onAnswerChange();
51621
+ notifyAnswerChange(e.target.value);
51619
51622
  }, label: question.title, id: question.id, value: value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory, min: getMinValueForNumberInput(config === null || config === void 0 ? void 0 : config.number), max: getMaxValueForNumberInput(config === null || config === void 0 ? void 0 : config.number) });
51620
51623
  } });
51621
51624
  case exports.UserQuestionType.ShortText:{
@@ -51632,7 +51635,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51632
51635
  var _b = _a.field,onChange = _b.onChange,value = _b.value,error = _a.fieldState.error;
51633
51636
  return jsxRuntime.exports.jsxs(jsxRuntime.exports.Fragment, { children: [jsxRuntime.exports.jsx(InputField, { autoFocus: inputAutoFocus, type: "text", onChange: function (e) {
51634
51637
  onChange(e.target.value);
51635
- onAnswerChange();
51638
+ notifyAnswerChange(e.target.value);
51636
51639
  }, label: question.title, id: question.id, value: value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory }), error && jsxRuntime.exports.jsx(Text, __assign({ variant: "textSmall", color: "var(--awell-signalError100)" }, { children: error.message }))] });
51637
51640
  } });
51638
51641
  }
@@ -51646,7 +51649,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51646
51649
  var _c = _a.field,onChange = _c.onChange,value = _c.value;
51647
51650
  return jsxRuntime.exports.jsx(PhoneInputField, { autoFocus: inputAutoFocus, onChange: function (e) {
51648
51651
  onChange(e.target.value);
51649
- onAnswerChange();
51652
+ notifyAnswerChange(e.target.value);
51650
51653
  }, label: question.title, id: question.id, value: value !== null && value !== void 0 ? value : '', mandatory: (_b = question.questionConfig) === null || _b === void 0 ? void 0 : _b.mandatory, availableCountries: availableCountries_1, initialCountry: initialCountry_1, forceDialCode: true });
51651
51654
  } });
51652
51655
  case exports.UserQuestionType.Slider:
@@ -51663,7 +51666,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51663
51666
  var _c = _a.field,onChange = _c.onChange,value = _c.value;
51664
51667
  return jsxRuntime.exports.jsx(RangeInput, { label: question.title, onChange: function (e) {
51665
51668
  onChange(e.target.value);
51666
- onAnswerChange();
51669
+ notifyAnswerChange(e.target.value);
51667
51670
  }, touchTooltipLabel: (_b = labels.slider) === null || _b === void 0 ? void 0 : _b.tooltip_guide, id: question.id, sliderConfig: config === null || config === void 0 ? void 0 : config.slider, value: value === '' ? undefined : value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory });
51668
51671
  } });
51669
51672
  case exports.UserQuestionType.Email:
@@ -51680,7 +51683,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51680
51683
  var _c = _a.field,onChange = _c.onChange,value = _c.value;
51681
51684
  return jsxRuntime.exports.jsx(InputField, { autoFocus: inputAutoFocus, type: "email", onChange: function (e) {
51682
51685
  onChange(e.target.value);
51683
- onAnswerChange();
51686
+ notifyAnswerChange(e.target.value);
51684
51687
  }, label: question.title, id: question.id, value: value, mandatory: (_b = config === null || config === void 0 ? void 0 : config.mandatory) !== null && _b !== void 0 ? _b : false, placeholder: "name@example.com" });
51685
51688
  } });
51686
51689
  case exports.UserQuestionType.Date:
@@ -51690,7 +51693,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51690
51693
  var _b = _a.field,onChange = _b.onChange,value = _b.value;
51691
51694
  return jsxRuntime.exports.jsx(InputField, { autoFocus: inputAutoFocus, type: "date", label: question.title, onChange: function (e) {
51692
51695
  onChange(e.target.value);
51693
- onAnswerChange();
51696
+ notifyAnswerChange(e.target.value);
51694
51697
  }, id: question.id, value: value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory, min: getMinValueForDateInput(config === null || config === void 0 ? void 0 : config.date), max: getMaxValueForDateInput(config === null || config === void 0 ? void 0 : config.date) });
51695
51698
  } });
51696
51699
  case exports.UserQuestionType.Icd10Classification:
@@ -51703,7 +51706,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51703
51706
  noOptions: (_c = labels.select) === null || _c === void 0 ? void 0 : _c.no_options },
51704
51707
  onChange: function (data) {
51705
51708
  onChange(data);
51706
- onAnswerChange();
51709
+ notifyAnswerChange(data);
51707
51710
  }, type: "single", options: icdClassificationOptions !== null && icdClassificationOptions !== void 0 ? icdClassificationOptions : [], mandatory: config === null || config === void 0 ? void 0 : config.mandatory, showCount: true, filtering: true, onSearch: onIcdClassificationSearchChange, loading: optionsLoading, allowSearchAfterSelect: true, allowEmptyOptionsList: true }), jsxRuntime.exports.jsxs("span", __assign({ className: classes$b.awell_question_description }, { children: [(_d = labels.select) === null || _d === void 0 ? void 0 : _d.icd_10_catalogue_description, ' ', jsxRuntime.exports.jsx("a", __assign({ href: "https://icd.who.int/browse10/2019/en#/J00", target: "blank" }, { children: (_e = labels.select) === null || _e === void 0 ? void 0 : _e.icd_10_catalogue_link })), '.'] }))] });
51708
51711
  } });
51709
51712
  case exports.UserQuestionType.File:
@@ -51722,8 +51725,11 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51722
51725
  var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value,fieldError = _a.fieldState.error;
51723
51726
  return jsxRuntime.exports.jsx(SingleFileInputField, { id: question.id, value: custom_json_parser(value, ''), onChange: function (attachment) {
51724
51727
  console.log('attachment', attachment === null || attachment === void 0 ? void 0 : attachment.contentType);
51725
- onControllerChange(attachment ? JSON.stringify(attachment) : '');
51726
- onAnswerChange();
51728
+ var attachmentValue = attachment ?
51729
+ JSON.stringify(attachment) :
51730
+ '';
51731
+ onControllerChange(attachmentValue);
51732
+ notifyAnswerChange(attachmentValue);
51727
51733
  }, onBlur: onBlur, accept: (_c = (_b = config === null || config === void 0 ? void 0 : config.file_storage) === null || _b === void 0 ? void 0 : _b.accepted_file_types) !== null && _c !== void 0 ? _c : undefined, configSlug: (_d = config === null || config === void 0 ? void 0 : config.file_storage) === null || _d === void 0 ? void 0 : _d.file_storage_config_slug, onFileUpload: onFileUpload, label: question.title, mandatory: config === null || config === void 0 ? void 0 : config.mandatory, error: fieldError === null || fieldError === void 0 ? void 0 : fieldError.message });
51728
51734
  } });
51729
51735
  case exports.UserQuestionType.Image:
@@ -51741,8 +51747,11 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
51741
51747
  var _b, _c, _d;
51742
51748
  var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value,fieldError = _a.fieldState.error;
51743
51749
  return jsxRuntime.exports.jsx(SingleFileInputField, { id: question.id, value: custom_json_parser(value, ''), onChange: function (attachment) {
51744
- onControllerChange(attachment ? JSON.stringify(attachment) : '');
51745
- onAnswerChange();
51750
+ var attachmentValue = attachment ?
51751
+ JSON.stringify(attachment) :
51752
+ '';
51753
+ onControllerChange(attachmentValue);
51754
+ notifyAnswerChange(attachmentValue);
51746
51755
  }, onBlur: onBlur, accept: (_c = (_b = config === null || config === void 0 ? void 0 : config.file_storage) === null || _b === void 0 ? void 0 : _b.accepted_file_types) !== null && _c !== void 0 ? _c : ['image/*'], configSlug: (_d = config === null || config === void 0 ? void 0 : config.file_storage) === null || _d === void 0 ? void 0 : _d.file_storage_config_slug, onFileUpload: onFileUpload, label: question.title, mandatory: config === null || config === void 0 ? void 0 : config.mandatory, error: fieldError === null || fieldError === void 0 ? void 0 : fieldError.message });
51747
51756
  } });
51748
51757
  case exports.UserQuestionType.Description:
@@ -52124,6 +52133,111 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
52124
52133
  return __assign(__assign({}, obj), (_a = {}, _a[item.id] = getDefaultValue(item), _a));
52125
52134
  }, {});
52126
52135
  };
52136
+ var getQuestionReferenceValues = function (question) {
52137
+ return [question.id, question.key, question.definition_id].filter(Boolean);
52138
+ };
52139
+ var getDependentQuestionIds = function (questions, changedQuestionId) {
52140
+ if (!changedQuestionId) {
52141
+ return [];
52142
+ }
52143
+ var changedQuestion = questions.find(function (_a) {
52144
+ var id = _a.id;
52145
+ return id === changedQuestionId;
52146
+ });
52147
+ if (!changedQuestion) {
52148
+ return [];
52149
+ }
52150
+ var dependentQuestionIds = new Set();
52151
+ var questionIdsToCheck = [changedQuestion.id];
52152
+ var _loop_1 = function () {
52153
+ var currentQuestionId = questionIdsToCheck.shift();
52154
+ var currentQuestion = questions.find(function (_a) {
52155
+ var id = _a.id;
52156
+ return id === currentQuestionId;
52157
+ });
52158
+ if (!currentQuestion) {
52159
+ return "continue";
52160
+ }
52161
+ var currentQuestionReferences = getQuestionReferenceValues(currentQuestion);
52162
+ questions.forEach(function (question) {
52163
+ var _a, _b;
52164
+ if (question.id === changedQuestion.id ||
52165
+ dependentQuestionIds.has(question.id)) {
52166
+ return;
52167
+ }
52168
+ var dependsOnCurrentQuestion = (_b = (_a = question.rule) === null || _a === void 0 ? void 0 : _a.conditions) === null || _b === void 0 ? void 0 : _b.some(function (_a) {
52169
+ var reference = _a.reference,reference_key = _a.reference_key;
52170
+ return currentQuestionReferences.includes(reference !== null && reference !== void 0 ? reference : '') ||
52171
+ currentQuestionReferences.includes(reference_key !== null && reference_key !== void 0 ? reference_key : '');
52172
+ });
52173
+ if (dependsOnCurrentQuestion) {
52174
+ dependentQuestionIds.add(question.id);
52175
+ questionIdsToCheck.push(question.id);
52176
+ }
52177
+ });
52178
+ };
52179
+ while (questionIdsToCheck.length > 0) {
52180
+ _loop_1();
52181
+ }
52182
+ return Array.from(dependentQuestionIds);
52183
+ };
52184
+ var resetQuestionToDefault = function (formMethods, question) {
52185
+ var defaultValue = getDefaultValue(question);
52186
+ var currentValue = formMethods.getValues(question.id);
52187
+ var fieldState = formMethods.getFieldState(question.id);
52188
+ var hasNonDefaultValue = JSON.stringify(currentValue) !== JSON.stringify(defaultValue);
52189
+ if (!fieldState.isDirty && !fieldState.isTouched && !hasNonDefaultValue) {
52190
+ return false;
52191
+ }
52192
+ formMethods.resetField(question.id, { defaultValue: defaultValue });
52193
+ return true;
52194
+ };
52195
+ var evaluateQuestionVisibility = function (_a) {
52196
+ var questions = _a.questions,formMethods = _a.formMethods,evaluateDisplayConditions = _a.evaluateDisplayConditions,updateVisibilityForQuestions = _a.updateVisibilityForQuestions,change = _a.change;
52197
+ return __awaiter(void 0, void 0, void 0, function () {
52198
+ var dependentQuestionIds, questionsWithVisibility, attempt, dirtyValues, formValuesInput, evaluationResults, didResetHiddenAnswer;
52199
+ var _b;
52200
+ return __generator(this, function (_c) {
52201
+ switch (_c.label) {
52202
+ case 0:
52203
+ dependentQuestionIds = getDependentQuestionIds(questions, change === null || change === void 0 ? void 0 : change.questionId);
52204
+ dependentQuestionIds.forEach(function (questionId) {
52205
+ var question = questions.find(function (_a) {
52206
+ var id = _a.id;
52207
+ return id === questionId;
52208
+ });
52209
+ if (question) {
52210
+ resetQuestionToDefault(formMethods, question);
52211
+ }
52212
+ });
52213
+ questionsWithVisibility = [];
52214
+ attempt = 0;
52215
+ _c.label = 1;
52216
+ case 1:
52217
+ if (!(attempt <= questions.length)) return [3, 4];
52218
+ dirtyValues = getDirtyFieldValues(formMethods);
52219
+ formValuesInput = convertToAwellInput(__assign(__assign({}, dirtyValues), change ? (_b = {}, _b[change.questionId] = change.value, _b) : {}));
52220
+ return [4, evaluateDisplayConditions(formValuesInput)];
52221
+ case 2:
52222
+ evaluationResults = _c.sent();
52223
+ questionsWithVisibility = updateVisibilityForQuestions(questions, evaluationResults);
52224
+ didResetHiddenAnswer = questionsWithVisibility.
52225
+ filter(function (question) {return !question.visible;}).
52226
+ reduce(function (didReset, question) {
52227
+ return resetQuestionToDefault(formMethods, question) || didReset;
52228
+ }, false);
52229
+ if (!didResetHiddenAnswer) {
52230
+ return [3, 4];
52231
+ }
52232
+ _c.label = 3;
52233
+ case 3:
52234
+ attempt += 1;
52235
+ return [3, 1];
52236
+ case 4:return [2, questionsWithVisibility.filter(function (question) {return question.visible;})];}
52237
+
52238
+ });
52239
+ });
52240
+ };
52127
52241
  var getValue = function (answer) {
52128
52242
  if (typeof answer === 'string') {
52129
52243
  return answer;
@@ -52372,16 +52486,19 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
52372
52486
  var _e = React.useState(false),formHasErrors = _e[0],setFormHasErrors = _e[1];
52373
52487
  var _f = React.useState(false),isSubmittingForm = _f[0],setIsSubmittingForm = _f[1];
52374
52488
  var _g = useValidate(),isValidE164Number = _g.isValidE164Number,validateDateResponse = _g.validateDateResponse,validateNumberResponse = _g.validateNumberResponse,validateEmailResponse = _g.validateEmailResponse,validateAttachmentsResponse = _g.validateAttachmentsResponse,validateInputValidationResponse = _g.validateInputValidationResponse;
52375
- var updateQuestionVisibility = React.useCallback(function () {return __awaiter(void 0, void 0, void 0, function () {
52376
- var formValuesInput, evaluationResults, updatedQuestions;
52489
+ var updateQuestionVisibility = React.useCallback(function (change) {return __awaiter(void 0, void 0, void 0, function () {
52490
+ var updatedQuestions;
52377
52491
  return __generator(this, function (_a) {
52378
52492
  switch (_a.label) {
52379
- case 0:
52380
- formValuesInput = convertToAwellInput(getDirtyFieldValues(formMethods));
52381
- return [4, evaluateDisplayConditions(formValuesInput)];
52493
+ case 0:return [4, evaluateQuestionVisibility({
52494
+ questions: questions,
52495
+ formMethods: formMethods,
52496
+ evaluateDisplayConditions: evaluateDisplayConditions,
52497
+ updateVisibilityForQuestions: updateVisibilityForTraditionalForm,
52498
+ change: change })];
52499
+
52382
52500
  case 1:
52383
- evaluationResults = _a.sent();
52384
- updatedQuestions = updateVisibilityForTraditionalForm(questions, evaluationResults).filter(function (e) {return e.visible;});
52501
+ updatedQuestions = _a.sent();
52385
52502
  setVisibleQuestions(updatedQuestions);
52386
52503
  return [2, updatedQuestions];}
52387
52504
 
@@ -52508,17 +52625,21 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
52508
52625
  var _g = React.useState(true),isEvaluatingQuestionVisibility = _g[0],setIsEvaluatingQuestionVisibility = _g[1];
52509
52626
  var _h = React.useState(0),percentageCompleted = _h[0],setPercentageCompleted = _h[1];
52510
52627
  var _j = React.useState(false),isSubmittingForm = _j[0],setIsSubmittingForm = _j[1];
52511
- var updateQuestionVisibility = React.useCallback(function () {return __awaiter(void 0, void 0, void 0, function () {
52512
- var formValuesInput, evaluationResults, updatedQuestions;
52628
+ var updateQuestionVisibility = React.useCallback(function (change) {return __awaiter(void 0, void 0, void 0, function () {
52629
+ var updatedQuestions;
52513
52630
  return __generator(this, function (_a) {
52514
52631
  switch (_a.label) {
52515
52632
  case 0:
52516
52633
  setIsEvaluatingQuestionVisibility(true);
52517
- formValuesInput = convertToAwellInput(getDirtyFieldValues(formMethods));
52518
- return [4, evaluateDisplayConditions(formValuesInput)];
52634
+ return [4, evaluateQuestionVisibility({
52635
+ questions: questions,
52636
+ formMethods: formMethods,
52637
+ evaluateDisplayConditions: evaluateDisplayConditions,
52638
+ updateVisibilityForQuestions: updateVisibility,
52639
+ change: change })];
52640
+
52519
52641
  case 1:
52520
- evaluationResults = _a.sent();
52521
- updatedQuestions = updateVisibility(questions, evaluationResults).filter(function (e) {return e.visible;});
52642
+ updatedQuestions = _a.sent();
52522
52643
  setVisibleQuestions(updatedQuestions);
52523
52644
  setIsEvaluatingQuestionVisibility(false);
52524
52645
  return [2, updatedQuestions];}
@@ -1,11 +1,20 @@
1
1
  import { UseFormReturn } from 'react-hook-form';
2
- import { Question, QuestionWithVisibility, FormError } from '../../types';
3
- import { AnswerValue, ErrorLabels, QuestionRuleResult } from './types';
2
+ import { Question, QuestionWithVisibility, FormError, AnswerInput } from '../../types';
3
+ import { AnswerChange, AnswerValue, ErrorLabels, QuestionRuleResult } from './types';
4
4
  import { CountryIso2 } from 'react-international-phone';
5
5
  import { Maybe, QuestionConfig } from '../../types/generated/types-orchestration';
6
6
  import { AttachmentsValidationErrorType, DateValidationErrorType, EmailValidationErrorType, InputValidationErrorType, NumberValidationErrorType } from '../useValidate/useValidate';
7
7
  export declare const getDefaultValue: (question: Question) => AnswerValue;
8
8
  export declare const getInitialValues: (questions: Array<Question>) => Record<string, AnswerValue>;
9
+ export declare const getDependentQuestionIds: (questions: Array<Question>, changedQuestionId?: string) => Array<string>;
10
+ interface EvaluateQuestionVisibilityParams {
11
+ questions: Array<Question>;
12
+ formMethods: UseFormReturn;
13
+ evaluateDisplayConditions: (response: Array<AnswerInput>) => Promise<Array<QuestionRuleResult>>;
14
+ updateVisibilityForQuestions: (questions: Array<Question>, evaluationResults: Array<QuestionRuleResult>) => Array<QuestionWithVisibility>;
15
+ change?: AnswerChange;
16
+ }
17
+ export declare const evaluateQuestionVisibility: ({ questions, formMethods, evaluateDisplayConditions, updateVisibilityForQuestions, change, }: EvaluateQuestionVisibilityParams) => Promise<Array<QuestionWithVisibility>>;
9
18
  export declare const convertToAwellInput: (formResponse: any) => {
10
19
  question_id: string;
11
20
  value: string;
@@ -28,6 +28,10 @@ export declare type ErrorLabels = {
28
28
  emailInvalidFormat?: string;
29
29
  };
30
30
  export declare type AnswerValue = string | number | number[] | undefined;
31
+ export interface AnswerChange {
32
+ questionId: string;
33
+ value: unknown;
34
+ }
31
35
  export interface FormSettingsContextProps {
32
36
  evaluateDisplayConditions: (response: Array<AnswerInput>) => Promise<Array<QuestionRuleResult>>;
33
37
  onSubmit: (response: Array<AnswerInput>) => Promise<void> | void;
@@ -38,7 +42,7 @@ export interface FormSettingsContextProps {
38
42
  onAnswersChange?: (answers: string) => void;
39
43
  }
40
44
  export interface ConversationalFormContext {
41
- updateQuestionVisibility: () => void;
45
+ updateQuestionVisibility: (change?: AnswerChange) => void;
42
46
  submitForm: () => void;
43
47
  isSubmittingForm: boolean;
44
48
  handleGoToNextQuestion: () => void;
@@ -52,7 +56,7 @@ export interface ConversationalFormContext {
52
56
  isEvaluatingQuestionVisibility: boolean;
53
57
  }
54
58
  export interface TraditionalFormContext {
55
- updateQuestionVisibility: () => void;
59
+ updateQuestionVisibility: (change?: AnswerChange) => void;
56
60
  submitForm: () => void;
57
61
  isSubmittingForm: boolean;
58
62
  formMethods: UseFormReturn;
@@ -1,5 +1,9 @@
1
1
  import { FormError, Question } from '../../types';
2
2
  import { Control, UseFormGetValues } from 'react-hook-form';
3
+ export interface AnswerChange {
4
+ questionId: string;
5
+ value: unknown;
6
+ }
3
7
  export interface QuestionLabels {
4
8
  yes_label: string;
5
9
  no_label: string;
@@ -22,7 +26,7 @@ export interface QuestionDataProps {
22
26
  labels: QuestionLabels;
23
27
  inputAutoFocus?: boolean;
24
28
  submitAndMoveToNextQuestion?: () => void;
25
- onAnswerChange?: () => void;
29
+ onAnswerChange?: (change?: AnswerChange) => void;
26
30
  shouldAutoProgress?: (question: Question) => boolean;
27
31
  onFileUpload?: (file: File, configSlug?: string) => Promise<string>;
28
32
  }
@@ -34,7 +38,7 @@ export interface QuestionProps {
34
38
  labels?: QuestionLabels;
35
39
  inputAutoFocus?: boolean;
36
40
  submitAndMoveToNextQuestion?: () => void;
37
- onAnswerChange?: () => void;
41
+ onAnswerChange?: (change?: AnswerChange) => void;
38
42
  shouldAutoProgress?: (question: Question) => boolean;
39
43
  onFileUpload?: (file: File, configSlug?: string) => Promise<string>;
40
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awell-health/ui-library",
3
- "version": "0.1.140",
3
+ "version": "0.1.142",
4
4
  "description": "UI components to integrate with Awell Health",
5
5
  "repository": {
6
6
  "type": "git",