@bigbinary/neeto-form-frontend 4.4.8 → 4.4.9

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 (90) hide show
  1. package/app/javascript/src/translations/ar.json +10 -1
  2. package/app/javascript/src/translations/bg.json +10 -1
  3. package/app/javascript/src/translations/ca.json +10 -1
  4. package/app/javascript/src/translations/cs.json +10 -1
  5. package/app/javascript/src/translations/da.json +10 -1
  6. package/app/javascript/src/translations/de.json +10 -1
  7. package/app/javascript/src/translations/es-MX.json +10 -1
  8. package/app/javascript/src/translations/es.json +10 -1
  9. package/app/javascript/src/translations/et.json +10 -1
  10. package/app/javascript/src/translations/fi.json +10 -1
  11. package/app/javascript/src/translations/fil.json +10 -1
  12. package/app/javascript/src/translations/fr.json +10 -1
  13. package/app/javascript/src/translations/he.json +10 -1
  14. package/app/javascript/src/translations/hi.json +10 -1
  15. package/app/javascript/src/translations/hr.json +10 -1
  16. package/app/javascript/src/translations/hu.json +10 -1
  17. package/app/javascript/src/translations/id.json +10 -1
  18. package/app/javascript/src/translations/it.json +10 -1
  19. package/app/javascript/src/translations/ja.json +10 -1
  20. package/app/javascript/src/translations/ko.json +10 -1
  21. package/app/javascript/src/translations/nl.json +10 -1
  22. package/app/javascript/src/translations/pl.json +10 -1
  23. package/app/javascript/src/translations/pt-BR.json +10 -1
  24. package/app/javascript/src/translations/pt.json +10 -1
  25. package/app/javascript/src/translations/ro.json +10 -1
  26. package/app/javascript/src/translations/ru.json +10 -1
  27. package/app/javascript/src/translations/sk.json +10 -1
  28. package/app/javascript/src/translations/sl.json +10 -1
  29. package/app/javascript/src/translations/sv.json +10 -1
  30. package/app/javascript/src/translations/th.json +10 -1
  31. package/app/javascript/src/translations/tr.json +10 -1
  32. package/app/javascript/src/translations/uk.json +10 -1
  33. package/app/javascript/src/translations/vi.json +10 -1
  34. package/app/javascript/src/translations/zh-CN.json +10 -1
  35. package/app/javascript/src/translations/zh-TW.json +10 -1
  36. package/package.json +1 -1
  37. package/dist/BuildForm.js +0 -3077
  38. package/dist/BuildForm.js.map +0 -1
  39. package/dist/ExternalForm.js +0 -647
  40. package/dist/ExternalForm.js.map +0 -1
  41. package/dist/NeetoFormProvider.js +0 -11
  42. package/dist/NeetoFormProvider.js.map +0 -1
  43. package/dist/Submission.js +0 -2832
  44. package/dist/Submission.js.map +0 -1
  45. package/dist/UrlBuilder.js +0 -317
  46. package/dist/UrlBuilder.js.map +0 -1
  47. package/dist/buildForm-CrOWLvLE.js +0 -35
  48. package/dist/buildForm-CrOWLvLE.js.map +0 -1
  49. package/dist/buildForm-DfMpfuSp.js +0 -38
  50. package/dist/buildForm-DfMpfuSp.js.map +0 -1
  51. package/dist/cjs/BuildForm.js +0 -3098
  52. package/dist/cjs/BuildForm.js.map +0 -1
  53. package/dist/cjs/ExternalForm.js +0 -649
  54. package/dist/cjs/ExternalForm.js.map +0 -1
  55. package/dist/cjs/NeetoFormProvider.js +0 -13
  56. package/dist/cjs/NeetoFormProvider.js.map +0 -1
  57. package/dist/cjs/Submission.js +0 -2834
  58. package/dist/cjs/Submission.js.map +0 -1
  59. package/dist/cjs/UrlBuilder.js +0 -319
  60. package/dist/cjs/UrlBuilder.js.map +0 -1
  61. package/dist/cjs/hooks.js +0 -33
  62. package/dist/cjs/hooks.js.map +0 -1
  63. package/dist/cjs/index.js +0 -113
  64. package/dist/cjs/index.js.map +0 -1
  65. package/dist/constants-Cj0XxE8a.js +0 -494
  66. package/dist/constants-Cj0XxE8a.js.map +0 -1
  67. package/dist/constants-D5JlvWws.js +0 -513
  68. package/dist/constants-D5JlvWws.js.map +0 -1
  69. package/dist/hooks.js +0 -20
  70. package/dist/hooks.js.map +0 -1
  71. package/dist/index-Beo6ztaM.js +0 -51
  72. package/dist/index-Beo6ztaM.js.map +0 -1
  73. package/dist/index-DhtQJpD_.js +0 -43
  74. package/dist/index-DhtQJpD_.js.map +0 -1
  75. package/dist/index.js +0 -95
  76. package/dist/index.js.map +0 -1
  77. package/dist/main.css +0 -2
  78. package/dist/main.css.map +0 -1
  79. package/dist/useFormSubmission-D3O7sDHp.js +0 -24
  80. package/dist/useFormSubmission-D3O7sDHp.js.map +0 -1
  81. package/dist/useFormSubmission-PLRMfzJ3.js +0 -22
  82. package/dist/useFormSubmission-PLRMfzJ3.js.map +0 -1
  83. package/dist/utils-CI844li1.js +0 -2718
  84. package/dist/utils-CI844li1.js.map +0 -1
  85. package/dist/utils-baAzU7l8.js +0 -2749
  86. package/dist/utils-baAzU7l8.js.map +0 -1
  87. package/dist/yup-CSYHMEsr.js +0 -1014
  88. package/dist/yup-CSYHMEsr.js.map +0 -1
  89. package/dist/yup-DMlViLLB.js +0 -1097
  90. package/dist/yup-DMlViLLB.js.map +0 -1
@@ -1,2749 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
- var formik = require('formik');
5
- var neetoCist = require('@bigbinary/neeto-cist');
6
- var index = require('./index-Beo6ztaM.js');
7
- var utils = require('@bigbinary/neeto-commons-frontend/utils');
8
- var libphonenumberJs = require('libphonenumber-js');
9
- var ramda = require('ramda');
10
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
11
- var EditorContent = require('@bigbinary/neeto-editor/EditorContent');
12
- var constants = require('./constants-D5JlvWws.js');
13
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
14
- var Plus = require('@bigbinary/neeto-icons/Plus');
15
- var Button = require('@bigbinary/neetoui/Button');
16
- var NeetoUIMultiEmailInput = require('@bigbinary/neetoui/MultiEmailInput');
17
- var reactI18next = require('react-i18next');
18
- var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
19
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
20
- var _regeneratorRuntime = require('@babel/runtime/regenerator');
21
- var utils$1 = require('@bigbinary/neeto-editor/utils');
22
- var PhoneNumber = require('@bigbinary/neeto-molecules/PhoneNumber');
23
- var i18next = require('i18next');
24
- var jsxRuntime = require('react/jsx-runtime');
25
- var yup = require('./yup-DMlViLLB.js');
26
- var _toArray = require('@babel/runtime/helpers/toArray');
27
- var yup$1 = require('yup');
28
- var classnames = require('classnames');
29
- var Select = require('@bigbinary/neetoui/Select');
30
- var Input = require('@bigbinary/neetoui/Input');
31
- var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
32
- var Refresh = require('@bigbinary/neeto-icons/Refresh');
33
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
34
- var initializers = require('@bigbinary/neeto-commons-frontend/initializers');
35
- var ReCAPTCHA = require('react-google-recaptcha');
36
- var Checkbox = require('@bigbinary/neetoui/Checkbox');
37
- var DatePicker = require('@bigbinary/neetoui/DatePicker');
38
- var Toastr = require('@bigbinary/neetoui/Toastr');
39
- var reactQuery = require('@tanstack/react-query');
40
- var axios = require('axios');
41
- var CheckCircle = require('@bigbinary/neeto-icons/CheckCircle');
42
- var Spinner = require('@bigbinary/neetoui/Spinner');
43
- var NeetoUICallout = require('@bigbinary/neetoui/Callout');
44
- var FileUpload = require('@bigbinary/neeto-molecules/FileUpload');
45
- var Label = require('@bigbinary/neetoui/Label');
46
- var Radio = require('@bigbinary/neetoui/Radio');
47
- var Image = require('@bigbinary/neeto-icons/Image');
48
- var NeetoEditor = require('@bigbinary/neeto-editor/Editor');
49
- var Info = require('@bigbinary/neeto-icons/Info');
50
- var Textarea = require('@bigbinary/neetoui/Textarea');
51
- var Tag = require('@bigbinary/neetoui/Tag');
52
-
53
- function _interopNamespaceDefault(e) {
54
- var n = Object.create(null);
55
- if (e) {
56
- Object.keys(e).forEach(function (k) {
57
- if (k !== 'default') {
58
- var d = Object.getOwnPropertyDescriptor(e, k);
59
- Object.defineProperty(n, k, d.get ? d : {
60
- enumerable: true,
61
- get: function () { return e[k]; }
62
- });
63
- }
64
- });
65
- }
66
- n.default = e;
67
- return Object.freeze(n);
68
- }
69
-
70
- var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup$1);
71
-
72
- var clientI18nInstance = i18next.cloneInstance();
73
-
74
- var clearLocalStorageValues = function clearLocalStorageValues(key) {
75
- try {
76
- localStorage.removeItem(key);
77
- } catch (error) {
78
- // eslint-disable-next-line no-console
79
- console.error(error);
80
- }
81
- };
82
- var setWithExpiry = function setWithExpiry(key, value) {
83
- var expireInDays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
84
- var expiryDate = utils.dayjs().add(expireInDays, "day").toDate();
85
- var item = {
86
- value: value,
87
- localStorageExpiry: expiryDate.getTime()
88
- };
89
- try {
90
- localStorage.setItem(key, JSON.stringify(item));
91
- } catch (error) {
92
- // eslint-disable-next-line no-console
93
- console.error(error);
94
- }
95
- };
96
- var getWithExpiry = function getWithExpiry(key) {
97
- try {
98
- var itemStr = localStorage.getItem(key);
99
- if (!itemStr) {
100
- return null;
101
- }
102
- var item = JSON.parse(itemStr);
103
- var now = new Date();
104
- if (now.getTime() > item.localStorageExpiry) {
105
- localStorage.removeItem(key);
106
- return null;
107
- }
108
- return item.value;
109
- } catch (error) {
110
- // eslint-disable-next-line no-console
111
- console.error(error);
112
- return null;
113
- }
114
- };
115
-
116
- var FormikWrap = function FormikWrap(_ref) {
117
- var onError = _ref.onError,
118
- children = _ref.children,
119
- formId = _ref.formId,
120
- preserveValues = _ref.preserveValues,
121
- onValuesChange = _ref.onValuesChange,
122
- dataUpdateCount = _ref.dataUpdateCount;
123
- var _useFormikContext = formik.useFormikContext(),
124
- errors = _useFormikContext.errors,
125
- touched = _useFormikContext.touched,
126
- isValid = _useFormikContext.isValid,
127
- isSubmitting = _useFormikContext.isSubmitting,
128
- values = _useFormikContext.values,
129
- validateForm = _useFormikContext.validateForm;
130
- var revalidate = function revalidate() {
131
- return neetoCist.isPresent(errors) && validateForm();
132
- };
133
- React.useEffect(function () {
134
- revalidate();
135
- }, [clientI18nInstance.language, dataUpdateCount]);
136
- var syncValuesWithLocalStorage = function syncValuesWithLocalStorage() {
137
- return preserveValues && !index.isEmptyValues(values) && setWithExpiry("".concat(formId, "/values"), values);
138
- };
139
- React.useEffect(function () {
140
- syncValuesWithLocalStorage();
141
- onValuesChange && onValuesChange(values);
142
- }, [values, formId, preserveValues]);
143
- React.useEffect(function () {
144
- if (isSubmitting || isValid) return;
145
-
146
- // include only touched fields
147
- var touchedErrors = Object.keys(errors).filter(function (key) {
148
- return touched[key];
149
- }).reduce(function (obj, key) {
150
- obj[key] = errors[key];
151
- return obj;
152
- }, {});
153
- if (index.isFunction(onError)) onError(touchedErrors);
154
- }, [isValid, isSubmitting]);
155
- return children;
156
- };
157
-
158
- var RESEND_DELAY = 120;
159
- var ONE_SECOND = 1000;
160
- var EMAIL_VERIFICATION_FIELD_NAME_PREFIX = "verificationCode";
161
- var EMAIL_VERIFICATION_PREFIX = "neeto_form_nano_email_verification_details_";
162
- var EMAIL_VERIFICATION_KEYS = {
163
- EMAIL: "email",
164
- TOKEN: "token",
165
- VERIFIED: "verified",
166
- CODE: "code",
167
- CODE_SENT_AT: "code-sent-at"
168
- };
169
- var CALLOUT_STYLES = {
170
- WARNING: "warning",
171
- ERROR: "danger"
172
- };
173
- var DEFAULT_CALLOUT_DETAILS = {
174
- message: "",
175
- style: ""
176
- };
177
-
178
- var getEmailVerificationKey = function getEmailVerificationKey(formId) {
179
- return "".concat(EMAIL_VERIFICATION_PREFIX, "-").concat(formId);
180
- };
181
- var getEmailVerificationDetails = function getEmailVerificationDetails(formId) {
182
- return utils.getFromLocalStorage(getEmailVerificationKey(formId)) || {};
183
- };
184
- var buildVerificationFieldName = function buildVerificationFieldName(questionId) {
185
- return "".concat(EMAIL_VERIFICATION_FIELD_NAME_PREFIX, "-").concat(questionId);
186
- };
187
- var getLastVerificationCodeSentAt = function getLastVerificationCodeSentAt(formId, questionId) {
188
- var codeSentAt = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT);
189
- return Number(codeSentAt) || 0;
190
- };
191
- var storeLastVerificationCodeSentAt = function storeLastVerificationCodeSentAt(formId, questionId) {
192
- var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
193
- return setEmailVerificationDetail(formId, questionId, _defineProperty({}, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT, Date.now() - offset));
194
- };
195
- var getRemainingTime = function getRemainingTime(formId, questionId) {
196
- var elapsedTime = Math.floor((Date.now() - getLastVerificationCodeSentAt(formId, questionId)) / ONE_SECOND);
197
- return ramda.max(RESEND_DELAY - elapsedTime, 0);
198
- };
199
- var getEmailVerificationDetail = function getEmailVerificationDetail(formId, questionId) {
200
- var _questionDetails$keys;
201
- var allDetails = getEmailVerificationDetails(formId);
202
- var questionDetails = allDetails[questionId] || {};
203
- for (var _len = arguments.length, keys = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
204
- keys[_key - 2] = arguments[_key];
205
- }
206
- return keys.length === 1 ? (_questionDetails$keys = questionDetails[keys[0]]) !== null && _questionDetails$keys !== void 0 ? _questionDetails$keys : "" : ramda.pick(keys, allDetails);
207
- };
208
- var setEmailVerificationDetail = function setEmailVerificationDetail(formId, questionId, data) {
209
- var storageKey = getEmailVerificationKey(formId);
210
- var allDetails = getEmailVerificationDetails(formId);
211
- allDetails[questionId] = ramda.mergeRight(allDetails[questionId] || {}, data);
212
- utils.setToLocalStorage(storageKey, allDetails);
213
- };
214
- var removeEmailVerificationDetail = function removeEmailVerificationDetail(formId, questionId) {
215
- var storageKey = getEmailVerificationKey(formId);
216
- var allDetails = getEmailVerificationDetails(formId);
217
- for (var _len2 = arguments.length, keys = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
218
- keys[_key2 - 2] = arguments[_key2];
219
- }
220
- allDetails[questionId] = ramda.omit(keys, allDetails[questionId]);
221
- if (ramda.isEmpty(allDetails[questionId])) delete allDetails[questionId];
222
- ramda.isEmpty(allDetails) ? utils.removeFromLocalStorage(storageKey) : utils.setToLocalStorage(storageKey, allDetails);
223
- };
224
- var clearEmailVerificationDetails = function clearEmailVerificationDetails(formId) {
225
- utils.removeFromLocalStorage(getEmailVerificationKey(formId));
226
- };
227
-
228
- var t$1 = clientI18nInstance.t;
229
- var getInvalidFieldError = function getInvalidFieldError(label) {
230
- return t$1("neetoForm.error.invalidField", {
231
- label: label
232
- });
233
- };
234
- var getRequiredFieldError = function getRequiredFieldError(label) {
235
- return t$1("neetoForm.error.requiredField", {
236
- label: label
237
- });
238
- };
239
- var getSelectMinError = function getSelectMinError() {
240
- var entity = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : t$1("neetoForm.common.option");
241
- return t$1("neetoForm.error.minOneEntity", {
242
- entity: entity
243
- });
244
- };
245
- var getInvalidTypeError = function getInvalidTypeError(label, type) {
246
- return t$1("neetoForm.error.invalidType", {
247
- label: label,
248
- type: type
249
- });
250
- };
251
-
252
- function ownKeys$i(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
253
- function _objectSpread$i(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$i(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$i(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
254
- var resolveQueryParamValue = ramda.when(ramda.is(Array), ramda.last);
255
- var toEmailValues = function toEmailValues() {
256
- var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
257
- return values.map(function (value) {
258
- return {
259
- label: value,
260
- value: value,
261
- valid: true
262
- };
263
- });
264
- };
265
- var getPhoneNumberFromUrl = function getPhoneNumberFromUrl(fieldCodes, fieldCode) {
266
- var _resolveQueryParamVal;
267
- var countryCode = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".country")]);
268
- var phoneNumber = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".number")]);
269
- var phoneNumberWithCountryCode = (_resolveQueryParamVal = resolveQueryParamValue(fieldCodes[fieldCode])) === null || _resolveQueryParamVal === void 0 ? void 0 : _resolveQueryParamVal.replace(yup.PARENTHESES_REGEX, "");
270
- if (phoneNumberWithCountryCode) return phoneNumberWithCountryCode;
271
- if (!countryCode || !phoneNumber) return undefined;
272
- var formattedValue = getPhoneData(phoneNumber, countryCode);
273
- if (!formattedValue) return undefined;
274
- return formattedValue.formatInternational();
275
- };
276
- var getOptionFromURL = function getOptionFromURL(_ref) {
277
- var _findBy;
278
- var optionsAttributes = _ref.optionsAttributes,
279
- fieldCodes = _ref.fieldCodes,
280
- fieldCode = _ref.fieldCode;
281
- var preFillOption = resolveQueryParamValue(fieldCodes[fieldCode]);
282
- return (_findBy = neetoCist.findBy({
283
- label: preFillOption
284
- }, optionsAttributes)) === null || _findBy === void 0 ? void 0 : _findBy.id;
285
- };
286
- var getMultipleOptionsFromURL = function getMultipleOptionsFromURL(_ref2) {
287
- var optionsAttributes = _ref2.optionsAttributes,
288
- fieldCodes = _ref2.fieldCodes,
289
- fieldCode = _ref2.fieldCode;
290
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
291
- if (!fieldCodeValue) return new Array(optionsAttributes.length).fill(false);
292
- var allOptions = fieldCodeValue.split(",").map(ramda.trim);
293
- return optionsAttributes.map(function (option) {
294
- return allOptions.includes(option.label);
295
- });
296
- };
297
- var getStarRatingOrOpinionScaleFromUrl = function getStarRatingOrOpinionScaleFromUrl(_ref3) {
298
- var minValue = _ref3.minValue,
299
- maxValue = _ref3.maxValue,
300
- fieldCodes = _ref3.fieldCodes,
301
- fieldCode = _ref3.fieldCode;
302
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
303
- var rating = parseInt(fieldCodeValue);
304
- return ramda.isNil(rating) || isNaN(rating) ? "" : ramda.clamp(minValue, maxValue, rating);
305
- };
306
- var getAdditionalGuestsFromUrl = function getAdditionalGuestsFromUrl(_ref4) {
307
- var fieldCodes = _ref4.fieldCodes,
308
- fieldCode = _ref4.fieldCode;
309
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
310
- var allEmails = fieldCodeValue === null || fieldCodeValue === void 0 ? void 0 : fieldCodeValue.split(",");
311
- if (!allEmails) return [];
312
- return allEmails.map(function (email) {
313
- return {
314
- label: email.trim(),
315
- value: email.trim(),
316
- valid: yup.EMAIL_REGEX.test(email.trim())
317
- };
318
- });
319
- };
320
- var getRatingFromUrl = function getRatingFromUrl(_ref5) {
321
- var fieldCodes = _ref5.fieldCodes,
322
- fieldCode = _ref5.fieldCode;
323
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
324
- var allowedValues = Object.values(yup.RATING_VALUES).map(ramda.prop("value"));
325
- return allowedValues.includes(fieldCodeValue) ? fieldCodeValue : "";
326
- };
327
- var getNumberFromUrl = function getNumberFromUrl(_ref6) {
328
- var fieldCodes = _ref6.fieldCodes,
329
- fieldCode = _ref6.fieldCode,
330
- kind = _ref6.kind;
331
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
332
- var parsedValue = kind === yup.QUESTION_KIND.INTEGER.value ? parseInt(fieldCodeValue) : parseFloat(fieldCodeValue);
333
- return parsedValue || "";
334
- };
335
- var getNameFromUrl = function getNameFromUrl(_ref7, fieldCodes) {
336
- var isSplitMode = _ref7.isSplitMode,
337
- fieldCode = _ref7.fieldCode;
338
- var fullName = resolveQueryParamValue(fieldCodes[fieldCode]) || "";
339
- if (!isSplitMode) return {
340
- fullName: fullName
341
- };
342
- var firstName = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".first_name")]) || "";
343
- var lastName = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".last_name")]) || "";
344
- if (neetoCist.isPresent(firstName) || neetoCist.isPresent(lastName)) {
345
- return {
346
- firstName: firstName,
347
- lastName: lastName
348
- };
349
- }
350
- if (neetoCist.isPresent(fullName)) {
351
- var _fullName$trim$split = fullName.trim().split(/\s+/),
352
- _fullName$trim$split2 = _toArray(_fullName$trim$split),
353
- computedFirstName = _fullName$trim$split2[0],
354
- remainingParts = _fullName$trim$split2.slice(1);
355
- return {
356
- firstName: computedFirstName,
357
- lastName: remainingParts.join(" ")
358
- };
359
- }
360
- return {
361
- firstName: firstName,
362
- lastName: lastName
363
- };
364
- };
365
- var isValidSpotValue = function isValidSpotValue(value, remainingSlotsCount) {
366
- var num = Number(value);
367
- if (!Number.isInteger(num) || num <= 0) return false;
368
- return !(typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0 && num > remainingSlotsCount);
369
- };
370
- var buildEmailVerificationEntries = function buildEmailVerificationEntries() {
371
- var questions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
372
- var emailQuestionsRequiringVerification = neetoCist.filterBy({
373
- kind: constants.QUESTION_TYPES.EMAIL,
374
- isVerificationEnabled: true
375
- }, questions);
376
- var fieldNames = ramda.map(function (_ref8) {
377
- var id = _ref8.id;
378
- return buildVerificationFieldName(id);
379
- }, emailQuestionsRequiringVerification);
380
- return ramda.zipObj(fieldNames, Array(fieldNames.length).fill(""));
381
- };
382
- var getLabel = function getLabel(label, isRequired) {
383
- return isRequired ? "".concat(label, "*") : label;
384
- };
385
- var generateInitValues = function generateInitValues(_ref9) {
386
- var questions = _ref9.questions,
387
- _ref9$initialValues = _ref9.initialValues,
388
- initialValues = _ref9$initialValues === void 0 ? [] : _ref9$initialValues,
389
- _ref9$localValues = _ref9.localValues,
390
- localValues = _ref9$localValues === void 0 ? {} : _ref9$localValues,
391
- _ref9$fieldCodes = _ref9.fieldCodes,
392
- fieldCodes = _ref9$fieldCodes === void 0 ? {} : _ref9$fieldCodes,
393
- remainingSlotsCount = _ref9.remainingSlotsCount;
394
- var initValues = {};
395
- var valuesMap = {};
396
- if (initialValues) {
397
- valuesMap = initialValues.reduce(function (acc, answer) {
398
- return _objectSpread$i(_objectSpread$i({}, acc), {}, _defineProperty({}, answer.questionId, {
399
- value: answer.value,
400
- optionIds: answer.optionIds
401
- }));
402
- }, {});
403
- }
404
- questions.forEach(function (question) {
405
- var id = question.id,
406
- kind = question.kind,
407
- optionsAttributes = question.optionsAttributes,
408
- fieldCode = question.fieldCode,
409
- minValue = question.minValue,
410
- maxValue = question.maxValue,
411
- fields = question.fields;
412
- switch (kind) {
413
- case yup.QUESTION_KIND.CONDITION.value:
414
- {
415
- var _valuesMap$id$value, _valuesMap;
416
- initValues[id] = (_valuesMap$id$value = (_valuesMap = valuesMap) === null || _valuesMap === void 0 || (_valuesMap = _valuesMap[id]) === null || _valuesMap === void 0 ? void 0 : _valuesMap.value) !== null && _valuesMap$id$value !== void 0 ? _valuesMap$id$value : false;
417
- return;
418
- }
419
- case yup.QUESTION_KIND.ADDITIONAL_GUESTS.value:
420
- {
421
- var _valuesMap2;
422
- var emailsFromSubmission = toEmailValues((_valuesMap2 = valuesMap) === null || _valuesMap2 === void 0 || (_valuesMap2 = _valuesMap2[id]) === null || _valuesMap2 === void 0 ? void 0 : _valuesMap2.value);
423
- initValues[id] = neetoCist.isNotEmpty(emailsFromSubmission) ? emailsFromSubmission : getAdditionalGuestsFromUrl({
424
- fieldCodes: fieldCodes,
425
- fieldCode: fieldCode
426
- });
427
- return;
428
- }
429
- case yup.QUESTION_KIND.CHECKBOX.value:
430
- {
431
- var _valuesMap$id;
432
- initValues[id] = (_valuesMap$id = valuesMap[id]) !== null && _valuesMap$id !== void 0 && (_valuesMap$id = _valuesMap$id.optionIds) !== null && _valuesMap$id !== void 0 && _valuesMap$id.length ? optionsAttributes.map(function (option) {
433
- var _valuesMap$id2;
434
- return (_valuesMap$id2 = valuesMap[id]) === null || _valuesMap$id2 === void 0 || (_valuesMap$id2 = _valuesMap$id2.optionIds) === null || _valuesMap$id2 === void 0 ? void 0 : _valuesMap$id2.includes(option.id);
435
- }) : getMultipleOptionsFromURL({
436
- optionsAttributes: optionsAttributes,
437
- fieldCodes: fieldCodes,
438
- fieldCode: fieldCode
439
- });
440
- return;
441
- }
442
- case yup.QUESTION_KIND.RADIO.value:
443
- case yup.QUESTION_KIND.DROPDOWN.value:
444
- {
445
- var _optionsAttributes$fi;
446
- var optionFromValues = optionsAttributes === null || optionsAttributes === void 0 || (_optionsAttributes$fi = optionsAttributes.find(function (option) {
447
- var _valuesMap$id3;
448
- return (_valuesMap$id3 = valuesMap[id]) === null || _valuesMap$id3 === void 0 || (_valuesMap$id3 = _valuesMap$id3.optionIds) === null || _valuesMap$id3 === void 0 ? void 0 : _valuesMap$id3.includes(option.id);
449
- })) === null || _optionsAttributes$fi === void 0 ? void 0 : _optionsAttributes$fi.id;
450
- var optionFromUrl = getOptionFromURL({
451
- optionsAttributes: optionsAttributes,
452
- fieldCodes: fieldCodes,
453
- fieldCode: fieldCode
454
- });
455
- initValues[id] = optionFromValues || optionFromUrl;
456
- return;
457
- }
458
- case yup.QUESTION_KIND.SPOT.value:
459
- {
460
- var _valuesMap$id$value2, _valuesMap3;
461
- var urlValue = getNumberFromUrl({
462
- fieldCodes: fieldCodes,
463
- fieldCode: fieldCode,
464
- kind: yup.QUESTION_KIND.INTEGER.value
465
- });
466
- var candidateValue = (_valuesMap$id$value2 = (_valuesMap3 = valuesMap) === null || _valuesMap3 === void 0 || (_valuesMap3 = _valuesMap3[id]) === null || _valuesMap3 === void 0 ? void 0 : _valuesMap3.value) !== null && _valuesMap$id$value2 !== void 0 ? _valuesMap$id$value2 : urlValue !== "" ? urlValue : yup.SPOT_QUESTION_DEFAULT_VALUE;
467
- initValues[id] = isValidSpotValue(candidateValue, remainingSlotsCount) ? candidateValue : yup.SPOT_QUESTION_DEFAULT_VALUE;
468
- return;
469
- }
470
- case yup.QUESTION_KIND.INTEGER.value:
471
- case yup.QUESTION_KIND.DECIMAL.value:
472
- {
473
- var _valuesMap4;
474
- initValues[id] = ((_valuesMap4 = valuesMap) === null || _valuesMap4 === void 0 || (_valuesMap4 = _valuesMap4[id]) === null || _valuesMap4 === void 0 ? void 0 : _valuesMap4.value) || getNumberFromUrl({
475
- fieldCodes: fieldCodes,
476
- fieldCode: fieldCode,
477
- kind: kind
478
- });
479
- return;
480
- }
481
- case yup.QUESTION_KIND.RATING.value:
482
- {
483
- var _valuesMap5;
484
- initValues[id] = ((_valuesMap5 = valuesMap) === null || _valuesMap5 === void 0 || (_valuesMap5 = _valuesMap5[id]) === null || _valuesMap5 === void 0 ? void 0 : _valuesMap5.value) || getRatingFromUrl({
485
- fieldCodes: fieldCodes,
486
- fieldCode: fieldCode
487
- });
488
- return;
489
- }
490
- case yup.QUESTION_KIND.TERMS.value:
491
- {
492
- initValues[id] = false;
493
- return;
494
- }
495
- case yup.QUESTION_KIND.FILE_UPLOAD.value:
496
- {
497
- var _valuesMap$id$value3, _valuesMap6;
498
- initValues[id] = {
499
- files: (_valuesMap$id$value3 = (_valuesMap6 = valuesMap) === null || _valuesMap6 === void 0 || (_valuesMap6 = _valuesMap6[id]) === null || _valuesMap6 === void 0 ? void 0 : _valuesMap6.value) !== null && _valuesMap$id$value3 !== void 0 ? _valuesMap$id$value3 : []
500
- };
501
- return;
502
- }
503
- case yup.QUESTION_KIND.PHONE.value:
504
- case yup.QUESTION_KIND.SMS_REMINDER.value:
505
- {
506
- var _valuesMap$id$value4, _valuesMap7;
507
- initValues[id] = (_valuesMap$id$value4 = (_valuesMap7 = valuesMap) === null || _valuesMap7 === void 0 || (_valuesMap7 = _valuesMap7[id]) === null || _valuesMap7 === void 0 ? void 0 : _valuesMap7.value) !== null && _valuesMap$id$value4 !== void 0 ? _valuesMap$id$value4 : getPhoneNumberFromUrl(fieldCodes, fieldCode);
508
- return;
509
- }
510
- case yup.QUESTION_KIND.STAR_RATING.value:
511
- case yup.QUESTION_KIND.OPINION_SCALE.value:
512
- {
513
- var _valuesMap$id$value5, _valuesMap8;
514
- initValues[id] = (_valuesMap$id$value5 = (_valuesMap8 = valuesMap) === null || _valuesMap8 === void 0 || (_valuesMap8 = _valuesMap8[id]) === null || _valuesMap8 === void 0 ? void 0 : _valuesMap8.value) !== null && _valuesMap$id$value5 !== void 0 ? _valuesMap$id$value5 : getStarRatingOrOpinionScaleFromUrl({
515
- minValue: minValue,
516
- maxValue: maxValue,
517
- fieldCodes: fieldCodes,
518
- fieldCode: fieldCode
519
- });
520
- return;
521
- }
522
- case yup.QUESTION_KIND.NAME.value:
523
- {
524
- var _valuesMap$id$value6, _valuesMap9;
525
- initValues[id] = (_valuesMap$id$value6 = (_valuesMap9 = valuesMap) === null || _valuesMap9 === void 0 || (_valuesMap9 = _valuesMap9[id]) === null || _valuesMap9 === void 0 ? void 0 : _valuesMap9.value) !== null && _valuesMap$id$value6 !== void 0 ? _valuesMap$id$value6 : getNameFromUrl(question, fieldCodes);
526
- return;
527
- }
528
- case yup.QUESTION_KIND.ADDRESS.value:
529
- {
530
- var _valuesMap$id$value7, _valuesMap10;
531
- initValues[id] = (_valuesMap$id$value7 = (_valuesMap10 = valuesMap) === null || _valuesMap10 === void 0 || (_valuesMap10 = _valuesMap10[id]) === null || _valuesMap10 === void 0 ? void 0 : _valuesMap10.value) !== null && _valuesMap$id$value7 !== void 0 ? _valuesMap$id$value7 : fields.reduce(function (values, field) {
532
- values[field.id] = "";
533
- return values;
534
- }, {});
535
- return;
536
- }
537
- default:
538
- {
539
- var _valuesMap$id$value8, _valuesMap11;
540
- initValues[id] = (_valuesMap$id$value8 = (_valuesMap11 = valuesMap) === null || _valuesMap11 === void 0 || (_valuesMap11 = _valuesMap11[id]) === null || _valuesMap11 === void 0 ? void 0 : _valuesMap11.value) !== null && _valuesMap$id$value8 !== void 0 ? _valuesMap$id$value8 : resolveQueryParamValue(fieldCodes[fieldCode] || "");
541
- return;
542
- }
543
- }
544
- });
545
- var formInitialValues = !index.isEmptyValues(localValues) ? localValues : initValues;
546
- return ramda.mergeLeft(formInitialValues, buildEmailVerificationEntries(questions));
547
- };
548
- var generateFormResponse = function generateFormResponse(response, questions) {
549
- var formResponse = [];
550
- questions.forEach(function (question) {
551
- var id = question.id,
552
- kind = question.kind,
553
- optionsAttributes = question.optionsAttributes;
554
- if (!yup.SCHEMA_LESS_QUESTION_KINDS.includes(kind)) {
555
- var responseValue = response[id];
556
- if (kind === yup.QUESTION_KIND.RADIO.value || kind === yup.QUESTION_KIND.DROPDOWN.value) {
557
- var option = neetoCist.findById(responseValue, optionsAttributes);
558
- if (option) {
559
- formResponse.push({
560
- questionId: id,
561
- questionOptionId: option.id,
562
- value: option.label,
563
- kind: kind
564
- });
565
- }
566
- } else if (kind === yup.QUESTION_KIND.SPOT.value) {
567
- formResponse.push({
568
- questionId: id,
569
- value: responseValue,
570
- kind: kind
571
- });
572
- } else if (kind === yup.QUESTION_KIND.CHECKBOX.value) {
573
- responseValue.forEach(function (isChecked, index) {
574
- if (!isChecked) return;
575
- var option = optionsAttributes[index];
576
- formResponse.push({
577
- questionId: id,
578
- questionOptionId: option.id,
579
- value: option.label,
580
- kind: kind
581
- });
582
- });
583
- } else if (isPhoneNumberField(kind)) {
584
- formResponse.push({
585
- questionId: id,
586
- value: responseValue ? libphonenumberJs.parsePhoneNumber(responseValue).formatInternational() : "",
587
- kind: kind
588
- });
589
- } else if (kind === yup.QUESTION_KIND.ADDITIONAL_GUESTS.value) {
590
- formResponse.push({
591
- questionId: id,
592
- value: responseValue ? ramda.pluck("value", responseValue) : null,
593
- kind: kind
594
- });
595
- } else if (kind === yup.QUESTION_KIND.RICH_TEXT.value) {
596
- formResponse.push({
597
- questionId: id,
598
- value: utils$1.isEditorEmpty(responseValue) ? null : responseValue,
599
- kind: kind
600
- });
601
- } else if (kind === yup.QUESTION_KIND.FILE_UPLOAD.value) {
602
- formResponse.push({
603
- questionId: id,
604
- files: neetoCist.isPresent(responseValue) ? responseValue.files : null,
605
- kind: kind
606
- });
607
- } else if (kind === yup.QUESTION_KIND.DATE.value) {
608
- formResponse.push({
609
- questionId: id,
610
- value: utils.dayjs(responseValue).isValid() ?
611
- // YYYY-MM-DD format is not supported by dateFormat.
612
- // eslint-disable-next-line @bigbinary/neeto/use-standard-date-time-formats
613
- utils.dayjs(responseValue).format("YYYY-MM-DD") : "",
614
- kind: kind
615
- });
616
- } else formResponse.push({
617
- questionId: id,
618
- value: responseValue,
619
- kind: kind
620
- });
621
- }
622
- });
623
- return formResponse;
624
- };
625
- var mergeRefs = function mergeRefs() {
626
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
627
- refs[_key] = arguments[_key];
628
- }
629
- return function (node) {
630
- return refs.forEach(function (ref) {
631
- return typeof ref === "function" ? ref(node) : ref.current = node;
632
- });
633
- };
634
- };
635
- var getError = function getError(meta) {
636
- if (meta.error && meta.touched) {
637
- return typeof meta.error === "string" ? meta.error : "";
638
- }
639
- return "";
640
- };
641
- var buildAutoCompleteAttribute = function buildAutoCompleteAttribute(kind, autoCompleteKinds, formDomProps) {
642
- return (formDomProps === null || formDomProps === void 0 ? void 0 : formDomProps.autoComplete) === "off" && ramda.includes(kind, autoCompleteKinds) ? "on" : undefined;
643
- };
644
- var renderButtonsInOrder = function renderButtonsInOrder(buttonsArray, shouldReverse) {
645
- var orderedButtons = shouldReverse ? buttonsArray.reverse() : buttonsArray;
646
- return ramda.map(ramda.identity, orderedButtons);
647
- };
648
- var getSelectedRating = function getSelectedRating(value) {
649
- var parsedValue = parseInt(value);
650
- return isNaN(parsedValue) ? -1 : parsedValue;
651
- };
652
- var isPhoneNumberField = ramda.includes(ramda.__, [yup.QUESTION_KIND.PHONE.value, yup.QUESTION_KIND.SMS_REMINDER.value]);
653
-
654
- var _excluded$4 = ["kind", "customValidator"];
655
- var _fieldKindValidatorMa;
656
- function ownKeys$h(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
657
- function _objectSpread$h(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$h(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$h(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
658
- var t = clientI18nInstance.t;
659
- var isValidDate = function isValidDate(date) {
660
- return date && utils.dayjs(date).isValid();
661
- };
662
- var extractEmailDomain = function extractEmailDomain(email) {
663
- return email === null || email === void 0 ? void 0 : email.split("@")[1];
664
- };
665
- var isEmailFromWhitelistedDomain = function isEmailFromWhitelistedDomain(email, whitelistedDomains) {
666
- if (ramda.isEmpty(whitelistedDomains)) return true;
667
- var domain = extractEmailDomain(email);
668
- return ramda.includes(domain, whitelistedDomains);
669
- };
670
- var isEmailFromBlacklistedDomain = function isEmailFromBlacklistedDomain(email, blacklistedDomains) {
671
- var domain = extractEmailDomain(email);
672
- return ramda.includes(domain, blacklistedDomains);
673
- };
674
- var validateTextField = function validateTextField(_ref) {
675
- var kind = _ref.kind,
676
- label = _ref.label,
677
- isRequired = _ref.isRequired,
678
- remainingSlotsCount = _ref.remainingSlotsCount;
679
- var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
680
- if (isPhoneNumberField(kind)) {
681
- schema = PhoneNumber.validation(getInvalidFieldError(t("neetoForm.common.phoneNumberValidation")));
682
- }
683
- var requiredError = kind === yup.QUESTION_KIND.SPOT.value ? t("neetoForm.questions.spot.numberOfSpotsRequired") : getRequiredFieldError(label);
684
- if (isRequired) schema = schema.trim().required(requiredError);
685
- if (kind === yup.QUESTION_KIND.SPOT.value) {
686
- schema = schema.test("integer-spots", t("neetoForm.questions.spot.mustBeInteger"), function (value) {
687
- return neetoCist.isNotPresent(value) || value === "" || Number.isInteger(Number(value));
688
- }).test("min-spots", t("neetoForm.error.mustBeOrGreaterThanOrEqualTo", {
689
- value: 1
690
- }), function (value) {
691
- return neetoCist.isNotPresent(value) || value === "" || Number(value) > 0;
692
- });
693
- if (typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0) {
694
- schema = schema.test("max-spots", t("neetoForm.questions.spot.exceedsRemainingSpots", {
695
- count: remainingSlotsCount
696
- }), function (value) {
697
- return neetoCist.isNotPresent(value) || value === "" || Number(value) > 0 && Number(value) <= remainingSlotsCount;
698
- });
699
- }
700
- }
701
- return schema.trim();
702
- };
703
- var validateEmailField = function validateEmailField(_ref2) {
704
- var label = _ref2.label,
705
- isRequired = _ref2.isRequired,
706
- whitelistedDomains = _ref2.whitelistedDomains,
707
- blacklistedDomains = _ref2.blacklistedDomains;
708
- var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string")).email(getInvalidFieldError("Email")).test("verify domain", function (_ref3) {
709
- var value = _ref3.value;
710
- return t("neetoForm.error.emailFromRestrictedDomain", {
711
- domain: extractEmailDomain(value)
712
- });
713
- }, function (value) {
714
- return neetoCist.isNotPresent(value) || isEmailFromWhitelistedDomain(value, whitelistedDomains) && !isEmailFromBlacklistedDomain(value, blacklistedDomains);
715
- });
716
- if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
717
- return schema.trim();
718
- };
719
- var validateNameField = function validateNameField(_ref4) {
720
- var label = _ref4.label,
721
- isRequired = _ref4.isRequired;
722
- var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
723
- if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
724
- return schema.trim();
725
- };
726
- var validateSingleChoiceField = function validateSingleChoiceField(_ref5) {
727
- var label = _ref5.label,
728
- isRequired = _ref5.isRequired;
729
- var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
730
- if (isRequired) schema = schema.required(getSelectMinError());
731
- return schema.trim();
732
- };
733
- var validateMultiChoiceField = function validateMultiChoiceField(_ref6) {
734
- var isRequired = _ref6.isRequired;
735
- var schema = yup__namespace.array().of(yup__namespace["boolean"]());
736
- if (isRequired) schema = schema.compact().min(1, getSelectMinError());
737
- return schema;
738
- };
739
- var validateRatingField = function validateRatingField(_ref7) {
740
- var label = _ref7.label,
741
- isRequired = _ref7.isRequired;
742
- var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
743
- if (isRequired) schema = schema.required(getSelectMinError());
744
- return schema.trim();
745
- };
746
- var validateStarRatingField = function validateStarRatingField(_ref8) {
747
- var label = _ref8.label,
748
- isRequired = _ref8.isRequired;
749
- var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
750
- if (isRequired) {
751
- schema = schema.required(getSelectMinError(t("neetoForm.common.rating")));
752
- }
753
- return schema.trim();
754
- };
755
- var validateOpinionScaleField = function validateOpinionScaleField(_ref9) {
756
- var label = _ref9.label,
757
- isRequired = _ref9.isRequired;
758
- var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
759
- if (isRequired) {
760
- schema = schema.required(getSelectMinError(t("neetoForm.common.selection")));
761
- }
762
- return schema.trim();
763
- };
764
- var validateTermsField = function validateTermsField(_ref10) {
765
- var _ref10$isRequired = _ref10.isRequired,
766
- isRequired = _ref10$isRequired === void 0 ? true : _ref10$isRequired;
767
- return isRequired ? yup__namespace["boolean"]().oneOf([true], t("neetoForm.common.mustAcceptTermsAndConditions")) : yup__namespace["boolean"]().notRequired();
768
- };
769
- var validateConditionField = function validateConditionField(_ref11) {
770
- var _ref11$isRequired = _ref11.isRequired,
771
- isRequired = _ref11$isRequired === void 0 ? true : _ref11$isRequired;
772
- return isRequired ? yup__namespace["boolean"]().oneOf([true], t("neetoForm.common.mustAcceptCondition")) : yup__namespace["boolean"]().notRequired();
773
- };
774
- var validateDateField = function validateDateField(_ref12) {
775
- var label = _ref12.label,
776
- isRequired = _ref12.isRequired;
777
- var schema = yup__namespace.string().test("is valid date", getInvalidTypeError(label, "date"), function (value) {
778
- return neetoCist.isNotPresent(value) || isValidDate(value);
779
- });
780
- if (isRequired) {
781
- schema = schema.required(getRequiredFieldError(label));
782
- }
783
- return schema;
784
- };
785
- var validateMultiEmailField = function validateMultiEmailField(_ref13) {
786
- var isRequired = _ref13.isRequired;
787
- var schema = yup__namespace.array().of(yup__namespace.object().shape({
788
- value: yup__namespace.string().email(getInvalidFieldError("Email")).trim()
789
- })).nullable();
790
- if (isRequired) {
791
- schema = schema.compact().min(1, getSelectMinError(t("neetoForm.common.email")));
792
- }
793
- return schema;
794
- };
795
- var validateAddressField = function validateAddressField(_ref14) {
796
- var label = _ref14.label,
797
- isRequired = _ref14.isRequired;
798
- var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
799
- if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
800
- return schema.trim();
801
- };
802
- var editorHasValue = function editorHasValue(content) {
803
- return !utils$1.isEditorEmpty(content);
804
- };
805
- var validateRichTextField = function validateRichTextField(_ref15) {
806
- var isRequired = _ref15.isRequired;
807
- var schema = yup__namespace.string();
808
- if (isRequired) {
809
- schema = schema.test("required", getRequiredFieldError("content"), editorHasValue);
810
- }
811
- return schema.trim();
812
- };
813
- var validateFileUploadField = function validateFileUploadField(_ref16) {
814
- var isRequired = _ref16.isRequired,
815
- multipleFilesAllowed = _ref16.multipleFilesAllowed;
816
- var files_schema = yup__namespace.array();
817
- if (isRequired) {
818
- files_schema = files_schema.of(yup__namespace.object().shape({
819
- name: yup__namespace.string(),
820
- signedId: yup__namespace.string().required(t("neetoForm.fileUpload.validations.waitForUpload")),
821
- url: yup__namespace.string().required(t("neetoForm.fileUpload.validations.waitForUpload"))
822
- })).unique("name", t("neetoForm.fileUpload.validations.removeDuplicates")).min(1, multipleFilesAllowed ? t("neetoForm.fileUpload.validations.atLeastOneFileRequired") : t("neetoForm.fileUpload.validations.fileIsRequired"));
823
- }
824
- return yup__namespace.object().shape({
825
- files: files_schema
826
- });
827
- };
828
- var validateCaptchaField = function validateCaptchaField(_ref17) {
829
- var variant = _ref17.variant;
830
- return variant === constants.CAPTCHA_TYPES.MATH_CAPTCHA ? yup__namespace.mixed().test("verification failed", t("neetoForm.error.captchaVerificationFailed"), function (value) {
831
- return neetoCist.isNotPresent(value) || value;
832
- }).transform(function (value) {
833
- return value === "" ? null : value;
834
- }).required(t("neetoForm.error.incompleteCaptcha")) : yup__namespace.string().trim().required(t("neetoForm.error.incompleteCaptcha"));
835
- };
836
- var fieldKindValidatorMap = (_fieldKindValidatorMa = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_fieldKindValidatorMa, yup.QUESTION_KIND.EMAIL.value, validateEmailField), yup.QUESTION_KIND.NAME.value, validateNameField), yup.QUESTION_KIND.PHONE.value, validateTextField), yup.QUESTION_KIND.TEXT.value, validateTextField), yup.QUESTION_KIND.QUESTION.value, validateTextField), yup.QUESTION_KIND.TEXTAREA.value, validateTextField), yup.QUESTION_KIND.DECIMAL.value, validateTextField), yup.QUESTION_KIND.INTEGER.value, validateTextField), yup.QUESTION_KIND.DROPDOWN.value, validateSingleChoiceField), yup.QUESTION_KIND.RADIO.value, validateSingleChoiceField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_fieldKindValidatorMa, yup.QUESTION_KIND.SPOT.value, validateTextField), yup.QUESTION_KIND.CHECKBOX.value, validateMultiChoiceField), yup.QUESTION_KIND.RATING.value, validateRatingField), yup.QUESTION_KIND.TERMS.value, validateTermsField), yup.QUESTION_KIND.DATE.value, validateDateField), yup.QUESTION_KIND.STAR_RATING.value, validateStarRatingField), yup.QUESTION_KIND.OPINION_SCALE.value, validateOpinionScaleField), yup.QUESTION_KIND.ADDITIONAL_GUESTS.value, validateMultiEmailField), yup.QUESTION_KIND.RICH_TEXT.value, validateRichTextField), yup.QUESTION_KIND.CONDITION.value, validateConditionField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_fieldKindValidatorMa, yup.QUESTION_KIND.FILE_UPLOAD.value, validateFileUploadField), yup.QUESTION_KIND.CAPTCHA.value, validateCaptchaField), yup.QUESTION_KIND.SMS_REMINDER.value, validateTextField), yup.QUESTION_KIND.ADDRESS.value, validateAddressField));
837
- var validateFieldValue = function validateFieldValue(_ref18) {
838
- var kind = _ref18.kind,
839
- customValidator = _ref18.customValidator,
840
- otherProps = _objectWithoutProperties(_ref18, _excluded$4);
841
- return function (value) {
842
- if (!(kind in fieldKindValidatorMap)) return;
843
- var validator = fieldKindValidatorMap[kind];
844
- var schema = customValidator || validator(_objectSpread$h({
845
- kind: kind
846
- }, otherProps));
847
-
848
- // eslint-disable-next-line consistent-return, no-async-promise-executor
849
- return new Promise(/*#__PURE__*/function () {
850
- var _ref19 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve) {
851
- return _regeneratorRuntime.wrap(function _callee$(_context) {
852
- while (1) switch (_context.prev = _context.next) {
853
- case 0:
854
- _context.prev = 0;
855
- _context.next = 3;
856
- return schema.validate(value);
857
- case 3:
858
- resolve(undefined);
859
- _context.next = 9;
860
- break;
861
- case 6:
862
- _context.prev = 6;
863
- _context.t0 = _context["catch"](0);
864
- resolve(_context.t0.message);
865
- case 9:
866
- case "end":
867
- return _context.stop();
868
- }
869
- }, _callee, null, [[0, 6]]);
870
- }));
871
- return function (_x) {
872
- return _ref19.apply(this, arguments);
873
- };
874
- }());
875
- };
876
- };
877
- var validateVerificationCode = function validateVerificationCode(context) {
878
- return function (value) {
879
- var entity = t("neetoForm.emailVerification.verificationCode");
880
- var schema = yup__namespace.string().trim().when("$isVerificationEnabled", {
881
- is: true,
882
- then: function then(schema) {
883
- return schema.when("$isRequired", {
884
- is: true,
885
- then: function then(s) {
886
- return s.required(getRequiredFieldError(entity));
887
- }
888
- }).when("$email", function (email, s) {
889
- if (email !== null && email !== void 0 && email.trim()) {
890
- return s.required(getRequiredFieldError(entity));
891
- }
892
- return s;
893
- }).test("is-6-digit-number", t("neetoForm.error.mustBeASixDigitNumber", {
894
- entity: entity
895
- }), function (value) {
896
- return neetoCist.isNotPresent(value) || yup.SIX_DIGIT_NUMBER_REGEX.test(value);
897
- }).test("verify code", t("neetoForm.error.emailNotVerified"), function () {
898
- var _this$options;
899
- return this === null || this === void 0 || (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.context) === null || _this$options === void 0 ? void 0 : _this$options.isCodeVerified;
900
- });
901
- }
902
- });
903
-
904
- // eslint-disable-next-line no-async-promise-executor
905
- return new Promise(/*#__PURE__*/function () {
906
- var _ref20 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve) {
907
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
908
- while (1) switch (_context2.prev = _context2.next) {
909
- case 0:
910
- _context2.prev = 0;
911
- _context2.next = 3;
912
- return schema.validate(value, {
913
- context: context
914
- });
915
- case 3:
916
- resolve(undefined);
917
- _context2.next = 9;
918
- break;
919
- case 6:
920
- _context2.prev = 6;
921
- _context2.t0 = _context2["catch"](0);
922
- resolve(_context2.t0.message);
923
- case 9:
924
- case "end":
925
- return _context2.stop();
926
- }
927
- }, _callee2, null, [[0, 6]]);
928
- }));
929
- return function (_x2) {
930
- return _ref20.apply(this, arguments);
931
- };
932
- }());
933
- };
934
- };
935
-
936
- var MultipleEmailInput = function MultipleEmailInput(_ref) {
937
- var question = _ref.question,
938
- customValidator = _ref.customValidator;
939
- var name = question.id,
940
- kind = question.kind,
941
- isRequired = question.isRequired,
942
- nodeId = question.nodeId,
943
- isReadOnly = question.isReadOnly;
944
- var label = index.fieldWithFallback(question, "label");
945
- var _useFormikContext = formik.useFormikContext(),
946
- submitCount = _useFormikContext.submitCount;
947
- var _useTranslation = reactI18next.useTranslation(),
948
- t = _useTranslation.t;
949
- var _useField = formik.useField({
950
- name: name || nodeId,
951
- validate: validateFieldValue({
952
- kind: kind,
953
- label: label,
954
- isRequired: isRequired,
955
- customValidator: customValidator
956
- })
957
- }),
958
- _useField2 = _slicedToArray(_useField, 3),
959
- field = _useField2[0],
960
- meta = _useField2[1],
961
- _useField2$ = _useField2[2],
962
- setValue = _useField2$.setValue,
963
- setTouched = _useField2$.setTouched;
964
- var _useState = React.useState(neetoCist.isPresent(field.value)),
965
- _useState2 = _slicedToArray(_useState, 2),
966
- isInputVisible = _useState2[0],
967
- setIsInputVisible = _useState2[1];
968
- return /*#__PURE__*/jsxRuntime.jsx("div", {
969
- className: "neeto-form-engine-input__wrapper",
970
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
971
- className: "neeto-ui-w-full",
972
- children: isInputVisible ? /*#__PURE__*/jsxRuntime.jsx(NeetoUIMultiEmailInput, {
973
- isRequired: isRequired,
974
- label: label,
975
- disabled: isReadOnly,
976
- error: meta.touched ? meta.error : "",
977
- helpText: t("neetoForm.common.addGuestsHelper"),
978
- name: field.name,
979
- placeholder: index.fieldWithFallback(question, "placeholder"),
980
- value: field.value,
981
- onBlur: function onBlur() {
982
- return setTouched(true);
983
- },
984
- onChange: setValue
985
- }) : /*#__PURE__*/jsxRuntime.jsxs("div", {
986
- className: "flex flex-col gap-2 items-end",
987
- children: [/*#__PURE__*/jsxRuntime.jsx(Button, _defineProperty(_defineProperty(_defineProperty({
988
- label: label,
989
- "data-testid": "add-guest-button",
990
- disabled: isReadOnly,
991
- icon: Plus,
992
- iconPosition: "left"
993
- }, "label", t("neetoForm.common.addGuests")), "style", "link"), "onClick", function onClick() {
994
- return setIsInputVisible(true);
995
- })), (meta === null || meta === void 0 ? void 0 : meta.error) && submitCount > 0 && /*#__PURE__*/jsxRuntime.jsx("span", {
996
- className: "neeto-ui-text-error-500",
997
- children: meta.error
998
- })]
999
- })
1000
- })
1001
- });
1002
- };
1003
-
1004
- function ownKeys$g(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1005
- function _objectSpread$g(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$g(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$g(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1006
- var AddressField = function AddressField(_ref) {
1007
- var question = _ref.question,
1008
- customValidator = _ref.customValidator;
1009
- var name = question.id,
1010
- kind = question.kind,
1011
- isAddressRequired = question.isRequired,
1012
- isReadOnly = question.isReadOnly,
1013
- _question$fields = question.fields,
1014
- fields = _question$fields === void 0 ? [] : _question$fields;
1015
- var label = index.fieldWithFallback(question, "label");
1016
- var transformedFields = fields.map(function (field) {
1017
- return _objectSpread$g(_objectSpread$g({}, field), {}, {
1018
- label: index.fieldWithFallback(field, "label")
1019
- });
1020
- });
1021
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
1022
- className: "neeto-form-engine-address-wrapper",
1023
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1024
- className: "neeto-form-engine-input__label-wrapper",
1025
- children: label && /*#__PURE__*/jsxRuntime.jsx("label", {
1026
- className: "neeto-form-engine-label",
1027
- "data-testid": "".concat(neetoCist.hyphenate(label), "-input-label"),
1028
- children: label
1029
- })
1030
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
1031
- className: "neeto-form-engine-address pb-1",
1032
- children: getVisibleOptions(transformedFields).map(function (_ref2) {
1033
- var id = _ref2.id,
1034
- label = _ref2.label,
1035
- width = _ref2.width,
1036
- fieldType = _ref2.fieldType,
1037
- properties = _ref2.properties,
1038
- isRequired = _ref2.isRequired;
1039
- return /*#__PURE__*/jsxRuntime.jsx("div", {
1040
- "data-testid": "neeto-form-engine-address-fields",
1041
- className: classnames("neeto-form-engine-address__field", {
1042
- "neeto-form-engine-address__field--width-full": width === yup.ADDRESS_FIELD_WIDTHS.FULL,
1043
- "neeto-form-engine-address__field--width-half": width === yup.ADDRESS_FIELD_WIDTHS.HALF,
1044
- "neeto-form-engine-address__field--width-one-forth": width === yup.ADDRESS_FIELD_WIDTHS.ONE_FOURTH,
1045
- "neeto-form-engine-address__field--width-three-forth": width === yup.ADDRESS_FIELD_WIDTHS.THREE_FOURTH
1046
- }),
1047
- children: /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
1048
- name: "".concat(name, ".").concat(id),
1049
- validate: isAddressRequired ? validateFieldValue({
1050
- kind: kind,
1051
- label: label,
1052
- isRequired: isRequired,
1053
- customValidator: customValidator
1054
- }) : neetoCist.noop,
1055
- children: function children(_ref3) {
1056
- var _properties$options;
1057
- var field = _ref3.field,
1058
- meta = _ref3.meta,
1059
- form = _ref3.form;
1060
- return fieldType === yup.ADDRESS_FIELD_TYPES.SELECT ? /*#__PURE__*/jsxRuntime.jsx(Select, _objectSpread$g(_objectSpread$g({
1061
- label: label,
1062
- size: "large"
1063
- }, field), {}, {
1064
- error: meta.touched && meta.error,
1065
- isDisabled: isReadOnly,
1066
- menuPosition: "absolute",
1067
- required: isRequired,
1068
- value: neetoCist.toLabelAndValue(field.value),
1069
- options: properties === null || properties === void 0 || (_properties$options = properties.options) === null || _properties$options === void 0 ? void 0 : _properties$options.map(function (_ref4) {
1070
- var label = _ref4.label;
1071
- return neetoCist.toLabelAndValue(label);
1072
- }),
1073
- onChange: function onChange(_ref5) {
1074
- var value = _ref5.value;
1075
- return !isReadOnly && form.setFieldValue("".concat(name, ".").concat(id), value);
1076
- }
1077
- })) : /*#__PURE__*/jsxRuntime.jsx(Input, _objectSpread$g(_objectSpread$g({}, _objectSpread$g(_objectSpread$g({}, field), {}, {
1078
- label: label
1079
- })), {}, {
1080
- disabled: isReadOnly,
1081
- error: meta.touched && meta.error,
1082
- required: isRequired
1083
- }));
1084
- }
1085
- })
1086
- }, id);
1087
- })
1088
- })]
1089
- });
1090
- };
1091
-
1092
- var CaptchaField = function CaptchaField(_ref) {
1093
- var question = _ref.question,
1094
- preview = _ref.preview,
1095
- customValidator = _ref.customValidator,
1096
- captchaRef = _ref.captchaRef;
1097
- var name = question.id,
1098
- kind = question.kind,
1099
- isRequired = question.isRequired,
1100
- variant = question.variant,
1101
- nodeId = question.nodeId;
1102
- var label = index.fieldWithFallback(question, "label");
1103
- var _useField = formik.useField({
1104
- name: name || nodeId,
1105
- validate: validateFieldValue({
1106
- kind: kind,
1107
- label: label,
1108
- isRequired: isRequired,
1109
- customValidator: customValidator,
1110
- variant: variant
1111
- })
1112
- }),
1113
- _useField2 = _slicedToArray(_useField, 3);
1114
- _useField2[0];
1115
- var _useField2$ = _useField2[1],
1116
- touched = _useField2$.touched,
1117
- error = _useField2$.error,
1118
- _useField2$2 = _useField2[2],
1119
- setValue = _useField2$2.setValue,
1120
- setTouched = _useField2$2.setTouched;
1121
- var handleVerifyCaptcha = function handleVerifyCaptcha(response) {
1122
- setTouched(true);
1123
- setValue(response);
1124
- };
1125
- var Component = CAPTCHA_COMPONENT_MAP[variant];
1126
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
1127
- className: "neeto-form-engine-input__wrapper",
1128
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1129
- className: "neeto-form-engine-input__label-wrapper",
1130
- children: label && /*#__PURE__*/jsxRuntime.jsx("label", {
1131
- className: "neeto-form-engine-label",
1132
- children: getLabel(label, isRequired)
1133
- })
1134
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
1135
- className: classnames({
1136
- "pointer-events-none": preview
1137
- }),
1138
- children: /*#__PURE__*/jsxRuntime.jsx(Component, {
1139
- captchaRef: captchaRef,
1140
- handleVerifyCaptcha: handleVerifyCaptcha,
1141
- handleBlur: function handleBlur() {
1142
- return setTouched(true);
1143
- }
1144
- })
1145
- }), touched && error && /*#__PURE__*/jsxRuntime.jsx("p", {
1146
- className: "neeto-form-engine-input__error",
1147
- "data-testid": "neeto-form-engine-captcha-error",
1148
- children: error
1149
- })]
1150
- });
1151
- };
1152
-
1153
- var MATH_OPERATORS = {
1154
- PLUS: "+",
1155
- MINUS: "-"
1156
- };
1157
-
1158
- var generateRandomOperation = function generateRandomOperation() {
1159
- var firstNumber = neetoCist.getRandomInt(1, 50);
1160
- var secondNumber = neetoCist.getRandomInt(1, 50);
1161
- var operator = neetoCist.randomPick.apply(void 0, _toConsumableArray(ramda.values(MATH_OPERATORS)));
1162
- return {
1163
- firstNumber: firstNumber,
1164
- secondNumber: secondNumber,
1165
- operator: operator
1166
- };
1167
- };
1168
-
1169
- var MathCaptcha = function MathCaptcha(_ref) {
1170
- var captchaRef = _ref.captchaRef,
1171
- handleVerifyCaptcha = _ref.handleVerifyCaptcha,
1172
- handleBlur = _ref.handleBlur;
1173
- var _useState = React.useState(generateRandomOperation()),
1174
- _useState2 = _slicedToArray(_useState, 2),
1175
- operation = _useState2[0],
1176
- setOperation = _useState2[1];
1177
- var _useState3 = React.useState(""),
1178
- _useState4 = _slicedToArray(_useState3, 2),
1179
- userInput = _useState4[0],
1180
- setUserInput = _useState4[1];
1181
- var firstNumber = operation.firstNumber,
1182
- secondNumber = operation.secondNumber,
1183
- operator = operation.operator;
1184
- var resetCaptcha = function resetCaptcha() {
1185
- setOperation(generateRandomOperation());
1186
- setUserInput("");
1187
- };
1188
- React.useImperativeHandle(captchaRef, function () {
1189
- return {
1190
- reset: resetCaptcha
1191
- };
1192
- });
1193
- var calculateResult = function calculateResult() {
1194
- switch (operator) {
1195
- case MATH_OPERATORS.PLUS:
1196
- return firstNumber + secondNumber;
1197
- case MATH_OPERATORS.MINUS:
1198
- return firstNumber - secondNumber;
1199
- default:
1200
- return null;
1201
- }
1202
- };
1203
- var verifyCaptcha = function verifyCaptcha() {
1204
- var result = calculateResult();
1205
- if (result === null) return;
1206
- handleVerifyCaptcha(result === Number(userInput));
1207
- };
1208
- reactUtils.useUpdateEffect(function () {
1209
- verifyCaptcha();
1210
- }, [userInput]);
1211
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
1212
- className: "neeto-form-nano-math-captcha",
1213
- "data-testid": "math-captcha",
1214
- ref: captchaRef,
1215
- children: [/*#__PURE__*/jsxRuntime.jsx("button", {
1216
- className: "neeto-form-nano-math-captcha__button",
1217
- type: "button",
1218
- onClick: resetCaptcha,
1219
- children: /*#__PURE__*/jsxRuntime.jsx(Refresh, {})
1220
- }), /*#__PURE__*/jsxRuntime.jsxs("div", {
1221
- className: "neeto-form-nano-math-captcha__equation",
1222
- children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1223
- "data-testid": "first-number",
1224
- children: firstNumber
1225
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
1226
- "data-testid": "operator",
1227
- children: operator
1228
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
1229
- "data-testid": "second-number",
1230
- children: secondNumber
1231
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
1232
- children: "="
1233
- })]
1234
- }), /*#__PURE__*/jsxRuntime.jsx(Input, {
1235
- required: true,
1236
- className: "neeto-form-nano-math-captcha__input",
1237
- "data-testid": "math-captcha-input",
1238
- value: userInput,
1239
- onBlur: handleBlur,
1240
- onChange: utils.withEventTargetValue(setUserInput)
1241
- })]
1242
- });
1243
- };
1244
-
1245
- var Recaptcha = function Recaptcha(_ref) {
1246
- var captchaRef = _ref.captchaRef,
1247
- handleVerifyCaptcha = _ref.handleVerifyCaptcha;
1248
- var verifyRecaptcha = function verifyRecaptcha(response) {
1249
- if (response === null) {
1250
- return;
1251
- }
1252
- handleVerifyCaptcha(response);
1253
- };
1254
- var expiredRecaptcha = function expiredRecaptcha() {
1255
- var _captchaRef$current;
1256
- captchaRef === null || captchaRef === void 0 || (_captchaRef$current = captchaRef.current) === null || _captchaRef$current === void 0 || _captchaRef$current.reset();
1257
- handleVerifyCaptcha("");
1258
- };
1259
- return /*#__PURE__*/jsxRuntime.jsx(ReCAPTCHA, {
1260
- hl: clientI18nInstance.language,
1261
- ref: captchaRef,
1262
- sitekey: initializers.globalProps.formNanoRecaptchaV2SiteKey,
1263
- onChange: verifyRecaptcha,
1264
- onErrored: neetoCist.noop,
1265
- onExpired: expiredRecaptcha
1266
- }, clientI18nInstance.language);
1267
- };
1268
-
1269
- function ownKeys$f(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1270
- function _objectSpread$f(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$f(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$f(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1271
- var ConditionField = function ConditionField(_ref) {
1272
- var question = _ref.question,
1273
- customValidator = _ref.customValidator;
1274
- var name = question.id,
1275
- kind = question.kind,
1276
- isRequired = question.isRequired,
1277
- nodeId = question.nodeId;
1278
- var label = index.fieldWithFallback(question, "label");
1279
- return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
1280
- name: name || nodeId,
1281
- validate: validateFieldValue({
1282
- kind: kind,
1283
- label: label,
1284
- isRequired: isRequired,
1285
- customValidator: customValidator
1286
- }),
1287
- children: function children(_ref2) {
1288
- var meta = _ref2.meta,
1289
- field = _ref2.field;
1290
- return /*#__PURE__*/jsxRuntime.jsx(Checkbox, _objectSpread$f(_objectSpread$f({}, _objectSpread$f(_objectSpread$f({}, field), {}, {
1291
- label: label,
1292
- name: name
1293
- })), {}, {
1294
- checked: field.value,
1295
- error: meta.touched ? meta.error : "",
1296
- required: isRequired
1297
- }));
1298
- }
1299
- });
1300
- };
1301
-
1302
- var _excluded$3 = ["value"];
1303
- function ownKeys$e(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1304
- function _objectSpread$e(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$e(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$e(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1305
- var DateField = function DateField(_ref) {
1306
- var question = _ref.question,
1307
- customValidator = _ref.customValidator;
1308
- var name = question.id,
1309
- kind = question.kind,
1310
- isRequired = question.isRequired,
1311
- nodeId = question.nodeId,
1312
- isReadOnly = question.isReadOnly;
1313
- var label = index.fieldWithFallback(question, "label");
1314
- var _QUESTION_KIND$kind$t = yup.QUESTION_KIND[kind.toUpperCase()].type,
1315
- type = _QUESTION_KIND$kind$t === void 0 ? "date" : _QUESTION_KIND$kind$t;
1316
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
1317
- className: "neeto-form-engine-input__wrapper",
1318
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1319
- className: "neeto-form-engine-input__label-wrapper",
1320
- children: label && /*#__PURE__*/jsxRuntime.jsx("label", {
1321
- className: "neeto-form-engine-label",
1322
- "data-testid": "".concat(neetoCist.hyphenate(label), "-input-label"),
1323
- children: getLabel(label, isRequired)
1324
- })
1325
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
1326
- className: "neeto-form-engine-date-picker",
1327
- children: /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
1328
- name: name || nodeId,
1329
- validate: validateFieldValue({
1330
- kind: kind,
1331
- label: label,
1332
- isRequired: isRequired,
1333
- customValidator: customValidator
1334
- }),
1335
- children: function children(_ref2) {
1336
- var meta = _ref2.meta,
1337
- _ref2$field = _ref2.field,
1338
- value = _ref2$field.value,
1339
- field = _objectWithoutProperties(_ref2$field, _excluded$3),
1340
- form = _ref2.form;
1341
- return /*#__PURE__*/jsxRuntime.jsx(DatePicker, _objectSpread$e(_objectSpread$e({}, _objectSpread$e(_objectSpread$e({}, field), {}, {
1342
- type: type
1343
- })), {}, {
1344
- "data-testid": "".concat(neetoCist.hyphenate(label), "-input-field"),
1345
- dateFormat: "MMM D, YYYY",
1346
- disabled: isReadOnly,
1347
- error: meta.touched ? meta.error : "",
1348
- placeholder: index.fieldWithFallback(question, "placeholder"),
1349
- popupClassName: "neeto-form-engine-date-picker-popup",
1350
- required: isRequired,
1351
- size: "small",
1352
- value: getValidDate(value),
1353
- onCalendarChange: function onCalendarChange(date) {
1354
- if (date) {
1355
- form.setFieldValue(name, date.toISOString());
1356
- }
1357
- },
1358
- onChange: function onChange(date) {
1359
- form.setFieldValue(name, date ? date.toISOString() : "");
1360
- }
1361
- }));
1362
- }
1363
- })
1364
- })]
1365
- });
1366
- };
1367
-
1368
- var create = function create(_ref) {
1369
- var formId = _ref.formId,
1370
- questionId = _ref.questionId,
1371
- payload = _ref.payload;
1372
- return axios.post(utils.buildUrl(constants.EMAIL_VERIFICATIONS_CREATE_URL, {
1373
- formId: formId,
1374
- questionId: questionId
1375
- }), payload, {
1376
- showToastr: false
1377
- });
1378
- };
1379
- var verify = function verify(_ref2) {
1380
- var formId = _ref2.formId,
1381
- questionId = _ref2.questionId,
1382
- payload = _ref2.payload;
1383
- return axios.post(utils.buildUrl(constants.EMAIL_VERIFICATIONS_VERIFY_URL, {
1384
- formId: formId,
1385
- questionId: questionId
1386
- }), payload, {
1387
- showToastr: false
1388
- });
1389
- };
1390
- var emailVerificationsApi = {
1391
- create: create,
1392
- verify: verify
1393
- };
1394
-
1395
- function ownKeys$d(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1396
- function _objectSpread$d(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$d(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$d(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1397
- var getMutationCallbacks = function getMutationCallbacks(options) {
1398
- return {
1399
- onSuccess: function onSuccess() {
1400
- var _options$onSuccess;
1401
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1402
- args[_key] = arguments[_key];
1403
- }
1404
- return (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 ? void 0 : _options$onSuccess.call.apply(_options$onSuccess, [options].concat(args));
1405
- },
1406
- onError: function onError() {
1407
- var _options$onError;
1408
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1409
- args[_key2] = arguments[_key2];
1410
- }
1411
- return (_options$onError = options.onError) === null || _options$onError === void 0 ? void 0 : _options$onError.call.apply(_options$onError, [options].concat(args));
1412
- }
1413
- };
1414
- };
1415
- var useSendEmailVerificationCode = function useSendEmailVerificationCode(formId, questionId) {
1416
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1417
- return reactQuery.useMutation(_objectSpread$d(_objectSpread$d({
1418
- mutationFn: function mutationFn(payload) {
1419
- return emailVerificationsApi.create({
1420
- formId: formId,
1421
- questionId: questionId,
1422
- payload: payload
1423
- });
1424
- }
1425
- }, options), getMutationCallbacks(options)));
1426
- };
1427
- var useVerifyEmailVerificationCode = function useVerifyEmailVerificationCode(formId, questionId) {
1428
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1429
- return reactQuery.useMutation(_objectSpread$d(_objectSpread$d({
1430
- mutationFn: function mutationFn(payload) {
1431
- return emailVerificationsApi.verify({
1432
- formId: formId,
1433
- questionId: questionId,
1434
- payload: payload
1435
- });
1436
- }
1437
- }, options), getMutationCallbacks(options)));
1438
- };
1439
-
1440
- var SendCodeButton = function SendCodeButton(_ref) {
1441
- var isCodeVerified = _ref.isCodeVerified,
1442
- isSendingVerificationCode = _ref.isSendingVerificationCode,
1443
- handleClick = _ref.handleClick,
1444
- isDisabled = _ref.isDisabled;
1445
- var _useTranslation = reactI18next.useTranslation(),
1446
- t = _useTranslation.t;
1447
- if (isCodeVerified) {
1448
- return /*#__PURE__*/jsxRuntime.jsx(CheckCircle, {});
1449
- }
1450
- return /*#__PURE__*/jsxRuntime.jsx(Button, {
1451
- "data-testid": "send-code-button",
1452
- disabled: isDisabled,
1453
- size: "small",
1454
- style: "secondary",
1455
- onClick: handleClick,
1456
- children: isSendingVerificationCode ? /*#__PURE__*/jsxRuntime.jsx(Spinner, {
1457
- size: "16"
1458
- }) : t("neetoForm.emailVerification.sendCode")
1459
- });
1460
- };
1461
-
1462
- var ResendVerificationCode = function ResendVerificationCode(_ref) {
1463
- var formId = _ref.formId,
1464
- questionId = _ref.questionId,
1465
- sendVerificationCode = _ref.sendVerificationCode,
1466
- isResendDisabled = _ref.isResendDisabled;
1467
- var _useState = React.useState(getRemainingTime(formId, questionId)),
1468
- _useState2 = _slicedToArray(_useState, 2),
1469
- secondsLeft = _useState2[0],
1470
- setSecondsLeft = _useState2[1];
1471
- var _useTranslation = reactI18next.useTranslation(),
1472
- t = _useTranslation.t;
1473
- React.useEffect(function () {
1474
- if (secondsLeft <= 0) return undefined;
1475
- var interval = setTimeout(function () {
1476
- setSecondsLeft(ramda.pipe(ramda.dec, ramda.max(0)));
1477
- }, ONE_SECOND);
1478
- return function () {
1479
- return clearTimeout(interval);
1480
- };
1481
- }, [secondsLeft]);
1482
- var handleResendClick = function handleResendClick() {
1483
- if (secondsLeft !== 0) return;
1484
- sendVerificationCode();
1485
- setSecondsLeft(RESEND_DELAY);
1486
- storeLastVerificationCodeSentAt(formId, questionId);
1487
- };
1488
- return /*#__PURE__*/jsxRuntime.jsx("p", {
1489
- children: !isResendDisabled && secondsLeft > 0 ? t("neetoForm.emailVerification.resendInSeconds", {
1490
- secondsLeft: secondsLeft
1491
- }) : /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
1492
- i18nKey: "neetoForm.emailVerification.resendCode",
1493
- components: {
1494
- button: /*#__PURE__*/jsxRuntime.jsx(Button, {
1495
- "data-testid": "otp-resend-button",
1496
- disabled: isResendDisabled,
1497
- size: "small",
1498
- style: "link",
1499
- onClick: handleResendClick
1500
- })
1501
- }
1502
- })
1503
- });
1504
- };
1505
-
1506
- function ownKeys$c(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1507
- function _objectSpread$c(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$c(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$c(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1508
- var VerifyCode = function VerifyCode(_ref) {
1509
- var formId = _ref.formId,
1510
- questionId = _ref.questionId,
1511
- email = _ref.email,
1512
- emailVerificationToken = _ref.emailVerificationToken,
1513
- isCodeVerified = _ref.isCodeVerified,
1514
- setIsCodeVerified = _ref.setIsCodeVerified,
1515
- handleResponseError = _ref.handleResponseError,
1516
- hasSentVerificationCode = _ref.hasSentVerificationCode,
1517
- calloutDetails = _ref.calloutDetails,
1518
- handleSendVerificationCode = _ref.handleSendVerificationCode,
1519
- isRequired = _ref.isRequired,
1520
- isVerificationEnabled = _ref.isVerificationEnabled;
1521
- var _useTranslation = reactI18next.useTranslation(),
1522
- t = _useTranslation.t;
1523
- var verificationFieldName = buildVerificationFieldName(questionId);
1524
- var _useField = formik.useField({
1525
- name: verificationFieldName,
1526
- validate: validateVerificationCode({
1527
- isVerificationEnabled: isVerificationEnabled,
1528
- isRequired: isRequired,
1529
- email: email,
1530
- isCodeVerified: isCodeVerified
1531
- })
1532
- }),
1533
- _useField2 = _slicedToArray(_useField, 3),
1534
- field = _useField2[0],
1535
- _useField2$ = _useField2[1],
1536
- touched = _useField2$.touched,
1537
- error = _useField2$.error,
1538
- _useField2$2 = _useField2[2],
1539
- setValue = _useField2$2.setValue,
1540
- setTouched = _useField2$2.setTouched;
1541
- var code = field.value;
1542
- var _useState = React.useState(code),
1543
- _useState2 = _slicedToArray(_useState, 2),
1544
- previousCode = _useState2[0],
1545
- setPreviousCode = _useState2[1];
1546
- var _useVerifyEmailVerifi = useVerifyEmailVerificationCode(formId, questionId, {
1547
- onSuccess: function onSuccess(_, _ref2) {
1548
- var emailVerifications = _ref2.emailVerifications;
1549
- setIsCodeVerified(true);
1550
- setPreviousCode(emailVerifications.otp);
1551
- setEmailVerificationDetail(formId, questionId, _defineProperty(_defineProperty(_defineProperty({}, EMAIL_VERIFICATION_KEYS.EMAIL, emailVerifications.email), EMAIL_VERIFICATION_KEYS.CODE, emailVerifications.otp), EMAIL_VERIFICATION_KEYS.VERIFIED, true));
1552
- },
1553
- onError: handleResponseError
1554
- }),
1555
- verifyCode = _useVerifyEmailVerifi.mutate,
1556
- isVerifyingCode = _useVerifyEmailVerifi.isPending;
1557
- var hasError = neetoCist.isPresent(error);
1558
- React.useEffect(function () {
1559
- var handleVerifyCode = function handleVerifyCode() {
1560
- if (ramda.equals(code, previousCode) || hasError || (code === null || code === void 0 ? void 0 : code.length) !== 6) {
1561
- return;
1562
- }
1563
- verifyCode({
1564
- emailVerifications: {
1565
- email: email,
1566
- token: emailVerificationToken,
1567
- otp: code
1568
- }
1569
- });
1570
- };
1571
- handleVerifyCode();
1572
- }, [code, hasError]);
1573
- return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
1574
- children: [/*#__PURE__*/jsxRuntime.jsx(Input, _objectSpread$c(_objectSpread$c({}, _objectSpread$c({}, field)), {}, {
1575
- "data-testid": "otp-input-field",
1576
- disabled: isVerifyingCode,
1577
- error: touched ? error : "",
1578
- loading: isVerifyingCode,
1579
- name: verificationFieldName,
1580
- placeholder: t("neetoForm.emailVerification.verificationCode"),
1581
- size: "small",
1582
- onBlur: function onBlur() {
1583
- return setTouched(true);
1584
- },
1585
- onChange: utils.withEventTargetValue(setValue)
1586
- })), hasSentVerificationCode && /*#__PURE__*/jsxRuntime.jsx(ResendVerificationCode, {
1587
- formId: formId,
1588
- questionId: questionId,
1589
- isResendDisabled: calloutDetails.style === CALLOUT_STYLES.ERROR,
1590
- sendVerificationCode: handleSendVerificationCode
1591
- }), calloutDetails.message && /*#__PURE__*/jsxRuntime.jsx(NeetoUICallout, {
1592
- style: calloutDetails.style,
1593
- children: calloutDetails.message
1594
- })]
1595
- });
1596
- };
1597
-
1598
- function ownKeys$b(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1599
- function _objectSpread$b(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$b(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1600
- var EmailField = function EmailField(_ref) {
1601
- var question = _ref.question,
1602
- customValidator = _ref.customValidator,
1603
- autoComplete = _ref.autoComplete,
1604
- isFormPreview = _ref.preview,
1605
- isUrlBuilderPreview = _ref.isUrlBuilderPreview;
1606
- var questionId = question.id,
1607
- kind = question.kind,
1608
- isRequired = question.isRequired,
1609
- isReadOnly = question.isReadOnly,
1610
- isDomainWhitelistingEnabled = question.isDomainWhitelistingEnabled,
1611
- whitelistedDomains = question.whitelistedDomains,
1612
- isDomainBlacklistingEnabled = question.isDomainBlacklistingEnabled,
1613
- blacklistedDomains = question.blacklistedDomains,
1614
- isVerificationEnabled = question.isVerificationEnabled,
1615
- nodeId = question.nodeId,
1616
- formId = question.formId;
1617
- var label = index.fieldWithFallback(question, "label");
1618
- var _useState = React.useState(DEFAULT_CALLOUT_DETAILS),
1619
- _useState2 = _slicedToArray(_useState, 2),
1620
- calloutDetails = _useState2[0],
1621
- setCalloutDetails = _useState2[1];
1622
- var type = yup.QUESTION_KIND[kind.toUpperCase()].type;
1623
- var _useState3 = React.useState(getLastVerificationCodeSentAt(questionId) > 0),
1624
- _useState4 = _slicedToArray(_useState3, 2),
1625
- hasSentVerificationCode = _useState4[0],
1626
- setHasSentVerificationCode = _useState4[1];
1627
- var verificationStatus = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.VERIFIED);
1628
- var _useStateWithDependen = reactUtils.useStateWithDependency(verificationStatus, [verificationStatus]),
1629
- _useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 2),
1630
- isCodeVerified = _useStateWithDependen2[0],
1631
- setIsCodeVerified = _useStateWithDependen2[1];
1632
- var _useField = formik.useField({
1633
- name: questionId || nodeId,
1634
- validate: validateFieldValue({
1635
- kind: kind,
1636
- label: label,
1637
- isRequired: isRequired,
1638
- customValidator: customValidator,
1639
- whitelistedDomains: isDomainWhitelistingEnabled ? whitelistedDomains : [],
1640
- blacklistedDomains: isDomainBlacklistingEnabled ? blacklistedDomains : []
1641
- })
1642
- }),
1643
- _useField2 = _slicedToArray(_useField, 3),
1644
- field = _useField2[0],
1645
- _useField2$ = _useField2[1],
1646
- touched = _useField2$.touched,
1647
- error = _useField2$.error,
1648
- _useField2$2 = _useField2[2],
1649
- setValue = _useField2$2.setValue,
1650
- setTouched = _useField2$2.setTouched;
1651
- var _useFormikContext = formik.useFormikContext(),
1652
- setFieldValue = _useFormikContext.setFieldValue;
1653
- var email = field.value;
1654
- var emailVerificationToken = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.TOKEN);
1655
- var handleResponseError = function handleResponseError(error) {
1656
- var _error$response;
1657
- var message = error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.data) === null || _error$response === void 0 ? void 0 : _error$response.error;
1658
- if ((error === null || error === void 0 ? void 0 : error.status) === 429) {
1659
- setCalloutDetails({
1660
- message: message,
1661
- style: CALLOUT_STYLES.ERROR
1662
- });
1663
- storeLastVerificationCodeSentAt(formId, questionId, RESEND_DELAY * ONE_SECOND);
1664
- } else {
1665
- Toastr.error(message);
1666
- }
1667
- };
1668
-
1669
- // TODO backend validation
1670
- var _useSendEmailVerifica = useSendEmailVerificationCode(formId, questionId, {
1671
- onSuccess: function onSuccess(_ref2) {
1672
- var token = _ref2.token,
1673
- message = _ref2.message;
1674
- setHasSentVerificationCode(true);
1675
- storeLastVerificationCodeSentAt(formId, questionId);
1676
- if (!emailVerificationToken) {
1677
- setEmailVerificationDetail(formId, questionId, _defineProperty({}, EMAIL_VERIFICATION_KEYS.TOKEN, token));
1678
- }
1679
- if (message) {
1680
- setCalloutDetails({
1681
- message: message,
1682
- style: CALLOUT_STYLES.WARNING
1683
- });
1684
- }
1685
- },
1686
- onError: handleResponseError
1687
- }),
1688
- sendVerificationCode = _useSendEmailVerifica.mutate,
1689
- isSendingVerificationCode = _useSendEmailVerifica.isPending;
1690
- var resetVerifiedData = function resetVerifiedData(email) {
1691
- var verifiedEmail = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.EMAIL);
1692
- if (email !== verifiedEmail) {
1693
- removeEmailVerificationDetail(formId, questionId, ramda.values(ramda.omit(["TOKEN"], EMAIL_VERIFICATION_KEYS)));
1694
- setIsCodeVerified(false);
1695
- setFieldValue(buildVerificationFieldName(questionId), "");
1696
- setHasSentVerificationCode(false);
1697
- setCalloutDetails(DEFAULT_CALLOUT_DETAILS);
1698
- }
1699
- };
1700
- var handleFieldChange = utils.withEventTargetValue(setValue);
1701
- var handleSendVerificationCode = function handleSendVerificationCode() {
1702
- return sendVerificationCode({
1703
- emailVerifications: {
1704
- email: email,
1705
- token: emailVerificationToken
1706
- }
1707
- });
1708
- };
1709
- var shouldShowVerifyButton = isVerificationEnabled && !isUrlBuilderPreview && (isFormPreview || neetoCist.isPresent(email) && neetoCist.isNotPresent(error));
1710
- var shouldShowVerificationCodeInput = shouldShowVerifyButton && !isFormPreview && !isCodeVerified;
1711
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
1712
- className: "flex-col space-y-2",
1713
- children: [/*#__PURE__*/jsxRuntime.jsx(Input, _objectSpread$b(_objectSpread$b({}, _objectSpread$b(_objectSpread$b({
1714
- type: type
1715
- }, field), {}, {
1716
- autoComplete: autoComplete,
1717
- label: label
1718
- }, shouldShowVerifyButton && {
1719
- suffix: /*#__PURE__*/jsxRuntime.jsx(SendCodeButton, {
1720
- isCodeVerified: isCodeVerified,
1721
- isSendingVerificationCode: isSendingVerificationCode,
1722
- handleClick: isFormPreview ? neetoCist.noop : handleSendVerificationCode,
1723
- isDisabled: isCodeVerified || hasSentVerificationCode
1724
- })
1725
- })), {}, {
1726
- disabled: isReadOnly,
1727
- error: touched && !isCodeVerified ? error : "",
1728
- name: kind,
1729
- placeholder: index.fieldWithFallback(question, "placeholder"),
1730
- required: isRequired,
1731
- onBlur: function onBlur() {
1732
- return setTouched(true);
1733
- },
1734
- onBlurCapture: utils.withEventTargetValue(resetVerifiedData),
1735
- onChange: handleFieldChange
1736
- })), shouldShowVerificationCodeInput && /*#__PURE__*/jsxRuntime.jsx(VerifyCode, {
1737
- calloutDetails: calloutDetails,
1738
- email: email,
1739
- emailVerificationToken: emailVerificationToken,
1740
- formId: formId,
1741
- handleResponseError: handleResponseError,
1742
- handleSendVerificationCode: handleSendVerificationCode,
1743
- hasSentVerificationCode: hasSentVerificationCode,
1744
- isCodeVerified: isCodeVerified,
1745
- isRequired: isRequired,
1746
- isVerificationEnabled: isVerificationEnabled,
1747
- questionId: questionId,
1748
- setIsCodeVerified: setIsCodeVerified
1749
- })]
1750
- });
1751
- };
1752
-
1753
- var FileUploadField = function FileUploadField(_ref) {
1754
- var question = _ref.question,
1755
- _ref$preview = _ref.preview,
1756
- preview = _ref$preview === void 0 ? false : _ref$preview,
1757
- customValidator = _ref.customValidator;
1758
- var name = question.id,
1759
- kind = question.kind,
1760
- isRequired = question.isRequired,
1761
- nodeId = question.nodeId,
1762
- allowedFileTypes = question.allowedFileTypes,
1763
- multipleFilesAllowed = question.multipleFilesAllowed,
1764
- maxFileSize = question.maxFileSize;
1765
- var label = index.fieldWithFallback(question, "label");
1766
- var _useField = formik.useField({
1767
- name: name || nodeId,
1768
- validate: validateFieldValue({
1769
- kind: kind,
1770
- label: label,
1771
- isRequired: isRequired,
1772
- customValidator: customValidator,
1773
- multipleFilesAllowed: multipleFilesAllowed
1774
- })
1775
- }),
1776
- _useField2 = _slicedToArray(_useField, 3);
1777
- _useField2[0];
1778
- var _useField2$ = _useField2[1],
1779
- value = _useField2$.value,
1780
- touched = _useField2$.touched,
1781
- error = _useField2$.error,
1782
- _useField2$2 = _useField2[2],
1783
- setValue = _useField2$2.setValue,
1784
- setError = _useField2$2.setError,
1785
- setTouched = _useField2$2.setTouched;
1786
- var errorToDisplay = touched && error ? error : "";
1787
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
1788
- className: "neeto-form-engine-input__wrapper",
1789
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1790
- className: "neeto-form-engine-input__label-wrapper",
1791
- children: /*#__PURE__*/jsxRuntime.jsx(Label, {
1792
- className: "neeto-form-engine-label",
1793
- required: isRequired,
1794
- children: label
1795
- })
1796
- }), /*#__PURE__*/jsxRuntime.jsx(FileUpload.FileUpload, {
1797
- allowedFileTypes: allowedFileTypes,
1798
- maxFileSize: maxFileSize,
1799
- multipleFilesAllowed: multipleFilesAllowed,
1800
- setError: setError,
1801
- setTouched: setTouched,
1802
- error: errorToDisplay,
1803
- files: value === null || value === void 0 ? void 0 : value.files,
1804
- isPreview: preview,
1805
- onChange: function onChange(files) {
1806
- return setValue({
1807
- files: files
1808
- });
1809
- }
1810
- })]
1811
- });
1812
- };
1813
-
1814
- function ownKeys$a(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1815
- function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1816
- var Field = function Field(_ref) {
1817
- var question = _ref.question,
1818
- name = _ref.name,
1819
- labelField = _ref.labelField,
1820
- placeholderField = _ref.placeholderField,
1821
- customValidator = _ref.customValidator,
1822
- autoComplete = _ref.autoComplete;
1823
- var kind = question.kind,
1824
- isRequired = question.isRequired,
1825
- nodeId = question.nodeId,
1826
- isReadOnly = question.isReadOnly;
1827
- var label = index.fieldWithFallback(question, labelField);
1828
- var type = yup.QUESTION_KIND.NAME.type;
1829
- var _useField = formik.useField({
1830
- name: name || nodeId,
1831
- validate: validateFieldValue({
1832
- kind: kind,
1833
- label: label,
1834
- isRequired: isRequired,
1835
- customValidator: customValidator
1836
- })
1837
- }),
1838
- _useField2 = _slicedToArray(_useField, 3),
1839
- field = _useField2[0],
1840
- _useField2$ = _useField2[1],
1841
- touched = _useField2$.touched,
1842
- error = _useField2$.error,
1843
- _useField2$2 = _useField2[2],
1844
- setValue = _useField2$2.setValue,
1845
- setTouched = _useField2$2.setTouched;
1846
- return /*#__PURE__*/jsxRuntime.jsx(Input, _objectSpread$a(_objectSpread$a({}, _objectSpread$a(_objectSpread$a({
1847
- type: type
1848
- }, field), {}, {
1849
- autoComplete: autoComplete,
1850
- label: label,
1851
- name: name
1852
- })), {}, {
1853
- disabled: isReadOnly,
1854
- error: touched ? error : "",
1855
- placeholder: index.fieldWithFallback(question, placeholderField),
1856
- required: isRequired,
1857
- onBlur: function onBlur() {
1858
- return setTouched(true);
1859
- },
1860
- onChange: utils.withEventTargetValue(setValue)
1861
- }));
1862
- };
1863
-
1864
- function ownKeys$9(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1865
- function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1866
- var NameField = function NameField(props) {
1867
- var _props$question = props.question,
1868
- id = _props$question.id,
1869
- isSplitMode = _props$question.isSplitMode;
1870
- if (isSplitMode) {
1871
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
1872
- className: "flex w-full justify-between space-x-4",
1873
- children: [/*#__PURE__*/jsxRuntime.jsx(Field, _objectSpread$9(_objectSpread$9({}, props), {}, {
1874
- labelField: yup.LABEL_FIELDS.FIRST_NAME,
1875
- name: "".concat(id, ".firstName"),
1876
- placeholderField: "firstNamePlaceholder"
1877
- })), /*#__PURE__*/jsxRuntime.jsx(Field, _objectSpread$9(_objectSpread$9({}, props), {}, {
1878
- labelField: yup.LABEL_FIELDS.LAST_NAME,
1879
- name: "".concat(id, ".lastName"),
1880
- placeholderField: "lastNamePlaceholder"
1881
- }))]
1882
- });
1883
- }
1884
- return /*#__PURE__*/jsxRuntime.jsx(Field, _objectSpread$9(_objectSpread$9({}, props), {}, {
1885
- labelField: yup.LABEL_FIELDS.FULL_NAME,
1886
- name: "".concat(id, ".fullName"),
1887
- placeholderField: "fullNamePlaceholder"
1888
- }));
1889
- };
1890
-
1891
- var OpinionScaleField = function OpinionScaleField(_ref) {
1892
- var question = _ref.question,
1893
- customValidator = _ref.customValidator;
1894
- var name = question.id,
1895
- kind = question.kind,
1896
- isRequired = question.isRequired,
1897
- minValue = question.minValue,
1898
- maxValue = question.maxValue,
1899
- isReadOnly = question.isReadOnly,
1900
- hasOpinionLabels = question.hasOpinionLabels;
1901
- var label = index.fieldWithFallback(question, "label");
1902
- var leftOpinionLabel = index.fieldWithFallback(question, "leftOpinionLabel");
1903
- var rightOpinionLabel = index.fieldWithFallback(question, "rightOpinionLabel");
1904
- var _useField = formik.useField({
1905
- name: name,
1906
- validate: validateFieldValue({
1907
- kind: kind,
1908
- label: label,
1909
- isRequired: isRequired,
1910
- customValidator: customValidator
1911
- })
1912
- }),
1913
- _useField2 = _slicedToArray(_useField, 3),
1914
- field = _useField2[0],
1915
- _useField2$ = _useField2[1],
1916
- error = _useField2$.error,
1917
- touched = _useField2$.touched,
1918
- setValue = _useField2[2].setValue;
1919
- var handleClick = function handleClick(event, index) {
1920
- if (index !== parseInt(field.value)) return;
1921
- event.preventDefault();
1922
- setValue("");
1923
- };
1924
- var opinionScaleOptions = yup.generateArray(minValue, maxValue);
1925
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
1926
- className: "neeto-form-engine-input__wrapper neeto-form-engine-opinion-scale",
1927
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1928
- className: "neeto-form-engine-input__label-wrapper",
1929
- children: /*#__PURE__*/jsxRuntime.jsx("label", {
1930
- className: "neeto-form-engine-label",
1931
- "data-testid": "opinion-scale-input-label",
1932
- children: getLabel(label, isRequired)
1933
- })
1934
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
1935
- className: "neeto-form-nano-opinion-scale",
1936
- "data-testid": "form-opinion-scale",
1937
- children: /*#__PURE__*/jsxRuntime.jsxs("div", {
1938
- className: "neeto-form-nano-opinion-scale__group",
1939
- children: [hasOpinionLabels && /*#__PURE__*/jsxRuntime.jsx("div", {
1940
- className: "neeto-form-nano-opinion-scale__labels-wrap neeto-form-nano-opinion-scale__labels-wrap-mobile",
1941
- children: /*#__PURE__*/jsxRuntime.jsx("label", {
1942
- className: "neeto-form-nano-opinion-scale__label",
1943
- "data-testid": "opinion-scale-left-label",
1944
- children: leftOpinionLabel
1945
- })
1946
- }), /*#__PURE__*/jsxRuntime.jsx("ul", {
1947
- className: "neeto-form-nano-opinion-scale__list",
1948
- "data-testid": "opinion-scale-list",
1949
- children: opinionScaleOptions.map(function (step) {
1950
- return /*#__PURE__*/jsxRuntime.jsx("li", {
1951
- className: "neeto-form-nano-opinion-scale__item",
1952
- "data-testid": "opinion-scale-list-item",
1953
- children: /*#__PURE__*/jsxRuntime.jsxs("label", {
1954
- className: "neeto-form-nano-opinion-scale__item-label",
1955
- "data-testid": "opinion-scale-label",
1956
- onClick: function onClick(event) {
1957
- return handleClick(event, step);
1958
- },
1959
- children: [/*#__PURE__*/jsxRuntime.jsx(formik.Field, {
1960
- name: name,
1961
- checked: parseInt(field.value) === step,
1962
- className: "neeto-form-nano-sr-only neeto-form-nano-opinion-scale__item-input",
1963
- "data-testid": "opinion-scale-input-".concat(step),
1964
- disabled: isReadOnly,
1965
- type: "radio",
1966
- value: step
1967
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
1968
- className: "neeto-form-nano-opinion-scale__item-highlight",
1969
- "data-testid": "opinion-scale-item-".concat(step),
1970
- children: step
1971
- })]
1972
- })
1973
- }, step);
1974
- })
1975
- }), hasOpinionLabels && /*#__PURE__*/jsxRuntime.jsxs("div", {
1976
- className: "neeto-form-nano-opinion-scale__labels-wrap",
1977
- children: [/*#__PURE__*/jsxRuntime.jsx("label", {
1978
- className: "neeto-form-nano-opinion-scale__label neeto-form-nano-opinion-scale__label--start",
1979
- "data-testid": "opinion-scale-left-label",
1980
- children: leftOpinionLabel
1981
- }), /*#__PURE__*/jsxRuntime.jsx("label", {
1982
- className: "neeto-form-nano-opinion-scale__label neeto-form-nano-opinion-scale__label--end",
1983
- "data-testid": "opinion-scale-right-label",
1984
- children: rightOpinionLabel
1985
- })]
1986
- })]
1987
- })
1988
- }), touched && error && /*#__PURE__*/jsxRuntime.jsx("p", {
1989
- className: "neeto-form-engine-input__error",
1990
- "data-testid": "neeto-form-engine-opinion-scale-error",
1991
- children: error
1992
- })]
1993
- });
1994
- };
1995
-
1996
- var ChoiceImage = function ChoiceImage(_ref) {
1997
- var src = _ref.src,
1998
- alt = _ref.alt,
1999
- height = _ref.height,
2000
- shouldFitImages = _ref.shouldFitImages;
2001
- var _useState = React.useState(false),
2002
- _useState2 = _slicedToArray(_useState, 2),
2003
- hasError = _useState2[0],
2004
- setHasError = _useState2[1];
2005
- var _useState3 = React.useState(true),
2006
- _useState4 = _slicedToArray(_useState3, 2),
2007
- isLoading = _useState4[0],
2008
- setIsLoading = _useState4[1];
2009
- var handleLoad = function handleLoad() {
2010
- return setIsLoading(false);
2011
- };
2012
- var handleError = function handleError() {
2013
- setHasError(true);
2014
- setIsLoading(false);
2015
- };
2016
- if (hasError || !src) {
2017
- return /*#__PURE__*/jsxRuntime.jsx("div", {
2018
- className: "neeto-form-engine-choice__image-placeholder neeto-ui-bg-gray-100",
2019
- style: {
2020
- height: height
2021
- },
2022
- children: /*#__PURE__*/jsxRuntime.jsx(Image, {
2023
- size: 32
2024
- })
2025
- });
2026
- }
2027
- return /*#__PURE__*/jsxRuntime.jsx("div", {
2028
- style: {
2029
- height: height
2030
- },
2031
- className: classnames("neeto-form-engine-choice__image-wrapper", {
2032
- "neeto-form-engine-choice__image-wrapper--loading": isLoading
2033
- }),
2034
- children: /*#__PURE__*/jsxRuntime.jsx("img", {
2035
- alt: alt,
2036
- src: src,
2037
- draggable: false,
2038
- className: classnames("neeto-form-engine-choice__image", {
2039
- "neeto-form-engine-choice__image--fit": shouldFitImages
2040
- }),
2041
- onError: handleError,
2042
- onLoad: handleLoad
2043
- })
2044
- });
2045
- };
2046
-
2047
- var Choices = function Choices(_ref) {
2048
- var label = _ref.label,
2049
- options = _ref.options,
2050
- type = _ref.type,
2051
- name = _ref.name,
2052
- value = _ref.value,
2053
- onChange = _ref.onChange,
2054
- onValueChange = _ref.onValueChange,
2055
- error = _ref.error,
2056
- disabled = _ref.isDisabled,
2057
- _ref$isPictureChoice = _ref.isPictureChoice,
2058
- isPictureChoice = _ref$isPictureChoice === void 0 ? yup.DEFAULT_CHOICE_QUESTION_ATTRIBUTES.isPictureChoice : _ref$isPictureChoice,
2059
- _ref$imageHeight = _ref.imageHeight,
2060
- imageHeight = _ref$imageHeight === void 0 ? yup.DEFAULT_CHOICE_QUESTION_ATTRIBUTES.imageHeight : _ref$imageHeight,
2061
- _ref$shouldFitImages = _ref.shouldFitImages,
2062
- shouldFitImages = _ref$shouldFitImages === void 0 ? yup.DEFAULT_CHOICE_QUESTION_ATTRIBUTES.shouldFitImages : _ref$shouldFitImages;
2063
- var isCheckBox = type === "checkbox";
2064
- var ChoiceWrapper = isCheckBox ? "div" : Radio;
2065
- var Component = isCheckBox ? Checkbox : Radio.Item;
2066
- var handleChoiceValueChange = function handleChoiceValueChange(updatedValue) {
2067
- if (typeof onValueChange === "function") {
2068
- onValueChange(updatedValue);
2069
- return;
2070
- }
2071
- onChange({
2072
- target: {
2073
- name: name,
2074
- value: updatedValue
2075
- }
2076
- });
2077
- };
2078
- var shouldDeselectOption = function shouldDeselectOption(optionId) {
2079
- return !isCheckBox && !disabled && value === optionId;
2080
- };
2081
- var handleChoiceClick = function handleChoiceClick(event, optionId) {
2082
- if (!shouldDeselectOption(optionId)) return;
2083
- event.preventDefault();
2084
- handleChoiceValueChange("");
2085
- };
2086
- var handleChoiceKeyDown = function handleChoiceKeyDown(event, optionId) {
2087
- if (!shouldDeselectOption(optionId)) return;
2088
- if (!yup.RADIO_DESELECT_KEYS.includes(event.key)) return;
2089
- event.preventDefault();
2090
- handleChoiceValueChange("");
2091
- };
2092
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
2093
- className: "neeto-form-engine-choices__wrapper",
2094
- "data-testid": "".concat(neetoCist.hyphenate(label), "-select-container-wrapper"),
2095
- children: [/*#__PURE__*/jsxRuntime.jsx("label", {
2096
- className: "neeto-form-engine-label",
2097
- "data-testid": "".concat(neetoCist.hyphenate(label), "-input-label"),
2098
- children: label
2099
- }), /*#__PURE__*/jsxRuntime.jsx(ChoiceWrapper, {
2100
- stacked: !isCheckBox,
2101
- className: classnames("neeto-form-engine-choices", {
2102
- "neeto-form-engine-choices--picture": isPictureChoice
2103
- }),
2104
- children: options.map(function (option, index) {
2105
- var _value$index, _option$image;
2106
- var isChecked = isCheckBox ? (_value$index = value === null || value === void 0 ? void 0 : value[index]) !== null && _value$index !== void 0 ? _value$index : false : value === option.id;
2107
- return /*#__PURE__*/jsxRuntime.jsxs("label", {
2108
- htmlFor: option.id,
2109
- className: classnames("neeto-form-engine-choice", {
2110
- "neeto-form-engine-choice--picture": isPictureChoice,
2111
- "neeto-form-engine-choice--selected": isChecked,
2112
- "cursor-not-allowed": disabled
2113
- }),
2114
- onClick: function onClick(event) {
2115
- return handleChoiceClick(event, option.id);
2116
- },
2117
- children: [isPictureChoice && /*#__PURE__*/jsxRuntime.jsx(ChoiceImage, {
2118
- shouldFitImages: shouldFitImages,
2119
- alt: option.label,
2120
- height: imageHeight,
2121
- src: (_option$image = option.image) === null || _option$image === void 0 ? void 0 : _option$image.url
2122
- }), /*#__PURE__*/jsxRuntime.jsx(Component, {
2123
- disabled: disabled,
2124
- onChange: onChange,
2125
- type: type,
2126
- checked: isChecked,
2127
- className: classnames({
2128
- "cursor-not-allowed": disabled
2129
- }),
2130
- id: option.id,
2131
- label: option.label,
2132
- name: isCheckBox ? "".concat(name, ".").concat(index) : name,
2133
- value: option.id,
2134
- labelProps: {
2135
- className: classnames({
2136
- "cursor-not-allowed": disabled
2137
- })
2138
- },
2139
- onKeyDown: function onKeyDown(event) {
2140
- return handleChoiceKeyDown(event, option.id);
2141
- }
2142
- })]
2143
- }, option.id);
2144
- })
2145
- }), !!error && typeof error === "string" && /*#__PURE__*/jsxRuntime.jsx("p", {
2146
- className: "neeto-form-engine-input__error",
2147
- "data-testid": "neeto-form-engine-".concat(type, "-error"),
2148
- children: error
2149
- })]
2150
- });
2151
- };
2152
- var Choices$1 = /*#__PURE__*/React.memo(Choices);
2153
-
2154
- function ownKeys$8(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2155
- function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$8(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$8(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2156
- var OptionsField = function OptionsField(_ref) {
2157
- var question = _ref.question,
2158
- customValidator = _ref.customValidator,
2159
- isLastFewElements = _ref.isLastFewElements;
2160
- var _useFormikContext = formik.useFormikContext(),
2161
- setFieldTouched = _useFormikContext.setFieldTouched,
2162
- setFieldValue = _useFormikContext.setFieldValue,
2163
- validateField = _useFormikContext.validateField;
2164
- var name = question.id,
2165
- kind = question.kind,
2166
- isRequired = question.isRequired,
2167
- isReadOnly = question.isReadOnly,
2168
- isPictureChoiceFromQuestion = question.isPictureChoice,
2169
- imageHeight = question.imageHeight,
2170
- shouldFitImages = question.shouldFitImages,
2171
- _question$optionsAttr = question.optionsAttributes,
2172
- options = _question$optionsAttr === void 0 ? [] : _question$optionsAttr;
2173
- var isPictureChoice = isPictureChoiceFromQuestion;
2174
- var isDropdown = kind === yup.QUESTION_KIND.DROPDOWN.value;
2175
- var label = index.fieldWithFallback(question, "label");
2176
- var Component = isDropdown ? Select : Choices$1;
2177
- var transformedOptions = isDropdown ? options.map(function (option) {
2178
- return {
2179
- label: index.fieldWithFallback(option, "label"),
2180
- position: option.position,
2181
- value: option.id
2182
- };
2183
- }) : options.map(function (option) {
2184
- return _objectSpread$8(_objectSpread$8({}, option), {}, {
2185
- label: index.fieldWithFallback(option, "label")
2186
- });
2187
- });
2188
- var handleSelect = function handleSelect(option) {
2189
- setFieldValue(name, option === null || option === void 0 ? void 0 : option.value, false);
2190
- setFieldTouched(name, true, false);
2191
- setTimeout(function () {
2192
- return validateField(name);
2193
- });
2194
- };
2195
- var handleValueChange = function handleValueChange(updatedValue) {
2196
- setFieldValue(name, updatedValue, false);
2197
- setFieldTouched(name, true, false);
2198
- setTimeout(function () {
2199
- return validateField(name);
2200
- });
2201
- };
2202
- var customFilter = function customFilter(option, inputValue) {
2203
- if (!option) return false;
2204
- return containsIgnoreCase(option.label, inputValue);
2205
- };
2206
- return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
2207
- name: name,
2208
- validate: validateFieldValue({
2209
- kind: kind,
2210
- label: label,
2211
- isRequired: isRequired,
2212
- customValidator: customValidator
2213
- }),
2214
- children: function children(_ref2) {
2215
- var meta = _ref2.meta,
2216
- field = _ref2.field;
2217
- var onChange = field.onChange,
2218
- value = field.value;
2219
- return /*#__PURE__*/jsxRuntime.jsx(Component, _objectSpread$8(_objectSpread$8({
2220
- error: getError(meta),
2221
- isDisabled: isReadOnly,
2222
- label: getLabel(label, isRequired),
2223
- options: transformedOptions,
2224
- strategy: "fixed",
2225
- type: kind
2226
- }, _objectSpread$8(_objectSpread$8({
2227
- isRequired: isRequired,
2228
- name: name
2229
- }, isDropdown && {
2230
- filterOption: customFilter
2231
- }), !isDropdown && {
2232
- imageHeight: imageHeight,
2233
- isPictureChoice: isPictureChoice,
2234
- shouldFitImages: shouldFitImages
2235
- })), {}, {
2236
- value: isDropdown ? neetoCist.findBy({
2237
- value: value
2238
- }, transformedOptions) || null : value,
2239
- onChange: isDropdown ? handleSelect : onChange,
2240
- onValueChange: !isDropdown ? handleValueChange : undefined
2241
- }, isDropdown && {
2242
- isClearable: true,
2243
- menuPlacement: isLastFewElements ? "top" : "auto",
2244
- menuPortalTarget: document.body,
2245
- menuPosition: "fixed"
2246
- }));
2247
- }
2248
- });
2249
- };
2250
-
2251
- var PhoneNumberField = function PhoneNumberField(_ref) {
2252
- var _getPhoneData;
2253
- var question = _ref.question,
2254
- autoComplete = _ref.autoComplete,
2255
- isLastFewElements = _ref.isLastFewElements;
2256
- var name = question.id,
2257
- kind = question.kind,
2258
- isRequired = question.isRequired,
2259
- nodeId = question.nodeId,
2260
- isReadOnly = question.isReadOnly;
2261
- var label = index.fieldWithFallback(question, "label");
2262
- var _useField = formik.useField({
2263
- name: name || nodeId,
2264
- validate: validateFieldValue({
2265
- kind: kind,
2266
- label: label,
2267
- isRequired: isRequired
2268
- })
2269
- }),
2270
- _useField2 = _slicedToArray(_useField, 3),
2271
- value = _useField2[0].value,
2272
- _useField2$ = _useField2[1],
2273
- touched = _useField2$.touched,
2274
- error = _useField2$.error,
2275
- _useField2$2 = _useField2[2],
2276
- setValue = _useField2$2.setValue,
2277
- setTouched = _useField2$2.setTouched;
2278
- return /*#__PURE__*/jsxRuntime.jsx(PhoneNumber.PhoneNumberInput, {
2279
- autoComplete: autoComplete,
2280
- label: label,
2281
- value: value,
2282
- className: "neeto-form-engine-input__wrapper items-stretch",
2283
- disabled: isReadOnly,
2284
- error: touched ? error : "",
2285
- initialCountryCode: (_getPhoneData = getPhoneData(value)) === null || _getPhoneData === void 0 ? void 0 : _getPhoneData.country,
2286
- placeholder: index.fieldWithFallback(question, "placeholder"),
2287
- required: isRequired,
2288
- selectProps: {
2289
- isDisabled: isReadOnly,
2290
- menuPlacement: isLastFewElements ? "top" : "auto",
2291
- menuPortalTarget: document.body,
2292
- menuPosition: "fixed"
2293
- },
2294
- onBlur: function onBlur() {
2295
- return setTouched(true);
2296
- },
2297
- onChange: setValue
2298
- });
2299
- };
2300
-
2301
- var _excluded$2 = ["name", "label", "error", "lowestRatingLabel", "averageRatingLabel", "highestRatingLabel", "value", "disabled"];
2302
- function ownKeys$7(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2303
- function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2304
- var Rating = function Rating(_ref) {
2305
- var name = _ref.name,
2306
- label = _ref.label,
2307
- error = _ref.error,
2308
- lowestRatingLabel = _ref.lowestRatingLabel,
2309
- averageRatingLabel = _ref.averageRatingLabel,
2310
- highestRatingLabel = _ref.highestRatingLabel,
2311
- value = _ref.value,
2312
- disabled = _ref.disabled,
2313
- other = _objectWithoutProperties(_ref, _excluded$2);
2314
- var handleClick = function handleClick(e) {
2315
- return e.currentTarget.nextElementSibling.click();
2316
- };
2317
- var render = function render() {
2318
- var labels = [highestRatingLabel, averageRatingLabel, lowestRatingLabel];
2319
- return yup.RATING_OPTIONS.map(function (_ref2, index) {
2320
- var Icon = _ref2.icon,
2321
- modifier = _ref2.modifier,
2322
- rating = _ref2.value;
2323
- return /*#__PURE__*/jsxRuntime.jsxs(React.Fragment, {
2324
- children: [/*#__PURE__*/jsxRuntime.jsxs("button", {
2325
- disabled: disabled,
2326
- type: "button",
2327
- className: classnames("neeto-form-engine-rating__item neeto-form-engine-rating__item--".concat(modifier), {
2328
- active: rating === value
2329
- }),
2330
- onClick: handleClick,
2331
- children: [/*#__PURE__*/jsxRuntime.jsx(Icon, {}), /*#__PURE__*/jsxRuntime.jsx("label", {
2332
- className: "neeto-form-engine-label",
2333
- children: labels[index]
2334
- })]
2335
- }), /*#__PURE__*/jsxRuntime.jsx("input", _objectSpread$7({
2336
- name: name,
2337
- hidden: true,
2338
- checked: rating === value,
2339
- type: "radio",
2340
- value: rating
2341
- }, other))]
2342
- }, rating);
2343
- });
2344
- };
2345
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
2346
- className: "neeto-form-engine-rating",
2347
- children: [/*#__PURE__*/jsxRuntime.jsx("label", {
2348
- className: "neeto-form-engine-label",
2349
- "data-testid": "rating-input-label",
2350
- children: label
2351
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
2352
- className: "neeto-form-engine-rating__row",
2353
- "data-testid": "rating-input-field",
2354
- children: render()
2355
- }), !!error && typeof error === "string" && /*#__PURE__*/jsxRuntime.jsx("p", {
2356
- className: "neeto-form-engine-input__error",
2357
- "data-testid": "neeto-form-engine-rating-error",
2358
- children: error
2359
- })]
2360
- });
2361
- };
2362
- var Rating$1 = /*#__PURE__*/React.memo(Rating);
2363
-
2364
- function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2365
- function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2366
- var RatingField = function RatingField(_ref) {
2367
- var question = _ref.question,
2368
- customValidator = _ref.customValidator;
2369
- var name = question.id,
2370
- kind = question.kind,
2371
- isRequired = question.isRequired,
2372
- isReadOnly = question.isReadOnly;
2373
- var label = index.fieldWithFallback(question, "label");
2374
- return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
2375
- name: name,
2376
- validate: validateFieldValue({
2377
- kind: kind,
2378
- label: label,
2379
- isRequired: isRequired,
2380
- customValidator: customValidator
2381
- }),
2382
- children: function children(_ref2) {
2383
- var meta = _ref2.meta,
2384
- field = _ref2.field;
2385
- return /*#__PURE__*/jsxRuntime.jsx(Rating$1, _objectSpread$6(_objectSpread$6({}, field), {}, {
2386
- disabled: isReadOnly,
2387
- error: meta.touched ? meta.error : "",
2388
- label: getLabel(label, isRequired),
2389
- averageRatingLabel: index.fieldWithFallback(question, "averageRatingLabel") || yup.RATING_VALUES.AVERAGE.label,
2390
- highestRatingLabel: index.fieldWithFallback(question, "highestRatingLabel") || yup.RATING_VALUES.GOOD.label,
2391
- lowestRatingLabel: index.fieldWithFallback(question, "lowestRatingLabel") || yup.RATING_VALUES.BAD.label
2392
- }));
2393
- }
2394
- });
2395
- };
2396
-
2397
- function ownKeys$5(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2398
- function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2399
- var RichTextEditor = function RichTextEditor(_ref) {
2400
- var editorRef = _ref.editorRef,
2401
- question = _ref.question,
2402
- _ref$editorProps = _ref.editorProps,
2403
- editorProps = _ref$editorProps === void 0 ? {} : _ref$editorProps;
2404
- var _useFormikContext = formik.useFormikContext(),
2405
- errors = _useFormikContext.errors,
2406
- touched = _useFormikContext.touched;
2407
- var name = question.id,
2408
- kind = question.kind,
2409
- isRequired = question.isRequired,
2410
- nodeId = question.nodeId,
2411
- isReadOnly = question.isReadOnly;
2412
- var label = index.fieldWithFallback(question, "label");
2413
- var debouncedPlaceholder = reactUtils.useDebounce(index.fieldWithFallback(question, "placeholder"), 300);
2414
- React.useEffect(function () {
2415
- var _editorRef$current, _editorRef$current$se;
2416
- editorRef === null || editorRef === void 0 || (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || (_editorRef$current = _editorRef$current.editor) === null || _editorRef$current === void 0 || (_editorRef$current$se = _editorRef$current.setEditable) === null || _editorRef$current$se === void 0 || _editorRef$current$se.call(_editorRef$current, !isReadOnly);
2417
- }, [editorRef === null || editorRef === void 0 ? void 0 : editorRef.current, isReadOnly]);
2418
- var propsToCompare = ["debouncedPlaceholder", "error", "touched", "isReadOnly"];
2419
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
2420
- className: "neeto-form-engine-input__wrapper",
2421
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
2422
- className: "neeto-form-engine-input__label-wrapper",
2423
- children: label && /*#__PURE__*/jsxRuntime.jsx("label", {
2424
- className: "neeto-form-engine-label",
2425
- "data-testid": "".concat(neetoCist.hyphenate(label), "-input-label"),
2426
- children: getLabel(label, isRequired)
2427
- })
2428
- }), /*#__PURE__*/jsxRuntime.jsx(formik.FastField, {
2429
- debouncedPlaceholder: debouncedPlaceholder,
2430
- isReadOnly: isReadOnly,
2431
- error: errors[name],
2432
- name: name || nodeId,
2433
- shouldUpdate: isPropsUnequal(propsToCompare),
2434
- touched: touched[name],
2435
- validate: validateFieldValue({
2436
- kind: kind,
2437
- label: label,
2438
- isRequired: isRequired
2439
- }),
2440
- children: function children(_ref2) {
2441
- var field = _ref2.field,
2442
- form = _ref2.form,
2443
- meta = _ref2.meta;
2444
- return /*#__PURE__*/jsxRuntime.jsx(NeetoEditor, _objectSpread$5({
2445
- editable: isReadOnly,
2446
- error: meta.touched ? meta.error : "",
2447
- initialValue: field.value,
2448
- menuType: isReadOnly ? "bubble" : "fixed",
2449
- placeholder: debouncedPlaceholder,
2450
- ref: editorRef,
2451
- addons: isReadOnly ? [] : ["attachments", "block-quote", "code-block", "image-upload"],
2452
- className: classnames("neeto-form-engine-rich-text-input", {
2453
- "cursor-not-allowed border": isReadOnly
2454
- }),
2455
- onBlur: function onBlur() {
2456
- return form.setFieldTouched(name, true);
2457
- },
2458
- onChange: function onChange(value) {
2459
- return form.setFieldValue(name, value);
2460
- }
2461
- }, editorProps), debouncedPlaceholder);
2462
- }
2463
- })]
2464
- });
2465
- };
2466
-
2467
- var _excluded$1 = ["value", "iconType", "label", "rating"];
2468
- function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2469
- function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2470
- var RatingButton = function RatingButton(_ref) {
2471
- var _ref$value = _ref.value,
2472
- value = _ref$value === void 0 ? 0 : _ref$value,
2473
- iconType = _ref.iconType,
2474
- label = _ref.label,
2475
- rating = _ref.rating,
2476
- otherProps = _objectWithoutProperties(_ref, _excluded$1);
2477
- var handleClick = function handleClick(e) {
2478
- return e.currentTarget.nextElementSibling.click();
2479
- };
2480
- var Icon = yup.ICONS_MAP[iconType];
2481
- var selectedRating = getSelectedRating(value);
2482
- return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2483
- children: [/*#__PURE__*/jsxRuntime.jsxs("button", {
2484
- className: classnames({
2485
- active: rating === value
2486
- }),
2487
- disabled: otherProps === null || otherProps === void 0 ? void 0 : otherProps.disabled,
2488
- type: "button",
2489
- onClick: handleClick,
2490
- children: [/*#__PURE__*/jsxRuntime.jsx(Icon, {
2491
- size: 24,
2492
- className: classnames("neeto-form-engine-star-rating__icon", {
2493
- "neeto-form-engine-star-rating__icon--active": rating <= selectedRating
2494
- })
2495
- }), /*#__PURE__*/jsxRuntime.jsx("label", {
2496
- className: "neeto-form-engine-label",
2497
- children: label
2498
- })]
2499
- }), /*#__PURE__*/jsxRuntime.jsx("input", _objectSpread$4({
2500
- hidden: true,
2501
- checked: ramda.equals(rating, value),
2502
- type: "radio",
2503
- value: rating
2504
- }, otherProps))]
2505
- });
2506
- };
2507
- var RatingButton$1 = /*#__PURE__*/React.memo(RatingButton);
2508
-
2509
- var _excluded = ["label", "minValue", "maxValue", "error"];
2510
- function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2511
- function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2512
- var StarRating = function StarRating(_ref) {
2513
- var label = _ref.label,
2514
- minValue = _ref.minValue,
2515
- maxValue = _ref.maxValue,
2516
- error = _ref.error,
2517
- props = _objectWithoutProperties(_ref, _excluded);
2518
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
2519
- className: "neeto-form-engine-input__wrapper neeto-form-engine-star-rating",
2520
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
2521
- className: "neeto-form-engine-input__label-wrapper",
2522
- children: /*#__PURE__*/jsxRuntime.jsx("label", {
2523
- className: "neeto-form-engine-label",
2524
- "data-testid": "star-rating-input-label",
2525
- children: label
2526
- })
2527
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
2528
- className: "neeto-form-engine-star-rating__row",
2529
- "data-testid": "star-rating-input-field",
2530
- children: yup.generateArray(minValue, maxValue).map(function (index) {
2531
- return /*#__PURE__*/jsxRuntime.jsx(RatingButton$1, _objectSpread$3({
2532
- label: index,
2533
- rating: index
2534
- }, props), index);
2535
- })
2536
- }), !!error && typeof error === "string" && /*#__PURE__*/jsxRuntime.jsx("p", {
2537
- className: "neeto-form-engine-input__error",
2538
- "data-testid": "neeto-form-engine-star-rating-error",
2539
- children: error
2540
- })]
2541
- });
2542
- };
2543
- var StarRating$1 = /*#__PURE__*/React.memo(StarRating);
2544
-
2545
- function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2546
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2547
- var StarRatingField = function StarRatingField(_ref) {
2548
- var question = _ref.question,
2549
- customValidator = _ref.customValidator;
2550
- var name = question.id,
2551
- kind = question.kind,
2552
- isRequired = question.isRequired,
2553
- minValue = question.minValue,
2554
- maxValue = question.maxValue,
2555
- iconType = question.iconType,
2556
- isReadOnly = question.isReadOnly;
2557
- var label = index.fieldWithFallback(question, "label");
2558
- return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
2559
- name: name,
2560
- validate: validateFieldValue({
2561
- kind: kind,
2562
- label: label,
2563
- isRequired: isRequired,
2564
- customValidator: customValidator
2565
- }),
2566
- children: function children(_ref2) {
2567
- var meta = _ref2.meta,
2568
- field = _ref2.field;
2569
- return /*#__PURE__*/jsxRuntime.jsx(StarRating$1, _objectSpread$2({
2570
- iconType: iconType,
2571
- maxValue: maxValue,
2572
- minValue: minValue,
2573
- name: name,
2574
- disabled: isReadOnly,
2575
- error: meta.touched ? meta.error : "",
2576
- label: getLabel(label, isRequired)
2577
- }, field));
2578
- }
2579
- });
2580
- };
2581
-
2582
- function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2583
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2584
- var TermsField = function TermsField(_ref) {
2585
- var question = _ref.question,
2586
- customValidator = _ref.customValidator;
2587
- var name = question.id,
2588
- kind = question.kind,
2589
- isRequired = question.isRequired,
2590
- nodeId = question.nodeId;
2591
- var label = index.fieldWithFallback(question, "label", true);
2592
- return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
2593
- name: name || nodeId,
2594
- validate: validateFieldValue({
2595
- kind: kind,
2596
- label: label,
2597
- isRequired: isRequired,
2598
- customValidator: customValidator
2599
- }),
2600
- children: function children(_ref2) {
2601
- var meta = _ref2.meta,
2602
- field = _ref2.field;
2603
- return /*#__PURE__*/jsxRuntime.jsx("div", {
2604
- className: "neeto-form-engine-terms",
2605
- children: /*#__PURE__*/jsxRuntime.jsx(Checkbox, _objectSpread$1(_objectSpread$1({}, _objectSpread$1(_objectSpread$1({}, field), {}, {
2606
- name: name
2607
- })), {}, {
2608
- checked: field.value,
2609
- error: meta.touched ? meta.error : "",
2610
- children: /*#__PURE__*/jsxRuntime.jsx(EditorContent, {
2611
- content: label
2612
- })
2613
- }))
2614
- });
2615
- }
2616
- });
2617
- };
2618
-
2619
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2620
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2621
- var TextField = function TextField(_ref) {
2622
- var _otherProps$onChange;
2623
- var question = _ref.question,
2624
- customValidator = _ref.customValidator,
2625
- autoComplete = _ref.autoComplete,
2626
- remainingSlotsCount = _ref.remainingSlotsCount;
2627
- var _useTranslation = reactI18next.useTranslation(),
2628
- t = _useTranslation.t;
2629
- var name = question.id,
2630
- kind = question.kind,
2631
- isRequired = question.isRequired,
2632
- isReadOnly = question.isReadOnly,
2633
- nodeId = question.nodeId;
2634
- var label = index.fieldWithFallback(question, "label");
2635
- var _QUESTION_KIND$kind$t = yup.QUESTION_KIND[kind.toUpperCase()],
2636
- _QUESTION_KIND$kind$t2 = _QUESTION_KIND$kind$t.type,
2637
- type = _QUESTION_KIND$kind$t2 === void 0 ? "text" : _QUESTION_KIND$kind$t2,
2638
- onKeyDown = _QUESTION_KIND$kind$t.onKeyDown,
2639
- otherProps = _QUESTION_KIND$kind$t.otherProps;
2640
- var Component = kind === yup.QUESTION_KIND.TEXTAREA.value ? Textarea : Input;
2641
- var _useField = formik.useField({
2642
- name: name || nodeId,
2643
- validate: validateFieldValue({
2644
- kind: kind,
2645
- label: label,
2646
- isRequired: isRequired,
2647
- customValidator: customValidator,
2648
- remainingSlotsCount: remainingSlotsCount
2649
- })
2650
- }),
2651
- _useField2 = _slicedToArray(_useField, 3),
2652
- field = _useField2[0],
2653
- _useField2$ = _useField2[1],
2654
- touched = _useField2$.touched,
2655
- error = _useField2$.error,
2656
- _useField2$2 = _useField2[2],
2657
- setValue = _useField2$2.setValue,
2658
- setTouched = _useField2$2.setTouched;
2659
- var handleFieldChange = utils.withEventTargetValue(setValue);
2660
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
2661
- className: "w-full flex flex-col gap-2",
2662
- children: [/*#__PURE__*/jsxRuntime.jsx(Component, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({
2663
- type: type
2664
- }, field), {}, {
2665
- autoComplete: autoComplete,
2666
- label: label,
2667
- onKeyDown: onKeyDown
2668
- }, kind === yup.QUESTION_KIND.SPOT.value && _objectSpread({
2669
- min: 1
2670
- }, typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0 && {
2671
- max: remainingSlotsCount
2672
- }))), {}, {
2673
- disabled: isReadOnly,
2674
- error: touched ? error : "",
2675
- name: neetoCist.slugify(label),
2676
- placeholder: index.fieldWithFallback(question, "placeholder"),
2677
- required: isRequired,
2678
- onBlur: function onBlur() {
2679
- return setTouched(true);
2680
- },
2681
- onChange: (_otherProps$onChange = otherProps === null || otherProps === void 0 ? void 0 : otherProps.onChange(handleFieldChange)) !== null && _otherProps$onChange !== void 0 ? _otherProps$onChange : handleFieldChange
2682
- })), kind === yup.QUESTION_KIND.SPOT.value && typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0 && /*#__PURE__*/jsxRuntime.jsx("div", {
2683
- className: "flex justify-end",
2684
- children: /*#__PURE__*/jsxRuntime.jsx(Tag, {
2685
- icon: Info,
2686
- style: "info",
2687
- label: t("neetoForm.questions.spot.remainingSlotsCount", {
2688
- count: remainingSlotsCount
2689
- })
2690
- })
2691
- })]
2692
- });
2693
- };
2694
-
2695
- var _QUESTION_TO_COMPONEN;
2696
- var QUESTION_TO_COMPONENT_MAP = (_QUESTION_TO_COMPONEN = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_QUESTION_TO_COMPONEN, yup.QUESTION_KIND.TEXT.value, TextField), yup.QUESTION_KIND.NAME.value, NameField), yup.QUESTION_KIND.EMAIL.value, EmailField), yup.QUESTION_KIND.INTEGER.value, TextField), yup.QUESTION_KIND.DECIMAL.value, TextField), yup.QUESTION_KIND.PHONE.value, PhoneNumberField), yup.QUESTION_KIND.QUESTION.value, TextField), yup.QUESTION_KIND.TEXTAREA.value, TextField), yup.QUESTION_KIND.CHECKBOX.value, OptionsField), yup.QUESTION_KIND.RADIO.value, OptionsField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_QUESTION_TO_COMPONEN, yup.QUESTION_KIND.DROPDOWN.value, OptionsField), yup.QUESTION_KIND.RATING.value, RatingField), yup.QUESTION_KIND.PARAGRAPH.value, function (_ref) {
2697
- var question = _ref.question;
2698
- return /*#__PURE__*/jsxRuntime.jsx(EditorContent, {
2699
- content: index.fieldWithFallback(question, "label", true)
2700
- });
2701
- }), yup.QUESTION_KIND.TERMS.value, TermsField), yup.QUESTION_KIND.DATE.value, DateField), yup.QUESTION_KIND.STAR_RATING.value, StarRatingField), yup.QUESTION_KIND.OPINION_SCALE.value, OpinionScaleField), yup.QUESTION_KIND.ADDITIONAL_GUESTS.value, MultipleEmailInput), yup.QUESTION_KIND.RICH_TEXT.value, RichTextEditor), yup.QUESTION_KIND.CONDITION.value, ConditionField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_QUESTION_TO_COMPONEN, yup.QUESTION_KIND.FILE_UPLOAD.value, FileUploadField), yup.QUESTION_KIND.CAPTCHA.value, CaptchaField), yup.QUESTION_KIND.SMS_REMINDER.value, PhoneNumberField), yup.QUESTION_KIND.SPOT.value, TextField), yup.QUESTION_KIND.ADDRESS.value, AddressField));
2702
- var CAPTCHA_COMPONENT_MAP = _defineProperty(_defineProperty({}, constants.CAPTCHA_TYPES.RECAPTCHA_V2, Recaptcha), constants.CAPTCHA_TYPES.MATH_CAPTCHA, MathCaptcha);
2703
-
2704
- var getFieldComponent = function getFieldComponent(_ref) {
2705
- var kind = _ref.kind;
2706
- if (kind in QUESTION_TO_COMPONENT_MAP) return QUESTION_TO_COMPONENT_MAP[kind];
2707
- return function () {
2708
- return null;
2709
- };
2710
- };
2711
- var isPropsUnequal = function isPropsUnequal(props) {
2712
- return function (nextProps, prevProps) {
2713
- return neetoCist.notEqualsDeep(ramda.pick(props, nextProps), ramda.pick(props, prevProps));
2714
- };
2715
- };
2716
- var getValidDate = function getValidDate(date) {
2717
- if (!date) return "";
2718
- return utils.dayjs(date).isValid() ? utils.dayjs(date) : "";
2719
- };
2720
- var getPhoneData = function getPhoneData(value, countryCode) {
2721
- try {
2722
- return libphonenumberJs.parsePhoneNumber(value, countryCode);
2723
- } catch (_unused) {
2724
- return undefined;
2725
- }
2726
- };
2727
- var containsIgnoreCase = function containsIgnoreCase(string, substring) {
2728
- return string.toLowerCase().includes(substring.toLowerCase());
2729
- };
2730
- var getVisibleOptions = function getVisibleOptions(options) {
2731
- return Array.isArray(options) ? options.filter(function (option) {
2732
- return !option.deleted;
2733
- }).sort(function (a, b) {
2734
- return a.position - b.position;
2735
- }) : [];
2736
- };
2737
-
2738
- exports.FormikWrap = FormikWrap;
2739
- exports.buildAutoCompleteAttribute = buildAutoCompleteAttribute;
2740
- exports.clearEmailVerificationDetails = clearEmailVerificationDetails;
2741
- exports.clearLocalStorageValues = clearLocalStorageValues;
2742
- exports.clientI18nInstance = clientI18nInstance;
2743
- exports.generateFormResponse = generateFormResponse;
2744
- exports.generateInitValues = generateInitValues;
2745
- exports.getFieldComponent = getFieldComponent;
2746
- exports.getWithExpiry = getWithExpiry;
2747
- exports.mergeRefs = mergeRefs;
2748
- exports.renderButtonsInOrder = renderButtonsInOrder;
2749
- //# sourceMappingURL=utils-baAzU7l8.js.map