@arquimedes.co/eureka-forms 2.0.96 → 2.0.98

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.
Files changed (30) hide show
  1. package/dist/@Types/GenericFormSteps.d.ts +1 -1
  2. package/dist/@Types/Organization.d.ts +2 -0
  3. package/dist/App/App.d.ts +3 -0
  4. package/dist/App/AppFunctions.d.ts +9 -2
  5. package/dist/App/AppFunctions.js +50 -29
  6. package/dist/App/AppHooks.js +14 -13
  7. package/dist/Form/FormFunctions.js +20 -8
  8. package/dist/FormSteps/PhoneInputStep/MaterialTextInputStep/MaterialPhoneInputStep.d.ts +4 -0
  9. package/dist/FormSteps/PhoneInputStep/MaterialTextInputStep/MaterialPhoneInputStep.js +51 -0
  10. package/dist/FormSteps/PhoneInputStep/MaterialTextInputStep/MaterialPhoneInputStep.module.css +9 -0
  11. package/dist/FormSteps/PhoneInputStep/PhoneInputStep.d.ts +11 -0
  12. package/dist/FormSteps/PhoneInputStep/PhoneInputStep.js +25 -0
  13. package/dist/FormSteps/Step.js +8 -3
  14. package/dist/Shared/RoundedCheckBox/RoundedCheckBox.d.ts +1 -1
  15. package/dist/Shared/RoundedCheckBox/RoundedCheckBox.js +1 -1
  16. package/dist/Shared/RoundedDatePicker/RoundedDatePicker.d.ts +1 -1
  17. package/dist/Shared/RoundedDatePicker/RoundedDatePicker.js +1 -1
  18. package/dist/Shared/RoundedPhoneInput/RoundedPhoneInput.d.ts +43 -0
  19. package/dist/Shared/RoundedPhoneInput/RoundedPhoneInput.js +226 -0
  20. package/dist/Shared/RoundedSelect/RoundedSelect.d.ts +1 -1
  21. package/dist/Shared/RoundedSelect/RoundedSelect.js +1 -1
  22. package/dist/Shared/RoundedTextField/RoundedTextField.d.ts +1 -1
  23. package/dist/Shared/RoundedTextField/RoundedTextField.js +1 -1
  24. package/dist/Shared/RoundedTimePicker/RoundedTimePicker.d.ts +1 -1
  25. package/dist/Shared/RoundedTimePicker/RoundedTimePicker.js +1 -1
  26. package/dist/States/GlobalSlice.d.ts +3 -0
  27. package/dist/States/GlobalSlice.js +1 -0
  28. package/dist/Utils/PhoneFunctions.d.ts +2 -0
  29. package/dist/Utils/PhoneFunctions.js +26 -0
  30. package/package.json +4 -1
@@ -35,7 +35,7 @@ export interface GTextInput extends GBaseStep {
35
35
  validation?: {
36
36
  message: string;
37
37
  value: string;
38
- type: 'EMAIL' | 'OTHER';
38
+ type: 'EMAIL' | 'PHONE' | 'OTHER';
39
39
  };
40
40
  required: boolean;
41
41
  showIcon?: boolean;
@@ -1,3 +1,4 @@
1
+ import { CountryCode } from 'libphonenumber-js';
1
2
  import { Branding } from './Branding';
2
3
  export interface Organization {
3
4
  /** The Organization's id */
@@ -6,4 +7,5 @@ export interface Organization {
6
7
  name: string;
7
8
  branding: Branding;
8
9
  customBrandings: boolean;
10
+ countryCode?: CountryCode;
9
11
  }
package/dist/App/App.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Classifier, Form } from '../@Types/Form';
3
3
  import './App.css';
4
4
  import { CustomStep, CustomStepProps } from '../FormSteps/CustomStep';
5
5
  import { EditorState } from 'draft-js';
6
+ import { CountryCode } from 'libphonenumber-js';
6
7
  export interface AppProps {
7
8
  /** If the app is currently a widget */
8
9
  isWidget?: boolean;
@@ -50,6 +51,8 @@ export interface AppProps {
50
51
  handleConfirmed?: () => void;
51
52
  /** Function called to scroll to the top */
52
53
  scrollToTop?: () => void;
54
+ /** The default country to use in phone pickers */
55
+ countryCode?: CountryCode;
53
56
  }
54
57
  export declare const IdFormContext: React.Context<string>;
55
58
  declare function AppComponent({ formData, valuesData, ...props }: AppProps): JSX.Element;
@@ -4,7 +4,11 @@ import { SiteState, ValuesStore } from '../States/SiteSlice';
4
4
  import { CustomStep } from '../FormSteps/CustomStep';
5
5
  import { MapperElement } from '../@Types/MapperElement';
6
6
  import { MapperValue } from '../FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep';
7
- export declare const calcValuesStore: (idOrganization: string, form: Readonly<Form>, originalValues?: Record<string, any>, postview?: boolean, customSteps?: Record<string, CustomStep>) => Promise<ValuesStore>;
7
+ import { CountryCode } from 'libphonenumber-js/max';
8
+ export declare const calcValuesStore: (orgInfo: {
9
+ idOrganization: string;
10
+ countryCode: CountryCode;
11
+ }, form: Readonly<Form>, originalValues?: Record<string, any>, postview?: boolean, customSteps?: Record<string, CustomStep>) => Promise<ValuesStore>;
8
12
  export declare const addMapperStep: <Type>(step: Mapper, customSteps: Record<string, CustomStep>, path?: string) => {
9
13
  element: MapperElement<Type>;
10
14
  /** Record of all the new mapper values created */
@@ -12,5 +16,8 @@ export declare const addMapperStep: <Type>(step: Mapper, customSteps: Record<str
12
16
  /** Record of all the new steps created */
13
17
  steps: Record<string, FormStep>;
14
18
  };
15
- export declare const mapOriginalValue: (idOrganization: string, step: FormStep, value: any, values: ValuesStore, form?: Readonly<Form>, path?: string) => Promise<any>;
19
+ export declare const mapOriginalValue: (orgInfo: {
20
+ idOrganization: string;
21
+ countryCode: CountryCode;
22
+ }, step: FormStep, value: any, values: ValuesStore, form?: Readonly<Form>, path?: string) => Promise<any>;
16
23
  export declare const calcInitialSections: (form: Form) => Pick<SiteState, 'previousSections' | 'idCurrentSection' | 'nextSections'>;
@@ -60,7 +60,9 @@ import { getRawText, stringToDraft } from '../Utils/DraftFunctions';
60
60
  import ConditionTypes from '../constants/ConditionTypes';
61
61
  import widgetInstance from '../Utils/AxiosWidget';
62
62
  import { calcRecursiveData } from '../Utils/FormStepFunctions';
63
- export var calcValuesStore = function (idOrganization, form, originalValues, postview, customSteps) {
63
+ import { getCountry } from 'react-international-phone';
64
+ import { isValidPhoneNumber } from '../Utils/PhoneFunctions';
65
+ export var calcValuesStore = function (orgInfo, form, originalValues, postview, customSteps) {
64
66
  if (originalValues === void 0) { originalValues = {}; }
65
67
  if (postview === void 0) { postview = false; }
66
68
  if (customSteps === void 0) { customSteps = {}; }
@@ -83,7 +85,7 @@ export var calcValuesStore = function (idOrganization, form, originalValues, pos
83
85
  case 0:
84
86
  step = form.steps[idValue];
85
87
  if (!step) return [3 /*break*/, 2];
86
- return [4 /*yield*/, mapOriginalValue(idOrganization, step, originalValues[step.id], values, form)];
88
+ return [4 /*yield*/, mapOriginalValue(orgInfo, step, originalValues[step.id], values, form)];
87
89
  case 1:
88
90
  value = _b.sent();
89
91
  if (value !== undefined) {
@@ -162,13 +164,13 @@ export var addMapperStep = function (step, customSteps, path) {
162
164
  }
163
165
  return { element: element, mappers: mappers, steps: steps };
164
166
  };
165
- export var mapOriginalValue = function (idOrganization, step, value, values, form, path) {
167
+ export var mapOriginalValue = function (orgInfo, step, value, values, form, path) {
166
168
  if (path === void 0) { path = ''; }
167
169
  return __awaiter(void 0, void 0, void 0, function () {
168
- var _a, elements, mappedElements, _loop_1, _i, elements_1, element, defaultValue, option, stepClassifier, classifier, params, url, entityValues, entityValue;
169
- var _b, _c, _d, _e, _f, _g, _h, _j;
170
- return __generator(this, function (_k) {
171
- switch (_k.label) {
170
+ var _a, elements, mappedElements, _loop_1, _i, elements_1, element, defaultValue, option, stepClassifier, classifier, params, url, entityValues, entityValue, country;
171
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
172
+ return __generator(this, function (_o) {
173
+ switch (_o.label) {
172
174
  case 0:
173
175
  if (!value)
174
176
  return [2 /*return*/, value];
@@ -179,15 +181,16 @@ export var mapOriginalValue = function (idOrganization, step, value, values, for
179
181
  case FormStepTypes.SELECTOR: return [3 /*break*/, 7];
180
182
  case FormStepTypes.CLASSIFIER_SELECTOR: return [3 /*break*/, 8];
181
183
  case FormStepTypes.ENTITYVALUEPICKER: return [3 /*break*/, 9];
184
+ case FormStepTypes.TEXTINPUT: return [3 /*break*/, 12];
182
185
  }
183
- return [3 /*break*/, 12];
186
+ return [3 /*break*/, 13];
184
187
  case 1:
185
188
  elements = value;
186
189
  mappedElements = [];
187
190
  _loop_1 = function (element) {
188
- var idElement, mappedElement, base, _l, _m, subStep, dependencies, _o, dependencies_1, idDep, mappedIdDep, _p, _q, key;
189
- return __generator(this, function (_r) {
190
- switch (_r.label) {
191
+ var idElement, mappedElement, base, _p, _q, subStep, dependencies, _r, dependencies_1, idDep, mappedIdDep, _s, _t, key;
192
+ return __generator(this, function (_u) {
193
+ switch (_u.label) {
191
194
  case 0:
192
195
  idElement = (_b = element.id) !== null && _b !== void 0 ? _b : nanoid();
193
196
  mappedElement = {
@@ -207,7 +210,7 @@ export var mapOriginalValue = function (idOrganization, step, value, values, for
207
210
  case 0:
208
211
  newIdStep = base + step.id + '-' + idElement + '-' + idStep;
209
212
  mappedElement.ids[idStep] = newIdStep;
210
- return [4 /*yield*/, mapOriginalValue(idOrganization, step.steps[idStep], element[idStep], values, form, base + step.id + '-' + idElement)];
213
+ return [4 /*yield*/, mapOriginalValue(orgInfo, step.steps[idStep], element[idStep], values, form, base + step.id + '-' + idElement)];
211
214
  case 1:
212
215
  value = _a.sent();
213
216
  if (value !== undefined) {
@@ -220,15 +223,15 @@ export var mapOriginalValue = function (idOrganization, step, value, values, for
220
223
  });
221
224
  }); }))];
222
225
  case 1:
223
- _r.sent();
224
- for (_l = 0, _m = Object.values(step.steps); _l < _m.length; _l++) {
225
- subStep = _m[_l];
226
+ _u.sent();
227
+ for (_p = 0, _q = Object.values(step.steps); _p < _q.length; _p++) {
228
+ subStep = _q[_p];
226
229
  dependencies = (_c = subStep.dependencies) !== null && _c !== void 0 ? _c : [];
227
230
  if (subStep.condition) {
228
231
  dependencies = __spreadArray(__spreadArray([], dependencies, true), calcNestedConditionSteps(subStep.condition), true).filter(function (item, i, ar) { return ar.indexOf(item) === i; });
229
232
  }
230
- for (_o = 0, dependencies_1 = dependencies; _o < dependencies_1.length; _o++) {
231
- idDep = dependencies_1[_o];
233
+ for (_r = 0, dependencies_1 = dependencies; _r < dependencies_1.length; _r++) {
234
+ idDep = dependencies_1[_r];
232
235
  mappedIdDep = base + step.id + '-' + idElement + '-' + idDep;
233
236
  if (!values.sections[step.idSection][idDep] &&
234
237
  !values.global[mappedIdDep] &&
@@ -238,8 +241,8 @@ export var mapOriginalValue = function (idOrganization, step, value, values, for
238
241
  }
239
242
  }
240
243
  }
241
- for (_p = 0, _q = Object.keys(element); _p < _q.length; _p++) {
242
- key = _q[_p];
244
+ for (_s = 0, _t = Object.keys(element); _s < _t.length; _s++) {
245
+ key = _t[_s];
243
246
  if (step.steps[key] || key === 'id')
244
247
  continue;
245
248
  mappedElement.originalValues[key] = element[key];
@@ -250,14 +253,14 @@ export var mapOriginalValue = function (idOrganization, step, value, values, for
250
253
  });
251
254
  };
252
255
  _i = 0, elements_1 = elements;
253
- _k.label = 2;
256
+ _o.label = 2;
254
257
  case 2:
255
258
  if (!(_i < elements_1.length)) return [3 /*break*/, 5];
256
259
  element = elements_1[_i];
257
260
  return [5 /*yield**/, _loop_1(element)];
258
261
  case 3:
259
- _k.sent();
260
- _k.label = 4;
262
+ _o.sent();
263
+ _o.label = 4;
261
264
  case 4:
262
265
  _i++;
263
266
  return [3 /*break*/, 2];
@@ -278,7 +281,7 @@ export var mapOriginalValue = function (idOrganization, step, value, values, for
278
281
  return [2 /*return*/, (_e = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.text) !== null && _e !== void 0 ? _e : ''];
279
282
  }
280
283
  }
281
- _k.label = 7;
284
+ _o.label = 7;
282
285
  case 7:
283
286
  {
284
287
  option = step.options.find(function (option) { return option.value === value; });
@@ -286,7 +289,7 @@ export var mapOriginalValue = function (idOrganization, step, value, values, for
286
289
  return [2 /*return*/, option];
287
290
  return [2 /*return*/, value];
288
291
  }
289
- _k.label = 8;
292
+ _o.label = 8;
290
293
  case 8:
291
294
  {
292
295
  stepClassifier = (_f = form === null || form === void 0 ? void 0 : form.classifiers) === null || _f === void 0 ? void 0 : _f[(_g = step.idClassifier) !== null && _g !== void 0 ? _g : ''];
@@ -294,16 +297,16 @@ export var mapOriginalValue = function (idOrganization, step, value, values, for
294
297
  classifier = (_h = form.classifiers) === null || _h === void 0 ? void 0 : _h[value];
295
298
  return [2 /*return*/, { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name }];
296
299
  }
297
- return [3 /*break*/, 13];
300
+ return [3 /*break*/, 14];
298
301
  }
299
- _k.label = 9;
302
+ _o.label = 9;
300
303
  case 9:
301
304
  if (!!value._id) return [3 /*break*/, 11];
302
305
  params = new URLSearchParams(value);
303
- url = "".concat(idOrganization, "/entities/").concat(step.idEntity, "?").concat(params.toString());
306
+ url = "".concat(orgInfo.idOrganization, "/entities/").concat(step.idEntity, "?").concat(params.toString());
304
307
  return [4 /*yield*/, widgetInstance.get(url)];
305
308
  case 10:
306
- entityValues = (_k.sent()).data;
309
+ entityValues = (_o.sent()).data;
307
310
  if (entityValues.length === 1) {
308
311
  entityValue = entityValues[0];
309
312
  if (((_j = step.options[entityValue._id]) === null || _j === void 0 ? void 0 : _j.type) ===
@@ -314,13 +317,31 @@ export var mapOriginalValue = function (idOrganization, step, value, values, for
314
317
  return [2 /*return*/, null];
315
318
  case 11: return [2 /*return*/, value];
316
319
  case 12:
320
+ {
321
+ if (step.clientInfoType === 'cel' ||
322
+ ((_k = step.validation) === null || _k === void 0 ? void 0 : _k.type) === 'PHONE') {
323
+ if (!isValidPhoneNumber(value)) {
324
+ country = getCountry({
325
+ field: 'iso2',
326
+ value: (_m = (_l = orgInfo.countryCode) === null || _l === void 0 ? void 0 : _l.toLowerCase()) !== null && _m !== void 0 ? _m : 'co',
327
+ });
328
+ if (country &&
329
+ isValidPhoneNumber(country.dialCode + value)) {
330
+ return [2 /*return*/, country.dialCode + value];
331
+ }
332
+ }
333
+ }
334
+ return [2 /*return*/, value];
335
+ }
336
+ _o.label = 13;
337
+ case 13:
317
338
  if (step.type.startsWith('CBR_') &&
318
339
  (value === null || value === void 0 ? void 0 : value.id) &&
319
340
  typeof value.id === 'number') {
320
341
  return [2 /*return*/, __assign(__assign({}, value), { id: value.id.toString() })];
321
342
  }
322
343
  return [2 /*return*/, value];
323
- case 13: return [2 /*return*/];
344
+ case 14: return [2 /*return*/];
324
345
  }
325
346
  });
326
347
  });
@@ -113,11 +113,11 @@ export var useSetupApp = function (isEmbedded, _a) {
113
113
  });
114
114
  }); };
115
115
  var loadData = function () { return __awaiter(void 0, void 0, void 0, function () {
116
- var idOrganization, organization, form, match, dependencies, values;
116
+ var idOrganization, organization, form, countryCode, match, dependencies, values;
117
117
  var _a;
118
- var _b, _c, _d;
119
- return __generator(this, function (_e) {
120
- switch (_e.label) {
118
+ var _b, _c, _d, _e, _f;
119
+ return __generator(this, function (_g) {
120
+ switch (_g.label) {
121
121
  case 0:
122
122
  idOrganization = others.idOrganization;
123
123
  organization = null;
@@ -125,7 +125,7 @@ export var useSetupApp = function (isEmbedded, _a) {
125
125
  if (!(form && preview && form.isStandAlone)) return [3 /*break*/, 2];
126
126
  return [4 /*yield*/, loadOrg()];
127
127
  case 1:
128
- organization = _e.sent();
128
+ organization = _g.sent();
129
129
  return [3 /*break*/, 4];
130
130
  case 2:
131
131
  if (!(!form && apiKey)) return [3 /*break*/, 4];
@@ -135,12 +135,13 @@ export var useSetupApp = function (isEmbedded, _a) {
135
135
  ])];
136
136
  case 3:
137
137
  //Is iframe or widget
138
- _a = _e.sent(), organization = _a[0], form = _a[1];
139
- _e.label = 4;
138
+ _a = _g.sent(), organization = _a[0], form = _a[1];
139
+ _g.label = 4;
140
140
  case 4:
141
141
  if (organization && !idOrganization)
142
142
  idOrganization = organization.idOrganization;
143
143
  setOrganization(organization);
144
+ countryCode = (_c = (_b = others.countryCode) !== null && _b !== void 0 ? _b : organization === null || organization === void 0 ? void 0 : organization.countryCode) !== null && _c !== void 0 ? _c : 'CO';
144
145
  /** For localhost development */
145
146
  if (!idOrganization && process.env.NODE_ENV !== 'production') {
146
147
  match = location.origin.match(/\/\/(.*?)\./);
@@ -178,15 +179,15 @@ export var useSetupApp = function (isEmbedded, _a) {
178
179
  if (!form || !idOrganization)
179
180
  return [2 /*return*/];
180
181
  dependencies = {};
181
- return [4 /*yield*/, calcValuesStore(idOrganization, form, valuesData, postview, customSteps)];
182
+ return [4 /*yield*/, calcValuesStore({ idOrganization: idOrganization, countryCode: countryCode }, form, valuesData, postview, customSteps)];
182
183
  case 5:
183
- values = _e.sent();
184
+ values = _g.sent();
184
185
  dispatch(reset(__assign(__assign({ formStyle: internal
185
186
  ? InternalFormStyle
186
- : __assign(__assign({}, InternalFormStyle), ((_b = form === null || form === void 0 ? void 0 : form.style) !== null && _b !== void 0 ? _b : {})), confirmation: {
187
- confirmationMessage: (_c = form.confirmationMessage) !== null && _c !== void 0 ? _c : BaseConfirmationMessage,
188
- showLink: (_d = form.showLink) !== null && _d !== void 0 ? _d : false,
189
- }, internal: !!internal, idOrganization: idOrganization, preview: !!preview, partial: !!partial, postview: !!postview, editable: !!(editable !== null && editable !== void 0 ? editable : true), values: values }, calcInitialSections(form)), { dependencies: calcDependencies(form.steps, customSteps, form.steps, dependencies, values) })));
187
+ : __assign(__assign({}, InternalFormStyle), ((_d = form === null || form === void 0 ? void 0 : form.style) !== null && _d !== void 0 ? _d : {})), confirmation: {
188
+ confirmationMessage: (_e = form.confirmationMessage) !== null && _e !== void 0 ? _e : BaseConfirmationMessage,
189
+ showLink: (_f = form.showLink) !== null && _f !== void 0 ? _f : false,
190
+ }, internal: !!internal, idOrganization: idOrganization, preview: !!preview, partial: !!partial, postview: !!postview, editable: !!(editable !== null && editable !== void 0 ? editable : true), values: values }, calcInitialSections(form)), { dependencies: calcDependencies(form.steps, customSteps, form.steps, dependencies, values), countryCode: countryCode })));
190
191
  return [2 /*return*/];
191
192
  }
192
193
  });
@@ -22,11 +22,12 @@ import { convertFromRaw, convertToRaw } from 'draft-js';
22
22
  import FormStepTypes, { EntityValueDataTypes, } from '../constants/FormStepTypes';
23
23
  import { calcStepDeps } from '../FormSteps/StepHooks';
24
24
  import { calcRecursiveData } from '../Utils/FormStepFunctions';
25
+ import { isValidPhoneNumber } from '../Utils/PhoneFunctions';
25
26
  /**
26
27
  * Function that cals the value of a step to output on submit
27
28
  */
28
29
  export var calcValue = function (idStep, steps, values, customSteps, deleteIds, value) {
29
- var _a, _b, _c;
30
+ var _a, _b, _c, _d;
30
31
  if (value === void 0) { value = values[idStep]; }
31
32
  var step = steps[idStep];
32
33
  if (!step)
@@ -37,6 +38,17 @@ export var calcValue = function (idStep, steps, values, customSteps, deleteIds,
37
38
  }
38
39
  else {
39
40
  switch (step.type) {
41
+ case FormStepTypes.TEXTINPUT: {
42
+ if (step.clientInfoType === 'cel' ||
43
+ ((_c = step.validation) === null || _c === void 0 ? void 0 : _c.type) === 'PHONE') {
44
+ if (isValidPhoneNumber(value))
45
+ return value;
46
+ return '';
47
+ }
48
+ else {
49
+ return value;
50
+ }
51
+ }
40
52
  case FormStepTypes.TEXTAREA: {
41
53
  if (step.hasTextEditor) {
42
54
  var currentContent = value.getCurrentContent();
@@ -63,29 +75,29 @@ export var calcValue = function (idStep, steps, values, customSteps, deleteIds,
63
75
  return value.value;
64
76
  }
65
77
  case FormStepTypes.MAPPER: {
66
- var elements = (_c = value === null || value === void 0 ? void 0 : value.elements) === null || _c === void 0 ? void 0 : _c.filter(function (element) { return element.deleted !== true; });
78
+ var elements = (_d = value === null || value === void 0 ? void 0 : value.elements) === null || _d === void 0 ? void 0 : _d.filter(function (element) { return element.deleted !== true; });
67
79
  var mappedValues = [];
68
80
  for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
69
81
  var element = elements_1[_i];
70
82
  var newValue = {
71
83
  id: element.id,
72
84
  };
73
- for (var _d = 0, _e = Object.keys(element.originalValues); _d < _e.length; _d++) {
74
- var key = _e[_d];
85
+ for (var _e = 0, _f = Object.keys(element.originalValues); _e < _f.length; _e++) {
86
+ var key = _f[_e];
75
87
  newValue[key] = element.originalValues[key];
76
88
  }
77
89
  if (element.value)
78
90
  newValue.value = element.value;
79
91
  var nestedDeleteIds = [];
80
- for (var _f = 0, _g = Object.keys(step.steps); _f < _g.length; _f++) {
81
- var idStep_1 = _g[_f];
92
+ for (var _g = 0, _h = Object.keys(step.steps); _g < _h.length; _g++) {
93
+ var idStep_1 = _h[_g];
82
94
  var mappedId = element.ids[idStep_1];
83
95
  if (values[mappedId] !== undefined) {
84
96
  newValue[idStep_1] = calcValue(idStep_1, step.steps, values, customSteps, nestedDeleteIds, values[mappedId]);
85
97
  }
86
98
  }
87
- for (var _h = 0, nestedDeleteIds_1 = nestedDeleteIds; _h < nestedDeleteIds_1.length; _h++) {
88
- var idStep_2 = nestedDeleteIds_1[_h];
99
+ for (var _j = 0, nestedDeleteIds_1 = nestedDeleteIds; _j < nestedDeleteIds_1.length; _j++) {
100
+ var idStep_2 = nestedDeleteIds_1[_j];
89
101
  delete newValue[idStep_2];
90
102
  }
91
103
  deleteIds.push.apply(deleteIds, nestedDeleteIds);
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { PhoneInputStepProps } from '../PhoneInputStep';
3
+ declare function PhoneInputStep({ step, editable, defaultValue, }: PhoneInputStepProps): JSX.Element;
4
+ export default PhoneInputStep;
@@ -0,0 +1,51 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import styles from './MaterialPhoneInputStep.module.css';
14
+ import { calcStepWidth } from '../../StepFunctions';
15
+ import { useContext } from 'react';
16
+ import FormContext from '../../../Contexts/FormContext';
17
+ import { selectBreakPoint, useAppSelector } from '../../../hooks';
18
+ import { useFormStep } from '../../StepHooks';
19
+ import RoundedPhoneInput from '../../../Shared/RoundedPhoneInput/RoundedPhoneInput';
20
+ import { isEmptyPhoneNumber, isValidPhoneNumber, } from '../../../Utils/PhoneFunctions';
21
+ function PhoneInputStep(_a) {
22
+ var _b;
23
+ var step = _a.step, editable = _a.editable, _c = _a.defaultValue, defaultValue = _c === void 0 ? step.defaultValue : _c;
24
+ var currentBreakPoint = useAppSelector(selectBreakPoint);
25
+ var _d = useAppSelector(function (state) { return state.global; }), formStyle = _d.formStyle, postview = _d.postview;
26
+ var form = useContext(FormContext);
27
+ var _e = useFormStep(step, {
28
+ defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : '',
29
+ debounce: true,
30
+ rules: {
31
+ required: step.required ? 'Este campo es obligatorio' : undefined,
32
+ validate: function (phone) {
33
+ var _a, _b;
34
+ if (isValidPhoneNumber(phone))
35
+ return true;
36
+ if (!step.required && isEmptyPhoneNumber(phone))
37
+ return true;
38
+ return ((_b = (_a = step.validation) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Número de teléfono inválido');
39
+ },
40
+ },
41
+ }), ref = _e.ref, value = _e.value, onChange = _e.onChange, error = _e.error, field = _e.field;
42
+ return (_jsx("div", __assign({ className: styles.container, style: {
43
+ width: currentBreakPoint <= step.size
44
+ ? '100%'
45
+ : calcStepWidth(step.size, form.size),
46
+ minHeight: step.description || (!postview && editable)
47
+ ? '55px'
48
+ : '43px',
49
+ } }, { children: _jsx(RoundedPhoneInput, __assign({}, field, { inputRef: ref, value: value, onChange: onChange, "data-testid": step.id, label: step.label, cantEdit: !editable || postview, required: step.required, fontWeight: 400, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, textColor: formStyle.textColor, errorColor: formStyle.errorColor, backgroundColor: formStyle.stepBackgroundColor, helperText: (_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : step.description, helperTextColor: formStyle.descriptionTextColor, error: !!error })) })));
50
+ }
51
+ export default PhoneInputStep;
@@ -0,0 +1,9 @@
1
+ .container {
2
+ width: fit-content;
3
+ max-width: calc(100% - 20px);
4
+ display: flex;
5
+ padding: 10px;
6
+ padding-bottom: 0px;
7
+ padding-top: 5px;
8
+ margin-bottom: 0px;
9
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { TextInput } from '../../@Types/FormStep';
3
+ import { StepProps } from '../Step';
4
+ export interface PhoneInputStepProps extends StepProps {
5
+ /** The TextInputStep to display */
6
+ step: TextInput;
7
+ /** Default value to display */
8
+ defaultValue?: string;
9
+ }
10
+ declare function PhoneInputStep(props: PhoneInputStepProps): JSX.Element;
11
+ export default PhoneInputStep;
@@ -0,0 +1,25 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { FormStyleTypes } from '../../constants/FormStepTypes';
14
+ import MaterialPhoneInputStep from './MaterialTextInputStep/MaterialPhoneInputStep';
15
+ import { useAppSelector } from '../../hooks';
16
+ function PhoneInputStep(props) {
17
+ var formStyle = useAppSelector(function (state) { return state.global; }).formStyle;
18
+ switch (formStyle.type) {
19
+ case FormStyleTypes.MATERIAL:
20
+ default: {
21
+ return _jsx(MaterialPhoneInputStep, __assign({}, props));
22
+ }
23
+ }
24
+ }
25
+ export default PhoneInputStep;
@@ -44,15 +44,16 @@ import { useContext } from 'react';
44
44
  import CustomContext from '../Contexts/CustomContext';
45
45
  import { selectOriginalValue, useCondition } from './StepHooks';
46
46
  import TimePickerStep from './TimePickerStep/TimePickerStep';
47
+ import PhoneInputStep from './PhoneInputStep/PhoneInputStep';
47
48
  function StepComponent(_a) {
48
- var _b;
49
+ var _b, _c;
49
50
  var step = _a.step, props = __rest(_a, ["step"]);
50
51
  if (!step) {
51
52
  console.error('Step not found!', step);
52
53
  return _jsx("div", {});
53
54
  }
54
- var _c = useAppSelector(function (state) { return state.global; }), postview = _c.postview, partial = _c.partial;
55
- var _d = useContext(CustomContext), customSteps = _d.customSteps, customClientInfoStep = _d.customClientInfoStep;
55
+ var _d = useAppSelector(function (state) { return state.global; }), postview = _d.postview, partial = _d.partial;
56
+ var _e = useContext(CustomContext), customSteps = _e.customSteps, customClientInfoStep = _e.customClientInfoStep;
56
57
  var originalValue = useAppSelector(function (state) {
57
58
  return selectOriginalValue(state, step);
58
59
  });
@@ -92,6 +93,10 @@ function StepComponent(_a) {
92
93
  return (_jsx(TextAreaStep, __assign({}, props, { step: step, editable: editable })));
93
94
  }
94
95
  case FormStepTypes.TEXTINPUT: {
96
+ if (step.clientInfoType === 'cel' ||
97
+ ((_c = step.validation) === null || _c === void 0 ? void 0 : _c.type) === 'PHONE') {
98
+ return (_jsx(PhoneInputStep, __assign({}, props, { step: step, editable: editable })));
99
+ }
95
100
  return (_jsx(TextInputStep, __assign({}, props, { step: step, editable: editable })));
96
101
  }
97
102
  case FormStepTypes.DATEPICKER: {
@@ -16,7 +16,7 @@ interface ComponentProps extends StyleProps, Omit<CheckboxProps, 'size' | 'onCha
16
16
  checked: boolean;
17
17
  }
18
18
  /**
19
- * Generic datepicker with apps designs. Is class do to the use in the react-hook-forms library
19
+ * Generic datepicker with apps designs. Is class due to the use in the react-hook-forms library
20
20
  */
21
21
  declare class RoundedCheckBox extends React.Component<ComponentProps> {
22
22
  render(): JSX.Element;
@@ -86,7 +86,7 @@ function CustomCheckBox(_a) {
86
86
  return (_jsx(Checkbox, __assign({}, others, { disabled: cantEdit, classes: classes, checked: checked, onChange: function (event) { return onChange === null || onChange === void 0 ? void 0 : onChange(event.target.checked); }, required: true, icon: _jsx(CheckBoxOutlineBlankRoundedIcon, { fontSize: "inherit" }), checkedIcon: _jsx(CheckBoxRoundedIcon, { fontSize: "inherit" }) })));
87
87
  }
88
88
  /**
89
- * Generic datepicker with apps designs. Is class do to the use in the react-hook-forms library
89
+ * Generic datepicker with apps designs. Is class due to the use in the react-hook-forms library
90
90
  */
91
91
  var RoundedCheckBox = /** @class */ (function (_super) {
92
92
  __extends(RoundedCheckBox, _super);
@@ -41,7 +41,7 @@ interface RoundedDatePickerProps extends Omit<DatePickerProps, 'ref'>, StyleProp
41
41
  ref?: React.RefObject<HTMLDivElement>;
42
42
  }
43
43
  /**
44
- * Generic datepicker with apps designs. Is class do to the use in the react-hook-forms library
44
+ * Generic datepicker with apps designs. Is class due to the use in the react-hook-forms library
45
45
  */
46
46
  declare class RoundedDatePicker extends React.Component<RoundedDatePickerProps> {
47
47
  render(): JSX.Element;
@@ -336,7 +336,7 @@ function CustomDatePicker(_a) {
336
336
  }
337
337
  }
338
338
  /**
339
- * Generic datepicker with apps designs. Is class do to the use in the react-hook-forms library
339
+ * Generic datepicker with apps designs. Is class due to the use in the react-hook-forms library
340
340
  */
341
341
  var RoundedDatePicker = /** @class */ (function (_super) {
342
342
  __extends(RoundedDatePicker, _super);
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { TextFieldProps } from '@material-ui/core/TextField';
3
+ interface StyleProps {
4
+ /** The color of the text */
5
+ textColor?: string;
6
+ /** The color of the outline when selected and hovered on */
7
+ focusColor?: string;
8
+ /** The color of the error to display */
9
+ errorColor?: string;
10
+ /** The color of the outline when it is not selected */
11
+ outlineColor?: string;
12
+ /** The backgroundColor of the input */
13
+ backgroundColor?: string;
14
+ /** The borderRadius of the input */
15
+ borderRadius?: number;
16
+ /** If input is readOnly */
17
+ readOnly?: boolean;
18
+ /** The padding of the input */
19
+ padding?: string;
20
+ /** The size of the font to display the input in */
21
+ fontSize?: number | string;
22
+ /** The weight of the font of the value and the placeholder */
23
+ fontWeight?: number | string;
24
+ /** Cant edit */
25
+ cantEdit?: boolean;
26
+ /** The color of the helper text when not error */
27
+ helperTextColor?: string;
28
+ /** The max length of the string */
29
+ maxLength?: number;
30
+ }
31
+ interface RoundedPhoneInputProps extends StyleProps {
32
+ /** The value of the phoneinput */
33
+ value?: string;
34
+ onChange: (value: string) => void;
35
+ inputRef?: any;
36
+ }
37
+ /**
38
+ * Generic phoneinput with apps designs. Is class due to the use in the react-hook-forms library
39
+ */
40
+ declare class RoundedPhoneInput extends React.Component<RoundedPhoneInputProps & Omit<TextFieldProps, 'onChange'>> {
41
+ render(): JSX.Element;
42
+ }
43
+ export default RoundedPhoneInput;
@@ -0,0 +1,226 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ var __rest = (this && this.__rest) || function (s, e) {
28
+ var t = {};
29
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
+ t[p] = s[p];
31
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
+ t[p[i]] = s[p[i]];
35
+ }
36
+ return t;
37
+ };
38
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
39
+ import React, { useMemo } from 'react';
40
+ import { makeStyles } from '@material-ui/core/styles';
41
+ import TextField from '@material-ui/core/TextField';
42
+ import { InputAdornment, MenuItem, Select } from '@material-ui/core';
43
+ import parse from 'libphonenumber-js/max';
44
+ import { defaultCountries, FlagImage, parseCountry, usePhoneInput, } from 'react-international-phone';
45
+ import { useAppSelector } from '../../hooks';
46
+ import isoCountries from 'i18n-iso-countries';
47
+ import es from 'i18n-iso-countries/langs/es.json';
48
+ isoCountries.registerLocale(es);
49
+ var useTextfieldStyles = function (props) {
50
+ return makeStyles(function () { return ({
51
+ root: {
52
+ borderRadius: props.borderRadius,
53
+ '& input': {
54
+ cursor: props.cantEdit ? 'default' : 'text',
55
+ padding: props.padding,
56
+ fontWeight: props.fontWeight,
57
+ color: props.textColor,
58
+ fontSize: props.fontSize,
59
+ '&::placeholder': {
60
+ fontSize: props.fontSize,
61
+ },
62
+ backgroundColor: props.backgroundColor,
63
+ borderRadius: props.borderRadius,
64
+ },
65
+ '& label': {
66
+ marginTop: '-4px',
67
+ fontSize: props.fontSize,
68
+ color: props.textColor + '8a',
69
+ whiteSpace: 'nowrap',
70
+ overflow: 'hidden',
71
+ textOverflow: 'ellipsis',
72
+ maxWidth: 'calc(100% - 22px)',
73
+ },
74
+ '& label.EF-MuiInputLabel-shrink': {
75
+ marginTop: '0px',
76
+ maxWidth: 'calc(100% - 5px)',
77
+ },
78
+ '& input + fieldset': {
79
+ borderRadius: props.borderRadius,
80
+ },
81
+ '& .EF-MuiInput-underline:after': {
82
+ borderBottomColor: props.outlineColor,
83
+ },
84
+ '& .EF-MuiOutlinedInput-root': {
85
+ borderRadius: props.borderRadius,
86
+ '&.Mui-focused fieldset': {
87
+ borderColor: props.focusColor,
88
+ borderWidth: props.readOnly ? 1 : 2,
89
+ },
90
+ '& .EF-MuiOutlinedInput-notchedOutline': {
91
+ borderColor: props.outlineColor,
92
+ '& legend': {
93
+ fontSize: 'calc(' + props.fontSize + ' * 0.75)',
94
+ },
95
+ },
96
+ },
97
+ '& .EF-MuiOutlinedInput-root:hover .EF-MuiOutlinedInput-notchedOutline': {
98
+ borderColor: props.cantEdit
99
+ ? props.outlineColor
100
+ : props.focusColor,
101
+ },
102
+ '& label.Mui-focused': {
103
+ color: props.focusColor,
104
+ },
105
+ '& .Mui-error': {
106
+ color: props.errorColor,
107
+ },
108
+ '& .EF-MuiOutlinedInput-adornedEnd': {
109
+ paddingRight: '7px',
110
+ },
111
+ '& .EF-MuiFormHelperText-root': {
112
+ color: props.helperTextColor,
113
+ position: 'relative',
114
+ marginRight: props.maxLength ? 40 : 14,
115
+ },
116
+ '& .EF-MuiFormHelperText-root.Mui-error': {
117
+ color: props.errorColor,
118
+ },
119
+ '& .EF-MuiInputAdornment-root': {
120
+ paddingTop: 2,
121
+ marginRight: 0,
122
+ '& .EF-MuiSelect-select': {
123
+ backgroundColor: props.backgroundColor,
124
+ },
125
+ '& input': {
126
+ padding: 0,
127
+ margin: 0,
128
+ },
129
+ '& .EF-MuiInput-underline:before': {
130
+ borderBottom: 'none !important',
131
+ },
132
+ '& .EF-MuiInput-underline:after': {
133
+ borderBottom: 'none',
134
+ },
135
+ },
136
+ },
137
+ }); });
138
+ };
139
+ var useCountrySelectStyles = makeStyles(function () { return ({
140
+ root: {
141
+ padding: 0,
142
+ input: {
143
+ padding: 0,
144
+ },
145
+ },
146
+ }); });
147
+ function CustomPhoneInput(_a) {
148
+ var _b = _a.focusColor, focusColor = _b === void 0 ? '#3d5a7f' : _b, _c = _a.helperTextColor, helperTextColor = _c === void 0 ? '#989898' : _c, _d = _a.outlineColor, outlineColor = _d === void 0 ? '#0000003b' : _d, _e = _a.backgroundColor, backgroundColor = _e === void 0 ? 'white' : _e, _f = _a.textColor, textColor = _f === void 0 ? '#293241' : _f, _g = _a.readOnly, readOnly = _g === void 0 ? false : _g, _h = _a.borderRadius, borderRadius = _h === void 0 ? 10 : _h, _j = _a.padding, padding = _j === void 0 ? '6px 12px 6px 6px' : _j, _k = _a.fontSize, fontSize = _k === void 0 ? '1rem' : _k, _l = _a.errorColor, errorColor = _l === void 0 ? '#cc2936' : _l, _m = _a.fontWeight, fontWeight = _m === void 0 ? '300' : _m, _o = _a.cantEdit, cantEdit = _o === void 0 ? false : _o, value = _a.value, onChange = _a.onChange, inputRef = _a.inputRef, others = __rest(_a, ["focusColor", "helperTextColor", "outlineColor", "backgroundColor", "textColor", "readOnly", "borderRadius", "padding", "fontSize", "errorColor", "fontWeight", "cantEdit", "value", "onChange", "inputRef"]);
149
+ var classes = useTextfieldStyles({
150
+ padding: padding,
151
+ textColor: textColor,
152
+ errorColor: errorColor,
153
+ focusColor: focusColor,
154
+ outlineColor: outlineColor,
155
+ helperTextColor: helperTextColor,
156
+ backgroundColor: backgroundColor,
157
+ borderRadius: borderRadius,
158
+ readOnly: readOnly,
159
+ fontSize: fontSize,
160
+ fontWeight: fontWeight,
161
+ cantEdit: cantEdit,
162
+ })();
163
+ var defaultCountry = useAppSelector(function (state) { return state.global.countryCode; });
164
+ var countrySelectClasses = useCountrySelectStyles();
165
+ var _p = usePhoneInput({
166
+ value: '+' + value,
167
+ inputRef: inputRef,
168
+ defaultCountry: defaultCountry.toLowerCase(),
169
+ disableDialCodePrefill: true,
170
+ disableDialCodeAndPrefix: true,
171
+ onChange: function (data) { return onChange(data.phone.replace('+', '')); },
172
+ }), inputValue = _p.inputValue, handlePhoneValueChange = _p.handlePhoneValueChange, phoneRef = _p.inputRef, country = _p.country, setCountry = _p.setCountry;
173
+ var countries = useMemo(function () {
174
+ return defaultCountries
175
+ .map(function (c) {
176
+ var _a;
177
+ var country = parseCountry(c);
178
+ return {
179
+ country: country,
180
+ name: (_a = isoCountries.getName(country.iso2.toUpperCase(), 'es')) !== null && _a !== void 0 ? _a : country.name,
181
+ };
182
+ })
183
+ .sort(function (a, b) { return a.name.localeCompare(b.name); });
184
+ }, []);
185
+ return (_jsx(TextField, __assign({ classes: classes }, others, { variant: "outlined", size: "small", fullWidth: true, value: inputValue, onChange: handlePhoneValueChange, type: "tel", onPaste: function (e) {
186
+ var value = e.clipboardData.getData('Text');
187
+ if (!value.startsWith('+')) {
188
+ var phone = parse('+' + value);
189
+ if (phone === null || phone === void 0 ? void 0 : phone.isValid()) {
190
+ e.preventDefault();
191
+ if (phone.country)
192
+ setCountry(phone.country.toLowerCase());
193
+ onChange(phone.number);
194
+ }
195
+ }
196
+ }, inputRef: phoneRef, InputProps: {
197
+ readOnly: readOnly,
198
+ autoComplete: 'tel',
199
+ disabled: cantEdit,
200
+ startAdornment: (_jsx(InputAdornment, __assign({ position: "start", style: {
201
+ borderBottom: 'none',
202
+ } }, { children: _jsx(Select, __assign({ classes: countrySelectClasses, value: country.iso2, onChange: function (e) {
203
+ return setCountry(e.target.value);
204
+ }, renderValue: function (value) { return (_jsx(FlagImage, { iso2: value, style: { display: 'flex' }, width: 20 })); } }, { children: countries.map(function (_a) {
205
+ var country = _a.country, name = _a.name;
206
+ return (_jsxs(MenuItem, __assign({ value: country.iso2 }, { children: [_jsx(FlagImage, { iso2: country.iso2, size: 20 }), _jsx("span", __assign({ style: {
207
+ marginLeft: '8px',
208
+ marginRight: '8px',
209
+ } }, { children: name })), _jsxs("span", __assign({ style: { color: 'grey' } }, { children: ["+", country.dialCode] }))] }), country.iso2));
210
+ }) })) }))),
211
+ } })));
212
+ }
213
+ /**
214
+ * Generic phoneinput with apps designs. Is class due to the use in the react-hook-forms library
215
+ */
216
+ var RoundedPhoneInput = /** @class */ (function (_super) {
217
+ __extends(RoundedPhoneInput, _super);
218
+ function RoundedPhoneInput() {
219
+ return _super !== null && _super.apply(this, arguments) || this;
220
+ }
221
+ RoundedPhoneInput.prototype.render = function () {
222
+ return _jsx(CustomPhoneInput, __assign({}, this.props));
223
+ };
224
+ return RoundedPhoneInput;
225
+ }(React.Component));
226
+ export default RoundedPhoneInput;
@@ -60,7 +60,7 @@ interface RoundedSelectProps extends Omit<SelectProps, 'color'>, SelectorStylePr
60
60
  ref?: any;
61
61
  }
62
62
  /**
63
- * Generic textfield with apps designs. Is class do to the use in the react-hook-forms library
63
+ * Generic textfield with apps designs. Is class due to the use in the react-hook-forms library
64
64
  */
65
65
  declare class RoundedSelect extends React.Component<RoundedSelectProps> {
66
66
  render(): JSX.Element;
@@ -199,7 +199,7 @@ function CustomSelect(_a) {
199
199
  }, input: _jsx(OutlinedInput, { disabled: cantEdit, name: label, label: label ? label + (required ? ' *' : '') : undefined, classes: outlinedInputClasses }) }, { children: children })), helperText !== undefined && (_jsx(FormHelperText, __assign({ classes: helperTextClasses }, { children: helperText })))] })));
200
200
  }
201
201
  /**
202
- * Generic textfield with apps designs. Is class do to the use in the react-hook-forms library
202
+ * Generic textfield with apps designs. Is class due to the use in the react-hook-forms library
203
203
  */
204
204
  var RoundedSelect = /** @class */ (function (_super) {
205
205
  __extends(RoundedSelect, _super);
@@ -37,7 +37,7 @@ interface RoundedTextFieldProps extends StyleProps {
37
37
  value?: string;
38
38
  }
39
39
  /**
40
- * Generic textfield with apps designs. Is class do to the use in the react-hook-forms library
40
+ * Generic textfield with apps designs. Is class due to the use in the react-hook-forms library
41
41
  */
42
42
  declare class RoundedTextField extends React.Component<RoundedTextFieldProps & TextFieldProps> {
43
43
  render(): JSX.Element;
@@ -160,7 +160,7 @@ function CustomTextfield(_a) {
160
160
  } }, { children: [length, "/", maxLength] })))] })));
161
161
  }
162
162
  /**
163
- * Generic textfield with apps designs. Is class do to the use in the react-hook-forms library
163
+ * Generic textfield with apps designs. Is class due to the use in the react-hook-forms library
164
164
  */
165
165
  var RoundedTextField = /** @class */ (function (_super) {
166
166
  __extends(RoundedTextField, _super);
@@ -33,7 +33,7 @@ interface RoundedTimePickerProps extends Omit<SelectProps, 'color' | 'onChange'>
33
33
  working?: boolean;
34
34
  }
35
35
  /**
36
- * Generic textfield with apps designs. Is class do to the use in the react-hook-forms library
36
+ * Generic textfield with apps designs. Is class due to the use in the react-hook-forms library
37
37
  */
38
38
  declare class RoundedTimePicker extends React.Component<RoundedTimePickerProps> {
39
39
  render(): JSX.Element;
@@ -278,7 +278,7 @@ function CustomSelect(_a) {
278
278
  } }, { children: _jsx(MenuItem, { value: 0 }) })), helperText !== undefined && (_jsx(FormHelperText, __assign({ classes: helperTextClasses }, { children: helperText })))] }))] }));
279
279
  }
280
280
  /**
281
- * Generic textfield with apps designs. Is class do to the use in the react-hook-forms library
281
+ * Generic textfield with apps designs. Is class due to the use in the react-hook-forms library
282
282
  */
283
283
  var RoundedTimePicker = /** @class */ (function (_super) {
284
284
  __extends(RoundedTimePicker, _super);
@@ -2,8 +2,10 @@ import { FormStyle } from '../@Types/Form';
2
2
  import type { PayloadAction } from '@reduxjs/toolkit';
3
3
  import { SiteState } from './SiteSlice';
4
4
  import { EurekaDraft } from '../@Types/Draft/Draft';
5
+ import { CountryCode } from 'libphonenumber-js';
5
6
  export interface GlobalState {
6
7
  idOrganization: string;
8
+ countryCode: CountryCode;
7
9
  formStyle: FormStyle;
8
10
  confirmation: {
9
11
  confirmationMessage: EurekaDraft;
@@ -26,6 +28,7 @@ export declare const GlobalSlice: import("@reduxjs/toolkit").Slice<GlobalState,
26
28
  formStyle: FormStyle;
27
29
  preview: boolean;
28
30
  idOrganization: string;
31
+ countryCode: CountryCode;
29
32
  confirmation: {
30
33
  confirmationMessage: EurekaDraft;
31
34
  showLink: boolean;
@@ -14,6 +14,7 @@ import { createSlice } from '@reduxjs/toolkit';
14
14
  import { BaseConfirmationMessage } from '../Contexts/FormContext';
15
15
  var initialState = {
16
16
  idOrganization: '',
17
+ countryCode: 'CO',
17
18
  formStyle: InternalFormStyle,
18
19
  confirmation: {
19
20
  confirmationMessage: BaseConfirmationMessage,
@@ -0,0 +1,2 @@
1
+ export declare function isValidPhoneNumber(phone: string): boolean;
2
+ export declare function isEmptyPhoneNumber(phone: string): boolean;
@@ -0,0 +1,26 @@
1
+ import * as libphonenumber from 'libphonenumber-js/max';
2
+ import { guessCountryByPartialPhoneNumber, removeDialCode, } from 'react-international-phone';
3
+ export function isValidPhoneNumber(phone) {
4
+ if (!phone.startsWith('+'))
5
+ phone = '+' + phone;
6
+ return libphonenumber.isValidPhoneNumber(phone);
7
+ }
8
+ export function isEmptyPhoneNumber(phone) {
9
+ if (!phone.startsWith('+'))
10
+ phone = '+' + phone;
11
+ var country = guessCountryByPartialPhoneNumber({
12
+ phone: phone,
13
+ }).country;
14
+ if (country &&
15
+ !removeDialCode({
16
+ phone: phone,
17
+ dialCode: country === null || country === void 0 ? void 0 : country.dialCode,
18
+ })) {
19
+ return true;
20
+ }
21
+ if (!country) {
22
+ console.error('Country not found for phone number:', phone);
23
+ return true;
24
+ }
25
+ return false;
26
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arquimedes.co/eureka-forms",
3
3
  "repository": "git://github.com/Arquimede5/Eureka-Forms.git",
4
- "version": "2.0.96",
4
+ "version": "2.0.98",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",
@@ -24,11 +24,14 @@
24
24
  "axios": "^1.6.3",
25
25
  "date-fns": "^2.23.0",
26
26
  "draft-js": "^0.11.7",
27
+ "i18n-iso-countries": "^7.11.3",
28
+ "libphonenumber-js": "^1.11.7",
27
29
  "logrocket": "^2.2.1",
28
30
  "nanoid": "^3.3.7",
29
31
  "react-draft-wysiwyg": "^1.15.0",
30
32
  "react-google-recaptcha": "^3.1.0",
31
33
  "react-hook-form": "^7.48.2",
34
+ "react-international-phone": "^4.3.0",
32
35
  "react-redux": "^8.1.3",
33
36
  "typescript": "^4.9.5"
34
37
  },