@awell-health/ui-library 0.1.101 → 0.1.102
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
|
@@ -48234,10 +48234,10 @@ var Kr=[{
|
|
|
48234
48234
|
|
|
48235
48235
|
var AUTO_PROGRESS_DELAY = 850;
|
|
48236
48236
|
var QuestionData = function (_a) {
|
|
48237
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
48238
|
-
var question = _a.question,control = _a.control,getValues = _a.getValues,labels = _a.labels,
|
|
48237
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
48238
|
+
var question = _a.question,control = _a.control,getValues = _a.getValues,labels = _a.labels,_o = _a.inputAutoFocus,inputAutoFocus = _o === void 0 ? false : _o,_p = _a.submitAndMoveToNextQuestion,submitAndMoveToNextQuestion = _p === void 0 ? lodash.exports.noop : _p,_q = _a.onAnswerChange,onAnswerChange = _q === void 0 ? lodash.exports.noop : _q,_r = _a.shouldAutoProgress,shouldAutoProgress = _r === void 0 ? function () {return false;} : _r,onFileUpload = _a.onFileUpload;
|
|
48239
48239
|
var config = question === null || question === void 0 ? void 0 : question.questionConfig;
|
|
48240
|
-
var
|
|
48240
|
+
var _s = useICDClassificationList(question.id),icdClassificationOptions = _s.options,optionsLoading = _s.loading,onIcdClassificationSearchChange = _s.onIcdClassificationSearchChange;
|
|
48241
48241
|
switch (question.userQuestionType) {
|
|
48242
48242
|
case exports.UserQuestionType.YesNo:
|
|
48243
48243
|
return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, defaultValue: "", rules: { required: config === null || config === void 0 ? void 0 : config.mandatory }, render: function (_a) {
|
|
@@ -48330,22 +48330,28 @@ var Kr=[{
|
|
|
48330
48330
|
onAnswerChange();
|
|
48331
48331
|
}, 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) });
|
|
48332
48332
|
} });
|
|
48333
|
-
case exports.UserQuestionType.ShortText:
|
|
48334
|
-
|
|
48335
|
-
|
|
48336
|
-
|
|
48337
|
-
|
|
48338
|
-
|
|
48339
|
-
|
|
48340
|
-
|
|
48341
|
-
|
|
48342
|
-
|
|
48343
|
-
|
|
48333
|
+
case exports.UserQuestionType.ShortText:{
|
|
48334
|
+
var hasValidInputValidation = !!(config === null || config === void 0 ? void 0 : config.input_validation) &&
|
|
48335
|
+
typeof ((_b = config === null || config === void 0 ? void 0 : config.input_validation) === null || _b === void 0 ? void 0 : _b.pattern) === 'string' &&
|
|
48336
|
+
((_c = config === null || config === void 0 ? void 0 : config.input_validation) === null || _c === void 0 ? void 0 : _c.pattern.length) > 0;
|
|
48337
|
+
return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, defaultValue: "", rules: __assign({ required: config === null || config === void 0 ? void 0 : config.mandatory }, hasValidInputValidation && {
|
|
48338
|
+
pattern: {
|
|
48339
|
+
value: new RegExp((_e = (_d = config === null || config === void 0 ? void 0 : config.input_validation) === null || _d === void 0 ? void 0 : _d.pattern) !== null && _e !== void 0 ? _e : ''),
|
|
48340
|
+
message: (_g = (_f = config === null || config === void 0 ? void 0 : config.input_validation) === null || _f === void 0 ? void 0 : _f.helper_text) !== null && _g !== void 0 ? _g : 'The input value is invalid.' } }),
|
|
48341
|
+
|
|
48342
|
+
render: function (_a) {
|
|
48343
|
+
var _b = _a.field,onChange = _b.onChange,value = _b.value,error = _a.fieldState.error;
|
|
48344
|
+
return jsxRuntime.exports.jsxs(jsxRuntime.exports.Fragment, { children: [jsxRuntime.exports.jsx(InputField, { autoFocus: inputAutoFocus, type: "text", onChange: function (e) {
|
|
48345
|
+
onChange(e.target.value);
|
|
48346
|
+
onAnswerChange();
|
|
48347
|
+
}, 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 }))] });
|
|
48348
|
+
} });
|
|
48349
|
+
}
|
|
48344
48350
|
case exports.UserQuestionType.Telephone:
|
|
48345
|
-
var availableCountries_1 = ((
|
|
48351
|
+
var availableCountries_1 = ((_j = (_h = config === null || config === void 0 ? void 0 : config.phone) === null || _h === void 0 ? void 0 : _h.available_countries) !== null && _j !== void 0 ? _j : []).
|
|
48346
48352
|
map(function (c) {return c === null || c === void 0 ? void 0 : c.toLocaleLowerCase();}).
|
|
48347
48353
|
filter(function (x) {return !lodash.exports.isNil(x);});
|
|
48348
|
-
var initialCountry_1 = (
|
|
48354
|
+
var initialCountry_1 = (_m = (_l = (_k = config === null || config === void 0 ? void 0 : config.phone) === null || _k === void 0 ? void 0 : _k.default_country) === null || _l === void 0 ? void 0 : _l.toLocaleLowerCase()) !== null && _m !== void 0 ? _m : 'gb';
|
|
48349
48355
|
return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, defaultValue: "", render: function (_a) {
|
|
48350
48356
|
var _b;
|
|
48351
48357
|
var _c = _a.field,onChange = _c.onChange,value = _c.value;
|
|
@@ -48783,6 +48789,26 @@ var Kr=[{
|
|
|
48783
48789
|
return {
|
|
48784
48790
|
isValid: true };
|
|
48785
48791
|
|
|
48792
|
+
};
|
|
48793
|
+
var validateInputValidationResponse = function (questionConfig, value) {
|
|
48794
|
+
if (!questionConfig || !questionConfig.input_validation) {
|
|
48795
|
+
return {
|
|
48796
|
+
isValid: true };
|
|
48797
|
+
|
|
48798
|
+
}
|
|
48799
|
+
var pattern = questionConfig.input_validation.pattern;
|
|
48800
|
+
if (pattern) {
|
|
48801
|
+
var regex = new RegExp(pattern);
|
|
48802
|
+
if (!regex.test(value)) {
|
|
48803
|
+
return {
|
|
48804
|
+
isValid: false,
|
|
48805
|
+
errorType: 'INVALID_FORMAT' };
|
|
48806
|
+
|
|
48807
|
+
}
|
|
48808
|
+
}
|
|
48809
|
+
return {
|
|
48810
|
+
isValid: true };
|
|
48811
|
+
|
|
48786
48812
|
};
|
|
48787
48813
|
return {
|
|
48788
48814
|
isValidE164Number: isValidE164Number,
|
|
@@ -48792,7 +48818,8 @@ var Kr=[{
|
|
|
48792
48818
|
validateDateResponse: validateDateResponse,
|
|
48793
48819
|
validateNumberResponse: validateNumberResponse,
|
|
48794
48820
|
validateEmailResponse: validateEmailResponse,
|
|
48795
|
-
validateAttachmentsResponse: validateAttachmentsResponse
|
|
48821
|
+
validateAttachmentsResponse: validateAttachmentsResponse,
|
|
48822
|
+
validateInputValidationResponse: validateInputValidationResponse };
|
|
48796
48823
|
|
|
48797
48824
|
};
|
|
48798
48825
|
|
|
@@ -48876,8 +48903,8 @@ var Kr=[{
|
|
|
48876
48903
|
}
|
|
48877
48904
|
return Math.round((currentQuestionIndex + 1) / allQuestions.length * 100);
|
|
48878
48905
|
};
|
|
48879
|
-
var getErrorsForQuestion = function (currentQuestion, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse, validateAttachmentsResponse) {
|
|
48880
|
-
var _a;
|
|
48906
|
+
var getErrorsForQuestion = function (currentQuestion, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse, validateAttachmentsResponse, validateInputValidationResponse) {
|
|
48907
|
+
var _a, _b, _c;
|
|
48881
48908
|
if ((currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.userQuestionType) === exports.UserQuestionType.Description) {
|
|
48882
48909
|
return [];
|
|
48883
48910
|
}
|
|
@@ -48980,6 +49007,20 @@ var Kr=[{
|
|
|
48980
49007
|
|
|
48981
49008
|
|
|
48982
49009
|
|
|
49010
|
+
}
|
|
49011
|
+
}
|
|
49012
|
+
if ((currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.userQuestionType) === exports.UserQuestionType.ShortText) {
|
|
49013
|
+
var error = validateInputValidationResponse(currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.questionConfig, valueOfCurrentQuestion);
|
|
49014
|
+
if (error.isValid === false) {
|
|
49015
|
+
switch (error.errorType) {
|
|
49016
|
+
case 'INVALID_FORMAT':
|
|
49017
|
+
return [
|
|
49018
|
+
{
|
|
49019
|
+
id: currentQuestion.id,
|
|
49020
|
+
error: ((_c = (_b = currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.questionConfig) === null || _b === void 0 ? void 0 : _b.input_validation) === null || _c === void 0 ? void 0 : _c.helper_text) || 'The input value is invalid.' }];}
|
|
49021
|
+
|
|
49022
|
+
|
|
49023
|
+
|
|
48983
49024
|
}
|
|
48984
49025
|
}
|
|
48985
49026
|
return [];
|
|
@@ -49019,7 +49060,7 @@ var Kr=[{
|
|
|
49019
49060
|
var _d = React.useState([]),errors = _d[0],setErrors = _d[1];
|
|
49020
49061
|
var _e = React.useState(false),formHasErrors = _e[0],setFormHasErrors = _e[1];
|
|
49021
49062
|
var _f = React.useState(false),isSubmittingForm = _f[0],setIsSubmittingForm = _f[1];
|
|
49022
|
-
var _g = useValidate(),isValidE164Number = _g.isValidE164Number,validateDateResponse = _g.validateDateResponse,validateNumberResponse = _g.validateNumberResponse,validateEmailResponse = _g.validateEmailResponse,validateAttachmentsResponse = _g.validateAttachmentsResponse;
|
|
49063
|
+
var _g = useValidate(),isValidE164Number = _g.isValidE164Number,validateDateResponse = _g.validateDateResponse,validateNumberResponse = _g.validateNumberResponse,validateEmailResponse = _g.validateEmailResponse,validateAttachmentsResponse = _g.validateAttachmentsResponse,validateInputValidationResponse = _g.validateInputValidationResponse;
|
|
49023
49064
|
var updateQuestionVisibility = React.useCallback(function () {return __awaiter(void 0, void 0, void 0, function () {
|
|
49024
49065
|
var formValuesInput, evaluationResults, updatedQuestions;
|
|
49025
49066
|
return __generator(this, function (_a) {
|
|
@@ -49088,7 +49129,7 @@ var Kr=[{
|
|
|
49088
49129
|
case 1:
|
|
49089
49130
|
_a.sent();
|
|
49090
49131
|
formErrors = visibleQuestions.flatMap(function (vq) {
|
|
49091
|
-
return getErrorsForQuestion(vq, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse, validateAttachmentsResponse);
|
|
49132
|
+
return getErrorsForQuestion(vq, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse, validateAttachmentsResponse, validateInputValidationResponse);
|
|
49092
49133
|
});
|
|
49093
49134
|
setErrors(formErrors);
|
|
49094
49135
|
if (formErrors.length === 0) {
|
|
@@ -49116,7 +49157,7 @@ var Kr=[{
|
|
|
49116
49157
|
var useConversationalForm = function (_a) {
|
|
49117
49158
|
var questions = _a.questions,evaluateDisplayConditions = _a.evaluateDisplayConditions,onSubmit = _a.onSubmit,errorLabels = _a.errorLabels,storedAnswers = _a.storedAnswers,_b = _a.autosaveAnswers,autosaveAnswers = _b === void 0 ? true : _b,onAnswersChange = _a.onAnswersChange;
|
|
49118
49159
|
var initialValues = convertToFormFormat(storedAnswers, questions);
|
|
49119
|
-
var _c = useValidate(),isValidE164Number = _c.isValidE164Number,validateDateResponse = _c.validateDateResponse,validateNumberResponse = _c.validateNumberResponse,validateEmailResponse = _c.validateEmailResponse,validateAttachmentsResponse = _c.validateAttachmentsResponse;
|
|
49160
|
+
var _c = useValidate(),isValidE164Number = _c.isValidE164Number,validateDateResponse = _c.validateDateResponse,validateNumberResponse = _c.validateNumberResponse,validateEmailResponse = _c.validateEmailResponse,validateAttachmentsResponse = _c.validateAttachmentsResponse,validateInputValidationResponse = _c.validateInputValidationResponse;
|
|
49120
49161
|
var formMethods = useForm({
|
|
49121
49162
|
defaultValues: getInitialValues(questions),
|
|
49122
49163
|
shouldUnregister: false,
|
|
@@ -49185,7 +49226,7 @@ var Kr=[{
|
|
|
49185
49226
|
}, []);
|
|
49186
49227
|
var handleCheckForErrors = function (currentQuestion) {
|
|
49187
49228
|
var errorsWithoutCurrent = errors.filter(function (err) {return err.id !== (currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.id);});
|
|
49188
|
-
var existingErrors = getErrorsForQuestion(currentQuestion, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse, validateAttachmentsResponse);
|
|
49229
|
+
var existingErrors = getErrorsForQuestion(currentQuestion, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse, validateAttachmentsResponse, validateInputValidationResponse);
|
|
49189
49230
|
setErrors(__spreadArray(__spreadArray([], errorsWithoutCurrent, true), existingErrors, true));
|
|
49190
49231
|
return existingErrors.length > 0;
|
|
49191
49232
|
};
|
|
@@ -3,7 +3,7 @@ import { Question, QuestionWithVisibility, FormError } from '../../types';
|
|
|
3
3
|
import { AnswerValue, ErrorLabels, QuestionRuleResult } from './types';
|
|
4
4
|
import { CountryIso2 } from 'react-international-phone';
|
|
5
5
|
import { Maybe, QuestionConfig } from '../../types/generated/types-orchestration';
|
|
6
|
-
import { AttachmentsValidationErrorType, DateValidationErrorType, EmailValidationErrorType, NumberValidationErrorType } from '../useValidate/useValidate';
|
|
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
9
|
export declare const convertToAwellInput: (formResponse: any) => {
|
|
@@ -30,6 +30,9 @@ export declare const getErrorsForQuestion: (currentQuestion: QuestionWithVisibil
|
|
|
30
30
|
}, validateAttachmentsResponse: (questionConfig: Maybe<QuestionConfig> | undefined, value: string) => {
|
|
31
31
|
isValid: boolean;
|
|
32
32
|
errorType?: AttachmentsValidationErrorType;
|
|
33
|
+
}, validateInputValidationResponse: (questionConfig: Maybe<QuestionConfig> | undefined, value: string) => {
|
|
34
|
+
isValid: boolean;
|
|
35
|
+
errorType?: InputValidationErrorType;
|
|
33
36
|
}) => Array<FormError>;
|
|
34
37
|
export declare const getDirtyFieldValues: (formMethods: UseFormReturn) => Record<string, AnswerValue>;
|
|
35
38
|
export declare const markInitialValuesAsDirty: ({ formMethods, defaultValues, initialValues, }: {
|
|
@@ -4,6 +4,7 @@ export declare type DateValidationErrorType = 'DATE_CANNOT_BE_IN_THE_FUTURE' | '
|
|
|
4
4
|
export declare type NumberValidationErrorType = 'NOT_A_NUMBER' | 'OUT_OF_RANGE';
|
|
5
5
|
export declare type EmailValidationErrorType = 'INVALID_FORMAT';
|
|
6
6
|
export declare type AttachmentsValidationErrorType = 'REQUIRED' | 'INVALID_FORMAT';
|
|
7
|
+
export declare type InputValidationErrorType = 'INVALID_FORMAT';
|
|
7
8
|
export interface UseValidateHook {
|
|
8
9
|
validatePhoneNumber: (number: string, availableCountries?: Array<CountryIso2>) => ValidatePhoneReturn;
|
|
9
10
|
isValidE164Number: (number: string, availableCountries?: Array<CountryIso2>) => boolean;
|
|
@@ -25,6 +26,10 @@ export interface UseValidateHook {
|
|
|
25
26
|
isValid: boolean;
|
|
26
27
|
errorType?: AttachmentsValidationErrorType;
|
|
27
28
|
};
|
|
29
|
+
validateInputValidationResponse: (questionConfig: Maybe<QuestionConfig> | undefined, value: string) => {
|
|
30
|
+
isValid: boolean;
|
|
31
|
+
errorType?: InputValidationErrorType;
|
|
32
|
+
};
|
|
28
33
|
}
|
|
29
34
|
export declare const handleUSException: (number: string, originalValidation: ValidatePhoneReturn) => ValidatePhoneReturn;
|
|
30
35
|
export declare const useValidate: () => UseValidateHook;
|