@legalplace/wizardx-core 4.4.4 → 4.5.0

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.
@@ -1,3 +1,4 @@
1
+ import { EMAIL_REGEX } from "../../constants/emailValidation";
1
2
  import { UPDATE_OPTION_INPUT, UPDATE_VARIABLE_INPUT, ADD_MULTIPLE_OCCURENCY, DELETE_MULTIPLE_OCCURENCY, } from "../constants/inputs";
2
3
  import { selectVariableInputByIndex, selectOptionInputByIndex, selectOptionInput, } from "../selectors/inputs";
3
4
  import { SET_MANDATORY_OPTION, SET_MANDATORY_VARIABLE, } from "../constants/mandatories";
@@ -5,7 +6,7 @@ import { selectOptionRelations, selectOptionReference, selectSectionReference, s
5
6
  import { selectMandatoryOption, selectMandatoryVariable, } from "../selectors/mandatories";
6
7
  import { setMandatoryOptionAction, setMandatorySectionAction, setMandatoryVariableAction, } from "../actions/mandatories";
7
8
  import { UPDATE_OPTION_CONDITION, UPDATE_VARIABLE_CONDITION, UPDATE_SECTION_CONDITION, } from "../constants/conditions";
8
- import { selectOptionConditionValue, selectVariableConditionValue, selectIsOptionDisplayed, selectIsVariableDisplayed, } from "../selectors/conditions";
9
+ import { selectOptionConditionValue, selectVariableConditionValue, selectIsOptionDisplayed, selectIsVariableDisplayed, selectVariableValidatorConditionValue, } from "../selectors/conditions";
9
10
  import { FETCH_MODEL_SUCCEEDED } from "../constants/app";
10
11
  import { checkDateValidity } from "../../helpers/date.helper";
11
12
  import { checkPhoneNumberValidity } from "../../helpers/phoneNumber.helper";
@@ -120,6 +121,7 @@ const watchSectionMandatory = (mpi, next, action) => {
120
121
  validateSectionMandatory(mpi, sectionId);
121
122
  };
122
123
  const watchUpdateVariableInputCondition = (mpi, next, action, ignoreNext) => {
124
+ var _a;
123
125
  const { type, id, index, value } = action;
124
126
  if (ignoreNext !== true)
125
127
  next(action);
@@ -128,19 +130,29 @@ const watchUpdateVariableInputCondition = (mpi, next, action, ignoreNext) => {
128
130
  const inputValue = type === UPDATE_VARIABLE_INPUT
129
131
  ? `${value}`.trim().length > 0
130
132
  : `${selectVariableInputByIndex(id, index)}`.trim().length > 0;
131
- const { type: variableType } = selectVariableReference(id);
133
+ const { type: variableType, mask } = selectVariableReference(id);
132
134
  const conditionValue = action.type === UPDATE_VARIABLE_CONDITION
133
135
  ? action.value
134
136
  : selectVariableConditionValue(id, index) !== false;
135
137
  let mandatoryValue = !conditionValue || (conditionValue && inputValue);
136
- if (variableType === "date" &&
138
+ const emailInvalidCheck = (variableType === "email" || variableType === "user_email") &&
137
139
  typeof value === "string" &&
138
- !checkDateValidity(value)) {
139
- mandatoryValue = false;
140
- }
141
- if (variableType === "phone_number" &&
140
+ !EMAIL_REGEX.test(value.toString());
141
+ const dateInvalidCheck = variableType === "date" &&
142
+ typeof value === "string" &&
143
+ !checkDateValidity(value);
144
+ const phoneNumberInvalidCheck = variableType === "phone_number" &&
145
+ typeof value === "string" &&
146
+ !checkPhoneNumberValidity(value);
147
+ const maskInvalidityCheck = variableType === "mask" &&
142
148
  typeof value === "string" &&
143
- !checkPhoneNumberValidity(value)) {
149
+ !(value.toString().trim().length === ((_a = mask === null || mask === void 0 ? void 0 : mask.formula) === null || _a === void 0 ? void 0 : _a.length));
150
+ const customValidatorInvalidCheck = selectVariableValidatorConditionValue(id, index) === false;
151
+ if (emailInvalidCheck ||
152
+ dateInvalidCheck ||
153
+ phoneNumberInvalidCheck ||
154
+ maskInvalidityCheck ||
155
+ customValidatorInvalidCheck) {
144
156
  mandatoryValue = false;
145
157
  }
146
158
  mpi.dispatch(setMandatoryVariableAction(id, index, mandatoryValue));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/wizardx-core",
3
- "version": "4.4.4",
3
+ "version": "4.5.0",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -95,5 +95,5 @@
95
95
  "*.test.ts",
96
96
  "*.test.tsx"
97
97
  ],
98
- "gitHead": "bc6c068f7f4db0d04786c920ac5eccc47487e506"
98
+ "gitHead": "c8d086ebb96ba3f5c61b81b2d297bfb06a24e9d6"
99
99
  }