@awell-health/ui-library 0.1.66 → 0.1.68
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
|
@@ -37264,6 +37264,11 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37264
37264
|
};
|
|
37265
37265
|
PhoneInputField.displayName = 'PhoneInputField';
|
|
37266
37266
|
|
|
37267
|
+
var isValidEmail = function (email) {
|
|
37268
|
+
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
37269
|
+
return emailRegex.test(email);
|
|
37270
|
+
};
|
|
37271
|
+
|
|
37267
37272
|
var handleUSException = function (number, originalValidation) {
|
|
37268
37273
|
var _a;
|
|
37269
37274
|
var areaCodes = (_a = originalValidation.country) === null || _a === void 0 ? void 0 : _a.areaCodes;
|
|
@@ -37415,6 +37420,23 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37415
37420
|
return {
|
|
37416
37421
|
isValid: true };
|
|
37417
37422
|
|
|
37423
|
+
};
|
|
37424
|
+
var validateEmailResponse = function (questionConfig, value) {
|
|
37425
|
+
var inputRequired = questionConfig === null || questionConfig === void 0 ? void 0 : questionConfig.mandatory;
|
|
37426
|
+
if (inputRequired === false && lodash.exports.isEmpty(value)) {
|
|
37427
|
+
return {
|
|
37428
|
+
isValid: true };
|
|
37429
|
+
|
|
37430
|
+
}
|
|
37431
|
+
if (!isValidEmail(value)) {
|
|
37432
|
+
return {
|
|
37433
|
+
isValid: false,
|
|
37434
|
+
errorType: 'INVALID_FORMAT' };
|
|
37435
|
+
|
|
37436
|
+
}
|
|
37437
|
+
return {
|
|
37438
|
+
isValid: true };
|
|
37439
|
+
|
|
37418
37440
|
};
|
|
37419
37441
|
return {
|
|
37420
37442
|
isValidE164Number: isValidE164Number,
|
|
@@ -37422,7 +37444,8 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37422
37444
|
validatePhoneNumber: validatePhoneNumber,
|
|
37423
37445
|
numberMatchesAvailableCountries: numberMatchesAvailableCountries,
|
|
37424
37446
|
validateDateResponse: validateDateResponse,
|
|
37425
|
-
validateNumberResponse: validateNumberResponse
|
|
37447
|
+
validateNumberResponse: validateNumberResponse,
|
|
37448
|
+
validateEmailResponse: validateEmailResponse };
|
|
37426
37449
|
|
|
37427
37450
|
};
|
|
37428
37451
|
|
|
@@ -37472,11 +37495,6 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37472
37495
|
return undefined;
|
|
37473
37496
|
};
|
|
37474
37497
|
|
|
37475
|
-
var isValidEmail = function (email) {
|
|
37476
|
-
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
37477
|
-
return emailRegex.test(email);
|
|
37478
|
-
};
|
|
37479
|
-
|
|
37480
37498
|
var AUTO_PROGRESS_DELAY = 850;
|
|
37481
37499
|
var QuestionData = function (_a) {
|
|
37482
37500
|
var _b, _c, _d, _e, _f;
|
|
@@ -37624,7 +37642,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37624
37642
|
return jsxRuntime.exports.jsx(InputField, { autoFocus: inputAutoFocus, type: "email", onChange: function (e) {
|
|
37625
37643
|
onChange(e.target.value);
|
|
37626
37644
|
onAnswerChange();
|
|
37627
|
-
}, label: question.title, id: question.id, value: value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory });
|
|
37645
|
+
}, label: question.title, id: question.id, value: value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory, placeholder: "name@example.com" });
|
|
37628
37646
|
} });
|
|
37629
37647
|
case exports.UserQuestionType.Date:
|
|
37630
37648
|
return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, rules: {
|
|
@@ -37851,7 +37869,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37851
37869
|
}
|
|
37852
37870
|
return Math.round((currentQuestionIndex + 1) / allQuestions.length * 100);
|
|
37853
37871
|
};
|
|
37854
|
-
var getErrorsForQuestion = function (currentQuestion, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse) {
|
|
37872
|
+
var getErrorsForQuestion = function (currentQuestion, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse) {
|
|
37855
37873
|
var _a;
|
|
37856
37874
|
if ((currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.userQuestionType) === exports.UserQuestionType.Description) {
|
|
37857
37875
|
return [];
|
|
@@ -37925,6 +37943,21 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37925
37943
|
|
|
37926
37944
|
|
|
37927
37945
|
|
|
37946
|
+
}
|
|
37947
|
+
}
|
|
37948
|
+
if ((currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.userQuestionType) === exports.UserQuestionType.Email) {
|
|
37949
|
+
var error = validateEmailResponse(currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.questionConfig, valueOfCurrentQuestion);
|
|
37950
|
+
if (error.isValid === false) {
|
|
37951
|
+
switch (error.errorType) {
|
|
37952
|
+
case 'INVALID_FORMAT':
|
|
37953
|
+
return [
|
|
37954
|
+
{
|
|
37955
|
+
id: currentQuestion.id,
|
|
37956
|
+
error: errorLabels.emailInvalidFormat ||
|
|
37957
|
+
'Value must be a valid email address' }];}
|
|
37958
|
+
|
|
37959
|
+
|
|
37960
|
+
|
|
37928
37961
|
}
|
|
37929
37962
|
}
|
|
37930
37963
|
return [];
|
|
@@ -37964,7 +37997,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37964
37997
|
var _d = React.useState([]),errors = _d[0],setErrors = _d[1];
|
|
37965
37998
|
var _e = React.useState(false),formHasErrors = _e[0],setFormHasErrors = _e[1];
|
|
37966
37999
|
var _f = React.useState(false),isSubmittingForm = _f[0],setIsSubmittingForm = _f[1];
|
|
37967
|
-
var _g = useValidate(),isValidE164Number = _g.isValidE164Number,validateDateResponse = _g.validateDateResponse,validateNumberResponse = _g.validateNumberResponse;
|
|
38000
|
+
var _g = useValidate(),isValidE164Number = _g.isValidE164Number,validateDateResponse = _g.validateDateResponse,validateNumberResponse = _g.validateNumberResponse,validateEmailResponse = _g.validateEmailResponse;
|
|
37968
38001
|
var updateQuestionVisibility = React.useCallback(function () {return __awaiter(void 0, void 0, void 0, function () {
|
|
37969
38002
|
var formValuesInput, evaluationResults, updatedQuestions;
|
|
37970
38003
|
return __generator(this, function (_a) {
|
|
@@ -38033,7 +38066,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
38033
38066
|
case 1:
|
|
38034
38067
|
_a.sent();
|
|
38035
38068
|
formErrors = visibleQuestions.flatMap(function (vq) {
|
|
38036
|
-
return getErrorsForQuestion(vq, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse);
|
|
38069
|
+
return getErrorsForQuestion(vq, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse);
|
|
38037
38070
|
});
|
|
38038
38071
|
setErrors(formErrors);
|
|
38039
38072
|
if (formErrors.length === 0) {
|
|
@@ -38061,7 +38094,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
38061
38094
|
var useConversationalForm = function (_a) {
|
|
38062
38095
|
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;
|
|
38063
38096
|
var initialValues = convertToFormFormat(storedAnswers, questions);
|
|
38064
|
-
var _c = useValidate(),isValidE164Number = _c.isValidE164Number,validateDateResponse = _c.validateDateResponse,validateNumberResponse = _c.validateNumberResponse;
|
|
38097
|
+
var _c = useValidate(),isValidE164Number = _c.isValidE164Number,validateDateResponse = _c.validateDateResponse,validateNumberResponse = _c.validateNumberResponse,validateEmailResponse = _c.validateEmailResponse;
|
|
38065
38098
|
var formMethods = useForm({
|
|
38066
38099
|
defaultValues: getInitialValues(questions),
|
|
38067
38100
|
shouldUnregister: false,
|
|
@@ -38130,7 +38163,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
38130
38163
|
}, []);
|
|
38131
38164
|
var handleCheckForErrors = function (currentQuestion) {
|
|
38132
38165
|
var errorsWithoutCurrent = errors.filter(function (err) {return err.id !== (currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.id);});
|
|
38133
|
-
var existingErrors = getErrorsForQuestion(currentQuestion, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse);
|
|
38166
|
+
var existingErrors = getErrorsForQuestion(currentQuestion, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse, validateEmailResponse);
|
|
38134
38167
|
setErrors(__spreadArray(__spreadArray([], errorsWithoutCurrent, true), existingErrors, true));
|
|
38135
38168
|
return existingErrors.length > 0;
|
|
38136
38169
|
};
|
|
@@ -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 { DateValidationErrorType, NumberValidationErrorType } from '../useValidate/useValidate';
|
|
6
|
+
import { DateValidationErrorType, EmailValidationErrorType, 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) => {
|
|
@@ -24,6 +24,9 @@ export declare const getErrorsForQuestion: (currentQuestion: QuestionWithVisibil
|
|
|
24
24
|
}, validateNumberResponse: (questionConfig: Maybe<QuestionConfig> | undefined, value: string) => {
|
|
25
25
|
isValid: boolean;
|
|
26
26
|
errorType?: NumberValidationErrorType;
|
|
27
|
+
}, validateEmailResponse: (questionConfig: Maybe<QuestionConfig> | undefined, value: string) => {
|
|
28
|
+
isValid: boolean;
|
|
29
|
+
errorType?: EmailValidationErrorType;
|
|
27
30
|
}) => Array<FormError>;
|
|
28
31
|
export declare const getDirtyFieldValues: (formMethods: UseFormReturn) => Record<string, AnswerValue>;
|
|
29
32
|
export declare const markInitialValuesAsDirty: ({ formMethods, defaultValues, initialValues, }: {
|
|
@@ -25,6 +25,7 @@ export declare type ErrorLabels = {
|
|
|
25
25
|
dateCannotBeToday?: string;
|
|
26
26
|
notANumber?: string;
|
|
27
27
|
numberOutOfRange?: string;
|
|
28
|
+
emailInvalidFormat?: string;
|
|
28
29
|
};
|
|
29
30
|
export declare type AnswerValue = string | number | number[] | undefined;
|
|
30
31
|
export interface FormSettingsContextProps {
|
|
@@ -2,6 +2,7 @@ import { ValidatePhoneReturn, CountryIso2 } from './types';
|
|
|
2
2
|
import { Maybe, QuestionConfig } from '../../types/generated/types-orchestration';
|
|
3
3
|
export declare type DateValidationErrorType = 'DATE_CANNOT_BE_IN_THE_FUTURE' | 'DATE_CANNOT_BE_IN_THE_PAST' | 'DATE_CANNOT_BE_TODAY';
|
|
4
4
|
export declare type NumberValidationErrorType = 'NOT_A_NUMBER' | 'OUT_OF_RANGE';
|
|
5
|
+
export declare type EmailValidationErrorType = 'INVALID_FORMAT';
|
|
5
6
|
export interface UseValidateHook {
|
|
6
7
|
validatePhoneNumber: (number: string, availableCountries?: Array<CountryIso2>) => ValidatePhoneReturn;
|
|
7
8
|
isValidE164Number: (number: string, availableCountries?: Array<CountryIso2>) => boolean;
|
|
@@ -15,6 +16,10 @@ export interface UseValidateHook {
|
|
|
15
16
|
isValid: boolean;
|
|
16
17
|
errorType?: NumberValidationErrorType;
|
|
17
18
|
};
|
|
19
|
+
validateEmailResponse: (questionConfig: Maybe<QuestionConfig> | undefined, value: string) => {
|
|
20
|
+
isValid: boolean;
|
|
21
|
+
errorType?: EmailValidationErrorType;
|
|
22
|
+
};
|
|
18
23
|
}
|
|
19
24
|
export declare const handleUSException: (number: string, originalValidation: ValidatePhoneReturn) => ValidatePhoneReturn;
|
|
20
25
|
export declare const useValidate: () => UseValidateHook;
|